From 9edfecaaad19d267907fbc5ce689c364d3aa5f3c Mon Sep 17 00:00:00 2001 From: zhupengyang <1165938320@qq.com> Date: Mon, 16 Mar 2020 09:23:48 +0800 Subject: [PATCH] [NPU] support increment, less than op bridge (#3147) * [NPU] subgraph's precision register to kAny --- lite/core/arena/framework.cc | 2 + lite/core/op_lite.cc | 19 +- lite/kernels/arm/CMakeLists.txt | 1 - lite/kernels/arm/compare_compute.cc | 81 +++--- lite/kernels/arm/compare_compute.h | 8 - lite/kernels/npu/bridges/CMakeLists.txt | 5 + lite/kernels/npu/bridges/compare_op.cc | 76 ++++++ lite/kernels/npu/bridges/increment_op.cc | 74 ++++++ lite/kernels/npu/bridges/paddle_use_bridges.h | 6 +- lite/kernels/npu/bridges/scale_op_test.cc | 125 --------- lite/kernels/npu/subgraph_compute.cc | 11 +- lite/kernels/npu/subgraph_compute.h | 2 +- lite/tests/kernels/CMakeLists.txt | 2 +- lite/tests/kernels/assign_compute_test.cc | 2 +- .../kernels/assign_value_compute_test.cc | 2 +- lite/tests/kernels/cast_compute_test.cc | 2 +- lite/tests/kernels/compare_compute_test.cc | 247 +++++++++--------- ...l_constant_batch_size_like_compute_test.cc | 2 +- .../kernels/fill_constant_compute_test.cc | 2 +- lite/tests/kernels/gather_compute_test.cc | 2 +- lite/tests/kernels/increment_compute_test.cc | 17 +- .../kernels/lookup_table_compute_test.cc | 2 +- .../lookup_table_dequant_compute_test.cc | 2 +- .../kernels/read_from_array_compute_test.cc | 2 +- .../kernels/write_to_array_compute_test.cc | 2 +- 25 files changed, 367 insertions(+), 329 deletions(-) create mode 100644 lite/kernels/npu/bridges/compare_op.cc create mode 100644 lite/kernels/npu/bridges/increment_op.cc delete mode 100644 lite/kernels/npu/bridges/scale_op_test.cc diff --git a/lite/core/arena/framework.cc b/lite/core/arena/framework.cc index ac822e3764..614ee990a9 100644 --- a/lite/core/arena/framework.cc +++ b/lite/core/arena/framework.cc @@ -59,6 +59,8 @@ void TestCase::CreateInstruction() { CHECK(it != kernels.end()) << "failed to create the kernel in " << place_.DebugString() << " with alias: " << alias_; + // reset final place + place_ = (*it)->place(); // prepare context (*it)->SetContext(std::move(ctx_)); instruction_.reset(new Instruction(op, std::move(*it))); diff --git a/lite/core/op_lite.cc b/lite/core/op_lite.cc index 0936a44a66..c76e369466 100644 --- a/lite/core/op_lite.cc +++ b/lite/core/op_lite.cc @@ -47,18 +47,19 @@ std::vector> OpLite::CreateKernels( return kernels; } - std::set place_set; - for (auto place : places) { - place_set.insert(place); - // Pick kernels those support any Precision and any DataLayout - place.precision = PRECISION(kAny); - place_set.insert(place); - place.layout = DATALAYOUT(kAny); - place_set.insert(place); + std::set expanded_places(places.begin(), places.end()); + for (auto &place : places) { + // Pick kernels those support any Precision and any DataLayout, For example: + // kARM,kFloat,kNCHW -> kARM,kFloat,kAny; kARM,kAny,kNCHW; kARM,kAny,kAny + expanded_places.insert( + Place(place.target, place.precision, DATALAYOUT(kAny))); + expanded_places.insert(Place(place.target, PRECISION(kAny), place.layout)); + expanded_places.insert( + Place(place.target, PRECISION(kAny), DATALAYOUT(kAny))); } std::set targets; - for (auto place : place_set) { + for (auto place : expanded_places) { pick_kernel(place); targets.insert(place.target); } diff --git a/lite/kernels/arm/CMakeLists.txt b/lite/kernels/arm/CMakeLists.txt index 26ae22ce9d..bfa5c85522 100644 --- a/lite/kernels/arm/CMakeLists.txt +++ b/lite/kernels/arm/CMakeLists.txt @@ -91,7 +91,6 @@ add_kernel(lookup_table_compute_arm ARM extra SRCS lookup_table_compute.cc DEPS add_kernel(lookup_table_dequant_compute_arm ARM extra SRCS lookup_table_dequant_compute.cc DEPS ${lite_kernel_deps} math_arm) add_kernel(logical_compute_arm ARM extra SRCS logical_compute.cc DEPS ${lite_kernel_deps} math_arm) add_kernel(sequence_softmax_compute_arm ARM extra SRCS sequence_softmax_compute.cc DEPS ${lite_kernel_deps} math_arm) -add_kernel(less_than_arm ARM extra SRCS compare_compute.cc DEPS ${lite_kernel_deps} math_arm) add_kernel(while_compute_arm ARM extra SRCS while_compute.cc DEPS ${lite_kernel_deps} math_arm) add_kernel(compare_compute_arm ARM extra SRCS compare_compute.cc DEPS ${lite_kernel_deps} math_arm) add_kernel(topk_compute_arm ARM extra SRCS topk_compute.cc DEPS ${lite_kernel_deps} math_arm) diff --git a/lite/kernels/arm/compare_compute.cc b/lite/kernels/arm/compare_compute.cc index 490d3c3028..709942a0d9 100644 --- a/lite/kernels/arm/compare_compute.cc +++ b/lite/kernels/arm/compare_compute.cc @@ -73,8 +73,6 @@ inline void get_mid_dims(const lite::DDim &x_dims, (*post) *= x_dims[i]; } } -template