TensorFlow:如何验证它是否在GPU上运行

时间:2017-03-01 09:07:34

标签: tensorflow gpu cudnn

我正在寻找一种简单的方法来验证我的TF图表是否实际在GPU上运行。

PS。验证是否使用了cuDNN库也很好。

3 个答案:

答案 0 :(得分:9)

有多种方法可以查看操作位置。

  1. 将RunOptions和RunMetadata添加到会话调用中,并在Tensorboard中查看操作和计算的位置。请参阅此处的代码:https://www.tensorflow.org/get_started/graph_viz

  2. 在会话ConfigProto中指定log_device_placement选项。这会记录到控制放置操作的设备。 https://www.tensorflow.org/api_docs/python/tf/ConfigProto

  3. 使用nvidia-smi查看终端中的GPU使用情况。

答案 1 :(得分:5)

在Python中导入TF时

import tensorflow as tf

您将获得表明CUDA库使用情况的这些日志

I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally

此外,当您在Config Proto中构建图形并使用log_device_placement运行会话时,您将获得这些日志(显示它找到了GPU设备):

I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:910] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: 
name: GeForce GTX 1060 6GB
major: 6 minor: 1 memoryClockRate (GHz) 1.759
pciBusID 0000:01:00.0
Total memory: 5.93GiB
Free memory: 4.94GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0)

答案 2 :(得分:0)

有一个相关的TensorFlow upstream issue。基本上它表示Python API尚未公开此类信息。

然而,C ++ API确实如此。例如。有tensorflow::KernelsRegisteredForOp()。我围绕它编写了一个小的Python包装器,然后实现了supported_devices_for_op here(在this commit中)。