Tensorflow 未在 jupyter 笔记本中的 GPU 上运行

2024-02-13

在Ubuntu上成功为GTX 1080 ti安装了Cuda和cudnn,在jupyter笔记本中运行一个简单的TF程序,在运行tensorflow-gpu==1.0与tensorflow==1.0的conda环境中速度没有增加。

当我运行 nvidia-smi 时:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 375.66 Driver Version: 375.66 |
|-------------------------------+----------------------+----------------------+
| 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 GTX 108... Off | 0000:01:00.0 On | N/A |
| 24% 45C P0 62W / 250W | 537MiB / 11171MiB | 0% Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1101 G /usr/lib/xorg/Xorg 310MiB |
| 0 1877 G compiz 219MiB |
| 0 3184 G /usr/lib/firefox/firefox 5MiB |
+-----------------------------------------------------------------------------+

我尝试将“with tf.device("/gpu:0"):”放在矩阵乘法前面,但它只是给了我一个错误:

“InvalidArgumentError(请参阅上面的回溯):无法将设备分配给节点“MatMul”:无法满足显式设备规范“/device:GPU:0”,因为在此过程中没有注册与该规范匹配的设备;可用设备:/job :本地主机/副本:0/任务:0/cpu:0 [[节点:MatMul = MatMul[T=DT_FLOAT,transpose_a=false,transpose_b=false,_device="/device:GPU:0"](重塑,softmax/变量/读取)]]"

我知道 cudnn 已正确安装,因为我在终端中运行它时收到此消息。

import tensorflow as tf
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

我想这一定是Jupiter笔记本的问题,有兼容性问题吗?当我运行 TF 会话时,我得到以下输出:

W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
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.
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.
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.
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.
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.
Device mapping: no known devices.

"""


我解决了这个问题。显然我在我的环境之外安装了 jupyter 和常规张量流。然而我在我的环境中安装了tensorflow-gpu。因此,当我运行 jupyter 时,它调用的是环境外部的tensorflow,而不是环境中安装的tensorflow-gpu。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Tensorflow 未在 jupyter 笔记本中的 GPU 上运行 的相关文章

随机推荐