-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpu-status.sh
31 lines (24 loc) · 1.1 KB
/
gpu-status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
function show_gpu_user {
pid=$(pstree -sg $1 | grep -Eo 'bash\([0-9]*\)' | head -1 | grep -Eo '[0-9]*');
docker ps -q | xargs docker inspect --format "{{.Name}} {{.State.Pid}}" | grep $pid | awk '{printf "%-24s", $1}';
ps aux | grep $1 | grep -v grep | awk '{ for(i=1;i<=NF;i++) {if ( i >= 11 ) printf $i" "}; printf "\n" }';
}
echo " ";
gpu_status=$(nvidia-smi --query-compute-apps=gpu_serial,pid --format=csv,noheader);
busy_gpu=$(nvidia-smi --query-compute-apps=gpu_serial,pid --format=csv,noheader | awk "{print $1}" |sort -u | wc -l);
echo "Total GPUs: 8";
echo "Tasks on GPU: $busy_gpu";
echo " ";
if [[ $(docker ps -q) ]]; then
echo -e "GPU_serial\tPorcess_id\tContainer_name\t\tProcess_name";
echo "======================================================================================";
while read -r line; do
process=$(echo $line | awk '{print $2}');
echo -en "$line\t\t" | sed 's/,\s/\t/';
show_gpu_user $process;
done <<< "$gpu_status"
else
echo "No process found."
fi
echo " ";