Overview
This guide takes a fresh Ubuntu 18.04 install and gets us to the point of building Tensorflow 2 Alpha with Nvidia GPU support and the following configuration:
- Nvidia drivers 418
- CUDA 10.0
- CUDNN 7.5
Nvidia drivers
Assuming you don’t have secure boot enabled, this is sufficient:
sudo add-apt-repository ppa:graphics-drivers sudo apt update sudo apt install nvidia-driver-418 sudo reboot
If you do have secure boot enabled, see here for some recommendations.
CUDA 10.0
Go the downloads page, and select Linux, x86_64, Ubuntu, 18.04, deb (network). Download the network installer and follow the installation instructions provided.
In your ~/.bashrc or ~/.profile, add to your binary and dynamic linker search path:
export PATH=$PATH:/usr/local/cuda/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64
CUDNN 7.5
Go the CUDNN downloads page, registering as a developer and blindly agreeing to various terms if necessary. Select “Download cuDNN v7.5.0 (Feb 21, 2019), for CUDA 10.0” and then download both “cuDNN Runtime Library for Ubuntu18.04 (Deb)” and “cuDNN Developer Library for Ubuntu18.04 (Deb)”. Install the runtime library first:
sudo dpkg -i libcudnn7_7.5.0.56-1+cuda10.0_amd64.deb
Then install the development library:
sudo dpkg -i libcudnn7-dev_7.5.0.56-1+cuda10.0_amd64.deb
Bazel 0.23.0
Install Bazel to ~/bin:
sudo apt install pkg-config zip g++ zlib1g-dev unzip python wget https://github.com/bazelbuild/bazel/releases/download/0.23.0/bazel-0.23.0-installer-linux-x86_64.sh chmod +x bazel-0.23.0-installer-linux-x86_64.sh ./bazel-0.23.0-installer-linux-x86_64.sh --user
In your ~/.bashrc or ~/.profile, add the installation location to your binary search path:
export PATH=$PATH:~/bin
Python prerequisites
Set up and enter a Python virtual environment:
sudo apt install python3 python3-dev python3-pip python3-venv python -m venv ~/envs/tf2 source ~/envs/tf2/bin/activate
Install the Python dependencies:
pip install -U pip six numpy wheel setuptools mock pip install -U keras_applications==1.0.6 pip install -U keras_preprocessing==1.0.5
Building
Fetch Tensorflow:
sudo apt install git git clone https://github.com/tensorflow/tensorflow.git cd tensorflow
Check out the desired tag:
git checkout v2.0.0-alpha0
Make sure your ~/bashrc or ~/.profile has been invoked so that the binary and dynamic linker paths are available.
Configure, e.g.:
$ ./configure WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown". You have bazel 0.23.0 installed. Please specify the location of python. [Default is /home/mikl/envs/tf2/bin/python]: Found possible Python library paths: /home/mikl/envs/tf2/lib/python3.6/site-packages Please input the desired Python library path to use. Default is [/home/mikl/envs/tf2/lib/python3.6/site-packages] Do you wish to build TensorFlow with XLA JIT support? [Y/n]: XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with ROCm support? [y/N]: No ROCm support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10.0]: Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: Do you wish to build TensorFlow with TensorRT support? [y/N]: No TensorRT support will be enabled for TensorFlow. Please specify the locally installed NCCL version you want to use. [Default is to use https://github.com/nvidia/nccl]: Please specify a list of comma-separated CUDA compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size, and that TensorFlow only supports compute capabilities >= 3.5 [Default is: 6.1]: Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. --config=gdr # Build with GDR support. --config=verbs # Build with libverbs support. --config=ngraph # Build with Intel nGraph support. --config=numa # Build with NUMA support. --config=dynamic_kernels # (Experimental) Build kernels into separate shared objects. Preconfigured Bazel build configs to DISABLE default on features: --config=noaws # Disable AWS S3 filesystem support. --config=nogcp # Disable GCP support. --config=nohdfs # Disable HDFS support. --config=noignite # Disable Apache Ignite support. --config=nokafka # Disable Apache Kafka support. --config=nonccl # Disable NVIDIA NCCL support. Configuration finished
Create the python package builder, assuming a system without much RAM to spare:
bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --local_resources 2048,.5,1.0
Build the package:
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Install it:
pip install /tmp/tensorflow_pkg/tensorflow-2.0.0a0-cp36-cp36m-linux_x86_64.whl