ubuntu16.0.4 Tensorflow-GPU源码编译

在Ubuntu16.0.4上安装TensorFlow

我在不同的电脑上安装编译安装TensorFlow出现过很多问题,几次都没有成功,这次重装的ubuntu16.0.4系统。不知怎么的道成功了,特此记录下来。
本机安装了jdk1.8,最新版的bazel,clang5.0.1,cuda9.1,cudnn7
安装过程如下:

  • 获取tensorflow仓库https://github.com/tensorflow/tensorflow.git
    1. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64 按照TensorFlow说明之前需要安装sudo apt-get install cuda-command-line-tools但是安装的时候提示没有,于是没有安装。
  • 在tensorflow git源码中使用./configure配置,配置如下(下面的triSYCL在将仓库clone放到/usr/local/下面了)
 WARNING: Running Bazel server needs to be killed, because the startup options are different.
You have bazel 0.10.1- (@non-git) installed.
Please specify the location of python. [Default is /home/liushuai/anaconda3/bin/python]: 


Found possible Python library paths:
  /home/liushuai/anaconda3/lib/python3.6/site-packages
Please input the desired Python library path to use.  Default is [/home/liushuai/anaconda3/lib/python3.6/site-packages]

Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: y
jemalloc as malloc support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: y
Google Cloud Platform support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: y
Hadoop File System support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: y
Amazon S3 File System support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Apache Kafka Platform support? [y/N]: n
No Apache Kafka Platform support will be enabled for TensorFlow.

Do you wish to build TensorFlow with XLA JIT support? [y/N]: y
XLA JIT support will be enabled for TensorFlow.

Do you wish to build TensorFlow with GDR support? [y/N]: n
No GDR support will be enabled for TensorFlow.

Do you wish to build TensorFlow with VERBS support? [y/N]: y
VERBS support will be enabled for TensorFlow.

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: y
OpenCL SYCL support will be enabled for TensorFlow.

Please specify which C++ compiler should be used as the host C++ compiler. [Default is /usr/bin/g++]: 


Please specify which C compiler should be used as the host C compiler. [Default is /usr/bin/gcc]: 


Do you wish to build TensorFlow with ComputeCPP support? [Y/n]: n
No ComputeCPP support will be enabled for TensorFlow.

Please specify the location of the triSYCL include directory. (Use --config=sycl_trisycl when building with Bazel) [Default is /usr/local/triSYCL/include]: 


Do you wish to build TensorFlow with CUDA support? [y/N]: n
No CUDA support will be enabled for TensorFlow.

Do you wish to build TensorFlow with MPI support? [y/N]: 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]: 


The WORKSPACE file has at least one of ["android_sdk_repository", "android_ndk_repository"] already set. Will not ask to help configure the WORKSPACE. Please delete the existing rules to activate the helper.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See tools/bazel.rc for more details.
    --config=mkl            # Build with MKL support.
    --config=monolithic     # Config for mostly static monolithic build.
Configuration finished
  • 编译bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package知道编译出现如下消息:
INFO: From Compiling tensorflow/stream_executor/cuda/cuda_blas.cc:
tensorflow/stream_executor/cuda/cuda_blas.cc: In function 'cudaDataType_t perftools::gputools::cuda::{anonymous}::CUDAComputationType(perftools::gputools::blas::ComputationType)':
tensorflow/stream_executor/cuda/cuda_blas.cc:604:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
  bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 2236.355s, Critical Path: 150.89s
INFO: Build completed successfully, 4272 total actions
  • . 生成文件bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
    文件目录在/tmp/tensorflow_pkg/tensorflow-1.6.0rc1-cp36-cp36m-linux_x86_64.whl

tensorflow开启vers和gdr

之前在笔记本上编译了最新版本的tensorflow,但是没有开启VERBS,GDR,因为后续会报错缺少dma.h之类的错误,安装相应的软件包即可sudo apt install librdmacm-dev,加上caffe需要只支持cuda8,编译的时候经常提示出错,于是我又安装了cuda9.1然后cudnn7,因为cuda9.1生成/usr/local/cuda符号链接的时候是cuda8生成的,在cuda9.1提示生成符号连接/usr/local/cuda的时候选择了否。安装位置选在了/usr/cuda-9.1在本地bash或者zsh文件配置好环境变量。
于是在服务器上重新编译开启VERBS和GDR。即在VERBS和GDR选项选中y
服务器环境如下:

  • cpu:E5-2620
  • gpu:GTX1080×2
  • ubuntu16.04 64bit
    提前预装的软件有clang,cmake,bazel,java1.8。为了开启mkl加速,又安装了mkl(开启mkl需要config=mkl),编译如上。
    开启mpi需要安装openmpi(目录选择默认/usr/local)
    下面有预编译好的tensorflow-gpu,如果需要可以在我的网盘中下载,编译了不同功能的,具体细节查看readme.md网盘 密码: ez2b

猜你喜欢

转载自blog.csdn.net/bleedingfight/article/details/79377921