Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@daveselinger
Last active April 27, 2018 00:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveselinger/54f5c131064555ab53c8ded1c00f842a to your computer and use it in GitHub Desktop.
Save daveselinger/54f5c131064555ab53c8ded1c00f842a to your computer and use it in GitHub Desktop.
Ubuntu 16.04 AMD + OpenCL + Theano + Keras from scratch (IN PROGRESS)
## Shout out to jarutis here https://gist.github.com/jarutis/ff28bca8cfb9ce0c8b1a
## install Catalyst proprietary
## sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.BAK
# on a clean install not needed but could be helpful
sudo apt-get remove --purge fglrx*
#
sudo add-apt-repository ppa:oibaf/graphics-drivers
sudo apt update
sudo apt install mesa-vdpau-drivers
sudo apt install mesa-opencl-icd
## install build essentials
sudo apt install linux-headers-generic cmake build-essential git
# Some mesa drivers can get upgraded
sudo apt upgrade
## Need to download this from here: http://developer.amd.com/amd-accelerated-parallel-processing-app-sdk/
# because it requires a browser, you can either download using Xwindows, or I download on my mac and then SCP it to the machine:
# scp ~/Downloads/AMD-APP-SDKInstaller-v3.0.130.136-GA-linux32.tar.bz2 ubuntu@IPADDRESS_x.xx.xx.xx:~/Downloads
## install AMD APP SDK from ~/Downloads
## Accept the license and install in /opt
cd ~/Downloads
tar xjf AMD-APP-SDKInstaller-v3.0.130.136-GA-linux64.tar.bz2
sudo ./AMD-APP-SDK-v3.0.130.136-GA-linux64.sh
## install libgpuarray
sudo apt-get install libboost-all-dev libgtest-dev
cd /usr/src/gtest
sudo mkdir build
cd build
sudo cmake ..
sudo make
sudo mv libg* /usr/lib/
## download AMD acml library
### mkdir ~/Ini
#### tar -xvf acml-6.1.0.31-gfortran64.tgz -C ~/Ini/acml
#### echo "###################################################################" >> ~/.bashrc
###### echo "export ACML_ROOT=/home/jjarutis/Ini/acml" >> ~/.bashrc
###### export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"/home/jjarutis/Ini/acml/gfortran64/lib" >> ~/.bashrc
# clBlas dependency...
sudo apt install libclblas2 libclblas-bin libclblas-dev libclblas-doc
sudo update-pciids
cd ~/Downloads
git clone https://github.com/Theano/libgpuarray.git
cd libgpuarray
git checkout v0.6.9
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DOPENCL_INCLUDE_DIRS=/opt/AMDAPPSDK-3.0/include/
make
sudo make install
cd ..
sudo apt install python-dev python3-dev python-pip python3-pip python-nose python3-nose g++ libopenblas-dev
sudo pip install cython numpy scipy
sudo pip3 install cython numpy scipy
python3 setup.py build
sudo python3 setup.py install
python setup.py build
sudo python setup.py install
## Theano
sudo pip install Theano
sudo pip3 install Theano
## Now for some reason the libgpu shared objects end up in /usr/local/lib and python only looks in /usr/lib by default so... :)
sudo mv /usr/local/lib/libgpuarray* /usr/lib
## Now it appears we need to install ffi
sudo apt install libffi-dev
sudo pip3 install cffi==1.5.2
sudo pip3 install pyopencl
sudo pip install cffi==1.5.2
sudo pip install pyopencl
THEANO_FLAGS=device=opencl0:0 python test.py
THEANO_FLAGS=device=opencl0:0 python3 test.py
@chingwayip
Copy link

This works for libgpuarray v0.6.9 and theano 0.9.0!

@chingwayip
Copy link

chingwayip commented Sep 7, 2017

To use this to run the on-board Asus Intel HD graphics card (after OpenCL installation):

  1. Install libgpuarray v0.6.9 only, as above
  2. Install Theano 0.10.0b1

@ShiangYong
Copy link

ShiangYong commented Sep 27, 2017

For Snapdragon, replace
pip install cython
with
sudo pip install Cython --install-option="--no-cython-compile"

@nullwiz
Copy link

nullwiz commented Feb 12, 2018

How can we get this to work with Ubuntu 16.04 and newer radeon cards since the drivers update?

@herossa
Copy link

herossa commented Apr 27, 2018

where did you find the file acml-6.1.0.31-gfortran64.tgz?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment