从源码编译TensorFlow

新的cudnnV6出了很久了,但是1.2的还不支持
就想自己编译一个
按照官方的教程试一下,记录在此
本人环境 GTX1080; i7 7700k; gcc 5.4; cuda8.0; cudnn6.0。 使用的是TF1.2
首先装Bazel,Google就是喜欢定标准啊哈哈

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 -
sudo apt-get update && sudo apt-get install bazel

随后如果想更新,那么

sudo apt-get upgrade bazel

然后切换到源码目录,我觉得git好慢就直接下载压缩包解压了。。
执行 ./configure 可得如下
目前具体的参数设置我还没研究,姑且这么搞吧
现在是GTX1080,所以计算能力6.1 cudnn我已经替换成6.0版本了,貌似它都可以检测到,直接默认即可

You have bazel 0.5.2 installed.
Please specify the location of python. [Default is /home/hzy/anaconda3/bin/python]: 
Found possible Python library paths:
  /home/hzy/anaconda3/lib/python3.6/site-packages
Please input the desired Python library path to use.  Default is [/home/hzy/anaconda3/lib/python3.6/site-packages]

Using python library path: /home/hzy/anaconda3/lib/python3.6/site-packages
Do you wish to build TensorFlow with MKL support? [y/N] n
No MKL 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]: 
Do you wish to use jemalloc as the malloc implementation? [Y/n] y
jemalloc enabled
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] n
No 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 the XLA just-in-time compiler (experimental)? [y/N] n
No XLA JIT 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 support? [y/N] n
No OpenCL 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
Do you want to use clang as CUDA compiler? [y/N] n
nvcc will be used as CUDA compiler
Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 8.0]: 
Please specify the location where CUDA  toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: 
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: 
Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 6.0]: 
Please specify the location where cuDNN  library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: 
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.
[Default is: "6.1"]: 
Do you wish to build TensorFlow with MPI support? [y/N] n
MPI support will not be enabled for TensorFlow
Configuration finished

这个介绍就提示你一下finished,接下来重头戏。
build时候官网提示,如果是gcc5或者更高版本的话,请加上后面--cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"这句。

bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package  --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"

编译过程还是很漫长的。。
我这个显示INFO: Elapsed time: 1320.414s, Critical Path: 130.33s
然后

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

OK 这就生成了whl文件了,我们切换路径到/tmp/tensorflow_pkg, ls一下看到
tensorflow-1.2.0-cp36-cp36m-linux_x86_64.whl
pip install 一下
这里写图片描述
一颗赛艇,安装成功! import一下试试,发现惨遭翻车,下面是车祸现场

ImportError: /home/hzy/anaconda3/bin/../lib/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /home/hzy/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

Google一下,感谢曾冠奇的解决方案~

I solved this problem by copying the libstdc++.so.6 file which contains version CXXABI_1.3.8.

Try run the following search command first:

$ strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep CXXABI_1.3.8

If it returns CXXABI_1.3.8. Then you can do the copying.

$ cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /home/jj/anaconda2/bin/../lib/libstdc++.so.6

吼 大功告成,待随后测试
这里写图片描述

补充:
cool 我试了下编译1.1的,configure选项和1.2有些不同,似乎无法支持cudnn6.0 。编译了下,它的计算能力默认支持的是3.5和5.2,针对1080我加入了6.1。其他有一些支持hadoop和谷歌云计算的选项。耗时Elapsed time: 1145.992s, Critical Path: 127.80s
1.0的耗时Elapsed time: 1211.101s, Critical Path: 243.46s
所以在1.0 1.1时代,直接用预编译好的版本基本就可以,推荐清华源的。1.2的话根据个人喜好可以自行编译~~这些编译好的我整理后发布在我的github上,同时做一份国内的百度云分享,欢迎使用提issue~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值