user8094905
user8094905

Reputation: 163

Tensorflow not detecting GPU - Adding visible gpu devices: 0

I have a system with an NVIDIA GeForce GTX 980 Ti. I installed tensorflow, and look for the gpu device with tf.test.gpu_device_name(). It looks like it finds the gpu, but then says "Adding visible gpu devices: 0"

>>> import tensorflow as tf
>>> tf.test.gpu_device_name()
2019-01-08 10:01:12.589000: I tensorflow/core/platform/cpu_feature_guard.cc:141]
 Your CPU supports instructions that this TensorFlow binary was not compiled to
use: AVX2
2019-01-08 10:01:12.855000: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1
432] Found device 0 with properties:
name: GeForce GTX 980 Ti major: 5 minor: 2 memoryClockRate(GHz): 1.228
pciBusID: 0000:01:00.0
totalMemory: 6.00GiB freeMemory: 5.67GiB
2019-01-08 10:01:12.862000: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1
511] Adding visible gpu devices: 0

Upvotes: 15

Views: 29111

Answers (4)

Nikhilanand Arya
Nikhilanand Arya

Reputation: 1

I was also facing the same problem and creating a conda environment with an environment.yml file solved the issue for me. The content of the .yml file are as follows: Please make sure to provide your system path in the last line of the code. eg. "/home/nikhilanand_1921cs24" should be replaced with your system path.

name: keras-gpu
channels:
  - conda-forge
  - defaults
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=4.5=1_gnu
  - _tflow_select=2.1.0=gpu
  - absl-py=0.13.0=py39h06a4308_0
  - aiohttp=3.8.1=py39h7f8727e_0
  - aiosignal=1.2.0=pyhd3eb1b0_0
  - astor=0.8.1=py39h06a4308_0
  - astunparse=1.6.3=py_0
  - async-timeout=4.0.1=pyhd3eb1b0_0
  - attrs=21.2.0=pyhd3eb1b0_0
  - blas=1.0=mkl
  - blinker=1.4=py39h06a4308_0
  - brotli=1.0.9=h7f98852_5
  - brotli-bin=1.0.9=h7f98852_5
  - brotlipy=0.7.0=py39h27cfd23_1003
  - c-ares=1.17.1=h27cfd23_0
  - ca-certificates=2021.10.8=ha878542_0
  - cachetools=4.2.2=pyhd3eb1b0_0
  - certifi=2021.10.8=py39hf3d152e_1
  - cffi=1.14.6=py39h400218f_0
  - charset-normalizer=2.0.4=pyhd3eb1b0_0
  - click=8.0.3=pyhd3eb1b0_0
  - cryptography=3.4.8=py39hd23ed53_0
  - cudatoolkit=10.1.243=h6bb024c_0
  - cudnn=7.6.5=cuda10.1_0
  - cupti=10.1.168=0
  - cycler=0.11.0=pyhd8ed1ab_0
  - dataclasses=0.8=pyh6d0b6a4_7
  - dbus=1.13.6=he372182_0
  - expat=2.2.10=h9c3ff4c_0
  - fontconfig=2.13.1=h6c09931_0
  - fonttools=4.25.0=pyhd3eb1b0_0
  - freetype=2.10.4=h0708190_1
  - frozenlist=1.2.0=py39h7f8727e_0
  - gast=0.4.0=pyhd3eb1b0_0
  - glib=2.69.1=h4ff587b_1
  - google-auth=1.33.0=pyhd3eb1b0_0
  - google-auth-oauthlib=0.4.4=pyhd3eb1b0_0
  - google-pasta=0.2.0=pyhd3eb1b0_0
  - grpcio=1.42.0=py39hce63b2e_0
  - gst-plugins-base=1.14.0=hbbd80ab_1
  - gstreamer=1.14.0=h28cd5cc_2
  - h5py=2.10.0=py39hec9cf62_0
  - hdf5=1.10.6=hb1b8bf9_0
  - icu=58.2=hf484d3e_1000
  - idna=3.3=pyhd3eb1b0_0
  - importlib-metadata=4.8.2=py39h06a4308_0
  - intel-openmp=2021.4.0=h06a4308_3561
  - jpeg=9d=h7f8727e_0
  - keras-preprocessing=1.1.2=pyhd3eb1b0_0
  - kiwisolver=1.3.1=py39h2531618_0
  - lcms2=2.12=hddcbb42_0
  - ld_impl_linux-64=2.35.1=h7274673_9
  - libbrotlicommon=1.0.9=h7f98852_5
  - libbrotlidec=1.0.9=h7f98852_5
  - libbrotlienc=1.0.9=h7f98852_5
  - libffi=3.3=he6710b0_2
  - libgcc-ng=9.3.0=h5101ec6_17
  - libgfortran-ng=7.5.0=ha8ba4b0_17
  - libgfortran4=7.5.0=ha8ba4b0_17
  - libgomp=9.3.0=h5101ec6_17
  - libpng=1.6.37=h21135ba_2
  - libprotobuf=3.17.2=h4ff587b_1
  - libstdcxx-ng=9.3.0=hd4cf53a_17
  - libtiff=4.2.0=h85742a9_0
  - libuuid=1.0.3=h7f8727e_2
  - libwebp-base=1.2.0=h27cfd23_0
  - libxcb=1.13=h7f98852_1003
  - libxml2=2.9.12=h03d6c58_0
  - lz4-c=1.9.3=h9c3ff4c_1
  - markdown=3.3.4=py39h06a4308_0
  - matplotlib=3.4.3=py39hf3d152e_2
  - matplotlib-base=3.4.3=py39hbbc1b5f_0
  - mkl=2021.4.0=h06a4308_640
  - mkl-service=2.4.0=py39h7f8727e_0
  - mkl_fft=1.3.1=py39hd3c417c_0
  - mkl_random=1.2.2=py39h51133e4_0
  - multidict=5.1.0=py39h27cfd23_2
  - munkres=1.1.4=pyh9f0ad1d_0
  - ncurses=6.3=h7f8727e_2
  - numpy=1.21.2=py39h20f2e39_0
  - numpy-base=1.21.2=py39h79a1101_0
  - oauthlib=3.1.1=pyhd3eb1b0_0
  - olefile=0.46=pyh9f0ad1d_1
  - openssl=1.1.1m=h7f8727e_0
  - opt_einsum=3.3.0=pyhd3eb1b0_1
  - pcre=8.45=h9c3ff4c_0
  - pip=21.2.4=py39h06a4308_0
  - protobuf=3.17.2=py39h295c915_0
  - pthread-stubs=0.4=h36c2ea0_1001
  - pyasn1=0.4.8=pyhd3eb1b0_0
  - pyasn1-modules=0.2.8=py_0
  - pycparser=2.21=pyhd3eb1b0_0
  - pyjwt=2.1.0=py39h06a4308_0
  - pyopenssl=21.0.0=pyhd3eb1b0_1
  - pyparsing=3.0.7=pyhd8ed1ab_0
  - pyqt=5.9.2=py39h2531618_6
  - pysocks=1.7.1=py39h06a4308_0
  - python=3.9.7=h12debd9_1
  - python-dateutil=2.8.2=pyhd8ed1ab_0
  - python-flatbuffers=2.0=pyhd3eb1b0_0
  - python_abi=3.9=2_cp39
  - qt=5.9.7=h5867ecd_1
  - readline=8.1=h27cfd23_0
  - requests=2.26.0=pyhd3eb1b0_0
  - requests-oauthlib=1.3.0=py_0
  - rsa=4.7.2=pyhd3eb1b0_1
  - scipy=1.7.1=py39h292c36d_2
  - setuptools=58.0.4=py39h06a4308_0
  - sip=4.19.13=py39h295c915_0
  - six=1.16.0=pyhd3eb1b0_0
  - sqlite=3.36.0=hc218d9a_0
  - tensorboard-plugin-wit=1.6.0=py_0
  - tensorflow-estimator=2.6.0=pyh7b7c402_0
  - termcolor=1.1.0=py39h06a4308_1
  - tk=8.6.11=h1ccaba5_0
  - tornado=6.1=py39h3811e60_1
  - typing-extensions=3.10.0.2=hd3eb1b0_0
  - typing_extensions=3.10.0.2=pyh06a4308_0
  - tzdata=2021e=hda174b7_0
  - urllib3=1.26.7=pyhd3eb1b0_0
  - werkzeug=2.0.2=pyhd3eb1b0_0
  - wheel=0.37.0=pyhd3eb1b0_1
  - wrapt=1.13.3=py39h7f8727e_2
  - xorg-libxau=1.0.9=h7f98852_0
  - xorg-libxdmcp=1.1.3=h7f98852_0
  - xz=5.2.5=h7b6447c_0
  - yarl=1.6.3=py39h27cfd23_0
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.11=h7f8727e_4
  - zstd=1.4.9=ha95c52a_0
  - pip:
    - joblib==1.1.0
    - keras==2.8.0
    - keras-applications==1.0.8
    - libclang==13.0.0
    - opencv-python==4.5.5.62
    - pandas==1.4.0
    - pillow==9.0.1
    - pytz==2021.3
    - pyyaml==6.0
    - scikit-learn==1.0.2
    - tensorboard==2.8.0
    - tensorboard-data-server==0.6.1
    - tensorflow==2.8.0
    - tensorflow-gpu==2.8.0
    - tensorflow-io-gcs-filesystem==0.23.1
    - tf-estimator-nightly==2.8.0.dev2021122109
    - threadpoolctl==3.0.0
prefix: /home/nikhilanand_1921cs24/anaconda3/envs/keras-gpu

Create the environment by runningconda env create -f environment.yml

Upvotes: 0

GopY
GopY

Reputation: 14

You can try one of the following commands:

  1. device_lib.list_local_devices()
  2. print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))

This will show you the gpu devices and their number.

My setup is as following to overcome the issue:

tensorflow 2.4.1

cuda 11.0.2

cudNN 8.1.0

So first you install tensorflow. Then you proceed with cuda (https://developer.nvidia.com/cuda-11.0-download-archive) and after you download the cudNN zip file from here -> https://developer.nvidia.com/rdp/cudnn-download, unzip and paste the cudnn64_8.dll file into C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin. Then everything works like a charm.

Upvotes: 0

Manu E Thomas
Manu E Thomas

Reputation: 73

Running the prompt as administrator solved the issue in my case

Upvotes: 1

Manu S Pillai
Manu S Pillai

Reputation: 949

Interestingly, the 0 you are concerned about is not the 0 you would use for counting. Precisely, its not "detected 0 devices" but " device 0 detected". "Adding visible device 0", 0 here is an identity for you GPU. Or you can say, the way of tensorflow to differentiate between multiple GPUs in the system. Here is the output of my system, and I'm pretty sure, I m using up my gpu for computation. So don't worry. You are good to go! 😉

Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.test.gpu_device_name()
2019-01-08 20:51:02.212125: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-01-08 20:51:03.199893: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1411] Found device 0 with properties:
name: GeForce GTX 1060 with Max-Q Design major: 6 minor: 1 memoryClockRate(GHz): 1.3415
pciBusID: 0000:01:00.0
totalMemory: 6.00GiB freeMemory: 4.97GiB
2019-01-08 20:51:03.207308: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1490] Adding visible gpu devices: 0
2019-01-08 20:51:04.857881: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-01-08 20:51:04.861791: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977]      0
2019-01-08 20:51:04.863796: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0:   N
2019-01-08 20:51:04.867507: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1103] Created TensorFlow device (/device:GPU:0 with 4722 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 with Max-Q Design, pci bus id: 0000:01:00.0, compute capability: 6.1)
'/device:GPU:0'

Upvotes: 32

Related Questions