【问题标题】:How do I create a debug build of a recent Tensorflow version with CUDA Support?如何创建具有 CUDA 支持的最新 Tensorflow 版本的调试版本?
【发布时间】:2018-11-10 10:26:38
【问题描述】:

我尝试并尝试使用官方 docker 映像 (latest-cuda-devel-py3 -> r1.12.0) 为最新版本的 Tensorflow 创建调试版本,但似乎没有任何效果。有人最近为 Tensorflow (>= r1.11.0) 创建了成功的调试版本并可以分享他的方法吗?

这是我迄今为止尝试过的。

我基本上尝试按照https://www.tensorflow.org/install/source 的说明进行操作,但尝试修改它们以生成调试版本。我没有尝试任何方法都可以成功构建。

主机系统是具有大量 RAM 的 Linux x86-64 机器(例如 512 GB 的 RAM -> DGX-1)。 Docker-Image 中的 CUDA 版本是 CUDA-9.0。 docker 镜像中最近的“最新”Tensorflow 版本是 r1.12.0

为了让任何 cuda-build 工作,我需要使用“nvidia-docker”,否则我会收到“libcuda.so.1”的链接器错误。

我是这样开始的:

nvidia-docker pull tensorflow/tensorflow:latest-devel-gpu-py3
nvidia-docker run --runtime=nvidia -it -w /tensorflow -v $PWD:/mnt -e HOST_PERMS="$(id -u):$(id -g)" \
    tensorflow/tensorflow:latest-devel-gpu-py3 bash

然后我尝试使用配置项目

cd /tensorflow
./configure

我尝试了各种配置。我尝试将所有值保持为默认值。我尝试只启用我需要的部分。我试过根本不运行 ./configure 。我将它指向我自己的 cuda-9.0 和 tensorrt 安装。但是根本不运行 ./configure(在 docker 映像中)似乎会产生最好的结果(例如,我可以用最少的努力成功地进行优化构建)。

如果我使用确切的官方构建说明构建它,即创建一个优化/非调试构建,一切都会按预期工作。所以运行以下似乎成功了。

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

同样的事情,如果我运行以下内容,其中包括调试信息,但不关闭优化(例如,我不能真正将其用于调试目的)。

bazel build --config cuda --strip=never -c opt --copt="-ggdb"  //tensorflow/tools/pip_package:build_pip_package

但是所有禁用优化的东西似乎都不起作用。如果我运行以下命令(带或不带 --strip=never 标志)

bazel build --config cuda --strip=never -c dbg
//tensorflow/tools/pip_package:build_pip_package

我遇到以下错误:

信息:来自编译 tensorflow/contrib/framework/kernels/zero_initializer_op_gpu.cu.cc: 外部/com_google_absl/absl/strings/string_view.h(496):错误: constexpr 函数返回是非常量的

这可以通过定义 -DNDEBUG 来解决(参见 nvcc error: string_view.h: constexpr function return is non-constant )。

但如果我运行以下命令:

bazel build --config cuda --strip=never -c dbg --copt="-DNDEBUG"  //tensorflow/tools/pip_package:build_pip_package

我在构建的最后一步遇到了这些链接错误:

