TensorFlow says CUDA not enabled

Robert, Thanks for your reply. I tried installing cudatoolkit as you described. The toolkit seemed to install without a problem.

conda install cudatoolkit
Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: /home/shallada/anaconda3

  added / updated specs:
    - cudatoolkit


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    certifi-2019.6.16          |           py37_0         154 KB
    conda-4.6.14               |           py37_0         2.1 MB
    cudatoolkit-10.1.168       |                0       516.0 MB
    ------------------------------------------------------------
                                           Total:       518.3 MB

The following NEW packages will be INSTALLED:

  cudatoolkit        pkgs/main/linux-64::cudatoolkit-10.1.168-0

The following packages will be UPDATED:

  certifi                 anaconda::certifi-2019.3.9-py37_0 --> pkgs/main::certifi-2019.6.16-py37_0

The following packages will be SUPERSEDED by a higher-priority channel:

  ca-certificates                                  anaconda --> pkgs/main
  conda                                            anaconda --> pkgs/main
  openssl                anaconda::openssl-1.1.1-h7b6447c_0 --> pkgs/main::openssl-1.1.1c-h7b6447c_1


Proceed ([y]/n)? y


Downloading and Extracting Packages
cudatoolkit-10.1.168 | 516.0 MB  | ##################################################################################################################################### | 100% 
certifi-2019.6.16    | 154 KB    | ##################################################################################################################################### | 100% 
conda-4.6.14         | 2.1 MB    | ##################################################################################################################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Then I tried rerunning tftest.py as shown previously. The result was exactly the same.

python tftest.py 
2019-06-21 09:10:03.247018: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-06-21 09:10:03.268028: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3192000000 Hz
2019-06-21 09:10:03.268884: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x562fde2f2090 executing computations on platform Host. Devices:
2019-06-21 09:10:03.268929: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>
Device mapping:
/job:localhost/replica:0/task:0/device:XLA_CPU:0 -> device: XLA_CPU device
2019-06-21 09:10:03.269694: I tensorflow/core/common_runtime/direct_session.cc:317] Device mapping:
/job:localhost/replica:0/task:0/device:XLA_CPU:0 -> device: XLA_CPU device

MatMul: (MatMul): /job:localhost/replica:0/task:0/device:CPU:0
2019-06-21 09:10:03.270269: I tensorflow/core/common_runtime/placer.cc:1059] MatMul: (MatMul)/job:localhost/replica:0/task:0/device:CPU:0
Traceback (most recent call last):
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1334, in _do_call
    return fn(*args)
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1317, in _run_fn
    self._extend_graph()
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1352, in _extend_graph
    tf_session.ExtendSession(self._session)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation a: {{node a}}was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0 ]. Make sure the device specification refers to a valid device. The requested device appears to be a GPU, but CUDA is not enabled.
	 [[{{node a}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tftest.py", line 11, in <module>
    print(sess.run(c))
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 929, in run
    run_metadata_ptr)
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1152, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1328, in _do_run
    run_metadata)
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1348, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation a: node a (defined at tftest.py:5) was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0 ]. Make sure the device specification refers to a valid device. The requested device appears to be a GPU, but CUDA is not enabled.
	 [[node a (defined at tftest.py:5) ]]

Caused by op 'a', defined at:
  File "tftest.py", line 5, in <module>
    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py", line 179, in constant_v1
    allow_broadcast=False)
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py", line 289, in _constant_impl
    name=name).outputs[0]
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 3300, in create_op
    op_def=op_def)
  File "/home/shallada/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 1801, in __init__
    self._traceback = tf_stack.extract_stack()

InvalidArgumentError (see above for traceback): Cannot assign a device for operation a: node a (defined at tftest.py:5) was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0 ]. Make sure the device specification refers to a valid device. The requested device appears to be a GPU, but CUDA is not enabled.
	 [[node a (defined at tftest.py:5) ]]
1 Like