Last active
August 21, 2022 09:32
-
-
Save georg-wolflein/d674dd31f391b3d2daf95522a0ade0e9 to your computer and use it in GitHub Desktop.
For each GPU, list used memory by process (and find associated docker container)
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 | |
for i in $(nvidia-smi --query-gpu=index --format=csv,noheader); do | |
echo GPU "#$i": $(nvidia-smi --query-gpu=memory.used --format=csv,noheader -i $i) used | |
while IFS="," read -r pid name used; do | |
pid_container_name= | |
for container in $(docker ps -q); do | |
if [[ $(docker top $container | awk '{print $2}'| grep $pid) ]]; then | |
pid_container_name=$(docker inspect $container --format '{{.Name}}') | |
fi | |
done | |
cmd=$(ps -p $pid -o cmd=) | |
if [ -z "$cmd" ]; then | |
cmd=$name | |
fi | |
if [[ $pid_container_name ]]; then | |
pid_container_name="in $pid_container_name" | |
fi | |
echo " " $used used by PID $pid $pid_container_name running $cmd | |
done < <(nvidia-smi --query-compute-apps=pid,process_name,used_gpu_memory -i $i --format=csv,noheader) | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment