构建TensorFlow时未宣布的特征函子

Eigen functor undeclared when building Tensorflow

本文关键字:特征 TensorFlow 构建      更新时间:2023-10-16

我正在尝试按照[问题#7531]中的要求,通过添加非内双曲线功能(SINH和COSH)来为TensorFlow代码做出贡献。(https://github.com/tensorflow/tensorflow/issues/7531)。

当我用命令测试构建时

$ bazel test --config opt //tensorflow/core/kernels:cwise_ops_test

,但我得到了错误:

> ...
>  external/eigen_archive/unsupported/Eigen/CXX11/../../../Eigen/src/Core/MathFunctions.h:1446:3:
> note: 'sinh' should be declared prior to the call site or in an
> associated namespace of one of its arguments T sinh(const T &x) {   ^
> 1 error generated. Target //tensorflow/core/kernels:cwise_ops_test
> failed to build Use --verbose_failures to see the command lines of
> failed build steps. INFO: Elapsed time: 6.106s, Critical Path: 5.78s
> 
> Executed 0 out of 1 test: 1 fails to build.

可以在这里看到完整的输出。

我所做的就是在cwise_ops.h中添加这两个模板:

template <typename T>
struct acos : base<T, Eigen::internal::scalar_acos_op<T> > {};
template <typename T>
struct atan : base<T, Eigen::internal::scalar_atan_op<T> > {};
// The following two templates are new:
template <typename T>
struct sinh : base<T, Eigen::internal::scalar_sinh_op<T> > {};
template <typename T>
struct cosh : base<T, Eigen::internal::scalar_cosh_op<T> > {};

并制作了两个新文件cwise_op_sinh.cccwise_op_cosh.cc,它们仅是非hyperbolic版本的副本,分别用SIN或COS替换为SINH和COSH。据我所知,现在的双曲线功能现在与特征库中的其他数学功能一样实现。但据我所知,它给出了特征源中缺少声明的错误。

这是我的第一个开源贡献,最重要的是,我对C 是相当新的。我做错了什么,可能会有更多的C 经验显而易见。

您是否将`cwise_op_sinh.cc'和'cwise_op_cosh.cc'添加到相应的构建文件中?快速搜索告诉我应该在这里,但我可能错了。不过,您肯定必须告诉Bazel您的新文件。

这应该是对OP的问题的评论,但我缺乏所需的业力。

--config opt标志似乎是错误的,您是指优化构建的-c opt吗?--config opt表示使用BAZELRC文件中的" OPT"配置,该配置假定您在BazelRC文件中具有诸如" build:opt -opt -flag1 = value1"的行中的行,并且相似。如果您不这样做,那么Bazel应该显示一个警告说:

WARNING: Config values are not defined in any .rc file: "opt"

或某种效果。