To check how many GPU are available to tensorflow on your machine, you can run
python -c "import tensorflow as tf; print('Num GPUs Available: ', len(tf.config.experimental.list_physical_devices('GPU')))"
If you try this on Ubuntu 20.04 (and tensorflow-gpu 2.3.1 installed via pip), you may get an error that no devices are available:
Num GPUs Available: 0.
In my case, a library was missing:
tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudnn.so.7'; dlerror: libcudnn.so.7: cannot open shared object file: No such file or directory tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
The following steps may help you to fix that error.
Make sure you have the NVIDIA CUDA development toolkit installed:
sudo apt install nvidia-cuda-toolkit
Download the cuDNN library from https://developer.nvidia.com/rdp/cudnn-archive, you may have to create an account. You are looking for cuDNN 7, named like this:
Install those packages:
sudo dpkg -i libcudnn7_188.8.131.52-1+cuda10.1_amd64.deb libcudnn7-dev_184.108.40.206-1+cuda10.1_amd64.deb
- Now your GPU should be listed:
python -c "import tensorflow as tf; print('Num GPUs Available: ', len(tf.config.experimental.list_physical_devices('GPU')))" ... Num GPUs Available: 1