Skip to content

Instantly share code, notes, and snippets.

@selwynsimsek
Created October 4, 2017 13:35
Show Gist options
  • Save selwynsimsek/b38c60a9b5782ba34f628f600bc4fbc2 to your computer and use it in GitHub Desktop.
Save selwynsimsek/b38c60a9b5782ba34f628f600bc4fbc2 to your computer and use it in GitHub Desktop.
Sets CUDA_VISIBLE_DEVICES to be the ID of the GPU with the most free memory.
#!/bin/bash
# Sets CUDA_VISIBLE_DEVICES to be the ID of the GPU with the most free memory, via text munging of nvidia-smi output.
#
# Usage: set-cvd.sh ./cudaexec sets CUDA_VISIBLE_DEVICES and runs cudaexec.
#
#
export CUDA_VISIBLE_DEVICES=$(nvidia-smi | grep % | awk '{print $9 }' | tr -d MiB | nl | sort -k2 -n | head -1 | awk '{print $1 -1}')
$*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment