可设置环境变量CUDA_VISIBLE_DEVICES,指明可见的cuda设备
方法1: 在/etc/profile或~/.bashrc的配置文件中配置环境变量(/etc/profile影响所有用户,~/.bashrc影响当前用户使用的bash shell)
在/etc/profile文件末尾添加以下行:
export CUDA_VISIBLE_DEVICES=0,1 ##仅显卡设备0,1GPU可见。可用的GPU可通过nvidia-smi -L命令查看
:wq保存并退出
source /etc/profile使配置文件生效
方法2:若上述配置无效,可在执行cuda程序时指明参数,如
CUDA_VISIBLE_DEVICES=0,1 ./cuda_executable
另附上一些参考文章:http://acceleware.com/blog/cudavisibledevices-masking-gpus
http://stackoverflow.com/questions/39649102/how-do-i-select-which-gpu-to-run-a-job-on
Environment Variable Syntax ResultsCUDA_VISIBLE_DEVICES=1 Only device 1 will be seen
CUDA_VISIBLE_DEVICES=0,1 Devices 0 and 1 will be visible
CUDA_VISIBLE_DEVICES=”0,1” Same as above, quotation marks are optional
CUDA_VISIBLE_DEVICES=0,2,3 Devices 0, 2, 3 will be visible; device 1 is masked