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