Tensorflow

The fastest and more reliable method to get ROCm + Tensorflow backend to work is to use the docker image provided by AMD developers. - Train neural networks using AMD GPU and Keras

Tensorflow Docker

Create a persistent space

It is useful to create a persistent space in the physical drive for storing files and Jupyter notebooks.

mkdir /home/$LOGNAME/tf_docker_share
docker run \
      -it \
      --network=host \
      --device=/dev/kfd \
      --device=/dev/dri \
      --ipc=host \
      --shm-size 16G \
      --group-add video \
      --cap-add=SYS_PTRACE \
      --security-opt seccomp=unconfined \
      --workdir=/tf_docker_share \
      -v $HOME/tf_docker_share:/tf_docker_share \
      rocm/tensorflow:latest bash

Running Jupyter from docker

jupyter notebook --allow-root --port=8889

Then click on link displayed in terminal (terminator) to open it in a browser outside of docker image.

Using GPU

Check Nb of GPU available

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

Tensorflow Benchmark

python3 tf_cnn_benchmarks.py --num_gpus=1 --batch_size=32 --model=resnet50
...
Done warm up
Step	Img/sec	total_loss
1	images/sec: 81.8 +/- 0.0 (jitter = 0.0)	7.750
10	images/sec: 82.3 +/- 0.1 (jitter = 0.2)	8.071
20	images/sec: 82.3 +/- 0.1 (jitter = 0.1)	7.801
30	images/sec: 82.3 +/- 0.0 (jitter = 0.3)	8.001
Written on September 6, 2020, Last update on January 29, 2023
AI NN tensorflow amd gpu