bazel 在 windows 10 上构建 tensorflow 获取 cudnn.h- 系统找不到指定的文件

bazel build tensorflow on windows 10 getting cudnn.h- system cannot find the file specified

在 Windows 10 中尝试使用 bazel 和 python 构建 tensorflow-gpu 时,我不断收到此错误:

Cuda Configuration Error: Error reading C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.2/cuda/include/cudnn.h: ja
va.io.IOException: ERROR: src/main/native/windows/processes-jni.cc(239): CreateProcessW("grep" --color=never -A1 -E "#de
fine CUDNN_MAJOR" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.2/cuda/include/cudnn.h"): The system cannot fin
d the file specified.

这是我正在尝试的命令 运行:

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

我已经确认 C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.2/cuda/include/cudnn.h 在那里。

我已经尝试 运行从 VS2015 x64 Native Tools 命令提示符、cmd 和 powershell 中使用它并得到相同的错误。

我正在使用 bazel 0.16.1、CUDA 9.2、Anaconda3(Python 3.6.5)和 CUDNN 7.2.1。我 "installed" 通过将其 cuda 文件夹解压缩到我的 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2 文件夹(即整个 "cuda" 文件夹)来 "installed" CUDDNN 文件。我在运行 configure.py 的cudnn 路径问题中指定了C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\cuda 路径。 configure.py 完成且没有错误。

我还尝试将 CUDNN 文件直接放在 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2 文件夹(而不是那里的 cuda 文件夹)并指定默认位置,但仍然得到基本相同的错误:"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.2/include/cudnn.h":系统找不到指定的文件。

我已将这些添加到我的路径(并重新启动):

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\libnvvp
C:\tools\msys64
C:\tools\bazel
C:\tools\bazel\bazel.exe
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\extras\CUPTI\libx64

这些是我设置的系统变量:

BAZEL_SH  C:\tools\msys64\usr\bin\bash.exe
BAZEL_VC  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC
BAZEL_VS  C:\Program Files (x86)\Microsoft Visual Studio 14.0

这是完整的错误:

ERROR: Skipping '//tensorflow/tools/pip_package:build_pip_package': error loading package 'tensorflow/tools/pip_package'
: Encountered error while reading extension file 'cuda/build_defs.bzl': no such package '@local_config_cuda//cuda': Trac
eback (most recent call last):
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 1458
                _create_local_cuda_repository(repository_ctx)
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 1185, in _create_local_cuda_repository
                _get_cuda_config(repository_ctx)
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 909, in _get_cuda_config
                _cudnn_version(repository_ctx, cudnn_install_base..., ...)
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 584, in _cudnn_version
                find_cuda_define(repository_ctx, cudnn_header_dir, "c...", ...)
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 534, in find_cuda_define
                auto_configure_fail(("Error reading %s: %s" % (str(h...)))
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 315, in auto_configure_fail
                fail(("\n%sCuda Configuration Error:%...)))

Cuda Configuration Error: Error reading C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.2/cuda/include/cudnn.h: ja
va.io.IOException: ERROR: src/main/native/windows/processes-jni.cc(239): CreateProcessW("grep" --color=never -A1 -E "#de
fine CUDNN_MAJOR" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.2/cuda/include/cudnn.h"): The system cannot fin
d the file specified.

WARNING: Target pattern parsing failed.
ERROR: error loading package 'tensorflow/tools/pip_package': Encountered error while reading extension file 'cuda/build_
defs.bzl': no such package '@local_config_cuda//cuda': Traceback (most recent call last):
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 1458
                _create_local_cuda_repository(repository_ctx)
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 1185, in _create_local_cuda_repository
                _get_cuda_config(repository_ctx)
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 909, in _get_cuda_config
                _cudnn_version(repository_ctx, cudnn_install_base..., ...)
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 584, in _cudnn_version
                find_cuda_define(repository_ctx, cudnn_header_dir, "c...", ...)
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 534, in find_cuda_define
                auto_configure_fail(("Error reading %s: %s" % (str(h...)))
        File "C:/tensorflow/third_party/gpus/cuda_configure.bzl", line 315, in auto_configure_fail
                fail(("\n%sCuda Configuration Error:%...)))

Cuda Configuration Error: Error reading C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.2/cuda/include/cudnn.h: ja
va.io.IOException: ERROR: src/main/native/windows/processes-jni.cc(239): CreateProcessW("grep" --color=never -A1 -E "#de
fine CUDNN_MAJOR" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.2/cuda/include/cudnn.h"): The system cannot fin
d the file specified.

知道我可能做错了什么,或者我可能遗漏了什么,或者接下来我可以检查什么吗?

问题是 cuda_configure.bzl: it uses ctx.execute instead of ctx.action.run_shell. If you'd be so kind to file a bug to TensorFlow 中的错误,那就太好了!

要解决此问题:将 c:\tools\msys64\usr\bin 添加到您的 PATH。这就是 grep.exe 所在的位置,因此 ctx.execute 可以在 PATH 上找到 grep