Tensorflow-gpu Error: InvalidArgumentError: Cannot assign a device for operation 'MatMul'
Tensorflow-gpu Error: InvalidArgumentError: Cannot assign a device for operation 'MatMul'
我正在使用 tensorflow 网站上给出的测试代码在 anaconda 中使用 GPU 测试 tensorflow:
import tensorflow as tf
with tf.device('/device:GPU:0'):
a = tf.constant([1,2,3,4,5,6],shape=[2,3],name='a')
b = tf.constant([1,2,3,4,5,6],shape=[3,2],name='b')
c = tf.matmul(a,b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))
我创建了anaconda环境并使用pip install tensorflow-gpu
安装了tensorflow+gpu。 Ipython notebook 用于执行上面的代码并不断收到 error:
InvalidArgumentError: Cannot assign a device for operation 'MatMul': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.
[[Node: MatMul = MatMul[T=DT_INT32, transpose_a=false, transpose_b=false, _device="/device:GPU:0"](a, b)]]
MatMul
运算符似乎无法加载到 GPU 上。我不知道为什么没有支持 GPU 设备的内核,因为正确安装了 cuda 和 cudNN。否则,tensorflow 消息显示 gpu 已被识别:
name: GeForce GTX 1080 Ti
major: 6 minor: 1 memoryClockRate (GHz) 1.683
pciBusID 0000:02:00.0
Total memory: 10.91GiB
Free memory: 10.75GiB
2017-11-17 19:12:50.212054: W tensorflow/stream_executor/cuda/cuda_driver.cc:523] A non-primary context 0x55a56f0c2420 exists before initializing the StreamExecutor. We haven't verified StreamExecutor works with that.
2017-11-17 19:12:50.213035: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 1 with properties:
name: GeForce GTX 1080 Ti
major: 6 minor: 1 memoryClockRate (GHz) 1.683
pciBusID 0000:82:00.0
Total memory: 10.91GiB
Free memory: 10.75GiB
2017-11-17 19:12:50.213089: I tensorflow/core/common_runtime/gpu/gpu_device.cc:847] Peer access not supported between device ordinals 0 and 1
2017-11-17 19:12:50.213108: I tensorflow/core/common_runtime/gpu/gpu_device.cc:847] Peer access not supported between device ordinals 1 and 0
2017-11-17 19:12:50.213132: I tensorflow/core/common_runtime/gpu/gpu_device.cc:976] DMA: 0 1
2017-11-17 19:12:50.213148: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 0: Y N
2017-11-17 19:12:50.213156: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 1: N Y
2017-11-17 19:12:50.213169: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0)
2017-11-17 19:12:50.213179: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0)
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0
/job:localhost/replica:0/task:0/gpu:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0
2017-11-17 19:12:50.471348: I tensorflow/core/common_runtime/direct_session.cc:300] Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0
/job:localhost/replica:0/task:0/gpu:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0
有两个gpu,都遇到了同样的问题。 cuda 和 cudnn 库已正确安装,并在 anaconda 中设置了环境变量。 cuda 示例 (deviceQuery) 代码能够被编译并且 运行 没有错误并显示 result = pass
。否则,Matmul
可以加载到 CPU 上并完成计算。程序中的变量a
和b
能够加载到GPU设备上。给出了 tensorflow 消息:
2017-11-17 20:27:25.965655: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0)
2017-11-17 20:27:25.965665: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0)
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0
/job:localhost/replica:0/task:0/gpu:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0
2017-11-17 20:27:26.228395: I tensorflow/core/common_runtime/direct_session.cc:300] Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0
/job:localhost/replica:0/task:0/gpu:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0
MatMul: (MatMul): /job:localhost/replica:0/task:0/cpu:0
2017-11-17 20:27:26.229489: I tensorflow/core/common_runtime/simple_placer.cc:872] MatMul: (MatMul)/job:localhost/replica:0/task:0/cpu:0
b: (Const): /job:localhost/replica:0/task:0/gpu:0
2017-11-17 20:27:26.229512: I tensorflow/core/common_runtime/simple_placer.cc:872] b: (Const)/job:localhost/replica:0/task:0/gpu:0
a: (Const): /job:localhost/replica:0/task:0/gpu:0
2017-11-17 20:27:26.229526: I tensorflow/core/common_runtime/simple_placer.cc:872] a: (Const)/job:localhost/replica:0/task:0/gpu:0
重装nvidia驱动、cuda和anaconda好几次都没有解决这个问题。如果有任何建议,那就太好了。
- OS 平台和发行版:Linux Ubuntu 16.04
- TensorFlow 安装自:二进制
- TensorFlow 版本:1.3
- Python 版本: 2.7.14
- GCC/Compiler 版本(如果从源代码编译): 5.4.0
- NVIDIA 驱动程序:384.98
- CUDA/cuDNN版本:cuda 8.0/cuDNN 6.0
- GPU 型号和内存:Geforce 1080Ti
您正在尝试在 GPU 上对具有 tf.int32
(DT_INT32
) 数据类型的多个张量进行处理。错误消息是说不支持在 GPU 上乘以 DT_INT32
张量。
请注意,网站上的代码使用的是浮点张量 (tf.float32
)(假设您说的是 https://www.tensorflow.org/tutorials/using_gpu 中的代码)
变化中:
a = tf.constant([1,2,3,4,5,6],shape=[2,3],name='a')
至:
a = tf.constant([1.,2.,3.,4.,5.,6.],shape=[2,3],name='a')
或:
a = tf.constant([1,2,3,4,5,6],shape=[2,3],name='a',dtype=tf.float32)
同样地,对于 b
应该可以消除错误,因为肯定有内核支持 GPU 上 float32 张量的矩阵乘法。
希望对您有所帮助。
我正在使用 tensorflow 网站上给出的测试代码在 anaconda 中使用 GPU 测试 tensorflow:
import tensorflow as tf
with tf.device('/device:GPU:0'):
a = tf.constant([1,2,3,4,5,6],shape=[2,3],name='a')
b = tf.constant([1,2,3,4,5,6],shape=[3,2],name='b')
c = tf.matmul(a,b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))
我创建了anaconda环境并使用pip install tensorflow-gpu
安装了tensorflow+gpu。 Ipython notebook 用于执行上面的代码并不断收到 error:
InvalidArgumentError: Cannot assign a device for operation 'MatMul': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.
[[Node: MatMul = MatMul[T=DT_INT32, transpose_a=false, transpose_b=false, _device="/device:GPU:0"](a, b)]]
MatMul
运算符似乎无法加载到 GPU 上。我不知道为什么没有支持 GPU 设备的内核,因为正确安装了 cuda 和 cudNN。否则,tensorflow 消息显示 gpu 已被识别:
name: GeForce GTX 1080 Ti
major: 6 minor: 1 memoryClockRate (GHz) 1.683
pciBusID 0000:02:00.0
Total memory: 10.91GiB
Free memory: 10.75GiB
2017-11-17 19:12:50.212054: W tensorflow/stream_executor/cuda/cuda_driver.cc:523] A non-primary context 0x55a56f0c2420 exists before initializing the StreamExecutor. We haven't verified StreamExecutor works with that.
2017-11-17 19:12:50.213035: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 1 with properties:
name: GeForce GTX 1080 Ti
major: 6 minor: 1 memoryClockRate (GHz) 1.683
pciBusID 0000:82:00.0
Total memory: 10.91GiB
Free memory: 10.75GiB
2017-11-17 19:12:50.213089: I tensorflow/core/common_runtime/gpu/gpu_device.cc:847] Peer access not supported between device ordinals 0 and 1
2017-11-17 19:12:50.213108: I tensorflow/core/common_runtime/gpu/gpu_device.cc:847] Peer access not supported between device ordinals 1 and 0
2017-11-17 19:12:50.213132: I tensorflow/core/common_runtime/gpu/gpu_device.cc:976] DMA: 0 1
2017-11-17 19:12:50.213148: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 0: Y N
2017-11-17 19:12:50.213156: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 1: N Y
2017-11-17 19:12:50.213169: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0)
2017-11-17 19:12:50.213179: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0)
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0
/job:localhost/replica:0/task:0/gpu:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0
2017-11-17 19:12:50.471348: I tensorflow/core/common_runtime/direct_session.cc:300] Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0
/job:localhost/replica:0/task:0/gpu:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0
有两个gpu,都遇到了同样的问题。 cuda 和 cudnn 库已正确安装,并在 anaconda 中设置了环境变量。 cuda 示例 (deviceQuery) 代码能够被编译并且 运行 没有错误并显示 result = pass
。否则,Matmul
可以加载到 CPU 上并完成计算。程序中的变量a
和b
能够加载到GPU设备上。给出了 tensorflow 消息:
2017-11-17 20:27:25.965655: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0)
2017-11-17 20:27:25.965665: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0)
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0
/job:localhost/replica:0/task:0/gpu:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0
2017-11-17 20:27:26.228395: I tensorflow/core/common_runtime/direct_session.cc:300] Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0
/job:localhost/replica:0/task:0/gpu:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0
MatMul: (MatMul): /job:localhost/replica:0/task:0/cpu:0
2017-11-17 20:27:26.229489: I tensorflow/core/common_runtime/simple_placer.cc:872] MatMul: (MatMul)/job:localhost/replica:0/task:0/cpu:0
b: (Const): /job:localhost/replica:0/task:0/gpu:0
2017-11-17 20:27:26.229512: I tensorflow/core/common_runtime/simple_placer.cc:872] b: (Const)/job:localhost/replica:0/task:0/gpu:0
a: (Const): /job:localhost/replica:0/task:0/gpu:0
2017-11-17 20:27:26.229526: I tensorflow/core/common_runtime/simple_placer.cc:872] a: (Const)/job:localhost/replica:0/task:0/gpu:0
重装nvidia驱动、cuda和anaconda好几次都没有解决这个问题。如果有任何建议,那就太好了。
- OS 平台和发行版:Linux Ubuntu 16.04
- TensorFlow 安装自:二进制
- TensorFlow 版本:1.3
- Python 版本: 2.7.14
- GCC/Compiler 版本(如果从源代码编译): 5.4.0
- NVIDIA 驱动程序:384.98
- CUDA/cuDNN版本:cuda 8.0/cuDNN 6.0
- GPU 型号和内存:Geforce 1080Ti
您正在尝试在 GPU 上对具有 tf.int32
(DT_INT32
) 数据类型的多个张量进行处理。错误消息是说不支持在 GPU 上乘以 DT_INT32
张量。
请注意,网站上的代码使用的是浮点张量 (tf.float32
)(假设您说的是 https://www.tensorflow.org/tutorials/using_gpu 中的代码)
变化中:
a = tf.constant([1,2,3,4,5,6],shape=[2,3],name='a')
至:
a = tf.constant([1.,2.,3.,4.,5.,6.],shape=[2,3],name='a')
或:
a = tf.constant([1,2,3,4,5,6],shape=[2,3],name='a',dtype=tf.float32)
同样地,对于 b
应该可以消除错误,因为肯定有内核支持 GPU 上 float32 张量的矩阵乘法。
希望对您有所帮助。