From 211602a2bf5a73f68aa59b5033514f6ad59dca22 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Tue, 3 Sep 2019 22:15:54 +0200 Subject: free-gpu script --- free-gpu | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 free-gpu (limited to 'free-gpu') 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