Last modified on 01 Oct 2021.

Check if GPU available?

# check if GPU available?
import tensorflow as tf
tf.config.list_physical_devices('GPU')

Installation with docker

๐Ÿ‘‰ Official guide.
๐Ÿ‘‰ Docker & GPU note.

The advantage of this method is that you only have to install GPU driver on the host machine.

Check docker version: docker --version:

  • <19.03: requires nvidia-docker2 (check by nvidia-docker version) and --runtime=nvidia.
  • >=19.03: requires nvidia-container-toolkit (check by which nvidia-container-toolkit) and --gpus all.

Without docker-compose

๐Ÿ‘‰ Different types of images for tensorflow.

# pull the image
docker pull tensorflow/tensorflow:latest-gpu-jupyter

# run a container
mkdir ~/Downloads/test/notebooks
docker run --name docker_thi_test -it --rm -v $(realpath ~/Downloads/test/notebooks):/tf/notebooks -p 8888:8888 tensorflow/tensorflow:latest-gpu-jupyter
# check if gpu available?
nvidia-smi

# check if tf2 working?
docker exec -it docker_thi_test bash
python
import tensorflow as tf
tf.config.list_physical_devices('GPU')

With docker-compose?

๐Ÿ‘‰ Read this note instead.

On Windows WSL2

Install directly on Linux (without docker)

On my computer, Dell XPS 15 7590 - NVIDIAยฎ GeForceยฎ GTX 1650 Mobile.

This section is not complete, the guide is still not working!

Installation

๐Ÿ‘‰ GPU support : TensorFlow

This guide is specific for:

pip show tensorflow # 2.3.1
pip show tensorflow-gpu # 2.3.1
nvidia-smi # NVIDIA-SMI 450.80.02 Driver Version: 450.80.02 CUDA Version: 11.0

๐Ÿ‘‰ PyTorch note.
๐Ÿ‘‰ Ubuntu note.
๐Ÿ‘‰ Linux note.

CUDA Toolkit:

  • If you meet Existing package manager installation of the driver found, try this method to remove some already-installed packages before continuing.
  • Or you can download cuda toolkit .run and then run
sudo sh cuda_11.1.0_*.run --toolkit --silent --override

Errors?

# Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory

Need to install new cuda & CUDNN libraries and tensorflow. (This note is for tensorflow==2.3.1 and CUDA 11.1). [ref]

# update path
export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib\
                         ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

# quickly test cuda version
nvcc --version

โ€ขNotes with this notation aren't good enough. They are being updated. If you can see this, you are so smart. ;)