How to build TensorFlow GPU from Source Code

Environment

Date: 2018.11.28
OS: Ubuntu 18.04
Graphic Card: NVIDIA Geforce 2080ti
Python: 3.6.7

NVIDIA Drive & Cuda 10.0

rm /etc/apt/sources.list.d/cuda*;
apt remove nvidia-cuda-toolkit;
apt remove nvidia-*;
apt update;

apt-key adv –fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub;
bash -c ‘echo “deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /” > /etc/apt/sources.list.d/cuda.list’;
apt update;
apt install nvidia-driver-410;

apt install cuda-10-0;

[.bashrc]
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

nvcc -V;

nvidia-smi;

cat /proc/driver/nvidia/version;

chmod 777 /usr/local/cuda/samples -R;
cd /usr/local/cuda/samples;
make -j48;
cd /usr/local/cuda/samples/bin/x86_64/linux/release;
./deviceQuery;
./bandwidthTest;

cuDNN

cd ~/Downloads;
tar xvfz cudnn-10.0-linux-x64-v7.4.1.5.tgz;
cp cuda/include/* /usr/local/cuda/include;
cp -d cuda/lib64/* /usr/local/cuda/lib64;
chmod a+r /usr/local/cuda/include/cudnn.h;
chmod a+r /usr/local/cuda/lib64/libcudnn*;
rm -rf cuda;

TensorRT

cd ~/Downloads;
dpkg -i nv-tensorrt-repo-ubuntu1804-cuda10.0-trt5.0.2.6-ga-20181009_1-1_amd64.deb;
apt-key add /var/nv-tensorrt-repo-cuda10.0-trt5.0.2.6-ga-20181009/7fa2af80.pub;
apt-get update;
apt-get install tensorrt;
apt-get install python3-libnvinfer-dev;
apt-get install uff-converter-tf;
dpkg -l | grep TensorRT;

NCCL

cd ~/Downloads;
dpkg -i nccl-repo-ubuntu1804-2.3.7-ga-cuda10.0_1-1_amd64.debj
apt update;
apt install libnccl2 libnccl-dev;
dpkg -l | grep nccl

OpenCL

apt install ocl-icd-*;
apt install opencl-headers;

ComputeCPP

cd ~/Downloads;
tar xvfz ComputeCpp-CE-1.0.2-Ubuntu.16.04-64bit.tar.gz;
cd ComputeCpp-CE-1.0.2-Ubuntu-16.04-x86_64;

cp -P bin/* /usr/local/bin;
cp -r doc/* /usr/local/share;
cp -r include/* /usr/local/include;
cp lib/libComputeCpp.so /usr/local/lib;
cp lib/pkgconfig/* /usr/local/lib/pkgconfig;

cd ..;
rm -rf ComputeCpp-CE-1.0.2-Ubuntu-16.04-x86_64;

[.bashrc]
export TF_NEED_OPENCL=1
export HOST_CXX_COMPILER=/usr/bin/g++
export HOST_C_COMPILER=/usr/bin/gcc
export COMPUTECPP_TOOLKIT_PATH=/usr/local
export COMPUTE=:0

computecpp_info;

Bazel

cd ~/Downloads;
apt-get install pkg-config zip g++ zlib1g-dev unzip python;
./bazel-0.19.2-installer-linux-x86_64.sh;

echo “deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8” | sudo tee /etc/apt/sources.list.d/bazel.list;
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -;
apt-get update;
apt-get install bazel;
apt-get install bazel;
apt-get install –only-upgrade bazel;

bazel version;

Keras

pip install -U –user keras_applications==1.0.0 –no-deps;
pip install -U –user keras_applications==1.0.1 –no-deps;
pip install -U –user keras_applications==1.0.2 –no-deps;
pip install -U –user keras_applications==1.0.4 –no-deps;
pip install -U –user keras_applications==1.0.5 –no-deps;
pip install -U –user keras_applications==1.0.6 –no-deps;

TensorFlow

cd /home/wanhochoi/Downloads;
git clone https://github.com/tensorflow/tensorflow.git;
cd tensorflow;

./configure;
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3
Please input the desired Python library path to use. Default is [/usr/lib/python3.6/dist-packages]: [ENTER]
Do you wish to build TensorFlow with XLA JIT support? [Y/n]: Y
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: N
Do you wish to build TensorFlow with ROCm support? [y/N]: N
Do you wish to build TensorFlow with CUDA support? [y/N]: y
Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 9.0]: 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]: [ENTER]
Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: [ENTER]
Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: [ENTER]
Do you wish to build TensorFlow with TensorRT support? [y/N]: y
Please specify the location where TensorRT is installed. [Default is /usr/lib/x86_64-linux-gnu]: [ENTER]
Please specify the locally installed NCCL version you want to use. [Default is to use https://github.com/nvidia/nccl]: [ENTER]
Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 7.5]: [ENTER]
Do you want to use clang as CUDA compiler? [y/N]: N
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: [ENTER]
Do you wish to build TensorFlow with MPI support? [y/N]: N
Please specify optimization flags to use during compilation when bazel option “–config=opt” is specified [Default is -march=native -Wno-sign-compare]: [ENTER]
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: N

bazel build –config=opt –config=cuda //tensorflow/tools/pip_package:build_pip_package;

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg;

pip install /tmp/tensorflow_pkg/tensorflow-1.12.0rc0-cp36-cp36m-linux_x86_64.whl;

[.bashrc]
export TF_CPP_MIN_LOG_LEVEL=2

Add a Comment