TensorFlow(不是TensorFlow-GPU):调用cuInit时失败:未知错误(303)。

14

我的测试

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()

我的错误

2019-12-27 10:51:17.887009: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/openmpi/lib:
2019-12-27 10:51:17.888489: E tensorflow/stream_executor/cuda/cuda_driver.cc:318] failed call to cuInit: UNKNOWN ERROR (303)
2019-12-27 10:51:17.888992: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (3e7d899714a9): /proc/driver/nvidia/version does not exist
2019-12-27 10:51:17.890608: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-12-27 10:51:17.915554: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2904000000 Hz
2019-12-27 10:51:17.918061: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x56101fca67e0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2019-12-27 10:51:17.918228: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version

我的环境

Ubuntu 18

TensorFlow 1.15.0/1.14.0

我的问题

我已经查看了类似的问题,例如TensorFlow: failed call to cuInit: CUDA_ERROR_NO_DEVICE

关键的区别在于我没有安装 tensorflow-gpu 包。为什么普通的 TensorFlow 会出现这个错误?


我在Windows上使用tensorflow:1.15.0 Docker镜像时,收到了与此处相同的消息。 - xdhmoore
3个回答

15

如果您使用仅限于CPU的机器,可以尝试使用tensorflow-cpu软件包来解决此问题,而不是使用tensorflow

pip uninstall tensorflow
pip install tensorflow-cpu

1
有什么缺点吗? - Jitin
2
@Jitin 嗯,唯一明显的缺点是如果您正在使用某种自动化部署模型跨GPU和非GPU机器,则没有一致的软件包要求。否则,如果您不使用tensorflow的GPU功能,则我认为没有任何缺点。 - dsalaj

1
安装nvidia-modprobe可以解决这个问题。
sudo apt install nvidia-modprobe

您可以尝试的其他解决方案包括:

  • 卸载并安装CUDA和cuDNN。
  • 安装tensorflow-gpu。
  • 卸载并安装不同版本的Nvidia驱动程序。

问题也可能是在使用sudo运行Python之前,只有一些/dev/nvidia*文件存在,请使用$ ls /dev/nvidia*进行检查,在运行设备节点验证脚本后,会添加/dev/nvidia-uvm文件。


0

我在Windows操作系统上遇到了同样的问题。我按照tensorflow的指示安装了CUDA、cudnn等,并尝试了上面答案中的建议,但都没有成功。

解决我的问题的方法是更新GPU驱动程序。您可以通过以下方式更新它们:

  1. 按下Windows键+R
  2. 输入devmgmt.msc
  3. 右键单击“显示适配器”,然后单击“属性”选项
  4. 转到“驱动程序”选项卡,选择“更新驱动程序”。
  5. 最后,单击“自动搜索更新的驱动程序软件”
  6. 重新启动计算机,然后再次运行以下检查:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()

Sample output:
2022-01-17 14:01:54.999571: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: GeForce 940MX major: 5 minor: 0 memoryClockRate(GHz): 1.189
pciBusID: 0000:01:00.0
2022-01-17 14:01:54.999820: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2022-01-17 14:01:55.000888: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2022-01-17 14:01:55.006480: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: GeForce 940MX major: 5 minor: 0 memoryClockRate(GHz): 1.189
pciBusID: 0000:01:00.0
2022-01-17 14:01:55.006696: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2022-01-17 14:01:55.007744: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2022-01-17 14:01:55.008511: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-01-17 14:01:55.009162: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0
2022-01-17 14:01:55.009876: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N
2022-01-17 14:01:55.010857: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1391 MB memory) -> physical GPU (device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0)

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