tensorflow源码编译安装

1. 安装 Bazel

在安装 bazel 时,要先安装 JDK8(按照官方网站安装就没问题:(here)

2. Install JDK 8

Install JDK 8 by using:

sudo apt-get install openjdk-8-jdk

On Ubuntu 14.04 LTS you'll have to use a PPA:

sudo add-apt-repository ppa:webupd8team/javasudo apt-get update && sudo apt-get install oracle-java8-installer

3. Add Bazel distribution URI as a package source (one time setup)

echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.listcurl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -

If you want to install the testing version of Bazel, replace stable withtesting.

4. Install and update Bazel

sudo apt-get update && sudo apt-get install bazel

Once installed, you can upgrade to a newer version of Bazel with:

sudo apt-get upgrade bazel

5. 配置TensorFlow编译环境**

先通过命令下载TensorFlow最新源码:git clone http://github.com/tensorflow/tensorflow

cd tebsorflow
ubuntu@ub:~/tensorflow$ ./configure 
You have bazel 0.6.1 installed.
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python
Found possible Python library paths:
/opt/ros/indigo/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/home/dh/deeplearing/caffe/python
Please input the desired Python library path to use. Default is [/opt/ros/indigo/lib/python2.7/dist-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]: n
No Google Cloud Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: n
No Hadoop File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with XLA JIT support? [y/N]: N
No 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]: N
No 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.
Please specify the CUDA SDK version you want to use, e.g. 7.0\. [Leave empty to default to CUDA 9.0]: 7.5
Please specify the location where CUDA 7.5 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda
Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 5.0.5
Please specify the location where cuDNN 5.0.5 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:/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: 3.5,5.2]5.2
Do you want to use clang as CUDA compiler? [y/N]: N
nvcc will be used as CUDA compiler.
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: /usr/bin/gcc
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]: -march=native
Add "--config=mkl" to your bazel command to build with MKL support.
Please note that MKL on MacOS or windows is still not supported.
If you would like to use a local MKL instead of downloading, please set the environment variable "TF_MKL_ROOT" every time before build.
Configuration finished
ubuntu@ub:~/tensorflow$ 

6. 当环境配置完成以后,通过 bazel 来编译 pip 的安装包,然后通过 pip 安装

  1. bazel build -c opt //tensorflow/tools/pip_package:build_pip_package(这里需要注意,我没有使用GPU ,因为我是在自己的笔记本上安装的,实验室里有台服务器可以运行TensorFlow。我使用笔记本安装GPU版本时,会出现莫名奇妙的 error 。如果安装GPU版本的,运行:bazel build -c --config=cuda opt //tensorflow/tools/pip_package:build_pip_package)

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

  3. sudo pip install /tmp/tensorflow_pkg/tensorflow-1.3.0-cp27-none-linux_x86_64.whl

注意: tensorflow-1.8.0-cp27-none-linux_x86_64.whl每个人都是不太相同的,所以,去你的目录 /tmp/tensorflow看一下,这个文件名字。当然啦,在安装的时候直接 Table 也行.

7. 安装完毕

你可能感兴趣的:(tensorflow源码编译安装)