c++ - 如何创建具有 CUDA 支持的最新 Tensorflow 版本的调试版本?

标签 c++ tensorflow build bazel debug-symbols

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

到目前为止,这是我尝试过的。

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

主机系统是一台 Linux x86-64 机器,具有大量 RAM(例如 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

我遇到了以下错误:

INFO: From Compiling tensorflow/contrib/framework/kernels/zero_initializer_op_gpu.cu.cc: external/com_google_absl/absl/strings/string_view.h(496): error: constexpr function return is non-constant

这可以通过定义 -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

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

ERROR: /tensorflow/python/BUILD:3865:1: Linking of rule '//tensorflow/python:_pywrap_tensorflow_internal.so' failed (Exit 1) /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o: In function _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: In function deregister_tm_clones': crtstuff.c:(.text+0x3): relocation truncated to fit: R_X86_64_PC32 against.tm_clone_table' crtstuff.c:(.text+0xa): relocation truncated to fit: R_X86_64_PC32 against symbol __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: In function register_tm_clones': crtstuff.c:(.text+0x43): relocation truncated to fit: R_X86_64_PC32 against.tm_clone_table' crtstuff.c:(.text+0x4a): relocation truncated to fit: R_X86_64_PC32 against symbol __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: In function __do_global_dtors_aux': crtstuff.c:(.text+0x92): relocation truncated to fit: R_X86_64_PC32 against.bss' crtstuff.c:(.text+0x9c): relocation truncated to fit: R_X86_64_GOTPCREL against symbol __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' defined in .data.rel.local section in /usr/lib/gcc/x86_64-linux-gnu/5/crtbeginS.o crtstuff.c:(.text+0xbb): additional relocation overflows omitted from the output bazel-out/k8-dbg/bin/tensorflow/python/_pywrap_tensorflow_internal.so: PC-relative offset overflow in GOT PLT entry for `_ZNK5Eigen10TensorBaseINS_9TensorMapINS_6TensorIKjLi1ELi1EiEELi16ENS_11MakePointerEEELi0EE9unaryExprINS_8internal11scalar_leftIjjN10tensorflow7functor14right_shift_opIjEEEEEEKNS_18TensorCwiseUnaryOpIT_KS6_EERKSH_' collect2: error: ld returned 1 exit status Target //tensorflow/tools/pip_package:build_pip_package failed to build

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

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 一起工作,包括调试符号和禁用的优化。

非常感谢你..

最佳答案

以防其他人遇到这个问题。我终于使用以下命令编译它:

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版本..

关于c++ - 如何创建具有 CUDA 支持的最新 Tensorflow 版本的调试版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53238019/

相关文章:

build - 如何选择哪个 CMake 可执行目标将是默认目标?

C++ 模板和工厂

c++ - 扩展函数模板的参数包

windows - Windows 上的 TF r2.3 错误地址构建问题

tensorflow - 什么是 MobileNetv1 depth_multiplier?

git - grgit:在build.gradle脚本中添加标签并将文件推送到远程分支

c# - 在 windows 中使用 linux 根库

c++ - 无需 iTunes 即可直接将音乐上传至 iPhone/iPod/...

tensorflow - tensorflow 中的名称范围和变量范围有什么区别?

android - Gradle汇编AAR库中的重复类定义