飞羽

Tensorflow源码编译
今天在虚拟机里安装keras和tensorflow,但是tensorflow出现问题,无奈自己编译tensorflow
扫描右侧二维码阅读全文
24
2019/06

Tensorflow源码编译

今天在虚拟机里安装keras和tensorflow,但是tensorflow出现问题,无奈自己编译tensorflow

Tensorflow源码编译

Tensorflow源码编译.jpg

一、本文简要说明


本文首先对tensorflow进行了简要介绍,接着介绍以下目前编译的环境和准备工作,最后记录以下tensorflow编译的方法,最后测试。

二、Tensorflow简要介绍

Tensorflow简要介绍,可略过

TensorFlow™ 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库。节点(Nodes)在图中表示数学操作,图中的线(edges)则表示在节点间相互联系的多维数据数组,即张量(tensor)。它灵活的架构让你可以在多种平台上展开计算,例如台式计算机中的一个或多个CPU(或GPU),服务器,移动设备等等。TensorFlow 最初由Google大脑小组(隶属于Google机器智能研究机构)的研究员和工程师们开发出来,用于机器学习和深度神经网络方面的研究,但这个系统的通用性使其也可广泛用于其他计算领域。

三、Tensorflow编译环境

3.1 虚拟机配置

  • 4核4G

3.2 系统环境

  • Centos7_X86-64

四、编译前的准备


我要安装python3的tensorfow,因此需要先安装python3

4.1 基本环境安装

[root@Centos7 ~]#yum install epel-release -y
#安装EPEL
[root@Centos7 ~]#yum install python36 python36-pip -y
#安装python3和pip3
[root@Centos7 ~]#yum install wget git gcc gcc-c++ python36-devel.x86_64 python-devel.x86_64  patch -y
#安装基础环境
[root@Centos7 ~]#ln -s /usr/local/lib/python3.6/site-packages/pip /usr/bin/pip3
#做一下软链接
[root@Centos7 ~]#pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy
#安装numpy

4.2 准备bazel

偷点懒,直接从github上下载编译好的bazel吧。


注意:我安装的是1.13,bazel版本不能超过0.20,因此我选的是0.20版本的bazel

[root@Centos7 ~]#wget https://github.com/bazelbuild/bazel/releases/download/0.20.0/bazel-0.20.0-linux-x86_64
#下载编译好的bazel
[root@Centos7 ~]#chmod +x bazel-0.20.0-linux-x86_64
[root@Centos7 ~]#cp bazel-0.20.0-linux-x86_64 /usr/bin/bazel
#把bazel放到/usr/bin里

4.3 准备Tensorflow

[root@Centos7 ~]#git clone https://github.com/tensorflow/tensorflow.git
#从github上拉tensorflow源代码
[root@Centos7 ~]#git checkout v1.13.1
#切换1.13版本

五、编译tensorflow

5.1 配置tensorflow编译选项

[root@Centos7 ~]#./configure
#选择tensorflow编译选项

Tensorflow配置选项

  ./configure
    You have bazel 0.20.0 installed.
    Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3.6

    Found possible Python library paths:
      /usr/local/lib/python3.6/dist-packages
      /usr/lib/python3.6/dist-packages
    Please input the desired Python library path to use.  Default is [/usr/lib/python3.6/dist-packages]

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

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

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

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

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

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

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

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

    Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]:
    No OpenCL SYCL 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. [Leave empty to default to CUDA 9.0]: 9.0

    Please specify the location where CUDA 9.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:

    Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 7.0

    Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:

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

    Please specify the NCCL version you want to use. If NCLL 2.2 is not installed, then you can use version 1.3 that can be fetched automatically but it may have worse performance with multiple GPUs. [Default is 2.2]: 1.3

    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,7.0] 6.1

    Do you want to use clang as CUDA compiler? [y/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]:

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

    Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]:
    Not configuring the WORKSPACE for Android builds.

    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

5.2 编译


如果内存不足,请加如限制--local_resources 2048,.5,1.0,因为我是虚拟机4核4G,因此我就加上限制,防止出错

[root@Centos7 ~]#cd tensorflow
[root@Centos7 ~]#bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package --local_resources 2048,.5,1.0
#开始编译
文章名: 《Tensorflow源码编译》

文章链接:https://blog.8086k.cn/archives/50/

联系方式:1412981048@qq.com

除特别注明外,文章均为飞羽小随笔原创,转载时请注明本文出处及文章链接
Last modification:June 25th, 2019 at 03:34 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment