tensorflow源码编译whl安装文件

1.首先安装bazel

如果linux系统上没有bazel,可参考https://blog.csdn.net/qq_41204464/article/details/95333396进行安装。建议采用“用二进制安装程序安装”

2.下载tensorflow源文件

https://github.com/tensorflow/tensorflow/tags中选择需要编译的tensorflow版本

3.配置tensroflow库

进入tensorflow源码根目录,运行 ./configure 进行配置,根据需求进行配置,以下是我的配置。从下面看出,所有配置我都选择no,因为我都不需要,连cuda我也不要,因为我要编译的tensorflow是要用在cpu上面的。

You have bazel 0.15.0 installed.
Please specify the location of python. [Default is /media/huaxin/tcl2/nlp/anaconda3/bin/python]: 


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

Do you wish to build TensorFlow with Apache Ignite support? [Y/n]: n
No Apache Ignite 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 OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.

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

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

Do you wish to download a fresh release of clang? (Experimental) [y/N]: n
Clang will not be downloaded.

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]: 


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: 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.
    --config=gdr             # Build with GDR support.
    --config=verbs           # Build with libverbs support.
    --config=ngraph          # Build with Intel nGraph support.
Configuration finished

4.编译tensroflow库

由于我需要将mkl库加到tensorflow中,所以使用一下命令进行编译

bazel build --config=mkl -c opt --copt=-march=native //tensorflow/tools/pip_package:build_pip_package

5.生成whl文件

通过一下命令,生成whl文件,[path_to_save_wheel]为生成的whl文件的保存路径

bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/path_to_save_wheel

6.使用pip命令进行安装即可

7.出现的坑

在第4步中,出现下述报错,可参考https://www.freesion.com/article/5917370408/https://blog.csdn.net/weixin_39634443/article/details/111109185进行解决

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值