Thursday, January 4, 2018

Install Tensorflow for CUDA 9 without root

At the moment latest Tensorflow 1.4 does not yet support Cuda 9.0. This tutorial is about how to install Tensorflow that uses Cuda 9.0 without root access.

Create a temp folder to install download sources into:
mkdir downloads
cd downloads

Building and installing CMake:
The easiest way to install CMake is from source. Head over to the CMake downloads page and get the latest “Unix/Linux Source” *.tar.gz file.

tar -xf cmake*.tar.gz
cd cmake*
./configure --prefix=$HOME
make install

You should now have the most up-to-date installation of cmake. Check the version by typing:
cmake --version

Building MKL locally without root access:
The Tensorflow wheels that we are going to install later on in this tutorial contain MKL support. If you don't have it, install MKL as follows. MKL is Intel's deep learning kernal library, which makes training neural nets on CPU much faster. If you don't have it, install it like the following:

git clone
cd mkl-dnn/scripts && ./ && cd ..
mkdir -p build && cd build && cmake .. && make
make install

At the last step, it's expected to get an error because without root access the output library can't be copied to system roots:
CMake Error at cmake_install.cmake:41 (file):
file INSTALL cannot copy file
to "/usr/local/lib/".

To fix it, lets add it manually to the shared libraries environment variable each time a bash script is opened by adding the following line to the file "home/your_user_name/.bashrc":

export LD_LIBRARY_PATH=/home/heraqi/downloads/mkl-dnn/external/mklml_lnx_2018.0.1.20171227/lib/:$LD_LIBRARY_PATH

Install Tensorflow CUDA 9.0 wheel:
Download a wheel files that support CUDA 9.0 and install it:

pip install

Usually use conda to allow a local installation for your Python distribution because if you are not root, pip call will fail.

You have successfully installed Tensorflow for CUDA 9 without root until Google supports it :)