From 6fbfe4b4ec5c7987b49c47367d3913081f6fd26c Mon Sep 17 00:00:00 2001 From: fuzhiye Date: Wed, 24 Feb 2021 14:42:35 +0800 Subject: [PATCH] bias_add_int8 op inherit add_int8 op --- .../src/runtime/kernel/arm/int8/add_int8.h | 2 +- .../runtime/kernel/arm/int8/bias_add_int8.cc | 50 ------------------- .../runtime/kernel/arm/int8/bias_add_int8.h | 18 ++----- 3 files changed, 5 insertions(+), 65 deletions(-) diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h index 7075dfc0e00..414f88b725b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h @@ -33,7 +33,7 @@ class QuantizedAddCPUKernel : public LiteKernel { : LiteKernel(parameter, inputs, outputs, ctx, primitive) { arith_para_ = reinterpret_cast(parameter); } - ~QuantizedAddCPUKernel() override {} + ~QuantizedAddCPUKernel() override = default; int Init() override; int ReSize() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc index 2b190c00619..638f0433ee0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc @@ -15,10 +15,7 @@ */ #include "src/runtime/kernel/arm/int8/bias_add_int8.h" -#include "nnacl/fp32/arithmetic_fp32.h" -#include "nnacl/errorcode.h" #include "src/kernel_registry.h" -#include "include/errorcode.h" using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; @@ -26,52 +23,5 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_BiasAdd; namespace mindspore::kernel { -int BiasAddInt8CPUKernel::Init() { - if (!InferShapeDone()) { - return RET_OK; - } - return ReSize(); -} - -int BiasAddInt8CPUKernel::ReSize() { - auto bias_param = reinterpret_cast(op_parameter_); - auto dims = in_tensors_.at(0)->shape(); - bias_param->ndim_ = dims.size(); - if (bias_param->ndim_ < 1 || bias_param->ndim_ > 5) { - MS_LOG(ERROR) << "input shape is invalid"; - return RET_ERROR; - } - for (size_t i = 0; i < bias_param->ndim_; i++) { - bias_param->in_shape0_[i] = dims[i]; - bias_param->in_shape1_[i] = 1; - bias_param->out_shape_[i] = dims[i]; - } - bias_param->in_shape1_[bias_param->ndim_ - 1] = dims[bias_param->ndim_ - 1]; - return RET_OK; -} - -int BiasAddInt8CPUKernel::Run() { - auto in = reinterpret_cast(in_tensors_.at(0)->MutableData()); - auto bias = reinterpret_cast(in_tensors_.at(1)->MutableData()); - auto out = reinterpret_cast(out_tensors_.at(0)->MutableData()); - size_t data_size = in_tensors_.at(0)->ElementsNum(); - auto tile_in = static_cast(ctx_->allocator->Malloc(data_size)); - if (tile_in == nullptr) { - MS_LOG(ERROR) << "Failed to malloc momery"; - return NNACL_ERR; - } - auto tile_bias = static_cast(ctx_->allocator->Malloc(data_size)); - if (tile_bias == nullptr) { - MS_LOG(ERROR) << "Failed to malloc momery"; - ctx_->allocator->Free(tile_in); - return NNACL_ERR; - } - BroadcastAddInt8(in, bias, tile_in, tile_bias, out, data_size, - reinterpret_cast(op_parameter_)); - ctx_->allocator->Free(tile_in); - ctx_->allocator->Free(tile_bias); - return NNACL_OK; -} - REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_BiasAdd, LiteKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h index 016bf13ad79..b7858383c2a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h @@ -17,26 +17,16 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_BAIS_ADD_INT8_H_ #include -#include "src/lite_kernel.h" -#include "nnacl/arithmetic.h" -#include "nnacl/int8/add_int8.h" -#include "nnacl/int8/arithmetic_int8.h" +#include "src/runtime/kernel/arm/int8/add_int8.h" namespace mindspore::kernel { -class BiasAddInt8CPUKernel : public LiteKernel { +class BiasAddInt8CPUKernel : public QuantizedAddCPUKernel { public: BiasAddInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx) {} - ~BiasAddInt8CPUKernel() = default; - - int Init() override; - int ReSize() override; - int Run() override; - - private: - const lite::InnerContext *ctx_; + : QuantizedAddCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + ~BiasAddInt8CPUKernel() override = default; }; } // namespace mindspore::kernel