Skip to content

CUDA_ERROR_NO_DEVICE inside docker with GTX Titan X #808

Closed

Description

@mcuadros

Running b.gcr.io/tensorflow/tensorflow:latest-gpu having CUDA 7.0 installed on the host when I try to create the session it returns CUDA_ERROR_NO_DEVICE and was unable to find libcuda.so DSO loaded into this program but when the strange thing is that when the module is imported all the libraries are loaded correctly.

Log:

root@5b1e79697b49:~# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcublas.so.7.0 locally
I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcudnn.so.6.5 locally
I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcufft.so.7.0 locally
I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcuda.so locally
I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcurand.so.7.0 locally
>>> 
>>> with tf.Session() as sess:
...   with tf.device("/gpu:0"):
...     matrix1 = tf.constant([[3., 3.]])
...     matrix2 = tf.constant([[2.],[2.]])
...     product = tf.matmul(matrix1, matrix2)
...     sess.run(product)
... 
I tensorflow/core/common_runtime/local_device.cc:40] Local device intra op parallelism threads: 8
E tensorflow/stream_executor/cuda/cuda_driver.cc:481] failed call to cuInit: CUDA_ERROR_NO_DEVICE
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:114] retrieving CUDA diagnostic information for host: 5b1e79697b49
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:121] hostname: 5b1e79697b49
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:146] libcuda reported version is: Not found: was unable to find libcuda.so DSO loaded into this program
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:257] driver version file contents: """NVRM version: NVIDIA UNIX x86_64 Kernel Module  358.16  Mon Nov 16 19:25:55 PST 2015
GCC version:  gcc version 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 
"""
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:150] kernel reported version is: 358.16
I tensorflow/core/common_runtime/gpu/gpu_init.cc:127] DMA: 
I tensorflow/core/common_runtime/direct_session.cc:58] Direct session inter op parallelism threads: 8
Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 368, in run
    results = self._do_run(target_list, unique_fetch_targets, feed_dict_string)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 444, in _do_run
    e.code)
tensorflow.python.framework.errors.InvalidArgumentError: Cannot assign a device to node 'Const_1': Could not satisfy explicit device specification '/gpu:0'
         [[Node: Const_1 = Const[dtype=DT_FLOAT, value=Tensor<type: float shape: [2,1] values: 2 2>, _device="/gpu:0"]()]]
Caused by op u'Const_1', defined at:
  File "<stdin>", line 4, in <module>
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/constant_op.py", line 165, in constant
    attrs={"value": tensor_value, "dtype": dtype_value}, name=name).outputs[0]
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1834, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1043, in __init__
    self._traceback = _extract_stack()

>>> 

Versions:

  • OS: CentOS Linux elease.2.1511(Core)
  • Kernel: Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
  • GPU: NVIDIA Corporation GM200 [GeForce GTX TITAN X] (rev a1)
  • Docker: 1.9.1

Env:

CUDA_HOME=/usr/local/cuda-7.0
LD_LIBRARY_PATH=/usr/local/cuda-7.0/lib64:

Command:

docker run -it -v /usr/lib/x86_64-linux-gnu/libcudadevrt.a:/usr/lib/x86_64-linux-gnu/libcudadevrt.a -v /usr/lib/x86_64-linux-gnu/libcudart.so:/usr/lib/x86_64-linux-gnu/libcudart.so -v /usr/lib/x86_64-linux-gnu/libcudart.so.7.0:/usr/lib/x86_64-linux-gnu/libcudart.so.7.0 -v /usr/lib/x86_64-linux-gnu/libcudart.so.7.0.28:/usr/lib/x86_64-linux-gnu/libcudart.so.7.0.28 -v /usr/lib/x86_64-linux-gnu/libcudart_static.a:/usr/lib/x86_64-linux-gnu/libcudart_static.a -v /usr/lib/x86_64-linux-gnu/libcuda.so:/usr/lib/x86_64-linux-gnu/libcuda.so --device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl --device /dev/nvidia-modeset:/dev/nvidia-modeset b.gcr.io/tensorflow/tensorflow:latest-gpu

