在matmul上使用GPU的Tensorflow问题.GPU无法识别

Max*_*rel 5 gpu invalid-argument matrix-multiplication tensorflow

我用gpu,cuda 7.0和cudnn 6.5安装了tensorflow.当我导入张量流时,效果很好.

我试图在Tensorflow上运行一个简单的矩阵乘法,它不想使用我的gpu,虽然它似乎认识到它.我的计算机上有一个nvidia geforce 970m和一个带有两个titan Z的集群.

我的第一个代码是:

import tensorflow as tf
import numpy as np

size=100
#I create 2 matrix
mat1 = np.random.random_sample([size, size])*100
mat2 = np.random.random_sample([size, size])*100

a = tf.constant(mat1)
b = tf.constant(mat2)
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
sess.run(c)
Run Code Online (Sandbox Code Playgroud)

此代码有效,结果如下:

Const_1: /job:localhost/replica:0/task:0/gpu:0
I tensorflow/core/common_runtime/simple_placer.cc:289] Const_1: /job:localhost/replica:0/task:0/gpu:0
Const: /job:localhost/replica:0/task:0/gpu:0
I tensorflow/core/common_runtime/simple_placer.cc:289] Const: /job:localhost/replica:0/task:0/gpu:0
MatMul: /job:localhost/replica:0/task:0/cpu:0
I tensorflow/core/common_runtime/simple_placer.cc:289] MatMul: /job:localhost/replica:0/task:0/cpu:0
Run Code Online (Sandbox Code Playgroud)

所以在我的方式中,tensorflow使用我的gpu创建常量但不是matmul(这很奇怪).然后,我像这样强制gpu:

with tf.device("/gpu:0"):
    a = tf.constant(mat1)
    b = tf.constant(mat2)
    c = tf.matmul(a, b)
    sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
    sess.run(c)
Run Code Online (Sandbox Code Playgroud)

并且Tensorflow返回:

InvalidArgumentError: Cannot assign a device to node 'MatMul': Could not satisfy explicit device specification '/gpu:0'
Run Code Online (Sandbox Code Playgroud)

如果有人有同样的问题或想法,我会很高兴看到你的答案!

ste*_*ano 3

我没有足够的声誉来发表评论,我遇到过类似的问题,我的问题在这里

TensorFlow:关键图形操作分配给 CPU 而不是 GPU