From c10a8b16f5e1412d28e2e2092b0b1576e19c4d16 Mon Sep 17 00:00:00 2001 From: zhupengyang Date: Thu, 17 Oct 2019 17:08:28 +0800 Subject: [PATCH] fix npu path (#2210) * move lite/backends/npu/bridges --> lite/kernels/npu/ test=develop * fix namespace for npu test=develop * mv npu runtime file to lite/backends/npu test=develop --- lite/backends/npu/CMakeLists.txt | 4 --- .../mir/subgraph/generate_npu_program_pass.cc | 20 ++++++------- .../mir/subgraph/generate_npu_program_pass.h | 6 ++-- lite/kernels/npu/CMakeLists.txt | 4 +++ .../npu/bridges}/CMakeLists.txt | 0 .../bridge => kernels/npu/bridges}/act_op.cc | 29 +++++++++++-------- .../npu/bridges}/act_op_test.cc | 10 ++++--- .../npu/bridges}/batch_norm_op.cc | 13 +++++---- .../npu/bridges}/batch_norm_op_test.cc | 10 ++++--- .../npu/bridges}/concat_op.cc | 13 +++++---- .../npu/bridges}/concat_op_test.cc | 10 ++++--- .../bridge => kernels/npu/bridges}/conv_op.cc | 15 ++++++---- .../npu/bridges}/conv_op_test.cc | 10 ++++--- .../npu/bridges}/conv_transpose_op.cc | 15 ++++++---- .../npu/bridges}/conv_transpose_op_test.cc | 10 ++++--- .../npu/bridges}/elementwise_ops.cc | 12 ++++---- .../npu/bridges}/elementwise_ops_test.cc | 10 ++++--- .../bridge => kernels/npu/bridges}/fc_op.cc | 12 ++++---- .../npu/bridges}/fc_op_test.cc | 12 ++++---- .../npu/bridges}/interpolate_op.cc | 14 +++++---- .../npu/bridges}/interpolate_op_test.cc | 10 ++++--- .../bridge => kernels/npu/bridges}/mul_op.cc | 12 ++++---- .../npu/bridges}/mul_op_test.cc | 12 ++++---- .../npu/bridges}/pad2d_op.cc | 12 ++++---- .../npu/bridges}/pad2d_op_test.cc | 10 ++++--- .../npu/bridges}/paddle_use_npu_bridges.h | 2 +- .../bridge => kernels/npu/bridges}/pool_op.cc | 12 ++++---- .../npu/bridges}/pool_op_test.cc | 10 ++++--- .../npu/bridges}/registry.cc | 8 +++-- .../bridge => kernels/npu/bridges}/registry.h | 10 ++++--- .../npu/bridges}/reshape_op.cc | 16 ++++++---- .../npu/bridges}/reshape_op_test.cc | 10 ++++--- .../npu/bridges}/scale_op.cc | 12 ++++---- .../npu/bridges}/scale_op_test.cc | 10 ++++--- .../npu/bridges}/shuffle_channel_op.cc | 15 ++++++---- .../npu/bridges}/shuffle_channel_op_test.cc | 10 ++++--- .../npu/bridges}/softmax_op.cc | 13 +++++---- .../npu/bridges}/softmax_op_test.cc | 10 ++++--- .../npu/bridges}/split_op.cc | 13 +++++---- .../npu/bridges}/split_op_test.cc | 12 ++++---- .../npu/bridges}/test_helper.cc | 14 +++++---- .../npu/bridges}/test_helper.h | 6 ++-- .../npu/bridges}/transpose_op.cc | 16 ++++++---- .../npu/bridges}/transpose_op_test.cc | 10 ++++--- .../bridge => kernels/npu/bridges}/utils.cc | 8 +++-- .../bridge => kernels/npu/bridges}/utils.h | 6 ++-- 46 files changed, 301 insertions(+), 207 deletions(-) rename lite/{backends/npu/bridge => kernels/npu/bridges}/CMakeLists.txt (100%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/act_op.cc (74%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/act_op_test.cc (94%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/batch_norm_op.cc (92%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/batch_norm_op_test.cc (96%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/concat_op.cc (89%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/concat_op_test.cc (95%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/conv_op.cc (96%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/conv_op_test.cc (98%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/conv_transpose_op.cc (95%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/conv_transpose_op_test.cc (98%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/elementwise_ops.cc (90%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/elementwise_ops_test.cc (96%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/fc_op.cc (94%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/fc_op_test.cc (94%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/interpolate_op.cc (94%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/interpolate_op_test.cc (98%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/mul_op.cc (94%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/mul_op_test.cc (93%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/pad2d_op.cc (92%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/pad2d_op_test.cc (97%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/paddle_use_npu_bridges.h (96%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/pool_op.cc (92%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/pool_op_test.cc (97%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/registry.cc (88%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/registry.h (92%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/reshape_op.cc (92%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/reshape_op_test.cc (97%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/scale_op.cc (92%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/scale_op_test.cc (95%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/shuffle_channel_op.cc (86%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/shuffle_channel_op_test.cc (95%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/softmax_op.cc (88%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/softmax_op_test.cc (95%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/split_op.cc (92%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/split_op_test.cc (95%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/test_helper.cc (92%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/test_helper.h (95%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/transpose_op.cc (86%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/transpose_op_test.cc (96%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/utils.cc (97%) rename lite/{backends/npu/bridge => kernels/npu/bridges}/utils.h (97%) diff --git a/lite/backends/npu/CMakeLists.txt b/lite/backends/npu/CMakeLists.txt index a98908a3bd..370f620b91 100644 --- a/lite/backends/npu/CMakeLists.txt +++ b/lite/backends/npu/CMakeLists.txt @@ -3,7 +3,3 @@ if(NOT LITE_WITH_NPU) endif() lite_cc_library(npu_runtime SRCS runtime.cc DEPS npu_ddk_hiai) - -if(NOT LITE_ON_TINY_PUBLISH) - add_subdirectory(bridge) -endif() diff --git a/lite/core/mir/subgraph/generate_npu_program_pass.cc b/lite/core/mir/subgraph/generate_npu_program_pass.cc index 5c297288e6..c47ab60d63 100644 --- a/lite/core/mir/subgraph/generate_npu_program_pass.cc +++ b/lite/core/mir/subgraph/generate_npu_program_pass.cc @@ -27,9 +27,9 @@ #include "ai_ddk_lib/include/graph/model.h" #include "ai_ddk_lib/include/graph/op/all_ops.h" // for ge::op::Data #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/paddle_use_npu_bridges.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/paddle_use_npu_bridges.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { @@ -51,7 +51,7 @@ std::shared_ptr GenerateNPUProgramPass::CvtVarNode( auto wgt = std::make_shared(arg.name); LOG(INFO) << "in convert const:" << arg.name; VLOG(4) << dims; - wgt->set_attr_value(lite::npu::bridge::CvtFromLiteTensor(tensor)); + wgt->set_attr_value(lite::kernels::npu::bridges::CvtFromLiteTensor(tensor)); return wgt; } else { CHECK_EQ(dims.size(), 4); @@ -74,13 +74,13 @@ std::shared_ptr GenerateNPUProgramPass::CvtVarNode( void GenerateNPUProgramPass::CvtAllOpNodes( const std::vector& nodes2cvt, - lite::npu::bridge::node_map_type* converted_vars) { - const auto& bridges = lite::npu::bridge::Factory::Instance(); + lite::kernels::npu::bridges::node_map_type* converted_vars) { + const auto& bridges = lite::kernels::npu::bridges::Factory::Instance(); const auto& cvtfunc_map = bridges.AllFunctions(); // return record all converted vars // op node's inputs must be found in converted_vars for (auto& node : nodes2cvt) { - lite::npu::bridge::node_map_type node_inputs; + lite::kernels::npu::bridges::node_map_type node_inputs; auto& stmt = node->AsStmt(); for (auto& var_node : node->inlinks) { auto& arg = var_node->AsArg(); @@ -106,7 +106,7 @@ std::string GenerateNPUProgramPass::BuildNPUGraph( const std::unordered_set& out_data_vars, int sub_id) { auto ordered_nodes = GetTopologicalOrder(op_nodes); - lite::npu::bridge::node_map_type converted_vars; + lite::kernels::npu::bridges::node_map_type converted_vars; CvtAllOpNodes(ordered_nodes, &converted_vars); std::vector in_var_names; @@ -132,7 +132,7 @@ std::string GenerateNPUProgramPass::BuildNPUGraph( // Compiling IR graph to NPU model and store mode data into weight tensor with // persistable=true, Sothat the model parser can recognize it and save it to // param files - if (!lite::npu::bridge::BuildModel(inputs, outputs, weight)) { + if (!lite::kernels::npu::bridges::BuildModel(inputs, outputs, weight)) { LOG(WARNING) << "Build NPU failed subgraph " << sub_id; throw std::runtime_error("Build NPU failed subgraph."); } @@ -172,7 +172,7 @@ void GenerateNPUProgramPass::GenNPUSubgraph( void GenerateNPUProgramPass::Apply(const std::unique_ptr& graph) { LOG(INFO) << "Before NPU Pass \n" << Visualize(graph.get()); - const auto& bridges = lite::npu::bridge::Factory::Instance(); + const auto& bridges = lite::kernels::npu::bridges::Factory::Instance(); const auto& op_map = bridges.AllFunctions(); std::vector supported_op_types; for (auto& i : op_map) { diff --git a/lite/core/mir/subgraph/generate_npu_program_pass.h b/lite/core/mir/subgraph/generate_npu_program_pass.h index 172e4805f3..be6b1aa24c 100644 --- a/lite/core/mir/subgraph/generate_npu_program_pass.h +++ b/lite/core/mir/subgraph/generate_npu_program_pass.h @@ -20,10 +20,10 @@ #include #include #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" #include "lite/core/mir/pass.h" #include "lite/core/mir/subgraph/subgraph_program_pass.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { @@ -41,7 +41,7 @@ class GenerateNPUProgramPass : public SubgraphProgramPass { // nodes2cvt: op nodes to convert // return cvted_vars: converted var nodes void CvtAllOpNodes(const std::vector& nodes2cvt, - lite::npu::bridge::node_map_type* cvted_vars); + lite::kernels::npu::bridges::node_map_type* cvted_vars); std::shared_ptr CvtVarNode(lite::mir::Node* var_node, const Scope* scope); diff --git a/lite/kernels/npu/CMakeLists.txt b/lite/kernels/npu/CMakeLists.txt index 111bd04dc8..eb1824e111 100644 --- a/lite/kernels/npu/CMakeLists.txt +++ b/lite/kernels/npu/CMakeLists.txt @@ -7,3 +7,7 @@ message(STATUS "compile with lite NPU kernels") add_kernel(graph_compute_npu NPU basic SRCS graph_compute.cc DEPS ${lite_kernel_deps} npu_runtime) # lite_cc_test(test_graph_compute_npu SRCS graph_compute_test.cc DEPS graph_compute_npu) + +if(NOT LITE_ON_TINY_PUBLISH) + add_subdirectory(bridges) +endif() diff --git a/lite/backends/npu/bridge/CMakeLists.txt b/lite/kernels/npu/bridges/CMakeLists.txt similarity index 100% rename from lite/backends/npu/bridge/CMakeLists.txt rename to lite/kernels/npu/bridges/CMakeLists.txt diff --git a/lite/backends/npu/bridge/act_op.cc b/lite/kernels/npu/bridges/act_op.cc similarity index 74% rename from lite/backends/npu/bridge/act_op.cc rename to lite/kernels/npu/bridges/act_op.cc index a301fc59a2..1e8500ef28 100644 --- a/lite/backends/npu/bridge/act_op.cc +++ b/lite/kernels/npu/bridges/act_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type ActConverter(const std::shared_ptr act_op, const node_map_type& inputs_map) { @@ -72,16 +73,20 @@ node_map_type ActConverter(const std::shared_ptr act_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(sigmod, paddle::lite::npu::bridge::ActConverter); -REGISTER_NPU_BRIDGE(relu, paddle::lite::npu::bridge::ActConverter); -REGISTER_NPU_BRIDGE(tanh, paddle::lite::npu::bridge::ActConverter); -REGISTER_NPU_BRIDGE(elu, paddle::lite::npu::bridge::ActConverter); -REGISTER_NPU_BRIDGE(abs, paddle::lite::npu::bridge::ActConverter); -REGISTER_NPU_BRIDGE(softsign, paddle::lite::npu::bridge::ActConverter); -REGISTER_NPU_BRIDGE(softplus, paddle::lite::npu::bridge::ActConverter); -REGISTER_NPU_BRIDGE(hardsigmoid, paddle::lite::npu::bridge::ActConverter); +REGISTER_NPU_BRIDGE(sigmod, paddle::lite::kernels::npu::bridges::ActConverter); +REGISTER_NPU_BRIDGE(relu, paddle::lite::kernels::npu::bridges::ActConverter); +REGISTER_NPU_BRIDGE(tanh, paddle::lite::kernels::npu::bridges::ActConverter); +REGISTER_NPU_BRIDGE(elu, paddle::lite::kernels::npu::bridges::ActConverter); +REGISTER_NPU_BRIDGE(abs, paddle::lite::kernels::npu::bridges::ActConverter); +REGISTER_NPU_BRIDGE(softsign, + paddle::lite::kernels::npu::bridges::ActConverter); +REGISTER_NPU_BRIDGE(softplus, + paddle::lite::kernels::npu::bridges::ActConverter); +REGISTER_NPU_BRIDGE(hardsigmoid, + paddle::lite::kernels::npu::bridges::ActConverter); diff --git a/lite/backends/npu/bridge/act_op_test.cc b/lite/kernels/npu/bridges/act_op_test.cc similarity index 94% rename from lite/backends/npu/bridge/act_op_test.cc rename to lite/kernels/npu/bridges/act_op_test.cc index edbfbb416f..420de655dc 100644 --- a/lite/backends/npu/bridge/act_op_test.cc +++ b/lite/kernels/npu/bridges/act_op_test.cc @@ -14,15 +14,16 @@ #include #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" #include "lite/operators/relu_op.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { void relu_ref(const std::shared_ptr op) { Scope* scope = op->scope(); @@ -91,8 +92,9 @@ TEST(NPUBridges, relu) { } } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/batch_norm_op.cc b/lite/kernels/npu/bridges/batch_norm_op.cc similarity index 92% rename from lite/backends/npu/bridge/batch_norm_op.cc rename to lite/kernels/npu/bridges/batch_norm_op.cc index 8a38abd884..9f3a506d76 100644 --- a/lite/backends/npu/bridge/batch_norm_op.cc +++ b/lite/kernels/npu/bridges/batch_norm_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type BatchNormConverter( const std::shared_ptr batch_norm_op, @@ -87,9 +88,11 @@ node_map_type BatchNormConverter( return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(batch_norm, paddle::lite::npu::bridge::BatchNormConverter); +REGISTER_NPU_BRIDGE(batch_norm, + paddle::lite::kernels::npu::bridges::BatchNormConverter); diff --git a/lite/backends/npu/bridge/batch_norm_op_test.cc b/lite/kernels/npu/bridges/batch_norm_op_test.cc similarity index 96% rename from lite/backends/npu/bridge/batch_norm_op_test.cc rename to lite/kernels/npu/bridges/batch_norm_op_test.cc index ec5898f6c8..38a876efb7 100644 --- a/lite/backends/npu/bridge/batch_norm_op_test.cc +++ b/lite/kernels/npu/bridges/batch_norm_op_test.cc @@ -14,14 +14,15 @@ #include "lite/operators/batch_norm_op.h" #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { template void batch_norm_ref(const std::shared_ptr op) { @@ -157,8 +158,9 @@ TEST(NPUBridges, batch_norm) { } } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/concat_op.cc b/lite/kernels/npu/bridges/concat_op.cc similarity index 89% rename from lite/backends/npu/bridge/concat_op.cc rename to lite/kernels/npu/bridges/concat_op.cc index 1d4575db61..9684031ac7 100644 --- a/lite/backends/npu/bridge/concat_op.cc +++ b/lite/kernels/npu/bridges/concat_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type ConcatConverter(const std::shared_ptr concat_op, const node_map_type& inputs_map) { @@ -64,9 +65,11 @@ node_map_type ConcatConverter(const std::shared_ptr concat_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(concat, paddle::lite::npu::bridge::ConcatConverter); +REGISTER_NPU_BRIDGE(concat, + paddle::lite::kernels::npu::bridges::ConcatConverter); diff --git a/lite/backends/npu/bridge/concat_op_test.cc b/lite/kernels/npu/bridges/concat_op_test.cc similarity index 95% rename from lite/backends/npu/bridge/concat_op_test.cc rename to lite/kernels/npu/bridges/concat_op_test.cc index f1bf3101b2..f870bb0e7e 100644 --- a/lite/backends/npu/bridge/concat_op_test.cc +++ b/lite/kernels/npu/bridges/concat_op_test.cc @@ -15,14 +15,15 @@ #include "lite/operators/concat_op.h" #include #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { std::vector stride_numel(const DDim& ddim) { std::vector strides(ddim.size()); @@ -119,8 +120,9 @@ TEST(NPUBridges, concat) { test_concat({{3, 3, 5, 2}, {3, 3, 5, 6}}, 3); } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/conv_op.cc b/lite/kernels/npu/bridges/conv_op.cc similarity index 96% rename from lite/backends/npu/bridge/conv_op.cc rename to lite/kernels/npu/bridges/conv_op.cc index bbc27f9cfb..db1f72ed69 100644 --- a/lite/backends/npu/bridge/conv_op.cc +++ b/lite/kernels/npu/bridges/conv_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type ConvConverter(const std::shared_ptr conv_op, const node_map_type& inputs_map) { @@ -206,10 +207,12 @@ node_map_type ConvConverter(const std::shared_ptr conv_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(conv2d, paddle::lite::npu::bridge::ConvConverter); -REGISTER_NPU_BRIDGE(depthwise_conv2d, paddle::lite::npu::bridge::ConvConverter); +REGISTER_NPU_BRIDGE(conv2d, paddle::lite::kernels::npu::bridges::ConvConverter); +REGISTER_NPU_BRIDGE(depthwise_conv2d, + paddle::lite::kernels::npu::bridges::ConvConverter); diff --git a/lite/backends/npu/bridge/conv_op_test.cc b/lite/kernels/npu/bridges/conv_op_test.cc similarity index 98% rename from lite/backends/npu/bridge/conv_op_test.cc rename to lite/kernels/npu/bridges/conv_op_test.cc index 27e1226eaf..26309aa9e2 100644 --- a/lite/backends/npu/bridge/conv_op_test.cc +++ b/lite/kernels/npu/bridges/conv_op_test.cc @@ -15,14 +15,15 @@ #include "lite/operators/conv_op.h" #include #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { void conv_ref(const std::shared_ptr op) { Scope* scope = op->scope(); @@ -268,8 +269,9 @@ TEST(NPUBridges, conv) { #endif } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/conv_transpose_op.cc b/lite/kernels/npu/bridges/conv_transpose_op.cc similarity index 95% rename from lite/backends/npu/bridge/conv_transpose_op.cc rename to lite/kernels/npu/bridges/conv_transpose_op.cc index 6b62a29708..21e3c73d32 100644 --- a/lite/backends/npu/bridge/conv_transpose_op.cc +++ b/lite/kernels/npu/bridges/conv_transpose_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type ConvTransposeConverter( const std::shared_ptr conv_transpose_op, @@ -136,10 +137,12 @@ node_map_type ConvTransposeConverter( return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(conv2d_transpose, - paddle::lite::npu::bridge::ConvTransposeConverter); +REGISTER_NPU_BRIDGE( + conv2d_transpose, + paddle::lite::kernels::npu::bridges::ConvTransposeConverter); diff --git a/lite/backends/npu/bridge/conv_transpose_op_test.cc b/lite/kernels/npu/bridges/conv_transpose_op_test.cc similarity index 98% rename from lite/backends/npu/bridge/conv_transpose_op_test.cc rename to lite/kernels/npu/bridges/conv_transpose_op_test.cc index 02e3c7a1ce..a009ef588e 100644 --- a/lite/backends/npu/bridge/conv_transpose_op_test.cc +++ b/lite/kernels/npu/bridges/conv_transpose_op_test.cc @@ -15,14 +15,15 @@ #include "lite/operators/conv_transpose_op.h" #include #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { template void add_bias_with_relu(DType* data, @@ -360,8 +361,9 @@ TEST(NPUBridges, conv_transpose) { #endif } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/elementwise_ops.cc b/lite/kernels/npu/bridges/elementwise_ops.cc similarity index 90% rename from lite/backends/npu/bridge/elementwise_ops.cc rename to lite/kernels/npu/bridges/elementwise_ops.cc index 0f8da458ae..e42a933e09 100644 --- a/lite/backends/npu/bridge/elementwise_ops.cc +++ b/lite/kernels/npu/bridges/elementwise_ops.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type ElementwiseConverter( const std::shared_ptr elementwise_op, @@ -69,10 +70,11 @@ node_map_type ElementwiseConverter( return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle REGISTER_NPU_BRIDGE(elementwise_add, - paddle::lite::npu::bridge::ElementwiseConverter); + paddle::lite::kernels::npu::bridges::ElementwiseConverter); diff --git a/lite/backends/npu/bridge/elementwise_ops_test.cc b/lite/kernels/npu/bridges/elementwise_ops_test.cc similarity index 96% rename from lite/backends/npu/bridge/elementwise_ops_test.cc rename to lite/kernels/npu/bridges/elementwise_ops_test.cc index ff82daec10..0e2fc9f262 100644 --- a/lite/backends/npu/bridge/elementwise_ops_test.cc +++ b/lite/kernels/npu/bridges/elementwise_ops_test.cc @@ -15,14 +15,15 @@ #include "lite/operators/elementwise_ops.h" #include #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { template void elementwise_add_ref(const std::shared_ptr op) { @@ -173,8 +174,9 @@ TEST(NPUBridges, elementwise_add) { } } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/fc_op.cc b/lite/kernels/npu/bridges/fc_op.cc similarity index 94% rename from lite/backends/npu/bridge/fc_op.cc rename to lite/kernels/npu/bridges/fc_op.cc index 7e4315091f..b96d62fd27 100644 --- a/lite/backends/npu/bridge/fc_op.cc +++ b/lite/kernels/npu/bridges/fc_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type FCConverter(const std::shared_ptr fc_op, const node_map_type& inputs_map) { @@ -110,9 +111,10 @@ node_map_type FCConverter(const std::shared_ptr fc_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(fc, paddle::lite::npu::bridge::FCConverter); +REGISTER_NPU_BRIDGE(fc, paddle::lite::kernels::npu::bridges::FCConverter); diff --git a/lite/backends/npu/bridge/fc_op_test.cc b/lite/kernels/npu/bridges/fc_op_test.cc similarity index 94% rename from lite/backends/npu/bridge/fc_op_test.cc rename to lite/kernels/npu/bridges/fc_op_test.cc index 5c005a3e63..92936dc6bf 100644 --- a/lite/backends/npu/bridge/fc_op_test.cc +++ b/lite/kernels/npu/bridges/fc_op_test.cc @@ -14,14 +14,15 @@ #include "lite/operators/fc_op.h" #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { void fc_ref(const std::shared_ptr op) { Scope* scope = op->scope(); @@ -73,7 +74,7 @@ void test_fc(const std::vector& input_shape, bool has_bias) { CHECK_EQ(w_shape.size(), 2UL); - const auto& bridges = lite::npu::bridge::Factory::Instance(); + const auto& bridges = lite::kernels::npu::bridges::Factory::Instance(); const auto& supported_lists = bridges.AllFunctions(); CHECK(bridges.HasType("fc")); @@ -128,8 +129,9 @@ TEST(NPUBridges, fc) { } } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/interpolate_op.cc b/lite/kernels/npu/bridges/interpolate_op.cc similarity index 94% rename from lite/backends/npu/bridge/interpolate_op.cc rename to lite/kernels/npu/bridges/interpolate_op.cc index 83cae61e3f..8f3e20b023 100644 --- a/lite/backends/npu/bridge/interpolate_op.cc +++ b/lite/kernels/npu/bridges/interpolate_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type InterpolateConverter( const std::shared_ptr interpolate_op, @@ -132,12 +133,13 @@ node_map_type InterpolateConverter( return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle REGISTER_NPU_BRIDGE(bilinear_interp, - paddle::lite::npu::bridge::InterpolateConverter); + paddle::lite::kernels::npu::bridges::InterpolateConverter); REGISTER_NPU_BRIDGE(nearest_interp, - paddle::lite::npu::bridge::InterpolateConverter); + paddle::lite::kernels::npu::bridges::InterpolateConverter); diff --git a/lite/backends/npu/bridge/interpolate_op_test.cc b/lite/kernels/npu/bridges/interpolate_op_test.cc similarity index 98% rename from lite/backends/npu/bridge/interpolate_op_test.cc rename to lite/kernels/npu/bridges/interpolate_op_test.cc index 79dd612c59..c061fbfe5f 100644 --- a/lite/backends/npu/bridge/interpolate_op_test.cc +++ b/lite/kernels/npu/bridges/interpolate_op_test.cc @@ -15,14 +15,15 @@ #include "lite/operators/interpolate_op.h" #include #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { template void bilinear_interp_ref(const std::shared_ptr op) { @@ -393,8 +394,9 @@ TEST(NPUBridges, bilinear_interp) { #endif } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/mul_op.cc b/lite/kernels/npu/bridges/mul_op.cc similarity index 94% rename from lite/backends/npu/bridge/mul_op.cc rename to lite/kernels/npu/bridges/mul_op.cc index e186f04002..f22c0d611d 100644 --- a/lite/backends/npu/bridge/mul_op.cc +++ b/lite/kernels/npu/bridges/mul_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { // Note: inputs_map the var_name contains only the data, the weight should be // handle in this converter @@ -112,9 +113,10 @@ node_map_type MulConverter(const std::shared_ptr mul_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(mul, paddle::lite::npu::bridge::MulConverter); +REGISTER_NPU_BRIDGE(mul, paddle::lite::kernels::npu::bridges::MulConverter); diff --git a/lite/backends/npu/bridge/mul_op_test.cc b/lite/kernels/npu/bridges/mul_op_test.cc similarity index 93% rename from lite/backends/npu/bridge/mul_op_test.cc rename to lite/kernels/npu/bridges/mul_op_test.cc index a9fb5a6da8..9bcd72bb35 100644 --- a/lite/backends/npu/bridge/mul_op_test.cc +++ b/lite/kernels/npu/bridges/mul_op_test.cc @@ -14,14 +14,15 @@ #include "lite/operators/mul_op.h" #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { void mul_ref(const std::shared_ptr op) { Scope* scope = op->scope(); @@ -55,7 +56,7 @@ void test_mul(const std::vector& x_shape, const std::vector& y_shape, int x_num_col_dims, int y_num_col_dims) { - const auto& bridges = lite::npu::bridge::Factory::Instance(); + const auto& bridges = lite::kernels::npu::bridges::Factory::Instance(); const auto& supported_lists = bridges.AllFunctions(); CHECK(bridges.HasType("mul")); @@ -103,8 +104,9 @@ TEST(NPUBridges, mul) { test_mul({1, 4, 1, 1}, {4, 8}, 1, 1); } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/pad2d_op.cc b/lite/kernels/npu/bridges/pad2d_op.cc similarity index 92% rename from lite/backends/npu/bridge/pad2d_op.cc rename to lite/kernels/npu/bridges/pad2d_op.cc index 2c67383c0c..a8eefbbc9e 100644 --- a/lite/backends/npu/bridge/pad2d_op.cc +++ b/lite/kernels/npu/bridges/pad2d_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type Pad2dConverter(const std::shared_ptr pad2d_op, const node_map_type& inputs_map) { @@ -78,9 +79,10 @@ node_map_type Pad2dConverter(const std::shared_ptr pad2d_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(pad2d, paddle::lite::npu::bridge::Pad2dConverter); +REGISTER_NPU_BRIDGE(pad2d, paddle::lite::kernels::npu::bridges::Pad2dConverter); diff --git a/lite/backends/npu/bridge/pad2d_op_test.cc b/lite/kernels/npu/bridges/pad2d_op_test.cc similarity index 97% rename from lite/backends/npu/bridge/pad2d_op_test.cc rename to lite/kernels/npu/bridges/pad2d_op_test.cc index 7a10e0a559..db39deb2e9 100644 --- a/lite/backends/npu/bridge/pad2d_op_test.cc +++ b/lite/kernels/npu/bridges/pad2d_op_test.cc @@ -14,14 +14,15 @@ #include "lite/operators/pad2d_op.h" #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { template void pad2d_ref(const std::shared_ptr op) { @@ -180,8 +181,9 @@ TEST(NPUBridges, pad2d) { #endif } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/paddle_use_npu_bridges.h b/lite/kernels/npu/bridges/paddle_use_npu_bridges.h similarity index 96% rename from lite/backends/npu/bridge/paddle_use_npu_bridges.h rename to lite/kernels/npu/bridges/paddle_use_npu_bridges.h index 404d003954..631f6f1499 100644 --- a/lite/backends/npu/bridge/paddle_use_npu_bridges.h +++ b/lite/kernels/npu/bridges/paddle_use_npu_bridges.h @@ -14,7 +14,7 @@ #pragma once -#include "lite/backends/npu/bridge/registry.h" +#include "lite/kernels/npu/bridges/registry.h" USE_NPU_BRIDGE(mul); USE_NPU_BRIDGE(fc); diff --git a/lite/backends/npu/bridge/pool_op.cc b/lite/kernels/npu/bridges/pool_op.cc similarity index 92% rename from lite/backends/npu/bridge/pool_op.cc rename to lite/kernels/npu/bridges/pool_op.cc index 43a60c1bb3..e4d6658432 100644 --- a/lite/backends/npu/bridge/pool_op.cc +++ b/lite/kernels/npu/bridges/pool_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type PoolConverter(const std::shared_ptr pool_op, const node_map_type& inputs_map) { @@ -80,9 +81,10 @@ node_map_type PoolConverter(const std::shared_ptr pool_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(pool2d, paddle::lite::npu::bridge::PoolConverter); +REGISTER_NPU_BRIDGE(pool2d, paddle::lite::kernels::npu::bridges::PoolConverter); diff --git a/lite/backends/npu/bridge/pool_op_test.cc b/lite/kernels/npu/bridges/pool_op_test.cc similarity index 97% rename from lite/backends/npu/bridge/pool_op_test.cc rename to lite/kernels/npu/bridges/pool_op_test.cc index 86ad893084..d4543a6ae1 100644 --- a/lite/backends/npu/bridge/pool_op_test.cc +++ b/lite/kernels/npu/bridges/pool_op_test.cc @@ -15,14 +15,15 @@ #include "lite/operators/pool_op.h" #include #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { void pool_ref(const std::shared_ptr op) { Scope* scope = op->scope(); @@ -240,8 +241,9 @@ TEST(NPUBridges, pool) { } } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/registry.cc b/lite/kernels/npu/bridges/registry.cc similarity index 88% rename from lite/backends/npu/bridge/registry.cc rename to lite/kernels/npu/bridges/registry.cc index 180e0aa46e..ead7567f41 100644 --- a/lite/backends/npu/bridge/registry.cc +++ b/lite/kernels/npu/bridges/registry.cc @@ -12,13 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "lite/backends/npu/bridge/registry.h" +#include "lite/kernels/npu/bridges/registry.h" #include namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { Factory& Factory::Instance() { static Factory g_npu_bridge; @@ -33,7 +34,8 @@ void Factory::Insert(const std::string& op_type, const func_type& func_name) { map_.insert(std::make_pair(op_type, func_name)); } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/registry.h b/lite/kernels/npu/bridges/registry.h similarity index 92% rename from lite/backends/npu/bridge/registry.h rename to lite/kernels/npu/bridges/registry.h index 979760c816..efbf2461c0 100644 --- a/lite/backends/npu/bridge/registry.h +++ b/lite/kernels/npu/bridges/registry.h @@ -25,8 +25,9 @@ namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { // var_name, npu node point using node_map_type = @@ -49,8 +50,9 @@ class Factory { DISALLOW_COPY_AND_ASSIGN(Factory); }; -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle @@ -73,8 +75,8 @@ class Factory { __reg_npu_bridge_##op_type##__, \ "REGISTER_NPU_BRIDGE must be called in global namespace only once!"); \ int __reg_npu_bridge_##op_type##_Insert() { \ - paddle::lite::npu::bridge::Factory::Instance().Insert(#op_type, \ - cvt_func_name); \ + paddle::lite::kernels::npu::bridges::Factory::Instance().Insert( \ + #op_type, cvt_func_name); \ return 0; \ } diff --git a/lite/backends/npu/bridge/reshape_op.cc b/lite/kernels/npu/bridges/reshape_op.cc similarity index 92% rename from lite/backends/npu/bridge/reshape_op.cc rename to lite/kernels/npu/bridges/reshape_op.cc index af160f9c72..081c49a303 100644 --- a/lite/backends/npu/bridge/reshape_op.cc +++ b/lite/kernels/npu/bridges/reshape_op.cc @@ -19,13 +19,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type ReshapeConverter(const std::shared_ptr reshape_op, const node_map_type& inputs_map) { @@ -112,10 +113,13 @@ node_map_type ReshapeConverter(const std::shared_ptr reshape_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(reshape, paddle::lite::npu::bridge::ReshapeConverter); -REGISTER_NPU_BRIDGE(reshape2, paddle::lite::npu::bridge::ReshapeConverter); +REGISTER_NPU_BRIDGE(reshape, + paddle::lite::kernels::npu::bridges::ReshapeConverter); +REGISTER_NPU_BRIDGE(reshape2, + paddle::lite::kernels::npu::bridges::ReshapeConverter); diff --git a/lite/backends/npu/bridge/reshape_op_test.cc b/lite/kernels/npu/bridges/reshape_op_test.cc similarity index 97% rename from lite/backends/npu/bridge/reshape_op_test.cc rename to lite/kernels/npu/bridges/reshape_op_test.cc index 4a75961fdf..d675b5cac2 100644 --- a/lite/backends/npu/bridge/reshape_op_test.cc +++ b/lite/kernels/npu/bridges/reshape_op_test.cc @@ -15,14 +15,15 @@ #include "lite/operators/reshape_op.h" #include #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { void reshape_ref(const std::shared_ptr op) { auto scope = op->scope(); @@ -190,8 +191,9 @@ TEST(NPUBridges, reshape) { #endif } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/scale_op.cc b/lite/kernels/npu/bridges/scale_op.cc similarity index 92% rename from lite/backends/npu/bridge/scale_op.cc rename to lite/kernels/npu/bridges/scale_op.cc index da8924f60a..af45e6102b 100644 --- a/lite/backends/npu/bridge/scale_op.cc +++ b/lite/kernels/npu/bridges/scale_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type ScaleConverter(const std::shared_ptr scale_op, const node_map_type& inputs_map) { @@ -80,9 +81,10 @@ node_map_type ScaleConverter(const std::shared_ptr scale_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(scale, paddle::lite::npu::bridge::ScaleConverter); +REGISTER_NPU_BRIDGE(scale, paddle::lite::kernels::npu::bridges::ScaleConverter); diff --git a/lite/backends/npu/bridge/scale_op_test.cc b/lite/kernels/npu/bridges/scale_op_test.cc similarity index 95% rename from lite/backends/npu/bridge/scale_op_test.cc rename to lite/kernels/npu/bridges/scale_op_test.cc index f4a241c8d9..e3a7505903 100644 --- a/lite/backends/npu/bridge/scale_op_test.cc +++ b/lite/kernels/npu/bridges/scale_op_test.cc @@ -15,14 +15,15 @@ #include "lite/operators/scale_op.h" #include #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { void scale_ref(const std::shared_ptr op) { Scope* scope = op->scope(); @@ -114,8 +115,9 @@ TEST(NPUBridges, scale) { } } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/shuffle_channel_op.cc b/lite/kernels/npu/bridges/shuffle_channel_op.cc similarity index 86% rename from lite/backends/npu/bridge/shuffle_channel_op.cc rename to lite/kernels/npu/bridges/shuffle_channel_op.cc index 6f898007c7..5c95fd53d5 100644 --- a/lite/backends/npu/bridge/shuffle_channel_op.cc +++ b/lite/kernels/npu/bridges/shuffle_channel_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type ShuffleChannelConverter( const std::shared_ptr shuffle_channel_op, @@ -50,10 +51,12 @@ node_map_type ShuffleChannelConverter( return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(shuffle_channel, - paddle::lite::npu::bridge::ShuffleChannelConverter); +REGISTER_NPU_BRIDGE( + shuffle_channel, + paddle::lite::kernels::npu::bridges::ShuffleChannelConverter); diff --git a/lite/backends/npu/bridge/shuffle_channel_op_test.cc b/lite/kernels/npu/bridges/shuffle_channel_op_test.cc similarity index 95% rename from lite/backends/npu/bridge/shuffle_channel_op_test.cc rename to lite/kernels/npu/bridges/shuffle_channel_op_test.cc index c37c97a3b4..cbf2eac9f3 100644 --- a/lite/backends/npu/bridge/shuffle_channel_op_test.cc +++ b/lite/kernels/npu/bridges/shuffle_channel_op_test.cc @@ -14,14 +14,15 @@ #include "lite/operators/shuffle_channel_op.h" #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { void shuffle_channel_ref( const std::shared_ptr op) { @@ -106,8 +107,9 @@ TEST(NPUBridges, softmax) { } } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/softmax_op.cc b/lite/kernels/npu/bridges/softmax_op.cc similarity index 88% rename from lite/backends/npu/bridge/softmax_op.cc rename to lite/kernels/npu/bridges/softmax_op.cc index b0d8743608..7473a8ea39 100644 --- a/lite/backends/npu/bridge/softmax_op.cc +++ b/lite/kernels/npu/bridges/softmax_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type SoftmaxConverter(const std::shared_ptr softmax_op, const node_map_type& inputs_map) { @@ -58,9 +59,11 @@ node_map_type SoftmaxConverter(const std::shared_ptr softmax_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(softmax, paddle::lite::npu::bridge::SoftmaxConverter); +REGISTER_NPU_BRIDGE(softmax, + paddle::lite::kernels::npu::bridges::SoftmaxConverter); diff --git a/lite/backends/npu/bridge/softmax_op_test.cc b/lite/kernels/npu/bridges/softmax_op_test.cc similarity index 95% rename from lite/backends/npu/bridge/softmax_op_test.cc rename to lite/kernels/npu/bridges/softmax_op_test.cc index c3114f5360..50415c4b96 100644 --- a/lite/backends/npu/bridge/softmax_op_test.cc +++ b/lite/kernels/npu/bridges/softmax_op_test.cc @@ -14,14 +14,15 @@ #include "lite/operators/softmax_op.h" #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { template void softmax_ref(const std::shared_ptr op) { @@ -125,8 +126,9 @@ TEST(NPUBridges, softmax) { } } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/split_op.cc b/lite/kernels/npu/bridges/split_op.cc similarity index 92% rename from lite/backends/npu/bridge/split_op.cc rename to lite/kernels/npu/bridges/split_op.cc index eb3caa7370..97b6c19156 100644 --- a/lite/backends/npu/bridge/split_op.cc +++ b/lite/kernels/npu/bridges/split_op.cc @@ -18,13 +18,15 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { + node_map_type SplitConverter(const std::shared_ptr split_op, const node_map_type& inputs_map) { lite::Scope* scope = split_op->scope(); @@ -76,9 +78,10 @@ node_map_type SplitConverter(const std::shared_ptr split_op, return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(split, paddle::lite::npu::bridge::SplitConverter); +REGISTER_NPU_BRIDGE(split, paddle::lite::kernels::npu::bridges::SplitConverter); diff --git a/lite/backends/npu/bridge/split_op_test.cc b/lite/kernels/npu/bridges/split_op_test.cc similarity index 95% rename from lite/backends/npu/bridge/split_op_test.cc rename to lite/kernels/npu/bridges/split_op_test.cc index 91629a70fc..9bbac09a98 100644 --- a/lite/backends/npu/bridge/split_op_test.cc +++ b/lite/kernels/npu/bridges/split_op_test.cc @@ -14,14 +14,15 @@ #include "lite/operators/split_op.h" #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { template void split_ref(const std::shared_ptr op) { @@ -99,7 +100,7 @@ void test_split(int bs, int axis, int num, std::vector sections) { - const auto& bridges = lite::npu::bridge::Factory::Instance(); + const auto& bridges = lite::kernels::npu::bridges::Factory::Instance(); const auto& supported_lists = bridges.AllFunctions(); CHECK(bridges.HasType("split")); // prepare input&output variables @@ -161,8 +162,9 @@ TEST(NPUBridges, split) { test_split(4, 2, 3, 6, 3, 0, {5, 1}); } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/test_helper.cc b/lite/kernels/npu/bridges/test_helper.cc similarity index 92% rename from lite/backends/npu/bridge/test_helper.cc rename to lite/kernels/npu/bridges/test_helper.cc index 8e646e79aa..594b2db474 100644 --- a/lite/backends/npu/bridge/test_helper.cc +++ b/lite/kernels/npu/bridges/test_helper.cc @@ -12,18 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "lite/backends/npu/bridge/test_helper.h" +#include "lite/kernels/npu/bridges/test_helper.h" #include #include "ai_ddk_lib/include/graph/op/all_ops.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" #include "lite/operators/graph_op.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { void LauchOp(const std::shared_ptr op, const std::vector& input_var_names, @@ -32,7 +33,7 @@ void LauchOp(const std::shared_ptr op, auto op_type = op->op_info()->Type(); // convert op to IR graph - const auto& bridges = lite::npu::bridge::Factory::Instance(); + const auto& bridges = lite::kernels::npu::bridges::Factory::Instance(); const auto& supported_lists = bridges.AllFunctions(); CHECK(bridges.HasType(op_type)); @@ -96,8 +97,9 @@ void LauchOp(const std::shared_ptr op, OpList::Global().clear(); } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/test_helper.h b/lite/kernels/npu/bridges/test_helper.h similarity index 95% rename from lite/backends/npu/bridge/test_helper.h rename to lite/kernels/npu/bridges/test_helper.h index 537f737640..4fe22ba28b 100644 --- a/lite/backends/npu/bridge/test_helper.h +++ b/lite/kernels/npu/bridges/test_helper.h @@ -22,8 +22,9 @@ namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { template std::shared_ptr CreateOp(const cpp::OpDesc& opdesc, lite::Scope* scope) { @@ -58,7 +59,8 @@ void LauchOp(const std::shared_ptr op, const std::vector& input_var_names, const std::vector& output_var_names); -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/transpose_op.cc b/lite/kernels/npu/bridges/transpose_op.cc similarity index 86% rename from lite/backends/npu/bridge/transpose_op.cc rename to lite/kernels/npu/bridges/transpose_op.cc index 5407574763..ac243a0601 100644 --- a/lite/backends/npu/bridge/transpose_op.cc +++ b/lite/kernels/npu/bridges/transpose_op.cc @@ -18,13 +18,14 @@ #include "ai_ddk_lib/include/graph/op/all_ops.h" #include "ai_ddk_lib/include/graph/operator.h" #include "ai_ddk_lib/include/graph/operator_reg.h" -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/utils.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { node_map_type TransposeConverter( const std::shared_ptr transpose_op, @@ -68,10 +69,13 @@ node_map_type TransposeConverter( return outputs_map; } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -REGISTER_NPU_BRIDGE(transpose, paddle::lite::npu::bridge::TransposeConverter); -REGISTER_NPU_BRIDGE(transpose2, paddle::lite::npu::bridge::TransposeConverter); +REGISTER_NPU_BRIDGE(transpose, + paddle::lite::kernels::npu::bridges::TransposeConverter); +REGISTER_NPU_BRIDGE(transpose2, + paddle::lite::kernels::npu::bridges::TransposeConverter); diff --git a/lite/backends/npu/bridge/transpose_op_test.cc b/lite/kernels/npu/bridges/transpose_op_test.cc similarity index 96% rename from lite/backends/npu/bridge/transpose_op_test.cc rename to lite/kernels/npu/bridges/transpose_op_test.cc index 9bbfb11123..9ad2610caa 100644 --- a/lite/backends/npu/bridge/transpose_op_test.cc +++ b/lite/kernels/npu/bridges/transpose_op_test.cc @@ -14,14 +14,15 @@ #include "lite/operators/transpose_op.h" #include -#include "lite/backends/npu/bridge/registry.h" -#include "lite/backends/npu/bridge/test_helper.h" #include "lite/core/op_registry.h" +#include "lite/kernels/npu/bridges/registry.h" +#include "lite/kernels/npu/bridges/test_helper.h" namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { int data_index(std::vector pos, DDimLite dims) { int d1 = dims[1]; @@ -139,8 +140,9 @@ TEST(NPUBridges, transpose) { // test_transpose(1, 1, 1, 2, std::vector{0,1,2,3}); } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/utils.cc b/lite/kernels/npu/bridges/utils.cc similarity index 97% rename from lite/backends/npu/bridge/utils.cc rename to lite/kernels/npu/bridges/utils.cc index f8244c4760..933d8188c9 100644 --- a/lite/backends/npu/bridge/utils.cc +++ b/lite/kernels/npu/bridges/utils.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "lite/backends/npu/bridge/utils.h" +#include "lite/kernels/npu/bridges/utils.h" #include // NOLINT #include #include "ai_ddk_lib/include/graph/buffer.h" @@ -24,8 +24,9 @@ namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { // Build HIAI IR graph to om model, and store om model data into lite tensor bool BuildModel(std::vector& inputs, // NOLINT @@ -164,7 +165,8 @@ bool HasInputArg(const OpInfo* op_info, } } -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle diff --git a/lite/backends/npu/bridge/utils.h b/lite/kernels/npu/bridges/utils.h similarity index 97% rename from lite/backends/npu/bridge/utils.h rename to lite/kernels/npu/bridges/utils.h index 285728f8d5..382879f649 100644 --- a/lite/backends/npu/bridge/utils.h +++ b/lite/kernels/npu/bridges/utils.h @@ -25,8 +25,9 @@ namespace paddle { namespace lite { +namespace kernels { namespace npu { -namespace bridge { +namespace bridges { class OpList { public: @@ -105,7 +106,8 @@ bool HasInputArg(const OpInfo* op_info, const Scope* scope, const std::string& argname); -} // namespace bridge +} // namespace bridges } // namespace npu +} // namespace kernels } // namespace lite } // namespace paddle -- GitLab