tensorflow编译操作---完整版

本文详细指导了如何下载并使用Bazel 3.1.0编译TensorFlow 2.4.0,包括设置环境变量、配置CUDA及CUDNN支持,适用于开发者需要在Linux系统上构建GPU版本的TensorFlow应用。
摘要由CSDN通过智能技术生成

首先我们需要下载对应的tensorflow的源码,在
Tensorflow源码图中可以看到对应源码的各个不同版本,这里下载自己所需要的那个版本即可
接下来需要下载tensorflow对应的编译工具,这里我们到tensorflow编译工具对应网址之中查看相应的编译工具bazel的编译工具
不同版本的tensorflow对应的Bazel的编译工具由于我调用的是tensorflow-2.4.0对应的代码,所以我需要使用Bazel 3.1.0去对tensorflow的源码进行编译
这里选择相应的安装版本进行下载
相应的安装版本我们选择对应的bazel-3.1.0-installer-linux-x86_64.sh文件进行相应的下载安装
对应的命令为:

chmod +x bazel-3.1.0-installer-linux-x86_64.sh
./bazel-3.1.0-installer-linux-x86_64.sh --user

然后需要改变对应的环境变量,

gedit ~/.bashrc

接下来在最后一句添加

export PATH="$PATH:$HOME/bin"

然后进入tensorflow的文件夹之中,输入对应的命令

./configure

这里相应的配置可以参照官网相应的命令配置

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

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

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 ROCm support? [y/N]:
No ROCm 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 wish to build TensorFlow with TensorRT support? [y/N]:
No TensorRT support will be enabled for TensorFlow.

Found CUDA 10.1 in:
    /usr/local/cuda-10.1/targets/x86_64-linux/lib
    /usr/local/cuda-10.1/targets/x86_64-linux/include
Found cuDNN 7 in:
    /usr/lib/x86_64-linux-gnu
    /usr/include

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 Each capability can be specified as "x.y" or "compute_xy" to include both virtual and binary GPU code, or as "sm_xy" to only include the binary code.
Please note that each additional compute capability significantly increases your build time and binary size, and that TensorFlow only supports compute capabilities >= 3.5 [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]:

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]:

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 .bazelrc for more details.
    --config=mkl            # Build with MKL support.
    --config=monolithic     # Config for mostly static monolithic build.
    --config=ngraph         # Build with Intel nGraph support.
    --config=numa           # Build with NUMA support.
    --config=dynamic_kernels    # (Experimental) Build kernels into separate shared objects.
    --config=v2             # Build TensorFlow 2.x instead of 1.x.
Preconfigured Bazel build configs to DISABLE default on features:
    --config=noaws          # Disable AWS S3 filesystem support.
    --config=nogcp          # Disable GCP support.
    --config=nohdfs         # Disable HDFS support.
    --config=nonccl         # Disable NVIDIA NCCL support.
Configuration finished

官网对应的网址
配置完成之后,这里我们想要构建支持GPU的Tensorflow软件包编译器,运行下面的命令

bazel build --config=cuda [--config=option] //tensorflow/tools/pip_package:build_pip_package
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值