How to install TensorFlow with GPU support for AMD on Debian Buster

The ordinary version of TensorFlow only supports Nvidia CUDA enabled graphic cards, which sucks for us AMD users – but there is a solution! We will be using the open source ROCM project (https://rocm.github.io/) (https://www.amd.com/en/graphics/servers-solutions-rocm).

First we get the needed key and add the source.

wget -qO - http://repo.radeon.com/rocm/apt/debian/rocm.gpg.key | sudo apt-key add echo 'deb [arch=amd64] http://repo.radeon.com/rocm/apt/debian/ xenial main' | sudo tee /etc/apt/sources.list.d/rocm.list sudo apt update
Code language: PHP (php)

Check if your user is a part of the video-group, if not – add it.

groups myuser

Now we install the needed packages and kernel module.

sudo apt install rocm-dkms rocm-libs hipcub miopen-hip sudo reboot

Let’s check if it works.

/opt/rocm/bin/rocminfo

It’s time to install the tensorflow-rocm package using pip.

pip3 install --user tensorflow-rocm --upgrade

Done! Now we can test a hello world example (stolen from https://github.com/aymericdamien/TensorFlow-Examples/).

''' HelloWorld example using TensorFlow library. Author: Aymeric Damien Project: https://github.com/aymericdamien/TensorFlow-Examples/ ''' from __future__ import print_function import tensorflow.compat.v1 as tf tf.disable_v2_behavior() # Simple hello world using TensorFlow # Create a Constant op # The op is added as a node to the default graph. # # The value returned by the constructor represents the output # of the Constant op. hello = tf.constant('Hello, TensorFlow!') # Start tf session sess = tf.Session() # Run the op print(sess.run(hello))
Code language: Python (python)

It’s working! I got the following output.

>WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow_core/python/compat/v2_compat.py:65: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. >Instructions for updating: >non-resource variables are not supported in the long term >2020-01-28 11:59:20.257996: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libhip_hcc.so >2020-01-28 11:59:20.304648: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1629] Found device 0 with properties: >name: Ellesmere [Radeon RX 470/480/570/570X/580/580X/590] >AMDGPU ISA: gfx803 >memoryClockRate (GHz) 1.366 >pciBusID 0000:08:00.0 >2020-01-28 11:59:20.470758: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library librocblas.so >2020-01-28 11:59:20.487690: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libMIOpen.so >2020-01-28 11:59:20.498248: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library librocfft.so >2020-01-28 11:59:20.505408: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library librocrand.so >2020-01-28 11:59:20.505622: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0 >2020-01-28 11:59:20.506136: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA >2020-01-28 11:59:20.513473: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3792680000 Hz >2020-01-28 11:59:20.514304: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x519fb60 executing computations on platform Host. Devices: >2020-01-28 11:59:20.514340: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version >2020-01-28 11:59:20.514497: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1629] Found device 0 with properties: >name: Ellesmere [Radeon RX 470/480/570/570X/580/580X/590] >AMDGPU ISA: gfx803 >memoryClockRate (GHz) 1.366 >pciBusID 0000:08:00.0 >2020-01-28 11:59:20.514536: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library librocblas.so >2020-01-28 11:59:20.514548: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libMIOpen.so >2020-01-28 11:59:20.514559: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library librocfft.so >2020-01-28 11:59:20.514569: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library librocrand.so >2020-01-28 11:59:20.514629: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0 >2020-01-28 11:59:20.514690: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix: >2020-01-28 11:59:20.514702: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165] 0 >2020-01-28 11:59:20.514709: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0: N >2020-01-28 11:59:20.514837: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7539 MB memory) -> physical GPU (device: 0, name: Ellesmere [Radeon RX 470/480/570/570X/580/580X/590], pci bus id: 0000:08:00.0) >b'Hello, TensorFlow!'
Code language: JavaScript (javascript)