简体   繁体   中英

Tensorflow-gpu not detecting GPU?

I have tensorflow-gpu version 2.2.0 installed with Anaconda in python 3.7.4, but my code always runs on CPU and It's not able to detect my GPU.

physical_devices= tf.config.experimental.list_physical_devices('GPU')
print(len(physical_devices))
>>> 0

When I run this:

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

I get:

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 6159543114609950707
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 4043157374881641271
physical_device_desc: "device: XLA_CPU device"
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 1519736160969870434
physical_device_desc: "device: XLA_GPU device"
]

The XLA_GPU:0 corresponds to the integrated graphics that runs on CPU, because I have tested running my code under with tf.device('/GPU:0'): and Task Manager shows only CPU usage.

I checked in my NVIDIA Control Panel -> System Information -> Components and under 3D Settings I have NVCUDA64.dll described as NVIDIA CUDA 11.0.208 Driver.

Up to this moment I haven't tried reinstalled tensorflow-gpu, expecting there could be something else that has to be done before.

My own answer. Finally it worked:

I had to download CUDA 10.1 and then cuDNN 7.6.5 for that version.

Thanks to @Gerry P and @Richard X

I do not believe 11.0 will work with tensorflow. You need 10.1. I have an RTX2070 and the driver version that work for that is 432.00. Go to the NVIDIA site and try to find a 10.1 compatible driver and install it. IF you used CONDA to install tensorflow then it should have installed the 10.1 CUDA toolkit and the compatible version of Cudnn.

I recently installed tensorflow 2.7 and it worked fine. Here is my configuration: CUDA: 11.5, CUDNN: 8.3, TENSORFLOW: 2.7, PYTHON: 3.9.9, GPU: NVIDIA GTX 1060, DRIVER VERSION: 497.29

I did not use Conda (even though it is very convenient but it results in a lot of version conflicts). I installed everything manually on Windows 10 like below. So, if anyone looking for instructions in or after Jan 2022:

  1. Install python b/w 3.90 - 3.9.9 ( https://www.python.org/downloads/release/python-399/ )
  2. Install cuda tool kit (Check compatibility with your GPU) ( https://developer.nvidia.com/cuda-toolkit-archiv e)
  3. Install cudnn and make sure it is compatible with the cuda version installed above ( https://developer.nvidia.com/rdp/cudnn-archive )
  4. Make sure the bin of both cuda and cudnn are on the PATH (C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\bin), (C:\Program Files\NVIDIA GPU Computing Toolkit\cudnn-windows-x86_64-8.3.1.22_cuda11.5-archive\bin)
  5. Install tensorflow ( https://www.tensorflow.org/install/gpu ) Use pip3 when installing for python3+
  6. If you want to create Jupyter notebooks then install jupyter "pip3 install jupyterlab" ( https://jupyter.org/install )
  7. Finally, restart your machine or atleast restart the shell
  8. Run the following from python REPL, you should get 1 or more
import tensorflow as tf print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM