Windows 上的 Cuda 的 Tensorflow 1.9 Bazel 构建错误

Tensorflow 1.9 Bazel build error with Cuda on Windows

我正在尝试编译一个使用 Tensorflow 核心的示例程序,在以下环境中通过 Bazel 在 Windows 10 64 位上支持 CUDA:

我通过了 configure.py 成功,我添加了 CUDA 和 CUDNN 位置。

这是我的 Bazel BUILD 文件:

cc_binary(
  name = "mnistpredict.dll",
  srcs = ["mnist.cc", "MNIST.h"],
  deps = [
      "//tensorflow/core:tensorflow",
  ],
  linkshared=1
)

我尝试用这个命令编译: bazel build //tensorflow/loadgraph:mnistpredict.dll

ERROR: C:/users/laci/downloads/tensorflow-1.9.0/tensorflow/loadgraph/BUILD:1:1: error loading package 'tensorflow/core': Encountered error while reading extension file 'cuda/build_defs.bzl': no such package '@local_config_cuda//cuda': Traceback (most recent call last): File "C:/users/laci/downloads/tensorflow-1.9.0/third_party/gpus/cuda_configure.bzl", line 1166 _create_local_cuda_repository(repository_ctx) File "C:/users/laci/downloads/tensorflow-1.9.0/third_party/gpus/cuda_configure.bzl", line 995, in _create_local_cuda_repository _get_cuda_config(repository_ctx) File "C:/users/laci/downloads/tensorflow-1.9.0/third_party/gpus/cuda_configure.bzl", line 750, in _get_cuda_config _cudnn_version(repository_ctx, cudnn_install_base..., ...) File "C:/users/laci/downloads/tensorflow-1.9.0/third_party/gpus/cuda_configure.bzl", line 466, in _cudnn_version find_cuda_define(repository_ctx, cudnn_header_dir, "c...", ...) File "C:/users/laci/downloads/tensorflow-1.9.0/third_party/gpus/cuda_configure.bzl", line 422, in find_cuda_define auto_configure_fail(("Error reading %s: %s" % (str(h...))) File "C:/users/laci/downloads/tensorflow-1.9.0/third_party/gpus/cuda_configure.bzl", line 210, in auto_configure_fail fail(("\n%sCuda Configuration Error:%...)))

Cuda Configuration Error: Error reading C:/Users/laci/Downloads/cudnn-9.0-windows10-x64-v7.1/cuda/include/cudnn.h: java.io.IOException: ERROR: src/main/native/windows/processes-jni.cc(239): CreateProcessW("grep" --color=never -A1 -E "#define CUDNN_MAJOR" C:/Users/laci/Downloads/cudnn-9.0-windows10-x64-v7.1/cuda/include/cudnn.h): The system cannot find the file specified.

and referenced by '//tensorflow/loadgraph:mnistpredict.dll' ERROR: Analysis of target '//tensorflow/loadgraph:mnistpredict.dll' failed; build aborted: Analysis failed INFO: Elapsed time: 1.612s INFO: 0 processes. FAILED: Build did NOT complete successfully (2 packages loaded) currently loading: tensorflow/core

我在没有CUDA支持的情况下试了一下,编译成功了

它正在 %PATH% 下寻找 grep.exe 但失败了。将 Git\bin 添加到 %PATH% 或为 Windows 安装 grep 即可。

我花了几天时间终于在 Windows 7 64 位上用 bazel + msys2 构建了一个 tensorflow-gpu 1.10 whl。