查看GPU-ID
CMD输入:
nvidia-smi
观察到存在序号为0的GPU ID
观察到存在序号为0、1、2、3的GPU ID
在终端运行代码时指定GPU
如果电脑有多个GPU,Tensorflow默认全部使用。如果想只使用部分GPU,可以设置CUDA_VISIBLE_DEVICES
命令行输入:
# 指定采用1号GPU运行*.py CUDA_VISIBLE_DEVICES=1 python *.py
Environment Variable Syntax Results CUDA_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 CUDA_VISIBLE_DEVICES="" No GPU will be visible