Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install TensorFlow from source on Ubuntu 16.04 with GPU support
#Ubuntu 16.04
#GPU - Nvidia GTX 750 Ti
#CUDA - 8.0, cuDNN - 5.1
#Prerequisite - Download cuDNN 5.1 tarball from https://developer.nvidia.com/rdp/cudnn-download to home directory
if [ ! -f "cudnn-8.0-linux-x64-v5.1.tgz" ]
then
echo "cudnn-8.0-linux-x64-v5.1.tgz not found"
exit 1
fi
#Create a installation directory
mkdir ~/tensorflowinstallation
cd ~/tensorflowinstallation
#Get cuda from nvidia and install
echo "Installing CUDA\n\n"
wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
mv cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb
sudo apt install -f
sudo apt update
sudo apt install cuda
#Extract cuDNN and copy to cuda installation directory
echo "Installing cuDNN\n\n"
mv ~/cudnn-8.0-linux-x64-v5.1.tgz .
tar -xvzf cudnn-8.0-linux-x64-v5.1.tgz
cd cudnn
sudo cp -P include/cudnn.h /usr/local/cuda-8.0/include
sudo cp -P lib64/libcudnn* /usr/local/cuda-8.0/lib64/
sudo chmod a+r /usr/local/cuda-8.0/lib64/libcudnn*
echo "export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64" >> ~/.bashrc
echo "export CUDA_HOME=/usr/local/cuda" >> ~/.bashrc
source ~/.bashrc
#Clone and build tensorflow
echo "Installing Tensorflow -> Specify cuDNN as 5\n\n"
cd ..
git clone https://github.com/tensorflow/tensorflow
cd tensorflow
sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel
sudo apt-get install libcupti-dev
./configure
bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo -H pip3 install /tmp/tensorflow_pkg/*.whl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment