From 664bb9a824cbc5d42dd00fff3a1024af09bc2786 Mon Sep 17 00:00:00 2001 From: zhangwen31 Date: Mon, 28 Sep 2020 03:39:54 +0000 Subject: [PATCH] [op][arm] mod: remove power_op, rename all `power` to `pow` test=develop --- docs/introduction/support_operation_list.md | 3 +- lite/backends/arm/math/CMakeLists.txt | 4 +- lite/backends/arm/math/funcs.h | 3 +- lite/backends/arm/math/{power.cc => pow.cc} | 11 ++-- lite/backends/arm/math/{power.h => pow.h} | 12 ++--- lite/kernels/arm/pow_compute.cc | 4 +- lite/operators/CMakeLists.txt | 1 - lite/operators/power_op.cc | 53 ------------------ lite/operators/power_op.h | 60 --------------------- 9 files changed, 18 insertions(+), 133 deletions(-) rename lite/backends/arm/math/{power.cc => pow.cc} (91%) rename lite/backends/arm/math/{power.h => pow.h} (84%) delete mode 100644 lite/operators/power_op.cc delete mode 100644 lite/operators/power_op.h diff --git a/docs/introduction/support_operation_list.md b/docs/introduction/support_operation_list.md index 1a0ba4e3c6..1ae8986f55 100644 --- a/docs/introduction/support_operation_list.md +++ b/docs/introduction/support_operation_list.md @@ -159,8 +159,7 @@ | not_equal | Y |   |   |   |   |   |   |   |   |   | | one_hot | Y |   |   |   |   |   |   |   |   |   | | pixel_shuffle | Y |   |   | Y | Y |   |   |   |   |   | -| pow |   |   |   |   |   |   |   |   |   |   | -| power |   |   |   | Y |   |   |   |   |   |   | +| pow |   |   |   | Y |   |   |   |   |   |   | | print | Y |   |   |   |   |   |   |   |   |   | | read_from_array | Y |   |   |   |   |   |   |   |   |   | | reciprocal |   |   |   | Y |   |   |   |   |   |   | diff --git a/lite/backends/arm/math/CMakeLists.txt b/lite/backends/arm/math/CMakeLists.txt index 88c449e6a9..26fcd8335e 100644 --- a/lite/backends/arm/math/CMakeLists.txt +++ b/lite/backends/arm/math/CMakeLists.txt @@ -101,8 +101,8 @@ if (NOT HAS_ARM_MATH_LIB_DIR) activation.cc yolo_box.cc dropout.cc - power.cc - interpolate.cc + pow.cc + interpolate.cc argmax.cc axpy.cc fill_bias_relu.cc diff --git a/lite/backends/arm/math/funcs.h b/lite/backends/arm/math/funcs.h index f1ac1d63a1..b2afa514cc 100644 --- a/lite/backends/arm/math/funcs.h +++ b/lite/backends/arm/math/funcs.h @@ -15,6 +15,7 @@ #pragma once #include + #include #include @@ -48,7 +49,7 @@ #include "lite/backends/arm/math/packed_sgemm_c4.h" #include "lite/backends/arm/math/pad2d.h" #include "lite/backends/arm/math/pooling.h" -#include "lite/backends/arm/math/power.h" +#include "lite/backends/arm/math/pow.h" #include "lite/backends/arm/math/prior_box.h" #include "lite/backends/arm/math/reduce_max.h" #include "lite/backends/arm/math/reduce_mean.h" diff --git a/lite/backends/arm/math/power.cc b/lite/backends/arm/math/pow.cc similarity index 91% rename from lite/backends/arm/math/power.cc rename to lite/backends/arm/math/pow.cc index 752c63d917..aef8277ee8 100644 --- a/lite/backends/arm/math/power.cc +++ b/lite/backends/arm/math/pow.cc @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "lite/backends/arm/math/power.h" +#include "lite/backends/arm/math/pow.h" + #include "lite/backends/arm/math/funcs.h" namespace paddle { @@ -26,13 +27,13 @@ void power(const float* din, const int num, float scale_, float shift_, - float power_) { + float factor_) { int cnt = num >> 4; int remain = num % 16; bool _do_power = true; bool _do_scale = true; bool _do_shift = true; - if (fabsf(power_ - 1.f) < 1e-6f) { + if (fabsf(factor_ - 1.f) < 1e-6f) { _do_power = false; } if (fabsf(scale_ - 1.f) < 1e-6f) { @@ -45,7 +46,7 @@ void power(const float* din, const float* ptr_in = din; float32x4_t vscale = vdupq_n_f32(scale_); float32x4_t vshift = vdupq_n_f32(shift_); - float32x4_t vpower = vdupq_n_f32(power_); + float32x4_t vpower = vdupq_n_f32(factor_); #pragma omp parallel for for (int nums = 0; nums < cnt; ++nums) { float32x4_t vr0 = vld1q_f32(ptr_in); @@ -84,7 +85,7 @@ void power(const float* din, ptr_out += 4; } for (int j = 0; j < remain; ++j) { - ptr_out[0] = std::pow((ptr_in[0] * scale_ + shift_), power_); + ptr_out[0] = std::pow((ptr_in[0] * scale_ + shift_), factor_); ptr_in++; ptr_out++; } diff --git a/lite/backends/arm/math/power.h b/lite/backends/arm/math/pow.h similarity index 84% rename from lite/backends/arm/math/power.h rename to lite/backends/arm/math/pow.h index 7b9074918d..9a01ec6e47 100644 --- a/lite/backends/arm/math/power.h +++ b/lite/backends/arm/math/pow.h @@ -20,12 +20,12 @@ namespace arm { namespace math { template -void power(const T* din, - T* dout, - const int num, - float scale_, - float shift_, - float power_); +void pow(const T* din, + T* dout, + const int num, + float scale_, + float shift_, + float factor_); } /* namespace math */ } /* namespace arm */ diff --git a/lite/kernels/arm/pow_compute.cc b/lite/kernels/arm/pow_compute.cc index f0f6c724ad..4a081e03fd 100644 --- a/lite/kernels/arm/pow_compute.cc +++ b/lite/kernels/arm/pow_compute.cc @@ -29,9 +29,7 @@ void PowCompute::Run() { float shift = 0.0; float power = param.factor; - // fixme: update lite::arm::math::power if necessary, for scale and shift is - // not used - lite::arm::math::power( + lite::arm::math::pow( x_data, output_data, x_dims.production(), scale, shift, power); } diff --git a/lite/operators/CMakeLists.txt b/lite/operators/CMakeLists.txt index 6cdf815a6f..e6b761e5a1 100644 --- a/lite/operators/CMakeLists.txt +++ b/lite/operators/CMakeLists.txt @@ -60,7 +60,6 @@ add_operator(sign_op extra SRCS sign_op.cc DEPS ${op_DEPS}) add_operator(negative_op extra SRCS negative_op.cc DEPS ${op_DEPS}) add_operator(crop_op extra SRCS crop_op.cc DEPS ${op_DEPS}) add_operator(assign_op extra SRCS assign_op.cc DEPS ${op_DEPS}) -add_operator(power_op extra SRCS power_op.cc DEPS ${op_DEPS}) add_operator(group_norm_op extra SRCS group_norm_op.cc DEPS ${op_DEPS}) add_operator(norm_op extra SRCS norm_op.cc DEPS ${op_DEPS}) diff --git a/lite/operators/power_op.cc b/lite/operators/power_op.cc deleted file mode 100644 index 83c9edfaca..0000000000 --- a/lite/operators/power_op.cc +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "lite/operators/power_op.h" -#include "lite/core/op_lite.h" -#include "lite/core/op_registry.h" -#include "lite/core/tensor.h" - -namespace paddle { -namespace lite { -namespace operators { - -bool PowerOp::CheckShape() const { - CHECK_OR_FALSE(param_.X); - CHECK_OR_FALSE(param_.Out); - return true; -} - -bool PowerOp::InferShapeImpl() const { - param_.Out->Resize(param_.X->dims()); - return true; -} - -bool PowerOp::AttachImpl(const cpp::OpDesc &op_desc, lite::Scope *scope) { - auto X = op_desc.Input("X").front(); - auto Out = op_desc.Output("Out").front(); - param_.X = scope->FindVar(X)->GetMutable(); - param_.Out = scope->FindVar(Out)->GetMutable(); - param_.scale = op_desc.GetAttr("scale"); - param_.shift = op_desc.GetAttr("shift"); - param_.power = op_desc.GetAttr("power"); - CHECK(param_.X); - CHECK(param_.Out); - - return true; -} - -} /* namespace operators */ -} /* namespace lite */ -} /* namespace paddle */ - -REGISTER_LITE_OP(power, paddle::lite::operators::PowerOp); diff --git a/lite/operators/power_op.h b/lite/operators/power_op.h deleted file mode 100644 index 0b2ab71dbf..0000000000 --- a/lite/operators/power_op.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once -#include -#include -#include "lite/core/op_lite.h" -#include "lite/core/scope.h" -#include "lite/utils/all.h" - -namespace paddle { -namespace lite { -namespace operators { - -/** - * @deprecated There is NO power op in paddle fluid - */ -class PowerOp : public OpLite { - public: - PowerOp() {} - - explicit PowerOp(const std::string &op_type) : OpLite(op_type) {} - - bool CheckShape() const override; - - bool InferShapeImpl() const override; - - bool AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) override; - - void AttachKernel(KernelBase *kernel) override { kernel->SetParam(param_); } - - std::string DebugString() const override { return "power"; } - -#ifdef LITE_WITH_PROFILE - void GetOpRuntimeInfo(paddle::lite::profile::OpCharacter *ch) { - ch->input_shape = ch->DimToStr(param_.X->dims()); - ch->output_shape = ch->DimToStr(param_.Out->dims()); - // ch->remark = ""; - ch->macs = param_.Out->numel() * 3.0f; - } -#endif - - private: - mutable PowerParam param_; -}; - -} /* namespace operators */ -} /* namespace lite */ -} /* namespace paddle */ -- GitLab