From 9de8df404c26eb8c28b07ab2a08af35a698f1929 Mon Sep 17 00:00:00 2001 From: Sven Date: Thu, 1 Sep 2022 18:56:49 +0800 Subject: [PATCH] Feat: disable maxpoolwithargmax2 feature if no low-level feature avaiable (#471) Convert operation list as compiler flags in cmake, when add new operation in tim-vx, always check if the feature define is available or not - so that tim-vx can compile with legacy ovxlib library. Signed-off-by: xiang.zhang --- include/tim/vx/ops/maxpoolgrad.h | 3 +++ include/tim/vx/ops/maxpoolwithargmax2.h | 3 +++ src/tim/CMakeLists.txt | 13 +++++++++++++ src/tim/vx/ops/maxpoolgrad.cc | 3 +++ src/tim/vx/ops/maxpoolgrad_test.cc | 2 ++ src/tim/vx/ops/maxpoolwithargmax2.cc | 3 +++ src/tim/vx/ops/maxpoolwithargmax2_test.cc | 3 +++ 7 files changed, 30 insertions(+) diff --git a/include/tim/vx/ops/maxpoolgrad.h b/include/tim/vx/ops/maxpoolgrad.h index 92970ec..a07895d 100644 --- a/include/tim/vx/ops/maxpoolgrad.h +++ b/include/tim/vx/ops/maxpoolgrad.h @@ -21,6 +21,8 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ +#if VSI_FEAT_OP_MAXPOOLWITHARGMAX + #ifndef TIM_VX_OPS_MAXPOOLGRAD_H_ #define TIM_VX_OPS_MAXPOOLGRAD_H_ @@ -68,3 +70,4 @@ class MaxpoolGrad: public Operation { } // namespace tim #endif /*TIM_VX_OPS_MAXPOOLGRAD_H_*/ +#endif \ No newline at end of file diff --git a/include/tim/vx/ops/maxpoolwithargmax2.h b/include/tim/vx/ops/maxpoolwithargmax2.h index 6bfaa43..4a7bd98 100644 --- a/include/tim/vx/ops/maxpoolwithargmax2.h +++ b/include/tim/vx/ops/maxpoolwithargmax2.h @@ -21,6 +21,7 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ +#if VSI_FEAT_OP_MAXPOOLWITHARGMAX #ifndef TIM_VX_OPS_MAXPOOLWITHARGMAX2_H_ #define TIM_VX_OPS_MAXPOOLWITHARGMAX2_H_ @@ -66,3 +67,5 @@ class MaxpoolWithArgmax2 : public DirectMapOp { } // namespace tim #endif /* TIM_VX_OPS_MAXPOOLWITHARGMAX2_H_ */ + +#endif //(VSI_FEAT_OP_MAXPOOLWITHARGMAX) \ No newline at end of file diff --git a/src/tim/CMakeLists.txt b/src/tim/CMakeLists.txt index be0da74..b1dbc34 100644 --- a/src/tim/CMakeLists.txt +++ b/src/tim/CMakeLists.txt @@ -81,6 +81,19 @@ if(${TIM_VX_ENABLE_VIPLITE}) ) endif() +# convert op list as compile flags so that we can implement compile compatable easier +if(${TIM_VX_USE_EXTERNAL_OVXLIB}) + file(STRINGS "${OVXLIB_INC}/interface/ops.def" ops_file_content) +else() + file(STRINGS "./vx/internal/include/interface/ops.def" ops_file_content) +endif() +string(LENGTH "/*; Add new ops to the end.;*_/" comment_len) +string(SUBSTRING "${ops_file_content}" ${comment_len} -1 op_list_only) +string(REGEX REPLACE "DEF_OP\\(" "-DVSI_FEAT_OP_" op_list_tmp ${op_list_only}) +string(REGEX REPLACE "\\)" " " op_as_flags ${op_list_tmp}) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${op_as_flags}") + add_library(${TARGET_NAME} ${${TARGET_NAME}_SRCS}) target_include_directories(${TARGET_NAME} PRIVATE ${INC_DIRS}) target_link_libraries(${TARGET_NAME} PUBLIC diff --git a/src/tim/vx/ops/maxpoolgrad.cc b/src/tim/vx/ops/maxpoolgrad.cc index f361cce..c514964 100644 --- a/src/tim/vx/ops/maxpoolgrad.cc +++ b/src/tim/vx/ops/maxpoolgrad.cc @@ -21,6 +21,7 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ +#if VSI_FEAT_OP_MAXPOOLWITHARGMAX #include "tim/vx/ops.h" #include "vsi_nn_pub.h" #include "op_impl.h" @@ -160,3 +161,5 @@ std::shared_ptr MaxpoolGrad::Clone( } // namespace ops } // namespace vx } // namespace tim + +#endif //(VSI_FEAT_OP_MAXPOOLWITHARGMAX) \ No newline at end of file diff --git a/src/tim/vx/ops/maxpoolgrad_test.cc b/src/tim/vx/ops/maxpoolgrad_test.cc index 5395a3e..dddecac 100644 --- a/src/tim/vx/ops/maxpoolgrad_test.cc +++ b/src/tim/vx/ops/maxpoolgrad_test.cc @@ -21,6 +21,7 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ +#if VSI_FEAT_OP_MAXPOOLWITHARGMAX #include "tim/vx/context.h" #include "tim/vx/graph.h" #include "tim/vx/ops/maxpoolgrad.h" @@ -207,3 +208,4 @@ TEST(Fuse_MaxpoolGrad, with_overlay_multi_channel_multi_batch) { EXPECT_TRUE(output_tensor->CopyDataFromTensor(output_values.data())); EXPECT_EQ(golden, output_values); } +#endif \ No newline at end of file diff --git a/src/tim/vx/ops/maxpoolwithargmax2.cc b/src/tim/vx/ops/maxpoolwithargmax2.cc index 85ffc3e..a1bdc14 100644 --- a/src/tim/vx/ops/maxpoolwithargmax2.cc +++ b/src/tim/vx/ops/maxpoolwithargmax2.cc @@ -21,6 +21,7 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ +#if VSI_FEAT_OP_MAXPOOLWITHARGMAX #include "tim/vx/ops/maxpoolwithargmax2.h" #include "direct_map_op_impl.h" @@ -62,3 +63,5 @@ std::shared_ptr MaxpoolWithArgmax2::Clone( } // namespace ops } // namespace vx } // namespace tim + +#endif //(FEAT_OP_MAXPOOLWITHARGMAX) diff --git a/src/tim/vx/ops/maxpoolwithargmax2_test.cc b/src/tim/vx/ops/maxpoolwithargmax2_test.cc index 04bcab6..b7ddb2d 100644 --- a/src/tim/vx/ops/maxpoolwithargmax2_test.cc +++ b/src/tim/vx/ops/maxpoolwithargmax2_test.cc @@ -21,6 +21,7 @@ * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ +#if VSI_FEAT_OP_MAXPOOLWITHARGMAX #include "tim/vx/context.h" #include "tim/vx/graph.h" #include "tim/vx/ops/maxpoolwithargmax2.h" @@ -368,3 +369,5 @@ TEST(MaxpoolGrad, with_overlay_multi_channel_multi_batch) { EXPECT_TRUE(output_tensor->CopyDataFromTensor(output_values.data())); EXPECT_EQ(golden, output_values); } + +#endif //(VSI_FEAT_OP_MAXPOOLWITHARGMAX) \ No newline at end of file