@@ -18,8 +18,8 @@ if [ "$1" == "--num-gpus" ]; then
1818 shift
1919fi
2020
21- if ! printf " %d" " $num_gpus " > /dev/null || [ $num_gpus -le 0 ]; then
22- echo $0 : Must pass a positive interger after --num-gpus
21+ if ! printf " %d" " $num_gpus " > /dev/null || [ $num_gpus -le -1 ]; then
22+ echo $0 : Must pass a positive interger or 0 after --num-gpus
2323 echo e.g. $0 --num-gpus 2 local/tfrnnlm/run_lstm.sh
2424 exit 1
2525fi
@@ -35,18 +35,24 @@ CUDA_VISIBLE_DEVICES=
3535num_total_gpus=` nvidia-smi -L | wc -l`
3636num_gpus_assigned=0
3737
38- for i in ` seq 0 $[$num_total_gpus -1]` ; do
39- # going over all GPUs and check if it is idle, and add to the list if yes
40- if nvidia-smi -i $i | grep " No running processes found" > /dev/null; then
41- CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES} $i , && num_gpus_assigned=$[$num_gpus_assigned +1]
42- fi
43- # once we have enough GPUs, break out of the loop
44- [ $num_gpus_assigned -eq $num_gpus ] && break
45- done
38+ if [ $num_gpus -eq 0 ] ; then
39+ echo " $0 : Running the job on CPU. Disabling submitting to gpu"
40+ export CUDA_VISIBLE_DEVICES=" "
41+ else
42+ for i in ` seq 0 $[$num_total_gpus -1]` ; do
43+ # going over all GPUs and check if it is idle, and add to the list if yes
44+ if nvidia-smi -i $i | grep " No running processes found" > /dev/null; then
45+ CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES} $i , && num_gpus_assigned=$[$num_gpus_assigned +1]
46+ fi
47+ # once we have enough GPUs, break out of the loop
48+ [ $num_gpus_assigned -eq $num_gpus ] && break
49+ done
4650
47- [ $num_gpus_assigned -ne $num_gpus ] && echo Could not find enough idle GPUs && exit 1
51+ [ $num_gpus_assigned -ne $num_gpus ] && echo Could not find enough idle GPUs && exit 1
4852
49- export CUDA_VISIBLE_DEVICES=$( echo $CUDA_VISIBLE_DEVICES | sed " s=,$==g" )
53+ export CUDA_VISIBLE_DEVICES=$( echo $CUDA_VISIBLE_DEVICES | sed " s=,$==g" )
54+
55+ echo " $0 : Running the job on GPU(s) $CUDA_VISIBLE_DEVICES "
56+ fi
5057
51- echo " $0 : Running the job on GPU(s) $CUDA_VISIBLE_DEVICES "
5258" $@ "
0 commit comments