diff options
author | Patrick Simianer <pks@pks.rocks> | 2019-09-03 22:15:54 +0200 |
---|---|---|
committer | Patrick Simianer <pks@pks.rocks> | 2019-09-03 22:15:54 +0200 |
commit | 211602a2bf5a73f68aa59b5033514f6ad59dca22 (patch) | |
tree | 0b3f71979f21c6b1e25695701556fd007de19c25 /free-gpu | |
parent | 412f9c3c86461ad937cbdddd590ceec590f281d0 (diff) |
free-gpu script
Diffstat (limited to 'free-gpu')
-rwxr-xr-x | free-gpu | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/free-gpu b/free-gpu new file mode 100755 index 0000000..3df48e9 --- /dev/null +++ b/free-gpu @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +export n_gpus=`lspci | grep -i "controller: nvidia" | wc -l` + +if [ $n_gpus -eq 0 ]; then + echo "-1" + exit -1 +fi + +if [[ -x $(which nvidia-smi) ]]; then + f_gpu=`nvidia-smi | sed -e '1,/Processes/d' \ + | tail -n+3 | head -n-1 | awk '{print $2}'\ + | awk -v ng=$n_gpus 'BEGIN{for (n=0;n<ng;++n){g[n] = 1}} {delete g[$1];} END{for (i in g) print i}' \ + | shuf -n 1 ` +fi + +if [ `echo $f_gpu | grep -v '^$' | wc -l` -eq 0 ]; then + echo "-1" + exit -1 +else + echo $f_gpu +fi + |