Merge pull request #58 from jaywonchung/better-gpu-usage

Support multi-gpu environment
This commit is contained in:
Ethan Edwards 2020-09-03 15:11:04 -04:00 committed by GitHub
commit 7f8bb35543
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,7 +16,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
;; ;;
@ -32,10 +32,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()
{ {
@ -47,5 +49,3 @@ main()
} }
# run the main driver # run the main driver
main main