Created
February 13, 2024 06:32
-
-
Save fpaupier/fca66c518ed6b9ac47ede2a8a1211adb to your computer and use it in GitHub Desktop.
Measure maximum VRAM consumption of a program on linux for Nvidia devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage ./gpumeter.sh my-gpu-hungry-script.sh | |
# Check if the command argument is provided | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 <script_to_run>" | |
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 | |
./$1 | |
# 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