Ubuntu16.04源码安装TensorFlow

在进行TensorFlow测试,想得到最优的性能,学习TensorFlow相关文档,源码编译会得到更好的性能

Building and installing from source

The default TensorFlow binaries target the broadest range of hardware to make TensorFlow accessible to everyone. If using CPUs for training or inference, it is recommended to compile TensorFlow with all of the optimizations available for the CPU in use. Speedups for training and inference on CPU are documented below in Comparing compiler optimizations.

To install the most optimized version of TensorFlow, @{$install_sources$build and install} from source If there is a need to build TensorFlow on a platform that has different hardware than the target, then cross-compile with the highest optimizations for the target platform. The following command is an example of using bazel to compile for a specific platform:

# This command optimizes for Intel’s Broadwell processor
bazel build -c opt --copt=-march="broadwell" --config=cuda //tensorflow/tools/pip_package:build_pip_package
Environment, build, and install tips
  • ./configure asks which compute capability to include in the build. This does not impact overall performance but does impact initial startup. After running TensorFlow once, the compiled kernels are cached by CUDA. If using a docker container, the data is not cached and the penalty is paid each time TensorFlow starts. The best practice is to include thecompute capabilities of the GPUs that will be used, e.g. P100: 6.0, Titan X (Pascal): 6.1, Titan X (Maxwell): 5.2, and K80: 3.7.
  • Use a version of gcc that supports all of the optimizations of the target CPU. The recommended minimum gcc version is 4.8.3. On OS X, upgrade to the latest Xcode version and use the version of clang that comes with Xcode.
  • Install the latest stable CUDA platform and cuDNN libraries supported by TensorFlow.

(https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/performance/performance_guide.md#building-and-installing-from-source)

因此考虑源码安装

========================================================================

下面放出我的安装过程,写的不太规范,也有吐槽的。。


1. 安装bazel

参考官网 https://docs.bazel.build/versions/master/install-ubuntu.html

其实首先是想按照 Installing using binary installer 方式安装的,奈何下载***.sh这个文件实在太慢,因此改为Using Bazel custom APT repository方式安装


bazel-install.sh

#!/bin/bash
echo "Install JDK 8"
./jdk8-install.sh
echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
curl https://bazel.build/bazel-release.pub.gpg | apt-key add -
echo "Install and update Bazel"
apt-get update && apt-get install bazel
echo "bazel version:"
bazel version


jdk8-install.sh

#!/bin/bash
apt-get install openjdk-8-jdk
java -version

2. TF 依赖包
参考 https://www.jianshu.com/p/636c6477250a

check.sh

#!/bin/bash
apt-get update&&sudo apt-get install -y \
build-essential \
curl \
libcurl3-dev \
git \
libfreetype6-dev \
libpng12-dev \
libzmq3-dev \
pkg-config \
python-dev \
python-numpy \
python-pip \
software-properties-common \
swig \
zip \
zlib1g-dev

添加环境变量到 ~/.bashrc

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda-8.0/extras/CUPTI/lib64"
这个其实我也不知道有啥用,但参考好多博客里都写上去了,我也就加上去了。。。

另外,我原本的环境变量是

export PATH="$PATH:/usr/local/cuda-8.0/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64:/usr/local/lib"

3. 源码安装TensorFlow


其实参考了好多博主的博客,因为比较多就不在这里放了,不过其实TensorFlow官方写的也比较详细了

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/install/install_sources.md


(1)下载源码

git clone --recurse-submodules  http://github.com/tensorflow/tensorflow
其中–recurse-submodules 参数是必须的, 用于获取 TesorFlow 依赖的 protobuf 库.

(2)配置TensorFlow
cd ~/tensorflow  
./configure 

下边有一个选项是关于选择CPU类型的:

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值