Support multi-gpu environment

This commit is contained in:
Jaewon Chung 2020-08-07 00:56:00 +09:00
parent 60c2017fb0
commit 14ad891d3d

View file

@ -4,7 +4,7 @@ get_platform()
{ {
case $(uname -s) in case $(uname -s) in
Linux) 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 echo $gpu
;; ;;
@ -20,10 +20,12 @@ get_platform()
get_gpu() get_gpu()
{ {
gpu=$(get_platform) gpu=$(get_platform)
if [ $gpu == nvidia-gpu ]; then if [[ "$gpu" == NVIDIA ]]; then
usage=$(nvidia-smi | grep "%" | awk '{print $13}') usage=$(nvidia-smi | grep '%' | awk '{ sum += $13 } END { printf("%d%%\n", sum / NR) }')
echo $usage else
usage='unknown'
fi fi
echo $usage
} }
main() main()
{ {
@ -33,5 +35,3 @@ main()
} }
# run the main driver # run the main driver
main main