diff --git a/mindspore/lite/nnacl/batch_to_space.h b/mindspore/lite/nnacl/batch_to_space.h index 04e43e22a6e..43b15bacac8 100644 --- a/mindspore/lite/nnacl/batch_to_space.h +++ b/mindspore/lite/nnacl/batch_to_space.h @@ -24,6 +24,7 @@ typedef struct BatchToSpaceParameter { OpParameter op_parameter_; int32_t block_shape_[BATCH_TO_SPACE_BLOCK_SHAPE_SIZE]; int32_t crops_[BATCH_TO_SPACE_CROPS_SIZE]; + bool no_crop_; } BatchToSpaceParameter; #ifdef __cplusplus diff --git a/mindspore/lite/src/lite_kernel.h b/mindspore/lite/src/lite_kernel.h index 9e79e7ac4d5..2a19c7966f7 100644 --- a/mindspore/lite/src/lite_kernel.h +++ b/mindspore/lite/src/lite_kernel.h @@ -227,6 +227,27 @@ class LiteKernelUtil { static int SetInput(LiteKernel &kernelMod, const std::vector &inputs); }; + +template +kernel::LiteKernel *CPUKernelCreator(const std::vector &inputs, + const std::vector &outputs, OpParameter *parameter, + const lite::InnerContext *ctx, const kernel::KernelKey &desc, + const mindspore::lite::PrimitiveC *primitive) { + auto *kernel = new (std::nothrow) T(parameter, inputs, outputs, ctx, primitive); + if (kernel == nullptr) { + MS_LOG(ERROR) << "kernel: " << parameter->name_ << "is nullptr."; + free(parameter); + return nullptr; + } + + auto ret = kernel->Init(); + if (ret != lite::RET_OK) { + MS_LOG(ERROR) << "Init kernel failed, name: " << parameter->name_; + delete kernel; + return nullptr; + } + return kernel; +} } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_LITE_KERNEL_H_ diff --git a/mindspore/lite/src/ops/populate/batch_to_space_populate.cc b/mindspore/lite/src/ops/populate/batch_to_space_populate.cc index 538a4957ec2..4a89dbdba2f 100644 --- a/mindspore/lite/src/ops/populate/batch_to_space_populate.cc +++ b/mindspore/lite/src/ops/populate/batch_to_space_populate.cc @@ -51,8 +51,12 @@ OpParameter *PopulateBatchToSpaceParameter(const mindspore::lite::PrimitiveC *pr batch_space_param->block_shape_[i] = block_shape[i]; } + batch_space_param->no_crop_ = true; for (int i = 0; i < BATCH_TO_SPACE_CROPS_SIZE; ++i) { batch_space_param->crops_[i] = crops[i]; + if (batch_space_param->crops_[i] != 0) { + batch_space_param->no_crop_ = false; + } } return reinterpret_cast(batch_space_param); } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/assert.cc b/mindspore/lite/src/runtime/kernel/arm/base/assert.cc index 49250b4d463..a84310646e5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/assert.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/assert.cc @@ -24,7 +24,6 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Assert; namespace mindspore::kernel { - int AssertCPUKernel::Init() { return RET_OK; } int AssertCPUKernel::ReSize() { return RET_OK; } @@ -41,37 +40,6 @@ int AssertCPUKernel::Run() { } } -kernel::LiteKernel *CpuAssertKernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *parameter, - const lite::InnerContext *ctx, const KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr) { - MS_LOG(ERROR) << "parameter is nullptr"; - return nullptr; - } - if (ctx == nullptr) { - MS_LOG(ERROR) << "ctx is nullptr"; - free(parameter); - return nullptr; - } - MS_ASSERT(desc.type == PrimitiveType_Assert); - auto *kernel = new (std::nothrow) AssertCPUKernel(parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; - free(parameter); - return nullptr; - } - - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << parameter->name_ - << ", type: " << schema::EnumNamePrimitiveType(static_cast(parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Assert, CpuAssertKernelCreator) -REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_Assert, CpuAssertKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Assert, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_Assert, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/assert.h b/mindspore/lite/src/runtime/kernel/arm/base/assert.h index 5e7e109d025..6195a8390dd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/assert.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/assert.h @@ -20,27 +20,17 @@ #include "src/lite_kernel.h" namespace mindspore::kernel { - -typedef struct AssertParameter { - OpParameter op_parameter_; -} AssertParameter; - class AssertCPUKernel : public LiteKernel { public: AssertCPUKernel(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) { - assert_param_ = reinterpret_cast(op_parameter_); - } + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~AssertCPUKernel() override {} int Init() override; int ReSize() override; int Run() override; - - private: - AssertParameter *assert_param_ = nullptr; }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc deleted file mode 100644 index 9e1c80475dd..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 "src/runtime/kernel/arm/base/batch_to_space_base.h" -#include "nnacl/batch_to_space.h" -#include "src/runtime/kernel/arm/fp32/batch_to_space_fp32.h" -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "include/context.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_FORMAT_ERR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_BatchToSpace; -using mindspore::schema::PrimitiveType_BatchToSpaceND; - -namespace mindspore::kernel { -int BatchToSpaceBaseCPUKernel::Init() { - if (in_tensors_.at(0)->format() != schema::Format::Format_NHWC) { - MS_LOG(ERROR) << "batch_to_space only support NHWC now!"; - return RET_FORMAT_ERR; - } - BatchToSpaceParameter *param = reinterpret_cast(this->op_parameter_); - for (int i = 0; i < BATCH_TO_SPACE_CROPS_SIZE; ++i) { - if (param->crops_[i] != 0) { - no_crop_ = false; - } - } - return RET_OK; -} - -int BatchToSpaceBaseCPUKernel::ReSize() { - auto shape = in_tensors_.at(0)->shape(); - if (shape.size() != 4) { - MS_LOG(ERROR) << "Unsupport shape size: " << shape.size(); - return RET_ERROR; - } - return RET_OK; -} - -kernel::LiteKernel *CpuBatchToSpaceFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *op_parameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (op_parameter == nullptr) { - MS_LOG(ERROR) << "Input op_parameter is nullptr!"; - return nullptr; - } - auto *kernel = new (std::nothrow) BatchToSpaceCPUKernel(op_parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new BatchToSpaceCPUKernel fail!"; - free(op_parameter); - return nullptr; - } - - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(op_parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_BatchToSpace, CpuBatchToSpaceFp32KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_BatchToSpaceND, CpuBatchToSpaceFp32KernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.h b/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.h deleted file mode 100644 index 95c5b7fa9ea..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_BATCH_TO_SPACE_BASE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_BATCH_TO_SPACE_BASE_H_ - -#include -#include "src/lite_kernel.h" -#include "nnacl/concat_parameter.h" - -namespace mindspore::kernel { -class BatchToSpaceBaseCPUKernel : public LiteKernel { - public: - BatchToSpaceBaseCPUKernel(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) {} - - virtual ~BatchToSpaceBaseCPUKernel() = default; - - int Init() override; - - int ReSize() override; - - int Run() override { return 0; } - - bool IsNoCrop() const { return no_crop_; } - - private: - bool no_crop_ = false; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_BATCH_TO_SPACE_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/concat_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/concat_base.cc deleted file mode 100644 index eeb732b4361..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/concat_base.cc +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 "src/runtime/kernel/arm/base/concat_base.h" -#include -#include "src/runtime/kernel/arm/fp32/concat_fp32.h" -#include "nnacl/fp32/concat_fp32.h" -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "include/context.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Concat; - -namespace mindspore::kernel { -int ConcatBaseCPUKernel::Init() { return RET_OK; } - -int ConcatBaseCPUKernel::ReSize() { - concat_param_->axis_ = - concat_param_->axis_ >= 0 ? concat_param_->axis_ : in_tensors_.front()->shape().size() + concat_param_->axis_; - return RET_OK; -} - -kernel::LiteKernel *CpuConcatInt32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Concat); - auto *kernel = new (std::nothrow) ConcatCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -kernel::LiteKernel *CpuConcatFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Concat); - auto *kernel = new (std::nothrow) ConcatCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Concat, CpuConcatInt32KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Concat, CpuConcatFp32KernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/concat_base.h b/mindspore/lite/src/runtime/kernel/arm/base/concat_base.h deleted file mode 100644 index 3a72f2d548e..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/concat_base.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_CONCAT_BASE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_CONCAT_BASE_H_ - -#include -#include "src/lite_kernel.h" -#include "nnacl/concat_parameter.h" -#include "src/runtime/kernel/arm/base/layout_transform.h" - -using mindspore::lite::InnerContext; - -namespace mindspore::kernel { -class ConcatBaseCPUKernel : public LiteKernel { - public: - ConcatBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { - concat_param_ = reinterpret_cast(op_parameter_); - } - - virtual ~ConcatBaseCPUKernel() = default; - - int Init() override; - - int ReSize() override; - - int Run() override { return 0; } - - protected: - const InnerContext *ctx_ = nullptr; - int thread_count_ = 1; - ConcatParameter *concat_param_ = nullptr; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_CONCAT_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc index e8ac28d63d0..94460ab3e31 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc @@ -31,30 +31,25 @@ int CropBaseCPUKernel::Init() { return RET_OK; } int CropBaseCPUKernel::ReSize() { auto *input_tensor = in_tensors_.at(kInputIndex); + auto *out_tensor = out_tensors_.at(kOutputIndex); auto input_shape = input_tensor->shape(); + auto output_shape = out_tensor->shape(); size_t input_dim = input_shape.size(); + size_t output_dim = output_shape.size(); crop_para_->in_shape_ = reinterpret_cast(malloc(input_dim * sizeof(int))); if (crop_para_->in_shape_ == nullptr) { MS_LOG(ERROR) << "in_shape_ is nullptr"; return RET_ERROR; } - - memcpy(reinterpret_cast(const_cast(crop_para_->in_shape_)), input_shape.data(), - sizeof(int) * input_dim); - - auto *out_tensor = out_tensors_.at(kOutputIndex); - auto output_shape = out_tensor->shape(); - size_t output_dim = output_shape.size(); + memcpy(crop_para_->in_shape_, input_shape.data(), sizeof(int) * input_dim); crop_para_->out_shape_ = reinterpret_cast(malloc(output_dim * sizeof(int))); if (crop_para_->out_shape_ == nullptr) { MS_LOG(ERROR) << "out_shape_ is nullptr"; return RET_ERROR; } - - memcpy(reinterpret_cast(const_cast(crop_para_->out_shape_)), output_shape.data(), - sizeof(int) * output_dim); + memcpy(crop_para_->out_shape_, output_shape.data(), sizeof(int) * output_dim); MS_ASSERT(input_dim <= CROP_OFFSET_MAX_SIZE); crop_para_->input_dim_ = input_dim; @@ -81,56 +76,4 @@ void CropBaseCPUKernel::PadOffset(int input_dim, CropParameter *crop_para) { crop_para->in_offset_[i] = crop_offset; } } - -kernel::LiteKernel *CpuCropInt32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Crop); - auto *kernel = new (std::nothrow) CropCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new CropCPUKernel fail!"; - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -kernel::LiteKernel *CpuCropFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Crop); - auto *kernel = new (std::nothrow) CropCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new CropCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Crop, CpuCropInt32KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Crop, CpuCropFp32KernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.h b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.h index c97d9abc528..84aac7ae3eb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.h @@ -21,15 +21,13 @@ #include "src/lite_kernel.h" #include "nnacl/crop_parameter.h" -using mindspore::lite::InnerContext; - namespace mindspore::kernel { class CropBaseCPUKernel : public LiteKernel { public: CropBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const InnerContext *ctx, + const std::vector &outputs, const mindspore::lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_) { + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { crop_para_ = reinterpret_cast(op_parameter_); crop_para_->thread_count_ = op_parameter_->thread_num_; } @@ -50,7 +48,6 @@ class CropBaseCPUKernel : public LiteKernel { protected: CropParameter *crop_para_; - int thread_count_; void PadOffset(int input_dim, CropParameter *crop_para); }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc index 3b4d5b2311e..8a95daf30e0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc @@ -30,15 +30,12 @@ using mindspore::lite::RET_PARAM_INVALID; using mindspore::schema::PrimitiveType_DepthToSpace; namespace mindspore::kernel { -int DepthToSpaceBaseCPUKernel::Init() { return RET_OK; } - int DepthToSpaceBaseCPUKernel::ReSize() { if (in_tensors_.at(0)->format() != schema::Format::Format_NHWC) { MS_LOG(ERROR) << "depth_to_space only support NHWC now!"; return RET_FORMAT_ERR; } - DepthToSpaceParameter *param = reinterpret_cast(op_parameter_); - if (param->block_size_ <= 0) { + if (param_->block_size_ <= 0) { MS_LOG(ERROR) << "Input block_size should > 0!"; return RET_PARAM_INVALID; } @@ -49,43 +46,14 @@ int DepthToSpaceBaseCPUKernel::ReSize() { } int32_t in_strides[DIMENSION_4D]; ComputeStrides(const_cast(in_tensors_.at(0)->shape().data()), in_strides, shape_size); - param->in_stride_dim0_ = in_strides[0]; - param->in_stride_dim1_ = in_strides[1]; - param->in_stride_dim2_ = in_strides[2]; + param_->in_stride_dim0_ = in_strides[0]; + param_->in_stride_dim1_ = in_strides[1]; + param_->in_stride_dim2_ = in_strides[2]; int32_t out_strides[DIMENSION_4D]; ComputeStrides(const_cast(out_tensors_.at(0)->shape().data()), out_strides, shape_size); - param->out_stride_dim0_ = out_strides[0]; - param->out_stride_dim1_ = out_strides[1]; - param->out_stride_dim2_ = out_strides[2]; + param_->out_stride_dim0_ = out_strides[0]; + param_->out_stride_dim1_ = out_strides[1]; + param_->out_stride_dim2_ = out_strides[2]; return RET_OK; } - -kernel::LiteKernel *CpuDepthToSpaceFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *op_parameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(desc.type == schema::PrimitiveType_DepthToSpace); - if (op_parameter == nullptr) { - MS_LOG(ERROR) << "Input op_parameter is nullptr!"; - return nullptr; - } - auto *kernel = new (std::nothrow) DepthToSpaceCPUKernel(op_parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new DepthToSpaceCPUKernel fail!"; - free(op_parameter); - return nullptr; - } - - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(op_parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_DepthToSpace, CpuDepthToSpaceFp32KernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.h b/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.h index 622e159da22..a5b49edf461 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.h @@ -18,8 +18,10 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_DEPTH_TO_SPACE_BASE_H_ #include +#include "include/errorcode.h" #include "src/lite_kernel.h" #include "nnacl/depth_to_space.h" +#include "nnacl/depth_to_space_parameter.h" namespace mindspore::kernel { class DepthToSpaceBaseCPUKernel : public LiteKernel { @@ -27,15 +29,16 @@ class DepthToSpaceBaseCPUKernel : public LiteKernel { DepthToSpaceBaseCPUKernel(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) {} - + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + param_ = reinterpret_cast(op_parameter_); + } virtual ~DepthToSpaceBaseCPUKernel() = default; - - int Init() override; - + int Init() override { return lite::RET_OK; } int ReSize() override; + int Run() override { return lite::RET_OK; } - int Run() override { return 0; } + protected: + DepthToSpaceParameter *param_ = nullptr; }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_DEPTH_TO_SPACE_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc index afea852cb7a..66b70c85e74 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/detection_post_process_base.cc @@ -26,7 +26,6 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_DetectionPostProcess; namespace mindspore::kernel { - void PartialArgSort(const float *scores, int *indexes, int num_to_sort, int num_values) { std::partial_sort(indexes, indexes + num_to_sort, indexes + num_values, [&scores](const int i, const int j) { if (scores[i] == scores[j]) { @@ -151,10 +150,10 @@ int DetectionPostProcessBaseCPUKernel::Run() { if (status != RET_OK) { return status; } - auto output_boxes = reinterpret_cast(out_tensors_.at(0)->MutableData()); - auto output_classes = reinterpret_cast(out_tensors_.at(1)->MutableData()); - auto output_scores = reinterpret_cast(out_tensors_.at(2)->MutableData()); - auto output_num = reinterpret_cast(out_tensors_.at(3)->MutableData()); + auto output_boxes = reinterpret_cast(out_tensors_.at(0)->data_c()); + auto output_classes = reinterpret_cast(out_tensors_.at(1)->data_c()); + auto output_scores = reinterpret_cast(out_tensors_.at(2)->data_c()); + auto output_num = reinterpret_cast(out_tensors_.at(3)->data_c()); num_boxes_ = in_tensors_.at(0)->shape().at(1); num_classes_with_bg_ = in_tensors_.at(1)->shape().at(2); @@ -256,5 +255,5 @@ int DetectionPostProcessBaseCPUKernel::Run() { } FreeAllocatedBuffer(); return RET_OK; -} // namespace mindspore::kernel +} } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.cc deleted file mode 100644 index 83cac47167d..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.cc +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 "src/runtime/kernel/arm/base/fullconnection_base.h" -#include "src/runtime/kernel/arm/fp32/fullconnection_fp32.h" -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "include/context.h" -#include "src/runtime/kernel/arm/base/dequant.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_FullConnection; - -namespace mindspore::kernel { -int FullconnectionBaseCPUKernel::Init() { - fc_param_->op_parameter_.thread_num_ = thread_count_; - return RET_OK; -} - -kernel::LiteKernel *CpuFullConnectionFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(opParameter != nullptr); - MS_ASSERT(desc.type == schema::PrimitiveType_FullConnection); - auto *weight_tensor = inputs.at(kWeightIndex); - // data of second tensor of fc may be nullptr - auto *restore_data = weight_tensor->data_c(); - auto restore_type = weight_tensor->data_type(); - bool dequant_flag = - !weight_tensor->quant_params().empty() && weight_tensor->quant_params().front().inited && restore_data != nullptr; - if (dequant_flag) { - auto *dequant_weight = kernel::DequantUtil::DequantWeight(weight_tensor); - if (dequant_weight == nullptr) { - MS_LOG(ERROR) << "dequant data is nullptr."; - return nullptr; - } - weight_tensor->set_data(dequant_weight); - } - auto kernel = new (std::nothrow) FullconnectionCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (!kernel) { - MS_LOG(ERROR) << "kernel is nullptr."; - if (dequant_flag) { - weight_tensor->FreeData(); - weight_tensor->set_data(restore_data); - weight_tensor->set_data_type(restore_type); - } - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - if (dequant_flag) { - weight_tensor->FreeData(); - weight_tensor->set_data(restore_data); - weight_tensor->set_data_type(restore_type); - } - delete kernel; - return nullptr; - } - if (dequant_flag) { - weight_tensor->FreeData(); - weight_tensor->set_data(restore_data); - weight_tensor->set_data_type(restore_type); - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_FullConnection, CpuFullConnectionFp32KernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.h b/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.h deleted file mode 100644 index 86dfccce0d7..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_FULLCONNECTION_BASE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_FULLCONNECTION_BASE_H_ - -#include -#include "src/lite_kernel.h" -#include "include/context.h" -#include "nnacl/matmul_parameter.h" - -using mindspore::lite::InnerContext; - -namespace mindspore::kernel { -class FullconnectionBaseCPUKernel : public LiteKernel { - public: - FullconnectionBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { - fc_param_ = reinterpret_cast(op_parameter_); - } - ~FullconnectionBaseCPUKernel() = default; - - int Init() override; - int ReSize() override { return 0; } - int Run() override { return 0; } - - protected: - MatMulParameter *fc_param_ = nullptr; - int thread_stride_ = 0; - const InnerContext *ctx_ = nullptr; - int thread_count_ = 1; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_FULLCONNECTION_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/gelu_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/gelu_base.cc deleted file mode 100644 index cbdddfa02cc..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/gelu_base.cc +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 "src/runtime/kernel/arm/base/gelu_base.h" -#include -#include "src/runtime/kernel/arm/fp32/gelu_fp32.h" -#include "nnacl/fp32/gelu_fp32.h" -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "include/context.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -// using mindspore::schema::PrimitiveType_GeLU; - -namespace mindspore::kernel { -int GeLUBaseCPUKernel::Init() { return RET_OK; } - -kernel::LiteKernel *CpuGeLUFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - // MS_ASSERT(desc.type == schema::PrimitiveType_GeLU); - auto *kernel = new (std::nothrow) GeLUCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new GeLUCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -// REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_GeLU, CpuGeLUFp32KernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/gelu_base.h b/mindspore/lite/src/runtime/kernel/arm/base/gelu_base.h deleted file mode 100644 index 49d54594833..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/gelu_base.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_GELU_BASE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_GELU_BASE_H_ - -#include -#include "src/lite_kernel.h" -#include "nnacl/gelu_parameter.h" -#include "src/runtime/kernel/arm/base/layout_transform.h" - -using mindspore::lite::InnerContext; - -namespace mindspore::kernel { -class GeLUBaseCPUKernel : public LiteKernel { - public: - GeLUBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { - gelu_param_ = reinterpret_cast(op_parameter_); - } - - virtual ~GeLUBaseCPUKernel() = default; - - int Init() override; - - int Run() override { return 0; } - - protected: - const InnerContext *ctx_ = nullptr; - int thread_count_ = 1; - GeLUParameter *gelu_param_ = nullptr; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_GELU_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/layout_transform.h b/mindspore/lite/src/runtime/kernel/arm/base/layout_transform.h index 851cfcb8234..500e5453d2c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/layout_transform.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/layout_transform.h @@ -21,7 +21,6 @@ #include #endif #include "nnacl/pack.h" - #include "schema/ops_generated.h" #include "src/tensor.h" diff --git a/mindspore/lite/src/runtime/kernel/arm/base/leaky_relu_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/leaky_relu_base.cc deleted file mode 100644 index cba58b92f0a..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/leaky_relu_base.cc +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 "src/runtime/kernel/arm/base/leaky_relu_base.h" -#include -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "include/context.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_LeakyReLU; - -namespace mindspore::kernel { -int LeakyReluBaseCPUKernel::Init() { return RET_OK; } - -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/leaky_relu_base.h b/mindspore/lite/src/runtime/kernel/arm/base/leaky_relu_base.h deleted file mode 100644 index 6f481d71e87..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/leaky_relu_base.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_LEAKY_RELU_BASE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_LEAKY_RELU_BASE_H_ - -#include -#include "src/lite_kernel.h" -#include "src/runtime/kernel/arm/base/layout_transform.h" - -using mindspore::lite::InnerContext; - -namespace mindspore::kernel { -class LeakyReluBaseCPUKernel : public LiteKernel { - public: - LeakyReluBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} - - ~LeakyReluBaseCPUKernel() = default; - - int Init() override; - - int ReSize() override { return 0; } - - int Run() override { return 0; } -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_LEAKY_RELU_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc deleted file mode 100644 index 14e1eb83e3d..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 "src/runtime/kernel/arm/base/matmul_base.h" -#include "src/runtime/kernel/arm/fp32/matmul_fp32.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "include/context.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_MatMul; - -namespace mindspore::kernel { -kernel::LiteKernel *CpuMatmulKernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(opParameter != nullptr); - MS_ASSERT(desc.type == schema::PrimitiveType_Concat); - - auto input_tensor = inputs.at(kInputIndex); - auto data_type = input_tensor->data_type(); - kernel::LiteKernel *kernel = nullptr; - if (data_type == kNumberTypeFloat32) { - kernel = new (std::nothrow) MatmulCPUKernel(opParameter, inputs, outputs, ctx, primitive); - } - if (kernel == nullptr) { - MS_LOG(ERROR) << "kernel is nullptr."; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_MatMul, CpuMatmulKernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.h b/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.h deleted file mode 100644 index 7942974c05c..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_MATMUL_BASE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_MATMUL_BASE_H_ - -#include -#include "src/lite_kernel.h" -#include "include/context.h" -#include "nnacl/matmul_parameter.h" - -using mindspore::lite::InnerContext; - -namespace mindspore::kernel { -class MatmulBaseCPUKernel : public LiteKernel { - public: - MatmulBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { - params_ = reinterpret_cast(op_parameter_); - } - ~MatmulBaseCPUKernel() = default; - - int Init() override { return 0; } - int ReSize() override { return 0; } - int Run() override { return 0; } - - protected: - MatMulParameter *params_ = nullptr; - int thread_stride_ = 0; - const InnerContext *ctx_ = nullptr; - int thread_count_ = 0; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_MATMUL_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/merge.cc b/mindspore/lite/src/runtime/kernel/arm/base/merge.cc index a3b2c33f91b..7a2d281006c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/merge.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/merge.cc @@ -25,7 +25,6 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Merge; namespace mindspore::kernel { - int MergeCPUKernel::FreeInWorkTensor() const { for (auto &in_tensor : this->in_tensors_) { MS_ASSERT(in_tensor != nullptr); @@ -131,35 +130,7 @@ int MergeCPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuMergeKernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *parameter, - const lite::InnerContext *ctx, const KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr) { - MS_LOG(ERROR) << "parameter is nullptr"; - return nullptr; - } - if (desc.type != PrimitiveType_Merge) { - MS_LOG(ERROR) << "type in desc is not Merge"; - free(parameter); - return nullptr; - } - if (ctx == nullptr) { - MS_LOG(ERROR) << "ctx is nullptr"; - free(parameter); - return nullptr; - } - - auto *kernel = new (std::nothrow) MergeCPUKernel(parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; - free(parameter); - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Merge, CpuMergeKernelCreator) -REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_Merge, CpuMergeKernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Merge, CpuMergeKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Merge, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_Merge, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Merge, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/merge.h b/mindspore/lite/src/runtime/kernel/arm/base/merge.h index 966d8a654ed..481a3b9ad42 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/merge.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/merge.h @@ -20,29 +20,21 @@ #include "src/lite_kernel.h" namespace mindspore::kernel { - -typedef struct MergeParameter { - OpParameter op_parameter_; -} MergeParameter; - class MergeCPUKernel : public LiteKernel { public: MergeCPUKernel(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) { - merge_param_ = reinterpret_cast(op_parameter_); - } + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~MergeCPUKernel() override {} - int FreeInWorkTensor() const override; - bool IsReady(const std::vector &scope_tensors) override; int Init() override; int ReSize() override; int Run() override; - bool PartialInputReady(int num_begin, int num_end); + int FreeInWorkTensor() const override; + bool IsReady(const std::vector &scope_tensors) override; private: - MergeParameter *merge_param_ = nullptr; + bool PartialInputReady(int num_begin, int num_end); }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/pad.cc b/mindspore/lite/src/runtime/kernel/arm/base/pad.cc deleted file mode 100644 index 38d8887b62d..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/pad.cc +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 -#include "src/runtime/kernel/arm/fp32/pad_fp32.h" -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "include/context.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Pad; - -namespace mindspore::kernel { - -kernel::LiteKernel *CpuPadFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(opParameter != nullptr); - MS_ASSERT(desc.type == schema::PrimitiveType_Pad); - auto *kernel = new (std::nothrow) PadCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new PadCPUKernel failed."; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Pad, CpuPadFp32KernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc index c0b03b78c81..506a63d1f43 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc @@ -115,31 +115,4 @@ int PoolingBaseCPUKernel::ReSize() { } return RET_OK; } - -kernel::LiteKernel *CpuPoolingFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Pooling); - auto *kernel = new (std::nothrow) PoolingCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new PoolingCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Pooling, CpuPoolingFp32KernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/power_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/power_base.cc deleted file mode 100644 index fe552c3d9e0..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/power_base.cc +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 "src/runtime/kernel/arm/base/power_base.h" -#include -#include "src/runtime/kernel/arm/fp32/power_fp32.h" -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Power; - -namespace mindspore::kernel { -int PowerBaseCPUKernel::Init() { return RET_OK; } - -int PowerBaseCPUKernel::ReSize() { return RET_OK; } - -kernel::LiteKernel *CpuPowerFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(opParameter != nullptr); - MS_ASSERT(desc.type == schema::PrimitiveType_Power); - PowerCPUKernel *kernel = new (std::nothrow) PowerCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new PowerCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Power, CpuPowerFp32KernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/power_base.h b/mindspore/lite/src/runtime/kernel/arm/base/power_base.h deleted file mode 100644 index 8691790fbab..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/power_base.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_POWER_BASE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_POWER_BASE_H_ - -#include -#include "src/lite_kernel.h" -#include "nnacl/power_parameter.h" - -namespace mindspore::kernel { -class PowerBaseCPUKernel : public LiteKernel { - public: - PowerBaseCPUKernel(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) { - param_ = reinterpret_cast(op_parameter_); - } - ~PowerBaseCPUKernel() = default; - - int Init() override; - int ReSize() override; - int Run() override { return 0; } - - protected: - PowerParameter *param_; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_POWER_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc b/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc index b190e822b5a..ac9153e5999 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc @@ -174,35 +174,6 @@ int PriorBoxCPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuPriorBoxKernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *op_parameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (op_parameter == nullptr) { - MS_LOG(ERROR) << "Input op_parameter is nullptr!"; - return nullptr; - } - if (desc.type != schema::PrimitiveType_PriorBox) { - MS_LOG(ERROR) << "PriorBox invalid desc type " << desc.type; - free(op_parameter); - return nullptr; - } - auto *kernel = new (std::nothrow) PriorBoxCPUKernel(op_parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new PriorBoxCPUKernel fail!"; - free(op_parameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(op_parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_PriorBox, CpuPriorBoxKernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_PriorBox, CpuPriorBoxKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_PriorBox, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_PriorBox, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc b/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc index cc3a47cbc7c..55e01d5ab8b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc @@ -212,31 +212,7 @@ int QuantDTypeCastCPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuQuantDTypeCastFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - auto *kernel = new (std::nothrow) QuantDTypeCastCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new QuantDTypeCastCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed! name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeUInt8, PrimitiveType_QuantDTypeCast, CpuQuantDTypeCastFp32KernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_QuantDTypeCast, CpuQuantDTypeCastFp32KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_QuantDTypeCast, CpuQuantDTypeCastFp32KernelCreator) +REG_KERNEL(kCPU, kNumberTypeUInt8, PrimitiveType_QuantDTypeCast, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_QuantDTypeCast, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_QuantDTypeCast, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.cc index 1328893318b..ebe0cd518da 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.cc @@ -200,28 +200,4 @@ kernel::LiteKernel *CpuReduceFp32KernelCreator(const std::vector } return kernel; } - -kernel::LiteKernel *CpuMeanFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - auto *kernel = new (std::nothrow) ReduceCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "Reduce new ReduceCPUKernel failed."; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Reduce, CpuReduceFp32KernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt, PrimitiveType_Reduce, CpuReduceFp32KernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Reduce, CpuReduceFp32KernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc deleted file mode 100644 index 56f2fa5d733..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 "src/runtime/kernel/arm/base/reshape_base.h" -#include -#include "src/runtime/kernel/arm/fp32/reshape_fp32.h" -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "include/context.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Reshape; - -namespace mindspore::kernel { -int ReshapeBaseCPUKernel::Init() { return RET_OK; } - -kernel::LiteKernel *CpuReshapeInt32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Reshape); - auto *kernel = new (std::nothrow) ReshapeCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new ReshapeCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -kernel::LiteKernel *CpuReshapeFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Reshape); - auto *kernel = new (std::nothrow) ReshapeCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new ReshapeCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Reshape, CpuReshapeInt32KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Reshape, CpuReshapeFp32KernelCreator) -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.h b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.h deleted file mode 100644 index 02c92c67b59..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_RESHAPE_BASE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_RESHAPE_BASE_H_ - -#include -#include "src/lite_kernel.h" -#include "nnacl/reshape_parameter.h" - -using mindspore::lite::InnerContext; - -namespace mindspore::kernel { -class ReshapeBaseCPUKernel : public LiteKernel { - public: - ReshapeBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx) { - reshape_param_ = reinterpret_cast(op_parameter_); - } - ~ReshapeBaseCPUKernel() = default; - - int Init() override; - int ReSize() override { return 0; } - int Run() override { return 0; } - - protected: - const InnerContext *ctx_; - ReshapeParameter *reshape_param_; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_RESHAPE_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc index 8860cedfead..f5565689197 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc @@ -126,32 +126,4 @@ int ResizeBaseCPUKernel::Init() { return RET_OK; } - -kernel::LiteKernel *CpuResizeFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Resize); - auto *kernel = new (std::nothrow) ResizeCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new ResizeCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Resize, CpuResizeFp32KernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc index b7d27e12b47..956e77b2d24 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc @@ -54,31 +54,4 @@ int SoftmaxBaseCPUKernel::ReSize() { softmax_param_->element_size_ = ele_size; return RET_OK; } - -kernel::LiteKernel *CpuSoftmaxFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_SoftMax); - auto *kernel = new (std::nothrow) SoftmaxCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new SoftmaxCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_SoftMax, CpuSoftmaxFp32KernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc index 0f22e0b9bec..19ce8b28daf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc @@ -75,57 +75,4 @@ int SplitBaseCPUKernel::ReSize() { thread_n_stride_ = UP_DIV(num_unit_, thread_n_num_); return RET_OK; } - -kernel::LiteKernel *CpuSplitInt32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Split); - auto *kernel = new (std::nothrow) SplitCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new SplitCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - delete kernel; - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - return nullptr; - } - return kernel; -} - -kernel::LiteKernel *CpuSplitFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Split); - auto *kernel = new (std::nothrow) SplitCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new SplitCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Split, CpuSplitInt32KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Split, CpuSplitFp32KernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc deleted file mode 100644 index c011b4a4152..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 "src/runtime/kernel/arm/base/squeeze_base.h" -#include -#include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "include/context.h" - -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Squeeze; - -namespace mindspore::kernel { -int SqueezeBaseCPUKernel::Init() { return RET_OK; } - -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.h b/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.h deleted file mode 100644 index 3a7b2a7d4bb..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_SQUEEZE_BASE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_SQUEEZE_BASE_H_ - -#include -#include "src/lite_kernel.h" -#include "nnacl/squeeze_parameter.h" -#include "src/runtime/kernel/arm/base/layout_transform.h" - -using mindspore::lite::InnerContext; - -namespace mindspore::kernel { -class SqueezeBaseCPUKernel : public LiteKernel { - public: - SqueezeBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) {} - - virtual ~SqueezeBaseCPUKernel() = default; - - int Init() override; - - int ReSize() override { return 0; } - - int Run() override { return 0; } - - protected: - int *axis_; - const InnerContext *ctx_; - int thread_count_; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_SQUEEZE_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc index a1d19b3a978..19b414b41d5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc @@ -70,7 +70,7 @@ int StridedSliceCPUKernel::Run() { } auto output = out_tensors_.at(0); MS_ASSERT(output); - auto ret = DoStridedSlice(input->MutableData(), output->MutableData(), param_); + auto ret = DoStridedSlice(input->data_c(), output->data_c(), param_); if (ret != RET_OK) { MS_LOG(ERROR) << "StridedSlice error error_code[" << ret << "]"; return RET_ERROR; @@ -78,33 +78,7 @@ int StridedSliceCPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuStridedSliceKernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(desc.type == schema::PrimitiveType_StridedSlice); - if (opParameter == nullptr) { - MS_LOG(ERROR) << "opParameter null pointer dereferencing."; - return nullptr; - } - auto *kernel = new (std::nothrow) StridedSliceCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "New kernel fails."; - free(opParameter); - return nullptr; - } - - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_StridedSlice, CpuStridedSliceKernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_StridedSlice, CpuStridedSliceKernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_StridedSlice, CpuStridedSliceKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_StridedSlice, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_StridedSlice, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_StridedSlice, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/switch.cc b/mindspore/lite/src/runtime/kernel/arm/base/switch.cc index e136f04f0e9..810b51d3d0e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/switch.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/switch.cc @@ -91,34 +91,7 @@ int SwitchCPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuSwitchKernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *parameter, - const lite::InnerContext *ctx, const KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr) { - MS_LOG(ERROR) << "parameter is nullptr"; - return nullptr; - } - if (desc.type != PrimitiveType_Switch) { - MS_LOG(ERROR) << "type in desc is not Switch"; - free(parameter); - return nullptr; - } - if (ctx == nullptr) { - MS_LOG(ERROR) << "ctx is nullptr"; - free(parameter); - return nullptr; - } - auto *kernel = new (std::nothrow) SwitchCPUKernel(parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; - free(parameter); - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Switch, CpuSwitchKernelCreator) -REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_Switch, CpuSwitchKernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Switch, CpuSwitchKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Switch, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_Switch, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Switch, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc index 4cf00d8b96f..235e06059a6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/activation_fp16.cc @@ -136,27 +136,5 @@ int ActivationFp16CPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuActivationFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(opParameter != nullptr); - MS_ASSERT(desc.type == schema::PrimitiveType_Activation); - auto *kernel = new (std::nothrow) ActivationFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "kernel is nullptr."; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Activation, CpuActivationFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Activation, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_compare_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_compare_fp16.cc index c4cfb7b1374..761429f8d8d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_compare_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_compare_fp16.cc @@ -184,35 +184,10 @@ void ArithmeticCompareFP16CPUKernel::FreeTmpBuffer() { } } -kernel::LiteKernel *CpuArithmeticCompareFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *parameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr) { - MS_LOG(ERROR) << "input parameter is null!"; - return nullptr; - } - auto kernel = new (std::nothrow) ArithmeticCompareFP16CPUKernel(parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; - free(parameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << parameter->name_ - << ", type: " << schema::EnumNamePrimitiveType(static_cast(parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_NotEqual, CpuArithmeticCompareFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Equal, CpuArithmeticCompareFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Less, CpuArithmeticCompareFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_LessEqual, CpuArithmeticCompareFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Greater, CpuArithmeticCompareFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_GreaterEqual, CpuArithmeticCompareFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_NotEqual, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Equal, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Less, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_LessEqual, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Greater, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_GreaterEqual, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc index f1498ff47b1..f4037d75937 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc @@ -236,40 +236,16 @@ void ArithmeticFP16CPUKernel::FreeTmpBuffer() { } } -kernel::LiteKernel *CpuArithmeticFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *parameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr) { - MS_LOG(ERROR) << "input parameter is null!"; - return nullptr; - } - auto kernel = new (std::nothrow) ArithmeticFP16CPUKernel(parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; - free(parameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << parameter->name_ - << ", type: " << schema::EnumNamePrimitiveType(static_cast(parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Mul, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Add, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Sub, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Div, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_FloorMod, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_FloorDiv, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_LogicalAnd, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_LogicalOr, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Maximum, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Minimum, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Eltwise, CpuArithmeticFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_SquaredDifference, CpuArithmeticFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Mul, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Add, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Sub, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Div, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_FloorMod, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_FloorDiv, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_LogicalAnd, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_LogicalOr, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Maximum, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Minimum, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Eltwise, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_SquaredDifference, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc index b9dcead1220..e85ea125dd7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc @@ -105,40 +105,17 @@ int ArithmeticSelfFp16CPUKernel::Run() { return ret; } -kernel::LiteKernel *CpuArithmeticSelfFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *parameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - auto *kernel = new (std::nothrow) ArithmeticSelfFp16CPUKernel(parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new ArithmeticSelfFp16CPUKernel fail!"; - if (parameter != nullptr) { - free(parameter); - } - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << parameter->name_ - << ", type: " << schema::EnumNamePrimitiveType(static_cast(parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Abs, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Cos, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Log, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Square, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Sqrt, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Rsqrt, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Sin, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_LogicalNot, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Floor, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Ceil, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Round, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Neg, CpuArithmeticSelfFp16KernelCreator) -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Reciprocal, CpuArithmeticSelfFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Abs, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Cos, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Log, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Square, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Sqrt, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Rsqrt, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Sin, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_LogicalNot, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Floor, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Ceil, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Round, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Neg, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Reciprocal, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc index d30c761cc5f..7287a956586 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc @@ -87,25 +87,5 @@ void BatchnormFp16CPUKernel::FreeInputAndOutput() { } } -kernel::LiteKernel *CpuBatchnormFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - auto *kernel = new (std::nothrow) BatchnormFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new BatchnormFp16CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_BatchNorm, CpuBatchnormFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_BatchNorm, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc index 061f578b4e6..613494cb194 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc @@ -128,39 +128,5 @@ int CastFp16CPUKernel::Run() { return ParallelLaunch(this->context_->thread_pool_, CastFp16Run, this, op_parameter_->thread_num_); } -kernel::LiteKernel *CpuCastFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - if (ctx == nullptr) { - MS_LOG(ERROR) << "Input context is nullptr!"; - free(opParameter); - return nullptr; - } - if (ctx->thread_num_ == 0) { - MS_LOG(ERROR) << "context thread num is 0!"; - free(opParameter); - return nullptr; - } - auto *kernel = new (std::nothrow) CastFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new CastFp16CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Cast, CpuCastFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Cast, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc index 304705adaff..e8e4db56816 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc @@ -14,12 +14,7 @@ * limitations under the License. */ #include "src/runtime/kernel/arm/fp16/concat_fp16.h" -#include "src/runtime/kernel/arm/fp16/common_fp16.h" -#include "src/runtime/kernel/arm/fp32/concat_fp32.h" -#include "nnacl/fp16/concat_fp16.h" #include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "nnacl/fp16/cast_fp16.h" using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; @@ -29,18 +24,17 @@ using mindspore::schema::PrimitiveType_Concat; namespace mindspore::kernel { int ConcatFp16CPUKernel::Init() { - auto ret = ConcatBaseCPUKernel::Init(); - if (ret != RET_OK) { - return ret; - } if (!InferShapeDone()) { return RET_OK; } - return ReSize(); } -int ConcatFp16CPUKernel::ReSize() { return ConcatBaseCPUKernel::ReSize(); } +int ConcatFp16CPUKernel::ReSize() { + concat_param_->axis_ = + concat_param_->axis_ >= 0 ? concat_param_->axis_ : in_tensors_.front()->shape().size() + concat_param_->axis_; + return RET_OK; +} int ConcatFp16CPUKernel::MallocTmpBuffer() { for (const auto &in_tensor : in_tensors_) { @@ -64,7 +58,6 @@ int ConcatFp16CPUKernel::MallocTmpBuffer() { return RET_ERROR; } } - return RET_OK; } @@ -130,28 +123,5 @@ int ConcatFp16CPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuConcatFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *parameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr) { - MS_LOG(ERROR) << "Input parameter is nullptr!"; - return nullptr; - } - kernel::LiteKernel *kernel = new (std::nothrow) ConcatFp16CPUKernel(parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; - free(parameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << parameter->name_ - << ", type: " << schema::EnumNamePrimitiveType(static_cast(parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Concat, CpuConcatFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Concat, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.h index 1603f217a7a..ee223041d71 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.h @@ -18,19 +18,24 @@ #include #include -#include "src/lite_kernel.h" #include "include/context.h" -#include "src/runtime/kernel/arm/base/concat_base.h" +#include "include/errorcode.h" +#include "nnacl/fp16/concat_fp16.h" +#include "nnacl/concat_parameter.h" +#include "nnacl/fp16/cast_fp16.h" +#include "src/lite_kernel.h" +#include "src/runtime/kernel/arm/fp16/common_fp16.h" using mindspore::lite::InnerContext; - namespace mindspore::kernel { -class ConcatFp16CPUKernel : public ConcatBaseCPUKernel { +class ConcatFp16CPUKernel : public LiteKernel { public: ConcatFp16CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : ConcatBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + concat_param_ = reinterpret_cast(op_parameter_); + } ~ConcatFp16CPUKernel() = default; @@ -47,6 +52,7 @@ class ConcatFp16CPUKernel : public ConcatBaseCPUKernel { private: std::vector fp16_inputs_; float16_t *fp16_output_ = nullptr; + ConcatParameter *concat_param_ = nullptr; }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP16_CONCAT_FP16_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc index 63cbc3f9139..9a32571663c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc @@ -14,15 +14,8 @@ * limitations under the License. */ #include "src/runtime/kernel/arm/fp16/crop_fp16.h" - -#include "include/errorcode.h" -#include "nnacl/crop_parameter.h" -#include "nnacl/fp16/cast_fp16.h" -#include "nnacl/fp16/crop_fp16.h" -#include "src/kernel_registry.h" -#include "src/runtime/kernel/arm/base/crop_base.h" -#include "src/runtime/kernel/arm/fp16/common_fp16.h" #include "src/runtime/runtime_api.h" +#include "src/kernel_registry.h" using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; @@ -31,12 +24,7 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Crop; namespace mindspore::kernel { - int CropFp16CPUKernel::Init() { - auto ret = CropBaseCPUKernel::Init(); - if (ret != RET_OK) { - return ret; - } if (!InferShapeDone()) { return RET_OK; } @@ -69,13 +57,13 @@ int CropFp16CPUKernel::Run() { return RET_ERROR; } - auto ret = ParallelLaunch(this->context_->thread_pool_, CropFp16Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, CropFp16Run, this, crop_para_->thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "ParallelLaunch failed: " << ret; FreeInputAndOutput(); } if (out_tensors_.at(kOutputIndex)->data_type() == kNumberTypeFloat32) { - Float16ToFloat32(output_ptr_, reinterpret_cast(out_tensors_.at(kOutputIndex)->MutableData()), + Float16ToFloat32(output_ptr_, reinterpret_cast(out_tensors_.at(kOutputIndex)->data_c()), out_tensors_.at(kOutputIndex)->ElementsNum()); } FreeInputAndOutput(); @@ -93,29 +81,5 @@ void CropFp16CPUKernel::FreeInputAndOutput() { } } -kernel::LiteKernel *CpuCropFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Crop); - auto *kernel = new (std::nothrow) CropFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new CropFp16CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Crop, CpuCropFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Crop, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.h index ad3facf6c28..4e925f84e46 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.h @@ -18,11 +18,14 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP16_CROP_H_ #include - #include - +#include "include/errorcode.h" +#include "nnacl/crop_parameter.h" +#include "nnacl/fp16/cast_fp16.h" +#include "nnacl/fp16/crop_fp16.h" #include "src/lite_kernel.h" #include "src/runtime/kernel/arm/base/crop_base.h" +#include "src/runtime/kernel/arm/fp16/common_fp16.h" namespace mindspore::kernel { class CropFp16CPUKernel : public CropBaseCPUKernel { @@ -30,10 +33,7 @@ class CropFp16CPUKernel : public CropBaseCPUKernel { CropFp16CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : CropBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) { - crop_para_ = reinterpret_cast(op_parameter_); - crop_para_->thread_count_ = op_parameter_->thread_num_; - } + : CropBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~CropFp16CPUKernel() override = default; int Init() override; @@ -44,7 +44,6 @@ class CropFp16CPUKernel : public CropBaseCPUKernel { private: float16_t *input_ptr_ = nullptr; float16_t *output_ptr_ = nullptr; - CropParameter *crop_para_; void FreeInputAndOutput(); }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc index 0397f1cd814..d34c0dd098c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc @@ -15,12 +15,8 @@ */ #include "src/runtime/kernel/arm/fp16/fullconnection_fp16.h" -#include "nnacl/fp16/matmul_fp16.h" -#include "nnacl/fp16/cast_fp16.h" #include "src/runtime/runtime_api.h" -#include "include/errorcode.h" #include "src/kernel_registry.h" -#include "src/runtime/kernel/arm/base/dequant.h" using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; @@ -34,19 +30,19 @@ FullconnectionFP16CPUKernel::~FullconnectionFP16CPUKernel() { FreeTmpBuffer(); } void FullconnectionFP16CPUKernel::FreeTmpBuffer() { if (a_pack_ptr_ != nullptr) { - ctx_->allocator->Free(a_pack_ptr_); + context_->allocator->Free(a_pack_ptr_); a_pack_ptr_ = nullptr; } if (b_pack_ptr_ != nullptr) { - ctx_->allocator->Free(b_pack_ptr_); + context_->allocator->Free(b_pack_ptr_); b_pack_ptr_ = nullptr; } if (bias_ptr_ != nullptr) { - ctx_->allocator->Free(bias_ptr_); + context_->allocator->Free(bias_ptr_); bias_ptr_ = nullptr; } if (output_fp16_ != nullptr) { - ctx_->allocator->Free(output_fp16_); + context_->allocator->Free(output_fp16_); output_fp16_ = nullptr; } } @@ -60,7 +56,7 @@ int FullconnectionFP16CPUKernel::ReSize() { fc_param_->deep_ = (in_tensors_.at(1)->shape()).at(1); fc_param_->row_16_ = UP_ROUND(fc_param_->row_, C16NUM); fc_param_->col_8_ = UP_ROUND(fc_param_->col_, C8NUM); - thread_count_ = MSMIN(thread_count_, UP_DIV(fc_param_->col_, C8NUM)); + thread_count_ = MSMIN(op_parameter_->thread_num_, UP_DIV(fc_param_->col_, C8NUM)); thread_stride_ = UP_DIV(UP_DIV(fc_param_->col_, C8NUM), thread_count_) * C8NUM; if (row == 1) is_vector_input_ = true; @@ -74,7 +70,7 @@ int FullconnectionFP16CPUKernel::ReSize() { b_pack_col = fc_param_->col_8_; } a_pack_ptr_ = - reinterpret_cast(ctx_->allocator->Malloc(a_pack_row * fc_param_->deep_ * sizeof(float16_t))); + reinterpret_cast(context_->allocator->Malloc(a_pack_row * fc_param_->deep_ * sizeof(float16_t))); if (a_pack_ptr_ == nullptr) { FreeTmpBuffer(); return RET_MEMORY_FAILED; @@ -82,7 +78,7 @@ int FullconnectionFP16CPUKernel::ReSize() { memset(a_pack_ptr_, 0, a_pack_row * fc_param_->deep_ * sizeof(float16_t)); b_pack_ptr_ = - reinterpret_cast(ctx_->allocator->Malloc(b_pack_col * fc_param_->deep_ * sizeof(float16_t))); + reinterpret_cast(context_->allocator->Malloc(b_pack_col * fc_param_->deep_ * sizeof(float16_t))); if (b_pack_ptr_ == nullptr) { FreeTmpBuffer(); return RET_MEMORY_FAILED; @@ -110,7 +106,7 @@ int FullconnectionFP16CPUKernel::ReSize() { } if (in_tensors_.size() == 3) { - bias_ptr_ = reinterpret_cast(ctx_->allocator->Malloc(b_pack_col * sizeof(float16_t))); + bias_ptr_ = reinterpret_cast(context_->allocator->Malloc(b_pack_col * sizeof(float16_t))); if (bias_ptr_ == nullptr) { FreeTmpBuffer(); return RET_MEMORY_FAILED; @@ -121,7 +117,7 @@ int FullconnectionFP16CPUKernel::ReSize() { if (out_tensors_.at(0)->data_type() == kNumberTypeFloat32) { output_fp16_ = - reinterpret_cast(ctx_->allocator->Malloc(fc_param_->row_ * fc_param_->col_ * sizeof(float16_t))); + reinterpret_cast(context_->allocator->Malloc(fc_param_->row_ * fc_param_->col_ * sizeof(float16_t))); if (output_fp16_ == nullptr) { FreeTmpBuffer(); return RET_MEMORY_FAILED; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.h index 08142172c6e..cce92802ca7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.h @@ -17,21 +17,24 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP16_FULLCONNECTION_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP16_FULLCONNECTION_H_ -#ifdef ENABLE_NEON #include -#endif #include -#include "src/lite_kernel.h" +#include "include/errorcode.h" #include "nnacl/matmul_parameter.h" -#include "src/runtime/kernel/arm/base/fullconnection_base.h" +#include "nnacl/fp16/matmul_fp16.h" +#include "nnacl/fp16/cast_fp16.h" +#include "src/lite_kernel.h" +#include "src/runtime/kernel/arm/base/dequant.h" namespace mindspore::kernel { -class FullconnectionFP16CPUKernel : public FullconnectionBaseCPUKernel { +class FullconnectionFP16CPUKernel : public LiteKernel { public: explicit FullconnectionFP16CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : FullconnectionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + fc_param_ = reinterpret_cast(op_parameter_); + } ~FullconnectionFP16CPUKernel() override; int Init() override; int ReSize() override; @@ -46,6 +49,7 @@ class FullconnectionFP16CPUKernel : public FullconnectionBaseCPUKernel { void FreeTmpBuffer(); private: + MatMulParameter *fc_param_ = nullptr; float16_t *a_pack_ptr_ = nullptr; float16_t *b_pack_ptr_ = nullptr; float16_t *bias_ptr_ = nullptr; @@ -54,6 +58,8 @@ class FullconnectionFP16CPUKernel : public FullconnectionBaseCPUKernel { float16_t *a_ptr_ = nullptr; float16_t *b_ptr_ = nullptr; bool is_vector_input_ = false; + int thread_count_ = 1; + int thread_stride_ = 0; }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc index d9c96b4e77b..9f964307fa6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc @@ -107,7 +107,7 @@ int MatmulFP16CPUKernel::MallocMatrixBBuffer() { return RET_MEMORY_FAILED; } memset(b_pack_ptr_, 0, params_->batch * params_->col_8_ * params_->deep_ * sizeof(float16_t)); - thread_count_ = MSMIN(thread_count_, UP_DIV(params_->col_, C8NUM)); + thread_count_ = MSMIN(op_parameter_->thread_num_, UP_DIV(params_->col_, C8NUM)); thread_stride_ = UP_DIV(UP_DIV(params_->col_, C8NUM), thread_count_) * C8NUM; return RET_OK; } @@ -228,7 +228,7 @@ int MatmulFP16CPUKernel::Init() { int MatmulFP16CPUKernel::MallocFp16Output() { if (out_tensors_[0]->data_type() == kNumberTypeFloat32) { output_ptr_ = reinterpret_cast( - ctx_->allocator->Malloc(params_->batch * params_->row_ * params_->col_ * sizeof(float16_t))); + context_->allocator->Malloc(params_->batch * params_->row_ * params_->col_ * sizeof(float16_t))); if (output_ptr_ == nullptr) { MS_LOG(ERROR) << "malloc output_ptr_ failed."; return RET_MEMORY_FAILED; @@ -313,7 +313,7 @@ int MatmulFP16CPUKernel::Run() { auto size = out_tensor->ElementsNum(); auto out_tensor_data = reinterpret_cast(out_tensor->data_c()); Float16ToFloat32(output_ptr_, out_tensor_data, size); - ctx_->allocator->Free(output_ptr_); + context_->allocator->Free(output_ptr_); } if (!params_->a_const_) { context_->allocator->Free(a_pack_ptr_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.h index 9b64f424a36..ff1ace93989 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.h @@ -23,15 +23,16 @@ #include #include "src/lite_kernel.h" #include "nnacl/matmul_parameter.h" -#include "src/runtime/kernel/arm/base/matmul_base.h" namespace mindspore::kernel { -class MatmulFP16CPUKernel : public MatmulBaseCPUKernel { +class MatmulFP16CPUKernel : public LiteKernel { public: explicit MatmulFP16CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : MatmulBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + params_ = reinterpret_cast(op_parameter_); + } ~MatmulFP16CPUKernel() override; int Init() override; int ReSize() override; @@ -50,6 +51,7 @@ class MatmulFP16CPUKernel : public MatmulBaseCPUKernel { void FreeTmpBuffer(); private: + MatMulParameter *params_ = nullptr; float16_t *a_pack_ptr_ = nullptr; float16_t *b_pack_ptr_ = nullptr; float16_t *bias_ptr_ = nullptr; @@ -57,6 +59,8 @@ class MatmulFP16CPUKernel : public MatmulBaseCPUKernel { float16_t *current_a_ = nullptr; float16_t *current_b_ = nullptr; float16_t *current_c_ = nullptr; + int thread_stride_ = 0; + int thread_count_ = 0; }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc index 60fa6e83a78..3dff13861a8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc @@ -91,24 +91,5 @@ void PadFp16CPUKernel::FreeInputAndOutput() { } } -kernel::LiteKernel *CpuPadFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - auto *kernel = new (std::nothrow) PadFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new PadFp16CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Pad, CpuPadFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Pad, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc index 3f6e8bf5668..4c3f0ad4c50 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc @@ -112,30 +112,5 @@ int PoolingFp16CPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuPoolingFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Pooling); - auto *kernel = new (std::nothrow) PoolingFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new PoolingCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Pooling, CpuPoolingFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Pooling, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc index 39730665e21..a4fe0798b8a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc @@ -197,5 +197,5 @@ kernel::LiteKernel *CpuQuantDTypeCastFp16KernelCreator(const std::vector) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc index a373fb0f37d..149550b1e9a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc @@ -157,54 +157,5 @@ int ReduceFp16CPUKernel::MallocTmpBuffer() { return RET_OK; } -kernel::LiteKernel *CpuReduceFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(opParameter != nullptr); - MS_ASSERT(desc.type == schema::PrimitiveType_Reduce); - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Reduce opParameter nullptr"; - return nullptr; - } - if (desc.type != schema::PrimitiveType_Reduce) { - MS_LOG(ERROR) << "Reduce op desc.type should be PrimitiveType_Reduce, got " << desc.type; - return nullptr; - } - auto *kernel = new (std::nothrow) ReduceFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "Reduce new ReduceCPUKernel failed."; - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -kernel::LiteKernel *CpuMeanFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - auto *kernel = new (std::nothrow) ReduceFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "Reduce new ReduceCPUKernel failed."; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Reduce, CpuReduceFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Reduce, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc index bd6c5516686..3cbfcf85b26 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc @@ -69,30 +69,5 @@ int ReshapeFp16CPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuReshapeFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Reshape); - auto *kernel = new (std::nothrow) ReshapeFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new ReshapeFp16CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Reshape, CpuReshapeFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Reshape, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc index 38b9bf0a7d9..ff469b85125 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc @@ -181,31 +181,5 @@ void ScaleFp16CPUKernel::FreeTmpBuffer() { } } -kernel::LiteKernel *CpuScaleFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(desc.type == schema::PrimitiveType_Scale); - if (opParameter == nullptr) { - MS_LOG(ERROR) << "opParameter is nullptr"; - return nullptr; - } - - auto *kernel = new (std::nothrow) ScaleFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "New kernel fails."; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Scale, CpuScaleFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Scale, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc index 3bc1cbc86d0..ad2ea1d934f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc @@ -65,25 +65,5 @@ void SliceFp16CPUKernel::FreeInputAndOutput() { } } -kernel::LiteKernel *CpuSliceFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - auto *kernel = new (std::nothrow) SliceFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new SliceFp16CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Slice, CpuSliceFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Slice, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc index f30048a83e4..23bcf75aa3e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc @@ -119,31 +119,5 @@ int SoftmaxFp16CPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuSoftmaxFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_SoftMax); - auto *kernel = new (std::nothrow) SoftmaxFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new SoftmaxFp16CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_SoftMax, CpuSoftmaxFp16KernelCreator) - +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_SoftMax, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc index 2a5f0fc16f5..a0988d9c617 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc @@ -116,29 +116,5 @@ void SplitFp16CPUKernel::FreeInputAndOutput() { } } -kernel::LiteKernel *CpuSplitFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Split); - auto *kernel = new (std::nothrow) SplitFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new SplitFp16CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Split, CpuSplitFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Split, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc index 89238b2446c..9979982ec79 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc @@ -100,31 +100,5 @@ int StackFp16CPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuStackFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *op_parameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (op_parameter == nullptr) { - MS_LOG(ERROR) << "Input op_parameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Stack); - auto *kernel = new (std::nothrow) StackFp16CPUKernel(op_parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new StackFp16CPUKernel fail!"; - free(op_parameter); - return nullptr; - } - - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(op_parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Stack, CpuStackFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Stack, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc index bdab6b2da98..3953679c1a4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc @@ -88,31 +88,5 @@ int TransposeFp16CPUKernel::Run() { return ret; } -kernel::LiteKernel *CpuTransposeFp16KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(desc.type == schema::PrimitiveType_Transpose); - if (opParameter == nullptr) { - MS_LOG(ERROR) << "desc type is not Transpose"; - return nullptr; - } - auto *kernel = new (std::nothrow) TransposeFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "New kernel fails."; - free(opParameter); - return nullptr; - } - - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Transpose, CpuTransposeFp16KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Transpose, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space_fp32.cc index 11edc030e03..d8b8d0aa0e8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space_fp32.cc @@ -14,39 +14,37 @@ * limitations under the License. */ #include "src/runtime/kernel/arm/fp32/batch_to_space_fp32.h" -#include #include "schema/model_generated.h" #include "src/kernel_registry.h" -#include "nnacl/batch_to_space.h" -#include "include/errorcode.h" -using mindspore::lite::RET_OK; +using mindspore::lite::KernelRegistrar; +using mindspore::schema::PrimitiveType_BatchToSpace; +using mindspore::schema::PrimitiveType_BatchToSpaceND; namespace mindspore::kernel { int BatchToSpaceCPUKernel::Init() { - auto ret = BatchToSpaceBaseCPUKernel::Init(); - if (ret != RET_OK) { - return ret; - } - + MS_ASSERT(in_tensors_.at(0)->format() == schema::Format::Format_NHWC); if (!InferShapeDone()) { - return RET_OK; + return lite::RET_OK; } return ReSize(); } -int BatchToSpaceCPUKernel::ReSize() { return BatchToSpaceBaseCPUKernel::ReSize(); } +int BatchToSpaceCPUKernel::ReSize() { + MS_ASSERT(in_tensors_.at(0)->shape().size() == 4); + return lite::RET_OK; +} int BatchToSpaceCPUKernel::Run() { auto input = in_tensors_[0]; auto output = out_tensors_[0]; - const float *input_data = reinterpret_cast(input->MutableData()); + const float *input_data = reinterpret_cast(input->data_c()); float *output_data = reinterpret_cast(output->MutableData()); auto in_shape = input->shape(); auto out_shape = output->shape(); BatchToSpaceParameter *param = reinterpret_cast(this->op_parameter_); - if (IsNoCrop()) { + if (param->no_crop_) { BatchToSpaceNoCropForNHWC(input_data, output_data, in_shape.data(), out_shape[0], param->block_shape_, sizeof(float)); } else { @@ -54,6 +52,9 @@ int BatchToSpaceCPUKernel::Run() { sizeof(float)); } - return RET_OK; + return lite::RET_OK; } + +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_BatchToSpace, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_BatchToSpaceND, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space_fp32.h index 615c7a3c678..6feeb4e627d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space_fp32.h @@ -15,17 +15,19 @@ */ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_BATCH_TO_SPACE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_BATCH_TO_SPACE_H_ + #include -#include "src/runtime/kernel/arm/base/batch_to_space_base.h" +#include "include/errorcode.h" +#include "nnacl/batch_to_space.h" +#include "src/lite_kernel.h" namespace mindspore::kernel { -class BatchToSpaceCPUKernel : public BatchToSpaceBaseCPUKernel { +class BatchToSpaceCPUKernel : public LiteKernel { public: BatchToSpaceCPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : BatchToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} - + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~BatchToSpaceCPUKernel() = default; int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.cc index bbbb69bd107..94e2e920110 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.cc @@ -15,13 +15,8 @@ */ #include "src/runtime/kernel/arm/fp32/concat_fp32.h" -#include -#include "nnacl/fp32/concat_fp32.h" #include "src/kernel_registry.h" #include "schema/model_generated.h" -#include "include/errorcode.h" -#include "src/runtime/runtime_api.h" -#include "src/runtime/thread_pool.h" using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; @@ -31,18 +26,17 @@ using mindspore::schema::PrimitiveType_Concat; namespace mindspore::kernel { int ConcatCPUKernel::Init() { - auto ret = ConcatBaseCPUKernel::Init(); - if (ret != RET_OK) { - return ret; - } if (!InferShapeDone()) { return RET_OK; } - return ReSize(); } -int ConcatCPUKernel::ReSize() { return ConcatBaseCPUKernel::ReSize(); } +int ConcatCPUKernel::ReSize() { + concat_param_->axis_ = + concat_param_->axis_ >= 0 ? concat_param_->axis_ : in_tensors_.front()->shape().size() + concat_param_->axis_; + return RET_OK; +} int ConcatCPUKernel::DoConcat(int task_id) { auto input_num = in_tensors_.size(); @@ -60,7 +54,7 @@ int ConcatCPUKernel::DoConcat(int task_id) { auto output_addr = out_tensors_.at(0)->MutableData(); Concat(inputs_addr.data(), input_num, concat_param_->axis_, inputs_output_shape.data(), output_shape.size(), - output_addr, task_id, thread_count_); + output_addr, task_id, op_parameter_->thread_num_); return RET_OK; } @@ -75,7 +69,10 @@ int ConcatsRun(void *cdata, int task_id) { } int ConcatCPUKernel::Run() { - int error_code = ParallelLaunch(this->context_->thread_pool_, ConcatsRun, this, thread_count_); + int error_code = ParallelLaunch(this->context_->thread_pool_, ConcatsRun, this, op_parameter_->thread_num_); return error_code; } + +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Concat, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Concat, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.h index 00299ebb1d3..6e4bb9175e7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/concat_fp32.h @@ -18,19 +18,24 @@ #include #include "src/lite_kernel.h" - +#include "nnacl/fp32/concat_fp32.h" +#include "nnacl/concat_parameter.h" +#include "include/errorcode.h" +#include "src/runtime/runtime_api.h" +#include "src/runtime/thread_pool.h" #include "include/context.h" -#include "src/runtime/kernel/arm/base/concat_base.h" using mindspore::lite::InnerContext; namespace mindspore::kernel { -class ConcatCPUKernel : public ConcatBaseCPUKernel { +class ConcatCPUKernel : public LiteKernel { public: ConcatCPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : ConcatBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + concat_param_ = reinterpret_cast(op_parameter_); + } ~ConcatCPUKernel() = default; @@ -38,6 +43,9 @@ class ConcatCPUKernel : public ConcatBaseCPUKernel { int ReSize() override; int DoConcat(int task_id); int Run() override; + + private: + ConcatParameter *concat_param_ = nullptr; }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.cc index 07e35e44879..02f68448efb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.cc @@ -16,14 +16,10 @@ #include "src/runtime/kernel/arm/fp32/crop_fp32.h" #include "schema/model_generated.h" #include "src/kernel_registry.h" -#include "nnacl/fp32/crop_fp32.h" -#include "nnacl/crop_parameter.h" -#include "include/errorcode.h" #include "src/runtime/runtime_api.h" using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_FORMAT_ERR; using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Crop; @@ -40,34 +36,42 @@ int CropLaunch(void *cdata, int task_id) { } } // namespace -int CropCPUKernel::Init() { return RET_OK; } +int CropCPUKernel::Init() { + if (!InferShapeDone()) { + return RET_OK; + } + return ReSize(); +} + +int CropCPUKernel::ReSize() { return CropBaseCPUKernel::ReSize(); } int CropCPUKernel::CropParallelRun(int thread_id) { auto input = in_tensors_[0]; auto output = out_tensors_[0]; - float *input_data = reinterpret_cast(input->MutableData()); - float *output_data = reinterpret_cast(output->MutableData()); - auto param = reinterpret_cast(op_parameter_); - Crop4D(input_data, output_data, input->shape().data(), output->shape().data(), param, thread_id); + float *input_data = reinterpret_cast(input->data_c()); + float *output_data = reinterpret_cast(output->data_c()); + Crop4D(input_data, output_data, input->shape().data(), output->shape().data(), crop_para_, thread_id); return RET_OK; } int CropCPUKernel::Run() { auto input = in_tensors_[0]; auto output = out_tensors_[0]; - auto param = reinterpret_cast(op_parameter_); - if (output->shape()[1] < param->op_parameter_.thread_num_) { - float *input_data = reinterpret_cast(input->MutableData()); - float *output_data = reinterpret_cast(output->MutableData()); - Crop4DNoParallel(input_data, output_data, input->shape().data(), output->shape().data(), param); + if (output->shape()[1] < crop_para_->thread_count_) { + float *input_data = reinterpret_cast(input->data_c()); + float *output_data = reinterpret_cast(output->data_c()); + Crop4DNoParallel(input_data, output_data, input->shape().data(), output->shape().data(), crop_para_); return RET_OK; } - auto ret = ParallelLaunch(this->context_->thread_pool_, CropLaunch, this, param->op_parameter_.thread_num_); + auto ret = ParallelLaunch(this->context_->thread_pool_, CropLaunch, this, crop_para_->thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "Crop launch fail!ret: " << ret; return RET_ERROR; } return RET_OK; } + +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Crop, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Crop, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.h index e08465317a7..658f96cdfb6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/crop_fp32.h @@ -15,7 +15,11 @@ */ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CROP_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CROP_H_ + #include +#include "include/errorcode.h" +#include "nnacl/fp32/crop_fp32.h" +#include "nnacl/crop_parameter.h" #include "src/lite_kernel.h" #include "src/runtime/kernel/arm/base/layout_transform.h" #include "src/runtime/kernel/arm/base/crop_base.h" @@ -29,7 +33,7 @@ class CropCPUKernel : public CropBaseCPUKernel { : CropBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~CropCPUKernel() = default; int Init() override; - int ReSize() override { return 0; } + int ReSize() override; int Run() override; int CropParallelRun(int thread_id); }; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space_fp32.cc index 64020349596..a19e1d36561 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space_fp32.cc @@ -14,12 +14,8 @@ * limitations under the License. */ #include "src/runtime/kernel/arm/fp32/depth_to_space_fp32.h" -#include #include "schema/model_generated.h" #include "src/kernel_registry.h" -#include "nnacl/arithmetic_common.h" -#include "nnacl/depth_to_space.h" -#include "include/errorcode.h" using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; @@ -29,18 +25,11 @@ using mindspore::lite::RET_PARAM_INVALID; using mindspore::schema::PrimitiveType_DepthToSpace; namespace mindspore::kernel { - int DepthToSpaceCPUKernel::Init() { - auto ret = DepthToSpaceBaseCPUKernel::Init(); - if (ret != RET_OK) { - return ret; - } - DepthToSpaceParameter *param = reinterpret_cast(op_parameter_); - param->data_type_size_ = sizeof(float); + param_->data_type_size_ = sizeof(float); if (!InferShapeDone()) { return RET_OK; } - return ReSize(); } @@ -49,16 +38,17 @@ int DepthToSpaceCPUKernel::ReSize() { return DepthToSpaceBaseCPUKernel::ReSize() int DepthToSpaceCPUKernel::Run() { auto input = in_tensors_[0]; auto output = out_tensors_[0]; - const float *input_data = reinterpret_cast(input->MutableData()); - float *output_data = reinterpret_cast(output->MutableData()); + const float *input_data = reinterpret_cast(input->data_c()); + float *output_data = reinterpret_cast(output->data_c()); auto in_shape = input->shape(); - DepthToSpaceParameter *param = reinterpret_cast(op_parameter_); if (input->format() == schema::Format::Format_NHWC) { - DepthToSpaceForNHWC(input_data, output_data, in_shape.data(), param); + DepthToSpaceForNHWC(input_data, output_data, in_shape.data(), param_); return RET_OK; } else { MS_LOG(ERROR) << "Depth_to_space only support NHWC now!"; return RET_ERROR; } } + +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_DepthToSpace, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space_fp32.h index 5dd55ca9842..99a9acf7a62 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space_fp32.h @@ -17,6 +17,9 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_DEPTH_TO_SPACE_H_ #include +#include "include/errorcode.h" +#include "nnacl/arithmetic_common.h" +#include "nnacl/depth_to_space.h" #include "src/runtime/kernel/arm/base/depth_to_space_base.h" namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process_fp32.cc index 7102d8cc3b8..bde48dba399 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process_fp32.cc @@ -26,7 +26,6 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_DetectionPostProcess; namespace mindspore::kernel { - int DetectionPostProcessCPUKernel::GetInputData() { if ((in_tensors_.at(0)->data_type() != kNumberTypeFloat32 && in_tensors_.at(0)->data_type() != kNumberTypeFloat) || (in_tensors_.at(1)->data_type() != kNumberTypeFloat32 && in_tensors_.at(1)->data_type() != kNumberTypeFloat)) { @@ -37,32 +36,6 @@ int DetectionPostProcessCPUKernel::GetInputData() { input_scores_ = reinterpret_cast(in_tensors_.at(1)->data_c()); return RET_OK; } - -kernel::LiteKernel *CpuDetectionPostProcessFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Create kernel failed, opParameter is nullptr, type: PrimitiveType_DetectionPostProcess. "; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_DetectionPostProcess); - auto *kernel = new (std::nothrow) DetectionPostProcessCPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new DetectionPostProcessCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_DetectionPostProcess, CpuDetectionPostProcessFp32KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_DetectionPostProcess, + CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection_fp32.cc index 83953139332..9f47dfee495 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection_fp32.cc @@ -15,10 +15,17 @@ */ #include "src/runtime/kernel/arm/fp32/fullconnection_fp32.h" +#include "src/kernel_registry.h" #include "src/runtime/runtime_api.h" + +using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_INVALID_OP_ATTR; using mindspore::lite::RET_MEMORY_FAILED; +using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_FullConnection; namespace mindspore::kernel { FullconnectionCPUKernel::~FullconnectionCPUKernel() { @@ -63,7 +70,7 @@ int FullconnectionCPUKernel::ReSize() { fc_param_->row_6_ = UP_ROUND(fc_param_->row_, C6NUM); fc_param_->row_4_ = UP_ROUND(fc_param_->row_, C4NUM); - thread_count_ = MSMIN(thread_count_, UP_DIV(fc_param_->col_align_, col_tile)); + thread_count_ = MSMIN(op_parameter_->thread_num_, UP_DIV(fc_param_->col_align_, col_tile)); thread_stride_ = UP_DIV(UP_DIV(fc_param_->col_align_, col_tile), thread_count_); #ifdef ENABLE_ARM @@ -214,4 +221,57 @@ int FullconnectionCPUKernel::Run() { return RET_OK; } +kernel::LiteKernel *CpuFullConnectionFp32KernelCreator(const std::vector &inputs, + const std::vector &outputs, + OpParameter *opParameter, const lite::InnerContext *ctx, + const kernel::KernelKey &desc, + const mindspore::lite::PrimitiveC *primitive) { + MS_ASSERT(opParameter != nullptr); + MS_ASSERT(desc.type == schema::PrimitiveType_FullConnection); + auto *weight_tensor = inputs.at(kWeightIndex); + // data of second tensor of fc may be nullptr + auto *restore_data = weight_tensor->data_c(); + auto restore_type = weight_tensor->data_type(); + bool dequant_flag = + !weight_tensor->quant_params().empty() && weight_tensor->quant_params().front().inited && restore_data != nullptr; + if (dequant_flag) { + auto *dequant_weight = kernel::DequantUtil::DequantWeight(weight_tensor); + if (dequant_weight == nullptr) { + MS_LOG(ERROR) << "dequant data is nullptr."; + return nullptr; + } + weight_tensor->set_data(dequant_weight); + } + auto kernel = new (std::nothrow) FullconnectionCPUKernel(opParameter, inputs, outputs, ctx, primitive); + if (!kernel) { + MS_LOG(ERROR) << "kernel is nullptr."; + if (dequant_flag) { + weight_tensor->FreeData(); + weight_tensor->set_data(restore_data); + weight_tensor->set_data_type(restore_type); + } + free(opParameter); + return nullptr; + } + auto ret = kernel->Init(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " + << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + if (dequant_flag) { + weight_tensor->FreeData(); + weight_tensor->set_data(restore_data); + weight_tensor->set_data_type(restore_type); + } + delete kernel; + return nullptr; + } + if (dequant_flag) { + weight_tensor->FreeData(); + weight_tensor->set_data(restore_data); + weight_tensor->set_data_type(restore_type); + } + return kernel; +} + +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_FullConnection, CpuFullConnectionFp32KernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection_fp32.h index 8ebe1934d71..9847cd5fe75 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection_fp32.h @@ -18,20 +18,22 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_FULLCONNECTION_H_ #include -#include "src/runtime/kernel/arm/base/fullconnection_base.h" #include "include/context.h" #include "include/errorcode.h" #include "nnacl/fp32/matmul_fp32.h" +#include "src/lite_kernel.h" +#include "src/runtime/kernel/arm/base/dequant.h" using mindspore::lite::InnerContext; - namespace mindspore::kernel { -class FullconnectionCPUKernel : public FullconnectionBaseCPUKernel { +class FullconnectionCPUKernel : public LiteKernel { public: FullconnectionCPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : FullconnectionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + fc_param_ = reinterpret_cast(op_parameter_); + } ~FullconnectionCPUKernel() override; int Init() override; @@ -47,6 +49,7 @@ class FullconnectionCPUKernel : public FullconnectionBaseCPUKernel { void InitMatrixB(const float *src_ptr, float *dst_ptr); private: + MatMulParameter *fc_param_ = nullptr; float *a_pack_ptr_ = nullptr; float *b_pack_ptr_ = nullptr; float *c_ptr_ = nullptr; @@ -54,6 +57,8 @@ class FullconnectionCPUKernel : public FullconnectionBaseCPUKernel { float *a_ptr_ = nullptr; float *b_ptr_ = nullptr; bool is_vector_input_ = false; + int thread_count_ = 1; + int thread_stride_ = 0; }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_FULLCONNECTION_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc index 9dcd0b792ae..79cd6b4cf72 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc @@ -129,27 +129,5 @@ int FusedBatchnormCPUKernel::DoExecute(int task_id) { return RET_OK; } -kernel::LiteKernel *CpuFusedBatchnormKernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *op_parameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - FusedBatchnormCPUKernel *kernel = - new (std::nothrow) FusedBatchnormCPUKernel(op_parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new FusedBatchnormCPUKernel fail!"; - free(op_parameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(op_parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_FusedBatchNorm, CpuFusedBatchnormKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_FusedBatchNorm, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/gelu_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/gelu_fp32.cc deleted file mode 100644 index 13834357d81..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/gelu_fp32.cc +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 "src/runtime/kernel/arm/fp32/gelu_fp32.h" -#include "src/runtime/kernel/arm/base/gelu_base.h" -#include "nnacl/fp32/gelu_fp32.h" -#include "nnacl/gelu_parameter.h" -#include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "src/runtime/runtime_api.h" - -using mindspore::kernel::KERNEL_ARCH::kCPU; -using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -// using mindspore::schema::PrimitiveType_GeLU; - -namespace mindspore::kernel { - -int GeLUCPUKernel::Init() { - auto ret = GeLUBaseCPUKernel::Init(); - if (ret != RET_OK) { - return ret; - } - - if (!InferShapeDone()) { - return RET_OK; - } - - return ReSize(); -} - -int GeLUCPUKernel::ReSize() { return RET_OK; } - -int GeLUCPUKernel::GeLU(int task_id) { - int64_t real_dst_count = MSMIN(elements_num_ - task_id * count_unit_, count_unit_); - if (real_dst_count <= 0) { - return lite::RET_OK; - } - float *cur_input_data = input_ptr_ + task_id * count_unit_; - float *cur_output_data = output_ptr_ + task_id * count_unit_; - auto ret = DoGeLU(cur_input_data, cur_output_data, real_dst_count, gelu_param_); - if (ret != RET_OK) { - MS_LOG(ERROR) << "GeLU error task_id[" << task_id << "] error_code[" << ret << "]"; - return RET_ERROR; - } - return RET_OK; -} - -int GeLURun(void *cdata, int task_id) { - auto g_kernel = reinterpret_cast(cdata); - auto ret = g_kernel->GeLU(task_id); - if (ret != RET_OK) { - MS_LOG(ERROR) << "GeLURun error task_id[" << task_id << "] error_code[" << ret << "]"; - return RET_ERROR; - } - return RET_OK; -} - -int GeLUCPUKernel::Run() { - auto in_tensor = in_tensors_.front(); - auto out_tensor = out_tensors_.front(); - input_ptr_ = reinterpret_cast(in_tensor->MutableData()); - output_ptr_ = reinterpret_cast(out_tensor->MutableData()); - elements_num_ = out_tensor->ElementsNum(); - count_unit_ = thread_count_ > 1 ? UP_DIV(elements_num_, thread_count_) : elements_num_; - auto ret = ParallelLaunch(this->context_->thread_pool_, GeLURun, this, thread_count_); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; - return RET_ERROR; - } - - return RET_OK; -} -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/gelu_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/gelu_fp32.h deleted file mode 100644 index d88d0aad5f0..00000000000 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/gelu_fp32.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GELU_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GELU_H_ - -#include -#include "src/runtime/kernel/arm/base/gelu_base.h" -#include "src/lite_kernel.h" - -namespace mindspore::kernel { -class GeLUCPUKernel : public GeLUBaseCPUKernel { - public: - GeLUCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::InnerContext *ctx, - const mindspore::lite::PrimitiveC *primitive) - : GeLUBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} - ~GeLUCPUKernel() override = default; - - int Init() override; - int ReSize() override; - int Run() override; - int GeLU(int task_id); - - private: - float *input_ptr_ = nullptr; - float *output_ptr_ = nullptr; - int64_t elements_num_ = 0; - int64_t count_unit_ = 0; -}; -} // namespace mindspore::kernel - -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GELU_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32.cc index 78f6fe20cb4..86dd24277d2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32.cc @@ -124,7 +124,7 @@ int MatmulCPUKernel::MallocMatrixBBuffer() { return RET_MEMORY_FAILED; } - thread_count_ = MSMIN(thread_count_, UP_DIV(params_->col_align_, col_tile_)); + thread_count_ = MSMIN(op_parameter_->thread_num_, UP_DIV(params_->col_align_, col_tile_)); thread_stride_ = UP_DIV(UP_DIV(params_->col_align_, col_tile_), thread_count_); return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32.h index c3e9fece363..efcf5cd8fe8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32.h @@ -20,15 +20,16 @@ #include #include "nnacl/matmul_parameter.h" #include "src/lite_kernel.h" -#include "src/runtime/kernel/arm/base/matmul_base.h" namespace mindspore::kernel { -class MatmulCPUKernel : public MatmulBaseCPUKernel { +class MatmulCPUKernel : public LiteKernel { public: explicit MatmulCPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : MatmulBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + params_ = reinterpret_cast(op_parameter_); + } ~MatmulCPUKernel() override; int Init() override; int ReSize() override; @@ -45,6 +46,7 @@ class MatmulCPUKernel : public MatmulBaseCPUKernel { void FreeTmpBuffer(); private: + MatMulParameter *params_ = nullptr; float *a_pack_ptr_ = nullptr; float *b_pack_ptr_ = nullptr; float *bias_ptr_ = nullptr; @@ -55,6 +57,8 @@ class MatmulCPUKernel : public MatmulBaseCPUKernel { float *cur_c_ptr_ = nullptr; bool is_vector_a_ = false; int col_tile_ = 0; + int thread_stride_ = 0; + int thread_count_ = 0; }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc index f0ca63ff5e7..d8f38be7279 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc @@ -413,4 +413,6 @@ int PadCPUKernel::Run() { return RET_OK; } + +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Pad, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_fp32.cc index dc8f7b3f326..86d24fe9684 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_fp32.cc @@ -91,4 +91,6 @@ int PoolingCPUKernel::Run() { } return RET_OK; } + +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Pooling, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.cc index ad65a8accb0..b9c673ae794 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.cc @@ -74,4 +74,5 @@ int PowerCPUKernel::RunImpl(int task_id) { return RET_OK; } +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Power, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.h index 8c04f749a55..4937ba81c3a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/power_fp32.h @@ -21,15 +21,14 @@ #include "src/lite_kernel.h" #include "include/context.h" #include "nnacl/power.h" -#include "src/runtime/kernel/arm/base/power_base.h" namespace mindspore::kernel { -class PowerCPUKernel : public PowerBaseCPUKernel { +class PowerCPUKernel : public LiteKernel { public: PowerCPUKernel(OpParameter *param, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : PowerBaseCPUKernel(param, inputs, outputs, ctx, primitive), + : LiteKernel(param, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_), power_(reinterpret_cast(op_parameter_)->power_), scale_(reinterpret_cast(op_parameter_)->scale_), diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc index d4293f06805..8b1f36d2772 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce_fp32.cc @@ -234,4 +234,8 @@ void ReduceCPUKernel::FreeTmpBuffer() { } data_buffers_.clear(); } + +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Reduce, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt, PrimitiveType_Reduce, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Reduce, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reshape_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reshape_fp32.cc index 6703180ec13..e258cc76763 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reshape_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reshape_fp32.cc @@ -28,20 +28,20 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Reshape; namespace mindspore::kernel { -int ReshapeCPUKernel::Init() { - ReshapeBaseCPUKernel::Init(); - return RET_OK; -} +int ReshapeCPUKernel::Init() { return RET_OK; } int ReshapeCPUKernel::ReSize() { return RET_OK; } int ReshapeCPUKernel::Run() { - auto input_ptr = in_tensors_.at(kInputIndex)->MutableData(); - auto output_ptr = out_tensors_.at(kOutputIndex)->MutableData(); + auto input_ptr = in_tensors_.at(kInputIndex)->data_c(); + auto output_ptr = out_tensors_.at(kOutputIndex)->data_c(); size_t data_size = in_tensors_.at(kInputIndex)->Size(); MS_ASSERT(input_ptr); MS_ASSERT(output_ptr); Reshape(input_ptr, output_ptr, data_size); return RET_OK; } + +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Reshape, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Reshape, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reshape_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/reshape_fp32.h index 695acb44cd5..4a1bc0f7a0e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reshape_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reshape_fp32.h @@ -19,19 +19,17 @@ #include #include "src/lite_kernel.h" - #include "include/context.h" -#include "src/runtime/kernel/arm/base/reshape_base.h" using mindspore::lite::InnerContext; namespace mindspore::kernel { -class ReshapeCPUKernel : public ReshapeBaseCPUKernel { +class ReshapeCPUKernel : public LiteKernel { public: ReshapeCPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : ReshapeBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~ReshapeCPUKernel() = default; int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.cc index a3278de0691..6e4b646ec9c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.cc @@ -15,17 +15,17 @@ */ #include "src/runtime/kernel/arm/fp32/resize_fp32.h" -#include -#include "include/errorcode.h" -#include "nnacl/fp32/resize_fp32.h" #include "schema/model_generated.h" +#include "src/kernel_registry.h" #include "src/runtime/runtime_api.h" using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_INVALID_OP_ATTR; using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_Resize; namespace mindspore::kernel { int ResizeCPUKernel::Init() { @@ -217,4 +217,6 @@ int ResizeCPUKernel::Run() { return RET_OK; } + +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Resize, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.h index 050890b1eeb..18fcaecf5c0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/resize_fp32.h @@ -17,6 +17,9 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_RESIZE_H_ #include +#include +#include "include/errorcode.h" +#include "nnacl/fp32/resize_fp32.h" #include "src/lite_kernel.h" #include "src/runtime/kernel/arm/base/resize_base.h" diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/softmax_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/softmax_fp32.cc index 52ab165a72c..bb5690b4897 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/softmax_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/softmax_fp32.cc @@ -111,4 +111,5 @@ int SoftmaxCPUKernel::Run() { return ret; } +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_SoftMax, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/split_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/split_fp32.cc index 1ee96f885a8..16d38eb8e1e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/split_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/split_fp32.cc @@ -87,4 +87,32 @@ int SplitCPUKernel::Run() { return RET_OK; } + +kernel::LiteKernel *CpuSplitInt32KernelCreator(const std::vector &inputs, + const std::vector &outputs, OpParameter *opParameter, + const InnerContext *ctx, const kernel::KernelKey &desc, + const mindspore::lite::PrimitiveC *primitive) { + if (opParameter == nullptr) { + MS_LOG(ERROR) << "Input opParameter is nullptr!"; + return nullptr; + } + MS_ASSERT(desc.type == schema::PrimitiveType_Split); + auto *kernel = new (std::nothrow) SplitCPUKernel(opParameter, inputs, outputs, ctx, primitive); + if (kernel == nullptr) { + MS_LOG(ERROR) << "new SplitCPUKernel fail!"; + free(opParameter); + return nullptr; + } + auto ret = kernel->Init(); + if (ret != RET_OK) { + delete kernel; + MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " + << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + return nullptr; + } + return kernel; +} + +REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Split, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Split, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc index 2e66eb59fa0..d9b0eb6282c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc @@ -14,27 +14,19 @@ * limitations under the License. */ #include "src/runtime/kernel/arm/int8/batch_to_space_int8.h" -#include #include "schema/model_generated.h" #include "src/kernel_registry.h" -#include "nnacl/batch_to_space.h" -#include "nnacl/int8/batch_to_space_int8.h" -#include "include/errorcode.h" - -using mindspore::lite::RET_OK; using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_FORMAT_ERR; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_BatchToSpace; using mindspore::schema::PrimitiveType_BatchToSpaceND; namespace mindspore::kernel { int BatchToSpaceInt8CPUKernel::Init() { - auto ret = BatchToSpaceBaseCPUKernel::Init(); - if (ret != RET_OK) { - return ret; - } + MS_ASSERT(in_tensors_.at(0)->format() == schema::Format::Format_NHWC); + auto *input_tensor = in_tensors_.at(kInputIndex); auto in_quant_args = input_tensor->quant_params(); in_quant_arg_.scale_ = in_quant_args.front().scale; @@ -50,7 +42,10 @@ int BatchToSpaceInt8CPUKernel::Init() { return ReSize(); } -int BatchToSpaceInt8CPUKernel::ReSize() { return BatchToSpaceBaseCPUKernel::ReSize(); } +int BatchToSpaceInt8CPUKernel::ReSize() { + MS_ASSERT(in_tensors_.at(0)->shape().size() == 4); + return RET_OK; +} int BatchToSpaceInt8CPUKernel::Run() { auto input = in_tensors_[0]; @@ -62,7 +57,7 @@ int BatchToSpaceInt8CPUKernel::Run() { BatchToSpaceParameter *param = reinterpret_cast(this->op_parameter_); if (in_quant_arg_.scale_ == out_quant_arg_.scale_ && in_quant_arg_.zp_ == out_quant_arg_.zp_) { - if (IsNoCrop()) { + if (param->no_crop_) { BatchToSpaceNoCropForNHWC(input_data, output_data, in_shape.data(), out_shape[0], param->block_shape_, sizeof(int8_t)); } else { @@ -70,7 +65,7 @@ int BatchToSpaceInt8CPUKernel::Run() { sizeof(int8_t)); } } else { - if (IsNoCrop()) { + if (param->no_crop_) { BatchToSpaceNoCropForNHWCInt8(input_data, output_data, in_shape.data(), out_shape[0], param->block_shape_, &in_quant_arg_, &out_quant_arg_); } else { @@ -82,27 +77,6 @@ int BatchToSpaceInt8CPUKernel::Run() { return RET_OK; } -kernel::LiteKernel *CpuBatchToSpaceInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *op_parameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - auto *kernel = new (std::nothrow) BatchToSpaceInt8CPUKernel(op_parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new BatchToSpaceInt8CPUKernel fail!"; - free(op_parameter); - return nullptr; - } - - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(op_parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_BatchToSpace, CpuBatchToSpaceInt8KernelCreator) -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_BatchToSpaceND, CpuBatchToSpaceInt8KernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_BatchToSpace, CPUKernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_BatchToSpaceND, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.h index b39f15d5fb1..7d4838b2e9b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.h @@ -17,15 +17,18 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_BATCH_TO_SPACE_INT8_H_ #include -#include "src/runtime/kernel/arm/base/batch_to_space_base.h" +#include "include/errorcode.h" +#include "nnacl/batch_to_space.h" +#include "nnacl/int8/batch_to_space_int8.h" +#include "src/lite_kernel.h" namespace mindspore::kernel { -class BatchToSpaceInt8CPUKernel : public BatchToSpaceBaseCPUKernel { +class BatchToSpaceInt8CPUKernel : public LiteKernel { public: BatchToSpaceInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : BatchToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~BatchToSpaceInt8CPUKernel() = default; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc index 7e1549460e8..eef4b34454d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc @@ -15,23 +15,17 @@ */ #include "src/runtime/kernel/arm/int8/concat_int8.h" -#include -#include "nnacl/int8/concat_int8.h" #include "schema/model_generated.h" -#include "include/errorcode.h" #include "src/kernel_registry.h" using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; - -using mindspore::lite::KernelRegistrar; using mindspore::schema::PrimitiveType_Concat; namespace mindspore::kernel { - int ConcatInt8CPUKernel::Init() { - ConcatBaseCPUKernel::Init(); concat_param_->input_shapes_ = nullptr; auto input_num = in_tensors_.size(); input_data_ = reinterpret_cast(malloc(sizeof(int8_t *) * input_num)); @@ -65,10 +59,9 @@ int ConcatInt8CPUKernel::Init() { } int ConcatInt8CPUKernel::ReSize() { - auto ret = ConcatBaseCPUKernel::ReSize(); - if (ret != RET_OK) { - return ret; - } + concat_param_->axis_ = + concat_param_->axis_ >= 0 ? concat_param_->axis_ : in_tensors_.front()->shape().size() + concat_param_->axis_; + auto input_num = in_tensors_.size(); concat_param_->input_num_ = input_num; concat_param_->input_shapes_ = reinterpret_cast(malloc(sizeof(int *) * input_num)); @@ -113,7 +106,8 @@ int ConcatInt8CPUKernel::ReSize() { int ConcatInt8CPUKernel::Run() { auto input_num = concat_param_->input_num_; - count_unit_ = thread_count_ > 1 ? UP_DIV(before_axis_size, thread_count_) : before_axis_size; + count_unit_ = + op_parameter_->thread_num_ > 1 ? UP_DIV(before_axis_size, op_parameter_->thread_num_) : before_axis_size; concat_param_->count_unit_ = count_unit_; for (int i = 0; i < input_num; i++) { @@ -121,7 +115,7 @@ int ConcatInt8CPUKernel::Run() { } output_data_ = reinterpret_cast(out_tensors_.at(0)->MutableData()); - auto ret = ParallelLaunch(this->context_->thread_pool_, ConcatInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, ConcatInt8Run, this, op_parameter_->thread_num_); return ret; } @@ -141,26 +135,5 @@ int ConcatInt8CPUKernel::DoExecute(int task_id) { return lite::RET_OK; } -kernel::LiteKernel *CpuConcatInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - auto *kernel = new (std::nothrow) ConcatInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Concat, CpuConcatInt8KernelCreator) - +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Concat, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.h index c14f7c2c149..358028bce34 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.h @@ -18,20 +18,22 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_CONCAT_INT8_H_ #include +#include +#include "nnacl/int8/concat_int8.h" +#include "include/errorcode.h" #include "src/lite_kernel.h" #include "include/context.h" -#include "src/runtime/kernel/arm/base/concat_base.h" #include "src/runtime/runtime_api.h" -using mindspore::lite::InnerContext; - namespace mindspore::kernel { -class ConcatInt8CPUKernel : public ConcatBaseCPUKernel { +class ConcatInt8CPUKernel : public LiteKernel { public: ConcatInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const InnerContext *ctx, + const std::vector &outputs, const mindspore::lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : ConcatBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + concat_param_ = reinterpret_cast(op_parameter_); + } ~ConcatInt8CPUKernel() override { if (input_data_ != nullptr) { free(input_data_); @@ -64,6 +66,7 @@ class ConcatInt8CPUKernel : public ConcatBaseCPUKernel { int64_t count_unit_; int8_t **input_data_ = nullptr; int8_t *output_data_ = nullptr; + ConcatParameter *concat_param_ = nullptr; }; int ConcatInt8Run(void *cdata, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc index 5026b2fcc8b..4a910085b9a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc @@ -15,22 +15,17 @@ */ #include "src/runtime/kernel/arm/int8/crop_int8.h" -#include -#include "nnacl/int8/crop_int8.h" -#include "include/errorcode.h" #include "src/runtime/runtime_api.h" #include "src/kernel_registry.h" using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_MEMORY_FAILED; using mindspore::lite::RET_OK; - -using mindspore::lite::KernelRegistrar; using mindspore::schema::PrimitiveType_Crop; namespace mindspore::kernel { - int CropInt8CPUKernel::Init() { auto ret = CropBaseCPUKernel::Init(); if (ret != RET_OK) { @@ -69,7 +64,7 @@ CropInt8CPUKernel::~CropInt8CPUKernel() { int CropInt8CPUKernel::ReSize() { return CropBaseCPUKernel::ReSize(); } int CropInt8CPUKernel::Run() { - auto ret = ParallelLaunch(this->context_->thread_pool_, CropInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, CropInt8Run, this, crop_para_->thread_count_); return ret; } @@ -82,31 +77,11 @@ int CropInt8Run(void *cdata, int task_id) { int CropInt8CPUKernel::DoExecute(int task_id) { auto input_tensor = in_tensors_.at(kInputIndex); auto out_tensor = out_tensors_.at(kOutputIndex); - int8_t *input_data = reinterpret_cast(input_tensor->MutableData()); - int8_t *output_data = reinterpret_cast(out_tensor->MutableData()); + int8_t *input_data = reinterpret_cast(input_tensor->data_c()); + int8_t *output_data = reinterpret_cast(out_tensor->data_c()); Int8Crop(input_data, output_data, task_id, crop_para_); return RET_OK; } -kernel::LiteKernel *CpuCropInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - auto *kernel = new (std::nothrow) CropInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new CropCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Crop, CpuCropInt8KernelCreator) - +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Crop, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h index faef49b5621..eb5e869c97f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h @@ -18,32 +18,27 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_CROP_INT8_H_ #include -#include "src/lite_kernel.h" +#include +#include "include/errorcode.h" #include "include/context.h" -#include "src/runtime/kernel/arm/base/crop_base.h" +#include "nnacl/int8/crop_int8.h" +#include "src/lite_kernel.h" #include "src/runtime/runtime_api.h" - -using mindspore::lite::InnerContext; +#include "src/runtime/kernel/arm/base/crop_base.h" namespace mindspore::kernel { class CropInt8CPUKernel : public CropBaseCPUKernel { public: CropInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const InnerContext *ctx, + const std::vector &outputs, const mindspore::lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : CropBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) { - crop_para_ = reinterpret_cast(op_parameter_); - crop_para_->thread_count_ = op_parameter_->thread_num_; - } + : CropBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~CropInt8CPUKernel(); int Init() override; int ReSize() override; int Run() override; int DoExecute(int task_id); - - private: - CropParameter *crop_para_; }; int CropInt8Run(void *cdata, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc index a5e541e4aed..f25833e282e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc @@ -14,29 +14,19 @@ * limitations under the License. */ #include "src/runtime/kernel/arm/int8/depth_to_space_int8.h" -#include #include "schema/model_generated.h" #include "src/kernel_registry.h" -#include "nnacl/depth_to_space.h" -#include "nnacl/int8/depth_to_space_int8.h" -#include "include/errorcode.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; using mindspore::lite::RET_FORMAT_ERR; +using mindspore::lite::RET_OK; using mindspore::lite::RET_PARAM_INVALID; using mindspore::schema::PrimitiveType_DepthToSpace; namespace mindspore::kernel { int DepthToSpaceInt8CPUKernel::Init() { - auto ret = DepthToSpaceBaseCPUKernel::Init(); - if (ret != RET_OK) { - return ret; - } - DepthToSpaceParameter *param = reinterpret_cast(op_parameter_); - param->data_type_size_ = sizeof(int8_t); + param_->data_type_size_ = sizeof(int8_t); auto *input_tensor = in_tensors_.at(kInputIndex); auto in_quant_args = input_tensor->quant_params(); @@ -58,44 +48,17 @@ int DepthToSpaceInt8CPUKernel::ReSize() { return DepthToSpaceBaseCPUKernel::ReSi int DepthToSpaceInt8CPUKernel::Run() { auto input = in_tensors_[0]; auto output = out_tensors_[0]; - const int8_t *input_data = reinterpret_cast(input->MutableData()); - int8_t *output_data = reinterpret_cast(output->MutableData()); + const int8_t *input_data = reinterpret_cast(input->data_c()); + int8_t *output_data = reinterpret_cast(output->data_c()); auto in_shape = input->shape(); - DepthToSpaceParameter *param = reinterpret_cast(op_parameter_); if (in_quant_arg_.scale_ == out_quant_arg_.scale_ && in_quant_arg_.zp_ == out_quant_arg_.zp_) { - DepthToSpaceForNHWC(input_data, output_data, in_shape.data(), param); + DepthToSpaceForNHWC(input_data, output_data, in_shape.data(), param_); } else { - DepthToSpaceForNHWCInt8(input_data, output_data, in_shape.data(), param, &in_quant_arg_, &out_quant_arg_); + DepthToSpaceForNHWCInt8(input_data, output_data, in_shape.data(), param_, &in_quant_arg_, &out_quant_arg_); } return RET_OK; } -kernel::LiteKernel *CpuDepthToSpaceInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *op_parameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - MS_ASSERT(desc.type == schema::PrimitiveType_DepthToSpace); - if (op_parameter == nullptr) { - MS_LOG(ERROR) << "Input op_parameter is nullptr!"; - return nullptr; - } - auto *kernel = new (std::nothrow) DepthToSpaceInt8CPUKernel(op_parameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new BatchToSpaceInt8CPUKernel fail!"; - free(op_parameter); - return nullptr; - } - - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(op_parameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_DepthToSpace, CpuDepthToSpaceInt8KernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_DepthToSpace, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.h index ac3d4f21b31..7a5ea651a30 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.h @@ -17,8 +17,11 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_DEPTH_TO_SPACE_INT8_H_ #include -#include "src/runtime/kernel/arm/base/depth_to_space_base.h" +#include "include/errorcode.h" +#include "nnacl/depth_to_space.h" +#include "nnacl/int8/depth_to_space_int8.h" #include "nnacl/quantization/quantize.h" +#include "src/runtime/kernel/arm/base/depth_to_space_base.h" namespace mindspore::kernel { class DepthToSpaceInt8CPUKernel : public DepthToSpaceBaseCPUKernel { @@ -27,7 +30,6 @@ class DepthToSpaceInt8CPUKernel : public DepthToSpaceBaseCPUKernel { const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) : DepthToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} - ~DepthToSpaceInt8CPUKernel() = default; int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc index d1f28d4f834..56d96a2aa67 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/detection_post_process_int8.cc @@ -26,7 +26,6 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_DetectionPostProcess; namespace mindspore::kernel { - int DetectionPostProcessInt8CPUKernel::DequantizeInt8ToFp32(const int task_id) { int num_unit_thread = MSMIN(thread_n_stride_, quant_size_ - task_id * thread_n_stride_); int thread_offset = task_id * thread_n_stride_; @@ -89,31 +88,6 @@ int DetectionPostProcessInt8CPUKernel::GetInputData() { return RET_OK; } -kernel::LiteKernel *CpuDetectionPostProcessInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const lite::InnerContext *ctx, - const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Create kernel failed, opParameter is nullptr, type: PrimitiveType_DetectionPostProcess. "; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_DetectionPostProcess); - auto *kernel = new (std::nothrow) DetectionPostProcessInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new DetectionPostProcessInt8CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_DetectionPostProcess, CpuDetectionPostProcessInt8KernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_DetectionPostProcess, + CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc index 4dfb5eae694..69616f68c74 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.cc @@ -15,21 +15,14 @@ */ #include "src/runtime/kernel/arm/int8/leaky_relu_int8.h" -#include -#include "nnacl/fp32/activation_fp32.h" -#include "nnacl/int8/leaky_relu_int8.h" #include "src/runtime/runtime_api.h" #include "src/kernel_registry.h" -#include "include/errorcode.h" -#include "nnacl/errorcode.h" using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_MEMORY_FAILED; using mindspore::lite::RET_OK; - -using mindspore::lite::KernelRegistrar; using mindspore::schema::PrimitiveType_LeakyReLU; namespace mindspore::kernel { @@ -46,7 +39,6 @@ int LeakyReluInt8Run(void *cdata, int task_id) { } // namespace int LeakyReluInt8CPUKernel::Init() { - LeakyReluBaseCPUKernel::Init(); quant_prelu_parm_.op_parameter_ = *op_parameter_; quant_prelu_parm_.slope_ = reinterpret_cast(op_parameter_)->alpha_; @@ -126,41 +118,17 @@ int LeakyReluInt8CPUKernel::Run() { int LeakyReluInt8CPUKernel::DoExecute(int task_id) { auto input_tensor = in_tensors_.at(kInputIndex); auto out_tensor = out_tensors_.at(kOutputIndex); - int8_t *input_data = reinterpret_cast(input_tensor->MutableData()); - int8_t *output_data = reinterpret_cast(out_tensor->MutableData()); + int8_t *input_data = reinterpret_cast(input_tensor->data_c()); + int8_t *output_data = reinterpret_cast(out_tensor->data_c()); MS_ASSERT(input_data); MS_ASSERT(output_data); auto ret = DoLeakReluInt8(input_data, output_data, &quant_prelu_parm_, task_id); - if (ret != NNACL_OK) { + if (ret != RET_OK) { MS_LOG(ERROR) << "DoLeakReluInt8 failed"; return RET_ERROR; } return RET_OK; } -kernel::LiteKernel *CpuLeakyReluInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - - auto *kernel = new (std::nothrow) LeakyReluInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new LeakyReluInt8CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_LeakyReLU, CpuLeakyReluInt8KernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_LeakyReLU, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.h index 33f3b748462..f96934b2871 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/leaky_relu_int8.h @@ -18,18 +18,21 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_PRELU_INT8_H_ #include -#include "src/lite_kernel.h" +#include +#include "include/errorcode.h" #include "include/context.h" -#include "src/runtime/kernel/arm/base/leaky_relu_base.h" +#include "nnacl/fp32/activation_fp32.h" +#include "nnacl/int8/leaky_relu_int8.h" +#include "src/lite_kernel.h" #include "src/runtime/runtime_api.h" namespace mindspore::kernel { -class LeakyReluInt8CPUKernel : public LeakyReluBaseCPUKernel { +class LeakyReluInt8CPUKernel : public LiteKernel { public: LeakyReluInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : LeakyReluBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~LeakyReluInt8CPUKernel() override; int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc index 3ea136c7feb..96d2c99fce6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc @@ -29,6 +29,30 @@ using mindspore::schema::PrimitiveType_MatMul; namespace mindspore::kernel { MatmulInt8CPUKernel::~MatmulInt8CPUKernel() { FreeTmpBuffer(); } +void MatmulInt8CPUKernel::FreeTmpBuffer() { + if (a_r4x16_ptr_ != nullptr) { + context_->allocator->Free(a_r4x16_ptr_); + a_r4x16_ptr_ = nullptr; + } + if (input_sums_ != nullptr) { + context_->allocator->Free(input_sums_); + input_sums_ = nullptr; + } + if (b_c16x4_batch_ != nullptr) { + context_->allocator->Free(b_c16x4_batch_); + b_c16x4_batch_ = nullptr; + } + if (weight_bias_sums_batch_ != nullptr) { + context_->allocator->Free(weight_bias_sums_batch_); + weight_bias_sums_batch_ = nullptr; + } + if (bias_ptr_ != nullptr) { + context_->allocator->Free(bias_ptr_); + bias_ptr_ = nullptr; + } + return; +} + int MatmulInt8CPUKernel::Init() { if (!InferShapeDone()) { return RET_OK; @@ -54,29 +78,29 @@ int MatmulInt8CPUKernel::ReSize() { params_->col_4_ = UP_ROUND(params_->col_, 4); params_->deep_16_ = UP_ROUND(params_->deep_, 16); a_r4x16_ptr_ = - reinterpret_cast(ctx_->allocator->Malloc(params_->row_4_ * params_->deep_16_ * sizeof(int8_t))); + reinterpret_cast(context_->allocator->Malloc(params_->row_4_ * params_->deep_16_ * sizeof(int8_t))); if (!a_r4x16_ptr_) return RET_MEMORY_FAILED; memset(a_r4x16_ptr_, 0, params_->row_4_ * params_->deep_16_ * sizeof(int8_t)); - input_sums_ = reinterpret_cast(ctx_->allocator->Malloc(params_->row_4_ * sizeof(int))); + input_sums_ = reinterpret_cast(context_->allocator->Malloc(params_->row_4_ * sizeof(int))); if (!input_sums_) return RET_MEMORY_FAILED; memset(input_sums_, 0, params_->row_4_ * sizeof(int)); b_c16x4_batch_ = reinterpret_cast( - ctx_->allocator->Malloc(params_->batch * params_->col_4_ * params_->deep_16_ * sizeof(int8_t))); + context_->allocator->Malloc(params_->batch * params_->col_4_ * params_->deep_16_ * sizeof(int8_t))); if (!b_c16x4_batch_) return RET_MEMORY_FAILED; memset(b_c16x4_batch_, 0, params_->batch * params_->col_4_ * params_->deep_16_ * sizeof(int8_t)); weight_bias_sums_batch_ = - reinterpret_cast(ctx_->allocator->Malloc(params_->batch * params_->col_4_ * sizeof(int))); + reinterpret_cast(context_->allocator->Malloc(params_->batch * params_->col_4_ * sizeof(int))); if (!weight_bias_sums_batch_) return RET_MEMORY_FAILED; memset(weight_bias_sums_batch_, 0, params_->batch * params_->col_4_ * sizeof(int)); if (in_tensors_.size() == 3) { auto bias_size = params_->col_4_ * sizeof(int); - bias_ptr_ = reinterpret_cast(ctx_->allocator->Malloc(bias_size)); + bias_ptr_ = reinterpret_cast(context_->allocator->Malloc(bias_size)); if (!bias_ptr_) return RET_MEMORY_FAILED; memcpy(bias_ptr_, in_tensors_[2]->data_c(), bias_size); } else { bias_ptr_ = NULL; } - thread_count_ = MSMIN(thread_count_, UP_DIV(params_->col_4_, 4)); + thread_count_ = MSMIN(op_parameter_->thread_num_, UP_DIV(params_->col_4_, 4)); thread_stride_ = UP_DIV(UP_DIV(params_->col_4_, 4), thread_count_); auto input_tensor = in_tensors_.at(0); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.h index 1c64160bf24..acd7fe5280e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.h @@ -18,19 +18,21 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_MATMUL_INT8_H_ #include -#include "src/runtime/kernel/arm/base/matmul_base.h" #include "include/context.h" +#include "nnacl/matmul_parameter.h" #include "nnacl/quantization/quantize.h" +#include "src/lite_kernel.h" using mindspore::lite::InnerContext; - namespace mindspore::kernel { -class MatmulInt8CPUKernel : public MatmulBaseCPUKernel { +class MatmulInt8CPUKernel : public LiteKernel { public: MatmulInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : MatmulBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + params_ = reinterpret_cast(op_parameter_); + } ~MatmulInt8CPUKernel() override; int Init() override; int ReSize() override; @@ -38,38 +40,22 @@ class MatmulInt8CPUKernel : public MatmulBaseCPUKernel { int RunImpl(int task_id); private: - void FreeTmpBuffer() { - if (a_r4x16_ptr_ != nullptr) { - ctx_->allocator->Free(a_r4x16_ptr_); - a_r4x16_ptr_ = nullptr; - } - if (input_sums_ != nullptr) { - ctx_->allocator->Free(input_sums_); - input_sums_ = nullptr; - } - if (b_c16x4_batch_ != nullptr) { - ctx_->allocator->Free(b_c16x4_batch_); - b_c16x4_batch_ = nullptr; - } - if (weight_bias_sums_batch_ != nullptr) { - ctx_->allocator->Free(weight_bias_sums_batch_); - weight_bias_sums_batch_ = nullptr; - } - if (bias_ptr_ != nullptr) { - ctx_->allocator->Free(bias_ptr_); - bias_ptr_ = nullptr; - } - } + void FreeTmpBuffer(); + + private: + MatMulParameter *params_ = nullptr; MatmulQuantArg quant_params_; int8_t *a_r4x16_ptr_ = nullptr; int8_t *b_c16x4_ptr_ = nullptr; int8_t *c_ptr_ = nullptr; + int8_t *b_c16x4_batch_ = nullptr; int *bias_ptr_ = nullptr; int *input_sums_ = nullptr; int *weight_bias_sums_ = nullptr; - int8_t *b_c16x4_batch_ = nullptr; int *weight_bias_sums_batch_ = nullptr; -}; // namespace mindspore::kernel + int thread_stride_ = 0; + int thread_count_ = 0; +}; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_MATMUL_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc index 59a9fe33ff6..e21389344dc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.cc @@ -22,20 +22,13 @@ #include "src/kernel_registry.h" using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; - -using mindspore::lite::KernelRegistrar; using mindspore::schema::PrimitiveType_Power; namespace mindspore::kernel { - int PowerInt8CPUKernel::Init() { - auto ret = PowerBaseCPUKernel::Init(); - if (ret != RET_OK) { - return ret; - } - auto input = in_tensors_.at(0); auto output = out_tensors_.at(0); MS_ASSERT(input); @@ -58,12 +51,12 @@ int PowerInt8CPUKernel::Init() { return ReSize(); } -int PowerInt8CPUKernel::ReSize() { return PowerBaseCPUKernel::ReSize(); } +int PowerInt8CPUKernel::ReSize() { return RET_OK; } int PowerInt8CPUKernel::DoPower(int task_id) { - const int8_t *input_data = reinterpret_cast(in_tensors_[0]->MutableData()); + const int8_t *input_data = reinterpret_cast(in_tensors_[0]->data_c()); MS_ASSERT(input_data); - int8_t *output_data = reinterpret_cast(out_tensors_[0]->MutableData()); + int8_t *output_data = reinterpret_cast(out_tensors_[0]->data_c()); MS_ASSERT(output_data); auto size = in_tensors_.at(0)->ElementsNum(); @@ -112,30 +105,6 @@ int PowerInt8CPUKernel::Run() { } return ret; } -kernel::LiteKernel *CpuPowerInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const lite::InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Power); - auto *kernel = new (std::nothrow) PowerInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new PowerInt8CPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Power, CpuPowerInt8KernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Power, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.h index cd989b10000..393ac7755d5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/power_int8.h @@ -18,22 +18,28 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_POWER_INT8_H_ #include -#include "src/runtime/kernel/arm/base/power_base.h" +#include "src/lite_kernel.h" #include "nnacl/quantization/quantize.h" +#include "nnacl/power_parameter.h" namespace mindspore::kernel { -class PowerInt8CPUKernel : public PowerBaseCPUKernel { +class PowerInt8CPUKernel : public LiteKernel { public: PowerInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : PowerBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + param_ = reinterpret_cast(op_parameter_); + } ~PowerInt8CPUKernel() {} int Init() override; int ReSize() override; int Run() override; int DoPower(int task_id); + + private: + PowerParameter *param_; }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc index 51557f6a351..4826d1e3482 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc @@ -31,7 +31,6 @@ using mindspore::schema::PrimitiveType_Reshape; namespace mindspore::kernel { int ReshapeInt8CPUKernel::Init() { - ReshapeBaseCPUKernel::Init(); auto *input_tensor = in_tensors_.at(kInputIndex); auto in_quant_args = input_tensor->quant_params(); reshape_param_->quant_para_.in_args_.scale_ = in_quant_args.front().scale; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.h index 2382636eab7..07119e81b38 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.h @@ -20,18 +20,20 @@ #include #include "src/lite_kernel.h" #include "include/context.h" -#include "src/runtime/kernel/arm/base/reshape_base.h" +#include "nnacl/reshape_parameter.h" #include "src/runtime/runtime_api.h" using mindspore::lite::InnerContext; namespace mindspore::kernel { -class ReshapeInt8CPUKernel : public ReshapeBaseCPUKernel { +class ReshapeInt8CPUKernel : public LiteKernel { public: ReshapeInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : ReshapeBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + reshape_param_ = reinterpret_cast(op_parameter_); + } ~ReshapeInt8CPUKernel() = default; int Init() override; @@ -44,6 +46,7 @@ class ReshapeInt8CPUKernel : public ReshapeBaseCPUKernel { int64_t count_unit_; int8_t *input_data_ = nullptr; int8_t *output_data_ = nullptr; + ReshapeParameter *reshape_param_ = nullptr; }; int ReshapeInt8Run(void *cdata, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc index 8369fae72cd..b318b16447c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc @@ -17,21 +17,18 @@ #include "nnacl/int8/squeeze_int8.h" #include "src/runtime/kernel/arm/int8/squeeze_int8.h" #include "nnacl/squeeze_parameter.h" - #include "schema/model_generated.h" #include "src/runtime/runtime_api.h" #include "include/errorcode.h" #include "src/kernel_registry.h" using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; - -using mindspore::lite::KernelRegistrar; using mindspore::schema::PrimitiveType_Squeeze; namespace mindspore::kernel { - SqueezeInt8CPUKernel::~SqueezeInt8CPUKernel() { if (quant_squeeze_param_ != nullptr) { if (quant_squeeze_param_->in_quant_args_ != nullptr) { @@ -95,7 +92,7 @@ int SqueezeInt8CPUKernel::Init() { int SqueezeInt8CPUKernel::ReSize() { return RET_OK; } int SqueezeInt8CPUKernel::Run() { - auto ret = ParallelLaunch(this->context_->thread_pool_, SqueezeInt8Run, this, thread_count_); + auto ret = ParallelLaunch(this->context_->thread_pool_, SqueezeInt8Run, this, op_parameter_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "RunSqueezeParam failed. errorcode: "; } @@ -113,39 +110,15 @@ int SqueezeInt8CPUKernel::DoExecute(int task_id) { MS_ASSERT(input_tensor); auto out_tensor = out_tensors_.at(kOutputIndex); MS_ASSERT(out_tensor); - int8_t *input_data = reinterpret_cast(input_tensor->MutableData()); + int8_t *input_data = reinterpret_cast(input_tensor->data_c()); MS_ASSERT(input_data); - int8_t *output_data = reinterpret_cast(out_tensor->MutableData()); + int8_t *output_data = reinterpret_cast(out_tensor->data_c()); MS_ASSERT(output_data); int num = input_tensor->ElementsNum(); SqueezeInt8(input_data, output_data, task_id, quant_squeeze_param_, para_, num); return RET_OK; } -kernel::LiteKernel *CpuSqueezeInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, OpParameter *opParameter, - const InnerContext *ctx, const kernel::KernelKey &desc, - const mindspore::lite::PrimitiveC *primitive) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Squeeze); - auto *kernel = new (std::nothrow) SqueezeInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new SqueezeCPUKernel fail!"; - free(opParameter); - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - delete kernel; - return nullptr; - } - return kernel; -} -REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Squeeze, CpuSqueezeInt8KernelCreator) +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Squeeze, CPUKernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.h index 5128a3825ef..0001fad685e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.h @@ -21,17 +21,15 @@ #include "src/lite_kernel.h" #include "include/context.h" #include "src/runtime/runtime_api.h" -#include "src/runtime/kernel/arm/base/squeeze_base.h" using mindspore::lite::InnerContext; - namespace mindspore::kernel { -class SqueezeInt8CPUKernel : public SqueezeBaseCPUKernel { +class SqueezeInt8CPUKernel : public LiteKernel { public: SqueezeInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const InnerContext *ctx, const mindspore::lite::PrimitiveC *primitive) - : SqueezeBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) { + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { para_ = reinterpret_cast(parameter); } ~SqueezeInt8CPUKernel() override; @@ -47,7 +45,6 @@ class SqueezeInt8CPUKernel : public SqueezeBaseCPUKernel { }; int SqueezeInt8Run(void *cdata, int task_id); - } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_SQUEEZE_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.h b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.h index 558e8eaf8d7..f685edc48f1 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.h +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.h @@ -19,7 +19,7 @@ #include #include "src/runtime/kernel/opencl/opencl_kernel.h" -#include "src/runtime/kernel/arm/base/concat_base.h" +#include "nnacl/concat_parameter.h" namespace mindspore::kernel {