Skip to content

Instantly share code, notes, and snippets.

@Sir-Photch
Forked from fpaupier/gpumeter.sh
Last active October 24, 2024 13:31
Show Gist options
  • Save Sir-Photch/1c155978776dfdd2afa08aa867230aee to your computer and use it in GitHub Desktop.
Save Sir-Photch/1c155978776dfdd2afa08aa867230aee to your computer and use it in GitHub Desktop.
Measure maximum VRAM consumption of a program on linux for Nvidia devices
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Usage: $0 executable [args...]"
exit 1
fi
# Start monitoring GPU memory usage in the background
nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -l 1 > gpu_usage.log &
PID=$!
# Execute the provided script
eval $@
# Kill the nvidia-smi monitoring process
kill $PID
# Calculate and display the max GPU memory usage
MAX_USAGE=$(awk '{ if(max < $1) { max=$1 } } END { print max }' gpu_usage.log)
echo "Maximum GPU VRAM usage: ${MAX_USAGE}MiB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment