2016年7月5日 星期二

build tensorflow from soruce on ubuntu 15.10 with GPU (ComputeCapability 3.0)

follow http://www.alexanderclines.net/howto/how-to-cuda-toolkit-7-5-on-ubuntu-15-10/


 1. install cuda


download file from https://developer.nvidia.com/cuda-downloads


sudo dpkg -i cuda-repo-ubuntu1504-7-5-local_7.5-18_amd64.deb

sudo apt-get update

sudo apt-get install cuda

export PATH=/usr/local/cuda-7.5/bin/:$PATH

export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH

1.1 download cudnn



https://developer.nvidia.com/cudnn

tar xvzf cudnn-7.5-linux-x64-v4.tgz
sudo cp cudnn-7.5-linux-x64-v4/cudnn.h /usr/local/cuda/include
sudo cp cudnn-7.5-linux-x64-v4/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*



2. change gcc to gcc4.9


sudo apt-get install gcc-4.9

sudo apt-get install g++-4.9

sudo ln -s /usr/bin/gcc-4.9 /usr/local/cuda/bin/gcc

sudo ln -s /usr/bin/g++-4.9 /usr/local/cuda/bin/g++

3. install python library numpy + spicy


pip install --upgrade setuptools

pip install numpy

pip install spicy

and use "pip list" check it was installed successful or not

4. git clone tensorflow

5. install bazel


http://www.bazel.io/docs/install.html#install-on-ubuntu

 


6. build tensorflow


TF_UNOFFICIAL_SETTING=1 ./configure    //TF_UNOFFICIAL for ComputeCapability == 3.0

bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer





issue 1:


gcc: error trying to exec 'cc1plus': execvp: No such file or directory



sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.9/cc1plus  /usr/local/bin/

sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.9/cc1  /usr/local/bin/

sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/4.9/collect2  /usr/local/bin/


edit "third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc"

before
return subprocess.call([CPU_COMPILER] + cpu_compiler_flags )

add:

 cpu_compiler_flags.append('-I/usr/lib/gcc/x86_64-linux-gnu/4.9/include/')
 cpu_compiler_flags.append('-I/usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed/')




issue 2:


gcc: fatal error: -fuse-linker-plugin, but liblto_plugin.so not found

solution:

sudo cp /usr/lib/gcc/x86_64-linux-gnu/ /usr/bin/ -r


issue 3;

undefined reference to `ceil'

solution:

add cpu_compiler_flags.append('-lm')





issue 4:


INFO: From Compiling tensorflow/core/kernels/dense_update_ops_gpu.cu.cc:

nvcc warning : option '--relaxed-constexpr' has been deprecated and replaced by option '--expt-relaxed-constexpr'

gcc: error trying to exec 'as': execvp: No such file or directory
ERROR: /home/zakk/tensorflow/tensorflow/core/kernels/BUILD:1458:1: output 'tensorflow/core/kernels/_objs/batchtospace_op_gpu/tensorflow/core/kernels/batchtospace_op_gpu.cu.o' was not created.
ERROR: /home/zakk/tensorflow/tensorflow/core/kernels/BUILD:1458:1: not all outputs were created.

 solution:
edit "third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc"

mask below code will be workable
# TODO(zhengxq): for some reason, 'gcc' needs this help to find 'as'.
# Need to investigate and fix.
#cmd = 'PATH=' + PREFIX_DIR + ' ' + cmd