如何判断tensorflow是否使用了cuda和cudnn?

9

我正在使用Ubuntu 16.04。以下是TensorFlow信息:

>>> pip show tensorflow-gpu
pip show tensorflow-gpu
Name: tensorflow-gpu
Version: 1.2.0
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /home/xxxx/anaconda3/envs/tensorflow/lib/python3.5/site-packages
Requires: markdown, backports.weakref, wheel, bleach, html5lib, protobuf, numpy, six, werkzeug

关于 CUDA 的信息:

nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2015 NVIDIA Corporation
Built on Tue_Aug_11_14:27:32_CDT_2015
Cuda compilation tools, release 7.5, V7.5.17

当我在Ubuntu终端从Python中导入tensorflow时,如下图所示,我没有得到任何加载信息。
>>> import tensorflow
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally

如果我在终端中运行Python程序,就会得到不同的信息。

2017-06-20 16:08:18.075709: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-20 16:08:18.075733: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-20 16:08:18.075740: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-06-20 16:08:18.075744: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-20 16:08:18.075750: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2017-06-20 16:08:18.260629: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:893] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2017-06-20 16:08:18.261462: I tensorflow/core/common_runtime/gpu/gpu_device.cc:940] Found device 0 with properties: 
name: Quadro K620M
major: 5 minor: 0 memoryClockRate (GHz) 1.124
pciBusID 0000:08:00.0
Total memory: 1.96GiB
Free memory: 1.58GiB
2017-06-20 16:08:18.261514: I tensorflow/core/common_runtime/gpu/gpu_device.cc:961] DMA: 0 
2017-06-20 16:08:18.261524: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0:   Y 
2017-06-20 16:08:18.261550: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Quadro K620M, pci bus id: 0000:08:00.0)
2

我如何知道tensorflow是否正在使用cuda和cudnn?还需要提供哪些其他信息?

在终端中输入import tensorflow会做什么?sys.implementationsys.executable是您要寻找的内容吗? - Artyer
1
抱歉,我的错。我在终端中使用Python运行了“import tensorflow”。我正在测试tensorflow是否使用cuda或cudnn。 - AZ2016
有关TensorFlow 1.2,请参见此问题 - HelloGoodbye
@HelloGoodbye,感谢提供链接。 - AZ2016
@AZ2016,你能解决这个问题吗?我也遇到了同样的情况。 - Kenan
@ksooklall,不是的。希望他们能在Tensorflow 1.3中修复这个问题。 - AZ2016
2个回答

1

您可以使用nvidia-smi检查GPU是否由Python/TensorFlow进程使用。如果没有进程使用GPU,则TensorFlow不会使用CUDA和CUDNN。


0

在Windows上有一个类似的问题 - 想要查看GPU的使用情况,但不知道如何安装smi实用程序。

我发现最令人信服的方法是运行教程来检查它是否正在使用CPU:

https://www.tensorflow.org/tutorials/layers

需要进行的主要更改如下:

# Create the Estimator
config = tf.ConfigProto(log_device_placement=True)
config.gpu_options.allow_growth = True
run_config = tf.estimator.RunConfig().replace(
    session_config=config)

mnist_classifier = tf.estimator.Estimator(
  model_fn=cnn_model_fn, model_dir="./mnist_convnet_model2",
  config = run_config)

日志显示了操作放在哪里 - GPU:0(您应该在控制台中看到此内容)

allow_growth通过立即分配所有内存来防止CUDA在我的机器上崩溃。花了相当长的时间才找到如何将其应用于估算器 - 我觉得文档对新用户来说可能需要改进!

一旦我让它运行起来,不仅与仅使用CPU版本相比速度非常快,而且我可以在任务管理器中看到GPU使用率达到70-80%!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接