首页 > 解决方案 > TensorFlow 不能使用 GPU。tf.test.is_gpu_available() 显示 GPU 但不能使用

问题描述

我有 Ubuntu 18.04。Python 3.7.3、张量流 2.0.0

这是我的 cuda 版本:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

我的电脑是UX430UQ,显卡是GeForce 940MX

这是 nvidia-smi 的输出:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.87.01    Driver Version: 418.87.01    CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce 940MX       On   | 00000000:01:00.0 Off |                  N/A |
| N/A   45C    P0    N/A /  N/A |    283MiB /  2004MiB |      9%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1014      G   /usr/lib/xorg/Xorg                            24MiB |
|    0      1164      G   /usr/bin/gnome-shell                          47MiB |
|    0      1440      G   /usr/lib/xorg/Xorg                           123MiB |
|    0      1615      G   /usr/bin/gnome-shell                          84MiB |
+-----------------------------------------------------------------------------+

这是我时的输出run sudo apt-get install cuda

Reading package lists...
Building dependency tree...
Reading state information...
cuda is already the newest version (10.1.243-1).
0 upgraded, 0 newly installed, 0 to remove and 138 not upgraded.

这是我运行时的输出tf.test.is_gpu_available()

2019-10-08 21:04:37.186069: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1006] 从 SysFS 读取的成功 NUMA 节点具有负值 (-1),但必须至少有一个 NUMA 节点,所以返回NUMA 节点零

2019-10-08 21:04:37.188434:我 tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] 找到具有以下属性的设备 0:

名称:GeForce 940MX 主要:5 次要:0 memoryClockRate(GHz):1.2415

pciBusID: 0000:01:00.0

2019-10-08 21:04:37.188863:W tensorflow/stream_executor/platform/default/dso_loader.cc:55] 无法加载动态库“libcudart.so.10.0”;dlerror:libcudart.so.10.0:无法打开共享对象文件:没有这样的文件或目录;LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64

2019-10-08 21:04:37.189156:W tensorflow/stream_executor/platform/default/dso_loader.cc:55] 无法加载动态库“libcublas.so.10.0”;dlerror:libcublas.so.10.0:无法打开共享对象文件:没有这样的文件或目录;LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64

2019-10-08 21:04:37.189426:W tensorflow/stream_executor/platform/default/dso_loader.cc:55] 无法加载动态库“libcufft.so.10.0”;dlerror:libcufft.so.10.0:无法打开共享对象文件:没有这样的文件或目录;LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64

2019-10-08 21:04:37.189687:W tensorflow/stream_executor/platform/default/dso_loader.cc:55] 无法加载动态库“libcurand.so.10.0”;dlerror:libcurand.so.10.0:无法打开共享对象文件:没有这样的文件或目录;LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64

2019-10-08 21:04:37.189946:W tensorflow/stream_executor/platform/default/dso_loader.cc:55] 无法加载动态库“libcusolver.so.10.0”;dlerror:libcusolver.so.10.0:无法打开共享对象文件:没有这样的文件或目录;LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64

2019-10-08 21:04:37.190202:W tensorflow/stream_executor/platform/default/dso_loader.cc:55] 无法加载动态库“libcusparse.so.10.0”;dlerror:libcusparse.so.10.0:无法打开共享对象文件:没有这样的文件或目录;LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64

2019-10-08 21:04:37.190236: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] 成功打开动态库 libcudnn.so.7

2019-10-08 21:04:37.190244: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1641] 无法打开某些 GPU 库。如果您想使用 GPU,请确保正确安装了上述缺少的库。按照https://www.tensorflow.org/install/gpu上的指南,了解如何为您的平台下载和设置所需的库。

跳过注册 GPU 设备...

2019-10-08 21:04:37.190261: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] 设备互连 StreamExecutor 与强度 1 边缘矩阵:

2019-10-08 21:04:37.190268: 我 tensorflow/core/common_runtime/gpu/gpu_device.cc:1165] 0

2019-10-08 21:04:37.190276: 我 tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0: N

标签: pythontensorflow2.0

解决方案


你应该使用 cuda10 和 cudnn7.4 参考这个网站


推荐阅读