Python 2.7 tensorflow异常CUDA相关错误

Python 2.7 tensorflow异常CUDA相关错误,python-2.7,tensorflow,cuda,gpu,Python 2.7,Tensorflow,Cuda,Gpu,我已经使用tensorflow将近两年了,从来没有见过这个。在一个新的Ubuntu设备上,我在virtualenv中安装了tensorflow。当我运行一个示例代码时,我得到了一个无效的设备错误。调用tf.Session()时发生 WARNING:tensorflow:From full_code.py:27: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be rem

我已经使用tensorflow将近两年了,从来没有见过这个。在一个新的Ubuntu设备上,我在virtualenv中安装了tensorflow。当我运行一个示例代码时,我得到了一个无效的设备错误。调用
tf.Session()
时发生

WARNING:tensorflow:From full_code.py:27: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:
Use `tf.global_variables_initializer` instead.
2017-06-05 11:01:55.853842: 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.
2017-06-05 11:01:55.853867: 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.
2017-06-05 11:01:55.853876: 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.
2017-06-05 11:01:55.853886: 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.
2017-06-05 11:01:55.853893: 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.
2017-06-05 11:01:55.937978: I tensorflow/core/common_runtime/gpu/gpu_device.cc:887] Found device 0 with properties: 
name: GeForce GTX 660 Ti
major: 3 minor: 0 memoryClockRate (GHz) 1.0455
pciBusID 0000:04:00.0
Total memory: 2.95GiB
Free memory: 2.91GiB
2017-06-05 11:01:55.938063: W tensorflow/stream_executor/cuda/cuda_driver.cc:485] creating context when one is currently active; existing: 0x19e5370
2017-06-05 11:01:56.014220: E tensorflow/core/common_runtime/direct_session.cc:137] Internal: failed initializing StreamExecutor for CUDA device ordinal 1: Internal: failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_INVALID_DEVICE
这是完整的规格

Ubuntu 14.04
CUDA 8.0
GeForce GTX 660 Ti 
python 3.4.3

多亏了谷歌的人,我才知道出了什么问题。在此Dell机箱中,有两个Nvidia图形卡。第一个是制造商提供的NVS 310卡。据我所知,这一个没有任何计算能力,我从来没有打算使用它的很多

然后我添加了第二张卡,GTX 660 Ti,我打算在所有计算中使用这张卡

调用Tensorflow时,默认为设备0,即NVS 310。当然,它会抛出一个无效的错误

当我这样做的时候

CUDA_VISIBLE_DEVICES=1 python myscript.py


它可以工作。

您验证CUDA安装了吗?@RobertCrovella不确定如何验证?请检查CUDA Linux安装guide@RobertCrovella在样本中运行nbody,结果正常。nvcc被找到。@horaceT:但是如果您运行了Nbody示例,那么您的CUDA安装工作正常,所以这不是CUDA的问题,而是Tensorflow配置的问题,所以解决方案涉及到一个硬件细节,您在问题中完全忽略了它?@talonmies完全是我的错。我对CUDA在存在多个GPU的情况下的行为有了更多的发现。