错误: /tensorflow/python/BUILD:3865:1: 规则'//tensorflow/python:_pywrap_tensorflow_internal.so'的链接 失败(出口 1) /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o:在 函数_init': (.init+0x7): relocation truncated to fit: R_X86_64_REX_GOTPCRELX against undefined symbolgmon_start' /usr/lib/gcc/x86_64-linux-gnu/5/crtbeginS.o:在函数中 deregister_tm_clones': crtstuff.c:(.text+0x3): relocation truncated to fit: R_X86_64_PC32 against.tm_clone_table' crtstuff.c:(.text+0xa):重定位被截断以适应:R_X86_64_PC32 反对符号__TMC_END__' defined in .nvFatBinSegment section in bazel-out/k8-dbg/bin/tensorflow/python/_pywrap_tensorflow_internal.so crtstuff.c:(.text+0x1e): relocation truncated to fit: R_X86_64_REX_GOTPCRELX against undefined symbol _ITM_deregisterTMCloneTable' /usr/lib/gcc/x86_64-linux-gnu/5/crtbeginS.o:在函数中 register_tm_clones': crtstuff.c:(.text+0x43): relocation truncated to fit: R_X86_64_PC32 against.tm_clone_table' crtstuff.c:(.text+0x4a): 重定位被截断以适应:R_X86_64_PC32 针对符号 __TMC_END__' defined in .nvFatBinSegment section in bazel-out/k8-dbg/bin/tensorflow/python/_pywrap_tensorflow_internal.so crtstuff.c:(.text+0x6b): relocation truncated to fit: R_X86_64_REX_GOTPCRELX against undefined symbol _ITM_registerTMCloneTable' /usr/lib/gcc/x86_64-linux-gnu/5/crtbeginS.o:在函数中 __do_global_dtors_aux': crtstuff.c:(.text+0x92): relocation truncated to fit: R_X86_64_PC32 against.bss' crtstuff.c:(.text+0x9c): 重定位被截断以适应:R_X86_64_GOTPCREL 针对符号 __cxa_finalize@@GLIBC_2.2.5' defined in .text section in /lib/x86_64-linux-gnu/libc.so.6 crtstuff.c:(.text+0xaa): relocation truncated to fit: R_X86_64_PC32 against symbol__dso_handle' 已定义 在 .data.rel.local 部分中 /usr/lib/gcc/x86_64-linux-gnu/5/crtbeginS.o crtstuff.c:(.text+0xbb): 输出中省略了额外的重定位溢出 bazel-out/k8-dbg/bin/tensorflow/python/_pywrap_tensorflow_internal.so: GOT PLT 条目中的 PC 相对偏移溢出 `_ZNK5Eigen10TensorBaseINS_9TensorMapINS_6TensorIKjLi1ELi1EiEELi16ENS_11MakePointerEEELi0EE9unaryExprINS_8internal11scalar_leftIjjN10tensorflow7functor14right_shift_opIjEEEEEEKNS_18TensorCwiseUnaryOpIT_KS6_EERKSH_' collect2:错误:ld 返回 1 退出状态目标 //tensorflow/tools/pip_package:build_pip_package 构建失败

我希望能够通过单体构建来解决这个问题。所以我试了一下,得到了基本相同的错误。

bazel build --config cuda -c dbg --config=monolithic --copt="-DNDEBUG"  //tensorflow/tools/pip_package:build_pip_package

我还尝试了来自 TensorFlow doesnt build with debug mode 的方法以及通过广泛的谷歌搜索发现的其他几个变体。我的选项不多了。

我会从 1.11 开始采用任何 Tensorflow 版本,包括(工作)夜间构建。它只需要在 x86 linux 上使用 CUDA 9,包括调试符号和禁用的优化。

非常感谢您提前..

【问题讨论】:

    标签: c++ tensorflow build bazel debug-symbols


    【解决方案1】:

    以防万一其他人遇到这个问题。我终于得到了编译,使用以下命令:

    bazel build --config cuda --strip=never --copt="-DNDEBUG" --copt="-march=native" --copt="-Og" --copt="-g3" --copt="-mcmodel=medium" --copt="-fPIC"  //tensorflow/tools/pip_package:build_pip_package
    

    在那之后,安装有点麻烦,因为无法再制造轮子了。但是无论如何都可以安装 tensorflow 构建:

    在造轮子的时候,通过

    ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
    

    该过程失败并出现错误,这似乎是 python 的内置 zip 压缩库的问题(即它无法压缩生成的存档,因为它太大了)。

    无论如何运行它很重要,因为它只会在最后一步(存档)失败。运行 build_pip_package 时,它​​会在进程开始时打印到控制台,它正在临时目录(例如 /tmp/Shjwejweu )中构建包 - 该临时目录的内容可用于安装 tf 调试版本。只需将其复制到目标机器,然后确保您已删除任何旧的 tensorflow 包(例如 pip uninstall tensorflow),并在其中运行:

    python setup.py install
    

    但要注意先主动卸载“tensorflow”包,否则会得到两个同时安装的tensorflow版本..

    【讨论】:

      猜你喜欢
      • 2020-10-04
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多