From 8cd5bd93ce1a2e29447c0eba9d0f658026e58961 Mon Sep 17 00:00:00 2001 From: "Qin.Chen" Date: Tue, 22 Nov 2022 09:57:37 +0000 Subject: [PATCH] Add BUILD_WITH_BAZEL option, marco of VSI_FEAT_OP_XXX should behind headers now. --- BUILD | 15 +++++++++++++++ gen_vsi_feat_ops_def.sh | 10 ++++++++++ include/tim/vx/graph.h | 4 ++++ include/tim/vx/ops/cumsum.h | 6 ++++-- include/tim/vx/ops/max_pool3d.h | 6 ++++-- include/tim/vx/ops/maxpoolgrad.h | 9 +++++---- include/tim/vx/ops/maxpoolwithargmax2.h | 6 +++--- include/tim/vx/ops/mod.h | 6 ++++-- src/tim/vx/ops/cumsum.cc | 4 +++- src/tim/vx/ops/cumsum_test.cc | 5 +++-- src/tim/vx/ops/max_pool3d.cc | 5 +++-- src/tim/vx/ops/max_pool3d_test.cc | 6 +++--- src/tim/vx/ops/maxpoolgrad.cc | 4 +++- src/tim/vx/ops/maxpoolgrad_test.cc | 3 ++- src/tim/vx/ops/maxpoolwithargmax2.cc | 3 ++- src/tim/vx/ops/maxpoolwithargmax2_test.cc | 4 +++- src/tim/vx/ops/mod.cc | 6 ++++-- src/tim/vx/ops/mod_test.cc | 6 ++++-- 18 files changed, 79 insertions(+), 29 deletions(-) create mode 100755 gen_vsi_feat_ops_def.sh diff --git a/BUILD b/BUILD index 3c0bb42..0fcaf9f 100644 --- a/BUILD +++ b/BUILD @@ -18,8 +18,22 @@ cc_library( strip_include_prefix = "include" ) +genrule( + name = "gen_vsi_feat_ops_def", + srcs = ["//src/tim/vx/internal:include/interface/ops.def"], + outs = ["vsi_feat_ops_def.h"], + cmd = "./$(location gen_vsi_feat_ops_def.sh) $(SRCS) > \"$(OUTS)\"", + tools = ["gen_vsi_feat_ops_def.sh"] +) + +cc_library( + name = "vsi_feat_ops_def", + hdrs = [":gen_vsi_feat_ops_def"] +) + cc_library( name = "tim-vx_interface", + defines = ["BUILD_WITH_BAZEL"], copts = ["-std=c++14", "-Werror", "-fvisibility=default", "-pthread"], includes = [ "include", @@ -64,6 +78,7 @@ cc_library( ], exclude = ["src/tim/vx/ops/*_test.cc"] ) + glob(["src/tim/transform/ops/*.*"]), deps = [ + ":vsi_feat_ops_def", "//src/tim/vx/internal:ovxlibimpl", ], linkstatic = True, diff --git a/gen_vsi_feat_ops_def.sh b/gen_vsi_feat_ops_def.sh new file mode 100755 index 0000000..2abedf7 --- /dev/null +++ b/gen_vsi_feat_ops_def.sh @@ -0,0 +1,10 @@ +# generate macro ops define for vsi feature ops + +for line in `cat $1` +do + if [[ $line =~ "DEF_OP" ]] + then + x=${line#*(} + echo "#define VSI_FEAT_OP_${x%)*}" + fi +done \ No newline at end of file diff --git a/include/tim/vx/graph.h b/include/tim/vx/graph.h index 08cef92..91376bc 100644 --- a/include/tim/vx/graph.h +++ b/include/tim/vx/graph.h @@ -24,6 +24,10 @@ #ifndef TIM_VX_GRAPH_H_ #define TIM_VX_GRAPH_H_ +#ifdef BUILD_WITH_BAZEL +#include "vsi_feat_ops_def.h" +#endif + #include #include diff --git a/include/tim/vx/ops/cumsum.h b/include/tim/vx/ops/cumsum.h index c75d8ca..164fc68 100644 --- a/include/tim/vx/ops/cumsum.h +++ b/include/tim/vx/ops/cumsum.h @@ -21,11 +21,13 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_CUMSUM #ifndef TIM_VX_OPS_CUMSUM_H_ #define TIM_VX_OPS_CUMSUM_H_ #include "tim/vx/builtin_op.h" + +#ifdef VSI_FEAT_OP_CUMSUM + namespace tim { namespace vx { namespace ops { @@ -60,5 +62,5 @@ class CumSum : public BuiltinOp { } // namespace ops } // namespace vx } // namespace tim +#endif //(VSI_FEAT_OP_CUMSUM) #endif /* TIM_VX_OPS_CUMSUM_H_ */ -#endif //(VSI_FEAT_OP_CUMSUM) \ No newline at end of file diff --git a/include/tim/vx/ops/max_pool3d.h b/include/tim/vx/ops/max_pool3d.h index 75f00f1..a97e07e 100644 --- a/include/tim/vx/ops/max_pool3d.h +++ b/include/tim/vx/ops/max_pool3d.h @@ -21,13 +21,15 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MAX_POOL3D #ifndef TIM_VX_OPS_MAX_POOL3D_H_ #define TIM_VX_OPS_MAX_POOL3D_H_ #include "tim/vx/builtin_op.h" #include "tim/vx/types.h" #include + +#ifdef VSI_FEAT_OP_MAX_POOL3D + namespace tim { namespace vx { namespace ops { @@ -73,5 +75,5 @@ class MaxPool3d : public BuiltinOp { } // namespace vx } // namespace tim +#endif //(VSI_FEAT_OP_MAX_POOL3D) #endif /* TIM_VX_OPS_MAX_POOL3D_H_ */ -#endif //(VSI_FEAT_OP_MAX_POOL3D) \ No newline at end of file diff --git a/include/tim/vx/ops/maxpoolgrad.h b/include/tim/vx/ops/maxpoolgrad.h index 3d941b9..9b02d13 100644 --- a/include/tim/vx/ops/maxpoolgrad.h +++ b/include/tim/vx/ops/maxpoolgrad.h @@ -21,13 +21,14 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX - #ifndef TIM_VX_OPS_MAXPOOLGRAD_H_ #define TIM_VX_OPS_MAXPOOLGRAD_H_ #include "tim/vx/operation.h" #include + +#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX + namespace tim { namespace vx { namespace ops { @@ -70,5 +71,5 @@ class MaxpoolGrad: public Operation { } // namespace vx } // namespace tim -#endif /*TIM_VX_OPS_MAXPOOLGRAD_H_*/ -#endif \ No newline at end of file +#endif //(VSI_FEAT_OP_MAXPOOLWITHARGMAX) +#endif /* TIM_VX_OPS_MAXPOOLGRAD_H_ */ diff --git a/include/tim/vx/ops/maxpoolwithargmax2.h b/include/tim/vx/ops/maxpoolwithargmax2.h index bcb5345..cd58466 100644 --- a/include/tim/vx/ops/maxpoolwithargmax2.h +++ b/include/tim/vx/ops/maxpoolwithargmax2.h @@ -21,7 +21,6 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX #ifndef TIM_VX_OPS_MAXPOOLWITHARGMAX2_H_ #define TIM_VX_OPS_MAXPOOLWITHARGMAX2_H_ @@ -30,6 +29,8 @@ #include "tim/vx/builtin_op.h" #include "tim/vx/types.h" +#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX + namespace tim { namespace vx { namespace ops { @@ -66,6 +67,5 @@ class MaxpoolWithArgmax2 : public BuiltinOp { } // namespace vx } // namespace tim +#endif //(VSI_FEAT_OP_MAXPOOLWITHARGMAX) #endif /* TIM_VX_OPS_MAXPOOLWITHARGMAX2_H_ */ - -#endif //(VSI_FEAT_OP_MAXPOOLWITHARGMAX) \ No newline at end of file diff --git a/include/tim/vx/ops/mod.h b/include/tim/vx/ops/mod.h index f5d8fdc..87497e9 100644 --- a/include/tim/vx/ops/mod.h +++ b/include/tim/vx/ops/mod.h @@ -21,11 +21,13 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MOD #ifndef TIM_VX_OPS_MOD_H_ #define TIM_VX_OPS_MOD_H_ #include "tim/vx/builtin_op.h" + +#ifdef VSI_FEAT_OP_MOD + namespace tim { namespace vx { namespace ops { @@ -57,5 +59,5 @@ class Mod : public BuiltinOp { } // namespace vx } // namespace tim +#endif //(VSI_FEAT_OP_MOD) #endif /* TIM_VX_OPS_MOD_H_ */ -#endif //(VSI_FEAT_OP_MOD) \ No newline at end of file diff --git a/src/tim/vx/ops/cumsum.cc b/src/tim/vx/ops/cumsum.cc index 54f2185..37fabce 100644 --- a/src/tim/vx/ops/cumsum.cc +++ b/src/tim/vx/ops/cumsum.cc @@ -21,11 +21,13 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_CUMSUM #include "tim/vx/ops/cumsum.h" #include "builtin_op_impl.h" #include "vsi_nn_pub.h" + +#ifdef VSI_FEAT_OP_CUMSUM + namespace tim { namespace vx { namespace ops { diff --git a/src/tim/vx/ops/cumsum_test.cc b/src/tim/vx/ops/cumsum_test.cc index 6308a77..16dec9a 100644 --- a/src/tim/vx/ops/cumsum_test.cc +++ b/src/tim/vx/ops/cumsum_test.cc @@ -21,13 +21,14 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_CUMSUM #include "tim/vx/context.h" #include "tim/vx/graph.h" #include "tim/vx/ops/cumsum.h" #include "gtest/gtest.h" +#ifdef VSI_FEAT_OP_CUMSUM + TEST(CumSum, shape_4_2_fp32_axis_0_exclusive_0_reverse_0) { auto ctx = tim::vx::Context::Create(); auto graph = ctx->CreateGraph(); @@ -203,4 +204,4 @@ TEST(CumSum, shape_4_2_fp32_axis_minus1_exclusive_1_reverse_1) { EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data())); EXPECT_EQ(golden, output); } -#endif //(VSI_FEAT_OP_CUMSUM) \ No newline at end of file +#endif //(VSI_FEAT_OP_CUMSUM) diff --git a/src/tim/vx/ops/max_pool3d.cc b/src/tim/vx/ops/max_pool3d.cc index 0f63cb3..eeff182 100644 --- a/src/tim/vx/ops/max_pool3d.cc +++ b/src/tim/vx/ops/max_pool3d.cc @@ -21,12 +21,13 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MAX_POOL3D #include "tim/vx/ops/max_pool3d.h" #include "type_utils.h" #include "builtin_op_impl.h" #include "vsi_nn_pub.h" +#ifdef VSI_FEAT_OP_MAX_POOL3D + namespace tim { namespace vx { namespace ops { @@ -62,4 +63,4 @@ std::shared_ptr MaxPool3d::Clone(std::shared_ptr& graph) const } // namespace vx } // namespace tim -#endif //(VSI_FEAT_OP_MAX_POOL3D) \ No newline at end of file +#endif //(VSI_FEAT_OP_MAX_POOL3D) diff --git a/src/tim/vx/ops/max_pool3d_test.cc b/src/tim/vx/ops/max_pool3d_test.cc index 8a416b1..6890f4a 100644 --- a/src/tim/vx/ops/max_pool3d_test.cc +++ b/src/tim/vx/ops/max_pool3d_test.cc @@ -21,13 +21,13 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MAX_POOL3D - #include "tim/vx/ops/max_pool3d.h" #include "tim/vx/context.h" #include "tim/vx/graph.h" #include "gtest/gtest.h" +#ifdef VSI_FEAT_OP_MAX_POOL3D + TEST(MaxPool3d, shape_3_2_2_2_1_fp32_kernel_2_2_2_stride_1_1_1_VALID) { auto ctx = tim::vx::Context::Create(); auto graph = ctx->CreateGraph(); @@ -116,4 +116,4 @@ TEST(MaxPool3d, shape_4_2_2_1_1_fp32_kernel_2_2_2_stride_1_1_1_SAME) { EXPECT_EQ(golden, output); } -# endif //(VSI_FEAT_OP_MAX_POOL3D) \ No newline at end of file +# endif //(VSI_FEAT_OP_MAX_POOL3D) diff --git a/src/tim/vx/ops/maxpoolgrad.cc b/src/tim/vx/ops/maxpoolgrad.cc index dece28e..a1f824c 100644 --- a/src/tim/vx/ops/maxpoolgrad.cc +++ b/src/tim/vx/ops/maxpoolgrad.cc @@ -21,12 +21,14 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX #include "tim/vx/ops.h" #include "vsi_nn_pub.h" #include "op_impl.h" #include + +#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX + namespace tim { namespace vx { namespace ops { diff --git a/src/tim/vx/ops/maxpoolgrad_test.cc b/src/tim/vx/ops/maxpoolgrad_test.cc index ccbe81d..2fe4a19 100644 --- a/src/tim/vx/ops/maxpoolgrad_test.cc +++ b/src/tim/vx/ops/maxpoolgrad_test.cc @@ -21,7 +21,6 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX #include "tim/vx/context.h" #include "tim/vx/graph.h" #include "tim/vx/ops/maxpoolgrad.h" @@ -30,6 +29,8 @@ #include "gtest/gtest.h" +#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX + TEST(Fuse_MaxpoolGrad, without_overlay) { auto ctx = tim::vx::Context::Create(); auto graph = ctx->CreateGraph(); diff --git a/src/tim/vx/ops/maxpoolwithargmax2.cc b/src/tim/vx/ops/maxpoolwithargmax2.cc index 7db787f..e3ebdb1 100644 --- a/src/tim/vx/ops/maxpoolwithargmax2.cc +++ b/src/tim/vx/ops/maxpoolwithargmax2.cc @@ -21,13 +21,14 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX #include "tim/vx/ops/maxpoolwithargmax2.h" #include "builtin_op_impl.h" #include "type_utils.h" #include "vsi_nn_pub.h" +#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX + namespace tim { namespace vx { namespace ops { diff --git a/src/tim/vx/ops/maxpoolwithargmax2_test.cc b/src/tim/vx/ops/maxpoolwithargmax2_test.cc index a6a1531..fcbc18c 100644 --- a/src/tim/vx/ops/maxpoolwithargmax2_test.cc +++ b/src/tim/vx/ops/maxpoolwithargmax2_test.cc @@ -21,7 +21,7 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX + #include "tim/vx/context.h" #include "tim/vx/graph.h" #include "tim/vx/ops/maxpoolwithargmax2.h" @@ -30,6 +30,8 @@ #include "gtest/gtest.h" +#ifdef VSI_FEAT_OP_MAXPOOLWITHARGMAX + TEST(MaxpoolWithArgmax2, without_overlay) { auto ctx = tim::vx::Context::Create(); auto graph = ctx->CreateGraph(); diff --git a/src/tim/vx/ops/mod.cc b/src/tim/vx/ops/mod.cc index 828e842..6238f45 100644 --- a/src/tim/vx/ops/mod.cc +++ b/src/tim/vx/ops/mod.cc @@ -21,11 +21,13 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MOD #include "tim/vx/ops/mod.h" #include "builtin_op_impl.h" #include "vsi_nn_pub.h" + +#ifdef VSI_FEAT_OP_MOD + namespace tim { namespace vx { namespace ops { @@ -42,4 +44,4 @@ std::shared_ptr Mod::Clone(std::shared_ptr& graph) const { } // namespace ops } // namespace vx } // namespace tim -#endif //(VSI_FEAT_OP_MOD) \ No newline at end of file +#endif //(VSI_FEAT_OP_MOD) diff --git a/src/tim/vx/ops/mod_test.cc b/src/tim/vx/ops/mod_test.cc index 28f23c3..cbee402 100644 --- a/src/tim/vx/ops/mod_test.cc +++ b/src/tim/vx/ops/mod_test.cc @@ -21,7 +21,6 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ -#ifdef VSI_FEAT_OP_MOD #include "tim/vx/ops/mod.h" #include "tim/vx/context.h" @@ -29,6 +28,9 @@ #include "tim/vx/types.h" #include "test_utils.h" #include "gtest/gtest.h" + +#ifdef VSI_FEAT_OP_MOD + TEST(Mod, shape_2_2_3_1_fp32_fmod_0) { auto ctx = tim::vx::Context::Create(); auto graph = ctx->CreateGraph(); @@ -137,4 +139,4 @@ TEST(Mod, shape_2_2_3_1_fp32_Broadcast) { EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data())); EXPECT_EQ(golden, output); } -#endif //(VSI_FEAT_OP_MOD) \ No newline at end of file +#endif //(VSI_FEAT_OP_MOD)