A simple Bash tool for managing GPU visibility in your shell environment by configuring CUDA_VISIBLE_DEVICES.
| Command | Description | Implementation |
|---|---|---|
setcuda any |
Enables all GPUs | Unsets CUDA_VISIBLE_DEVICES |
setcuda none |
Disables all GPUs | Sets CUDA_VISIBLE_DEVICES to an empty value |
setcuda <gpu_ids> |
Enables specified GPU(s) | Sets CUDA_VISIBLE_DEVICES to gpu_ids after validation |
When all GPUs are enabled:
[cuda:any] user@host:~$
When no GPUs are enabled:
[cuda:none] user@host:~$
When GPU 0 is enabled:
[cuda:0] user@host:~$
When GPUs 0 and 2 are enabled:
[cuda:0,2] user@host:~$
-
Download
setcuda.shto your preferred directory (e.g.,~/.local/bin/setcuda.sh). -
Append the following line to your
~/.bashrc:source /path/to/setcuda.sh