首页 > 解决方案 > 使用 LTCG 构建 TensorFlow

问题描述

我正在尝试使用启用了 LTCG(链接时间代码生成)的 VS 2017 在 Windows 上构建 Tensorflow 1.14。我在构建过程中遇到了这个崩溃:

external/bazel_tools/tools/def_parser/def_parser.exe bazel-out/x64_windows-opt/bin/tensorflow/contrib/layers/python/ops/_sparse_feature_cross_op.so.gen.def _sparse_feature_cross_op.so @bazel-out/x64_windows-opt/bin/tensorflow/contrib/layers/python/ops/_sparse_feature_cross_op.so.gen.def-0.params

ERROR: E:/tensorflow/tensorflow/contrib/layers/BUILD:22:1: DefParser tensorflow/contrib/layers/python/ops/_sparse_feature_cross_op.so.gen.def failed (Exit -1073741819): def_parser.exe failed: error executing command

我的环境是:

脚步:

set BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC
set BAZEL_VC_FULL_VERSION=14.16.27023
set BAZEL_VS=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise
python .\configure.py  
<Use all of the defaults>
bazel build -s --config=opt --copt=/GL --linkopt=/LTCG //tensorflow/tools/pip_package:build_pip_package  

我尝试了各种版本的 bazel(0.21、0.26、0.27、0.28),并且在更改 BAZEL_* 环境变量时也尝试了 VS 2019,但我仍然遇到同样的错误。我已经在external/bazel_tools/tools/def_parser/def_parser.exe bazel-out/x64_windows-opt/bin/tensorflow/contrib/layers/python/ops/_sparse_feature_cross_op.so.gen.def _sparse_feature_cross_op.so @bazel-out/x64_windows-opt/bin/tensorflow/contrib/layers/python/ops/_sparse_feature_cross_op.so.gen.def-0.params本地运行了该命令,但它确实以 -1073741819 错误代码崩溃。

有没有人有使用 LTCG 构建 Tensorflow 或使用 Bazel 和 LTCG 的经验?

标签: windowstensorflowbazel

解决方案


TF 1.14 需要 Bazel 0.24.1,AFAIK 它不适用于较新的 Bazel 版本 (>= 0.25)。

我不知道问题可能是什么,但我可以告诉你如何调试它。

您需要获取 Bazel 0.24.1 的源代码,将调试日志添加到 DEF 解析器,从源代码构建 Bazel,然后使用生成的二进制文件构建 TensorFlow。

为此:

  1. 下载Bazel 0.24.1 版本
  2. 下载并提取0.24.1 源代码 git clone Bazel 的 GitHub 树并查看 0.24.1 标签
  3. 将调试日志记录/ printf 调用添加到您认为合适的third_party/def_parser/*
  4. 使用 0.24.1 发行版二进制文件,bazel build //src:bazel.exe在修补的源代码树中运行
  5. 使用结果bazel-bin\src\bazel.exe构建 TensorFlow
  6. 如果您需要添加更多调试日志记录,请重复步骤 3..5

推荐阅读