From 14ad891d3dda829675898ef096ae6aa4c0616c5b Mon Sep 17 00:00:00 2001 From: Jaewon Chung Date: Fri, 7 Aug 2020 00:56:00 +0900 Subject: [PATCH] Support multi-gpu environment --- scripts/gpu_usage.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/gpu_usage.sh b/scripts/gpu_usage.sh index 3bb1445..f59e306 100755 --- a/scripts/gpu_usage.sh +++ b/scripts/gpu_usage.sh @@ -4,7 +4,7 @@ get_platform() { case $(uname -s) in Linux) - gpu=$(lspci -v | grep -i gpu | grep driver | awk '{print $5}') + gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}') echo $gpu ;; @@ -20,10 +20,12 @@ get_platform() get_gpu() { gpu=$(get_platform) - if [ $gpu == nvidia-gpu ]; then - usage=$(nvidia-smi | grep "%" | awk '{print $13}') - echo $usage + if [[ "$gpu" == NVIDIA ]]; then + usage=$(nvidia-smi | grep '%' | awk '{ sum += $13 } END { printf("%d%%\n", sum / NR) }') + else + usage='unknown' fi + echo $usage } main() { @@ -33,5 +35,3 @@ main() } # run the main driver main - -