安装Tensorflow-GPU及其所有要求(即CUDA和cuDNN)后,我尝试在Pycharm下运行具有GPU支持的Tensorflow 。
当我在Pycharm下运行一个简单程序时,session.run 引发异常。
self._session = tf_session.TF_NewSessionRef(self._graph._c_graph, opts)
tensorflow.python.framework.errors_impl.InternalError: cudaGetDevice() failed. Status: CUDA driver version is insufficient for CUDA runtime version
重要提示:我相信问题来自 Pycharm和/或其配置,因为在终端机中运行相同的简单程序不会抛出异常< / strong>。
如何摆脱此异常并使Pycharm环境按Tensorflow的预期运行?
import tensorflow as tf
def main():
# define the graph
a = tf.constant(1.0)
b = tf.constant(1.0)
c = tf.constant(4.0)
d = tf.div(tf.add(a, b), c)
# execute the graph
with tf.Session() as session:
print(session.run(d)) # 0.5
if __name__ == '__main__':
print("tensorflow version : " + tf.__version__)
main()
(tf_env) usr@WHATEVER ~/Documents/Repos/tftest/tftest $ python intro.py
tensorflow version : 1.12.0
2018-12-05 10:56:09.888809: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:964] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-12-05 10:56:09.889285: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties:
name: GeForce GTX 1070 major: 6 minor: 1 memoryClockRate(GHz): 1.7465
pciBusID: 0000:01:00.0
totalMemory: 7.92GiB freeMemory: 7.52GiB
2018-12-05 10:56:09.889304: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2018-12-05 10:56:10.126095: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-12-05 10:56:10.126135: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0
2018-12-05 10:56:10.126142: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N
2018-12-05 10:56:10.126366: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7252 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)
0.5
我不认为问题出在我的硬件/安装上,而是Pycharm,但这是您所需要(或不需要)了解的全部信息
我在名为tf_env
的 conda虚拟环境中安装了Tensorflow。
GPU :NVIDIA GTX GeForce 1070(功能6.1)
GPU驱动程序:384.130
Linux :16.04
Tensorflow :1.12.0
CUDA工具包:9.0.176
cuDNN :7.4.1.5
Gabriel Alhrishy的法定人数答案可能会有所帮助:https://www.quora.com/How-does-one-install-TensorFlow-to-use-with-PyCharm
但是我尝试将/ usr / local / cuda / bin /添加到无法正常工作的根目录中,而且我不知道他对cuDNN / bin /的含义,因为我不知道该目录是否存在。尚不清楚我是否有相同的问题。
答案 0 :(得分:0)
问题实际上是由于混淆了conda环境。我在Pycharm上运行了另一个具有类似名称的conda环境,但安装了不同的Tensorflow(来自conda,不是pip)。
放回正确的conda env即可完成工作。