Skip to content

Instantly share code, notes, and snippets.

@salehjg
Last active August 15, 2021 23:08
Show Gist options
  • Save salehjg/a70e51c2634de774cc7e9b71045ff2c6 to your computer and use it in GitHub Desktop.
Save salehjg/a70e51c2634de774cc7e9b71045ff2c6 to your computer and use it in GitHub Desktop.
install tensorflow for AMD GPUs tf v1 variant on ubuntu 18.04.3

Useful Links

https://github.com/ROCmSoftwarePlatform/tensorflow-upstream/blob/8520e9800c7cbda6418496c55bcd414621d616c8/rocm_docs/tensorflow-install-basic.md

https://pypi.org/project/tensorflow-rocm/#history

https://github.com/ROCmSoftwarePlatform/tensorflow-upstream

https://github.com/xuhuisheng/rocm-build/tree/master/gfx803

WARNING

AMD has dropped support for gfx803 (rx5xx family like rx570, rx580...) https://github.com/xuhuisheng/rocm-build/tree/master/gfx803

Distro

Tested with Ubuntu 18.04.2 LTS without installing any recent updates. No AMD specific software/driver is required to be installed beforehand.

$ uname -a
Linux linux1 4.18.0-15-generic #16~18.04.1-Ubuntu SMP Thu Feb 7 14:06:04 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Steps

It's all about finding the right dependency versions for the pre-compile binary downloaded from pip3.

wget -qO - http://repo.radeon.com/rocm/apt/debian/rocm.gpg.key | sudo apt-key add -

sudo sh -c 'echo deb [arch=amd64] http://repo.radeon.com/rocm/apt/3.0/ xenial main > /etc/apt/sources.list.d/rocm.list'

Above cmnds will install rocm v3.0 which works with tensorflow-rocm==1.15.1.

sudo apt-get update && sudo apt-get install -y \
  build-essential \
  clang \
  clang-format \
  clang-tidy \
  cmake \
  cmake-qt-gui \
  ssh \
  curl \
  apt-utils \
  pkg-config \
  g++-multilib \
  git \
  libunwind-dev \
  libfftw3-dev \
  libelf-dev \
  libncurses5-dev \
  libpthread-stubs0-dev \
  vim \
  gfortran \
  libboost-program-options-dev \
  libssl-dev \
  libboost-dev \
  libboost-system-dev \
  libboost-filesystem-dev \
  rpm \
  wget && \
  sudo apt-get clean && \
  sudo rm -rf /var/lib/apt/lists/*

Then install rocm (v 3.0 will be selected automatically)

sudo apt-get update && \
    sudo apt-get install -y --allow-unauthenticated \
    rocm-dkms rocm-dev rocm-libs rccl \
    rocm-device-libs \
    hsa-ext-rocr-dev hsakmt-roct-dev hsa-rocr-dev \
    rocm-opencl rocm-opencl-dev \
    rocm-utils 

Also install: sudo apt-get install miopen-hip

sudo adduser $LOGNAME video
sudo reboot

After that do:

sudo apt-get update && sudo apt-get install -y \
    python3-numpy \
    python3-dev \
    python3-wheel \
    python3-mock \
    python3-future \
    python3-pip \
    python3-yaml \
    python3-setuptools && \
    sudo apt-get clean && \
    sudo rm -rf /var/lib/apt/lists/*

Finally: sudo pip3 install tensorflow-rocm==1.15.1

Find the simple tf test script in this gist below to test the whole setup.

gl hf. :)

import tensorflow as tf
mat1 = [0,1,2]
mat2 = [2,1,0]
with tf.device('/gpu:0'):
tn1 = tf.placeholder(dtype= tf.int32, shape=[3])
tn2 = tf.placeholder(dtype= tf.int32, shape=[3])
tn3 = tn1 + tn2
with tf.Session() as sess:
result = sess.run(tn3,{tn1:mat1,tn2:mat2})
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment