编译支持 GPU 的 Tensorflow 时,遇到 CUDA_TOOLKIT_PATH unbound variable

When compiling Tensorflow with GPU support, CUDA_TOOLKIT_PATH unbound variable is encountered

我正在关注 this link 以编译支持 GPU 的 Tensorflow。在 ./configure 之后,我输入 bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package。在编译过程中,我看到以下错误。

ERROR: /home/super/.cache/bazel/_bazel_super/6fad3aac5da8510114d7933cea773172/external/nccl_archive/BUILD.bazel:139:1: Executing genrule @nccl_archive//:device_code_fatbin_h failed (Exit 1)
/bin/bash: CUDA_TOOLKIT_PATH: unbound variable
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.973s, Critical Path: 0.12s
INFO: 4 processes: 4 local.
FAILED: Build did NOT complete successfully

我检查了 .tf_configure.bazelrc 文件并定义了 CUDA_TOOLKIT_PATH

build --action_env PYTHON_BIN_PATH="/home/super/anaconda3/envs/tf/bin/python"
build --action_env PYTHON_LIB_PATH="/home/super/anaconda3/envs/tf/lib/python3.6/site-packages"
build --python_path="/home/super/anaconda3/envs/tf/bin/python"
build:xla --define with_xla_support=true
build --config=xla
build --action_env TF_NEED_OPENCL_SYCL="0"
build --action_env TF_NEED_ROCM="0"
build --action_env TF_NEED_CUDA="1"
build --action_env CUDA_TOOLKIT_PATH="/usr/local/cuda"
build --action_env TF_CUDA_VERSION="10.0"
build --action_env CUDNN_INSTALL_PATH="/usr/local/cuda-10.0"
build --action_env TF_CUDNN_VERSION="7"
build --action_env TF_NCCL_VERSION=""
build --action_env TF_CUDA_COMPUTE_CAPABILITIES="5.2"
build --action_env LD_LIBRARY_PATH="/usr/local/cuda-10.0/lib64"
build --action_env TF_CUDA_CLANG="0"
build --action_env GCC_HOST_COMPILER_PATH="/usr/bin/gcc"
build --config=cuda
test --config=cuda
build:opt --copt=-march=native
build:opt --copt=-Wno-sign-compare
build:opt --host_copt=-march=native
build:opt --define with_default_optimizations=true
build:v2 --define=tf_api_version=2

我的 .bashrc 有以下内容。

export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export CUDA_HOME=/usr/loca/cuda
export CUDA_TOOLKIT_PATH=/usr/local/cuda

我的环境设置如下

有什么想法吗?

我的假设是您正在尝试直接从 master 分支进行编译。我之前 运行 遇到了同样的问题,但在查看已发布的版本 (v1.12.0-rc2) 后,我能够毫无问题地编译 TensorFlow。通过 ./configure 和 bazel 编译再次尝试 git checkout v1.12.0-rc2 然后 运行。主分支更新非常频繁。我的想法是构建在我们尝试安装的那一刻被破坏了。