Activity

  1. zheng-xq commented on Jan 19, 2016

    @zheng-xq
    Contributor

    @mcuadros, TF docker has trouble finding your Cuda driver, not the Cuda libraries. Could you check?

    • /usr/lib/x86_64-linux-gnu/libcuda.so does exist on your machine, and in the docerk container?
    • Please make sure that path is on your LD_LIBRARY_PATH as well
    • If still having trouble with the docerk container, could you also try without the docker container just to see if that works?

    Thanks.

  2. ruffsl commented on Jan 28, 2016

    @ruffsl

    @mcuadros, the images taged with -gpu are intended to be used with the nvidia-docker project, as you may well note the parent image they are built from, FROM nvidia/cuda:7.0-cudnn2-runtime. Go check out nvidia-docker wiki on how to get started and launch GPU enabeled containers. Cuda is already setup in the image, all your host needs is the nvidia driver, docker, and the nvidia-docker plugin.

    Looks like this wasn't yet made clear in the README.md, could a dev kindly touch that up?

  3. mcuadros commented on Jan 28, 2016

    @mcuadros
    Author

    @ruffsl I will try to run it with nvidia-docker, to see if works.

    In the documentation always speaks about the normal docker-engine and also the old bash to run tf with docker was running the normal command.

  4. cancan101 commented on Feb 2, 2016

    @cancan101
    Contributor

    I tried to start this using nvidia-docker and it still does not work:

    I tensorflow/stream_executor/dso_loader.cc:93] Couldn't open CUDA library libcuda.so. LD_LIBRARY_PATH: /usr/local/cuda/lib64
    ...
    E tensorflow/stream_executor/cuda/cuda_driver.cc:481] failed call to cuInit: CUDA_ERROR_NO_DEVICE
    I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:109] no NVIDIA GPU device is present: /dev/nvidia0 does not exist
    
  5. caisq commented on Feb 2, 2016

    @caisq
    Contributor

    Here are the debugging steps that I recently went through to get TensorFlow working (kind of) with GPU and Docker. (I say "kind of" because there are still some GPU-related bugs in Tensorflow, which caused some test failures and will likely cause some user-code errors in that regard as well).

    See:
    #952
    #953

    That said, here are the things you want to check on:

    1. On the host, outside Docker, you have NVIDIA driver installed. If you have it installed, the binaries "nvidia-smi" and "nvidia-debugdump" ought to be available on the host. Make sure that the following two commands list your GPU:
      nvidia-smi
      nvidia-debugdump -l

    2. On the host, the output of nvidia-smi tells you the version of the NVIDIA driver installed. It needs to be recent enough for your GPU. For example, on my machine, version 340 doesn't work, but version 352 does.

    3. On the host, get the CUDA sample code and compile the deviceQuery binary:
      http://docs.nvidia.com/cuda/cuda-samples/#axzz3z3C3lhk1

    For this you'll need to install the CUDA toolkit, which includes the nvcc compiler and supporting libraries.
    https://developer.nvidia.com/cuda-downloads

    Once the deviceQuery binary is compiled, try to run it
    ./deviceQuery

    If it fails, don't panic, just try
    sudo ./deviceQuery

    There are some file permissions issues related to NVIDIA devices in /dev that requires you to do sudo like the above for each boot cycle, for detailed dicussion, see:
    https://devtalk.nvidia.com/default/topic/749939/cuda-is-not-active-unless-i-run-it-with-sudo-privillages-/

    1. After step 3, CUDA GPU is all set on the host. Let's now look inside Docker. Make sure that you install the same CUDA Toolkit as listed in step 3. TensorFlow additionally requires CUDA DNN (cudnn) libraries which you can also get from the CUDA website, after a somewhat time consuming user approval process.

    After this make sure that the following files are present in your docker, as they will be used by (the current version of) TensorFlow:

    /usr/local/cuda/include/cudnn.h 
    /usr/local/cuda/lib64/libcudnn_static.a
    /usr/local/cuda/lib64/libcudnn.so.6.5.48 
    /usr/local/cuda/lib64/libcudnn.so.6.5/libcudnn.so.6.5.48 
    /usr/local/cuda/lib64/libcudnn.so/libcudnn.so.6.5
    

    It is okay for NVIDIA driver to be unavailable inside the Docker, even though the CUDA Toolkit is required inside it.

    1. Before you can try to start your Docker container, make sure you use docker flags to map a few devices so the the NVIDIA devices are available under /dev, inside the container:
    "--device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl"
    

    Also, map a bunch of lib files, to make sure that cuda library files are visible inside the container

    "-v /usr/lib/x86_64-linux-gnu/libcudadevrt.a:/usr/lib/x86_64-linux-gnu/libcudadevrt.a" "-v /usr/lib/x86_64-linux-gnu/libcudart.so:/usr/lib/x86_64-linux-gnu/libcudart.so" "-v /usr/lib/x86_64-linux-gnu/libcudart.so.5.5:/usr/lib/x86_64-linux-gnu/libcudart.so.5.5" "-v /usr/lib/x86_64-linux-gnu/libcudart.so.5.5.22:/usr/lib/x86_64-linux-gnu/libcudart.so.5.5.22" "-v /usr/lib/x86_64-linux-gnu/libcudart_static.a:/usr/lib/x86_64-linux-gnu/libcudart_static.a" "-v /usr/lib/x86_64-linux-gnu/libcuda.so:/usr/lib/x86_64-linux-gnu/libcuda.so" "-v /usr/lib/x86_64-linux-gnu/libcuda.so.1:/usr/lib/x86_64-linux-gnu/libcuda.so.1" "-v /usr/lib/x86_64-linux-gnu/libcuda.so.352.63:/usr/lib/x86_64-linux-gnu/libcuda.so.352.63"
    

    Now the NVIDIA docker container should be ready to run TensorFlow with GPU.

  6. ruffsl commented on Feb 4, 2016

    @ruffsl

    @cancan101 , that's odd. Just did a fresh build of both cuda and tensorflow with Dockerfile.devel-gpu and then got the same error you got:

    ...
    I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcublas.so.7.0 locally
    I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcudnn.so.6.5 locally
    I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcufft.so.7.0 locally
    I tensorflow/stream_executor/dso_loader.cc:93] Couldn't open CUDA library libcuda.so. LD_LIBRARY_PATH: /usr/local/nvidia/lib:/usr/local/nvidia/lib64:
    I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:121] hostname: 6816d202e2bd
    ...
    I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1061] failed to find libcuda.so on this system: Failed precondition: could not dlopen DSO: libcuda.so; dlerror: libcuda.so: cannot open shared object file: No such file or directory
    

    I checked to make sure the library was installed and ldconfig finds it just fine:

    env
    ...
    LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:
    PATH=/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    CUDA_PATH=/usr/local/cuda
    ...
    
    ldconfig -p | grep libcuda
            libcudart.so.7.0 (libc6,x86-64) => /usr/local/cuda/lib64/libcudart.so.7.0
            libcudart.so (libc6,x86-64) => /usr/local/cuda/lib64/libcudart.so
            libcuda.so.1 (libc6,x86-64) => /usr/local/nvidia/lib64/libcuda.so.1
            libcuda.so.1 (libc6) => /usr/local/nvidia/lib/libcuda.so.1

    Is there a path missing somewhere?

    I even tried the old images up on docker hub last repo modified 2 months ago and the b.gcr.io updated recently by adding in the new nvidia meta label:

    FROM tensorflow/tensorflow:0.6.0-gpu # or b.gcr.io/tensorflow/tensorflow-devel-gpu
    LABEL com.nvidia.volumes.needed="nvidia_driver"

    for nvidia-docker, but still got the same error.

  7. 3XX0 commented on Feb 4, 2016

    @3XX0

    @ruffsl I suppose you used nvidia-docker given your paths.

    I quickly looked at the Tensorflow code, the DsoLoader tries to find libcuda in third_party/gpus/cuda/driver/lib64. Not sure how it is supposed to end up there, but libcuda is not part of the CUDA toolkit so you can't rely on the standard CUDA path to find it.
    In the case of nvidia-docker it is mounted at runtime in /usr/local/nvidia/, you will need to add this location into the third_party search script.

  8. ruffsl commented on Feb 5, 2016

    @ruffsl

    Pardon the noise, but pinging @vrv @craigcitro or @jendap , do you know what the intended setup for tensorflow cuda paths are? Or perhaps what this feature is meant to address? I'm not sure how this third_party path is coming into play.

  9. vrv commented on Feb 5, 2016

    @vrv

    @zheng-xq, any ideas here?

  10. craigcitro commented on Feb 5, 2016

    @craigcitro
    Contributor

    also pinging @ebrevdo who may have hit this more recently.

  11. ebrevdo commented on Feb 5, 2016

    @ebrevdo
    Contributor

    You have cuda_path set, maybe it should be CUDA_HOME?

  12. ebrevdo commented on Feb 5, 2016

    @ebrevdo
    Contributor

    Also add this to ld library path:

    /usr/lib/x86_64-linux-gnu

  13. 14 remaining items

  14. manjunaths commented on Jul 13, 2016

    @manjunaths

    I am using nvidia-docker and the latest everything on RHEL 7.2 and I still have this issue.

    manju@o185i089:/lvol/manju$ docker run -it gcr.io/tensorflow/tensorflow:latest-devel-gpu
    Unable to find image 'gcr.io/tensorflow/tensorflow:latest-devel-gpu' locally
    latest-devel-gpu: Pulling from tensorflow/tensorflow
    759d6771041e: Pull complete
    8836b825667b: Pull complete
    c2f5e51744e6: Pull complete
    a3ed95caeb02: Pull complete
    d5b215eff347: Pull complete
    34d39ef2e894: Pull complete
    a7a36155eb9e: Pull complete
    b1bfa35e6e17: Pull complete
    8210f508bb7c: Pull complete
    fd02f6ca3839: Pull complete
    c7e296ba93f3: Pull complete
    7b9159cc5928: Pull complete
    25abb1637a5a: Pull complete
    71595b8a5fcb: Pull complete
    00fa70dea9b1: Pull complete
    4c3f9ea22d7e: Pull complete
    077e0cee8ca6: Pull complete
    65b6e5754aad: Pull complete
    0811f4c80537: Pull complete
    e0a07be9804b: Pull complete
    c8e3ab48d3ab: Pull complete
    cc5ff4523b24: Pull complete
    Digest: sha256:a38c40a95869d8e36380f88bb0682c77988d12cefd28d4e161093049a4bbb4b5
    Status: Downloaded newer image for gcr.io/tensorflow/tensorflow:latest-devel-gpu
    root@40afc612354b:~#
    root@40afc612354b:~#
    root@40afc612354b:~# python
    Python 2.7.6 (default, Jun 22 2015, 17:58:13)
    [GCC 4.8.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow as tf
    I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcublas.so locally
    I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcudnn.so locally
    I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcufft.so locally
    I tensorflow/stream_executor/dso_loader.cc:99] Couldn't open CUDA library libcuda.so.1. LD_LIBRARY_PATH: /usr/local/nvidia/lib:/usr/local/nvidia/lib64:
    I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:121] hostname: 40afc612354b
    I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:146] libcuda reported version is: Not found: was unable to find libcuda.so DSO loaded into this program
    I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:257] driver version file contents: """NVRM version: NVIDIA UNIX x86_64 Kernel Module 352.93 Tue Apr 5 18:18:24 PDT 2016
    GCC version: gcc version 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
    """
    I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:150] kernel reported version is: 352.93
    I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1051] LD_LIBRARY_PATH: /usr/local/nvidia/lib:/usr/local/nvidia/lib64:
    I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1052] failed to find libcuda.so on this system: Failed precondition: could not dlopen DSO: libcuda.so.1; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
    I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcurand.so locally
    >>>

    Is there a fix for this issue ?

  15. RiemannianAnalyzer commented on Jul 27, 2016

    @RiemannianAnalyzer

    Did you guys find a solution to this issue? I am on dual Titan X. The error that I get is similar to the one reported above:

    $ python input_data.py I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so locally I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally E tensorflow/stream_executor/cuda/cuda_driver.cc:491] failed call to cuInit: CUDA_ERROR_NO_DEVICE I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:153] retrieving CUDA diagnostic information for host: maximus I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:160] hostname: maximus I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:185] libcuda reported version is: Not found: was unable to find libcuda.so DSO loaded into this program I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:347] driver version file contents: """NVRM version: NVIDIA UNIX x86_64 Kernel Module 340.96 Sun Nov 8 22:33:28 PST 2015 GCC version: gcc version 4.8.5 (Ubuntu 4.8.5-2ubuntu1~14.04.1) """ I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:189] kernel reported version is: 340.96.0 I tensorflow/core/common_runtime/gpu/gpu_init.cc:81] No GPU devices available on machine. Extracting MNIST_data/train-images-idx3-ubyte.gz Extracting MNIST_data/train-labels-idx1-ubyte.gz Extracting MNIST_data/t10k-images-idx3-ubyte.gz Extracting MNIST_data/t10k-labels-idx1-ubyte.gz 0.9092

  16. manjunaths commented on Jul 27, 2016

    @manjunaths

    RiemannianAnalyzer,

    In my case the libcuda.so was not available in the container at the specified location. I was also using docker instead of nvidia-docker. I added in a libcuda* from the host machine into the cuda path (/usr/local/cuda/lib/*) and then froze the image. Now I no longer get the error, with the new image.

    In your case, did your driver install successfully (Have you looked at the driver install log?) ? It seems that the cuda library is missing. Also I am using a more recent version of the driver than you are. I don't know if that makes a difference. In one of my machines I had to install cuda and other support libraries by myself, too.

    HTH.

  17. pulak09 commented on Feb 1, 2019

    @pulak09

    import os

    os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
    os.environ["CUDA_VISIBLE_DEVICES"]="0"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions