gpt4 book ai didi

c++ - 构建 Tensorflow 调试时出错 LNK2019

转载 作者:行者123 更新时间:2023-12-01 14:08:07 26 4
gpt4 key购买 nike

我尝试在 Windows 中对 Tensorflow 2.0 的 C++ API 的 CPU 版本进行调试版本。我用于构建的命令是:

bazel build -c dbg --copt=/w34716 tensorflow:tensorflow.dll

但是当我构建它时,我收到此错误:
depth_space_ops.lo.lib(depthtospace_op.obj) : error LNK2019: unresolved external symbol "public: void __cdecl tensorflow::functor::DepthToSpaceOpFunctor<struct Eigen::GpuDevice,struct Eigen::half,1>::operator()(struct Eigen::GpuDevice const &,class Eigen::TensorMap<class Eigen::Tensor<struct Eigen::half const ,4,1,__int64>,16,struct Eigen::MakePointer>,int,class Eigen::TensorMap<class Eigen::Tensor<struct Eigen::half,4,1,__int64>,16,struct Eigen::MakePointer>)" (??R?$DepthToSpaceOpFunctor@UGpuDevice@Eigen@@Uhalf@2@$00@functor@tensorflow@@QEAAXAEBUGpuDevice@Eigen@@V?$TensorMap@V?$Tensor@$$CBUhalf@Eigen@@$03$00_J@Eigen@@$0BA@UMakePointer@2@@4@HV?$TensorMap@V?$Tensor@Uhalf@Eigen@@$03$00_J@Eigen@@$0BA@UMakePointer@2@@4@@Z) referenced in function "public: virtual void __cdecl tensorflow::DepthToSpaceOp<struct Eigen::ThreadPoolDevice,struct Eigen::half>::Compute(class tensorflow::OpKernelContext *)" (?Compute@?$DepthToSpaceOp@UThreadPoolDevice@Eigen@@Uhalf@2@@tensorflow@@UEAAXPEAVOpKernelContext@2@@Z)

关于这个问题,我唯一发现的是 this GitHub 问题,未解决。

有谁知道如何解决这个问题?

最佳答案

面对同样的需要,我在代码中翻了翻,居然找到了问题的根源: 包含在以下两个if中块:https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/core/kernels/spacetodepth_op.cc#L129https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/core/kernels/depthtospace_op.cc#L115 .
如果您正在调试中构建库的非 GPU 版本,那么发生错误的原因就很清楚了:if (std::is_same<Device, GPUDevice>::value)DepthToSpaceOp例如,使用 CPUDevice 参数化的类将评估为 if (false)在编译期间。启用任何优化后,if 子句中的代码(使用模板参数 GPUDevice 显式触发 DepthToSpaceOpFunctor - 正是您获得的缺失符号)根本不会被编译,因此不需要链接。
在调试版本中,它仍然可能被编译,即使很明显它永远不会被执行。然后链接器尝试找到 operator()对于使用 GPUDevice 参数化的 DepthToSpaceOpFunctor 模板,但未能这样做。
解决此问题的快速而肮脏的方法是 注释掉整个 if 子句 (如果您正在构建仅限 CPU 的 dll)在两个文件中 上文提到的。
一个更优雅的解决方案是通过模板特化避免这些链接器错误,方法是将 GPUDevice 的显式引用更改为 Device,因为这些将在仅当 Device 为 GPUDevice 时执行的代码中。我很快就会向类似的 issue 添加拉取请求我希望在经过更多测试后在 github 上提出。
更新:拉取请求已提交,您可以在此处找到修复此特定链接器错误集的代码更改:https://github.com/tensorflow/tensorflow/pull/42307/files#
对于 GPU 调试 dll - 我不确定为什么这些错误仍然存​​在,但无论如何在这种情况下还有其他链接错误;)

关于c++ - 构建 Tensorflow 调试时出错 LNK2019,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62149596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com