无法满足显式设备规范'/ device:GPU:0',因为没有匹配的设备

时间:2017-06-28 23:12:18

标签: tensorflow gpu tensorflow-gpu

我想在我的Ubuntu 14.04上使用tensorflow 0.12 for GPU。

但是在将设备分配给节点时,我收到以下错误。

InvalidArgumentError (see above for traceback): Cannot assign a device to
node 'my_model/RNN/zeros': Could not satisfy explicit device specification
'/device:GPU:0' because no devices matching that specification are registered
in this process; available devices: /job:localhost/replica:0/task:0/cpu:0
    [[Node: my_model/RNN/zeros = Fill[T=DT_FLOAT, _device="/device:GPU:0"]
(my_model/RNN/pack, my_model/RNN/zeros/Const)]]

我的张量流似乎设置正确,因为这个简单的程序有效:

import tensorflow as tf
# Creates a graph.
with tf.device('/gpu:0'):
  a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
  b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
  c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))

哪个输出:

    I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA 
library libcublas.so locally I tensorflow/stream_executor/dso_loader.cc:128] 
successfully opened CUDA library libcudnn.so locally I 
tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library
 libcufft.so locally I tensorflow/stream_executor/dso_loader.cc:128] 
successfully opened CUDA library libcuda.so.1 locally I 
tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library
 libcurand.so locally I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] 
Found device 0 with properties:  name: Tesla K40m major: 3 minor: 5 
memoryClockRate (GHz) 0.745 pciBusID 0000:08:00.0 Total memory: 11.17GiB Free 
memory:

    11.10GiB I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0  I
 tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y  I 
tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow 
device (/gpu:0) -> (device: 0, name: Tesla K40m, pci bus id: 0000:08:00.0) 
Device mapping: /job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: 
Tesla K40m, pci bus id: 0000:08:00.0 I tensorflow/core/common_runtime
/direct_session.cc:255] Device mapping: /job:localhost/replica:0/task:0/gpu:0 
-> device: 0, name: Tesla K40m, pci bus id: 0000:08:00.0


    MatMul: (MatMul): /job:localhost/replica:0/task:0/gpu:0 I tensorflow/core
/common_runtime/simple_placer.cc:827] MatMul: (MatMul)/job:localhost/replica:0
/task:0/gpu:0 b: (Const): /job:localhost/replica:0/task:0/gpu:0 I 
tensorflow/core/common_runtime/simple_placer.cc:827] b: (Const)/job:localhost
/replica:0/task:0/gpu:0 a: (Const): /job:localhost/replica:0/task:0/gpu:0 I 
tensorflow/core/common_runtime/simple_placer.cc:827] a: (Const)/job:localhost
/replica:0/task:0/gpu:0 [[ 22.  28.]  [ 49. 
    64.]]

如何正确地为节点分配deive?

1 个答案:

答案 0 :(得分:12)

尝试使用sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True))。如果它不能在GPU上进行操作,这将解决问题。由于某些操作只有CPU实现。

当没有GPU实现时,使用allow_soft_placement=True将允许TensorFlow回退到CPU。