Python TensorFlow从多个GPU中选择要使用的GPU

Python TensorFlow从多个GPU中选择要使用的GPU,python,cuda,tensorflow,gpu,Python,Cuda,Tensorflow,Gpu,我是TensorFlow的新手,已经按照TensorFlow网站上的说明安装了CUDA-7.5和cudnn-v4。调整TensorFlow配置文件并尝试从网站运行以下示例后: python -m tensorflow.models.image.mnist.convolutional 我非常确定TensorFlow使用的是其中一个GPU,而不是另一个,不过,我希望它使用更快的GPU。我想知道这个示例代码是否默认使用它找到的第一个GPU。如果是这样,我如何选择在python的TensorFlow代

我是TensorFlow的新手,已经按照TensorFlow网站上的说明安装了CUDA-7.5和cudnn-v4。调整TensorFlow配置文件并尝试从网站运行以下示例后:

python -m tensorflow.models.image.mnist.convolutional
我非常确定TensorFlow使用的是其中一个GPU,而不是另一个,不过,我希望它使用更快的GPU。我想知道这个示例代码是否默认使用它找到的第一个GPU。如果是这样,我如何选择在python的TensorFlow代码中使用哪个GPU

运行示例代码时收到的消息如下:

ldt-tesla:~$ python -m tensorflow.models.image.mnist.convolutional
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties:
name: Tesla K20c
major: 3 minor: 5 memoryClockRate (GHz) 0.7055
pciBusID 0000:03:00.0
Total memory: 4.63GiB
Free memory: 4.57GiB
W tensorflow/stream_executor/cuda/cuda_driver.cc:572] creating context when one is currently active; existing: 0x2f27390
I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 1 with properties:
name: Quadro K2200
major: 5 minor: 0 memoryClockRate (GHz) 1.124
pciBusID 0000:02:00.0
Total memory: 3.95GiB
Free memory: 3.62GiB
I tensorflow/core/common_runtime/gpu/gpu_init.cc:59] cannot enable peer access from device ordinal 0 to device ordinal 1
I tensorflow/core/common_runtime/gpu/gpu_init.cc:59] cannot enable peer access from device ordinal 1 to device ordinal 0
I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 1
I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0:   Y N
I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 1:   N Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:806] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Tesla K20c, pci bus id: 0000:03:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:793] Ignoring gpu device (device: 1, name: Quadro K2200, pci bus id: 0000:02:00.0) with Cuda multiprocessor count: 5. The minimum required count is 8. You can adjust this requirement with the env var TF_MIN_GPU_MULTIPROCESSOR_COUNT.
Initialized!

您可以将
CUDA\u VISIBLE\u设备
环境变量设置为仅公开您想要的设备,引用以下示例:


您可以在运行时设置要在哪个GPU上运行程序,而不是将其硬编码到脚本中。这将防止在没有多个GPU或没有太多GPU的设备上运行时出现问题

假设您想在GPU#3上运行,您可以这样做:

CUDA_VISIBLE_DEVICES=3, python -m tensorflow.models.image.mnist.convolutional

谢谢这似乎完成了任务并消除了错误:)。我还收到一条消息,上面说“忽略cuda多处理器计数为5的gpu设备。所需的最小计数为8。您可以使用…”调整此要求。按照您的建议,我可以使用环境变量来更改计数,但我不确定这意味着什么。计数/最小计数是什么意思?非常感谢。其他选择-
CUDA_VISIBLE_DEVICES=3, python -m tensorflow.models.image.mnist.convolutional