Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow: no supported kernel for GPU devices is available

The code below is a part of my model and is trying to do linear interpolation, similar to numpy.interp(). In my model t has shape (64,64). x has shape (91,). y has shape (91,).

def tf_interp(b, x, y):
    xaxis_pad = tf.concat([[tf.minimum(b, tf.gather(x, 0))], x, [tf.maximum(b, tf.gather(x, height_sino - 1))]],
                          axis=0)
    yaxis_pad = tf.concat([[0.0], y, [0.0]], axis=0)

    cmp = tf.cast(b > xaxis_pad, dtype=tf.float32)
    diff = cmp[1:] - cmp[:-1]
    idx = tf.argmin(diff)

    # Interpolate
    alpha = (b - xaxis_pad[idx]) / (xaxis_pad[idx + 1] - xaxis_pad[idx])
    res = alpha * yaxis_pad[idx + 1] + (1 - alpha) * yaxis_pad[idx]

    #def f1(): return 0.0

    #def f2(): return alpha * yaxis_pad[idx + 1] + (1 - alpha) * yaxis_pad[idx]

    #with tf.device('/gpu:0'):
        #res = tf.cond(pred=tf.is_nan(res), true_fn=f1, false_fn=f2)

    return res


def tf_interpolation(t, x, y):
    t1 = tf.reshape(t, [-1, ])
    t_return = tf.map_fn(lambda b: tf_interp(b, x, y), t1, dtype=tf.float32, name='t_return')
    t_return = tf.reshape(t_return, [width, height])
    return t_return

When I try to define an Adam optimizer to my model. Following error occurs:

Traceback (most recent call last):
  File "net_training_new.py", line 411, in <module>
    sess.run(tf.global_variables_initializer())
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 900, in run
    run_metadata_ptr)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1135, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run
    run_metadata)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation 'gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.
Colocation Debug Info:
Colocation group had the following types and devices: 
TensorArrayWriteV3: GPU CPU 
Add: GPU CPU 
Range: GPU CPU 
Const: GPU CPU 
Enter: GPU CPU 
StackPushV2: GPU CPU 
StackV2: GPU CPU 
TensorArrayV3: GPU CPU 
TensorArrayScatterV3: GPU CPU 
StackPopV2: CPU 
TensorArrayGatherV3: GPU CPU 
Identity: GPU CPU 
TensorArrayGradV3: GPU CPU 
Exit: GPU CPU 
TensorArrayReadV3: GPU CPU 
TensorArraySizeV3: GPU CPU 

