Building Tensorflow-GPU from source for RTX 2080
Today lets look at how to build a Tensorflow-GPU pip package for the newly available GeForce RTX 2080. The reason behind compiling a custom build will give us the leverage of all the optimizations that are done during the build as well as the major reason being all the available TF-gpu packages till date are built using CUDA-9 and CuDNN 7.3.1. The major issue being CUDA-9 is not aware of the latest GeForce RTX 2080 and its architecture hence when you run a program with TF as backend it shows segmentation fault.
Although I have custom built with many required installations recently I found a github repository which has a bash script which automates all the bull work for this purpose.
STEP 1: Install the required Graphics Driver and CUDA Toolkit 10
This can be done by downloading the run file for Ubuntu 16.04 from here and for Ubuntu 18.04 from here. Now to install the CUDA 10 Toolkit you have to stop the lightdm service first which can be done by issuing the following commands
CTRL + ALT + F1sudo service lightdm stopcd /path/to/the/run/file/sudo sh cuda_10.0.130_410.48_linux.run
Now after the installation of the CUDA Toolkit 10 and the Driver reboot the system
After successful login into the system, run this command in the terminal
nvidia-smi
The output should look something like this
If that is successful run the following commands to add the set the PATHs
sudo echo >> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64sudo echo >> export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}sudo echo >> export PATH=/usr/local/cuda/lib64${PATH:+:${PATH}}sudo echo >> export PATH=~/anaconda3/bin:$PATHsudo echo >> export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATHsudo echo >> export PATH="$PATH:$HOME/bin"sudo echo >> export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
Open a new terminal and run this following command:
nvcc -V
The output should look something like this
Install the CuDNN 7.3.1 deb file by downloading the file from here (you will have to login/create an account)
Install it by issuing the following command
sudo dpkg -i /path/to/the/deb/file/
Install the NCCL deb file by downloading the file from here (you will have to login/create an account)
Install it by issuing the following command
sudo dpkg -i /path/to/the/deb/file/
If you have reached till this point then proceed to step-2
STEP 2: Installing the prerequisites and building the tf-gpu pip file
Download bezel and prerequisites
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python3=3.5.1 curl pip3curl https://github.com/bazelbuild/bazel/releases/download/0.18.0/bazel-0.18.0-installer-linux-x86_64.shchmod +x bazel-0.18.0-installer-linux-x86_64.sh./bazel-0.18.0-installer-linux-x86_64.shexport PATH="$PATH:$HOME/bin"sudo echo export PATH="$PATH:$HOME/bin" >> .bashrc
Download the TensorFlow source code and configure the bezel build accordingly
git clone https://github.com/tensorflow/tensorflow.gitcd tensorflowgit checkout r1.11./configure
Bazel Build (This will take quite some time, sit down sip some coffee)
bazel build --config=opt --config=cuda --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" //tensorflow/tools/pip_package:build_pip_package
Build the package. The following builds a .whl
package in the /tmp/tensorflow_pkg
directory copy this to any place you want.
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
STEP 3: Anaconda and installing custom TF-GPU build
Now install Anaconda and install this .whl package using pip within the virtual env of your choice
Pip may show errors with missing packages and incompatible versions correct them manually and you are ready to go
P.S : Clap if this guide was useful. the pre-compiled whl package for tensorflow-gpu-cuda10-cuDnn7.3.1 python 3.5.2 is available here