【发布时间】:2017-07-06 04:31:41
【问题描述】:
我有两台没有 CUDA 的计算机:一台在 Microsoft Windows 上运行,另一台在 Linux 上运行(Ubuntu 14.04 64bit / Linux 3.13.0-100-generic))
我可以在 Microsoft Windows 上使用没有 CUDA 的 TensorFlow,没有任何问题:TensorFlow 使用 CPU。但是,如果在 Linux 机器上我在 python import tensorflow as tf 中运行,则由于未安装 CUDA,TensorFlow 无法导入:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 72, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 61, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
如何在 Linux 上使用没有 CUDA 的 TensorFlow?
我使用tensorflow-gpu==1.0.0。
我知道tensorflow.ConfigProto 中的参数device_count 允许禁用GPU,例如:
import tensorflow as tf
a = tf.constant(1, name = 'a')
b = tf.constant(3, name = 'b')
c = tf.constant(9, name = 'c')
d = tf.add(a, b, name='d')
e = tf.add(d, c, name='e')
config = tf.ConfigProto(device_count={'CPU': 1, 'GPU': 0})
sess = tf.Session(config=config)
print(sess.run([d, e]))
但这无济于事,因为import tensorflow as tf 是问题所在。
我也知道如何安装 CUDA 8:
# Install Nvidia drivers, CUDA and CUDA toolkit, following some instructions from http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64-deb
sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64-deb
sudo apt-get update
sudo apt-get install cuda
但宁愿在这两台机器上避免它。
【问题讨论】:
-
使用
tensorflow-gpu意味着您必须安装 CUDA 驱动程序,即使机器没有 GPU。如果没有 gpu 驱动程序,您必须使用编译为仅 CPU 的版本 -
在我们的舰队中,我们在 GPU 和非 GPU 机器上都安装了 GPU 驱动程序,以便能够使用相同的 TF 二进制文件
-
@YaroslavBulatov 谢谢,我不知道
tensorflow-gpu需要 CUDA(我认为它可以选择使用 GPU)。这就解释了。很高兴知道可以在非 GPU 机器上安装 GPU 驱动程序,这确实有助于部署。 -
@YaroslavBulatov 如果您想在答案中总结您的 cmets,我相信它对其他人有用,我会投票赞成。
-
标签: python linux cuda tensorflow