Colocation members and user-requested devices:
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Const (Const) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc (StackV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2/Enter (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/Const (Const) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/f_acc (StackV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPopV2/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Const_1 (Const) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc_1 (StackV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2_1/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter_1 (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Const (Const) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc (StackV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2 (StackPopV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter_1 (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPopV2 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2_1 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3 (TensorArrayGradV3) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/gradient_flow (Identity) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range/delta (Const) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range/start (Const) 
  generator_model/backprojected/while/t_return/TensorArray_1 (TensorArrayV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2 (StackPushV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2 (StackPushV2) 
  generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3/Enter (Enter) /device:GPU:0
  generator_model/backprojected/while/t_return/while/Exit_1 (Exit) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2_1 (StackPushV2) 
  generator_model/backprojected/while/t_return/TensorArrayStack/TensorArraySizeV3 (TensorArraySizeV3) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range (Range) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPushV2 (StackPushV2) 
  generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3 (TensorArrayGatherV3) 
  generator_model/backprojected/while/t_return/while/add_7 (Add) /device:GPU:0
  generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3 (TensorArrayWriteV3) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3 (TensorArrayScatterV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3 (TensorArrayGradV3) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/gradient_flow (Identity) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayReadV3 (TensorArrayReadV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/tuple/control_dependency (Identity) 
  gradients_1/generator_model/backprojected/while/t_return/while/add_7_grad/tuple/control_dependency_1 (Identity) 
  gradients_1/generator_model/backprojected/while/t_return/while/add_7_grad/tuple/control_dependency (Identity) 

Registered kernels:
  device='GPU'
  device='CPU'

     [[Node: gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc = StackV2[_class=["loc:@generator_model/backprojected/while/t_return/TensorArray_1", "loc:@generator_model/backprojected/while/t_return/while/add_7"], elem_type=DT_RESOURCE, stack_name="", _device="/device:GPU:0"](gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Const)]]

Caused by op 'gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc', defined at:
  File "net_training_new.py", line 397, in <module>
    g_trainer = tf.train.AdamOptimizer(learning_rate=lr).minimize(g_loss, var_list=gen_variables)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/training/optimizer.py", line 414, in minimize
    grad_loss=grad_loss)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/training/optimizer.py", line 526, in compute_gradients
    colocate_gradients_with_ops=colocate_gradients_with_ops)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 494, in gradients
    gate_gradients, aggregation_method, stop_gradients)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 636, in _GradientsHelper
    lambda: grad_fn(op, *out_grads))
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 385, in _MaybeCompile
    return grad_fn()  # Exit early
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 636, in <lambda>
    lambda: grad_fn(op, *out_grads))
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/tensor_array_grad.py", line 130, in _TensorArrayWriteGrad
    .grad(source=grad_source, flow=flow))
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 849, in grad
    return self._implementation.grad(source, flow=flow, name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 241, in grad
    handle=self._handle, source=source, flow_in=flow, name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 6229, in tensor_array_grad_v3
    name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1760, in __init__
    self._control_flow_post_processing()
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1771, in _control_flow_post_processing
    self._control_flow_context.AddOp(self)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2445, in AddOp
    self._AddOpInternal(op)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2466, in _AddOpInternal
    real_x = self.AddValue(x)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2398, in AddValue
    real_val = grad_ctxt.grad_state.GetRealValue(val)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1155, in GetRealValue
    history_value = cur_grad_state.AddForwardAccumulator(cur_value)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1022, in AddForwardAccumulator
    max_size=max_size, elem_type=value.dtype.base_dtype, name="f_acc")
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 5033, in stack_v2
    stack_name=stack_name, name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

...which was originally created as op 'generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3', defined at:
  File "net_training_new.py", line 365, in <module>
    Gz = generator(LD_placeholder)
  File "net_training_new.py", line 212, in generator
    backprojected = tf.map_fn(lambda s: tf_interpolation(t, x, s[:, i]), radon_filtered, name='backprojected')
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 423, in map_fn
    swap_memory=swap_memory)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
    result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
    pred, body, original_loop_vars, loop_vars, shape_invariants)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
    body_result = body(*packed_vars_for_body)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 413, in compute
    packed_fn_values = fn(packed_values)
  File "net_training_new.py", line 212, in <lambda>
    backprojected = tf.map_fn(lambda s: tf_interpolation(t, x, s[:, i]), radon_filtered, name='backprojected')
  File "net_training_new.py", line 79, in tf_interpolation
    t_return = tf.map_fn(lambda b: tf_interp(b, x, y), t1, dtype=tf.float32, name='t_return')
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 423, in map_fn
    swap_memory=swap_memory)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
    result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
    pred, body, original_loop_vars, loop_vars, shape_invariants)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
    body_result = body(*packed_vars_for_body)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 416, in compute
    tas = [ta.write(i, value) for (ta, value) in zip(tas, flat_fn_values)]
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 416, in <listcomp>
    tas = [ta.write(i, value) for (ta, value) in zip(tas, flat_fn_values)]
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/util/tf_should_use.py", line 118, in wrapped
    return _add_should_use_warning(fn(*args, **kwargs))
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 879, in write
    return self._implementation.write(index, value, name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/util/tf_should_use.py", line 118, in wrapped
    return _add_should_use_warning(fn(*args, **kwargs))
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 278, in write
    name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 7344, in tensor_array_write_v3
    flow_in=flow_in, name=name)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
    op_def=op_def)
  File "/home/xiehuidong/anaconda3/envs/CtProject/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.
Colocation Debug Info:
Colocation group had the following types and devices: 
TensorArrayWriteV3: GPU CPU 
Add: GPU CPU 
Range: GPU CPU 
Const: GPU CPU 
Enter: GPU CPU 
StackPushV2: GPU CPU 
StackV2: GPU CPU 
TensorArrayV3: GPU CPU 
TensorArrayScatterV3: GPU CPU 
StackPopV2: CPU 
TensorArrayGatherV3: GPU CPU 
Identity: GPU CPU 
TensorArrayGradV3: GPU CPU 
Exit: GPU CPU 
TensorArrayReadV3: GPU CPU 
TensorArraySizeV3: GPU CPU 

Colocation members and user-requested devices:
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Const (Const) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc (StackV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2/Enter (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/Const (Const) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/f_acc (StackV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPopV2/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Const_1 (Const) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc_1 (StackV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2_1/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter_1 (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Const (Const) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc (StackV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter (Enter) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2 (StackPopV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Enter_1 (Enter) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPopV2 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2_1 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPopV2 (StackPopV2) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3 (TensorArrayGradV3) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/gradient_flow (Identity) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range/delta (Const) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range/start (Const) 
  generator_model/backprojected/while/t_return/TensorArray_1 (TensorArrayV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2 (StackPushV2) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2 (StackPushV2) 
  generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3/Enter (Enter) /device:GPU:0
  generator_model/backprojected/while/t_return/while/Exit_1 (Exit) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayGrad/TensorArrayGradV3/StackPushV2_1 (StackPushV2) 
  generator_model/backprojected/while/t_return/TensorArrayStack/TensorArraySizeV3 (TensorArraySizeV3) 
  generator_model/backprojected/while/t_return/TensorArrayStack/range (Range) 
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3/StackPushV2 (StackPushV2) 
  generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3 (TensorArrayGatherV3) 
  generator_model/backprojected/while/t_return/while/add_7 (Add) /device:GPU:0
  generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3 (TensorArrayWriteV3) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/TensorArrayStack/TensorArrayGatherV3_grad/TensorArrayScatter/TensorArrayScatterV3 (TensorArrayScatterV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3 (TensorArrayGradV3) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/gradient_flow (Identity) /device:GPU:0
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayReadV3 (TensorArrayReadV3) 
  gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/tuple/control_dependency (Identity) 
  gradients_1/generator_model/backprojected/while/t_return/while/add_7_grad/tuple/control_dependency_1 (Identity) 
  gradients_1/generator_model/backprojected/while/t_return/while/add_7_grad/tuple/control_dependency (Identity) 

Registered kernels:
  device='GPU'
  device='CPU'

     [[Node: gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/f_acc = StackV2[_class=["loc:@generator_model/backprojected/while/t_return/TensorArray_1", "loc:@generator_model/backprojected/while/t_return/while/add_7"], elem_type=DT_RESOURCE, stack_name="", _device="/device:GPU:0"](gradients_1/generator_model/backprojected/while/t_return/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayGrad/TensorArrayGradV3/Const)]]

And it says that the problem is on this line

t_return = tf.map_fn(lambda b: tf_interp(b, x, y), t1, dtype=tf.float32, name='t_return') 

TensorFlow cannot assign a device for this operation because no supported kernel for GPU devices is available.

I can run it on CPU perfectly. Why I cannot run this line on GPU?

like image 246
ddxxdds Avatar asked Jul 17 '18 17:07

ddxxdds


1 Answers

Try this, let's see if it works:

with tf.device('/device:GPU:2'):
    t1 = tf.reshape(t, [-1, ])
    t_return = tf.map_fn(lambda b: tf_interp(b, x, y), t1, dtype=tf.float32, name='t_return')
    t_return = tf.reshape(t_return, [width, height])
    return t_return

Also, try using this piece of code to initialize your session object.

with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, \
                  log_device_placement=True)) as sess:
    sess.run(tf.global_variables_initializer())
    ...

If the device you have specified does not exist, you will get InvalidArgumentError:

> InvalidArgumentError: Invalid argument: Cannot assign a device to node
> 'b': Could not satisfy explicit device specification '/device:GPU:2'  
> [[Node: b = Const[dtype=DT_FLOAT, value=Tensor<type: float shape:
> [3,2]    values: 1 2 3...>, _device="/device:GPU:2"]()]]

If you would like TensorFlow to automatically choose an existing and supported device to run the operations in case the specified one doesn't exist, you can set allow_soft_placement to True in the configuration option when creating the session.

like image 180
Ekaba Bisong Avatar answered Nov 15 '22 14:11

Ekaba Bisong