diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index 474868e5ee..f418468b54 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -31,7 +31,6 @@ set(LITE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/kernel_registry.cc ${CMAKE_CURRENT_SOURCE_DIR}/lite_kernel.cc ${CMAKE_CURRENT_SOURCE_DIR}/sub_graph_kernel.cc - ${CMAKE_CURRENT_SOURCE_DIR}/populate_parameter.cc ${CMAKE_CURRENT_SOURCE_DIR}/scheduler.cc ${CMAKE_CURRENT_SOURCE_DIR}/lite_session.cc ${CMAKE_CURRENT_SOURCE_DIR}/model.cc @@ -65,7 +64,7 @@ if (SUPPORT_TRAIN) ) endif () -file(GLOB_RECURSE C_OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/ops/*.cc) +file(GLOB_RECURSE C_OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/ops/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/ops/populate/*.cc) add_subdirectory(runtime/kernel/arm) add_library(mindspore-lite SHARED ${LITE_SRC} ${C_OPS_SRC}) diff --git a/mindspore/lite/src/kernel_registry.cc b/mindspore/lite/src/kernel_registry.cc index 6744a804f6..1cd0826e99 100644 --- a/mindspore/lite/src/kernel_registry.cc +++ b/mindspore/lite/src/kernel_registry.cc @@ -15,8 +15,7 @@ */ #include "src/kernel_registry.h" #include "include/errorcode.h" - -#include "src/populate_parameter.h" +#include "src/ops/populate/populate_register.h" #ifdef ENABLE_ARM64 #include #include "common/utils.h" @@ -107,7 +106,8 @@ kernel::LiteKernel *KernelRegistry::GetKernel(const std::vector &in_te const InnerContext *ctx, const kernel::KernelKey &key) { MS_ASSERT(nullptr != primitive); MS_ASSERT(nullptr != ctx); - auto parameter = kernel::PopulateParameter(primitive); + auto parameter = + PopulateRegistry::GetInstance()->getParameterCreator(schema::PrimitiveType(primitive->Type()))(primitive); if (parameter == nullptr) { MS_LOG(ERROR) << "PopulateParameter return nullptr, type: " << schema::EnumNamePrimitiveType((schema::PrimitiveType)primitive->Type()); diff --git a/mindspore/lite/src/model_common.cc b/mindspore/lite/src/model_common.cc index 92ed8c76fe..15ba907e9c 100644 --- a/mindspore/lite/src/model_common.cc +++ b/mindspore/lite/src/model_common.cc @@ -16,7 +16,9 @@ #include "src/model_common.h" #include "include/version.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore::lite { bool ConvertNodes(const schema::MetaGraph *meta_graph, Model *model) { diff --git a/mindspore/lite/src/ops/abs.cc b/mindspore/lite/src/ops/abs.cc index 3e9c3a19d0..97c53026bb 100644 --- a/mindspore/lite/src/ops/abs.cc +++ b/mindspore/lite/src/ops/abs.cc @@ -15,7 +15,9 @@ */ #include "src/ops/abs.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -31,6 +33,6 @@ int Abs::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::Fl PrimitiveC *AbsCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry AbsRegistry(schema::PrimitiveType_Abs, AbsCreator); #endif -Registry AbsParameterRegistry(schema::PrimitiveType_Abs, PopulateArithmeticSelf); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/activation.cc b/mindspore/lite/src/ops/activation.cc index 428f526713..9021392dfa 100644 --- a/mindspore/lite/src/ops/activation.cc +++ b/mindspore/lite/src/ops/activation.cc @@ -16,8 +16,9 @@ #include "src/ops/activation.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/activation.h" +#endif namespace mindspore { namespace lite { @@ -88,24 +89,6 @@ PrimitiveC *ActivationCreator(const schema::Primitive *primitive) { } Registry ActivationRegistry(schema::PrimitiveType_Activation, ActivationCreator); #endif -OpParameter *PopulateActivationParameter(const mindspore::lite::PrimitiveC *primitive) { - ActivationParameter *act_param = reinterpret_cast(malloc(sizeof(ActivationParameter))); - if (act_param == nullptr) { - MS_LOG(ERROR) << "malloc ActivationParameter failed."; - return nullptr; - } - memset(act_param, 0, sizeof(ActivationParameter)); - act_param->op_parameter_.type_ = primitive->Type(); - auto activation = - reinterpret_cast(const_cast(primitive)); - act_param->type_ = static_cast(activation->GetType()); - act_param->alpha_ = activation->GetAlpha(); - act_param->min_val_ = activation->GetMinVal(); - act_param->max_val_ = activation->GetMaxVal(); - return reinterpret_cast(act_param); -} - -Registry ActivationParameterRegistry(schema::PrimitiveType_Activation, PopulateActivationParameter); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/activation_grad.cc b/mindspore/lite/src/ops/activation_grad.cc index 3dcf2ab216..ac4f093fc8 100644 --- a/mindspore/lite/src/ops/activation_grad.cc +++ b/mindspore/lite/src/ops/activation_grad.cc @@ -16,7 +16,9 @@ #include "src/ops/activation_grad.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/adam.cc b/mindspore/lite/src/ops/adam.cc index a3a2b8d922..63a140b6cf 100644 --- a/mindspore/lite/src/ops/adam.cc +++ b/mindspore/lite/src/ops/adam.cc @@ -14,7 +14,9 @@ * limitations under the License. */ #include "src/ops/adam.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/add.cc b/mindspore/lite/src/ops/add.cc index 1d92a6625f..0d868ac499 100644 --- a/mindspore/lite/src/ops/add.cc +++ b/mindspore/lite/src/ops/add.cc @@ -16,8 +16,9 @@ #include "src/ops/add.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/arithmetic_common.h" +#endif namespace mindspore { namespace lite { @@ -77,27 +78,5 @@ PrimitiveC *AddCreator(const schema::Primitive *primitive) { return PrimitiveC:: Registry AddRegistry(schema::PrimitiveType_Add, AddCreator); #endif -OpParameter *PopulateAddParameter(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); - if (arithmetic_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; - return nullptr; - } - memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); - arithmetic_param->op_parameter_.type_ = primitive->Type(); - arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); - arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); - arithmetic_param->activation_type_ = - reinterpret_cast(const_cast(primitive))->GetActivationType(); - auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); - memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); - memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); - memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - return reinterpret_cast(arithmetic_param); -} -Registry AddParameterRegistry(schema::PrimitiveType_Add, PopulateAddParameter); - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/addn.cc b/mindspore/lite/src/ops/addn.cc index 11e8556058..711adb99b5 100644 --- a/mindspore/lite/src/ops/addn.cc +++ b/mindspore/lite/src/ops/addn.cc @@ -16,7 +16,9 @@ #include "src/ops/addn.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -68,18 +70,6 @@ PrimitiveC *AddNCreator(const schema::Primitive *primitive) { return PrimitiveC: Registry AddNRegistry(schema::PrimitiveType_AddN, AddNCreator); #endif -OpParameter *PopulateAddNParameter(const mindspore::lite::PrimitiveC *primitive) { - OpParameter *addn_param = reinterpret_cast(malloc(sizeof(OpParameter))); - if (addn_param == nullptr) { - MS_LOG(ERROR) << "malloc OpParameter failed."; - return nullptr; - } - memset(addn_param, 0, sizeof(OpParameter)); - addn_param->type_ = primitive->Type(); - return reinterpret_cast(addn_param); -} -Registry AddNParameterRegistry(schema::PrimitiveType_AddN, PopulateAddNParameter); - namespace { constexpr int kLeastInputNum = 2; } diff --git a/mindspore/lite/src/ops/apply_momentum.cc b/mindspore/lite/src/ops/apply_momentum.cc index 56c50f00e4..b2759bc1e5 100644 --- a/mindspore/lite/src/ops/apply_momentum.cc +++ b/mindspore/lite/src/ops/apply_momentum.cc @@ -14,7 +14,9 @@ * limitations under the License. */ #include "src/ops/apply_momentum.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/argmax.cc b/mindspore/lite/src/ops/argmax.cc index 562b7a39b5..b7276de94d 100644 --- a/mindspore/lite/src/ops/argmax.cc +++ b/mindspore/lite/src/ops/argmax.cc @@ -16,8 +16,9 @@ #include "src/ops/argmax.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/arg_min_max_parameter.h" +#endif namespace mindspore { namespace lite { @@ -59,25 +60,6 @@ PrimitiveC *ArgMaxCreator(const schema::Primitive *primitive) { return Primitive Registry ArgMaxRegistry(schema::PrimitiveType_ArgMax, ArgMaxCreator); #endif -OpParameter *PopulateArgMaxParameter(const mindspore::lite::PrimitiveC *primitive) { - ArgMinMaxParameter *arg_param = reinterpret_cast(malloc(sizeof(ArgMinMaxParameter))); - if (arg_param == nullptr) { - MS_LOG(ERROR) << "malloc ArgMinMaxParameter failed."; - return nullptr; - } - memset(arg_param, 0, sizeof(ArgMinMaxParameter)); - arg_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - arg_param->axis_ = param->GetAxis(); - arg_param->topk_ = param->GetTopK(); - arg_param->axis_type_ = param->GetAxisType(); - arg_param->out_value_ = param->GetOutMaxValue(); - arg_param->keep_dims_ = param->GetKeepDims(); - return reinterpret_cast(arg_param); -} - -Registry ArgMaxParameterRegistry(schema::PrimitiveType_ArgMax, PopulateArgMaxParameter); - int ArgMax::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/argmin.cc b/mindspore/lite/src/ops/argmin.cc index 5bd0250bf1..ac6602594e 100644 --- a/mindspore/lite/src/ops/argmin.cc +++ b/mindspore/lite/src/ops/argmin.cc @@ -16,8 +16,9 @@ #include "src/ops/argmin.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/arg_min_max_parameter.h" +#endif namespace mindspore { namespace lite { @@ -59,25 +60,6 @@ PrimitiveC *ArgMinCreator(const schema::Primitive *primitive) { return Primitive Registry ArgMinRegistry(schema::PrimitiveType_ArgMin, ArgMinCreator); #endif -OpParameter *PopulateArgMinParameter(const mindspore::lite::PrimitiveC *primitive) { - ArgMinMaxParameter *arg_param = reinterpret_cast(malloc(sizeof(ArgMinMaxParameter))); - if (arg_param == nullptr) { - MS_LOG(ERROR) << "malloc ArgMinMaxParameter failed."; - return nullptr; - } - memset(arg_param, 0, sizeof(ArgMinMaxParameter)); - arg_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - arg_param->axis_ = param->GetAxis(); - arg_param->topk_ = param->GetTopK(); - arg_param->axis_type_ = param->GetAxisType(); - arg_param->out_value_ = param->GetOutMaxValue(); - arg_param->keep_dims_ = param->GetKeepDims(); - return reinterpret_cast(arg_param); -} - -Registry ArgMinParameterRegistry(schema::PrimitiveType_ArgMin, PopulateArgMinParameter); - int ArgMin::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/arithmetic.cc b/mindspore/lite/src/ops/arithmetic.cc index 120d6eaf8f..67218884ac 100644 --- a/mindspore/lite/src/ops/arithmetic.cc +++ b/mindspore/lite/src/ops/arithmetic.cc @@ -22,28 +22,6 @@ namespace mindspore { namespace lite { -OpParameter *PopulateArithmetic(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); - if (arithmetic_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; - return nullptr; - } - memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); - arithmetic_param->op_parameter_.type_ = primitive->Type(); - arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); - arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); - - arithmetic_param->activation_type_ = 0; - - auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); - memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); - memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); - memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - return reinterpret_cast(arithmetic_param); -} - int Arithmetic::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); if (inputs_.size() != kDoubleNum) { diff --git a/mindspore/lite/src/ops/arithmetic.h b/mindspore/lite/src/ops/arithmetic.h index 6ee2d51694..ad82a3851e 100644 --- a/mindspore/lite/src/ops/arithmetic.h +++ b/mindspore/lite/src/ops/arithmetic.h @@ -52,8 +52,6 @@ class Arithmetic : public PrimitiveC { std::vector in_shape1_; std::vector out_shape_; }; - -OpParameter *PopulateArithmetic(const mindspore::lite::PrimitiveC *primitive); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/arithmetic_self.cc b/mindspore/lite/src/ops/arithmetic_self.cc index 798fa9fd5a..d99304f57c 100644 --- a/mindspore/lite/src/ops/arithmetic_self.cc +++ b/mindspore/lite/src/ops/arithmetic_self.cc @@ -17,21 +17,12 @@ #include "src/ops/arithmetic_self.h" #include "include/errorcode.h" #include "src/common/log_adapter.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { -OpParameter *PopulateArithmeticSelf(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticSelfParameter *arithmetic_self_param = - reinterpret_cast(malloc(sizeof(ArithmeticSelfParameter))); - if (arithmetic_self_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticSelfParameter failed."; - return nullptr; - } - memset(arithmetic_self_param, 0, sizeof(ArithmeticSelfParameter)); - arithmetic_self_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(arithmetic_self_param); -} int ArithmeticSelf::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); diff --git a/mindspore/lite/src/ops/assign.cc b/mindspore/lite/src/ops/assign.cc index 456b6802e8..bda4ca3a62 100644 --- a/mindspore/lite/src/ops/assign.cc +++ b/mindspore/lite/src/ops/assign.cc @@ -17,7 +17,9 @@ #include "src/ops/assign.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/batch_norm.cc b/mindspore/lite/src/ops/batch_norm.cc index e2ca9d43f2..0b09798d1b 100644 --- a/mindspore/lite/src/ops/batch_norm.cc +++ b/mindspore/lite/src/ops/batch_norm.cc @@ -16,8 +16,9 @@ #include "src/ops/batch_norm.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/batchnorm_parameter.h" +#endif namespace mindspore { namespace lite { @@ -69,22 +70,5 @@ PrimitiveC *BatchNormCreator(const schema::Primitive *primitive) { Registry BatchNormRegistry(schema::PrimitiveType_BatchNorm, BatchNormCreator); #endif -OpParameter *PopulateBatchNorm(const mindspore::lite::PrimitiveC *primitive) { - const auto param = - reinterpret_cast(const_cast(primitive)); - BatchNormParameter *batch_norm_param = reinterpret_cast(malloc(sizeof(BatchNormParameter))); - if (batch_norm_param == nullptr) { - MS_LOG(ERROR) << "malloc BatchNormParameter failed."; - return nullptr; - } - memset(batch_norm_param, 0, sizeof(BatchNormParameter)); - batch_norm_param->op_parameter_.type_ = primitive->Type(); - batch_norm_param->epsilon_ = param->GetEpsilon(); - batch_norm_param->fused_ = false; - return reinterpret_cast(batch_norm_param); -} - -Registry BatchNormParameterRegistry(schema::PrimitiveType_BatchNorm, PopulateBatchNorm); - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/batch_to_space.cc b/mindspore/lite/src/ops/batch_to_space.cc index e55edbc9f1..2e34124e22 100644 --- a/mindspore/lite/src/ops/batch_to_space.cc +++ b/mindspore/lite/src/ops/batch_to_space.cc @@ -20,8 +20,9 @@ #include "src/common/log_adapter.h" #include "src/tensor.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/batch_to_space.h" +#endif namespace mindspore { namespace lite { @@ -75,43 +76,6 @@ PrimitiveC *BatchToSpaceCreator(const schema::Primitive *primitive) { Registry BatchToSpaceRegistry(schema::PrimitiveType_BatchToSpace, BatchToSpaceCreator); #endif -OpParameter *PopulateBatchToSpaceParameter(const mindspore::lite::PrimitiveC *primitive) { - BatchToSpaceParameter *batch_space_param = - reinterpret_cast(malloc(sizeof(BatchToSpaceParameter))); - if (batch_space_param == nullptr) { - MS_LOG(ERROR) << "malloc BatchToSpaceParameter failed."; - return nullptr; - } - memset(batch_space_param, 0, sizeof(BatchToSpaceParameter)); - batch_space_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - auto block_shape = param->GetBlockShape(); - if (block_shape.size() != BATCH_TO_SPACE_BLOCK_SHAPE_SIZE) { - MS_LOG(ERROR) << "batch_to_space blockShape size should be " << BATCH_TO_SPACE_BLOCK_SHAPE_SIZE; - free(batch_space_param); - return nullptr; - } - - auto crops = param->GetCrops(); - if (crops.size() != BATCH_TO_SPACE_CROPS_SIZE) { - MS_LOG(ERROR) << "batch_to_space crops size should be " << BATCH_TO_SPACE_CROPS_SIZE; - free(batch_space_param); - return nullptr; - } - - for (int i = 0; i < BATCH_TO_SPACE_BLOCK_SHAPE_SIZE; ++i) { - batch_space_param->block_shape_[i] = block_shape[i]; - } - - for (int i = 0; i < BATCH_TO_SPACE_CROPS_SIZE; ++i) { - batch_space_param->crops_[i] = crops[i]; - } - return reinterpret_cast(batch_space_param); -} - -Registry BatchToSpaceParameterRegistry(schema::PrimitiveType_BatchToSpace, PopulateBatchToSpaceParameter); -Registry BatchToSpaceNDParameterRegistry(schema::PrimitiveType_BatchToSpaceND, PopulateBatchToSpaceParameter); - namespace { constexpr int kBatchToSpaceOutputNum = 1; constexpr int kBatchToSpaceInputNum = 1; diff --git a/mindspore/lite/src/ops/bias_add.cc b/mindspore/lite/src/ops/bias_add.cc index ec0e54040e..899597ea41 100644 --- a/mindspore/lite/src/ops/bias_add.cc +++ b/mindspore/lite/src/ops/bias_add.cc @@ -16,8 +16,10 @@ #include "src/ops/bias_add.h" #include -#include "nnacl/arithmetic_common.h" + +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -84,18 +86,5 @@ PrimitiveC *BiasAddCreator(const schema::Primitive *primitive) { return Primitiv Registry BiasAddRegistry(schema::PrimitiveType_BiasAdd, BiasAddCreator); #endif -OpParameter *PopulateBiasAddParameter(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); - if (arithmetic_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; - return nullptr; - } - memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); - arithmetic_param->op_parameter_.type_ = primitive->Type(); - - return reinterpret_cast(arithmetic_param); -} -Registry BiasAddParameterRegistry(schema::PrimitiveType_BiasAdd, PopulateBiasAddParameter); - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/bias_grad.cc b/mindspore/lite/src/ops/bias_grad.cc index 3da20349b6..dfe57ec218 100644 --- a/mindspore/lite/src/ops/bias_grad.cc +++ b/mindspore/lite/src/ops/bias_grad.cc @@ -16,7 +16,9 @@ #include "src/ops/bias_grad.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/bn_grad.cc b/mindspore/lite/src/ops/bn_grad.cc index ef450a809e..5770a3a9e9 100644 --- a/mindspore/lite/src/ops/bn_grad.cc +++ b/mindspore/lite/src/ops/bn_grad.cc @@ -16,7 +16,9 @@ #include "src/ops/bn_grad.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/broadcast_to.cc b/mindspore/lite/src/ops/broadcast_to.cc index a4741e2954..2ce4a5d260 100644 --- a/mindspore/lite/src/ops/broadcast_to.cc +++ b/mindspore/lite/src/ops/broadcast_to.cc @@ -16,8 +16,9 @@ #include "src/ops/broadcast_to.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/broadcast_to.h" +#endif namespace mindspore { namespace lite { @@ -59,26 +60,6 @@ PrimitiveC *BroadcastToCreator(const schema::Primitive *primitive) { Registry BroadcastToRegistry(schema::PrimitiveType_BroadcastTo, BroadcastToCreator); #endif -OpParameter *PopulateBroadcastToParameter(const mindspore::lite::PrimitiveC *primitive) { - BroadcastToParameter *broadcast_param = - reinterpret_cast(malloc(sizeof(BroadcastToParameter))); - if (broadcast_param == nullptr) { - MS_LOG(ERROR) << "malloc BroadcastToParameter failed."; - return nullptr; - } - memset(broadcast_param, 0, sizeof(BroadcastToParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - broadcast_param->op_parameter_.type_ = primitive->Type(); - auto dst_shape = param->GetDstShape(); - broadcast_param->shape_size_ = dst_shape.size(); - for (size_t i = 0; i < broadcast_param->shape_size_; ++i) { - broadcast_param->shape_[i] = dst_shape[i]; - } - return reinterpret_cast(broadcast_param); -} - -Registry BroadcastToParameterRegistry(schema::PrimitiveType_BroadcastTo, PopulateBroadcastToParameter); - namespace { constexpr int kBroadcastToInputNum = 1; constexpr int kBroadcastToOutputNum = 1; diff --git a/mindspore/lite/src/ops/cast.cc b/mindspore/lite/src/ops/cast.cc index 348abd0c99..9a9ef7f94b 100644 --- a/mindspore/lite/src/ops/cast.cc +++ b/mindspore/lite/src/ops/cast.cc @@ -16,8 +16,9 @@ #include "src/ops/cast.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/cast.h" +#endif namespace mindspore { namespace lite { @@ -82,22 +83,6 @@ PrimitiveC *CastCreator(const schema::Primitive *primitive) { return PrimitiveC: Registry CastRegistry(schema::PrimitiveType_Cast, CastCreator); #endif -OpParameter *PopulateCastParameter(const mindspore::lite::PrimitiveC *primitive) { - CastParameter *cast_param = reinterpret_cast(malloc(sizeof(CastParameter))); - if (cast_param == nullptr) { - MS_LOG(ERROR) << "malloc CastParameter failed."; - return nullptr; - } - memset(cast_param, 0, sizeof(CastParameter)); - cast_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - cast_param->src_type_ = param->GetSrcT(); - cast_param->dst_type_ = param->GetDstT(); - return reinterpret_cast(cast_param); -} - -Registry CastParameterRegistry(schema::PrimitiveType_Cast, PopulateCastParameter); - int Cast::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/ceil.h b/mindspore/lite/src/ops/ceil.h index 3a7ebfa739..1f8d88d8bb 100644 --- a/mindspore/lite/src/ops/ceil.h +++ b/mindspore/lite/src/ops/ceil.h @@ -21,7 +21,6 @@ #include #include #include "src/ops/arithmetic_self.h" -#include "src/ops/ops_register.h" namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/clip.cc b/mindspore/lite/src/ops/clip.cc index f928601e47..a5fd8e9616 100644 --- a/mindspore/lite/src/ops/clip.cc +++ b/mindspore/lite/src/ops/clip.cc @@ -16,7 +16,9 @@ #include "src/ops/clip.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif #include "nnacl/clip.h" namespace mindspore { @@ -48,21 +50,6 @@ float Clip::GetMin() const { return this->primitive_->value_as_Clip()->min(); } PrimitiveC *ClipCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry ClipRegistry(schema::PrimitiveType_Clip, ClipCreator); #endif -OpParameter *PopulateClipParameter(const mindspore::lite::PrimitiveC *primitive) { - ClipParameter *act_param = reinterpret_cast(malloc(sizeof(ClipParameter))); - if (act_param == nullptr) { - MS_LOG(ERROR) << "malloc ClipParameter failed."; - return nullptr; - } - memset(act_param, 0, sizeof(ClipParameter)); - act_param->op_parameter_.type_ = primitive->Type(); - auto activation = reinterpret_cast(const_cast(primitive)); - act_param->min_val_ = activation->GetMin(); - act_param->max_val_ = activation->GetMax(); - return reinterpret_cast(act_param); -} - -Registry ClipParameterRegistry(schema::PrimitiveType_Clip, PopulateClipParameter); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/concat.cc b/mindspore/lite/src/ops/concat.cc index 27e29bc8c0..64e5fe8c32 100644 --- a/mindspore/lite/src/ops/concat.cc +++ b/mindspore/lite/src/ops/concat.cc @@ -19,8 +19,9 @@ #include "include/errorcode.h" #include "src/common/log_adapter.h" #include "src/tensor.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/concat_parameter.h" +#endif namespace mindspore { namespace lite { @@ -83,21 +84,6 @@ Registry ConcatRegistry(schema::PrimitiveType_Concat, ConcatCreator); #endif -OpParameter *PopulateConcatParameter(const mindspore::lite::PrimitiveC *primitive) { - ConcatParameter *concat_param = reinterpret_cast(malloc(sizeof(ConcatParameter))); - if (concat_param == nullptr) { - MS_LOG(ERROR) << "malloc ConcatParameter failed."; - return nullptr; - } - memset(concat_param, 0, sizeof(ConcatParameter)); - concat_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - concat_param->axis_ = param->GetAxis(); - return reinterpret_cast(concat_param); -} - -Registry ConcatParameterRegistry(schema::PrimitiveType_Concat, PopulateConcatParameter); - namespace { constexpr int kConcatOutputNum = 1; } diff --git a/mindspore/lite/src/ops/constant_of_shape.cc b/mindspore/lite/src/ops/constant_of_shape.cc index f1e7e60bdb..e6b3e14b90 100644 --- a/mindspore/lite/src/ops/constant_of_shape.cc +++ b/mindspore/lite/src/ops/constant_of_shape.cc @@ -18,8 +18,9 @@ #include "include/errorcode.h" #include "src/common/log_adapter.h" #include "src/tensor.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/constant_of_shape.h" +#endif namespace mindspore::lite { namespace { @@ -54,22 +55,6 @@ Registry ConstantOfShapeRegistry(schema::PrimitiveType_ConstantOfShape, Constant #endif -OpParameter *PopulateConstantOfShapeParameter(const mindspore::lite::PrimitiveC *primitive) { - auto attr = - reinterpret_cast(const_cast(primitive)); - ConstantOfShapeParameter *param = - reinterpret_cast(malloc(sizeof(ConstantOfShapeParameter))); - if (param == nullptr) { - MS_LOG(ERROR) << "malloc ConstantOfShapeParameter failed."; - return nullptr; - } - memset(param, 0, sizeof(ConstantOfShapeParameter)); - param->op_parameter_.type_ = primitive->Type(); - param->value_ = attr->GetValue(); - return reinterpret_cast(param); -} -Registry ConstantOfShapeParameterRegistry(schema::PrimitiveType_ConstantOfShape, PopulateConstantOfShapeParameter); - int ConstantOfShape::InferShape(std::vector inputs_, std::vector outputs_) { if (inputs_.size() != kShapeInputNum) { MS_LOG(ERROR) << "inputs to ConstantOfShape operator should be 1, but " << inputs_.size() << " is given."; diff --git a/mindspore/lite/src/ops/conv2d.cc b/mindspore/lite/src/ops/conv2d.cc index a4a0c6ca17..ed9148b168 100644 --- a/mindspore/lite/src/ops/conv2d.cc +++ b/mindspore/lite/src/ops/conv2d.cc @@ -26,8 +26,10 @@ #include #include "tools/converter/quantizer/quantize_util.h" #endif -#include "nnacl/conv_parameter.h" + +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -324,47 +326,6 @@ int Conv2D::GetActivationType() const { return this->primitive_->value_as_Conv2D PrimitiveC *Conv2DCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry Conv2DRegistry(schema::PrimitiveType_Conv2D, Conv2DCreator); #endif -OpParameter *PopulateConvParameter(const mindspore::lite::PrimitiveC *primitive) { - ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); - if (conv_param == nullptr) { - MS_LOG(ERROR) << "malloc ConvParameter failed."; - return nullptr; - } - memset(conv_param, 0, sizeof(ConvParameter)); - conv_param->op_parameter_.type_ = primitive->Type(); - auto conv_primitive = - reinterpret_cast(const_cast(primitive)); - conv_param->kernel_h_ = conv_primitive->GetKernelH(); - conv_param->kernel_w_ = conv_primitive->GetKernelW(); - conv_param->group_ = conv_primitive->GetGroup(); - conv_param->stride_h_ = conv_primitive->GetStrideH(); - conv_param->stride_w_ = conv_primitive->GetStrideW(); - - auto conv2d_lite_primitive = (lite::Conv2D *)primitive; - conv_param->pad_u_ = conv2d_lite_primitive->PadUp(); - conv_param->pad_d_ = conv2d_lite_primitive->PadDown(); - conv_param->pad_l_ = conv2d_lite_primitive->PadLeft(); - conv_param->pad_r_ = conv2d_lite_primitive->PadRight(); - conv_param->dilation_h_ = conv_primitive->GetDilateH(); - conv_param->dilation_w_ = conv_primitive->GetDilateW(); - conv_param->input_channel_ = conv_primitive->GetChannelIn(); - conv_param->output_channel_ = conv_primitive->GetChannelOut(); - conv_param->group_ = conv_primitive->GetGroup(); - auto act_type = conv_primitive->GetActivationType(); - switch (act_type) { - case schema::ActivationType_RELU: - conv_param->act_type_ = ActType_Relu; - break; - case schema::ActivationType_RELU6: - conv_param->act_type_ = ActType_Relu6; - break; - default: - conv_param->act_type_ = ActType_No; - break; - } - return reinterpret_cast(conv_param); -} -Registry Conv2DParameterRegistry(schema::PrimitiveType_Conv2D, PopulateConvParameter); void Conv2D::ConvInferShape(int input_h, int input_w, int *output_h, int *output_w) { MS_ASSERT(this->primitive_ != nullptr); diff --git a/mindspore/lite/src/ops/conv2d_grad_filter.cc b/mindspore/lite/src/ops/conv2d_grad_filter.cc index 5665ec971f..a184eeeef2 100644 --- a/mindspore/lite/src/ops/conv2d_grad_filter.cc +++ b/mindspore/lite/src/ops/conv2d_grad_filter.cc @@ -15,7 +15,9 @@ */ #include "src/ops/conv2d_grad_filter.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/conv2d_grad_input.cc b/mindspore/lite/src/ops/conv2d_grad_input.cc index 7b2fefd811..4d074f9d8d 100644 --- a/mindspore/lite/src/ops/conv2d_grad_input.cc +++ b/mindspore/lite/src/ops/conv2d_grad_input.cc @@ -16,7 +16,9 @@ #include "src/ops/conv2d_grad_input.h" #include "src/ops/group_conv2d_grad_input.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/cos.cc b/mindspore/lite/src/ops/cos.cc index c01aec3588..6a49363a09 100644 --- a/mindspore/lite/src/ops/cos.cc +++ b/mindspore/lite/src/ops/cos.cc @@ -16,7 +16,9 @@ #include "src/ops/cos.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -32,7 +34,6 @@ int Cos::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::Fl PrimitiveC *CosCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry CosRegistry(schema::PrimitiveType_Cos, CosCreator); #endif -Registry CosParameterRegistry(schema::PrimitiveType_Cos, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/crop.cc b/mindspore/lite/src/ops/crop.cc index 1d88d4361e..141d55f239 100644 --- a/mindspore/lite/src/ops/crop.cc +++ b/mindspore/lite/src/ops/crop.cc @@ -16,8 +16,9 @@ #include "src/ops/crop.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/crop_parameter.h" +#endif namespace mindspore { namespace lite { @@ -58,29 +59,6 @@ PrimitiveC *CropCreator(const schema::Primitive *primitive) { return PrimitiveC: Registry CropRegistry(schema::PrimitiveType_Crop, CropCreator); #endif -OpParameter *PopulateCropParameter(const mindspore::lite::PrimitiveC *primitive) { - auto param = reinterpret_cast(const_cast(primitive)); - auto param_offset = param->GetOffsets(); - if (param_offset.size() > CROP_OFFSET_MAX_SIZE) { - MS_LOG(ERROR) << "crop_param offset size(" << param_offset.size() << ") should <= " << CROP_OFFSET_MAX_SIZE; - return nullptr; - } - CropParameter *crop_param = reinterpret_cast(malloc(sizeof(CropParameter))); - if (crop_param == nullptr) { - MS_LOG(ERROR) << "malloc CropParameter failed."; - return nullptr; - } - memset(crop_param, 0, sizeof(CropParameter)); - crop_param->op_parameter_.type_ = primitive->Type(); - crop_param->axis_ = param->GetAxis(); - crop_param->offset_size_ = param_offset.size(); - for (size_t i = 0; i < param_offset.size(); ++i) { - crop_param->offset_[i] = param_offset[i]; - } - return reinterpret_cast(crop_param); -} -Registry CropParameterRegistry(schema::PrimitiveType_Crop, PopulateCropParameter); - namespace { constexpr int kCropOutputNum = 1; constexpr int kCropInputNum = 2; diff --git a/mindspore/lite/src/ops/custom_extract_features.cc b/mindspore/lite/src/ops/custom_extract_features.cc index afaaf010e0..82441a1d4e 100644 --- a/mindspore/lite/src/ops/custom_extract_features.cc +++ b/mindspore/lite/src/ops/custom_extract_features.cc @@ -17,7 +17,9 @@ #include "src/common/string_util.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -39,19 +41,6 @@ PrimitiveC *CustomExtractFeaturesCreator(const schema::Primitive *primitive) { Registry CustomExtractFeaturesRegistry(schema::PrimitiveType_CustomExtractFeatures, CustomExtractFeaturesCreator); #endif -OpParameter *PopulateExtractFeaturesParameter(const mindspore::lite::PrimitiveC *primitive) { - OpParameter *param = reinterpret_cast(malloc(sizeof(OpParameter))); - if (param == nullptr) { - MS_LOG(ERROR) << "new OpParameter failed."; - return nullptr; - } - memset(param, 0, sizeof(OpParameter)); - param->type_ = primitive->Type(); - return param; -} -Registry CustomExtractFeaturesParameterRegistry(schema::PrimitiveType_CustomExtractFeatures, - PopulateExtractFeaturesParameter); - int CustomExtractFeatures::InferShape(std::vector inputs_, std::vector outputs_) { auto input = inputs_.at(0); auto output0 = outputs_.at(0); diff --git a/mindspore/lite/src/ops/custom_normalize.cc b/mindspore/lite/src/ops/custom_normalize.cc index 565b90fc14..e9a9f8f3c8 100644 --- a/mindspore/lite/src/ops/custom_normalize.cc +++ b/mindspore/lite/src/ops/custom_normalize.cc @@ -17,7 +17,9 @@ #include "src/common/string_util.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -39,18 +41,6 @@ PrimitiveC *CustomNormalizeCreator(const schema::Primitive *primitive) { Registry CustomNormalizeRegistry(schema::PrimitiveType_CustomNormalize, CustomNormalizeCreator); #endif -OpParameter *PopulateCustomNormalizeParameter(const mindspore::lite::PrimitiveC *primitive) { - OpParameter *param = reinterpret_cast(malloc(sizeof(OpParameter))); - if (param == nullptr) { - MS_LOG(ERROR) << "new OpParameter failed."; - return nullptr; - } - memset(param, 0, sizeof(OpParameter)); - param->type_ = primitive->Type(); - return param; -} -Registry CustomNormalizeParameterRegistry(schema::PrimitiveType_CustomNormalize, PopulateCustomNormalizeParameter); - int CustomNormalize::InferShape(std::vector inputs_, std::vector outputs_) { auto input = inputs_.at(0); auto output = outputs_.at(0); diff --git a/mindspore/lite/src/ops/custom_predict.cc b/mindspore/lite/src/ops/custom_predict.cc index 72625aef38..8504125059 100644 --- a/mindspore/lite/src/ops/custom_predict.cc +++ b/mindspore/lite/src/ops/custom_predict.cc @@ -15,8 +15,9 @@ */ #include "src/ops/custom_predict.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/predict_parameter.h" +#endif namespace mindspore { namespace lite { @@ -54,20 +55,6 @@ PrimitiveC *CustomPredictCreator(const schema::Primitive *primitive) { } Registry CustomPredictRegistry(schema::PrimitiveType_CustomPredict, CustomPredictCreator); #endif -OpParameter *PopulateCustomPredictParameter(const mindspore::lite::PrimitiveC *primitive) { - PredictParameter *param = reinterpret_cast(malloc(sizeof(PredictParameter))); - if (param == nullptr) { - MS_LOG(ERROR) << "malloc param failed."; - return nullptr; - } - memset(param, 0, sizeof(PredictParameter)); - param->op_parameter_.type_ = primitive->Type(); - auto prim = reinterpret_cast(const_cast(primitive)); - param->output_num = prim->GetOutputNum(); - param->weight_threshold = prim->GetWeightThreshold(); - return reinterpret_cast(param); -} -Registry CustomPredictParameterRegistry(schema::PrimitiveType_CustomPredict, PopulateCustomPredictParameter); int CustomPredict::InferShape(std::vector inputs_, std::vector outputs_) { auto input = inputs_.at(0); diff --git a/mindspore/lite/src/ops/deconv2d.cc b/mindspore/lite/src/ops/deconv2d.cc index bc9b39e706..5d3f6fbc9a 100644 --- a/mindspore/lite/src/ops/deconv2d.cc +++ b/mindspore/lite/src/ops/deconv2d.cc @@ -25,8 +25,9 @@ #include "tools/converter/quantizer/quantize_util.h" #endif +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/conv_parameter.h" +#endif namespace mindspore { namespace lite { @@ -304,45 +305,6 @@ PrimitiveC *DeConv2DCreator(const schema::Primitive *primitive) { Registry DeConv2DRegistry(schema::PrimitiveType_DeConv2D, DeConv2DCreator); #endif -OpParameter *PopulateDeconvParameter(const mindspore::lite::PrimitiveC *primitive) { - ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); - if (conv_param == nullptr) { - MS_LOG(ERROR) << "malloc ConvParameter failed."; - return nullptr; - } - memset(conv_param, 0, sizeof(ConvParameter)); - conv_param->op_parameter_.type_ = primitive->Type(); - auto conv_primitive = - reinterpret_cast(const_cast(primitive)); - conv_param->kernel_h_ = conv_primitive->GetKernelH(); - conv_param->kernel_w_ = conv_primitive->GetKernelW(); - conv_param->stride_h_ = conv_primitive->GetStrideH(); - conv_param->stride_w_ = conv_primitive->GetStrideW(); - - auto deconv_lite_primitive = (lite::DeConv2D *)primitive; - conv_param->pad_u_ = deconv_lite_primitive->PadUp(); - conv_param->pad_d_ = deconv_lite_primitive->PadDown(); - conv_param->pad_l_ = deconv_lite_primitive->PadLeft(); - conv_param->pad_r_ = deconv_lite_primitive->PadRight(); - conv_param->dilation_h_ = conv_primitive->GetDilateH(); - conv_param->dilation_w_ = conv_primitive->GetDilateW(); - auto act_type = conv_primitive->GetActivationType(); - switch (act_type) { - case schema::ActivationType_RELU: - conv_param->act_type_ = ActType_Relu; - break; - case schema::ActivationType_RELU6: - conv_param->act_type_ = ActType_Relu6; - break; - default: - conv_param->act_type_ = ActType_No; - break; - } - return reinterpret_cast(conv_param); -} - -Registry DeConv2DParameterRegistry(schema::PrimitiveType_DeConv2D, PopulateDeconvParameter); - int DeConv2D::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/dedepthwise_conv2d.cc b/mindspore/lite/src/ops/dedepthwise_conv2d.cc index 6af0cf523a..0d87449547 100644 --- a/mindspore/lite/src/ops/dedepthwise_conv2d.cc +++ b/mindspore/lite/src/ops/dedepthwise_conv2d.cc @@ -16,8 +16,9 @@ #include "src/ops/dedepthwise_conv2d.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/conv_parameter.h" +#endif namespace mindspore { namespace lite { @@ -118,45 +119,6 @@ PrimitiveC *DeDepthwiseConv2DCreator(const schema::Primitive *primitive) { Registry DeDepthwiseConv2DRegistry(schema::PrimitiveType_DeDepthwiseConv2D, DeDepthwiseConv2DCreator); #endif -OpParameter *PopulateDeconvDwParameter(const mindspore::lite::PrimitiveC *primitive) { - ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); - if (conv_param == nullptr) { - MS_LOG(ERROR) << "malloc ConvParameter failed."; - return nullptr; - } - memset(conv_param, 0, sizeof(ConvParameter)); - conv_param->op_parameter_.type_ = primitive->Type(); - auto conv_primitive = - reinterpret_cast(const_cast(primitive)); - conv_param->kernel_h_ = conv_primitive->GetKernelH(); - conv_param->kernel_w_ = conv_primitive->GetKernelW(); - conv_param->stride_h_ = conv_primitive->GetStrideH(); - conv_param->stride_w_ = conv_primitive->GetStrideW(); - - auto deconvdw_lite_primitive = (mindspore::lite::DeDepthwiseConv2D *)primitive; - conv_param->pad_u_ = deconvdw_lite_primitive->PadUp(); - conv_param->pad_d_ = deconvdw_lite_primitive->PadDown(); - conv_param->pad_l_ = deconvdw_lite_primitive->PadLeft(); - conv_param->pad_r_ = deconvdw_lite_primitive->PadRight(); - conv_param->dilation_h_ = conv_primitive->GetDilateH(); - conv_param->dilation_w_ = conv_primitive->GetDilateW(); - auto act_type = conv_primitive->GetActivationType(); - switch (act_type) { - case schema::ActivationType_RELU: - conv_param->act_type_ = ActType_Relu; - break; - case schema::ActivationType_RELU6: - conv_param->act_type_ = ActType_Relu6; - break; - default: - conv_param->act_type_ = ActType_No; - break; - } - return reinterpret_cast(conv_param); -} - -Registry DeDepthwiseConv2DParameterRegistry(schema::PrimitiveType_DeDepthwiseConv2D, PopulateDeconvDwParameter); - int DeDepthwiseConv2D::InferShape(std::vector inputs_, std::vector outputs_) { if (inputs_.size() != kDoubleNum && inputs_.size() != kMultiNum) { MS_LOG(ERROR) << "inputs number is invalid"; diff --git a/mindspore/lite/src/ops/depend.cc b/mindspore/lite/src/ops/depend.cc index 20313a9b85..f1a4139e4f 100644 --- a/mindspore/lite/src/ops/depend.cc +++ b/mindspore/lite/src/ops/depend.cc @@ -17,7 +17,9 @@ #include #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/depth_to_space.cc b/mindspore/lite/src/ops/depth_to_space.cc index e2ab49cc6b..9d35b2ea5f 100644 --- a/mindspore/lite/src/ops/depth_to_space.cc +++ b/mindspore/lite/src/ops/depth_to_space.cc @@ -16,8 +16,9 @@ #include "src/ops/depth_to_space.h" #include "src/common/common.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/depth_to_space_parameter.h" +#endif namespace mindspore { namespace lite { @@ -52,22 +53,6 @@ Registry DepthToSpaceRegistry(schema::PrimitiveType_DepthToSpace, DepthToSpaceCr #endif -OpParameter *PopulateDepthToSpaceParameter(const mindspore::lite::PrimitiveC *primitive) { - DepthToSpaceParameter *depth_space_param = - reinterpret_cast(malloc(sizeof(DepthToSpaceParameter))); - if (depth_space_param == nullptr) { - MS_LOG(ERROR) << "malloc DepthToSpaceParameter failed."; - return nullptr; - } - memset(depth_space_param, 0, sizeof(DepthToSpaceParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - depth_space_param->op_parameter_.type_ = primitive->Type(); - depth_space_param->block_size_ = param->GetBlockSize(); - return reinterpret_cast(depth_space_param); -} - -Registry DepthToSpaceParameterRegistry(schema::PrimitiveType_DepthToSpace, PopulateDepthToSpaceParameter); - namespace { constexpr int kDepthToSpaceOutputNum = 1; constexpr int kDepthToSpaceInputNum = 1; diff --git a/mindspore/lite/src/ops/depthwise_conv2d.cc b/mindspore/lite/src/ops/depthwise_conv2d.cc index cd6b8eca9a..f7bb3222dd 100644 --- a/mindspore/lite/src/ops/depthwise_conv2d.cc +++ b/mindspore/lite/src/ops/depthwise_conv2d.cc @@ -21,8 +21,9 @@ #ifdef PRIMITIVE_WRITEABLE #include "tools/converter/quantizer/quantize_util.h" #endif +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/conv_parameter.h" +#endif namespace mindspore { namespace lite { @@ -201,47 +202,6 @@ Registry DepthWiseConv2DRegistry(schema::PrimitiveType_DepthwiseConv2D, DepthWis #endif -OpParameter *PopulateConvDwParameter(const mindspore::lite::PrimitiveC *primitive) { - ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); - if (conv_param == nullptr) { - MS_LOG(ERROR) << "malloc ConvParameter failed."; - return nullptr; - } - memset(conv_param, 0, sizeof(ConvParameter)); - conv_param->op_parameter_.type_ = primitive->Type(); - - auto conv_primitive = - reinterpret_cast(const_cast(primitive)); - conv_param->kernel_h_ = conv_primitive->GetKernelH(); - conv_param->kernel_w_ = conv_primitive->GetKernelW(); - conv_param->stride_h_ = conv_primitive->GetStrideH(); - conv_param->stride_w_ = conv_primitive->GetStrideW(); - - auto convdw_lite_primitive = (lite::DepthwiseConv2D *)primitive; - conv_param->pad_u_ = convdw_lite_primitive->PadUp(); - conv_param->pad_d_ = convdw_lite_primitive->PadDown(); - conv_param->pad_l_ = convdw_lite_primitive->PadLeft(); - conv_param->pad_r_ = convdw_lite_primitive->PadRight(); - conv_param->input_channel_ = convdw_lite_primitive->GetInputChannel(); - conv_param->dilation_h_ = conv_primitive->GetDilateH(); - conv_param->dilation_w_ = conv_primitive->GetDilateW(); - auto act_type = conv_primitive->GetActivationType(); - switch (act_type) { - case schema::ActivationType_RELU: - conv_param->act_type_ = ActType_Relu; - break; - case schema::ActivationType_RELU6: - conv_param->act_type_ = ActType_Relu6; - break; - default: - conv_param->act_type_ = ActType_No; - break; - } - return reinterpret_cast(conv_param); -} - -Registry DepthwiseConv2DParameterRegistry(schema::PrimitiveType_DepthwiseConv2D, PopulateConvDwParameter); - int DepthwiseConv2D::InferShape(std::vector inputs_, std::vector outputs_) { if (inputs_.size() != kDoubleNum && inputs_.size() != kMultiNum) { MS_LOG(ERROR) << "inputs number is invalid"; diff --git a/mindspore/lite/src/ops/detection_post_process.cc b/mindspore/lite/src/ops/detection_post_process.cc index eed4fb9b66..2233813d67 100644 --- a/mindspore/lite/src/ops/detection_post_process.cc +++ b/mindspore/lite/src/ops/detection_post_process.cc @@ -16,8 +16,9 @@ #include "src/ops/detection_post_process.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/detection_post_process_parameter.h" +#endif namespace mindspore { namespace lite { @@ -147,33 +148,6 @@ PrimitiveC *DetectionPostProcessCreator(const schema::Primitive *primitive) { } Registry DetectionPostProcessRegistry(schema::PrimitiveType_DetectionPostProcess, DetectionPostProcessCreator); #endif -OpParameter *PopulateDetectionPostProcessParameter(const mindspore::lite::PrimitiveC *primitive) { - DetectionPostProcessParameter *detection_post_process_parameter = - reinterpret_cast(malloc(sizeof(DetectionPostProcessParameter))); - if (detection_post_process_parameter == nullptr) { - MS_LOG(ERROR) << "malloc EluParameter failed."; - return nullptr; - } - memset(detection_post_process_parameter, 0, sizeof(DetectionPostProcessParameter)); - detection_post_process_parameter->op_parameter_.type_ = primitive->Type(); - auto param = - reinterpret_cast(const_cast(primitive)); - detection_post_process_parameter->h_scale_ = param->GetHScale(); - detection_post_process_parameter->w_scale_ = param->GetWScale(); - detection_post_process_parameter->x_scale_ = param->GetXScale(); - detection_post_process_parameter->y_scale_ = param->GetYScale(); - detection_post_process_parameter->nms_iou_threshold_ = param->GetNmsIouThreshold(); - detection_post_process_parameter->nms_score_threshold_ = param->GetNmsScoreThreshold(); - detection_post_process_parameter->max_detections_ = param->GetMaxDetections(); - detection_post_process_parameter->detections_per_class_ = param->GetDetectionsPerClass(); - detection_post_process_parameter->max_classes_per_detection_ = param->GetMaxClassesPerDetection(); - detection_post_process_parameter->num_classes_ = param->GetNumClasses(); - detection_post_process_parameter->use_regular_nms_ = param->GetUseRegularNms(); - return reinterpret_cast(detection_post_process_parameter); -} -Registry DetectionPostProcessParameterRegistry(schema::PrimitiveType_DetectionPostProcess, - PopulateDetectionPostProcessParameter); - namespace { constexpr int kDetectionPostProcessOutputNum = 4; constexpr int kDetectionPostProcessInputNum = 3; diff --git a/mindspore/lite/src/ops/div.cc b/mindspore/lite/src/ops/div.cc index a9ce630bb2..bb5a2f9034 100644 --- a/mindspore/lite/src/ops/div.cc +++ b/mindspore/lite/src/ops/div.cc @@ -16,7 +16,9 @@ #include "src/ops/div.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -46,27 +48,6 @@ int Div::GetActivationType() const { return this->primitive_->value_as_Div()->ac PrimitiveC *DivCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC
(primitive); } Registry DivRegistry(schema::PrimitiveType_Div, DivCreator); #endif -OpParameter *PopulateDivParameter(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); - if (arithmetic_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; - return nullptr; - } - memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); - arithmetic_param->op_parameter_.type_ = primitive->Type(); - arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); - arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); - arithmetic_param->activation_type_ = - reinterpret_cast(const_cast(primitive))->GetActivationType(); - auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); - memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); - memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); - memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - return reinterpret_cast(arithmetic_param); -} -Registry DivParameterRegistry(schema::PrimitiveType_Div, PopulateDivParameter); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/dropout.cc b/mindspore/lite/src/ops/dropout.cc index 94451e4bb1..4470f55e9b 100644 --- a/mindspore/lite/src/ops/dropout.cc +++ b/mindspore/lite/src/ops/dropout.cc @@ -16,7 +16,9 @@ #include "src/ops/dropout.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/eltwise.cc b/mindspore/lite/src/ops/eltwise.cc index 2598514af7..0bec8276c4 100644 --- a/mindspore/lite/src/ops/eltwise.cc +++ b/mindspore/lite/src/ops/eltwise.cc @@ -16,8 +16,9 @@ #include "src/ops/eltwise.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/arithmetic_common.h" +#endif namespace mindspore { namespace lite { @@ -46,31 +47,5 @@ PrimitiveC *EltwiseCreator(const schema::Primitive *primitive) { return Primitiv Registry EltwiseRegistry(schema::PrimitiveType_Eltwise, EltwiseCreator); #endif -OpParameter *PopulateEltwiseParameter(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); - if (arithmetic_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; - return nullptr; - } - memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); - auto eltwise = reinterpret_cast(const_cast(primitive)); - switch (eltwise->GetMode()) { - case schema::EltwiseMode_PROD: - arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Mul; - break; - case schema::EltwiseMode_SUM: - arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Add; - break; - case schema::EltwiseMode_MAXIMUM: - arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Maximum; - break; - default: - free(arithmetic_param); - return nullptr; - } - return reinterpret_cast(arithmetic_param); -} -Registry EltwiseParameterRegistry(schema::PrimitiveType_Eltwise, PopulateEltwiseParameter); - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/elu.cc b/mindspore/lite/src/ops/elu.cc index d68a22e5ed..506f9f381f 100644 --- a/mindspore/lite/src/ops/elu.cc +++ b/mindspore/lite/src/ops/elu.cc @@ -16,8 +16,10 @@ #include "src/ops/elu.h" #include -#include "nnacl/fp32/elu.h" + +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -67,18 +69,5 @@ PrimitiveC *EluCreator(const schema::Primitive *primitive) { return PrimitiveC:: Registry EluRegistry(schema::PrimitiveType_Elu, EluCreator); #endif -OpParameter *PopulateEluParameter(const mindspore::lite::PrimitiveC *primitive) { - EluParameter *elu_parameter = reinterpret_cast(malloc(sizeof(EluParameter))); - if (elu_parameter == nullptr) { - MS_LOG(ERROR) << "malloc EluParameter failed."; - return nullptr; - } - memset(elu_parameter, 0, sizeof(EluParameter)); - elu_parameter->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - elu_parameter->alpha_ = param->GetAlpha(); - return reinterpret_cast(elu_parameter); -} -Registry EluParameterRegistry(schema::PrimitiveType_Elu, PopulateEluParameter); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/embedding_lookup.cc b/mindspore/lite/src/ops/embedding_lookup.cc index e028f130d9..97958a89b3 100644 --- a/mindspore/lite/src/ops/embedding_lookup.cc +++ b/mindspore/lite/src/ops/embedding_lookup.cc @@ -16,8 +16,9 @@ #include "src/ops/embedding_lookup.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/embedding_lookup.h" +#endif namespace mindspore { namespace lite { @@ -50,29 +51,6 @@ PrimitiveC *EmbeddingLookupCreator(const schema::Primitive *primitive) { Registry EmbeddingLookupRegistry(schema::PrimitiveType_EmbeddingLookup, EmbeddingLookupCreator); #endif -OpParameter *PopulateEmbeddingLookupParameter(const mindspore::lite::PrimitiveC *primitive) { - EmbeddingLookupParameter *embedding_lookup_parameter = - reinterpret_cast(malloc(sizeof(EmbeddingLookupParameter))); - if (embedding_lookup_parameter == nullptr) { - MS_LOG(ERROR) << "malloc EmbeddingLookupParameter failed."; - return nullptr; - } - memset(embedding_lookup_parameter, 0, sizeof(EmbeddingLookupParameter)); - embedding_lookup_parameter->op_parameter_.type_ = primitive->Type(); - auto param = - reinterpret_cast(const_cast(primitive)); - embedding_lookup_parameter->max_norm_ = param->GetMaxNorm(); - if (embedding_lookup_parameter->max_norm_ < 0) { - MS_LOG(ERROR) << "Embedding lookup max norm should be positive number, got " - << embedding_lookup_parameter->max_norm_; - free(embedding_lookup_parameter); - return nullptr; - } - return reinterpret_cast(embedding_lookup_parameter); -} - -Registry EmbeddingLookupParameterRegistry(schema::PrimitiveType_EmbeddingLookup, PopulateEmbeddingLookupParameter); - int EmbeddingLookup::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); if (inputs_.size() < kDoubleNum) { diff --git a/mindspore/lite/src/ops/embedding_lookup_sparse.cc b/mindspore/lite/src/ops/embedding_lookup_sparse.cc index 5dd0c55d6c..54d2cacad9 100644 --- a/mindspore/lite/src/ops/embedding_lookup_sparse.cc +++ b/mindspore/lite/src/ops/embedding_lookup_sparse.cc @@ -16,7 +16,9 @@ #include "src/ops/embedding_lookup_sparse.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/equal.cc b/mindspore/lite/src/ops/equal.cc index 4db93bd4bd..2b4e3aa62d 100644 --- a/mindspore/lite/src/ops/equal.cc +++ b/mindspore/lite/src/ops/equal.cc @@ -16,7 +16,9 @@ #include "src/ops/equal.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -43,6 +45,6 @@ int Equal::InferShape(std::vector inputs_, std::vector outpu output->SetFormat(input->GetFormat()); return RET_OK; } -Registry EqualParameterRegistry(schema::PrimitiveType_Equal, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/exp.cc b/mindspore/lite/src/ops/exp.cc index 967d7775d8..e51a67f05e 100644 --- a/mindspore/lite/src/ops/exp.cc +++ b/mindspore/lite/src/ops/exp.cc @@ -16,7 +16,9 @@ #include "src/ops/exp.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif #include "src/ops/arithmetic_self.h" namespace mindspore { @@ -77,7 +79,6 @@ float Exp::GetShift() const { return this->primitive_->value_as_Exp()->shift(); PrimitiveC *ExpCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry ExpRegistry(schema::PrimitiveType_Exp, ExpCreator); #endif -Registry ExpParameterRegistry(schema::PrimitiveType_Exp, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/expand_dims.cc b/mindspore/lite/src/ops/expand_dims.cc index a57ec68c4a..01e8d5c66f 100644 --- a/mindspore/lite/src/ops/expand_dims.cc +++ b/mindspore/lite/src/ops/expand_dims.cc @@ -16,8 +16,9 @@ #include "src/ops/expand_dims.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/expandDims.h" +#endif namespace mindspore { namespace lite { @@ -49,21 +50,6 @@ PrimitiveC *ExpandDimsCreator(const schema::Primitive *primitive) { Registry ExpandDimsRegistry(schema::PrimitiveType_ExpandDims, ExpandDimsCreator); #endif -OpParameter *PopulateExpandDimsParameter(const mindspore::lite::PrimitiveC *primitive) { - auto param = reinterpret_cast(const_cast(primitive)); - ExpandDimsParameter *expand_dims_param = reinterpret_cast(malloc(sizeof(ExpandDimsParameter))); - if (expand_dims_param == nullptr) { - MS_LOG(ERROR) << "malloc ExpandDimsParameter failed."; - return nullptr; - } - memset(expand_dims_param, 0, sizeof(ExpandDimsParameter)); - expand_dims_param->op_parameter_.type_ = primitive->Type(); - expand_dims_param->dim_ = param->GetDim(); - return reinterpret_cast(expand_dims_param); -} - -Registry ExpandDimsParameterRegistry(schema::PrimitiveType_ExpandDims, PopulateExpandDimsParameter); - int ExpandDims::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/fake_quant_with_min_max_vars.cc b/mindspore/lite/src/ops/fake_quant_with_min_max_vars.cc index dfa565eeb0..0f09dc4de2 100644 --- a/mindspore/lite/src/ops/fake_quant_with_min_max_vars.cc +++ b/mindspore/lite/src/ops/fake_quant_with_min_max_vars.cc @@ -16,7 +16,9 @@ #include "src/ops/fake_quant_with_min_max_vars.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/fill.cc b/mindspore/lite/src/ops/fill.cc index e8a2d68432..40196fa909 100644 --- a/mindspore/lite/src/ops/fill.cc +++ b/mindspore/lite/src/ops/fill.cc @@ -16,8 +16,9 @@ #include "src/ops/fill.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/fill.h" +#endif namespace mindspore { namespace lite { @@ -55,26 +56,6 @@ PrimitiveC *FillCreator(const schema::Primitive *primitive) { return PrimitiveC: Registry FillRegistry(schema::PrimitiveType_Fill, FillCreator); #endif -OpParameter *PopulateFillParameter(const mindspore::lite::PrimitiveC *primitive) { - const auto param = reinterpret_cast(const_cast(primitive)); - FillParameter *fill_param = reinterpret_cast(malloc(sizeof(FillParameter))); - if (fill_param == nullptr) { - MS_LOG(ERROR) << "malloc FillParameter failed."; - return nullptr; - } - memset(fill_param, 0, sizeof(FillParameter)); - fill_param->op_parameter_.type_ = primitive->Type(); - auto flatDims = param->GetDims(); - fill_param->num_dims_ = flatDims.size(); - int i = 0; - for (auto iter = flatDims.begin(); iter != flatDims.end(); iter++) { - fill_param->dims_[i++] = *iter; - } - return reinterpret_cast(fill_param); -} - -Registry FillParameterRegistry(schema::PrimitiveType_Fill, PopulateFillParameter); - int Fill::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/flatten.cc b/mindspore/lite/src/ops/flatten.cc index 65b523b652..c37a5d7ed5 100644 --- a/mindspore/lite/src/ops/flatten.cc +++ b/mindspore/lite/src/ops/flatten.cc @@ -17,8 +17,9 @@ #include "src/ops/flatten.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/flatten.h" +#endif namespace mindspore { namespace lite { @@ -93,18 +94,5 @@ PrimitiveC *FlattenCreator(const schema::Primitive *primitive) { return Primitiv Registry FlattenRegistry(schema::PrimitiveType_Flatten, FlattenCreator); #endif -OpParameter *PopulateFlattenParameter(const mindspore::lite::PrimitiveC *primitive) { - FlattenParameter *flatten_param = reinterpret_cast(malloc(sizeof(FlattenParameter))); - if (flatten_param == nullptr) { - MS_LOG(ERROR) << "malloc FlattenParameter failed."; - return nullptr; - } - memset(flatten_param, 0, sizeof(FlattenParameter)); - flatten_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(flatten_param); -} - -Registry FlattenParameterRegistry(schema::PrimitiveType_Flatten, PopulateFlattenParameter); - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/flatten_grad.cc b/mindspore/lite/src/ops/flatten_grad.cc index f80af5c78c..44bced4370 100644 --- a/mindspore/lite/src/ops/flatten_grad.cc +++ b/mindspore/lite/src/ops/flatten_grad.cc @@ -17,7 +17,9 @@ #include "src/ops/flatten_grad.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/floor.cc b/mindspore/lite/src/ops/floor.cc index 1f544f2513..12148c0883 100644 --- a/mindspore/lite/src/ops/floor.cc +++ b/mindspore/lite/src/ops/floor.cc @@ -16,7 +16,9 @@ #include "src/ops/floor.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -33,7 +35,6 @@ int Floor::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers:: PrimitiveC *FloorCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry FloorRegistry(schema::PrimitiveType_Floor, FloorCreator); #endif -Registry FloorParameterRegistry(schema::PrimitiveType_Floor, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/floor_div.cc b/mindspore/lite/src/ops/floor_div.cc index ee737a7e59..58c61ebf3d 100644 --- a/mindspore/lite/src/ops/floor_div.cc +++ b/mindspore/lite/src/ops/floor_div.cc @@ -16,7 +16,9 @@ #include "src/ops/floor_div.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -36,6 +38,6 @@ PrimitiveC *FloorDivCreator(const schema::Primitive *primitive) { } Registry FloorDivRegistry(schema::PrimitiveType_FloorDiv, FloorDivCreator); #endif -Registry FloorDivParameterRegistry(schema::PrimitiveType_FloorDiv, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/floor_mod.cc b/mindspore/lite/src/ops/floor_mod.cc index d633f364d8..d84de0d21d 100644 --- a/mindspore/lite/src/ops/floor_mod.cc +++ b/mindspore/lite/src/ops/floor_mod.cc @@ -16,7 +16,9 @@ #include "src/ops/floor_mod.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -35,6 +37,6 @@ PrimitiveC *FloorModCreator(const schema::Primitive *primitive) { } Registry FloorModRegistry(schema::PrimitiveType_FloorMod, FloorModCreator); #endif -Registry FloorModParameterRegistry(schema::PrimitiveType_FloorMod, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/full_connection.cc b/mindspore/lite/src/ops/full_connection.cc index ad045f4f28..5958742493 100644 --- a/mindspore/lite/src/ops/full_connection.cc +++ b/mindspore/lite/src/ops/full_connection.cc @@ -16,8 +16,9 @@ #include "src/ops/full_connection.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/matmul_parameter.h" +#endif namespace mindspore { namespace lite { @@ -60,32 +61,6 @@ PrimitiveC *FullConnectionCreator(const schema::Primitive *primitive) { Registry FullConnectionRegistry(schema::PrimitiveType_FullConnection, FullConnectionCreator); #endif -OpParameter *PopulateFullconnectionParameter(const mindspore::lite::PrimitiveC *primitive) { - auto param = - reinterpret_cast(const_cast(primitive)); - MatMulParameter *matmul_param = reinterpret_cast(malloc(sizeof(MatMulParameter))); - if (matmul_param == nullptr) { - MS_LOG(ERROR) << "malloc MatMulParameter failed."; - return nullptr; - } - memset(matmul_param, 0, sizeof(MatMulParameter)); - matmul_param->op_parameter_.type_ = primitive->Type(); - matmul_param->b_transpose_ = true; - matmul_param->a_transpose_ = false; - matmul_param->has_bias_ = param->GetHasBias(); - if (param->GetActivationType() == schema::ActivationType_RELU) { - matmul_param->act_type_ = ActType_Relu; - } else if (param->GetActivationType() == schema::ActivationType_RELU6) { - matmul_param->act_type_ = ActType_Relu6; - } else { - matmul_param->act_type_ = ActType_No; - } - - return reinterpret_cast(matmul_param); -} - -Registry FullConnectionParameterRegistry(schema::PrimitiveType_FullConnection, PopulateFullconnectionParameter); - int FullConnection::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input0 = inputs_.front(); diff --git a/mindspore/lite/src/ops/fused_batchnorm.cc b/mindspore/lite/src/ops/fused_batchnorm.cc index 94a3e97e5f..11054cfd6d 100644 --- a/mindspore/lite/src/ops/fused_batchnorm.cc +++ b/mindspore/lite/src/ops/fused_batchnorm.cc @@ -16,8 +16,9 @@ #include "src/ops/fused_batchnorm.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/batchnorm_parameter.h" +#endif namespace mindspore { namespace lite { @@ -80,23 +81,6 @@ PrimitiveC *FusedBatchNormCreator(const schema::Primitive *primitive) { } Registry FusedBatchNormRegistry(schema::PrimitiveType_FusedBatchNorm, FusedBatchNormCreator); #endif -OpParameter *PopulateFusedBatchNorm(const mindspore::lite::PrimitiveC *primitive) { - BatchNormParameter *batch_norm_param = reinterpret_cast(malloc(sizeof(BatchNormParameter))); - if (batch_norm_param == nullptr) { - MS_LOG(ERROR) << "malloc BatchNormParameter failed."; - return nullptr; - } - memset(batch_norm_param, 0, sizeof(BatchNormParameter)); - batch_norm_param->op_parameter_.type_ = primitive->Type(); - auto param = - reinterpret_cast(const_cast(primitive)); - batch_norm_param->epsilon_ = param->GetEpsilon(); - batch_norm_param->momentum_ = param->GetMomentum(); - batch_norm_param->fused_ = true; - return reinterpret_cast(batch_norm_param); -} - -Registry FusedBatchNormParameterRegistry(schema::PrimitiveType_FusedBatchNorm, PopulateFusedBatchNorm); int FusedBatchNorm::InferShape(std::vector inputs_, std::vector outputs_) { for (size_t i = 0; i < inputs_.size(); i++) { diff --git a/mindspore/lite/src/ops/gather.cc b/mindspore/lite/src/ops/gather.cc index 56cda0a19f..bd18ecc21b 100644 --- a/mindspore/lite/src/ops/gather.cc +++ b/mindspore/lite/src/ops/gather.cc @@ -19,8 +19,9 @@ #include "src/common/log_adapter.h" #include "src/tensor.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/gather_parameter.h" +#endif namespace mindspore { namespace lite { @@ -53,21 +54,6 @@ PrimitiveC *GatherCreator(const schema::Primitive *primitive) { return Primitive Registry GatherRegistry(schema::PrimitiveType_Gather, GatherCreator); #endif -OpParameter *PopulateGatherParameter(const mindspore::lite::PrimitiveC *primitive) { - auto gather_attr = reinterpret_cast(const_cast(primitive)); - GatherParameter *gather_param = reinterpret_cast(malloc(sizeof(GatherParameter))); - if (gather_param == nullptr) { - MS_LOG(ERROR) << "malloc GatherParameter failed."; - return nullptr; - } - memset(gather_param, 0, sizeof(GatherParameter)); - gather_param->op_parameter_.type_ = primitive->Type(); - gather_param->axis_ = gather_attr->GetAxis(); - gather_param->batchDims_ = gather_attr->GetBatchDims(); - return reinterpret_cast(gather_param); -} -Registry GatherParameterRegistry(schema::PrimitiveType_Gather, PopulateGatherParameter); - int Gather::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); if (inputs_.size() != kDoubleNum) { diff --git a/mindspore/lite/src/ops/gather_nd.cc b/mindspore/lite/src/ops/gather_nd.cc index ae3376f7ca..b0d7e4c621 100644 --- a/mindspore/lite/src/ops/gather_nd.cc +++ b/mindspore/lite/src/ops/gather_nd.cc @@ -16,8 +16,9 @@ #include "src/ops/gather_nd.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/gatherNd.h" +#endif namespace mindspore { namespace lite { @@ -49,22 +50,6 @@ PrimitiveC *GatherNdCreator(const schema::Primitive *primitive) { Registry GatherNdRegistry(schema::PrimitiveType_GatherNd, GatherNdCreator); #endif -OpParameter *PopulateGatherNdParameter(const mindspore::lite::PrimitiveC *primitive) { - GatherNdParameter *gather_nd_param = reinterpret_cast(malloc(sizeof(GatherNdParameter))); - if (gather_nd_param == nullptr) { - MS_LOG(ERROR) << "malloc GatherNdParameter failed."; - return nullptr; - } - memset(gather_nd_param, 0, sizeof(GatherNdParameter)); - gather_nd_param->op_parameter_.type_ = primitive->Type(); - auto gatherNd_attr = - reinterpret_cast(const_cast(primitive)); - gather_nd_param->batchDims_ = gatherNd_attr->GetBatchDims(); - return reinterpret_cast(gather_nd_param); -} - -Registry GatherNdParameterRegistry(schema::PrimitiveType_GatherNd, PopulateGatherNdParameter); - int GatherNd::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); if (inputs_.size() != kDoubleNum) { diff --git a/mindspore/lite/src/ops/greater.cc b/mindspore/lite/src/ops/greater.cc index 72828eacd8..b30da60029 100644 --- a/mindspore/lite/src/ops/greater.cc +++ b/mindspore/lite/src/ops/greater.cc @@ -16,7 +16,9 @@ #include "src/ops/greater.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -44,6 +46,6 @@ int Greater::InferShape(std::vector inputs_, std::vector out output->SetFormat(input->GetFormat()); return RET_OK; } -Registry GreaterParameterRegistry(schema::PrimitiveType_Greater, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/greater_equal.cc b/mindspore/lite/src/ops/greater_equal.cc index 203e8969f5..cf83423f55 100644 --- a/mindspore/lite/src/ops/greater_equal.cc +++ b/mindspore/lite/src/ops/greater_equal.cc @@ -16,7 +16,9 @@ #include "src/ops/greater_equal.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -46,6 +48,6 @@ int GreaterEqual::InferShape(std::vector inputs_, std::vectorSetFormat(input->GetFormat()); return RET_OK; } -Registry GreaterEqualParameterRegistry(schema::PrimitiveType_GreaterEqual, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/group_conv2d_grad_input.cc b/mindspore/lite/src/ops/group_conv2d_grad_input.cc index 47f0a14ecd..dfcfd7466c 100644 --- a/mindspore/lite/src/ops/group_conv2d_grad_input.cc +++ b/mindspore/lite/src/ops/group_conv2d_grad_input.cc @@ -16,7 +16,9 @@ #include "src/ops/group_conv2d_grad_input.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/hashtable_lookup.cc b/mindspore/lite/src/ops/hashtable_lookup.cc index 48a107c055..cba417ad12 100644 --- a/mindspore/lite/src/ops/hashtable_lookup.cc +++ b/mindspore/lite/src/ops/hashtable_lookup.cc @@ -17,7 +17,9 @@ #include "src/common/string_util.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -38,18 +40,6 @@ PrimitiveC *HashtableLookupCreator(const schema::Primitive *primitive) { Registry HashtableLookupRegistry(schema::PrimitiveType_HashtableLookup, HashtableLookupCreator); #endif -OpParameter *PopulateHashtableLookupParameter(const mindspore::lite::PrimitiveC *primitive) { - OpParameter *param = reinterpret_cast(malloc(sizeof(OpParameter))); - if (param == nullptr) { - MS_LOG(ERROR) << "new OpParameter failed."; - return nullptr; - } - memset(param, 0, sizeof(OpParameter)); - param->type_ = primitive->Type(); - return param; -} -Registry HashtableLookupParameterRegistry(schema::PrimitiveType_HashtableLookup, PopulateHashtableLookupParameter); - int HashtableLookup::InferShape(std::vector inputs_, std::vector outputs_) { auto input = inputs_.at(0); auto values = inputs_.at(2); diff --git a/mindspore/lite/src/ops/l2_norm.cc b/mindspore/lite/src/ops/l2_norm.cc index 030e55e061..3edaec93e6 100644 --- a/mindspore/lite/src/ops/l2_norm.cc +++ b/mindspore/lite/src/ops/l2_norm.cc @@ -16,8 +16,9 @@ #include "src/ops/l2_norm.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/l2_norm_parameter.h" +#endif namespace mindspore { namespace lite { @@ -63,41 +64,6 @@ int L2Norm::GetActivationType() const { return this->primitive_->value_as_L2Norm PrimitiveC *L2NormCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry L2NormRegistry(schema::PrimitiveType_L2Norm, L2NormCreator); #endif -OpParameter *PopulateL2NormParameter(const mindspore::lite::PrimitiveC *primitive) { - L2NormParameter *l2_norm_parameter = reinterpret_cast(malloc(sizeof(L2NormParameter))); - if (l2_norm_parameter == nullptr) { - MS_LOG(ERROR) << "malloc L2NormParameter failed."; - return nullptr; - } - memset(l2_norm_parameter, 0, sizeof(L2NormParameter)); - l2_norm_parameter->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - auto axis_vec = param->GetAxis(); - l2_norm_parameter->axis_num_ = axis_vec.size(); - l2_norm_parameter->axis_ = reinterpret_cast(malloc(axis_vec.size() * sizeof(int))); - if (l2_norm_parameter->axis_ == nullptr) { - MS_LOG(ERROR) << "malloc axis_ data failed"; - free(l2_norm_parameter); - return nullptr; - } - for (size_t i = 0; i < axis_vec.size(); i++) { - l2_norm_parameter->axis_[i] = axis_vec[i]; - } - if (param->GetEpsilon() < 1e-6) { - l2_norm_parameter->epsilon_ = 1e-6; - } else { - l2_norm_parameter->epsilon_ = param->GetEpsilon(); - } - if (param->GetActivationType() == static_cast(schema::ActivationType_RELU)) { - l2_norm_parameter->act_type_ = ActType_Relu; - } else if (param->GetActivationType() == static_cast(schema::ActivationType_RELU6)) { - l2_norm_parameter->act_type_ = ActType_Relu6; - } else { - l2_norm_parameter->act_type_ = ActType_No; - } - return reinterpret_cast(l2_norm_parameter); -} -Registry L2NormParameterRegistry(schema::PrimitiveType_L2Norm, PopulateL2NormParameter); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/leaky_relu.cc b/mindspore/lite/src/ops/leaky_relu.cc index dfc7069093..e39858c8e1 100644 --- a/mindspore/lite/src/ops/leaky_relu.cc +++ b/mindspore/lite/src/ops/leaky_relu.cc @@ -16,7 +16,9 @@ #include "src/ops/leaky_relu.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/less.cc b/mindspore/lite/src/ops/less.cc index a6c87ecbf8..84ca9f3aa0 100644 --- a/mindspore/lite/src/ops/less.cc +++ b/mindspore/lite/src/ops/less.cc @@ -16,7 +16,9 @@ #include "src/ops/less.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -46,6 +48,6 @@ int Less::InferShape(std::vector inputs_, std::vector output output->SetFormat(input->GetFormat()); return RET_OK; } -Registry LessParameterRegistry(schema::PrimitiveType_Less, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/less_equal.cc b/mindspore/lite/src/ops/less_equal.cc index ec5df2c1db..22163f5aef 100644 --- a/mindspore/lite/src/ops/less_equal.cc +++ b/mindspore/lite/src/ops/less_equal.cc @@ -16,7 +16,9 @@ #include "src/ops/less_equal.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -45,6 +47,6 @@ int LessEqual::InferShape(std::vector inputs_, std::vector o output->SetFormat(input->GetFormat()); return RET_OK; } -Registry LessEqualParameterRegistry(schema::PrimitiveType_LessEqual, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/local_response_normalization.cc b/mindspore/lite/src/ops/local_response_normalization.cc index 92e9231eb8..d3df71d4a6 100644 --- a/mindspore/lite/src/ops/local_response_normalization.cc +++ b/mindspore/lite/src/ops/local_response_normalization.cc @@ -16,8 +16,9 @@ #include "src/ops/local_response_normalization.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/local_response_norm.h" +#endif namespace mindspore { namespace lite { @@ -86,27 +87,5 @@ Registry LocalResponseNormalizationRegistry(schema::PrimitiveType_LocalResponseN LocalResponseNormalizationCreator); #endif - -OpParameter *PopulateLocalResponseNormParameter(const mindspore::lite::PrimitiveC *primitive) { - auto local_response_norm_attr = reinterpret_cast( - const_cast(primitive)); - LocalResponseNormParameter *lrn_param = - reinterpret_cast(malloc(sizeof(LocalResponseNormParameter))); - if (lrn_param == nullptr) { - MS_LOG(ERROR) << "malloc LocalResponseNormParameter failed."; - return nullptr; - } - memset(lrn_param, 0, sizeof(LocalResponseNormParameter)); - lrn_param->op_parameter_.type_ = primitive->Type(); - lrn_param->depth_radius_ = local_response_norm_attr->GetDepthRadius(); - lrn_param->bias_ = local_response_norm_attr->GetBias(); - lrn_param->alpha_ = local_response_norm_attr->GetAlpha(); - lrn_param->beta_ = local_response_norm_attr->GetBeta(); - return reinterpret_cast(lrn_param); -} - -Registry LocalResponseNormalizationParameterRegistry(schema::PrimitiveType_LocalResponseNormalization, - PopulateLocalResponseNormParameter); - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/log.cc b/mindspore/lite/src/ops/log.cc index 6835c6d19a..73b57e2a25 100644 --- a/mindspore/lite/src/ops/log.cc +++ b/mindspore/lite/src/ops/log.cc @@ -17,7 +17,9 @@ #include "src/ops/log.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -56,7 +58,6 @@ PrimitiveC *LogCreator(const schema::Primitive *primitive) { return PrimitiveC:: Registry LogRegistry(schema::PrimitiveType_Log, LogCreator); #endif -Registry LogParameterRegistry(schema::PrimitiveType_Log, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/log_grad.cc b/mindspore/lite/src/ops/log_grad.cc index 3e797c7fcf..4bb8be9d67 100644 --- a/mindspore/lite/src/ops/log_grad.cc +++ b/mindspore/lite/src/ops/log_grad.cc @@ -16,7 +16,9 @@ #include "src/ops/log_grad.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif #include "src/ops/arithmetic_self.h" namespace mindspore { @@ -39,7 +41,6 @@ int LogGrad::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers PrimitiveC *LogGradCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry LogGradRegistry(schema::PrimitiveType_LogGrad, LogGradCreator); #endif -Registry LogGradParameterRegistry(schema::PrimitiveType_LogGrad, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/logical_and.cc b/mindspore/lite/src/ops/logical_and.cc index c6e43984ae..461d87e7b3 100644 --- a/mindspore/lite/src/ops/logical_and.cc +++ b/mindspore/lite/src/ops/logical_and.cc @@ -16,7 +16,9 @@ #include "src/ops/logical_and.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -37,6 +39,5 @@ PrimitiveC *LogicalAndCreator(const schema::Primitive *primitive) { Registry LogicalAndRegistry(schema::PrimitiveType_LogicalAnd, LogicalAndCreator); #endif -Registry LogicalAndParameterRegistry(schema::PrimitiveType_LogicalAnd, PopulateArithmetic); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/logical_not.cc b/mindspore/lite/src/ops/logical_not.cc index 3847e2b6a8..5eeae1915d 100644 --- a/mindspore/lite/src/ops/logical_not.cc +++ b/mindspore/lite/src/ops/logical_not.cc @@ -16,7 +16,9 @@ #include "src/ops/logical_not.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -35,7 +37,6 @@ PrimitiveC *LogicalNotCreator(const schema::Primitive *primitive) { } Registry LogicalNotRegistry(schema::PrimitiveType_LogicalNot, LogicalNotCreator); #endif -Registry LogicalNotParameterRegistry(schema::PrimitiveType_LogicalNot, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/logical_or.cc b/mindspore/lite/src/ops/logical_or.cc index 1fc125b059..142d22b986 100644 --- a/mindspore/lite/src/ops/logical_or.cc +++ b/mindspore/lite/src/ops/logical_or.cc @@ -16,7 +16,9 @@ #include "src/ops/logical_or.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -36,6 +38,6 @@ PrimitiveC *LogicalOrCreator(const schema::Primitive *primitive) { } Registry LogicalOrRegistry(schema::PrimitiveType_LogicalOr, LogicalOrCreator); #endif -Registry LogicalOrParameterRegistry(schema::PrimitiveType_LogicalOr, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/lrn.cc b/mindspore/lite/src/ops/lrn.cc index c4bde64483..851e070c10 100644 --- a/mindspore/lite/src/ops/lrn.cc +++ b/mindspore/lite/src/ops/lrn.cc @@ -16,7 +16,9 @@ #include "src/ops/lrn.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/lsh_projection.cc b/mindspore/lite/src/ops/lsh_projection.cc index b206df98c2..2883d66e18 100644 --- a/mindspore/lite/src/ops/lsh_projection.cc +++ b/mindspore/lite/src/ops/lsh_projection.cc @@ -15,9 +15,9 @@ */ #include "src/ops/lsh_projection.h" -#include "nnacl/lsh_projection_parameter.h" - +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -48,21 +48,6 @@ Registry LshProjectionRegistry(schema::PrimitiveType_LshProjection, LshProjectio #endif -OpParameter *PopulateLshProjectionParameter(const mindspore::lite::PrimitiveC *primitive) { - LshProjectionParameter *lsh_project_param = - reinterpret_cast(malloc(sizeof(LshProjectionParameter))); - if (lsh_project_param == nullptr) { - MS_LOG(ERROR) << "malloc LshProjectionParameter failed."; - return nullptr; - } - memset(lsh_project_param, 0, sizeof(LshProjectionParameter)); - lsh_project_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - lsh_project_param->lsh_type_ = param->GetLshType(); - return reinterpret_cast(lsh_project_param); -} -Registry LshProjectionParameterRegistry(schema::PrimitiveType_LshProjection, PopulateLshProjectionParameter); - int LshProjection::InferShape(std::vector inputs_, std::vector outputs_) { if (inputs_.size() != kDoubleNum && inputs_.size() != kMultiNum) { MS_LOG(ERROR) << "inputs to LshProjection operator should be 2 or 3, but " << inputs_.size() << " is given."; diff --git a/mindspore/lite/src/ops/lstm.cc b/mindspore/lite/src/ops/lstm.cc index ef24a0f2bc..f22f69afef 100644 --- a/mindspore/lite/src/ops/lstm.cc +++ b/mindspore/lite/src/ops/lstm.cc @@ -16,8 +16,9 @@ #include "src/ops/lstm.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/lstm.h" +#endif namespace mindspore { namespace lite { @@ -48,25 +49,6 @@ Registry LstmRegistry(schema::PrimitiveType_Lstm, LstmCreator); #endif -OpParameter *PopulateLstmParameter(const mindspore::lite::PrimitiveC *primitive) { - LstmParameter *lstm_param = reinterpret_cast(malloc(sizeof(LstmParameter))); - if (lstm_param == nullptr) { - MS_LOG(ERROR) << "malloc LstmParameter failed."; - return nullptr; - } - memset(lstm_param, 0, sizeof(LstmParameter)); - lstm_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - if (param == nullptr) { - free(lstm_param); - MS_LOG(ERROR) << "get Lstm param nullptr."; - return nullptr; - } - lstm_param->bidirectional_ = param->GetBidirection(); - return reinterpret_cast(lstm_param); -} -Registry LstmParameterRegistry(schema::PrimitiveType_Lstm, PopulateLstmParameter); - const int kLstmInputNum = 6; const int kLstmOutputNum = 3; int Lstm::InferShape(std::vector inputs_, std::vector outputs_) { diff --git a/mindspore/lite/src/ops/make_tuple.cc b/mindspore/lite/src/ops/make_tuple.cc index b149679867..63528302d5 100644 --- a/mindspore/lite/src/ops/make_tuple.cc +++ b/mindspore/lite/src/ops/make_tuple.cc @@ -18,7 +18,9 @@ #include #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/matmul.cc b/mindspore/lite/src/ops/matmul.cc index e91d51a4d7..1e72733d8e 100644 --- a/mindspore/lite/src/ops/matmul.cc +++ b/mindspore/lite/src/ops/matmul.cc @@ -21,8 +21,9 @@ #include "tools/converter/quantizer/quantize_util.h" #endif +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/matmul_parameter.h" +#endif namespace mindspore { namespace lite { @@ -93,23 +94,6 @@ PrimitiveC *MatMulCreator(const schema::Primitive *primitive) { return Primitive Registry MatMulRegistry(schema::PrimitiveType_MatMul, MatMulCreator); #endif -OpParameter *PopulateMatMulParameter(const mindspore::lite::PrimitiveC *primitive) { - auto param = reinterpret_cast(const_cast(primitive)); - MatMulParameter *matmul_param = reinterpret_cast(malloc(sizeof(MatMulParameter))); - if (matmul_param == nullptr) { - MS_LOG(ERROR) << "malloc MatMulParameter failed."; - return nullptr; - } - memset(matmul_param, 0, sizeof(MatMulParameter)); - matmul_param->op_parameter_.type_ = primitive->Type(); - matmul_param->b_transpose_ = param->GetTransposeB(); - matmul_param->a_transpose_ = param->GetTransposeA(); - matmul_param->has_bias_ = false; - matmul_param->act_type_ = ActType_No; - return reinterpret_cast(matmul_param); -} -Registry MatMulParameterRegistry(schema::PrimitiveType_MatMul, PopulateMatMulParameter); - int MatMul::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input0 = inputs_.front(); diff --git a/mindspore/lite/src/ops/matrix_diag.cc b/mindspore/lite/src/ops/matrix_diag.cc index 54958d6712..f078287452 100644 --- a/mindspore/lite/src/ops/matrix_diag.cc +++ b/mindspore/lite/src/ops/matrix_diag.cc @@ -16,7 +16,9 @@ #include "src/ops/matrix_diag.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/maximum.cc b/mindspore/lite/src/ops/maximum.cc index 20be10444a..15899974d2 100644 --- a/mindspore/lite/src/ops/maximum.cc +++ b/mindspore/lite/src/ops/maximum.cc @@ -23,7 +23,9 @@ #include "tools/converter/quantizer/quantize_util.h" #endif +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -68,6 +70,6 @@ int Maximum::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers PrimitiveC *MaximumCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry MaximumRegistry(schema::PrimitiveType_Maximum, MaximumCreator); #endif -Registry MaximumParameterRegistry(schema::PrimitiveType_Maximum, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/mean.cc b/mindspore/lite/src/ops/mean.cc index 2e827b5fc6..d4a9c838d8 100644 --- a/mindspore/lite/src/ops/mean.cc +++ b/mindspore/lite/src/ops/mean.cc @@ -16,8 +16,9 @@ #include "src/ops/mean.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/reduce_parameter.h" +#endif namespace mindspore { namespace lite { @@ -60,32 +61,6 @@ PrimitiveC *MeanCreator(const schema::Primitive *primitive) { return PrimitiveC: Registry MeanRegistry(schema::PrimitiveType_Mean, MeanCreator); #endif -OpParameter *PopulateMeanParameter(const mindspore::lite::PrimitiveC *primitive) { - ReduceParameter *mean_param = reinterpret_cast(malloc(sizeof(ReduceParameter))); - if (mean_param == nullptr) { - MS_LOG(ERROR) << "malloc ReduceParameter failed."; - return nullptr; - } - memset(mean_param, 0, sizeof(ReduceParameter)); - mean_param->op_parameter_.type_ = primitive->Type(); - auto mean = reinterpret_cast(const_cast(primitive)); - mean_param->keep_dims_ = mean->GetKeepDims(); - auto axisVector = mean->GetAxis(); - if (axisVector.size() > REDUCE_MAX_AXES_NUM) { - MS_LOG(ERROR) << "Reduce axes size " << axisVector.size() << " exceed limit " << REDUCE_MAX_AXES_NUM; - free(mean_param); - return nullptr; - } - mean_param->num_axes_ = static_cast(axisVector.size()); - int i = 0; - for (auto iter = axisVector.begin(); iter != axisVector.end(); iter++) { - mean_param->axes_[i++] = *iter; - } - mean_param->mode_ = static_cast(schema::ReduceMode_ReduceMean); - return reinterpret_cast(mean_param); -} -Registry MeanParameterRegistry(schema::PrimitiveType_Mean, PopulateMeanParameter); - namespace { constexpr size_t kInputSize = 1; constexpr size_t kOutputSize = 1; diff --git a/mindspore/lite/src/ops/minimum.cc b/mindspore/lite/src/ops/minimum.cc index 8d584e754a..a7126c9502 100644 --- a/mindspore/lite/src/ops/minimum.cc +++ b/mindspore/lite/src/ops/minimum.cc @@ -16,7 +16,9 @@ #include "src/ops/minimum.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -34,6 +36,5 @@ PrimitiveC *MinimumCreator(const schema::Primitive *primitive) { return Primitiv Registry MinimumRegistry(schema::PrimitiveType_Minimum, MinimumCreator); #endif -Registry MinimumParameterRegistry(schema::PrimitiveType_Minimum, PopulateArithmetic); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/mul.cc b/mindspore/lite/src/ops/mul.cc index d7a9dad330..bb46cb0382 100644 --- a/mindspore/lite/src/ops/mul.cc +++ b/mindspore/lite/src/ops/mul.cc @@ -16,8 +16,10 @@ #include "src/ops/mul.h" #include -#include "nnacl/arithmetic_common.h" + +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -77,27 +79,6 @@ int Mul::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::Fl PrimitiveC *MulCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry MulRegistry(schema::PrimitiveType_Mul, MulCreator); #endif -OpParameter *PopulateMulParameter(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); - if (arithmetic_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; - return nullptr; - } - memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); - arithmetic_param->op_parameter_.type_ = primitive->Type(); - arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); - arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); - arithmetic_param->activation_type_ = - reinterpret_cast(const_cast(primitive))->GetActivationType(); - auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); - memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); - memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); - memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - return reinterpret_cast(arithmetic_param); -} -Registry MulParameterRegistry(schema::PrimitiveType_Mul, PopulateMulParameter); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/nchw2nhwc.cc b/mindspore/lite/src/ops/nchw2nhwc.cc index 3413042baf..ac60eadfcb 100644 --- a/mindspore/lite/src/ops/nchw2nhwc.cc +++ b/mindspore/lite/src/ops/nchw2nhwc.cc @@ -17,8 +17,9 @@ #include "src/ops/nchw2nhwc.h" #include "src/common/common.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/transpose.h" +#endif namespace mindspore { namespace lite { @@ -38,23 +39,6 @@ PrimitiveC *Nchw2NhwcCreator(const schema::Primitive *primitive) { Registry Nchw2NhwcRegistry(schema::PrimitiveType_Nchw2Nhwc, Nchw2NhwcCreator); #endif -OpParameter *PopulateNchw2NhwcParameter(const mindspore::lite::PrimitiveC *primitive) { - TransposeParameter *parameter = reinterpret_cast(malloc(sizeof(TransposeParameter))); - if (parameter == nullptr) { - MS_LOG(ERROR) << "malloc OpParameter failed."; - return nullptr; - } - memset(parameter, 0, sizeof(OpParameter)); - parameter->op_parameter_.type_ = primitive->Type(); - parameter->num_axes_ = 4; - parameter->perm_[0] = 0; - parameter->perm_[1] = 2; - parameter->perm_[2] = 3; - parameter->perm_[3] = 1; - return reinterpret_cast(parameter); -} -Registry Nchw2NhwcParameterRegistry(schema::PrimitiveType_Nchw2Nhwc, PopulateNchw2NhwcParameter); - int Nchw2Nhwc::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/neg.cc b/mindspore/lite/src/ops/neg.cc index 8e51f870fc..8f52f69dcc 100644 --- a/mindspore/lite/src/ops/neg.cc +++ b/mindspore/lite/src/ops/neg.cc @@ -16,7 +16,9 @@ #include "src/ops/neg.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -57,6 +59,6 @@ int Neg::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::Fl PrimitiveC *NegCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry NegRegistry(schema::PrimitiveType_Neg, NegCreator); #endif -Registry NegParameterRegistry(schema::PrimitiveType_Neg, PopulateArithmeticSelf); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/neg_grad.cc b/mindspore/lite/src/ops/neg_grad.cc index d244388e6a..4c74be9953 100644 --- a/mindspore/lite/src/ops/neg_grad.cc +++ b/mindspore/lite/src/ops/neg_grad.cc @@ -16,7 +16,9 @@ #include "src/ops/neg_grad.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -34,7 +36,6 @@ PrimitiveC *NegGradCreator(const schema::Primitive *primitive) { return Primitiv Registry NegGradRegistry(schema::PrimitiveType_NegGrad, NegGradCreator); #endif -Registry NegGradParameterRegistry(schema::PrimitiveType_NegGrad, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/nhwc2nchw.cc b/mindspore/lite/src/ops/nhwc2nchw.cc index 76022ef857..97fa7db85e 100644 --- a/mindspore/lite/src/ops/nhwc2nchw.cc +++ b/mindspore/lite/src/ops/nhwc2nchw.cc @@ -17,8 +17,9 @@ #include "src/ops/nhwc2nchw.h" #include "src/common/common.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/transpose.h" +#endif namespace mindspore { namespace lite { @@ -39,24 +40,6 @@ PrimitiveC *Nhwc2NchwCreator(const schema::Primitive *primitive) { Registry Nhwc2NchwRegistry(schema::PrimitiveType_Nhwc2Nchw, Nhwc2NchwCreator); #endif -OpParameter *PopulateNhwc2NchwParameter(const mindspore::lite::PrimitiveC *primitive) { - TransposeParameter *parameter = reinterpret_cast(malloc(sizeof(TransposeParameter))); - if (parameter == nullptr) { - MS_LOG(ERROR) << "malloc OpParameter failed."; - return nullptr; - } - memset(parameter, 0, sizeof(OpParameter)); - parameter->op_parameter_.type_ = primitive->Type(); - parameter->num_axes_ = 4; - parameter->perm_[0] = 0; - parameter->perm_[1] = 3; - parameter->perm_[2] = 1; - parameter->perm_[3] = 2; - return reinterpret_cast(parameter); -} - -Registry Nhwc2NchwParameterRegistry(schema::PrimitiveType_Nhwc2Nchw, PopulateNhwc2NchwParameter); - int Nhwc2Nchw::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/not_equal.cc b/mindspore/lite/src/ops/not_equal.cc index bb36ba8394..b8128ede6e 100644 --- a/mindspore/lite/src/ops/not_equal.cc +++ b/mindspore/lite/src/ops/not_equal.cc @@ -16,7 +16,9 @@ #include "src/ops/not_equal.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -46,6 +48,6 @@ int NotEqual::InferShape(std::vector inputs_, std::vector ou output->SetFormat(input->GetFormat()); return RET_OK; } -Registry NotEqualParameterRegistry(schema::PrimitiveType_NotEqual, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/one_hot.cc b/mindspore/lite/src/ops/one_hot.cc index d99a725581..93f1857bcd 100644 --- a/mindspore/lite/src/ops/one_hot.cc +++ b/mindspore/lite/src/ops/one_hot.cc @@ -16,8 +16,9 @@ #include "src/ops/one_hot.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/one_hot.h" +#endif namespace mindspore { namespace lite { @@ -79,25 +80,6 @@ PrimitiveC *OneHotCreator(const schema::Primitive *primitive) { return Primitive Registry OneHotRegistry(schema::PrimitiveType_OneHot, OneHotCreator); #endif -OpParameter *PopulateOneHotParameter(const mindspore::lite::PrimitiveC *primitive) { - OneHotParameter *one_hot_param = reinterpret_cast(malloc(sizeof(OneHotParameter))); - if (one_hot_param == nullptr) { - MS_LOG(ERROR) << "malloc OneHotParameter failed."; - return nullptr; - } - memset(one_hot_param, 0, sizeof(OneHotParameter)); - one_hot_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - if (param == nullptr) { - free(one_hot_param); - MS_LOG(ERROR) << "get OneHot param nullptr."; - return nullptr; - } - one_hot_param->axis_ = param->GetAxis(); - return reinterpret_cast(one_hot_param); -} -Registry OneHotParameterRegistry(schema::PrimitiveType_OneHot, PopulateOneHotParameter); - namespace { constexpr size_t kOneHotInputNum = 4; } diff --git a/mindspore/lite/src/ops/ops_register.h b/mindspore/lite/src/ops/ops_register.h index 78dfd0de2b..e86f00dde4 100644 --- a/mindspore/lite/src/ops/ops_register.h +++ b/mindspore/lite/src/ops/ops_register.h @@ -40,20 +40,8 @@ class OpsRegistry { } } - void insertParameterMap(schema::PrimitiveType type, ParameterCreator creator) { parameter_creators[type] = creator; } - - ParameterCreator getParameterCreator(schema::PrimitiveType type) { - if (parameter_creators.find(type) != parameter_creators.end()) { - return parameter_creators[type]; - } else { - MS_LOG(ERROR) << "Unsupported parameter type in Create : " << schema::EnumNamePrimitiveType(type); - return nullptr; - } - } - protected: std::map primitive_creators; - std::map parameter_creators; }; class Registry { @@ -61,9 +49,6 @@ class Registry { Registry(schema::PrimitiveType primitive_type, PrimitiveCCreator creator) { OpsRegistry::GetInstance()->insertPrimitiveCMap(primitive_type, creator); } - Registry(schema::PrimitiveType primitive_type, ParameterCreator creator) { - OpsRegistry::GetInstance()->insertParameterMap(primitive_type, creator); - } }; } // namespace lite diff --git a/mindspore/lite/src/ops/p_relu.cc b/mindspore/lite/src/ops/p_relu.cc index 6cfe20ed57..6600a44396 100644 --- a/mindspore/lite/src/ops/p_relu.cc +++ b/mindspore/lite/src/ops/p_relu.cc @@ -16,8 +16,9 @@ #include "src/ops/p_relu.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/prelu_parameter.h" +#endif namespace mindspore { namespace lite { @@ -54,19 +55,5 @@ Registry PReLURegistry(schema::PrimitiveType_PReLU, PReLUCreator); #endif -OpParameter *PopulatePReLUParameter(const mindspore::lite::PrimitiveC *primitive) { - auto param = reinterpret_cast(const_cast(primitive)); - PReluParameter *prelu_param = reinterpret_cast(malloc(sizeof(PReluParameter))); - if (prelu_param == nullptr) { - MS_LOG(ERROR) << "malloc PReluParameter failed."; - return nullptr; - } - memset(prelu_param, 0, sizeof(PReluParameter)); - prelu_param->op_parameter_.type_ = primitive->Type(); - prelu_param->channelShared = param->GetChannelShared(); - return reinterpret_cast(prelu_param); -} -Registry PReLUParameterRegistry(schema::PrimitiveType_PReLU, PopulatePReLUParameter); - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/pad.cc b/mindspore/lite/src/ops/pad.cc index 65dc8b9190..0a07484221 100644 --- a/mindspore/lite/src/ops/pad.cc +++ b/mindspore/lite/src/ops/pad.cc @@ -16,8 +16,9 @@ #include "src/ops/pad.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/pad_parameter.h" +#endif namespace mindspore { namespace lite { @@ -64,37 +65,6 @@ int Pad::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::Fl PrimitiveC *PadCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry PadRegistry(schema::PrimitiveType_Pad, PadCreator); #endif -OpParameter *PopulatePadParameter(const mindspore::lite::PrimitiveC *primitive) { - PadParameter *pad_param = reinterpret_cast(malloc(sizeof(PadParameter))); - if (pad_param == nullptr) { - MS_LOG(ERROR) << "malloc PadParameter failed."; - return nullptr; - } - memset(pad_param, 0, sizeof(PadParameter)); - pad_param->op_parameter_.type_ = primitive->Type(); - auto pad_node = reinterpret_cast(const_cast(primitive)); - pad_param->pad_mode_ = pad_node->GetPaddingMode(); - if (pad_param->pad_mode_ == static_cast(schema::PaddingMode_CONSTANT)) { - pad_param->constant_value_ = pad_node->GetConstantValue(); - auto size = pad_node->GetPaddings().size(); - if (size > MAX_PAD_SIZE) { - MS_LOG(ERROR) << "Invalid padding size: " << size; - free(pad_param); - return nullptr; - } - - for (size_t i = 0; i < MAX_PAD_SIZE - size; ++i) { - pad_param->paddings_[i] = 0; - } - for (size_t i = 0; i < size; i++) { - pad_param->paddings_[MAX_PAD_SIZE - size + i] = pad_node->GetPaddings()[i]; - } - pad_param->padding_length = MAX_PAD_SIZE; - } - - return reinterpret_cast(pad_param); -} -Registry PadParameterRegistry(schema::PrimitiveType_Pad, PopulatePadParameter); int Pad::InferShape(std::vector inputs, std::vector outputs) { MS_ASSERT(this->primitive_ != nullptr); diff --git a/mindspore/lite/src/ops/permute.cc b/mindspore/lite/src/ops/permute.cc index 176c1c85b0..de1dccc1d6 100644 --- a/mindspore/lite/src/ops/permute.cc +++ b/mindspore/lite/src/ops/permute.cc @@ -16,7 +16,9 @@ #include "src/ops/permute.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/pooling.cc b/mindspore/lite/src/ops/pooling.cc index 24bb472f4d..3b415339c6 100644 --- a/mindspore/lite/src/ops/pooling.cc +++ b/mindspore/lite/src/ops/pooling.cc @@ -19,8 +19,9 @@ #include #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/pooling_parameter.h" +#endif namespace mindspore { namespace lite { @@ -166,68 +167,6 @@ Registry PoolingRegistry(schema::PrimitiveType_Pooling, PoolingCreator); #endif -OpParameter *PopulatePoolingParameter(const mindspore::lite::PrimitiveC *primitive) { - auto pooling_primitive = - reinterpret_cast(const_cast(primitive)); - PoolingParameter *pooling_param = reinterpret_cast(malloc(sizeof(PoolingParameter))); - if (pooling_param == nullptr) { - MS_LOG(ERROR) << "malloc PoolingParameter failed."; - return nullptr; - } - memset(pooling_param, 0, sizeof(PoolingParameter)); - pooling_param->op_parameter_.type_ = primitive->Type(); - pooling_param->global_ = pooling_primitive->GetGlobal(); - pooling_param->window_w_ = pooling_primitive->GetWindowW(); - pooling_param->window_h_ = pooling_primitive->GetWindowH(); - auto pooling_lite_primitive = (lite::Pooling *)primitive; - pooling_param->pad_u_ = pooling_lite_primitive->PadUp(); - pooling_param->pad_d_ = pooling_lite_primitive->PadDown(); - pooling_param->pad_l_ = pooling_lite_primitive->PadLeft(); - pooling_param->pad_r_ = pooling_lite_primitive->PadRight(); - pooling_param->stride_w_ = pooling_primitive->GetStrideW(); - pooling_param->stride_h_ = pooling_primitive->GetStrideH(); - pooling_param->avg_mode_ = pooling_primitive->GetAvgMode(); - - auto is_global = pooling_primitive->GetGlobal(); - pooling_param->global_ = is_global; - auto pool_mode = pooling_primitive->GetPoolingMode(); - switch (pool_mode) { - case schema::PoolMode_MAX_POOLING: - pooling_param->pool_mode_ = PoolMode_MaxPool; - break; - case schema::PoolMode_MEAN_POOLING: - pooling_param->pool_mode_ = PoolMode_AvgPool; - break; - default: - pooling_param->pool_mode_ = PoolMode_No; - break; - } - - auto round_mode = pooling_primitive->GetRoundMode(); - switch (round_mode) { - case schema::RoundMode_FLOOR: - pooling_param->round_mode_ = RoundMode_Floor; - break; - case schema::RoundMode_CEIL: - pooling_param->round_mode_ = RoundMode_Ceil; - break; - default: - pooling_param->round_mode_ = RoundMode_No; - break; - } - - if (pooling_primitive->GetActivationType() == schema::ActivationType_RELU) { - pooling_param->act_type_ = ActType_Relu; - } else if (pooling_primitive->GetActivationType() == schema::ActivationType_RELU6) { - pooling_param->act_type_ = ActType_Relu6; - } else { - pooling_param->act_type_ = ActType_No; - } - return reinterpret_cast(pooling_param); -} - -Registry PoolingParameterRegistry(schema::PrimitiveType_Pooling, PopulatePoolingParameter); - int Pooling::PadUp() const { return this->pad_u_; } int Pooling::PadDown() const { return this->pad_d_; } int Pooling::PadLeft() const { return this->pad_l_; } diff --git a/mindspore/lite/src/ops/pooling_grad.cc b/mindspore/lite/src/ops/pooling_grad.cc index db9618556a..9d2e633d2b 100644 --- a/mindspore/lite/src/ops/pooling_grad.cc +++ b/mindspore/lite/src/ops/pooling_grad.cc @@ -16,7 +16,9 @@ #include "src/ops/pooling_grad.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/populate/activation_populate.cc b/mindspore/lite/src/ops/populate/activation_populate.cc new file mode 100644 index 0000000000..3688bb414e --- /dev/null +++ b/mindspore/lite/src/ops/populate/activation_populate.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2019-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/ops/activation.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/activation.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateActivationParameter(const mindspore::lite::PrimitiveC *primitive) { + ActivationParameter *act_param = reinterpret_cast(malloc(sizeof(ActivationParameter))); + if (act_param == nullptr) { + MS_LOG(ERROR) << "malloc ActivationParameter failed."; + return nullptr; + } + memset(act_param, 0, sizeof(ActivationParameter)); + act_param->op_parameter_.type_ = primitive->Type(); + auto activation = + reinterpret_cast(const_cast(primitive)); + act_param->type_ = static_cast(activation->GetType()); + act_param->alpha_ = activation->GetAlpha(); + act_param->min_val_ = activation->GetMinVal(); + act_param->max_val_ = activation->GetMaxVal(); + return reinterpret_cast(act_param); +} +Registry ActivationParameterRegistry(schema::PrimitiveType_Activation, PopulateActivationParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/add_populate.cc b/mindspore/lite/src/ops/populate/add_populate.cc new file mode 100644 index 0000000000..7ef0e6eaa9 --- /dev/null +++ b/mindspore/lite/src/ops/populate/add_populate.cc @@ -0,0 +1,46 @@ +/** + * Copyright 2019-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/ops/add.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/arithmetic_common.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateAddParameter(const mindspore::lite::PrimitiveC *primitive) { + ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); + if (arithmetic_param == nullptr) { + MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; + return nullptr; + } + memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); + arithmetic_param->op_parameter_.type_ = primitive->Type(); + arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); + arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); + arithmetic_param->activation_type_ = + reinterpret_cast(const_cast(primitive))->GetActivationType(); + auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); + memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); + memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); + memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + return reinterpret_cast(arithmetic_param); +} +Registry AddParameterRegistry(schema::PrimitiveType_Add, PopulateAddParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/ceil.cc b/mindspore/lite/src/ops/populate/addn_populate.cc similarity index 53% rename from mindspore/lite/src/ops/ceil.cc rename to mindspore/lite/src/ops/populate/addn_populate.cc index 848f92e2dc..22aacebc72 100644 --- a/mindspore/lite/src/ops/ceil.cc +++ b/mindspore/lite/src/ops/populate/addn_populate.cc @@ -14,14 +14,22 @@ * limitations under the License. */ -#include "src/ops/ceil.h" - -#include "src/ops/ops_register.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/op_base.h" namespace mindspore { namespace lite { - -Registry CeilParameterRegistry(schema::PrimitiveType_Ceil, PopulateArithmeticSelf); - +OpParameter *PopulateAddNParameter(const mindspore::lite::PrimitiveC *primitive) { + OpParameter *addn_param = reinterpret_cast(malloc(sizeof(OpParameter))); + if (addn_param == nullptr) { + MS_LOG(ERROR) << "malloc OpParameter failed."; + return nullptr; + } + memset(addn_param, 0, sizeof(OpParameter)); + addn_param->type_ = primitive->Type(); + return reinterpret_cast(addn_param); +} +Registry AddNParameterRegistry(schema::PrimitiveType_AddN, PopulateAddNParameter); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/argmax_populate.cc b/mindspore/lite/src/ops/populate/argmax_populate.cc new file mode 100644 index 0000000000..8f81b37e6c --- /dev/null +++ b/mindspore/lite/src/ops/populate/argmax_populate.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2019-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/ops/argmax.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/arg_min_max_parameter.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateArgMaxParameter(const mindspore::lite::PrimitiveC *primitive) { + ArgMinMaxParameter *arg_param = reinterpret_cast(malloc(sizeof(ArgMinMaxParameter))); + if (arg_param == nullptr) { + MS_LOG(ERROR) << "malloc ArgMinMaxParameter failed."; + return nullptr; + } + memset(arg_param, 0, sizeof(ArgMinMaxParameter)); + arg_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + arg_param->axis_ = param->GetAxis(); + arg_param->topk_ = param->GetTopK(); + arg_param->axis_type_ = param->GetAxisType(); + arg_param->out_value_ = param->GetOutMaxValue(); + arg_param->keep_dims_ = param->GetKeepDims(); + return reinterpret_cast(arg_param); +} + +Registry ArgMaxParameterRegistry(schema::PrimitiveType_ArgMax, PopulateArgMaxParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/argmin_populate.cc b/mindspore/lite/src/ops/populate/argmin_populate.cc new file mode 100644 index 0000000000..225538a160 --- /dev/null +++ b/mindspore/lite/src/ops/populate/argmin_populate.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2019-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/ops/argmin.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/arg_min_max_parameter.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateArgMinParameter(const mindspore::lite::PrimitiveC *primitive) { + ArgMinMaxParameter *arg_param = reinterpret_cast(malloc(sizeof(ArgMinMaxParameter))); + if (arg_param == nullptr) { + MS_LOG(ERROR) << "malloc ArgMinMaxParameter failed."; + return nullptr; + } + memset(arg_param, 0, sizeof(ArgMinMaxParameter)); + arg_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + arg_param->axis_ = param->GetAxis(); + arg_param->topk_ = param->GetTopK(); + arg_param->axis_type_ = param->GetAxisType(); + arg_param->out_value_ = param->GetOutMaxValue(); + arg_param->keep_dims_ = param->GetKeepDims(); + return reinterpret_cast(arg_param); +} + +Registry ArgMinParameterRegistry(schema::PrimitiveType_ArgMin, PopulateArgMinParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/arithmetic_populate.cc b/mindspore/lite/src/ops/populate/arithmetic_populate.cc new file mode 100644 index 0000000000..05d0e7f9cb --- /dev/null +++ b/mindspore/lite/src/ops/populate/arithmetic_populate.cc @@ -0,0 +1,62 @@ +/** + * Copyright 2019-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/ops/arithmetic.h" +#include "src/common/log_adapter.h" +#include "src/tensor.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateArithmetic(const mindspore::lite::PrimitiveC *primitive) { + ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); + if (arithmetic_param == nullptr) { + MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; + return nullptr; + } + memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); + arithmetic_param->op_parameter_.type_ = primitive->Type(); + arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); + arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); + + arithmetic_param->activation_type_ = 0; + + auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); + memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); + memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); + memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + return reinterpret_cast(arithmetic_param); +} + +Registry RealDivParameterRegistry(schema::PrimitiveType_RealDiv, PopulateArithmetic); +Registry LogicalAndParameterRegistry(schema::PrimitiveType_LogicalAnd, PopulateArithmetic); +Registry ParameterRegistry(schema::PrimitiveType_LogicalOr, PopulateArithmetic); +Registry EqualParameterRegistry(schema::PrimitiveType_Equal, PopulateArithmetic); +Registry LessParameterRegistry(schema::PrimitiveType_Less, PopulateArithmetic); +Registry GreaterParameterRegistry(schema::PrimitiveType_Greater, PopulateArithmetic); +Registry NotEqualParameterRegistry(schema::PrimitiveType_NotEqual, PopulateArithmetic); +Registry LessEqualParameterRegistry(schema::PrimitiveType_LessEqual, PopulateArithmetic); +Registry MaximumParameterRegistry(schema::PrimitiveType_Maximum, PopulateArithmetic); +Registry MinimumParameterRegistry(schema::PrimitiveType_Minimum, PopulateArithmetic); +Registry FloorDivParameterRegistry(schema::PrimitiveType_FloorDiv, PopulateArithmetic); +Registry FloorModParameterRegistry(schema::PrimitiveType_FloorMod, PopulateArithmetic); +Registry SquaredDifferenceParameterRegistry(schema::PrimitiveType_SquaredDifference, PopulateArithmetic); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/arithmetic_self_populate.cc b/mindspore/lite/src/ops/populate/arithmetic_self_populate.cc new file mode 100644 index 0000000000..580cb6673d --- /dev/null +++ b/mindspore/lite/src/ops/populate/arithmetic_self_populate.cc @@ -0,0 +1,52 @@ +/** + * 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/ops/arithmetic_self.h" +#include "src/common/log_adapter.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateArithmeticSelf(const mindspore::lite::PrimitiveC *primitive) { + ArithmeticSelfParameter *arithmetic_self_param = + reinterpret_cast(malloc(sizeof(ArithmeticSelfParameter))); + if (arithmetic_self_param == nullptr) { + MS_LOG(ERROR) << "malloc ArithmeticSelfParameter failed."; + return nullptr; + } + memset(arithmetic_self_param, 0, sizeof(ArithmeticSelfParameter)); + arithmetic_self_param->op_parameter_.type_ = primitive->Type(); + return reinterpret_cast(arithmetic_self_param); +} + +Registry AbsParameterRegistry(schema::PrimitiveType_Abs, PopulateArithmeticSelf); +Registry CosParameterRegistry(schema::PrimitiveType_Cos, PopulateArithmeticSelf); +Registry SinParameterRegistry(schema::PrimitiveType_Sin, PopulateArithmeticSelf); +Registry LogParameterRegistry(schema::PrimitiveType_Log, PopulateArithmeticSelf); +Registry NegParameterRegistry(schema::PrimitiveType_Neg, PopulateArithmeticSelf); +Registry NegGradParameterRegistry(schema::PrimitiveType_NegGrad, PopulateArithmeticSelf); +Registry LogGradParameterRegistry(schema::PrimitiveType_LogGrad, PopulateArithmeticSelf); +Registry SqrtParameterRegistry(schema::PrimitiveType_Sqrt, PopulateArithmeticSelf); +Registry SquareParameterRegistry(schema::PrimitiveType_Square, PopulateArithmeticSelf); +Registry RsqrtParameterRegistry(schema::PrimitiveType_Rsqrt, PopulateArithmeticSelf); +Registry LogicalNotParameterRegistry(schema::PrimitiveType_LogicalNot, PopulateArithmeticSelf); +Registry FloorParameterRegistry(schema::PrimitiveType_Floor, PopulateArithmeticSelf); +Registry CeilParameterRegistry(schema::PrimitiveType_Ceil, PopulateArithmeticSelf); +Registry RoundParameterRegistry(schema::PrimitiveType_Round, PopulateArithmeticSelf); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/batch_norm_populate.cc b/mindspore/lite/src/ops/populate/batch_norm_populate.cc new file mode 100644 index 0000000000..3561572f49 --- /dev/null +++ b/mindspore/lite/src/ops/populate/batch_norm_populate.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2019-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/ops/batch_norm.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/batchnorm_parameter.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateBatchNorm(const mindspore::lite::PrimitiveC *primitive) { + const auto param = + reinterpret_cast(const_cast(primitive)); + BatchNormParameter *batch_norm_param = reinterpret_cast(malloc(sizeof(BatchNormParameter))); + if (batch_norm_param == nullptr) { + MS_LOG(ERROR) << "malloc BatchNormParameter failed."; + return nullptr; + } + memset(batch_norm_param, 0, sizeof(BatchNormParameter)); + batch_norm_param->op_parameter_.type_ = primitive->Type(); + batch_norm_param->epsilon_ = param->GetEpsilon(); + batch_norm_param->fused_ = false; + return reinterpret_cast(batch_norm_param); +} + +Registry BatchNormParameterRegistry(schema::PrimitiveType_BatchNorm, PopulateBatchNorm); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/batch_to_space_populate.cc b/mindspore/lite/src/ops/populate/batch_to_space_populate.cc new file mode 100644 index 0000000000..538a4957ec --- /dev/null +++ b/mindspore/lite/src/ops/populate/batch_to_space_populate.cc @@ -0,0 +1,62 @@ +/** + * Copyright 2019-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/ops/batch_to_space.h" +#include "src/common/log_adapter.h" +#include "src/tensor.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/batch_to_space.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateBatchToSpaceParameter(const mindspore::lite::PrimitiveC *primitive) { + BatchToSpaceParameter *batch_space_param = + reinterpret_cast(malloc(sizeof(BatchToSpaceParameter))); + if (batch_space_param == nullptr) { + MS_LOG(ERROR) << "malloc BatchToSpaceParameter failed."; + return nullptr; + } + memset(batch_space_param, 0, sizeof(BatchToSpaceParameter)); + batch_space_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + auto block_shape = param->GetBlockShape(); + if (block_shape.size() != BATCH_TO_SPACE_BLOCK_SHAPE_SIZE) { + MS_LOG(ERROR) << "batch_to_space blockShape size should be " << BATCH_TO_SPACE_BLOCK_SHAPE_SIZE; + free(batch_space_param); + return nullptr; + } + + auto crops = param->GetCrops(); + if (crops.size() != BATCH_TO_SPACE_CROPS_SIZE) { + MS_LOG(ERROR) << "batch_to_space crops size should be " << BATCH_TO_SPACE_CROPS_SIZE; + free(batch_space_param); + return nullptr; + } + + for (int i = 0; i < BATCH_TO_SPACE_BLOCK_SHAPE_SIZE; ++i) { + batch_space_param->block_shape_[i] = block_shape[i]; + } + + for (int i = 0; i < BATCH_TO_SPACE_CROPS_SIZE; ++i) { + batch_space_param->crops_[i] = crops[i]; + } + return reinterpret_cast(batch_space_param); +} +Registry BatchToSpaceParameterRegistry(schema::PrimitiveType_BatchToSpace, PopulateBatchToSpaceParameter); +Registry BatchToSpaceNDParameterRegistry(schema::PrimitiveType_BatchToSpaceND, PopulateBatchToSpaceParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/bias_add_populate.cc b/mindspore/lite/src/ops/populate/bias_add_populate.cc new file mode 100644 index 0000000000..953c6fdbc3 --- /dev/null +++ b/mindspore/lite/src/ops/populate/bias_add_populate.cc @@ -0,0 +1,37 @@ +/** + * Copyright 2019-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/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/arithmetic_common.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateBiasAddParameter(const mindspore::lite::PrimitiveC *primitive) { + ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); + if (arithmetic_param == nullptr) { + MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; + return nullptr; + } + memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); + arithmetic_param->op_parameter_.type_ = primitive->Type(); + + return reinterpret_cast(arithmetic_param); +} +Registry BiasAddParameterRegistry(schema::PrimitiveType_BiasAdd, PopulateBiasAddParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/broadcast_to_populate.cc b/mindspore/lite/src/ops/populate/broadcast_to_populate.cc new file mode 100644 index 0000000000..f30bc7f5de --- /dev/null +++ b/mindspore/lite/src/ops/populate/broadcast_to_populate.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2019-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/ops/broadcast_to.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/broadcast_to.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateBroadcastToParameter(const mindspore::lite::PrimitiveC *primitive) { + BroadcastToParameter *broadcast_param = + reinterpret_cast(malloc(sizeof(BroadcastToParameter))); + if (broadcast_param == nullptr) { + MS_LOG(ERROR) << "malloc BroadcastToParameter failed."; + return nullptr; + } + memset(broadcast_param, 0, sizeof(BroadcastToParameter)); + auto param = reinterpret_cast(const_cast(primitive)); + broadcast_param->op_parameter_.type_ = primitive->Type(); + auto dst_shape = param->GetDstShape(); + broadcast_param->shape_size_ = dst_shape.size(); + for (size_t i = 0; i < broadcast_param->shape_size_; ++i) { + broadcast_param->shape_[i] = dst_shape[i]; + } + return reinterpret_cast(broadcast_param); +} + +Registry BroadcastToParameterRegistry(schema::PrimitiveType_BroadcastTo, PopulateBroadcastToParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/cast_populate.cc b/mindspore/lite/src/ops/populate/cast_populate.cc new file mode 100644 index 0000000000..b83d6af0eb --- /dev/null +++ b/mindspore/lite/src/ops/populate/cast_populate.cc @@ -0,0 +1,40 @@ +/** + * Copyright 2019-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/ops/cast.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/cast.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateCastParameter(const mindspore::lite::PrimitiveC *primitive) { + CastParameter *cast_param = reinterpret_cast(malloc(sizeof(CastParameter))); + if (cast_param == nullptr) { + MS_LOG(ERROR) << "malloc CastParameter failed."; + return nullptr; + } + memset(cast_param, 0, sizeof(CastParameter)); + cast_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + cast_param->src_type_ = param->GetSrcT(); + cast_param->dst_type_ = param->GetDstT(); + return reinterpret_cast(cast_param); +} + +Registry CastParameterRegistry(schema::PrimitiveType_Cast, PopulateCastParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/clip_populate.cc b/mindspore/lite/src/ops/populate/clip_populate.cc new file mode 100644 index 0000000000..75aa4994d8 --- /dev/null +++ b/mindspore/lite/src/ops/populate/clip_populate.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2019-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/ops/clip.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/clip.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateClipParameter(const mindspore::lite::PrimitiveC *primitive) { + ClipParameter *act_param = reinterpret_cast(malloc(sizeof(ClipParameter))); + if (act_param == nullptr) { + MS_LOG(ERROR) << "malloc ClipParameter failed."; + return nullptr; + } + memset(act_param, 0, sizeof(ClipParameter)); + act_param->op_parameter_.type_ = primitive->Type(); + auto activation = reinterpret_cast(const_cast(primitive)); + act_param->min_val_ = activation->GetMin(); + act_param->max_val_ = activation->GetMax(); + return reinterpret_cast(act_param); +} + +Registry ClipParameterRegistry(schema::PrimitiveType_Clip, PopulateClipParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/concat_populate.cc b/mindspore/lite/src/ops/populate/concat_populate.cc new file mode 100644 index 0000000000..e9be7786c9 --- /dev/null +++ b/mindspore/lite/src/ops/populate/concat_populate.cc @@ -0,0 +1,41 @@ +/** + * Copyright 2019-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/ops/concat.h" +#include "src/common/log_adapter.h" +#include "src/tensor.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/concat_parameter.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateConcatParameter(const mindspore::lite::PrimitiveC *primitive) { + ConcatParameter *concat_param = reinterpret_cast(malloc(sizeof(ConcatParameter))); + if (concat_param == nullptr) { + MS_LOG(ERROR) << "malloc ConcatParameter failed."; + return nullptr; + } + memset(concat_param, 0, sizeof(ConcatParameter)); + concat_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + concat_param->axis_ = param->GetAxis(); + return reinterpret_cast(concat_param); +} + +Registry ConcatParameterRegistry(schema::PrimitiveType_Concat, PopulateConcatParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/constant_of_shape_populate.cc b/mindspore/lite/src/ops/populate/constant_of_shape_populate.cc new file mode 100644 index 0000000000..90889afbcc --- /dev/null +++ b/mindspore/lite/src/ops/populate/constant_of_shape_populate.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2019-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/ops/constant_of_shape.h" +#include "src/common/log_adapter.h" +#include "src/tensor.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/constant_of_shape.h" + +namespace mindspore::lite { +namespace { +OpParameter *PopulateConstantOfShapeParameter(const mindspore::lite::PrimitiveC *primitive) { + auto attr = + reinterpret_cast(const_cast(primitive)); + ConstantOfShapeParameter *param = + reinterpret_cast(malloc(sizeof(ConstantOfShapeParameter))); + if (param == nullptr) { + MS_LOG(ERROR) << "malloc ConstantOfShapeParameter failed."; + return nullptr; + } + memset(param, 0, sizeof(ConstantOfShapeParameter)); + param->op_parameter_.type_ = primitive->Type(); + param->value_ = attr->GetValue(); + return reinterpret_cast(param); +} +Registry ConstantOfShapeParameterRegistry(schema::PrimitiveType_ConstantOfShape, PopulateConstantOfShapeParameter); +} // namespace +} // namespace mindspore::lite diff --git a/mindspore/lite/src/ops/populate/conv2d_populate.cc b/mindspore/lite/src/ops/populate/conv2d_populate.cc new file mode 100644 index 0000000000..7eac2bba82 --- /dev/null +++ b/mindspore/lite/src/ops/populate/conv2d_populate.cc @@ -0,0 +1,67 @@ +/** + * Copyright 2019-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/ops/conv2d.h" +#include "src/common/log_adapter.h" +#include "nnacl/conv_parameter.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateConvParameter(const mindspore::lite::PrimitiveC *primitive) { + ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); + if (conv_param == nullptr) { + MS_LOG(ERROR) << "malloc ConvParameter failed."; + return nullptr; + } + memset(conv_param, 0, sizeof(ConvParameter)); + conv_param->op_parameter_.type_ = primitive->Type(); + auto conv_primitive = + reinterpret_cast(const_cast(primitive)); + conv_param->kernel_h_ = conv_primitive->GetKernelH(); + conv_param->kernel_w_ = conv_primitive->GetKernelW(); + conv_param->group_ = conv_primitive->GetGroup(); + conv_param->stride_h_ = conv_primitive->GetStrideH(); + conv_param->stride_w_ = conv_primitive->GetStrideW(); + + auto conv2d_lite_primitive = (lite::Conv2D *)primitive; + conv_param->pad_u_ = conv2d_lite_primitive->PadUp(); + conv_param->pad_d_ = conv2d_lite_primitive->PadDown(); + conv_param->pad_l_ = conv2d_lite_primitive->PadLeft(); + conv_param->pad_r_ = conv2d_lite_primitive->PadRight(); + conv_param->dilation_h_ = conv_primitive->GetDilateH(); + conv_param->dilation_w_ = conv_primitive->GetDilateW(); + conv_param->input_channel_ = conv_primitive->GetChannelIn(); + conv_param->output_channel_ = conv_primitive->GetChannelOut(); + conv_param->group_ = conv_primitive->GetGroup(); + auto act_type = conv_primitive->GetActivationType(); + switch (act_type) { + case schema::ActivationType_RELU: + conv_param->act_type_ = ActType_Relu; + break; + case schema::ActivationType_RELU6: + conv_param->act_type_ = ActType_Relu6; + break; + default: + conv_param->act_type_ = ActType_No; + break; + } + return reinterpret_cast(conv_param); +} +Registry Conv2DParameterRegistry(schema::PrimitiveType_Conv2D, PopulateConvParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/crop_populate.cc b/mindspore/lite/src/ops/populate/crop_populate.cc new file mode 100644 index 0000000000..a59ba5a2d6 --- /dev/null +++ b/mindspore/lite/src/ops/populate/crop_populate.cc @@ -0,0 +1,49 @@ +/** + * Copyright 2019-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/ops/crop.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/crop_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateCropParameter(const mindspore::lite::PrimitiveC *primitive) { + auto param = reinterpret_cast(const_cast(primitive)); + auto param_offset = param->GetOffsets(); + if (param_offset.size() > CROP_OFFSET_MAX_SIZE) { + MS_LOG(ERROR) << "crop_param offset size(" << param_offset.size() << ") should <= " << CROP_OFFSET_MAX_SIZE; + return nullptr; + } + CropParameter *crop_param = reinterpret_cast(malloc(sizeof(CropParameter))); + if (crop_param == nullptr) { + MS_LOG(ERROR) << "malloc CropParameter failed."; + return nullptr; + } + memset(crop_param, 0, sizeof(CropParameter)); + crop_param->op_parameter_.type_ = primitive->Type(); + crop_param->axis_ = param->GetAxis(); + crop_param->offset_size_ = param_offset.size(); + for (size_t i = 0; i < param_offset.size(); ++i) { + crop_param->offset_[i] = param_offset[i]; + } + return reinterpret_cast(crop_param); +} +Registry CropParameterRegistry(schema::PrimitiveType_Crop, PopulateCropParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/custom_extract_features_populate.cc b/mindspore/lite/src/ops/populate/custom_extract_features_populate.cc new file mode 100644 index 0000000000..9d755dd15c --- /dev/null +++ b/mindspore/lite/src/ops/populate/custom_extract_features_populate.cc @@ -0,0 +1,38 @@ +/** + * 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/ops/custom_extract_features.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateExtractFeaturesParameter(const mindspore::lite::PrimitiveC *primitive) { + OpParameter *param = reinterpret_cast(malloc(sizeof(OpParameter))); + if (param == nullptr) { + MS_LOG(ERROR) << "new OpParameter failed."; + return nullptr; + } + memset(param, 0, sizeof(OpParameter)); + param->type_ = primitive->Type(); + return param; +} +Registry CustomExtractFeaturesParameterRegistry(schema::PrimitiveType_CustomExtractFeatures, + PopulateExtractFeaturesParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/custom_normalize_populate.cc b/mindspore/lite/src/ops/populate/custom_normalize_populate.cc new file mode 100644 index 0000000000..2a127670da --- /dev/null +++ b/mindspore/lite/src/ops/populate/custom_normalize_populate.cc @@ -0,0 +1,37 @@ +/** + * 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/ops/custom_normalize.h" +#include "src/common/string_util.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateCustomNormalizeParameter(const mindspore::lite::PrimitiveC *primitive) { + OpParameter *param = reinterpret_cast(malloc(sizeof(OpParameter))); + if (param == nullptr) { + MS_LOG(ERROR) << "new OpParameter failed."; + return nullptr; + } + memset(param, 0, sizeof(OpParameter)); + param->type_ = primitive->Type(); + return param; +} +Registry CustomNormalizeParameterRegistry(schema::PrimitiveType_CustomNormalize, PopulateCustomNormalizeParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/custom_predict_populate.cc b/mindspore/lite/src/ops/populate/custom_predict_populate.cc new file mode 100644 index 0000000000..bf00613e81 --- /dev/null +++ b/mindspore/lite/src/ops/populate/custom_predict_populate.cc @@ -0,0 +1,40 @@ +/** + * 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/ops/custom_predict.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/predict_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateCustomPredictParameter(const mindspore::lite::PrimitiveC *primitive) { + PredictParameter *param = reinterpret_cast(malloc(sizeof(PredictParameter))); + if (param == nullptr) { + MS_LOG(ERROR) << "malloc param failed."; + return nullptr; + } + memset(param, 0, sizeof(PredictParameter)); + param->op_parameter_.type_ = primitive->Type(); + auto prim = reinterpret_cast(const_cast(primitive)); + param->output_num = prim->GetOutputNum(); + param->weight_threshold = prim->GetWeightThreshold(); + return reinterpret_cast(param); +} +Registry CustomPredictParameterRegistry(schema::PrimitiveType_CustomPredict, PopulateCustomPredictParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/deconv2d_populate.cc b/mindspore/lite/src/ops/populate/deconv2d_populate.cc new file mode 100644 index 0000000000..6abd355e93 --- /dev/null +++ b/mindspore/lite/src/ops/populate/deconv2d_populate.cc @@ -0,0 +1,67 @@ +/** + * Copyright 2019-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/ops/deconv2d.h" +#include "src/common/log_adapter.h" + +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/conv_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateDeconvParameter(const mindspore::lite::PrimitiveC *primitive) { + ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); + if (conv_param == nullptr) { + MS_LOG(ERROR) << "malloc ConvParameter failed."; + return nullptr; + } + memset(conv_param, 0, sizeof(ConvParameter)); + conv_param->op_parameter_.type_ = primitive->Type(); + auto conv_primitive = + reinterpret_cast(const_cast(primitive)); + conv_param->kernel_h_ = conv_primitive->GetKernelH(); + conv_param->kernel_w_ = conv_primitive->GetKernelW(); + conv_param->stride_h_ = conv_primitive->GetStrideH(); + conv_param->stride_w_ = conv_primitive->GetStrideW(); + + auto deconv_lite_primitive = (lite::DeConv2D *)primitive; + conv_param->pad_u_ = deconv_lite_primitive->PadUp(); + conv_param->pad_d_ = deconv_lite_primitive->PadDown(); + conv_param->pad_l_ = deconv_lite_primitive->PadLeft(); + conv_param->pad_r_ = deconv_lite_primitive->PadRight(); + conv_param->dilation_h_ = conv_primitive->GetDilateH(); + conv_param->dilation_w_ = conv_primitive->GetDilateW(); + auto act_type = conv_primitive->GetActivationType(); + switch (act_type) { + case schema::ActivationType_RELU: + conv_param->act_type_ = ActType_Relu; + break; + case schema::ActivationType_RELU6: + conv_param->act_type_ = ActType_Relu6; + break; + default: + conv_param->act_type_ = ActType_No; + break; + } + return reinterpret_cast(conv_param); +} + +Registry DeConv2DParameterRegistry(schema::PrimitiveType_DeConv2D, PopulateDeconvParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/dedepthwise_conv2d_populate.cc b/mindspore/lite/src/ops/populate/dedepthwise_conv2d_populate.cc new file mode 100644 index 0000000000..732c26cac3 --- /dev/null +++ b/mindspore/lite/src/ops/populate/dedepthwise_conv2d_populate.cc @@ -0,0 +1,65 @@ +/** + * Copyright 2019-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/ops/dedepthwise_conv2d.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/conv_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateDeconvDwParameter(const mindspore::lite::PrimitiveC *primitive) { + ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); + if (conv_param == nullptr) { + MS_LOG(ERROR) << "malloc ConvParameter failed."; + return nullptr; + } + memset(conv_param, 0, sizeof(ConvParameter)); + conv_param->op_parameter_.type_ = primitive->Type(); + auto conv_primitive = + reinterpret_cast(const_cast(primitive)); + conv_param->kernel_h_ = conv_primitive->GetKernelH(); + conv_param->kernel_w_ = conv_primitive->GetKernelW(); + conv_param->stride_h_ = conv_primitive->GetStrideH(); + conv_param->stride_w_ = conv_primitive->GetStrideW(); + + auto deconvdw_lite_primitive = (mindspore::lite::DeDepthwiseConv2D *)primitive; + conv_param->pad_u_ = deconvdw_lite_primitive->PadUp(); + conv_param->pad_d_ = deconvdw_lite_primitive->PadDown(); + conv_param->pad_l_ = deconvdw_lite_primitive->PadLeft(); + conv_param->pad_r_ = deconvdw_lite_primitive->PadRight(); + conv_param->dilation_h_ = conv_primitive->GetDilateH(); + conv_param->dilation_w_ = conv_primitive->GetDilateW(); + auto act_type = conv_primitive->GetActivationType(); + switch (act_type) { + case schema::ActivationType_RELU: + conv_param->act_type_ = ActType_Relu; + break; + case schema::ActivationType_RELU6: + conv_param->act_type_ = ActType_Relu6; + break; + default: + conv_param->act_type_ = ActType_No; + break; + } + return reinterpret_cast(conv_param); +} + +Registry DeDepthwiseConv2DParameterRegistry(schema::PrimitiveType_DeDepthwiseConv2D, PopulateDeconvDwParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/depth_to_space_populate.cc b/mindspore/lite/src/ops/populate/depth_to_space_populate.cc new file mode 100644 index 0000000000..4b4227a886 --- /dev/null +++ b/mindspore/lite/src/ops/populate/depth_to_space_populate.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2019-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/ops/depth_to_space.h" +#include "src/common/common.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/depth_to_space_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateDepthToSpaceParameter(const mindspore::lite::PrimitiveC *primitive) { + DepthToSpaceParameter *depth_space_param = + reinterpret_cast(malloc(sizeof(DepthToSpaceParameter))); + if (depth_space_param == nullptr) { + MS_LOG(ERROR) << "malloc DepthToSpaceParameter failed."; + return nullptr; + } + memset(depth_space_param, 0, sizeof(DepthToSpaceParameter)); + auto param = reinterpret_cast(const_cast(primitive)); + depth_space_param->op_parameter_.type_ = primitive->Type(); + depth_space_param->block_size_ = param->GetBlockSize(); + return reinterpret_cast(depth_space_param); +} + +Registry DepthToSpaceParameterRegistry(schema::PrimitiveType_DepthToSpace, PopulateDepthToSpaceParameter); + +} // namespace lite + +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/depthwise_conv2d_populate.cc b/mindspore/lite/src/ops/populate/depthwise_conv2d_populate.cc new file mode 100644 index 0000000000..10ea2f036e --- /dev/null +++ b/mindspore/lite/src/ops/populate/depthwise_conv2d_populate.cc @@ -0,0 +1,67 @@ +/** + * Copyright 2019-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/ops/depthwise_conv2d.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/conv_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateConvDwParameter(const mindspore::lite::PrimitiveC *primitive) { + ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); + if (conv_param == nullptr) { + MS_LOG(ERROR) << "malloc ConvParameter failed."; + return nullptr; + } + memset(conv_param, 0, sizeof(ConvParameter)); + conv_param->op_parameter_.type_ = primitive->Type(); + + auto conv_primitive = + reinterpret_cast(const_cast(primitive)); + conv_param->kernel_h_ = conv_primitive->GetKernelH(); + conv_param->kernel_w_ = conv_primitive->GetKernelW(); + conv_param->stride_h_ = conv_primitive->GetStrideH(); + conv_param->stride_w_ = conv_primitive->GetStrideW(); + + auto convdw_lite_primitive = (lite::DepthwiseConv2D *)primitive; + conv_param->pad_u_ = convdw_lite_primitive->PadUp(); + conv_param->pad_d_ = convdw_lite_primitive->PadDown(); + conv_param->pad_l_ = convdw_lite_primitive->PadLeft(); + conv_param->pad_r_ = convdw_lite_primitive->PadRight(); + conv_param->input_channel_ = convdw_lite_primitive->GetInputChannel(); + conv_param->dilation_h_ = conv_primitive->GetDilateH(); + conv_param->dilation_w_ = conv_primitive->GetDilateW(); + auto act_type = conv_primitive->GetActivationType(); + switch (act_type) { + case schema::ActivationType_RELU: + conv_param->act_type_ = ActType_Relu; + break; + case schema::ActivationType_RELU6: + conv_param->act_type_ = ActType_Relu6; + break; + default: + conv_param->act_type_ = ActType_No; + break; + } + return reinterpret_cast(conv_param); +} + +Registry DepthwiseConv2DParameterRegistry(schema::PrimitiveType_DepthwiseConv2D, PopulateConvDwParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/detection_post_process_populate.cc b/mindspore/lite/src/ops/populate/detection_post_process_populate.cc new file mode 100644 index 0000000000..51895495cd --- /dev/null +++ b/mindspore/lite/src/ops/populate/detection_post_process_populate.cc @@ -0,0 +1,53 @@ +/** + * Copyright 2019-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/ops/detection_post_process.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/detection_post_process_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateDetectionPostProcessParameter(const mindspore::lite::PrimitiveC *primitive) { + DetectionPostProcessParameter *detection_post_process_parameter = + reinterpret_cast(malloc(sizeof(DetectionPostProcessParameter))); + if (detection_post_process_parameter == nullptr) { + MS_LOG(ERROR) << "malloc EluParameter failed."; + return nullptr; + } + memset(detection_post_process_parameter, 0, sizeof(DetectionPostProcessParameter)); + detection_post_process_parameter->op_parameter_.type_ = primitive->Type(); + auto param = + reinterpret_cast(const_cast(primitive)); + detection_post_process_parameter->h_scale_ = param->GetHScale(); + detection_post_process_parameter->w_scale_ = param->GetWScale(); + detection_post_process_parameter->x_scale_ = param->GetXScale(); + detection_post_process_parameter->y_scale_ = param->GetYScale(); + detection_post_process_parameter->nms_iou_threshold_ = param->GetNmsIouThreshold(); + detection_post_process_parameter->nms_score_threshold_ = param->GetNmsScoreThreshold(); + detection_post_process_parameter->max_detections_ = param->GetMaxDetections(); + detection_post_process_parameter->detections_per_class_ = param->GetDetectionsPerClass(); + detection_post_process_parameter->max_classes_per_detection_ = param->GetMaxClassesPerDetection(); + detection_post_process_parameter->num_classes_ = param->GetNumClasses(); + detection_post_process_parameter->use_regular_nms_ = param->GetUseRegularNms(); + return reinterpret_cast(detection_post_process_parameter); +} +Registry DetectionPostProcessParameterRegistry(schema::PrimitiveType_DetectionPostProcess, + PopulateDetectionPostProcessParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/div_populate.cc b/mindspore/lite/src/ops/populate/div_populate.cc new file mode 100644 index 0000000000..a2e20bb9de --- /dev/null +++ b/mindspore/lite/src/ops/populate/div_populate.cc @@ -0,0 +1,47 @@ +/** + * Copyright 2019-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/ops/div.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateDivParameter(const mindspore::lite::PrimitiveC *primitive) { + ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); + if (arithmetic_param == nullptr) { + MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; + return nullptr; + } + memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); + arithmetic_param->op_parameter_.type_ = primitive->Type(); + arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); + arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); + arithmetic_param->activation_type_ = + reinterpret_cast(const_cast(primitive))->GetActivationType(); + auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); + memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); + memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); + memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + return reinterpret_cast(arithmetic_param); +} +Registry DivParameterRegistry(schema::PrimitiveType_Div, PopulateDivParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/eltwise_populate.cc b/mindspore/lite/src/ops/populate/eltwise_populate.cc new file mode 100644 index 0000000000..3531bb304b --- /dev/null +++ b/mindspore/lite/src/ops/populate/eltwise_populate.cc @@ -0,0 +1,52 @@ +/** + * Copyright 2019-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/ops/eltwise.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/arithmetic_common.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateEltwiseParameter(const mindspore::lite::PrimitiveC *primitive) { + ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); + if (arithmetic_param == nullptr) { + MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; + return nullptr; + } + memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); + auto eltwise = reinterpret_cast(const_cast(primitive)); + switch (eltwise->GetMode()) { + case schema::EltwiseMode_PROD: + arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Mul; + break; + case schema::EltwiseMode_SUM: + arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Add; + break; + case schema::EltwiseMode_MAXIMUM: + arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Maximum; + break; + default: + free(arithmetic_param); + return nullptr; + } + return reinterpret_cast(arithmetic_param); +} +Registry EltwiseParameterRegistry(schema::PrimitiveType_Eltwise, PopulateEltwiseParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/elu_populate.cc b/mindspore/lite/src/ops/populate/elu_populate.cc new file mode 100644 index 0000000000..107e9f4135 --- /dev/null +++ b/mindspore/lite/src/ops/populate/elu_populate.cc @@ -0,0 +1,39 @@ +/** + * Copyright 2019-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/ops/elu.h" +#include "nnacl/fp32/elu.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateEluParameter(const mindspore::lite::PrimitiveC *primitive) { + EluParameter *elu_parameter = reinterpret_cast(malloc(sizeof(EluParameter))); + if (elu_parameter == nullptr) { + MS_LOG(ERROR) << "malloc EluParameter failed."; + return nullptr; + } + memset(elu_parameter, 0, sizeof(EluParameter)); + elu_parameter->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + elu_parameter->alpha_ = param->GetAlpha(); + return reinterpret_cast(elu_parameter); +} +Registry EluParameterRegistry(schema::PrimitiveType_Elu, PopulateEluParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/embedding_lookup_populate.cc b/mindspore/lite/src/ops/populate/embedding_lookup_populate.cc new file mode 100644 index 0000000000..18fa81e1b0 --- /dev/null +++ b/mindspore/lite/src/ops/populate/embedding_lookup_populate.cc @@ -0,0 +1,49 @@ +/** + * Copyright 2019-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/ops/embedding_lookup.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/embedding_lookup.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateEmbeddingLookupParameter(const mindspore::lite::PrimitiveC *primitive) { + EmbeddingLookupParameter *embedding_lookup_parameter = + reinterpret_cast(malloc(sizeof(EmbeddingLookupParameter))); + if (embedding_lookup_parameter == nullptr) { + MS_LOG(ERROR) << "malloc EmbeddingLookupParameter failed."; + return nullptr; + } + memset(embedding_lookup_parameter, 0, sizeof(EmbeddingLookupParameter)); + embedding_lookup_parameter->op_parameter_.type_ = primitive->Type(); + auto param = + reinterpret_cast(const_cast(primitive)); + embedding_lookup_parameter->max_norm_ = param->GetMaxNorm(); + if (embedding_lookup_parameter->max_norm_ < 0) { + MS_LOG(ERROR) << "Embedding lookup max norm should be positive number, got " + << embedding_lookup_parameter->max_norm_; + free(embedding_lookup_parameter); + return nullptr; + } + return reinterpret_cast(embedding_lookup_parameter); +} + +Registry EmbeddingLookupParameterRegistry(schema::PrimitiveType_EmbeddingLookup, PopulateEmbeddingLookupParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/exp_populate.cc b/mindspore/lite/src/ops/populate/exp_populate.cc new file mode 100644 index 0000000000..0ceee08e05 --- /dev/null +++ b/mindspore/lite/src/ops/populate/exp_populate.cc @@ -0,0 +1,46 @@ +/** + * Copyright 2019-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/ops/exp.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/exp.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateExpParameter(const mindspore::lite::PrimitiveC *primitive) { + ExpParameter *exp_parameter = reinterpret_cast(malloc(sizeof(ExpParameter))); + if (exp_parameter == nullptr) { + MS_LOG(ERROR) << "malloc ExpParameter failed."; + return nullptr; + } + memset(exp_parameter, 0, sizeof(ExpParameter)); + exp_parameter->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + exp_parameter->base_ = param->GetBase(); + exp_parameter->scale_ = param->GetScale(); + exp_parameter->shift_ = param->GetShift(); + if (exp_parameter->base_ != -1 && exp_parameter->base_ <= 0) { + MS_LOG(ERROR) << "Exp base must be strictly positive, got " << exp_parameter->base_; + free(exp_parameter); + return nullptr; + } + return reinterpret_cast(exp_parameter); +} + +Registry ExpParameterRegistry(schema::PrimitiveType_Exp, PopulateExpParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/expand_dims_populate.cc b/mindspore/lite/src/ops/populate/expand_dims_populate.cc new file mode 100644 index 0000000000..cb48fe701a --- /dev/null +++ b/mindspore/lite/src/ops/populate/expand_dims_populate.cc @@ -0,0 +1,41 @@ +/** + * Copyright 2019-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/ops/expand_dims.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/expandDims.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateExpandDimsParameter(const mindspore::lite::PrimitiveC *primitive) { + auto param = reinterpret_cast(const_cast(primitive)); + ExpandDimsParameter *expand_dims_param = reinterpret_cast(malloc(sizeof(ExpandDimsParameter))); + if (expand_dims_param == nullptr) { + MS_LOG(ERROR) << "malloc ExpandDimsParameter failed."; + return nullptr; + } + memset(expand_dims_param, 0, sizeof(ExpandDimsParameter)); + expand_dims_param->op_parameter_.type_ = primitive->Type(); + expand_dims_param->dim_ = param->GetDim(); + return reinterpret_cast(expand_dims_param); +} + +Registry ExpandDimsParameterRegistry(schema::PrimitiveType_ExpandDims, PopulateExpandDimsParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/fill_populate.cc b/mindspore/lite/src/ops/populate/fill_populate.cc new file mode 100644 index 0000000000..a3c3d75b86 --- /dev/null +++ b/mindspore/lite/src/ops/populate/fill_populate.cc @@ -0,0 +1,46 @@ +/** + * Copyright 2019-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/ops/fill.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/fill.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateFillParameter(const mindspore::lite::PrimitiveC *primitive) { + const auto param = reinterpret_cast(const_cast(primitive)); + FillParameter *fill_param = reinterpret_cast(malloc(sizeof(FillParameter))); + if (fill_param == nullptr) { + MS_LOG(ERROR) << "malloc FillParameter failed."; + return nullptr; + } + memset(fill_param, 0, sizeof(FillParameter)); + fill_param->op_parameter_.type_ = primitive->Type(); + auto flatDims = param->GetDims(); + fill_param->num_dims_ = flatDims.size(); + int i = 0; + for (auto iter = flatDims.begin(); iter != flatDims.end(); iter++) { + fill_param->dims_[i++] = *iter; + } + return reinterpret_cast(fill_param); +} + +Registry FillParameterRegistry(schema::PrimitiveType_Fill, PopulateFillParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/flatten_populate.cc b/mindspore/lite/src/ops/populate/flatten_populate.cc new file mode 100644 index 0000000000..52d5877320 --- /dev/null +++ b/mindspore/lite/src/ops/populate/flatten_populate.cc @@ -0,0 +1,37 @@ +/** + * 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/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/flatten.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateFlattenParameter(const mindspore::lite::PrimitiveC *primitive) { + FlattenParameter *flatten_param = reinterpret_cast(malloc(sizeof(FlattenParameter))); + if (flatten_param == nullptr) { + MS_LOG(ERROR) << "malloc FlattenParameter failed."; + return nullptr; + } + memset(flatten_param, 0, sizeof(FlattenParameter)); + flatten_param->op_parameter_.type_ = primitive->Type(); + return reinterpret_cast(flatten_param); +} + +Registry FlattenParameterRegistry(schema::PrimitiveType_Flatten, PopulateFlattenParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/full_connection_populate.cc b/mindspore/lite/src/ops/populate/full_connection_populate.cc new file mode 100644 index 0000000000..fafc985b64 --- /dev/null +++ b/mindspore/lite/src/ops/populate/full_connection_populate.cc @@ -0,0 +1,52 @@ +/** + * Copyright 2019-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/ops/full_connection.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/matmul_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateFullconnectionParameter(const mindspore::lite::PrimitiveC *primitive) { + auto param = + reinterpret_cast(const_cast(primitive)); + MatMulParameter *matmul_param = reinterpret_cast(malloc(sizeof(MatMulParameter))); + if (matmul_param == nullptr) { + MS_LOG(ERROR) << "malloc MatMulParameter failed."; + return nullptr; + } + memset(matmul_param, 0, sizeof(MatMulParameter)); + matmul_param->op_parameter_.type_ = primitive->Type(); + matmul_param->b_transpose_ = true; + matmul_param->a_transpose_ = false; + matmul_param->has_bias_ = param->GetHasBias(); + if (param->GetActivationType() == schema::ActivationType_RELU) { + matmul_param->act_type_ = ActType_Relu; + } else if (param->GetActivationType() == schema::ActivationType_RELU6) { + matmul_param->act_type_ = ActType_Relu6; + } else { + matmul_param->act_type_ = ActType_No; + } + + return reinterpret_cast(matmul_param); +} + +Registry FullConnectionParameterRegistry(schema::PrimitiveType_FullConnection, PopulateFullconnectionParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/fused_batchnorm_populate.cc b/mindspore/lite/src/ops/populate/fused_batchnorm_populate.cc new file mode 100644 index 0000000000..c7825066f0 --- /dev/null +++ b/mindspore/lite/src/ops/populate/fused_batchnorm_populate.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2019-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/ops/fused_batchnorm.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/batchnorm_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateFusedBatchNorm(const mindspore::lite::PrimitiveC *primitive) { + BatchNormParameter *batch_norm_param = reinterpret_cast(malloc(sizeof(BatchNormParameter))); + if (batch_norm_param == nullptr) { + MS_LOG(ERROR) << "malloc BatchNormParameter failed."; + return nullptr; + } + memset(batch_norm_param, 0, sizeof(BatchNormParameter)); + batch_norm_param->op_parameter_.type_ = primitive->Type(); + auto param = + reinterpret_cast(const_cast(primitive)); + batch_norm_param->epsilon_ = param->GetEpsilon(); + batch_norm_param->momentum_ = param->GetMomentum(); + batch_norm_param->fused_ = true; + return reinterpret_cast(batch_norm_param); +} + +Registry FusedBatchNormParameterRegistry(schema::PrimitiveType_FusedBatchNorm, PopulateFusedBatchNorm); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/gather_nd_populate.cc b/mindspore/lite/src/ops/populate/gather_nd_populate.cc new file mode 100644 index 0000000000..045dc9e3fd --- /dev/null +++ b/mindspore/lite/src/ops/populate/gather_nd_populate.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2019-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/ops/gather_nd.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/gatherNd.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateGatherNdParameter(const mindspore::lite::PrimitiveC *primitive) { + GatherNdParameter *gather_nd_param = reinterpret_cast(malloc(sizeof(GatherNdParameter))); + if (gather_nd_param == nullptr) { + MS_LOG(ERROR) << "malloc GatherNdParameter failed."; + return nullptr; + } + memset(gather_nd_param, 0, sizeof(GatherNdParameter)); + gather_nd_param->op_parameter_.type_ = primitive->Type(); + auto gatherNd_attr = + reinterpret_cast(const_cast(primitive)); + gather_nd_param->batchDims_ = gatherNd_attr->GetBatchDims(); + return reinterpret_cast(gather_nd_param); +} + +Registry GatherNdParameterRegistry(schema::PrimitiveType_GatherNd, PopulateGatherNdParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/gather_populate.cc b/mindspore/lite/src/ops/populate/gather_populate.cc new file mode 100644 index 0000000000..d42b1ef9e4 --- /dev/null +++ b/mindspore/lite/src/ops/populate/gather_populate.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2019-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/ops/gather.h" +#include "src/common/log_adapter.h" +#include "src/tensor.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/gather_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateGatherParameter(const mindspore::lite::PrimitiveC *primitive) { + auto gather_attr = reinterpret_cast(const_cast(primitive)); + GatherParameter *gather_param = reinterpret_cast(malloc(sizeof(GatherParameter))); + if (gather_param == nullptr) { + MS_LOG(ERROR) << "malloc GatherParameter failed."; + return nullptr; + } + memset(gather_param, 0, sizeof(GatherParameter)); + gather_param->op_parameter_.type_ = primitive->Type(); + gather_param->axis_ = gather_attr->GetAxis(); + gather_param->batchDims_ = gather_attr->GetBatchDims(); + return reinterpret_cast(gather_param); +} +Registry GatherParameterRegistry(schema::PrimitiveType_Gather, PopulateGatherParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/hashtable_lookup_populate.cc b/mindspore/lite/src/ops/populate/hashtable_lookup_populate.cc new file mode 100644 index 0000000000..3b97fa9f5f --- /dev/null +++ b/mindspore/lite/src/ops/populate/hashtable_lookup_populate.cc @@ -0,0 +1,37 @@ +/** + * 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/ops/hashtable_lookup.h" +#include "src/common/string_util.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateHashtableLookupParameter(const mindspore::lite::PrimitiveC *primitive) { + OpParameter *param = reinterpret_cast(malloc(sizeof(OpParameter))); + if (param == nullptr) { + MS_LOG(ERROR) << "new OpParameter failed."; + return nullptr; + } + memset(param, 0, sizeof(OpParameter)); + param->type_ = primitive->Type(); + return param; +} +Registry HashtableLookupParameterRegistry(schema::PrimitiveType_HashtableLookup, PopulateHashtableLookupParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/instance_norm_populate.cc b/mindspore/lite/src/ops/populate/instance_norm_populate.cc new file mode 100644 index 0000000000..91f9450c5b --- /dev/null +++ b/mindspore/lite/src/ops/populate/instance_norm_populate.cc @@ -0,0 +1,42 @@ +/** + * 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/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "src/ops/instance_norm.h" +#include "nnacl/instance_norm_parameter.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateInstanceNorm(const mindspore::lite::PrimitiveC *primitive) { + const auto param = + reinterpret_cast(const_cast(primitive)); + InstanceNormParameter *instance_norm_param = + reinterpret_cast(malloc(sizeof(InstanceNormParameter))); + if (instance_norm_param == nullptr) { + MS_LOG(ERROR) << "malloc InstanceNormParameter failed."; + return nullptr; + } + memset(instance_norm_param, 0, sizeof(InstanceNormParameter)); + instance_norm_param->op_parameter_.type_ = primitive->Type(); + instance_norm_param->epsilon_ = param->GetEpsilon(); + instance_norm_param->fused_ = false; + return reinterpret_cast(instance_norm_param); +} + +Registry InstanceNormParameterRegistry(schema::PrimitiveType_L2Norm, PopulateInstanceNorm); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/l2_norm_populate.cc b/mindspore/lite/src/ops/populate/l2_norm_populate.cc new file mode 100644 index 0000000000..9f3e8a1aa0 --- /dev/null +++ b/mindspore/lite/src/ops/populate/l2_norm_populate.cc @@ -0,0 +1,62 @@ +/** + * Copyright 2019-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/ops/l2_norm.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/l2_norm_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateL2NormParameter(const mindspore::lite::PrimitiveC *primitive) { + L2NormParameter *l2_norm_parameter = reinterpret_cast(malloc(sizeof(L2NormParameter))); + if (l2_norm_parameter == nullptr) { + MS_LOG(ERROR) << "malloc L2NormParameter failed."; + return nullptr; + } + memset(l2_norm_parameter, 0, sizeof(L2NormParameter)); + l2_norm_parameter->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + auto axis_vec = param->GetAxis(); + l2_norm_parameter->axis_num_ = axis_vec.size(); + l2_norm_parameter->axis_ = reinterpret_cast(malloc(axis_vec.size() * sizeof(int))); + if (l2_norm_parameter->axis_ == nullptr) { + MS_LOG(ERROR) << "malloc axis_ data failed"; + free(l2_norm_parameter); + return nullptr; + } + for (size_t i = 0; i < axis_vec.size(); i++) { + l2_norm_parameter->axis_[i] = axis_vec[i]; + } + if (param->GetEpsilon() < 1e-6) { + l2_norm_parameter->epsilon_ = 1e-6; + } else { + l2_norm_parameter->epsilon_ = param->GetEpsilon(); + } + if (param->GetActivationType() == static_cast(schema::ActivationType_RELU)) { + l2_norm_parameter->act_type_ = ActType_Relu; + } else if (param->GetActivationType() == static_cast(schema::ActivationType_RELU6)) { + l2_norm_parameter->act_type_ = ActType_Relu6; + } else { + l2_norm_parameter->act_type_ = ActType_No; + } + return reinterpret_cast(l2_norm_parameter); +} +Registry L2NormParameterRegistry(schema::PrimitiveType_L2Norm, PopulateL2NormParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/layer_norm_populate.cc b/mindspore/lite/src/ops/populate/layer_norm_populate.cc new file mode 100644 index 0000000000..336771aacb --- /dev/null +++ b/mindspore/lite/src/ops/populate/layer_norm_populate.cc @@ -0,0 +1,47 @@ +/** + * Copyright 2019-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 "nnacl/layer_norm_parameter.h" +#include "src/ops/layer_norm.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateLayerNormParameter(const mindspore::lite::PrimitiveC *primitive) { + auto layer_norm_parameter = reinterpret_cast(malloc(sizeof(LayerNormParameter))); + if (layer_norm_parameter == nullptr) { + MS_LOG(ERROR) << "malloc LayerNormParameter failed."; + return nullptr; + } + memset(layer_norm_parameter, 0, sizeof(LayerNormParameter)); + layer_norm_parameter->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + auto normalized_shape = param->GetNormalizedShape(); + layer_norm_parameter->normalized_dims_ = normalized_shape.size(); + layer_norm_parameter->normalized_shape_ = reinterpret_cast(malloc(normalized_shape.size() * sizeof(int))); + for (size_t i = 0; i < normalized_shape.size(); i++) { + layer_norm_parameter->normalized_shape_[i] = normalized_shape[i]; + } + layer_norm_parameter->epsilon_ = param->GetEpsilon(); + layer_norm_parameter->elementwise_affine_ = param->GetElementwiseAffine(); + + return reinterpret_cast(layer_norm_parameter); +} + +Registry LayerNormParameterRegistry(schema::PrimitiveType_LayerNorm, PopulateLayerNormParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/local_response_normalization_populate.cc b/mindspore/lite/src/ops/populate/local_response_normalization_populate.cc new file mode 100644 index 0000000000..b2260a712b --- /dev/null +++ b/mindspore/lite/src/ops/populate/local_response_normalization_populate.cc @@ -0,0 +1,47 @@ +/** + * Copyright 2019-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/ops/local_response_normalization.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/local_response_norm.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateLocalResponseNormParameter(const mindspore::lite::PrimitiveC *primitive) { + auto local_response_norm_attr = reinterpret_cast( + const_cast(primitive)); + LocalResponseNormParameter *lrn_param = + reinterpret_cast(malloc(sizeof(LocalResponseNormParameter))); + if (lrn_param == nullptr) { + MS_LOG(ERROR) << "malloc LocalResponseNormParameter failed."; + return nullptr; + } + memset(lrn_param, 0, sizeof(LocalResponseNormParameter)); + lrn_param->op_parameter_.type_ = primitive->Type(); + lrn_param->depth_radius_ = local_response_norm_attr->GetDepthRadius(); + lrn_param->bias_ = local_response_norm_attr->GetBias(); + lrn_param->alpha_ = local_response_norm_attr->GetAlpha(); + lrn_param->beta_ = local_response_norm_attr->GetBeta(); + return reinterpret_cast(lrn_param); +} + +Registry LocalResponseNormalizationParameterRegistry(schema::PrimitiveType_LocalResponseNormalization, + PopulateLocalResponseNormParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/lsh_projection_populate.cc b/mindspore/lite/src/ops/populate/lsh_projection_populate.cc new file mode 100644 index 0000000000..70fccf14da --- /dev/null +++ b/mindspore/lite/src/ops/populate/lsh_projection_populate.cc @@ -0,0 +1,40 @@ +/** + * 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/ops/lsh_projection.h" +#include "nnacl/lsh_projection_parameter.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateLshProjectionParameter(const mindspore::lite::PrimitiveC *primitive) { + LshProjectionParameter *lsh_project_param = + reinterpret_cast(malloc(sizeof(LshProjectionParameter))); + if (lsh_project_param == nullptr) { + MS_LOG(ERROR) << "malloc LshProjectionParameter failed."; + return nullptr; + } + memset(lsh_project_param, 0, sizeof(LshProjectionParameter)); + lsh_project_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + lsh_project_param->lsh_type_ = param->GetLshType(); + return reinterpret_cast(lsh_project_param); +} +Registry LshProjectionParameterRegistry(schema::PrimitiveType_LshProjection, PopulateLshProjectionParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/lstm_populate.cc b/mindspore/lite/src/ops/populate/lstm_populate.cc new file mode 100644 index 0000000000..182282d852 --- /dev/null +++ b/mindspore/lite/src/ops/populate/lstm_populate.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2019-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/ops/lstm.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/lstm.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateLstmParameter(const mindspore::lite::PrimitiveC *primitive) { + LstmParameter *lstm_param = reinterpret_cast(malloc(sizeof(LstmParameter))); + if (lstm_param == nullptr) { + MS_LOG(ERROR) << "malloc LstmParameter failed."; + return nullptr; + } + memset(lstm_param, 0, sizeof(LstmParameter)); + lstm_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + if (param == nullptr) { + free(lstm_param); + MS_LOG(ERROR) << "get Lstm param nullptr."; + return nullptr; + } + lstm_param->bidirectional_ = param->GetBidirection(); + return reinterpret_cast(lstm_param); +} +Registry LstmParameterRegistry(schema::PrimitiveType_Lstm, PopulateLstmParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/matmul_populate.cc b/mindspore/lite/src/ops/populate/matmul_populate.cc new file mode 100644 index 0000000000..3c824202dc --- /dev/null +++ b/mindspore/lite/src/ops/populate/matmul_populate.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2019-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/ops/matmul.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/matmul_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateMatMulParameter(const mindspore::lite::PrimitiveC *primitive) { + auto param = reinterpret_cast(const_cast(primitive)); + MatMulParameter *matmul_param = reinterpret_cast(malloc(sizeof(MatMulParameter))); + if (matmul_param == nullptr) { + MS_LOG(ERROR) << "malloc MatMulParameter failed."; + return nullptr; + } + memset(matmul_param, 0, sizeof(MatMulParameter)); + matmul_param->op_parameter_.type_ = primitive->Type(); + matmul_param->b_transpose_ = param->GetTransposeB(); + matmul_param->a_transpose_ = param->GetTransposeA(); + matmul_param->has_bias_ = false; + matmul_param->act_type_ = ActType_No; + return reinterpret_cast(matmul_param); +} +Registry MatMulParameterRegistry(schema::PrimitiveType_MatMul, PopulateMatMulParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/mean_populate.cc b/mindspore/lite/src/ops/populate/mean_populate.cc new file mode 100644 index 0000000000..28e429b5dc --- /dev/null +++ b/mindspore/lite/src/ops/populate/mean_populate.cc @@ -0,0 +1,52 @@ +/** + * Copyright 2019-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/ops/mean.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/reduce_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateMeanParameter(const mindspore::lite::PrimitiveC *primitive) { + ReduceParameter *mean_param = reinterpret_cast(malloc(sizeof(ReduceParameter))); + if (mean_param == nullptr) { + MS_LOG(ERROR) << "malloc ReduceParameter failed."; + return nullptr; + } + memset(mean_param, 0, sizeof(ReduceParameter)); + mean_param->op_parameter_.type_ = primitive->Type(); + auto mean = reinterpret_cast(const_cast(primitive)); + mean_param->keep_dims_ = mean->GetKeepDims(); + auto axisVector = mean->GetAxis(); + if (axisVector.size() > REDUCE_MAX_AXES_NUM) { + MS_LOG(ERROR) << "Reduce axes size " << axisVector.size() << " exceed limit " << REDUCE_MAX_AXES_NUM; + free(mean_param); + return nullptr; + } + mean_param->num_axes_ = static_cast(axisVector.size()); + int i = 0; + for (auto iter = axisVector.begin(); iter != axisVector.end(); iter++) { + mean_param->axes_[i++] = *iter; + } + mean_param->mode_ = static_cast(schema::ReduceMode_ReduceMean); + return reinterpret_cast(mean_param); +} +Registry MeanParameterRegistry(schema::PrimitiveType_Mean, PopulateMeanParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/mul_populate.cc b/mindspore/lite/src/ops/populate/mul_populate.cc new file mode 100644 index 0000000000..81011ac1bd --- /dev/null +++ b/mindspore/lite/src/ops/populate/mul_populate.cc @@ -0,0 +1,48 @@ +/** + * Copyright 2019-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/ops/mul.h" +#include "nnacl/arithmetic_common.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateMulParameter(const mindspore::lite::PrimitiveC *primitive) { + ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); + if (arithmetic_param == nullptr) { + MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; + return nullptr; + } + memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); + arithmetic_param->op_parameter_.type_ = primitive->Type(); + arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); + arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); + arithmetic_param->activation_type_ = + reinterpret_cast(const_cast(primitive))->GetActivationType(); + auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); + memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); + memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); + memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + return reinterpret_cast(arithmetic_param); +} +Registry MulParameterRegistry(schema::PrimitiveType_Mul, PopulateMulParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/nchw2nhwc_populate.cc b/mindspore/lite/src/ops/populate/nchw2nhwc_populate.cc new file mode 100644 index 0000000000..47ba44e401 --- /dev/null +++ b/mindspore/lite/src/ops/populate/nchw2nhwc_populate.cc @@ -0,0 +1,43 @@ +/** + * 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/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "src/common/common.h" +#include "nnacl/transpose.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateNchw2NhwcParameter(const mindspore::lite::PrimitiveC *primitive) { + TransposeParameter *parameter = reinterpret_cast(malloc(sizeof(TransposeParameter))); + if (parameter == nullptr) { + MS_LOG(ERROR) << "malloc OpParameter failed."; + return nullptr; + } + memset(parameter, 0, sizeof(OpParameter)); + parameter->op_parameter_.type_ = primitive->Type(); + parameter->num_axes_ = 4; + parameter->perm_[0] = 0; + parameter->perm_[1] = 2; + parameter->perm_[2] = 3; + parameter->perm_[3] = 1; + return reinterpret_cast(parameter); +} +Registry Nchw2NhwcParameterRegistry(schema::PrimitiveType_Nchw2Nhwc, PopulateNchw2NhwcParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/nhwc2nchw_populate.cc b/mindspore/lite/src/ops/populate/nhwc2nchw_populate.cc new file mode 100644 index 0000000000..5156fa0b25 --- /dev/null +++ b/mindspore/lite/src/ops/populate/nhwc2nchw_populate.cc @@ -0,0 +1,44 @@ +/** + * 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/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "src/common/common.h" +#include "nnacl/transpose.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateNhwc2NchwParameter(const mindspore::lite::PrimitiveC *primitive) { + TransposeParameter *parameter = reinterpret_cast(malloc(sizeof(TransposeParameter))); + if (parameter == nullptr) { + MS_LOG(ERROR) << "malloc OpParameter failed."; + return nullptr; + } + memset(parameter, 0, sizeof(OpParameter)); + parameter->op_parameter_.type_ = primitive->Type(); + parameter->num_axes_ = 4; + parameter->perm_[0] = 0; + parameter->perm_[1] = 3; + parameter->perm_[2] = 1; + parameter->perm_[3] = 2; + return reinterpret_cast(parameter); +} + +Registry Nhwc2NchwParameterRegistry(schema::PrimitiveType_Nhwc2Nchw, PopulateNhwc2NchwParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/one_hot_populate.cc b/mindspore/lite/src/ops/populate/one_hot_populate.cc new file mode 100644 index 0000000000..fa470131b0 --- /dev/null +++ b/mindspore/lite/src/ops/populate/one_hot_populate.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2019-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/ops/one_hot.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/one_hot.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateOneHotParameter(const mindspore::lite::PrimitiveC *primitive) { + OneHotParameter *one_hot_param = reinterpret_cast(malloc(sizeof(OneHotParameter))); + if (one_hot_param == nullptr) { + MS_LOG(ERROR) << "malloc OneHotParameter failed."; + return nullptr; + } + memset(one_hot_param, 0, sizeof(OneHotParameter)); + one_hot_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + if (param == nullptr) { + free(one_hot_param); + MS_LOG(ERROR) << "get OneHot param nullptr."; + return nullptr; + } + one_hot_param->axis_ = param->GetAxis(); + return reinterpret_cast(one_hot_param); +} +Registry OneHotParameterRegistry(schema::PrimitiveType_OneHot, PopulateOneHotParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/p_relu_populate.cc b/mindspore/lite/src/ops/populate/p_relu_populate.cc new file mode 100644 index 0000000000..d666069659 --- /dev/null +++ b/mindspore/lite/src/ops/populate/p_relu_populate.cc @@ -0,0 +1,40 @@ +/** + * Copyright 2019-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/ops/p_relu.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/prelu_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulatePReLUParameter(const mindspore::lite::PrimitiveC *primitive) { + auto param = reinterpret_cast(const_cast(primitive)); + PReluParameter *prelu_param = reinterpret_cast(malloc(sizeof(PReluParameter))); + if (prelu_param == nullptr) { + MS_LOG(ERROR) << "malloc PReluParameter failed."; + return nullptr; + } + memset(prelu_param, 0, sizeof(PReluParameter)); + prelu_param->op_parameter_.type_ = primitive->Type(); + prelu_param->channelShared = param->GetChannelShared(); + return reinterpret_cast(prelu_param); +} +Registry PReLUParameterRegistry(schema::PrimitiveType_PReLU, PopulatePReLUParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/pad_populate.cc b/mindspore/lite/src/ops/populate/pad_populate.cc new file mode 100644 index 0000000000..bc5b9eb2a4 --- /dev/null +++ b/mindspore/lite/src/ops/populate/pad_populate.cc @@ -0,0 +1,58 @@ +/** + * Copyright 2019-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/ops/pad.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/pad_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulatePadParameter(const mindspore::lite::PrimitiveC *primitive) { + PadParameter *pad_param = reinterpret_cast(malloc(sizeof(PadParameter))); + if (pad_param == nullptr) { + MS_LOG(ERROR) << "malloc PadParameter failed."; + return nullptr; + } + memset(pad_param, 0, sizeof(PadParameter)); + pad_param->op_parameter_.type_ = primitive->Type(); + auto pad_node = reinterpret_cast(const_cast(primitive)); + pad_param->pad_mode_ = pad_node->GetPaddingMode(); + if (pad_param->pad_mode_ == static_cast(schema::PaddingMode_CONSTANT)) { + pad_param->constant_value_ = pad_node->GetConstantValue(); + auto size = pad_node->GetPaddings().size(); + if (size > MAX_PAD_SIZE) { + MS_LOG(ERROR) << "Invalid padding size: " << size; + free(pad_param); + return nullptr; + } + + for (size_t i = 0; i < MAX_PAD_SIZE - size; ++i) { + pad_param->paddings_[i] = 0; + } + for (size_t i = 0; i < size; i++) { + pad_param->paddings_[MAX_PAD_SIZE - size + i] = pad_node->GetPaddings()[i]; + } + pad_param->padding_length = MAX_PAD_SIZE; + } + + return reinterpret_cast(pad_param); +} +Registry PadParameterRegistry(schema::PrimitiveType_Pad, PopulatePadParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/pooling_populate.cc b/mindspore/lite/src/ops/populate/pooling_populate.cc new file mode 100644 index 0000000000..828d58fbaf --- /dev/null +++ b/mindspore/lite/src/ops/populate/pooling_populate.cc @@ -0,0 +1,88 @@ +/** + * Copyright 2019-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/ops/pooling.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/pooling_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulatePoolingParameter(const mindspore::lite::PrimitiveC *primitive) { + auto pooling_primitive = + reinterpret_cast(const_cast(primitive)); + PoolingParameter *pooling_param = reinterpret_cast(malloc(sizeof(PoolingParameter))); + if (pooling_param == nullptr) { + MS_LOG(ERROR) << "malloc PoolingParameter failed."; + return nullptr; + } + memset(pooling_param, 0, sizeof(PoolingParameter)); + pooling_param->op_parameter_.type_ = primitive->Type(); + pooling_param->global_ = pooling_primitive->GetGlobal(); + pooling_param->window_w_ = pooling_primitive->GetWindowW(); + pooling_param->window_h_ = pooling_primitive->GetWindowH(); + auto pooling_lite_primitive = (lite::Pooling *)primitive; + pooling_param->pad_u_ = pooling_lite_primitive->PadUp(); + pooling_param->pad_d_ = pooling_lite_primitive->PadDown(); + pooling_param->pad_l_ = pooling_lite_primitive->PadLeft(); + pooling_param->pad_r_ = pooling_lite_primitive->PadRight(); + pooling_param->stride_w_ = pooling_primitive->GetStrideW(); + pooling_param->stride_h_ = pooling_primitive->GetStrideH(); + pooling_param->avg_mode_ = pooling_primitive->GetAvgMode(); + + auto is_global = pooling_primitive->GetGlobal(); + pooling_param->global_ = is_global; + auto pool_mode = pooling_primitive->GetPoolingMode(); + switch (pool_mode) { + case schema::PoolMode_MAX_POOLING: + pooling_param->pool_mode_ = PoolMode_MaxPool; + break; + case schema::PoolMode_MEAN_POOLING: + pooling_param->pool_mode_ = PoolMode_AvgPool; + break; + default: + pooling_param->pool_mode_ = PoolMode_No; + break; + } + + auto round_mode = pooling_primitive->GetRoundMode(); + switch (round_mode) { + case schema::RoundMode_FLOOR: + pooling_param->round_mode_ = RoundMode_Floor; + break; + case schema::RoundMode_CEIL: + pooling_param->round_mode_ = RoundMode_Ceil; + break; + default: + pooling_param->round_mode_ = RoundMode_No; + break; + } + + if (pooling_primitive->GetActivationType() == schema::ActivationType_RELU) { + pooling_param->act_type_ = ActType_Relu; + } else if (pooling_primitive->GetActivationType() == schema::ActivationType_RELU6) { + pooling_param->act_type_ = ActType_Relu6; + } else { + pooling_param->act_type_ = ActType_No; + } + return reinterpret_cast(pooling_param); +} + +Registry PoolingParameterRegistry(schema::PrimitiveType_Pooling, PopulatePoolingParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/populate_register.h b/mindspore/lite/src/ops/populate/populate_register.h new file mode 100644 index 0000000000..d6754644d7 --- /dev/null +++ b/mindspore/lite/src/ops/populate/populate_register.h @@ -0,0 +1,55 @@ +/** + * Copyright 2019-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 LITE_MINDSPORE_LITE_C_OPS_OP_POPULATE_REGISTER_H +#define LITE_MINDSPORE_LITE_C_OPS_OP_POPULATE_REGISTER_H + +#include + +namespace mindspore { +namespace lite { +class PopulateRegistry { + public: + static PopulateRegistry *GetInstance() { + static PopulateRegistry registry; + return ®istry; + } + + void insertParameterMap(schema::PrimitiveType type, ParameterCreator creator) { parameter_creators[type] = creator; } + + ParameterCreator getParameterCreator(schema::PrimitiveType type) { + if (parameter_creators.find(type) != parameter_creators.end()) { + return parameter_creators[type]; + } else { + MS_LOG(ERROR) << "Unsupported parameter type in Create : " << schema::EnumNamePrimitiveType(type); + return nullptr; + } + } + + protected: + std::map parameter_creators; +}; + +class Registry { + public: + Registry(schema::PrimitiveType primitive_type, ParameterCreator creator) { + PopulateRegistry::GetInstance()->insertParameterMap(primitive_type, creator); + } +}; +OpParameter *PopulateArithmetic(const mindspore::lite::PrimitiveC *primitive); +} // namespace lite +} // namespace mindspore +#endif diff --git a/mindspore/lite/src/ops/populate/power_populate.cc b/mindspore/lite/src/ops/populate/power_populate.cc new file mode 100644 index 0000000000..a2e805c086 --- /dev/null +++ b/mindspore/lite/src/ops/populate/power_populate.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2019-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/ops/power.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/power_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulatePowerParameter(const mindspore::lite::PrimitiveC *primitive) { + PowerParameter *power_param = reinterpret_cast(malloc(sizeof(PowerParameter))); + if (power_param == nullptr) { + MS_LOG(ERROR) << "malloc PowerParameter failed."; + return nullptr; + } + memset(power_param, 0, sizeof(PowerParameter)); + power_param->op_parameter_.type_ = primitive->Type(); + auto power = reinterpret_cast(const_cast(primitive)); + power_param->power_ = power->GetPower(); + power_param->scale_ = power->GetScale(); + power_param->shift_ = power->GetShift(); + return reinterpret_cast(power_param); +} + +Registry PowerParameterRegistry(schema::PrimitiveType_Power, PopulatePowerParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/prior_box_populate.cc b/mindspore/lite/src/ops/populate/prior_box_populate.cc new file mode 100644 index 0000000000..ee429e7566 --- /dev/null +++ b/mindspore/lite/src/ops/populate/prior_box_populate.cc @@ -0,0 +1,83 @@ +/** + * Copyright 2019-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/ops/prior_box.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/prior_box.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulatePriorBoxParameter(const mindspore::lite::PrimitiveC *primitive) { + PriorBoxParameter *prior_box_param = reinterpret_cast(malloc(sizeof(PriorBoxParameter))); + if (prior_box_param == nullptr) { + MS_LOG(ERROR) << "malloc PriorBoxParameter failed."; + return nullptr; + } + memset(prior_box_param, 0, sizeof(PriorBoxParameter)); + prior_box_param->op_parameter_.type_ = primitive->Type(); + auto prior_box_attr = + reinterpret_cast(const_cast(primitive)); + + if (prior_box_attr->GetMinSizes().size() > PRIOR_BOX_MAX_NUM) { + MS_LOG(ERROR) << "PriorBox min_sizes size exceeds max num " << PRIOR_BOX_MAX_NUM << ", got " + << prior_box_attr->GetMinSizes(); + free(prior_box_param); + return nullptr; + } + prior_box_param->min_sizes_size = prior_box_attr->GetMinSizes().size(); + if (prior_box_attr->GetMaxSizes().size() > PRIOR_BOX_MAX_NUM) { + MS_LOG(ERROR) << "PriorBox max_sizes size exceeds max num " << PRIOR_BOX_MAX_NUM << ", got " + << prior_box_attr->GetMaxSizes(); + free(prior_box_param); + return nullptr; + } + prior_box_param->max_sizes_size = prior_box_attr->GetMaxSizes().size(); + memcpy(prior_box_param->max_sizes, prior_box_attr->GetMaxSizes().data(), + prior_box_attr->GetMaxSizes().size() * sizeof(int32_t)); + memcpy(prior_box_param->min_sizes, prior_box_attr->GetMinSizes().data(), + prior_box_attr->GetMinSizes().size() * sizeof(int32_t)); + + if (prior_box_attr->GetAspectRatios().size() > PRIOR_BOX_MAX_NUM) { + MS_LOG(ERROR) << "PriorBox aspect_ratios size exceeds max num " << PRIOR_BOX_MAX_NUM << ", got " + << prior_box_attr->GetAspectRatios(); + free(prior_box_param); + return nullptr; + } + prior_box_param->aspect_ratios_size = prior_box_attr->GetAspectRatios().size(); + memcpy(prior_box_param->aspect_ratios, prior_box_attr->GetAspectRatios().data(), + prior_box_attr->GetAspectRatios().size() * sizeof(float)); + if (prior_box_attr->GetVariances().size() != PRIOR_BOX_VAR_NUM) { + MS_LOG(ERROR) << "PriorBox variances size should be " << PRIOR_BOX_VAR_NUM << ", got " + << prior_box_attr->GetVariances().size(); + free(prior_box_param); + return nullptr; + } + memcpy(prior_box_param->variances, prior_box_attr->GetVariances().data(), PRIOR_BOX_VAR_NUM * sizeof(float)); + prior_box_param->flip = prior_box_attr->GetFlip(); + prior_box_param->clip = prior_box_attr->GetClip(); + prior_box_param->offset = prior_box_attr->GetOffset(); + prior_box_param->image_size_h = prior_box_attr->GetImageSizeH(); + prior_box_param->image_size_w = prior_box_attr->GetImageSizeW(); + prior_box_param->step_h = prior_box_attr->GetStepH(); + prior_box_param->step_w = prior_box_attr->GetStepW(); + return reinterpret_cast(prior_box_param); +} +Registry PriorBoxParameterRegistry(schema::PrimitiveType_PriorBox, PopulatePriorBoxParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/quant_dtype_cast_populate.cc b/mindspore/lite/src/ops/populate/quant_dtype_cast_populate.cc new file mode 100644 index 0000000000..a7fa86eef4 --- /dev/null +++ b/mindspore/lite/src/ops/populate/quant_dtype_cast_populate.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2019-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/ops/quant_dtype_cast.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/int8/quant_dtype_cast.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateQuantDTypeCastParameter(const mindspore::lite::PrimitiveC *primitive) { + QuantDTypeCastParameter *parameter = + reinterpret_cast(malloc(sizeof(QuantDTypeCastParameter))); + if (parameter == nullptr) { + MS_LOG(ERROR) << "malloc QuantDTypeCastParameter failed."; + return nullptr; + } + memset(parameter, 0, sizeof(QuantDTypeCastParameter)); + parameter->op_parameter_.type_ = primitive->Type(); + auto quant_dtype_cast_param = + reinterpret_cast(const_cast(primitive)); + parameter->srcT = quant_dtype_cast_param->GetSrcT(); + parameter->dstT = quant_dtype_cast_param->GetDstT(); + return reinterpret_cast(parameter); +} +Registry QuantDTypeCastParameterRegistry(schema::PrimitiveType_QuantDTypeCast, PopulateQuantDTypeCastParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/range_populate.cc b/mindspore/lite/src/ops/populate/range_populate.cc new file mode 100644 index 0000000000..0c02abcbd9 --- /dev/null +++ b/mindspore/lite/src/ops/populate/range_populate.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2019-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/ops/range.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/range.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateRangeParameter(const mindspore::lite::PrimitiveC *primitive) { + auto range_attr = reinterpret_cast(const_cast(primitive)); + RangeParameter *range_param = reinterpret_cast(malloc(sizeof(RangeParameter))); + if (range_param == nullptr) { + MS_LOG(ERROR) << "malloc RangeParameter failed."; + return nullptr; + } + memset(range_param, 0, sizeof(RangeParameter)); + range_param->op_parameter_.type_ = primitive->Type(); + range_param->start_ = range_attr->GetStart(); + range_param->limit_ = range_attr->GetLimit(); + range_param->delta_ = range_attr->GetDelta(); + range_param->dType_ = range_attr->GetDType(); + return reinterpret_cast(range_param); +} +Registry RangeParameterRegistry(schema::PrimitiveType_Range, PopulateRangeParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/reduce_populate.cc b/mindspore/lite/src/ops/populate/reduce_populate.cc new file mode 100644 index 0000000000..c35b18d875 --- /dev/null +++ b/mindspore/lite/src/ops/populate/reduce_populate.cc @@ -0,0 +1,56 @@ +/** + * Copyright 2019-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/ops/reduce.h" +#include +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/reduce_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateReduceParameter(const mindspore::lite::PrimitiveC *primitive) { + ReduceParameter *reduce_param = reinterpret_cast(malloc(sizeof(ReduceParameter))); + if (reduce_param == nullptr) { + MS_LOG(ERROR) << "malloc ReduceParameter failed."; + return nullptr; + } + memset(reduce_param, 0, sizeof(ReduceParameter)); + reduce_param->op_parameter_.type_ = primitive->Type(); + auto reduce = reinterpret_cast(const_cast(primitive)); + reduce_param->keep_dims_ = reduce->GetKeepDims(); + reduce_param->reduce_to_end_ = reduce->GetReduceToEnd(); + reduce_param->coeff = reduce->GetCoeff(); + auto axisVector = reduce->GetAxes(); + if (axisVector.size() > REDUCE_MAX_AXES_NUM) { + MS_LOG(ERROR) << "Reduce axes size " << axisVector.size() << " exceed limit " << REDUCE_MAX_AXES_NUM; + free(reduce_param); + return nullptr; + } + reduce_param->num_axes_ = static_cast(axisVector.size()); + int i = 0; + for (auto iter = axisVector.begin(); iter != axisVector.end(); iter++) { + reduce_param->axes_[i++] = *iter; + } + reduce_param->mode_ = static_cast(reduce->GetMode()); + return reinterpret_cast(reduce_param); +} + +Registry ReduceParameterRegistry(schema::PrimitiveType_Reduce, PopulateReduceParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/reshape_populate.cc b/mindspore/lite/src/ops/populate/reshape_populate.cc new file mode 100644 index 0000000000..7008cb63be --- /dev/null +++ b/mindspore/lite/src/ops/populate/reshape_populate.cc @@ -0,0 +1,40 @@ +/** + * Copyright 2019-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/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "src/common/log_adapter.h" +#include "src/tensor.h" +#include "nnacl/reshape_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateReshapeParameter(const mindspore::lite::PrimitiveC *primitive) { + ReshapeParameter *reshape_param = reinterpret_cast(malloc(sizeof(ReshapeParameter))); + if (reshape_param == nullptr) { + MS_LOG(ERROR) << "malloc ReshapeParameter failed."; + return nullptr; + } + memset(reshape_param, 0, sizeof(ReshapeParameter)); + reshape_param->op_parameter_.type_ = primitive->Type(); + return reinterpret_cast(reshape_param); +} + +Registry ReshapeParameterRegistry(schema::PrimitiveType_Reshape, PopulateReshapeParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/resize_populate.cc b/mindspore/lite/src/ops/populate/resize_populate.cc new file mode 100644 index 0000000000..937ac7ac04 --- /dev/null +++ b/mindspore/lite/src/ops/populate/resize_populate.cc @@ -0,0 +1,46 @@ +/** + * Copyright 2019-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/ops/resize.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/resize_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateResizeParameter(const mindspore::lite::PrimitiveC *primitive) { + ResizeParameter *resize_param = reinterpret_cast(malloc(sizeof(ResizeParameter))); + if (resize_param == nullptr) { + MS_LOG(ERROR) << "malloc ResizeParameter failed."; + return nullptr; + } + memset(resize_param, 0, sizeof(ResizeParameter)); + resize_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + resize_param->method_ = static_cast(param->GetMethod()); + resize_param->new_height_ = param->GetNewHeight(); + resize_param->new_width_ = param->GetNewWidth(); + resize_param->align_corners_ = param->GetAlignCorners(); + resize_param->preserve_aspect_ratio_ = param->GetPreserveAspectRatio(); + return reinterpret_cast(resize_param); +} + +Registry ResizeParameterRegistry(schema::PrimitiveType_Resize, PopulateResizeParameter); + +} // namespace lite + +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/reverse_populate.cc b/mindspore/lite/src/ops/populate/reverse_populate.cc new file mode 100644 index 0000000000..3e22f38e8c --- /dev/null +++ b/mindspore/lite/src/ops/populate/reverse_populate.cc @@ -0,0 +1,47 @@ +/** + * Copyright 2019-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/ops/reverse.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/reverse.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateReverseParameter(const mindspore::lite::PrimitiveC *primitive) { + auto reverse_attr = + reinterpret_cast(const_cast(primitive)); + ReverseParameter *reverse_param = reinterpret_cast(malloc(sizeof(ReverseParameter))); + if (reverse_param == nullptr) { + MS_LOG(ERROR) << "malloc ReverseParameter failed."; + return nullptr; + } + memset(reverse_param, 0, sizeof(ReverseParameter)); + reverse_param->op_parameter_.type_ = primitive->Type(); + auto flatAxis = reverse_attr->GetAxis(); + reverse_param->num_axis_ = flatAxis.size(); + int i = 0; + for (auto iter = flatAxis.begin(); iter != flatAxis.end(); iter++) { + reverse_param->axis_[i++] = *iter; + } + return reinterpret_cast(reverse_param); +} + +Registry ReverseParameterRegistry(schema::PrimitiveType_Reverse, PopulateReverseParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/reverse_sequence_populate.cc b/mindspore/lite/src/ops/populate/reverse_sequence_populate.cc new file mode 100644 index 0000000000..83827266e3 --- /dev/null +++ b/mindspore/lite/src/ops/populate/reverse_sequence_populate.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2019-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/ops/reverse_sequence.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/reverse_sequence.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateReverseSequenceParameter(const mindspore::lite::PrimitiveC *primitive) { + ReverseSequenceParameter *reverse_sequence_param = + reinterpret_cast(malloc(sizeof(ReverseSequenceParameter))); + if (reverse_sequence_param == nullptr) { + MS_LOG(ERROR) << "malloc ReverseSequenceParameter failed."; + return nullptr; + } + memset(reverse_sequence_param, 0, sizeof(ReverseSequenceParameter)); + auto param = + reinterpret_cast(const_cast(primitive)); + reverse_sequence_param->op_parameter_.type_ = primitive->Type(); + reverse_sequence_param->seq_axis_ = param->GetSeqAxis(); + reverse_sequence_param->batch_axis_ = param->GetBatchAxis(); + return reinterpret_cast(reverse_sequence_param); +} +Registry ReverseSequenceParameterRegistry(schema::PrimitiveType_ReverseSequence, PopulateReverseSequenceParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/roi_pooling_populate.cc b/mindspore/lite/src/ops/populate/roi_pooling_populate.cc new file mode 100644 index 0000000000..016328de83 --- /dev/null +++ b/mindspore/lite/src/ops/populate/roi_pooling_populate.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2019-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/ops/roi_pooling.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/roi_pooling.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateROIPoolingParameter(const mindspore::lite::PrimitiveC *primitive) { + const auto param = + reinterpret_cast(const_cast(primitive)); + ROIPoolingParameter *roi_pooling_param = reinterpret_cast(malloc(sizeof(ROIPoolingParameter))); + if (roi_pooling_param == nullptr) { + MS_LOG(ERROR) << "malloc ROIPoolingParameter failed."; + return nullptr; + } + memset(roi_pooling_param, 0, sizeof(ROIPoolingParameter)); + roi_pooling_param->op_parameter_.type_ = primitive->Type(); + roi_pooling_param->pooledH_ = param->GetPooledW(); + roi_pooling_param->pooledW_ = param->GetPooledW(); + roi_pooling_param->scale_ = param->GetScale(); + return reinterpret_cast(roi_pooling_param); +} + +Registry ROIPoolingParameterRegistry(schema::PrimitiveType_ROIPooling, PopulateROIPoolingParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/scale_populate.cc b/mindspore/lite/src/ops/populate/scale_populate.cc new file mode 100644 index 0000000000..f71294cc55 --- /dev/null +++ b/mindspore/lite/src/ops/populate/scale_populate.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2019-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/ops/scale.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/scale.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateScaleParameter(const mindspore::lite::PrimitiveC *primitive) { + if (primitive == nullptr) { + MS_LOG(ERROR) << "input primitive is nullptr"; + return nullptr; + } + ScaleParameter *scale_param = reinterpret_cast(malloc(sizeof(ScaleParameter))); + if (scale_param == nullptr) { + MS_LOG(ERROR) << "malloc ScaleParameter failed."; + return nullptr; + } + memset(scale_param, 0, sizeof(ScaleParameter)); + scale_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + scale_param->axis_ = param->GetAxis(); + scale_param->activation_type_ = param->GetActivationType(); + return reinterpret_cast(scale_param); +} +Registry ScaleParameterRegistry(schema::PrimitiveType_Scale, PopulateScaleParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/scatter_nd_populate.cc b/mindspore/lite/src/ops/populate/scatter_nd_populate.cc new file mode 100644 index 0000000000..e81860a027 --- /dev/null +++ b/mindspore/lite/src/ops/populate/scatter_nd_populate.cc @@ -0,0 +1,38 @@ +/** + * 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/ops/scatter_nd.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/scatter_nd.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateScatterNDParameter(const mindspore::lite::PrimitiveC *primitive) { + ScatterNDParameter *scatter_nd_param = reinterpret_cast(malloc(sizeof(ScatterNDParameter))); + if (scatter_nd_param == nullptr) { + MS_LOG(ERROR) << "malloc ScatterNDParameter failed."; + return nullptr; + } + memset(scatter_nd_param, 0, sizeof(ScatterNDParameter)); + scatter_nd_param->op_parameter_.type_ = primitive->Type(); + return reinterpret_cast(scatter_nd_param); +} +Registry ScatterNDParameterRegistry(schema::PrimitiveType_ScatterND, PopulateScatterNDParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/shape_populate.cc b/mindspore/lite/src/ops/populate/shape_populate.cc new file mode 100644 index 0000000000..d097e0ee15 --- /dev/null +++ b/mindspore/lite/src/ops/populate/shape_populate.cc @@ -0,0 +1,40 @@ +/** + * Copyright 2019-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/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "src/common/log_adapter.h" +#include "src/tensor.h" +#include "nnacl/shape.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateShapeParameter(const mindspore::lite::PrimitiveC *primitive) { + ShapeParameter *shape_param = reinterpret_cast(malloc(sizeof(ShapeParameter))); + if (shape_param == nullptr) { + MS_LOG(ERROR) << "malloc ShapeParameter failed."; + return nullptr; + } + memset(shape_param, 0, sizeof(ShapeParameter)); + shape_param->op_parameter_.type_ = primitive->Type(); + return reinterpret_cast(shape_param); +} + +Registry ShapeParameterRegistry(schema::PrimitiveType_Shape, PopulateShapeParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/skip_gram_populate.cc b/mindspore/lite/src/ops/populate/skip_gram_populate.cc new file mode 100644 index 0000000000..6f690e9ab7 --- /dev/null +++ b/mindspore/lite/src/ops/populate/skip_gram_populate.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2019-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/ops/skip_gram.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/skip_gram.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateSkipGramParameter(const mindspore::lite::PrimitiveC *primitive) { + SkipGramParameter *skipGramParameter = reinterpret_cast(malloc(sizeof(SkipGramParameter))); + if (skipGramParameter == nullptr) { + MS_LOG(ERROR) << "malloc SkipGramParameter failed."; + return nullptr; + } + memset(skipGramParameter, 0, sizeof(SkipGramParameter)); + skipGramParameter->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + skipGramParameter->ngram_size = param->GetNgramSize(); + skipGramParameter->max_skip_size = param->GetMaxSkipSize(); + skipGramParameter->include_all_ngrams = param->GetIncludeAllNgrams(); + return reinterpret_cast(skipGramParameter); +} +Registry SkipGramParameterRegistry(schema::PrimitiveType_SkipGram, PopulateSkipGramParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/slice_populate.cc b/mindspore/lite/src/ops/populate/slice_populate.cc new file mode 100644 index 0000000000..28eacce93d --- /dev/null +++ b/mindspore/lite/src/ops/populate/slice_populate.cc @@ -0,0 +1,52 @@ +/** + * Copyright 2019-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/ops/slice.h" +#include "src/common/log_adapter.h" +#include "src/tensor.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/slice_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateSliceParameter(const mindspore::lite::PrimitiveC *primitive) { + SliceParameter *slice_param = reinterpret_cast(malloc(sizeof(SliceParameter))); + if (slice_param == nullptr) { + MS_LOG(ERROR) << "malloc SliceParameter failed."; + return nullptr; + } + memset(slice_param, 0, sizeof(SliceParameter)); + auto param = reinterpret_cast(const_cast(primitive)); + slice_param->op_parameter_.type_ = primitive->Type(); + auto param_begin = param->GetPostProcessBegin(); + auto param_size = param->GetPostProcessSize(); + if (param_begin.size() != param_size.size()) { + free(slice_param); + return nullptr; + } + slice_param->param_length_ = static_cast(param_begin.size()); + for (int32_t i = 0; i < slice_param->param_length_; ++i) { + slice_param->begin_[i] = param_begin[i]; + slice_param->size_[i] = param_size[i]; + } + return reinterpret_cast(slice_param); +} +Registry SliceParameterRegistry(schema::PrimitiveType_Slice, PopulateSliceParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/softmax_populate.cc b/mindspore/lite/src/ops/populate/softmax_populate.cc new file mode 100644 index 0000000000..fa29b6eaaa --- /dev/null +++ b/mindspore/lite/src/ops/populate/softmax_populate.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2019-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/ops/softmax.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/softmax_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateSoftmaxParameter(const mindspore::lite::PrimitiveC *primitive) { + auto softmax_primitive = + reinterpret_cast(const_cast(primitive)); + SoftmaxParameter *softmax_param = reinterpret_cast(malloc(sizeof(SoftmaxParameter))); + if (softmax_param == nullptr) { + MS_LOG(ERROR) << "malloc SoftmaxParameter failed."; + return nullptr; + } + memset(softmax_param, 0, sizeof(SoftmaxParameter)); + softmax_param->op_parameter_.type_ = primitive->Type(); + softmax_param->axis_ = softmax_primitive->GetAxis(); + return reinterpret_cast(softmax_param); +} + +Registry SoftMaxParameterRegistry(schema::PrimitiveType_SoftMax, PopulateSoftmaxParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/space_to_batch_nd_populate.cc b/mindspore/lite/src/ops/populate/space_to_batch_nd_populate.cc new file mode 100644 index 0000000000..f6257cbf2a --- /dev/null +++ b/mindspore/lite/src/ops/populate/space_to_batch_nd_populate.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2019-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/ops/space_to_batch_nd.h" +#include "src/common/common.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/space_to_batch.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateSpaceToBatchNDParameter(const mindspore::lite::PrimitiveC *primitive) { + auto *space_batch_param_nd = new (std::nothrow) SpaceToBatchParameter(); + if (space_batch_param_nd == nullptr) { + MS_LOG(ERROR) << "new SpaceToBatchParameter failed."; + return nullptr; + } + + space_batch_param_nd->op_parameter_.type_ = primitive->Type(); + auto block_sizes = ((mindspore::lite::SpaceToBatchND *)primitive)->GetBlockShape(); + memcpy(space_batch_param_nd->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int)); + auto paddings = ((mindspore::lite::SpaceToBatchND *)primitive)->GetPaddings(); + memcpy(space_batch_param_nd->paddings_, (paddings.data()), paddings.size() * sizeof(int)); + return reinterpret_cast(space_batch_param_nd); +} +Registry SpaceToBatchNDParameterRegistry(schema::PrimitiveType_SpaceToBatchND, PopulateSpaceToBatchNDParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/space_to_batch_populate.cc b/mindspore/lite/src/ops/populate/space_to_batch_populate.cc new file mode 100644 index 0000000000..d0a1b536af --- /dev/null +++ b/mindspore/lite/src/ops/populate/space_to_batch_populate.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2019-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/ops/space_to_batch.h" +#include "src/common/common.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/space_to_batch.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateSpaceToBatchParameter(const mindspore::lite::PrimitiveC *primitive) { + SpaceToBatchParameter *space_batch_param = + reinterpret_cast(malloc(sizeof(SpaceToBatchParameter))); + if (space_batch_param == nullptr) { + MS_LOG(ERROR) << "malloc SpaceToBatchParameter failed."; + return nullptr; + } + memset(space_batch_param, 0, sizeof(SpaceToBatchParameter)); + space_batch_param->op_parameter_.type_ = primitive->Type(); + auto block_sizes = ((mindspore::lite::SpaceToBatch *)primitive)->BlockSizes(); + memcpy(space_batch_param->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int)); + auto paddings = ((mindspore::lite::SpaceToBatch *)primitive)->Paddings(); + memcpy(space_batch_param->paddings_, (paddings.data()), paddings.size() * sizeof(int)); + return reinterpret_cast(space_batch_param); +} +Registry SpaceToBatchParameterRegistry(schema::PrimitiveType_SpaceToBatch, PopulateSpaceToBatchParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/space_to_depth_populate.cc b/mindspore/lite/src/ops/populate/space_to_depth_populate.cc new file mode 100644 index 0000000000..6ea0c6dd62 --- /dev/null +++ b/mindspore/lite/src/ops/populate/space_to_depth_populate.cc @@ -0,0 +1,46 @@ +/** + * Copyright 2019-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/ops/space_to_depth.h" +#include "src/common/common.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/space_to_depth.h" + +namespace mindspore { +namespace lite { +OpParameter *PopulateSpaceToDepthParameter(const mindspore::lite::PrimitiveC *primitive) { + SpaceToDepthParameter *space_depth_param = + reinterpret_cast(malloc(sizeof(SpaceToDepthParameter))); + if (space_depth_param == nullptr) { + MS_LOG(ERROR) << "malloc SpaceToDepthParameter failed."; + return nullptr; + } + memset(space_depth_param, 0, sizeof(SpaceToDepthParameter)); + space_depth_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + space_depth_param->op_parameter_.type_ = primitive->Type(); + space_depth_param->block_size_ = param->GetBlockSize(); + if (param->GetFormat() != schema::Format::Format_NHWC) { + MS_LOG(ERROR) << "Currently only NHWC format is supported."; + free(space_depth_param); + return nullptr; + } + return reinterpret_cast(space_depth_param); +} +Registry SpaceToDepthParameterRegistry(schema::PrimitiveType_SpaceToDepth, PopulateSpaceToDepthParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/sparse_to_dense_populate.cc b/mindspore/lite/src/ops/populate/sparse_to_dense_populate.cc new file mode 100644 index 0000000000..637685b9b6 --- /dev/null +++ b/mindspore/lite/src/ops/populate/sparse_to_dense_populate.cc @@ -0,0 +1,41 @@ +/** + * Copyright 2019-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/ops/sparse_to_dense.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/sparse_to_dense_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateSparseToDenseParameter(const mindspore::lite::PrimitiveC *primitive) { + SparseToDenseParameter *sparse_to_dense_param = + reinterpret_cast(malloc(sizeof(SparseToDenseParameter))); + if (sparse_to_dense_param == nullptr) { + MS_LOG(ERROR) << "malloc SparseToDenseParameter failed."; + return nullptr; + } + memset(sparse_to_dense_param, 0, sizeof(SparseToDenseParameter)); + sparse_to_dense_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + sparse_to_dense_param->validate_indices_ = param->GetValidateIndices(); + return reinterpret_cast(sparse_to_dense_param); +} + +Registry SparseToDenseParameterRegistry(schema::PrimitiveType_SparseToDense, PopulateSparseToDenseParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/split_populate.cc b/mindspore/lite/src/ops/populate/split_populate.cc new file mode 100644 index 0000000000..eeaeed8349 --- /dev/null +++ b/mindspore/lite/src/ops/populate/split_populate.cc @@ -0,0 +1,46 @@ +/** + * Copyright 2019-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/ops/split.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/split_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateSplitParameter(const mindspore::lite::PrimitiveC *primitive) { + SplitParameter *split_param = reinterpret_cast(malloc(sizeof(SplitParameter))); + if (split_param == nullptr) { + MS_LOG(ERROR) << "malloc SplitParameter failed."; + return nullptr; + } + memset(split_param, 0, sizeof(SplitParameter)); + auto param = reinterpret_cast(const_cast(primitive)); + split_param->op_parameter_.type_ = primitive->Type(); + split_param->num_split_ = param->GetNumberSplit(); + auto split_sizes_vector_ = param->GetSizeSplits(); + int i = 0; + for (auto iter = split_sizes_vector_.begin(); iter != split_sizes_vector_.end(); iter++) { + split_param->split_sizes_[i++] = *iter; + } + split_param->split_dim_ = param->GetSplitDim(); + split_param->num_split_ = param->GetNumberSplit(); + return reinterpret_cast(split_param); +} +Registry SplitParameterRegistry(schema::PrimitiveType_Split, PopulateSplitParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/squeeze_populate.cc b/mindspore/lite/src/ops/populate/squeeze_populate.cc new file mode 100644 index 0000000000..d270fc829e --- /dev/null +++ b/mindspore/lite/src/ops/populate/squeeze_populate.cc @@ -0,0 +1,37 @@ +/** + * Copyright 2019-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/ops/squeeze.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/squeeze.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateSqueezeParameter(const mindspore::lite::PrimitiveC *primitive) { + SqueezeParameter *squeeze_param = reinterpret_cast(malloc(sizeof(SqueezeParameter))); + if (squeeze_param == nullptr) { + MS_LOG(ERROR) << "malloc SqueezeParameter failed."; + return nullptr; + } + memset(squeeze_param, 0, sizeof(SqueezeParameter)); + squeeze_param->op_parameter_.type_ = primitive->Type(); + return reinterpret_cast(squeeze_param); +} +Registry SqueezeParameterRegistry(schema::PrimitiveType_Squeeze, PopulateSqueezeParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/stack_populate.cc b/mindspore/lite/src/ops/populate/stack_populate.cc new file mode 100644 index 0000000000..728b197688 --- /dev/null +++ b/mindspore/lite/src/ops/populate/stack_populate.cc @@ -0,0 +1,39 @@ +/** + * Copyright 2019-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/ops/stack.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/stack_parameter.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateStackParameter(const mindspore::lite::PrimitiveC *primitive) { + StackParameter *stack_param = reinterpret_cast(malloc(sizeof(StackParameter))); + if (stack_param == nullptr) { + MS_LOG(ERROR) << "malloc StackParameter failed."; + return nullptr; + } + memset(stack_param, 0, sizeof(StackParameter)); + auto param = reinterpret_cast(const_cast(primitive)); + stack_param->op_parameter_.type_ = primitive->Type(); + stack_param->axis_ = param->GetAxis(); + return reinterpret_cast(stack_param); +} +Registry StackParameterRegistry(schema::PrimitiveType_Stack, PopulateStackParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/strided_slice_populate.cc b/mindspore/lite/src/ops/populate/strided_slice_populate.cc new file mode 100644 index 0000000000..9f25183f62 --- /dev/null +++ b/mindspore/lite/src/ops/populate/strided_slice_populate.cc @@ -0,0 +1,49 @@ +/** + * Copyright 2019-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/ops/strided_slice.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/strided_slice.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateStridedSliceParameter(const mindspore::lite::PrimitiveC *primitive) { + StridedSliceParameter *strided_slice_param = + reinterpret_cast(malloc(sizeof(StridedSliceParameter))); + if (strided_slice_param == nullptr) { + MS_LOG(ERROR) << "malloc StridedSliceParameter failed."; + return nullptr; + } + memset(strided_slice_param, 0, sizeof(StridedSliceParameter)); + strided_slice_param->op_parameter_.type_ = primitive->Type(); + auto n_dims = ((lite::StridedSlice *)primitive)->NDims(); + strided_slice_param->num_axes_ = n_dims; + auto begin = ((lite::StridedSlice *)primitive)->GetBegins(); + memcpy(strided_slice_param->begins_, (begin.data()), begin.size() * sizeof(int)); + auto end = ((lite::StridedSlice *)primitive)->GetEnds(); + memcpy(strided_slice_param->ends_, (end.data()), end.size() * sizeof(int)); + auto stride = ((lite::StridedSlice *)primitive)->GetStrides(); + memcpy(strided_slice_param->strides_, (stride.data()), stride.size() * sizeof(int)); + auto in_shape = ((lite::StridedSlice *)primitive)->GetInShape(); + memcpy(strided_slice_param->in_shape_, (in_shape.data()), in_shape.size() * sizeof(int)); + return reinterpret_cast(strided_slice_param); +} + +Registry StridedSliceParameterRegistry(schema::PrimitiveType_StridedSlice, PopulateStridedSliceParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/sub_populate.cc b/mindspore/lite/src/ops/populate/sub_populate.cc new file mode 100644 index 0000000000..8aaaf5f295 --- /dev/null +++ b/mindspore/lite/src/ops/populate/sub_populate.cc @@ -0,0 +1,47 @@ +/** + * Copyright 2019-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/ops/sub.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/arithmetic_common.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateSubParameter(const mindspore::lite::PrimitiveC *primitive) { + ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); + if (arithmetic_param == nullptr) { + MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; + return nullptr; + } + memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); + arithmetic_param->op_parameter_.type_ = primitive->Type(); + arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); + arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); + arithmetic_param->activation_type_ = + reinterpret_cast(const_cast(primitive))->GetActivationType(); + auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); + memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); + memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); + memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); + return reinterpret_cast(arithmetic_param); +} +Registry SubParameterRegistry(schema::PrimitiveType_Sub, PopulateSubParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/tile_populate.cc b/mindspore/lite/src/ops/populate/tile_populate.cc new file mode 100644 index 0000000000..d745331483 --- /dev/null +++ b/mindspore/lite/src/ops/populate/tile_populate.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2019-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/ops/tile.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/tile.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateTileParameter(const mindspore::lite::PrimitiveC *primitive) { + TileParameter *tile_param = reinterpret_cast(malloc(sizeof(TileParameter))); + if (tile_param == nullptr) { + MS_LOG(ERROR) << "malloc TileParameter failed."; + return nullptr; + } + memset(tile_param, 0, sizeof(TileParameter)); + tile_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + auto multiples = param->GetMultiples(); + tile_param->in_dim_ = multiples.size(); + for (int i = 0; i < tile_param->in_dim_; ++i) { + tile_param->multiples_[i] = multiples[i]; + } + return reinterpret_cast(tile_param); +} + +Registry TileParameterRegistry(schema::PrimitiveType_Tile, PopulateTileParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/topk_populate.cc b/mindspore/lite/src/ops/populate/topk_populate.cc new file mode 100644 index 0000000000..e75069311d --- /dev/null +++ b/mindspore/lite/src/ops/populate/topk_populate.cc @@ -0,0 +1,41 @@ +/** + * Copyright 2019-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/ops/topk.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/topk.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateTopKParameter(const mindspore::lite::PrimitiveC *primitive) { + TopkParameter *topk_param = reinterpret_cast(malloc(sizeof(TopkParameter))); + if (topk_param == nullptr) { + MS_LOG(ERROR) << "malloc TopkParameter failed."; + return nullptr; + } + memset(topk_param, 0, sizeof(TopkParameter)); + topk_param->op_parameter_.type_ = primitive->Type(); + auto param = reinterpret_cast(const_cast(primitive)); + topk_param->k_ = param->GetK(); + topk_param->sorted_ = param->GetSorted(); + return reinterpret_cast(topk_param); +} +Registry TopKParameterRegistry(schema::PrimitiveType_TopK, PopulateTopKParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/transpose_populate.cc b/mindspore/lite/src/ops/populate/transpose_populate.cc new file mode 100644 index 0000000000..509cf1dc46 --- /dev/null +++ b/mindspore/lite/src/ops/populate/transpose_populate.cc @@ -0,0 +1,49 @@ +/** + * Copyright 2019-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/ops/transpose.h" +#include +#include "src/common/log_adapter.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/transpose.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateTransposeParameter(const mindspore::lite::PrimitiveC *primitive) { + TransposeParameter *transpose_param = reinterpret_cast(malloc(sizeof(TransposeParameter))); + if (transpose_param == nullptr) { + MS_LOG(ERROR) << "malloc TransposeParameter failed."; + return nullptr; + } + memset(transpose_param, 0, sizeof(TransposeParameter)); + auto param = reinterpret_cast(const_cast(primitive)); + transpose_param->op_parameter_.type_ = primitive->Type(); + auto perm_vector_ = param->GetPerm(); + int i = 0; + for (auto iter = perm_vector_.begin(); iter != perm_vector_.end(); iter++) { + transpose_param->perm_[i++] = *iter; + } + transpose_param->num_axes_ = i; + transpose_param->conjugate_ = param->GetConjugate(); + return reinterpret_cast(transpose_param); +} + +Registry TransposeParameterRegistry(schema::PrimitiveType_Transpose, PopulateTransposeParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/unique_populate.cc b/mindspore/lite/src/ops/populate/unique_populate.cc new file mode 100644 index 0000000000..d81aa778fe --- /dev/null +++ b/mindspore/lite/src/ops/populate/unique_populate.cc @@ -0,0 +1,39 @@ +/** + * Copyright 2019-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/ops/unique.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/unique.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateUniqueParameter(const mindspore::lite::PrimitiveC *primitive) { + UniqueParameter *unique_param = reinterpret_cast(malloc(sizeof(UniqueParameter))); + if (unique_param == nullptr) { + MS_LOG(ERROR) << "malloc UniqueParameter failed."; + return nullptr; + } + memset(unique_param, 0, sizeof(UniqueParameter)); + unique_param->op_parameter_.type_ = primitive->Type(); + return reinterpret_cast(unique_param); +} + +Registry UniqueParameterRegistry(schema::PrimitiveType_Unique, PopulateUniqueParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/unsqueeze_populate.cc b/mindspore/lite/src/ops/populate/unsqueeze_populate.cc new file mode 100644 index 0000000000..d4fbd20506 --- /dev/null +++ b/mindspore/lite/src/ops/populate/unsqueeze_populate.cc @@ -0,0 +1,48 @@ +/** + * Copyright 2019-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/ops/unsqueeze.h" +#include "src/common/log_adapter.h" +#include "src/tensor.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/fp32/unsqueeze.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateUnsqueezeParameter(const mindspore::lite::PrimitiveC *primitive) { + auto unsqueeze_attr = + reinterpret_cast(const_cast(primitive)); + UnsqueezeParameter *unsqueeze_param = reinterpret_cast(malloc(sizeof(UnsqueezeParameter))); + if (unsqueeze_param == nullptr) { + MS_LOG(ERROR) << "malloc UnsqueezeParameter failed."; + return nullptr; + } + memset(unsqueeze_param, 0, sizeof(UnsqueezeParameter)); + unsqueeze_param->op_parameter_.type_ = primitive->Type(); + auto flatAxis = unsqueeze_attr->GetAxis(); + unsqueeze_param->num_dim_ = flatAxis.size(); + int i = 0; + for (auto iter = flatAxis.begin(); iter != flatAxis.end(); iter++) { + unsqueeze_param->dims_[i++] = *iter; + } + return reinterpret_cast(unsqueeze_param); +} +Registry UnsqueezeParameterRegistry(schema::PrimitiveType_Unsqueeze, PopulateUnsqueezeParameter); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/populate/unstack_populate.cc b/mindspore/lite/src/ops/populate/unstack_populate.cc new file mode 100644 index 0000000000..09f9768d30 --- /dev/null +++ b/mindspore/lite/src/ops/populate/unstack_populate.cc @@ -0,0 +1,40 @@ +/** + * Copyright 2019-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/ops/unstack.h" +#include "src/ops/primitive_c.h" +#include "src/ops/populate/populate_register.h" +#include "nnacl/unstack.h" + +namespace mindspore { +namespace lite { + +OpParameter *PopulateUnstackParameter(const mindspore::lite::PrimitiveC *primitive) { + UnstackParameter *unstack_param = reinterpret_cast(malloc(sizeof(UnstackParameter))); + if (unstack_param == nullptr) { + MS_LOG(ERROR) << "malloc UnstackParameter failed."; + return nullptr; + } + memset(unstack_param, 0, sizeof(UnstackParameter)); + auto param = reinterpret_cast(const_cast(primitive)); + unstack_param->op_parameter_.type_ = primitive->Type(); + unstack_param->num_ = param->GetNum(); + unstack_param->axis_ = param->GetAxis(); + return reinterpret_cast(unstack_param); +} +Registry UnstackParameterRegistry(schema::PrimitiveType_Unstack, PopulateUnstackParameter); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/src/ops/power.cc b/mindspore/lite/src/ops/power.cc index b9ea0904e3..0e2c9a6ad5 100644 --- a/mindspore/lite/src/ops/power.cc +++ b/mindspore/lite/src/ops/power.cc @@ -16,8 +16,9 @@ #include "src/ops/power.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/power_parameter.h" +#endif namespace mindspore { namespace lite { @@ -53,23 +54,6 @@ PrimitiveC *PowerCreator(const schema::Primitive *primitive) { return PrimitiveC Registry PowerRegistry(schema::PrimitiveType_Power, PowerCreator); #endif -OpParameter *PopulatePowerParameter(const mindspore::lite::PrimitiveC *primitive) { - PowerParameter *power_param = reinterpret_cast(malloc(sizeof(PowerParameter))); - if (power_param == nullptr) { - MS_LOG(ERROR) << "malloc PowerParameter failed."; - return nullptr; - } - memset(power_param, 0, sizeof(PowerParameter)); - power_param->op_parameter_.type_ = primitive->Type(); - auto power = reinterpret_cast(const_cast(primitive)); - power_param->power_ = power->GetPower(); - power_param->scale_ = power->GetScale(); - power_param->shift_ = power->GetShift(); - return reinterpret_cast(power_param); -} - -Registry PowerParameterRegistry(schema::PrimitiveType_Power, PopulatePowerParameter); - int Power::InferShape(std::vector inputs, std::vector outputs) { MS_ASSERT(this->primitive_ != nullptr); auto x_tensor = inputs[0]; diff --git a/mindspore/lite/src/ops/power_grad.cc b/mindspore/lite/src/ops/power_grad.cc index 1178de428f..e95a3fcabf 100644 --- a/mindspore/lite/src/ops/power_grad.cc +++ b/mindspore/lite/src/ops/power_grad.cc @@ -16,7 +16,9 @@ #include "src/ops/power_grad.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/primitive_c.h b/mindspore/lite/src/ops/primitive_c.h index 631c67a978..df858cd6d9 100644 --- a/mindspore/lite/src/ops/primitive_c.h +++ b/mindspore/lite/src/ops/primitive_c.h @@ -213,9 +213,8 @@ class PrimitiveC { bool infer_flag_ = true; schema::QuantType quant_type_{schema::QuantType_QUANT_NONE}; }; - -#endif typedef PrimitiveC *(*PrimitiveCCreator)(const schema::Primitive *primitive); +#endif typedef OpParameter *(*ParameterCreator)(const PrimitiveC *primitive); } // namespace lite diff --git a/mindspore/lite/src/ops/prior_box.cc b/mindspore/lite/src/ops/prior_box.cc index 36de9bf067..f32a5c3aed 100644 --- a/mindspore/lite/src/ops/prior_box.cc +++ b/mindspore/lite/src/ops/prior_box.cc @@ -16,8 +16,9 @@ #include "src/ops/prior_box.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/prior_box.h" +#endif namespace mindspore { namespace lite { @@ -124,63 +125,6 @@ PrimitiveC *PriorBoxCreator(const schema::Primitive *primitive) { Registry PriorBoxRegistry(schema::PrimitiveType_PriorBox, PriorBoxCreator); #endif -OpParameter *PopulatePriorBoxParameter(const mindspore::lite::PrimitiveC *primitive) { - PriorBoxParameter *prior_box_param = reinterpret_cast(malloc(sizeof(PriorBoxParameter))); - if (prior_box_param == nullptr) { - MS_LOG(ERROR) << "malloc PriorBoxParameter failed."; - return nullptr; - } - memset(prior_box_param, 0, sizeof(PriorBoxParameter)); - prior_box_param->op_parameter_.type_ = primitive->Type(); - auto prior_box_attr = - reinterpret_cast(const_cast(primitive)); - - if (prior_box_attr->GetMinSizes().size() > PRIOR_BOX_MAX_NUM) { - MS_LOG(ERROR) << "PriorBox min_sizes size exceeds max num " << PRIOR_BOX_MAX_NUM << ", got " - << prior_box_attr->GetMinSizes(); - free(prior_box_param); - return nullptr; - } - prior_box_param->min_sizes_size = prior_box_attr->GetMinSizes().size(); - if (prior_box_attr->GetMaxSizes().size() > PRIOR_BOX_MAX_NUM) { - MS_LOG(ERROR) << "PriorBox max_sizes size exceeds max num " << PRIOR_BOX_MAX_NUM << ", got " - << prior_box_attr->GetMaxSizes(); - free(prior_box_param); - return nullptr; - } - prior_box_param->max_sizes_size = prior_box_attr->GetMaxSizes().size(); - memcpy(prior_box_param->max_sizes, prior_box_attr->GetMaxSizes().data(), - prior_box_attr->GetMaxSizes().size() * sizeof(int32_t)); - memcpy(prior_box_param->min_sizes, prior_box_attr->GetMinSizes().data(), - prior_box_attr->GetMinSizes().size() * sizeof(int32_t)); - - if (prior_box_attr->GetAspectRatios().size() > PRIOR_BOX_MAX_NUM) { - MS_LOG(ERROR) << "PriorBox aspect_ratios size exceeds max num " << PRIOR_BOX_MAX_NUM << ", got " - << prior_box_attr->GetAspectRatios(); - free(prior_box_param); - return nullptr; - } - prior_box_param->aspect_ratios_size = prior_box_attr->GetAspectRatios().size(); - memcpy(prior_box_param->aspect_ratios, prior_box_attr->GetAspectRatios().data(), - prior_box_attr->GetAspectRatios().size() * sizeof(float)); - if (prior_box_attr->GetVariances().size() != PRIOR_BOX_VAR_NUM) { - MS_LOG(ERROR) << "PriorBox variances size should be " << PRIOR_BOX_VAR_NUM << ", got " - << prior_box_attr->GetVariances().size(); - free(prior_box_param); - return nullptr; - } - memcpy(prior_box_param->variances, prior_box_attr->GetVariances().data(), PRIOR_BOX_VAR_NUM * sizeof(float)); - prior_box_param->flip = prior_box_attr->GetFlip(); - prior_box_param->clip = prior_box_attr->GetClip(); - prior_box_param->offset = prior_box_attr->GetOffset(); - prior_box_param->image_size_h = prior_box_attr->GetImageSizeH(); - prior_box_param->image_size_w = prior_box_attr->GetImageSizeW(); - prior_box_param->step_h = prior_box_attr->GetStepH(); - prior_box_param->step_w = prior_box_attr->GetStepW(); - return reinterpret_cast(prior_box_param); -} -Registry PriorBoxParameterRegistry(schema::PrimitiveType_PriorBox, PopulatePriorBoxParameter); - namespace { constexpr int kPriorBoxPoints = 4; constexpr int kPriorBoxN = 1; diff --git a/mindspore/lite/src/ops/quant.cc b/mindspore/lite/src/ops/quant.cc index e5ad6aed3e..9df5c609bb 100644 --- a/mindspore/lite/src/ops/quant.cc +++ b/mindspore/lite/src/ops/quant.cc @@ -18,7 +18,9 @@ #include #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/quant_dtype_cast.cc b/mindspore/lite/src/ops/quant_dtype_cast.cc index b9dfc7e06d..e42d5f46b3 100644 --- a/mindspore/lite/src/ops/quant_dtype_cast.cc +++ b/mindspore/lite/src/ops/quant_dtype_cast.cc @@ -16,8 +16,9 @@ #include "src/ops/quant_dtype_cast.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/int8/quant_dtype_cast.h" +#endif namespace mindspore { namespace lite { @@ -52,23 +53,6 @@ PrimitiveC *QuantDTypeCastCreator(const schema::Primitive *primitive) { Registry QuantDTypeCastRegistry(schema::PrimitiveType_QuantDTypeCast, QuantDTypeCastCreator); #endif -OpParameter *PopulateQuantDTypeCastParameter(const mindspore::lite::PrimitiveC *primitive) { - QuantDTypeCastParameter *parameter = - reinterpret_cast(malloc(sizeof(QuantDTypeCastParameter))); - if (parameter == nullptr) { - MS_LOG(ERROR) << "malloc QuantDTypeCastParameter failed."; - return nullptr; - } - memset(parameter, 0, sizeof(QuantDTypeCastParameter)); - parameter->op_parameter_.type_ = primitive->Type(); - auto quant_dtype_cast_param = - reinterpret_cast(const_cast(primitive)); - parameter->srcT = quant_dtype_cast_param->GetSrcT(); - parameter->dstT = quant_dtype_cast_param->GetDstT(); - return reinterpret_cast(parameter); -} -Registry QuantDTypeCastParameterRegistry(schema::PrimitiveType_QuantDTypeCast, PopulateQuantDTypeCastParameter); - int QuantDTypeCast::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/range.cc b/mindspore/lite/src/ops/range.cc index e5c64c7ad6..df4f1b8ae1 100644 --- a/mindspore/lite/src/ops/range.cc +++ b/mindspore/lite/src/ops/range.cc @@ -16,8 +16,9 @@ #include "src/ops/range.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/range.h" +#endif namespace mindspore { namespace lite { @@ -56,23 +57,6 @@ PrimitiveC *RangeCreator(const schema::Primitive *primitive) { return PrimitiveC Registry RangeRegistry(schema::PrimitiveType_Range, RangeCreator); #endif -OpParameter *PopulateRangeParameter(const mindspore::lite::PrimitiveC *primitive) { - auto range_attr = reinterpret_cast(const_cast(primitive)); - RangeParameter *range_param = reinterpret_cast(malloc(sizeof(RangeParameter))); - if (range_param == nullptr) { - MS_LOG(ERROR) << "malloc RangeParameter failed."; - return nullptr; - } - memset(range_param, 0, sizeof(RangeParameter)); - range_param->op_parameter_.type_ = primitive->Type(); - range_param->start_ = range_attr->GetStart(); - range_param->limit_ = range_attr->GetLimit(); - range_param->delta_ = range_attr->GetDelta(); - range_param->dType_ = range_attr->GetDType(); - return reinterpret_cast(range_param); -} -Registry RangeParameterRegistry(schema::PrimitiveType_Range, PopulateRangeParameter); - int Range::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/rank.cc b/mindspore/lite/src/ops/rank.cc index b4a1fed042..a3130bb5a5 100644 --- a/mindspore/lite/src/ops/rank.cc +++ b/mindspore/lite/src/ops/rank.cc @@ -16,7 +16,9 @@ #include "src/ops/rank.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/real_div.cc b/mindspore/lite/src/ops/real_div.cc index fd3f0efbda..2b36e748ed 100644 --- a/mindspore/lite/src/ops/real_div.cc +++ b/mindspore/lite/src/ops/real_div.cc @@ -15,8 +15,9 @@ */ #include "src/ops/real_div.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/arithmetic_common.h" +#endif namespace mindspore { namespace lite { @@ -45,8 +46,6 @@ int RealDiv::UnPackAttr(const Primitive &prim, const std::vector &in return RET_OK; } -Registry RealDivParameterRegistry(schema::PrimitiveType_RealDiv, PopulateArithmetic); - #else int RealDiv::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::FlatBufferBuilder *fbb) { MS_ASSERT(nullptr != primitive); diff --git a/mindspore/lite/src/ops/reduce.cc b/mindspore/lite/src/ops/reduce.cc index 4e10b0d33d..9aaee7543a 100644 --- a/mindspore/lite/src/ops/reduce.cc +++ b/mindspore/lite/src/ops/reduce.cc @@ -17,8 +17,9 @@ #include "src/ops/reduce.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/reduce_parameter.h" +#endif namespace mindspore { namespace lite { @@ -132,35 +133,6 @@ PrimitiveC *ReduceCreator(const schema::Primitive *primitive) { return Primitive Registry ReduceRegistry(schema::PrimitiveType_Reduce, ReduceCreator); #endif -OpParameter *PopulateReduceParameter(const mindspore::lite::PrimitiveC *primitive) { - ReduceParameter *reduce_param = reinterpret_cast(malloc(sizeof(ReduceParameter))); - if (reduce_param == nullptr) { - MS_LOG(ERROR) << "malloc ReduceParameter failed."; - return nullptr; - } - memset(reduce_param, 0, sizeof(ReduceParameter)); - reduce_param->op_parameter_.type_ = primitive->Type(); - auto reduce = reinterpret_cast(const_cast(primitive)); - reduce_param->keep_dims_ = reduce->GetKeepDims(); - reduce_param->reduce_to_end_ = reduce->GetReduceToEnd(); - reduce_param->coeff = reduce->GetCoeff(); - auto axisVector = reduce->GetAxes(); - if (axisVector.size() > REDUCE_MAX_AXES_NUM) { - MS_LOG(ERROR) << "Reduce axes size " << axisVector.size() << " exceed limit " << REDUCE_MAX_AXES_NUM; - free(reduce_param); - return nullptr; - } - reduce_param->num_axes_ = static_cast(axisVector.size()); - int i = 0; - for (auto iter = axisVector.begin(); iter != axisVector.end(); iter++) { - reduce_param->axes_[i++] = *iter; - } - reduce_param->mode_ = static_cast(reduce->GetMode()); - return reinterpret_cast(reduce_param); -} - -Registry ReduceParameterRegistry(schema::PrimitiveType_Reduce, PopulateReduceParameter); - namespace { constexpr size_t kInputSize = 1; constexpr size_t kOutputSize = 1; diff --git a/mindspore/lite/src/ops/reshape.cc b/mindspore/lite/src/ops/reshape.cc index 2b4b0ca863..9e6ca197a0 100644 --- a/mindspore/lite/src/ops/reshape.cc +++ b/mindspore/lite/src/ops/reshape.cc @@ -20,8 +20,9 @@ #include "include/errorcode.h" #include "src/common/log_adapter.h" #include "src/tensor.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/reshape_parameter.h" +#endif namespace mindspore { namespace lite { @@ -107,19 +108,6 @@ PrimitiveC *ReshapeCreator(const schema::Primitive *primitive) { return Primitiv Registry ReshapeRegistry(schema::PrimitiveType_Reshape, ReshapeCreator); #endif -OpParameter *PopulateReshapeParameter(const mindspore::lite::PrimitiveC *primitive) { - ReshapeParameter *reshape_param = reinterpret_cast(malloc(sizeof(ReshapeParameter))); - if (reshape_param == nullptr) { - MS_LOG(ERROR) << "malloc ReshapeParameter failed."; - return nullptr; - } - memset(reshape_param, 0, sizeof(ReshapeParameter)); - reshape_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(reshape_param); -} - -Registry ReshapeParameterRegistry(schema::PrimitiveType_Reshape, PopulateReshapeParameter); - int Reshape::CalNewShape(const Tensor *in_tensor, std::vector *out_shape) const { size_t in_shape_size = 1; for (size_t i = 0; i < in_tensor->shape().size(); i++) { diff --git a/mindspore/lite/src/ops/resize.cc b/mindspore/lite/src/ops/resize.cc index 9aa740a846..ffbb17b692 100644 --- a/mindspore/lite/src/ops/resize.cc +++ b/mindspore/lite/src/ops/resize.cc @@ -16,8 +16,9 @@ #include "src/ops/resize.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/resize_parameter.h" +#endif namespace mindspore { namespace lite { @@ -101,25 +102,6 @@ PrimitiveC *ResizeCreator(const schema::Primitive *primitive) { return Primitive Registry ResizeRegistry(schema::PrimitiveType_Resize, ResizeCreator); #endif -OpParameter *PopulateResizeParameter(const mindspore::lite::PrimitiveC *primitive) { - ResizeParameter *resize_param = reinterpret_cast(malloc(sizeof(ResizeParameter))); - if (resize_param == nullptr) { - MS_LOG(ERROR) << "malloc ResizeParameter failed."; - return nullptr; - } - memset(resize_param, 0, sizeof(ResizeParameter)); - resize_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - resize_param->method_ = static_cast(param->GetMethod()); - resize_param->new_height_ = param->GetNewHeight(); - resize_param->new_width_ = param->GetNewWidth(); - resize_param->align_corners_ = param->GetAlignCorners(); - resize_param->preserve_aspect_ratio_ = param->GetPreserveAspectRatio(); - return reinterpret_cast(resize_param); -} - -Registry ResizeParameterRegistry(schema::PrimitiveType_Resize, PopulateResizeParameter); - namespace { constexpr int kInputRank = 4; } // namespace diff --git a/mindspore/lite/src/ops/return.cc b/mindspore/lite/src/ops/return.cc index 4a13f41716..4486992e49 100644 --- a/mindspore/lite/src/ops/return.cc +++ b/mindspore/lite/src/ops/return.cc @@ -17,7 +17,9 @@ #include "src/ops/return.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/reverse.cc b/mindspore/lite/src/ops/reverse.cc index 8bb9180a0c..26efd182a5 100644 --- a/mindspore/lite/src/ops/reverse.cc +++ b/mindspore/lite/src/ops/reverse.cc @@ -16,8 +16,9 @@ #include "src/ops/reverse.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/reverse.h" +#endif namespace mindspore { namespace lite { @@ -56,26 +57,6 @@ PrimitiveC *ReverseCreator(const schema::Primitive *primitive) { return Primitiv Registry ReverseRegistry(schema::PrimitiveType_Reverse, ReverseCreator); #endif -OpParameter *PopulateReverseParameter(const mindspore::lite::PrimitiveC *primitive) { - auto reverse_attr = - reinterpret_cast(const_cast(primitive)); - ReverseParameter *reverse_param = reinterpret_cast(malloc(sizeof(ReverseParameter))); - if (reverse_param == nullptr) { - MS_LOG(ERROR) << "malloc ReverseParameter failed."; - return nullptr; - } - memset(reverse_param, 0, sizeof(ReverseParameter)); - reverse_param->op_parameter_.type_ = primitive->Type(); - auto flatAxis = reverse_attr->GetAxis(); - reverse_param->num_axis_ = flatAxis.size(); - int i = 0; - for (auto iter = flatAxis.begin(); iter != flatAxis.end(); iter++) { - reverse_param->axis_[i++] = *iter; - } - return reinterpret_cast(reverse_param); -} - -Registry ReverseParameterRegistry(schema::PrimitiveType_Reverse, PopulateReverseParameter); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/reverse_sequence.cc b/mindspore/lite/src/ops/reverse_sequence.cc index 8ffacf792f..e7c84f4ee7 100644 --- a/mindspore/lite/src/ops/reverse_sequence.cc +++ b/mindspore/lite/src/ops/reverse_sequence.cc @@ -16,8 +16,9 @@ #include "src/ops/reverse_sequence.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/reverse_sequence.h" +#endif namespace mindspore { namespace lite { @@ -56,23 +57,6 @@ Registry ReverseSequenceRegistry(schema::PrimitiveType_ReverseSequence, ReverseS #endif -OpParameter *PopulateReverseSequenceParameter(const mindspore::lite::PrimitiveC *primitive) { - ReverseSequenceParameter *reverse_sequence_param = - reinterpret_cast(malloc(sizeof(ReverseSequenceParameter))); - if (reverse_sequence_param == nullptr) { - MS_LOG(ERROR) << "malloc ReverseSequenceParameter failed."; - return nullptr; - } - memset(reverse_sequence_param, 0, sizeof(ReverseSequenceParameter)); - auto param = - reinterpret_cast(const_cast(primitive)); - reverse_sequence_param->op_parameter_.type_ = primitive->Type(); - reverse_sequence_param->seq_axis_ = param->GetSeqAxis(); - reverse_sequence_param->batch_axis_ = param->GetBatchAxis(); - return reinterpret_cast(reverse_sequence_param); -} -Registry ReverseSequenceParameterRegistry(schema::PrimitiveType_ReverseSequence, PopulateReverseSequenceParameter); - int ReverseSequence::InferShape(std::vector inputs, std::vector outputs) { auto input = inputs.front(); auto output = outputs.front(); diff --git a/mindspore/lite/src/ops/roi_pooling.cc b/mindspore/lite/src/ops/roi_pooling.cc index e1e3cd69fb..d6efa6f235 100644 --- a/mindspore/lite/src/ops/roi_pooling.cc +++ b/mindspore/lite/src/ops/roi_pooling.cc @@ -16,8 +16,9 @@ #include "src/ops/roi_pooling.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/roi_pooling.h" +#endif namespace mindspore { namespace lite { @@ -57,24 +58,6 @@ PrimitiveC *ROIPoolingCreator(const schema::Primitive *primitive) { Registry ROIPoolingRegistry(schema::PrimitiveType_ROIPooling, ROIPoolingCreator); #endif -OpParameter *PopulateROIPoolingParameter(const mindspore::lite::PrimitiveC *primitive) { - const auto param = - reinterpret_cast(const_cast(primitive)); - ROIPoolingParameter *roi_pooling_param = reinterpret_cast(malloc(sizeof(ROIPoolingParameter))); - if (roi_pooling_param == nullptr) { - MS_LOG(ERROR) << "malloc ROIPoolingParameter failed."; - return nullptr; - } - memset(roi_pooling_param, 0, sizeof(ROIPoolingParameter)); - roi_pooling_param->op_parameter_.type_ = primitive->Type(); - roi_pooling_param->pooledH_ = param->GetPooledW(); - roi_pooling_param->pooledW_ = param->GetPooledW(); - roi_pooling_param->scale_ = param->GetScale(); - return reinterpret_cast(roi_pooling_param); -} - -Registry ROIPoolingParameterRegistry(schema::PrimitiveType_ROIPooling, PopulateROIPoolingParameter); - int ROIPooling::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); if (inputs_.size() != kDoubleNum) { diff --git a/mindspore/lite/src/ops/round.cc b/mindspore/lite/src/ops/round.cc index 33e902cf4e..35512ef604 100644 --- a/mindspore/lite/src/ops/round.cc +++ b/mindspore/lite/src/ops/round.cc @@ -16,7 +16,9 @@ #include "src/ops/round.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -35,7 +37,6 @@ PrimitiveC *RoundCreator(const schema::Primitive *primitive) { return PrimitiveC Registry RoundRegistry(schema::PrimitiveType_Round, RoundCreator); #endif -Registry RoundParameterRegistry(schema::PrimitiveType_Round, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/rsqrt.cc b/mindspore/lite/src/ops/rsqrt.cc index c3de4f79e9..758bfd6ca1 100644 --- a/mindspore/lite/src/ops/rsqrt.cc +++ b/mindspore/lite/src/ops/rsqrt.cc @@ -16,7 +16,9 @@ #include "src/ops/rsqrt.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -34,7 +36,6 @@ int Rsqrt::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers:: PrimitiveC *RsqrtCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry RsqrtRegistry(schema::PrimitiveType_Rsqrt, RsqrtCreator); #endif -Registry RsqrtParameterRegistry(schema::PrimitiveType_Rsqrt, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/scale.cc b/mindspore/lite/src/ops/scale.cc index 5a852c209c..26362b1d3c 100644 --- a/mindspore/lite/src/ops/scale.cc +++ b/mindspore/lite/src/ops/scale.cc @@ -16,8 +16,9 @@ #include "src/ops/scale.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/scale.h" +#endif namespace mindspore { namespace lite { @@ -51,24 +52,5 @@ PrimitiveC *ScaleCreator(const schema::Primitive *primitive) { return PrimitiveC Registry ScaleRegistry(schema::PrimitiveType_Scale, ScaleCreator); #endif -OpParameter *PopulateScaleParameter(const mindspore::lite::PrimitiveC *primitive) { - if (primitive == nullptr) { - MS_LOG(ERROR) << "input primitive is nullptr"; - return nullptr; - } - ScaleParameter *scale_param = reinterpret_cast(malloc(sizeof(ScaleParameter))); - if (scale_param == nullptr) { - MS_LOG(ERROR) << "malloc ScaleParameter failed."; - return nullptr; - } - memset(scale_param, 0, sizeof(ScaleParameter)); - scale_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - scale_param->axis_ = param->GetAxis(); - scale_param->activation_type_ = param->GetActivationType(); - return reinterpret_cast(scale_param); -} -Registry ScaleParameterRegistry(schema::PrimitiveType_Scale, PopulateScaleParameter); - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/scatter_nd.cc b/mindspore/lite/src/ops/scatter_nd.cc index 2c3aa94675..1115e1169e 100644 --- a/mindspore/lite/src/ops/scatter_nd.cc +++ b/mindspore/lite/src/ops/scatter_nd.cc @@ -16,8 +16,9 @@ #include "src/ops/scatter_nd.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/scatter_nd.h" +#endif namespace mindspore { namespace lite { @@ -77,17 +78,5 @@ int ScatterND::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffe } #endif -OpParameter *PopulateScatterNDParameter(const mindspore::lite::PrimitiveC *primitive) { - ScatterNDParameter *scatter_nd_param = reinterpret_cast(malloc(sizeof(ScatterNDParameter))); - if (scatter_nd_param == nullptr) { - MS_LOG(ERROR) << "malloc ScatterNDParameter failed."; - return nullptr; - } - memset(scatter_nd_param, 0, sizeof(ScatterNDParameter)); - scatter_nd_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(scatter_nd_param); -} -Registry ScatterNDParameterRegistry(schema::PrimitiveType_ScatterND, PopulateScatterNDParameter); - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/sgd.cc b/mindspore/lite/src/ops/sgd.cc index b3a96e4df2..8a357deee6 100644 --- a/mindspore/lite/src/ops/sgd.cc +++ b/mindspore/lite/src/ops/sgd.cc @@ -14,7 +14,9 @@ * limitations under the License. */ #include "src/ops/sgd.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/shape.cc b/mindspore/lite/src/ops/shape.cc index a32f4ef7fe..9199467b72 100644 --- a/mindspore/lite/src/ops/shape.cc +++ b/mindspore/lite/src/ops/shape.cc @@ -19,8 +19,9 @@ #include "src/common/log_adapter.h" #include "src/tensor.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/shape.h" +#endif namespace mindspore { namespace lite { @@ -65,18 +66,5 @@ PrimitiveC *ShapeCreator(const schema::Primitive *primitive) { return PrimitiveC Registry ShapeRegistry(schema::PrimitiveType_Shape, ShapeCreator); #endif -OpParameter *PopulateShapeParameter(const mindspore::lite::PrimitiveC *primitive) { - ShapeParameter *shape_param = reinterpret_cast(malloc(sizeof(ShapeParameter))); - if (shape_param == nullptr) { - MS_LOG(ERROR) << "malloc ShapeParameter failed."; - return nullptr; - } - memset(shape_param, 0, sizeof(ShapeParameter)); - shape_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(shape_param); -} - -Registry ShapeParameterRegistry(schema::PrimitiveType_Shape, PopulateShapeParameter); - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/sin.cc b/mindspore/lite/src/ops/sin.cc index e7f4baee7c..b080f2f3da 100644 --- a/mindspore/lite/src/ops/sin.cc +++ b/mindspore/lite/src/ops/sin.cc @@ -16,7 +16,9 @@ #include "src/ops/sin.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -36,7 +38,6 @@ PrimitiveC *SinCreator(const schema::Primitive *primitive) { return PrimitiveC:: Registry SinRegistry(schema::PrimitiveType_Sin, SinCreator); #endif -Registry SinParameterRegistry(schema::PrimitiveType_Sin, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/skip_gram.cc b/mindspore/lite/src/ops/skip_gram.cc index 490619ad4b..7ccdcf9240 100644 --- a/mindspore/lite/src/ops/skip_gram.cc +++ b/mindspore/lite/src/ops/skip_gram.cc @@ -16,8 +16,9 @@ #include "src/ops/skip_gram.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/skip_gram.h" +#endif namespace mindspore { namespace lite { @@ -58,21 +59,6 @@ PrimitiveC *SkipGramCreator(const schema::Primitive *primitive) { } Registry SkipGramRegistry(schema::PrimitiveType_SkipGram, SkipGramCreator); #endif -OpParameter *PopulateSkipGramParameter(const mindspore::lite::PrimitiveC *primitive) { - SkipGramParameter *skipGramParameter = reinterpret_cast(malloc(sizeof(SkipGramParameter))); - if (skipGramParameter == nullptr) { - MS_LOG(ERROR) << "malloc SkipGramParameter failed."; - return nullptr; - } - memset(skipGramParameter, 0, sizeof(SkipGramParameter)); - skipGramParameter->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - skipGramParameter->ngram_size = param->GetNgramSize(); - skipGramParameter->max_skip_size = param->GetMaxSkipSize(); - skipGramParameter->include_all_ngrams = param->GetIncludeAllNgrams(); - return reinterpret_cast(skipGramParameter); -} -Registry SkipGramParameterRegistry(schema::PrimitiveType_SkipGram, PopulateSkipGramParameter); int SkipGram::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); diff --git a/mindspore/lite/src/ops/slice.cc b/mindspore/lite/src/ops/slice.cc index ea5f279f1c..94dbb4e8ce 100644 --- a/mindspore/lite/src/ops/slice.cc +++ b/mindspore/lite/src/ops/slice.cc @@ -19,8 +19,9 @@ #include "src/common/log_adapter.h" #include "src/tensor.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/slice_parameter.h" +#endif namespace mindspore { namespace lite { @@ -155,30 +156,6 @@ Registry SliceRegistry(schema::PrimitiveType_Slice, SliceCreator); #endif -OpParameter *PopulateSliceParameter(const mindspore::lite::PrimitiveC *primitive) { - SliceParameter *slice_param = reinterpret_cast(malloc(sizeof(SliceParameter))); - if (slice_param == nullptr) { - MS_LOG(ERROR) << "malloc SliceParameter failed."; - return nullptr; - } - memset(slice_param, 0, sizeof(SliceParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - slice_param->op_parameter_.type_ = primitive->Type(); - auto param_begin = param->GetPostProcessBegin(); - auto param_size = param->GetPostProcessSize(); - if (param_begin.size() != param_size.size()) { - free(slice_param); - return nullptr; - } - slice_param->param_length_ = static_cast(param_begin.size()); - for (int32_t i = 0; i < slice_param->param_length_; ++i) { - slice_param->begin_[i] = param_begin[i]; - slice_param->size_[i] = param_size[i]; - } - return reinterpret_cast(slice_param); -} -Registry SliceParameterRegistry(schema::PrimitiveType_Slice, PopulateSliceParameter); - std::vector Slice::GetPostProcessBegin() const { return this->begin; } std::vector Slice::GetPostProcessSize() const { return this->size; } int Slice::InferShape(std::vector inputs, std::vector outputs) { diff --git a/mindspore/lite/src/ops/softmax.cc b/mindspore/lite/src/ops/softmax.cc index 187395b8d1..099c6ee3ac 100644 --- a/mindspore/lite/src/ops/softmax.cc +++ b/mindspore/lite/src/ops/softmax.cc @@ -15,8 +15,9 @@ */ #include "src/ops/softmax.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/softmax_parameter.h" +#endif namespace mindspore { namespace lite { @@ -76,22 +77,6 @@ PrimitiveC *SoftMaxCreator(const schema::Primitive *primitive) { return Primitiv Registry SoftMaxRegistry(schema::PrimitiveType_SoftMax, SoftMaxCreator); #endif -OpParameter *PopulateSoftmaxParameter(const mindspore::lite::PrimitiveC *primitive) { - auto softmax_primitive = - reinterpret_cast(const_cast(primitive)); - SoftmaxParameter *softmax_param = reinterpret_cast(malloc(sizeof(SoftmaxParameter))); - if (softmax_param == nullptr) { - MS_LOG(ERROR) << "malloc SoftmaxParameter failed."; - return nullptr; - } - memset(softmax_param, 0, sizeof(SoftmaxParameter)); - softmax_param->op_parameter_.type_ = primitive->Type(); - softmax_param->axis_ = softmax_primitive->GetAxis(); - return reinterpret_cast(softmax_param); -} - -Registry SoftMaxParameterRegistry(schema::PrimitiveType_SoftMax, PopulateSoftmaxParameter); - int SoftMax::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/softmax_cross_entropy.cc b/mindspore/lite/src/ops/softmax_cross_entropy.cc index c7e78b0930..f2a4caaab0 100644 --- a/mindspore/lite/src/ops/softmax_cross_entropy.cc +++ b/mindspore/lite/src/ops/softmax_cross_entropy.cc @@ -16,7 +16,9 @@ #include "src/ops/softmax_cross_entropy.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/space_to_batch.cc b/mindspore/lite/src/ops/space_to_batch.cc index 0629be39f2..4e4d00e4fd 100644 --- a/mindspore/lite/src/ops/space_to_batch.cc +++ b/mindspore/lite/src/ops/space_to_batch.cc @@ -17,8 +17,9 @@ #include "src/ops/space_to_batch.h" #include "src/common/common.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/space_to_batch.h" +#endif namespace mindspore { namespace lite { @@ -75,22 +76,6 @@ PrimitiveC *SpaceToBatchCreator(const schema::Primitive *primitive) { Registry SpaceToBatchRegistry(schema::PrimitiveType_SpaceToBatch, SpaceToBatchCreator); #endif -OpParameter *PopulateSpaceToBatchParameter(const mindspore::lite::PrimitiveC *primitive) { - SpaceToBatchParameter *space_batch_param = - reinterpret_cast(malloc(sizeof(SpaceToBatchParameter))); - if (space_batch_param == nullptr) { - MS_LOG(ERROR) << "malloc SpaceToBatchParameter failed."; - return nullptr; - } - memset(space_batch_param, 0, sizeof(SpaceToBatchParameter)); - space_batch_param->op_parameter_.type_ = primitive->Type(); - auto block_sizes = ((mindspore::lite::SpaceToBatch *)primitive)->BlockSizes(); - memcpy(space_batch_param->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int)); - auto paddings = ((mindspore::lite::SpaceToBatch *)primitive)->Paddings(); - memcpy(space_batch_param->paddings_, (paddings.data()), paddings.size() * sizeof(int)); - return reinterpret_cast(space_batch_param); -} -Registry SpaceToBatchParameterRegistry(schema::PrimitiveType_SpaceToBatch, PopulateSpaceToBatchParameter); namespace { constexpr int kSpaceToBatchNDOutputNum = 1; diff --git a/mindspore/lite/src/ops/space_to_batch_nd.cc b/mindspore/lite/src/ops/space_to_batch_nd.cc index 59c89b6726..640b6e50a9 100644 --- a/mindspore/lite/src/ops/space_to_batch_nd.cc +++ b/mindspore/lite/src/ops/space_to_batch_nd.cc @@ -17,8 +17,9 @@ #include "src/ops/space_to_batch_nd.h" #include "src/common/common.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/space_to_batch.h" +#endif namespace mindspore { namespace lite { @@ -86,22 +87,6 @@ Registry SpaceToBatchNDRegistry(schema::PrimitiveType_SpaceToBatchND, SpaceToBat #endif // PRIMITIVE_WRITEABLE -OpParameter *PopulateSpaceToBatchNDParameter(const mindspore::lite::PrimitiveC *primitive) { - auto *space_batch_param_nd = new (std::nothrow) SpaceToBatchParameter(); - if (space_batch_param_nd == nullptr) { - MS_LOG(ERROR) << "new SpaceToBatchParameter failed."; - return nullptr; - } - - space_batch_param_nd->op_parameter_.type_ = primitive->Type(); - auto block_sizes = ((mindspore::lite::SpaceToBatchND *)primitive)->GetBlockShape(); - memcpy(space_batch_param_nd->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int)); - auto paddings = ((mindspore::lite::SpaceToBatchND *)primitive)->GetPaddings(); - memcpy(space_batch_param_nd->paddings_, (paddings.data()), paddings.size() * sizeof(int)); - return reinterpret_cast(space_batch_param_nd); -} -Registry SpaceToBatchNDParameterRegistry(schema::PrimitiveType_SpaceToBatchND, PopulateSpaceToBatchNDParameter); - int SpaceToBatchND::InferShape(std::vector inputs, std::vector outputs) { if (outputs.size() != kSpaceToBatchNDOutputNum || inputs.size() != kSpaceToBatchNDInputNum) { MS_LOG(ERROR) << "Invalid output/input size! output size: " << outputs.size() << ",input size: " << inputs.size(); diff --git a/mindspore/lite/src/ops/space_to_depth.cc b/mindspore/lite/src/ops/space_to_depth.cc index 2e2b53ed1a..6bb61fc84c 100644 --- a/mindspore/lite/src/ops/space_to_depth.cc +++ b/mindspore/lite/src/ops/space_to_depth.cc @@ -17,8 +17,9 @@ #include "src/ops/space_to_depth.h" #include "src/common/common.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/space_to_depth.h" +#endif namespace mindspore { namespace lite { @@ -52,26 +53,6 @@ PrimitiveC *SpaceToDepthCreator(const schema::Primitive *primitive) { } Registry SpaceToDepthRegistry(schema::PrimitiveType_SpaceToDepth, SpaceToDepthCreator); #endif -OpParameter *PopulateSpaceToDepthParameter(const mindspore::lite::PrimitiveC *primitive) { - SpaceToDepthParameter *space_depth_param = - reinterpret_cast(malloc(sizeof(SpaceToDepthParameter))); - if (space_depth_param == nullptr) { - MS_LOG(ERROR) << "malloc SpaceToDepthParameter failed."; - return nullptr; - } - memset(space_depth_param, 0, sizeof(SpaceToDepthParameter)); - space_depth_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - space_depth_param->op_parameter_.type_ = primitive->Type(); - space_depth_param->block_size_ = param->GetBlockSize(); - if (param->GetFormat() != schema::Format::Format_NHWC) { - MS_LOG(ERROR) << "Currently only NHWC format is supported."; - free(space_depth_param); - return nullptr; - } - return reinterpret_cast(space_depth_param); -} -Registry SpaceToDepthParameterRegistry(schema::PrimitiveType_SpaceToDepth, PopulateSpaceToDepthParameter); namespace { constexpr int kSpaceToDepthOutputNum = 1; diff --git a/mindspore/lite/src/ops/sparse_to_dense.cc b/mindspore/lite/src/ops/sparse_to_dense.cc index 35be40d322..9192f2823a 100644 --- a/mindspore/lite/src/ops/sparse_to_dense.cc +++ b/mindspore/lite/src/ops/sparse_to_dense.cc @@ -16,8 +16,9 @@ #include "src/ops/sparse_to_dense.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/sparse_to_dense_parameter.h" +#endif namespace mindspore { namespace lite { @@ -51,22 +52,6 @@ PrimitiveC *SparseToDenseCreator(const schema::Primitive *primitive) { Registry SparseToDenseRegistry(schema::PrimitiveType_SparseToDense, SparseToDenseCreator); #endif -OpParameter *PopulateSparseToDenseParameter(const mindspore::lite::PrimitiveC *primitive) { - SparseToDenseParameter *sparse_to_dense_param = - reinterpret_cast(malloc(sizeof(SparseToDenseParameter))); - if (sparse_to_dense_param == nullptr) { - MS_LOG(ERROR) << "malloc SparseToDenseParameter failed."; - return nullptr; - } - memset(sparse_to_dense_param, 0, sizeof(SparseToDenseParameter)); - sparse_to_dense_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - sparse_to_dense_param->validate_indices_ = param->GetValidateIndices(); - return reinterpret_cast(sparse_to_dense_param); -} - -Registry SparseToDenseParameterRegistry(schema::PrimitiveType_SparseToDense, PopulateSparseToDenseParameter); - int SparseToDense::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); MS_ASSERT(output_shape != nullptr); diff --git a/mindspore/lite/src/ops/split.cc b/mindspore/lite/src/ops/split.cc index f57634b94d..7f62a3a8a8 100644 --- a/mindspore/lite/src/ops/split.cc +++ b/mindspore/lite/src/ops/split.cc @@ -16,8 +16,9 @@ #include "src/ops/split.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/split_parameter.h" +#endif namespace mindspore { namespace lite { @@ -96,27 +97,6 @@ PrimitiveC *SplitCreator(const schema::Primitive *primitive) { return PrimitiveC Registry SplitRegistry(schema::PrimitiveType_Split, SplitCreator); #endif -OpParameter *PopulateSplitParameter(const mindspore::lite::PrimitiveC *primitive) { - SplitParameter *split_param = reinterpret_cast(malloc(sizeof(SplitParameter))); - if (split_param == nullptr) { - MS_LOG(ERROR) << "malloc SplitParameter failed."; - return nullptr; - } - memset(split_param, 0, sizeof(SplitParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - split_param->op_parameter_.type_ = primitive->Type(); - split_param->num_split_ = param->GetNumberSplit(); - auto split_sizes_vector_ = param->GetSizeSplits(); - int i = 0; - for (auto iter = split_sizes_vector_.begin(); iter != split_sizes_vector_.end(); iter++) { - split_param->split_sizes_[i++] = *iter; - } - split_param->split_dim_ = param->GetSplitDim(); - split_param->num_split_ = param->GetNumberSplit(); - return reinterpret_cast(split_param); -} -Registry SplitParameterRegistry(schema::PrimitiveType_Split, PopulateSplitParameter); - namespace { constexpr int kSplitInputNum = 1; } // namespace diff --git a/mindspore/lite/src/ops/sqrt.cc b/mindspore/lite/src/ops/sqrt.cc index 036776a1a4..e35ef381ac 100644 --- a/mindspore/lite/src/ops/sqrt.cc +++ b/mindspore/lite/src/ops/sqrt.cc @@ -16,7 +16,9 @@ #include "src/ops/sqrt.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -35,7 +37,6 @@ int Sqrt::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers::F PrimitiveC *SqrtCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry SqrtRegistry(schema::PrimitiveType_Sqrt, SqrtCreator); #endif -Registry SqrtParameterRegistry(schema::PrimitiveType_Sqrt, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/square.cc b/mindspore/lite/src/ops/square.cc index b0a32b1658..e9f179dfbd 100644 --- a/mindspore/lite/src/ops/square.cc +++ b/mindspore/lite/src/ops/square.cc @@ -16,7 +16,9 @@ #include "src/ops/square.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -35,7 +37,6 @@ int Square::UnPackToFlatBuilder(const schema::Primitive *primitive, flatbuffers: PrimitiveC *SquareCreator(const schema::Primitive *primitive) { return PrimitiveC::NewPrimitiveC(primitive); } Registry SquareRegistry(schema::PrimitiveType_Square, SquareCreator); #endif -Registry SquareGradParameterRegistry(schema::PrimitiveType_Square, PopulateArithmeticSelf); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/squared_difference.cc b/mindspore/lite/src/ops/squared_difference.cc index 3a75d91469..5ef7c43f2c 100644 --- a/mindspore/lite/src/ops/squared_difference.cc +++ b/mindspore/lite/src/ops/squared_difference.cc @@ -16,7 +16,9 @@ #include "src/ops/squared_difference.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { @@ -38,6 +40,6 @@ PrimitiveC *SquaredDifferenceCreator(const schema::Primitive *primitive) { Registry SquaredDifferenceRegistry(schema::PrimitiveType_SquaredDifference, SquaredDifferenceCreator); #endif -Registry SquaredDifferenceParameterRegistry(schema::PrimitiveType_SquaredDifference, PopulateArithmetic); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/squeeze.cc b/mindspore/lite/src/ops/squeeze.cc index eee558b2ff..32b281a07b 100644 --- a/mindspore/lite/src/ops/squeeze.cc +++ b/mindspore/lite/src/ops/squeeze.cc @@ -16,8 +16,9 @@ #include "src/ops/squeeze.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/squeeze.h" +#endif namespace mindspore { namespace lite { @@ -85,18 +86,6 @@ PrimitiveC *SqueezeCreator(const schema::Primitive *primitive) { return Primitiv Registry SqueezeRegistry(schema::PrimitiveType_Squeeze, SqueezeCreator); #endif -OpParameter *PopulateSqueezeParameter(const mindspore::lite::PrimitiveC *primitive) { - SqueezeParameter *squeeze_param = reinterpret_cast(malloc(sizeof(SqueezeParameter))); - if (squeeze_param == nullptr) { - MS_LOG(ERROR) << "malloc SqueezeParameter failed."; - return nullptr; - } - memset(squeeze_param, 0, sizeof(SqueezeParameter)); - squeeze_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(squeeze_param); -} -Registry SqueezeParameterRegistry(schema::PrimitiveType_Squeeze, PopulateSqueezeParameter); - namespace { constexpr int kSqueezeInputNum = 1; constexpr int kSqueezeOutputNum = 1; diff --git a/mindspore/lite/src/ops/stack.cc b/mindspore/lite/src/ops/stack.cc index ec20f03635..dd1daa7688 100644 --- a/mindspore/lite/src/ops/stack.cc +++ b/mindspore/lite/src/ops/stack.cc @@ -16,8 +16,9 @@ #include "src/ops/stack.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/stack_parameter.h" +#endif namespace mindspore { namespace lite { @@ -63,20 +64,6 @@ Registry StackRegistry(schema::PrimitiveType_Stack, StackCreator); #endif -OpParameter *PopulateStackParameter(const mindspore::lite::PrimitiveC *primitive) { - StackParameter *stack_param = reinterpret_cast(malloc(sizeof(StackParameter))); - if (stack_param == nullptr) { - MS_LOG(ERROR) << "malloc StackParameter failed."; - return nullptr; - } - memset(stack_param, 0, sizeof(StackParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - stack_param->op_parameter_.type_ = primitive->Type(); - stack_param->axis_ = param->GetAxis(); - return reinterpret_cast(stack_param); -} -Registry StackParameterRegistry(schema::PrimitiveType_Stack, PopulateStackParameter); - namespace { constexpr int kStackOutputNum = 1; constexpr int kStackMinInputNum = 1; diff --git a/mindspore/lite/src/ops/strided_slice.cc b/mindspore/lite/src/ops/strided_slice.cc index 98ce40a531..8b6a8fa97d 100644 --- a/mindspore/lite/src/ops/strided_slice.cc +++ b/mindspore/lite/src/ops/strided_slice.cc @@ -16,8 +16,9 @@ #include "src/ops/strided_slice.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/strided_slice.h" +#endif namespace mindspore { namespace lite { @@ -168,30 +169,6 @@ PrimitiveC *StridedSliceCreator(const schema::Primitive *primitive) { Registry StridedSliceRegistry(schema::PrimitiveType_StridedSlice, StridedSliceCreator); #endif -OpParameter *PopulateStridedSliceParameter(const mindspore::lite::PrimitiveC *primitive) { - StridedSliceParameter *strided_slice_param = - reinterpret_cast(malloc(sizeof(StridedSliceParameter))); - if (strided_slice_param == nullptr) { - MS_LOG(ERROR) << "malloc StridedSliceParameter failed."; - return nullptr; - } - memset(strided_slice_param, 0, sizeof(StridedSliceParameter)); - strided_slice_param->op_parameter_.type_ = primitive->Type(); - auto n_dims = ((lite::StridedSlice *)primitive)->NDims(); - strided_slice_param->num_axes_ = n_dims; - auto begin = ((lite::StridedSlice *)primitive)->GetBegins(); - memcpy(strided_slice_param->begins_, (begin.data()), begin.size() * sizeof(int)); - auto end = ((lite::StridedSlice *)primitive)->GetEnds(); - memcpy(strided_slice_param->ends_, (end.data()), end.size() * sizeof(int)); - auto stride = ((lite::StridedSlice *)primitive)->GetStrides(); - memcpy(strided_slice_param->strides_, (stride.data()), stride.size() * sizeof(int)); - auto in_shape = ((lite::StridedSlice *)primitive)->GetInShape(); - memcpy(strided_slice_param->in_shape_, (in_shape.data()), in_shape.size() * sizeof(int)); - return reinterpret_cast(strided_slice_param); -} - -Registry StridedSliceParameterRegistry(schema::PrimitiveType_StridedSlice, PopulateStridedSliceParameter); - namespace { constexpr size_t kStridedSliceOutputNum = 1; constexpr size_t kStridedSliceInputNum = 1; diff --git a/mindspore/lite/src/ops/sub.cc b/mindspore/lite/src/ops/sub.cc index a5e5292015..70ba6465a2 100644 --- a/mindspore/lite/src/ops/sub.cc +++ b/mindspore/lite/src/ops/sub.cc @@ -16,8 +16,9 @@ #include "src/ops/sub.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/arithmetic_common.h" +#endif namespace mindspore { namespace lite { @@ -49,26 +50,6 @@ PrimitiveC *SubCreator(const schema::Primitive *primitive) { return PrimitiveC:: Registry SubRegistry(schema::PrimitiveType_Sub, SubCreator); #endif -OpParameter *PopulateSubParameter(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); - if (arithmetic_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; - return nullptr; - } - memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); - arithmetic_param->op_parameter_.type_ = primitive->Type(); - arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); - arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); - arithmetic_param->activation_type_ = - reinterpret_cast(const_cast(primitive))->GetActivationType(); - auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); - memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); - memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); - memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - return reinterpret_cast(arithmetic_param); -} -Registry SubParameterRegistry(schema::PrimitiveType_Sub, PopulateSubParameter); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/ops/tile.cc b/mindspore/lite/src/ops/tile.cc index 786d950aa6..f9d64b5f21 100644 --- a/mindspore/lite/src/ops/tile.cc +++ b/mindspore/lite/src/ops/tile.cc @@ -17,8 +17,9 @@ #include "src/ops/tile.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/tile.h" +#endif namespace mindspore { namespace lite { @@ -116,25 +117,6 @@ PrimitiveC *TileCreator(const schema::Primitive *primitive) { return PrimitiveC: Registry TileRegistry(schema::PrimitiveType_Tile, TileCreator); #endif -OpParameter *PopulateTileParameter(const mindspore::lite::PrimitiveC *primitive) { - TileParameter *tile_param = reinterpret_cast(malloc(sizeof(TileParameter))); - if (tile_param == nullptr) { - MS_LOG(ERROR) << "malloc TileParameter failed."; - return nullptr; - } - memset(tile_param, 0, sizeof(TileParameter)); - tile_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - auto multiples = param->GetMultiples(); - tile_param->in_dim_ = multiples.size(); - for (int i = 0; i < tile_param->in_dim_; ++i) { - tile_param->multiples_[i] = multiples[i]; - } - return reinterpret_cast(tile_param); -} - -Registry TileParameterRegistry(schema::PrimitiveType_Tile, PopulateTileParameter); - int Tile::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/topk.cc b/mindspore/lite/src/ops/topk.cc index 02a02fa7a6..84a3c85d6a 100644 --- a/mindspore/lite/src/ops/topk.cc +++ b/mindspore/lite/src/ops/topk.cc @@ -16,8 +16,9 @@ #include "src/ops/topk.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/topk.h" +#endif namespace mindspore { namespace lite { @@ -51,21 +52,6 @@ Registry TopKRegistry(schema::PrimitiveType_TopK, TopKCreator); #endif -OpParameter *PopulateTopKParameter(const mindspore::lite::PrimitiveC *primitive) { - TopkParameter *topk_param = reinterpret_cast(malloc(sizeof(TopkParameter))); - if (topk_param == nullptr) { - MS_LOG(ERROR) << "malloc TopkParameter failed."; - return nullptr; - } - memset(topk_param, 0, sizeof(TopkParameter)); - topk_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - topk_param->k_ = param->GetK(); - topk_param->sorted_ = param->GetSorted(); - return reinterpret_cast(topk_param); -} -Registry TopKParameterRegistry(schema::PrimitiveType_TopK, PopulateTopKParameter); - int TopK::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); if (inputs_.size() != kSingleNum || outputs_.size() != kDoubleNum) { diff --git a/mindspore/lite/src/ops/transpose.cc b/mindspore/lite/src/ops/transpose.cc index c19610ef67..a228dda6f3 100644 --- a/mindspore/lite/src/ops/transpose.cc +++ b/mindspore/lite/src/ops/transpose.cc @@ -19,8 +19,9 @@ #include "include/errorcode.h" #include "src/common/log_adapter.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/transpose.h" +#endif namespace mindspore { namespace lite { @@ -112,27 +113,6 @@ Registry TransposeRegistry(schema::PrimitiveType_Transpose, TransposeCreator); #endif -OpParameter *PopulateTransposeParameter(const mindspore::lite::PrimitiveC *primitive) { - TransposeParameter *transpose_param = reinterpret_cast(malloc(sizeof(TransposeParameter))); - if (transpose_param == nullptr) { - MS_LOG(ERROR) << "malloc TransposeParameter failed."; - return nullptr; - } - memset(transpose_param, 0, sizeof(TransposeParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - transpose_param->op_parameter_.type_ = primitive->Type(); - auto perm_vector_ = param->GetPerm(); - int i = 0; - for (auto iter = perm_vector_.begin(); iter != perm_vector_.end(); iter++) { - transpose_param->perm_[i++] = *iter; - } - transpose_param->num_axes_ = i; - transpose_param->conjugate_ = param->GetConjugate(); - return reinterpret_cast(transpose_param); -} - -Registry TransposeParameterRegistry(schema::PrimitiveType_Transpose, PopulateTransposeParameter); - int Transpose::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/tuple_get_item.cc b/mindspore/lite/src/ops/tuple_get_item.cc index 8bc68bc4e3..2e4c0925a2 100644 --- a/mindspore/lite/src/ops/tuple_get_item.cc +++ b/mindspore/lite/src/ops/tuple_get_item.cc @@ -18,7 +18,9 @@ #include #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/unique.cc b/mindspore/lite/src/ops/unique.cc index 44d190a047..45c01553f6 100644 --- a/mindspore/lite/src/ops/unique.cc +++ b/mindspore/lite/src/ops/unique.cc @@ -16,8 +16,9 @@ #include "src/ops/unique.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/unique.h" +#endif namespace mindspore { namespace lite { @@ -47,19 +48,6 @@ PrimitiveC *UniqueCreator(const schema::Primitive *primitive) { return Primitive Registry UniqueRegistry(schema::PrimitiveType_Unique, UniqueCreator); #endif -OpParameter *PopulateUniqueParameter(const mindspore::lite::PrimitiveC *primitive) { - UniqueParameter *unique_param = reinterpret_cast(malloc(sizeof(UniqueParameter))); - if (unique_param == nullptr) { - MS_LOG(ERROR) << "malloc UniqueParameter failed."; - return nullptr; - } - memset(unique_param, 0, sizeof(UniqueParameter)); - unique_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(unique_param); -} - -Registry UniqueParameterRegistry(schema::PrimitiveType_Unique, PopulateUniqueParameter); - int Unique::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); if (inputs_.size() != kSingleNum || outputs_.size() != kDoubleNum) { diff --git a/mindspore/lite/src/ops/unsqueeze.cc b/mindspore/lite/src/ops/unsqueeze.cc index 62b8674f5f..e9cd9ed58b 100644 --- a/mindspore/lite/src/ops/unsqueeze.cc +++ b/mindspore/lite/src/ops/unsqueeze.cc @@ -19,8 +19,9 @@ #include "src/common/log_adapter.h" #include "src/tensor.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/fp32/unsqueeze.h" +#endif namespace mindspore { namespace lite { @@ -62,27 +63,6 @@ Registry UnsqueezeRegistry(schema::PrimitiveType_Unsqueeze, UnsqueezeCreator); #endif -OpParameter *PopulateUnsqueezeParameter(const mindspore::lite::PrimitiveC *primitive) { - auto unsqueeze_attr = - reinterpret_cast(const_cast(primitive)); - UnsqueezeParameter *unsqueeze_param = reinterpret_cast(malloc(sizeof(UnsqueezeParameter))); - if (unsqueeze_param == nullptr) { - MS_LOG(ERROR) << "malloc UnsqueezeParameter failed."; - return nullptr; - } - memset(unsqueeze_param, 0, sizeof(UnsqueezeParameter)); - unsqueeze_param->op_parameter_.type_ = primitive->Type(); - auto flatAxis = unsqueeze_attr->GetAxis(); - unsqueeze_param->num_dim_ = flatAxis.size(); - int i = 0; - for (auto iter = flatAxis.begin(); iter != flatAxis.end(); iter++) { - unsqueeze_param->dims_[i++] = *iter; - } - return reinterpret_cast(unsqueeze_param); -} - -Registry UnsqueezeParameterRegistry(schema::PrimitiveType_Unsqueeze, PopulateUnsqueezeParameter); - int Unsqueeze::InferShape(std::vector inputs_, std::vector outputs_) { MS_ASSERT(this->primitive_ != nullptr); auto input = inputs_.front(); diff --git a/mindspore/lite/src/ops/unstack.cc b/mindspore/lite/src/ops/unstack.cc index 0102bed99f..a9f9d929e8 100644 --- a/mindspore/lite/src/ops/unstack.cc +++ b/mindspore/lite/src/ops/unstack.cc @@ -15,8 +15,9 @@ */ #include "src/ops/unstack.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" -#include "nnacl/unstack.h" +#endif namespace mindspore { namespace lite { @@ -49,21 +50,6 @@ PrimitiveC *UnstackCreator(const schema::Primitive *primitive) { return Primitiv Registry UnstackRegistry(schema::PrimitiveType_Unstack, UnstackCreator); #endif -OpParameter *PopulateUnstackParameter(const mindspore::lite::PrimitiveC *primitive) { - UnstackParameter *unstack_param = reinterpret_cast(malloc(sizeof(UnstackParameter))); - if (unstack_param == nullptr) { - MS_LOG(ERROR) << "malloc UnstackParameter failed."; - return nullptr; - } - memset(unstack_param, 0, sizeof(UnstackParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - unstack_param->op_parameter_.type_ = primitive->Type(); - unstack_param->num_ = param->GetNum(); - unstack_param->axis_ = param->GetAxis(); - return reinterpret_cast(unstack_param); -} -Registry UnstackParameterRegistry(schema::PrimitiveType_Unstack, PopulateUnstackParameter); - int Unstack::InferShape(std::vector inputs, std::vector outputs) { auto input = inputs.at(0); MS_ASSERT(input != nullptr); diff --git a/mindspore/lite/src/ops/upsample.cc b/mindspore/lite/src/ops/upsample.cc index 776496ce19..620c0745df 100644 --- a/mindspore/lite/src/ops/upsample.cc +++ b/mindspore/lite/src/ops/upsample.cc @@ -17,7 +17,9 @@ #include "src/ops/upsample.h" #include +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/where.cc b/mindspore/lite/src/ops/where.cc index 4b3707148b..d108141a96 100644 --- a/mindspore/lite/src/ops/where.cc +++ b/mindspore/lite/src/ops/where.cc @@ -16,7 +16,9 @@ #include "src/ops/where.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/ops/zeros_like.cc b/mindspore/lite/src/ops/zeros_like.cc index 527fd21735..2ec562edfe 100644 --- a/mindspore/lite/src/ops/zeros_like.cc +++ b/mindspore/lite/src/ops/zeros_like.cc @@ -16,7 +16,9 @@ #include "src/ops/zeros_like.h" +#ifndef PRIMITIVE_WRITEABLE #include "src/ops/ops_register.h" +#endif namespace mindspore { namespace lite { diff --git a/mindspore/lite/src/populate_parameter.cc b/mindspore/lite/src/populate_parameter.cc deleted file mode 100644 index b3200e9330..0000000000 --- a/mindspore/lite/src/populate_parameter.cc +++ /dev/null @@ -1,1866 +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/populate_parameter.h" -#include "src/ops/primitive_c.h" -#include "src/common/log_adapter.h" -#include "schema/ops_generated.h" -#include "src/ops/constant_of_shape.h" -#include "src/ops/space_to_batch.h" -#include "src/ops/space_to_batch_nd.h" -#include "src/ops/conv2d.h" -#include "src/ops/roi_pooling.h" -#include "src/ops/topk.h" -#include "src/ops/broadcast_to.h" -#include "src/ops/unsqueeze.h" -#include "src/ops/unstack.h" -#include "src/ops/depth_to_space.h" -#include "src/ops/batch_to_space.h" -#include "src/ops/prior_box.h" -#include "src/ops/lstm.h" -#include "src/ops/instance_norm.h" -#include "src/ops/softmax.h" -#include "src/ops/activation.h" -#include "src/ops/deconv2d.h" -#include "src/ops/reduce.h" -#include "src/ops/pooling.h" -#include "src/ops/fused_batchnorm.h" -#include "src/ops/batch_norm.h" -#include "src/ops/power.h" -#include "src/ops/range.h" -#include "src/ops/add.h" -#include "src/ops/sub.h" -#include "src/ops/div.h" -#include "src/ops/real_div.h" -#include "src/ops/bias_add.h" -#include "src/ops/expand_dims.h" -#include "src/ops/full_connection.h" -#include "src/ops/shape.h" -#include "src/ops/elu.h" -#include "src/ops/embedding_lookup.h" -#include "src/ops/quant_dtype_cast.h" -#include "src/ops/matmul.h" -#include "src/ops/resize.h" -#include "src/ops/tile.h" -#include "src/ops/one_hot.h" -#include "src/ops/lsh_projection.h" -#include "src/ops/space_to_depth.h" -#include "src/ops/split.h" -#include "src/ops/argmax.h" -#include "src/ops/argmin.h" -#include "src/ops/cast.h" -#include "src/ops/clip.h" -#include "src/ops/reshape.h" -#include "src/ops/scale.h" -#include "src/ops/concat.h" -#include "src/ops/nchw2nhwc.h" -#include "src/ops/slice.h" -#include "src/ops/squeeze.h" -#include "src/ops/flatten.h" -#include "src/ops/mean.h" -#include "src/ops/nhwc2nchw.h" -#include "src/ops/stack.h" -#include "src/ops/crop.h" -#include "src/ops/addn.h" -#include "src/ops/gather.h" -#include "src/ops/gather_nd.h" -#include "src/ops/local_response_normalization.h" -#include "src/ops/pad.h" -#include "src/ops/leaky_relu.h" -#include "src/ops/p_relu.h" -#include "src/ops/reverse_sequence.h" -#include "src/ops/dedepthwise_conv2d.h" -#include "src/ops/depthwise_conv2d.h" -#include "src/ops/mul.h" -#include "src/ops/eltwise.h" -#include "src/ops/fill.h" -#include "src/ops/transpose.h" -#include "src/ops/log.h" -#include "src/ops/abs.h" -#include "src/ops/sin.h" -#include "src/ops/cos.h" -#include "src/ops/sqrt.h" -#include "src/ops/square.h" -#include "src/ops/exp.h" -#include "src/ops/rsqrt.h" -#include "src/ops/maximum.h" -#include "src/ops/minimum.h" -#include "src/ops/strided_slice.h" -#include "src/ops/reverse.h" -#include "src/ops/logical_and.h" -#include "src/ops/logical_or.h" -#include "src/ops/logical_not.h" -#include "src/ops/floor_div.h" -#include "src/ops/floor_mod.h" -#include "src/ops/equal.h" -#include "src/ops/not_equal.h" -#include "src/ops/less.h" -#include "src/ops/less_equal.h" -#include "src/ops/greater_equal.h" -#include "src/ops/greater.h" -#include "src/ops/floor.h" -#include "src/ops/squared_difference.h" -#include "src/ops/ceil.h" -#include "src/ops/round.h" -#include "src/ops/sparse_to_dense.h" -#include "src/ops/l2_norm.h" -#include "src/ops/neg.h" -#include "src/ops/detection_post_process.h" -#include "src/ops/skip_gram.h" -#include "src/ops/custom_predict.h" -#include "src/ops/layer_norm.h" -#include "nnacl/op_base.h" -#include "nnacl/fp32/arg_min_max.h" -#include "nnacl/fp32/cast.h" -#include "nnacl/concat_parameter.h" -#include "nnacl/fp32/slice.h" -#include "nnacl/fp32/broadcast_to.h" -#include "nnacl/reshape_parameter.h" -#include "nnacl/prelu_parameter.h" -#include "nnacl/shape.h" -#include "nnacl/fp32/constant_of_shape.h" -#include "nnacl/stack_parameter.h" -#include "nnacl/unstack.h" -#include "nnacl/depth_to_space.h" -#include "nnacl/conv_parameter.h" -#include "nnacl/lsh_projection_parameter.h" -#include "nnacl/fp32/pooling.h" -#include "nnacl/matmul_parameter.h" -#include "nnacl/fp32/roi_pooling.h" -#include "nnacl/softmax_parameter.h" -#include "nnacl/instance_norm_parameter.h" -#include "nnacl/fp32/tile.h" -#include "nnacl/fp32/topk.h" -#include "nnacl/reduce_parameter.h" -#include "nnacl/fp32/activation.h" -#include "nnacl/clip.h" -#include "nnacl/fp32/arithmetic.h" -#include "nnacl/fp32/batchnorm.h" -#include "nnacl/power.h" -#include "nnacl/fp32/range.h" -#include "nnacl/fp32/local_response_norm.h" -#include "nnacl/fp32/expandDims.h" -#include "nnacl/arithmetic_self_parameter.h" -#include "nnacl/pad_parameter.h" -#include "nnacl/fp32/fill.h" -#include "nnacl/transpose.h" -#include "nnacl/split_parameter.h" -#include "nnacl/squeeze.h" -#include "nnacl/gather_parameter.h" -#include "nnacl/fp32/reverse.h" -#include "nnacl/reverse_sequence.h" -#include "nnacl/fp32/unique.h" -#include "nnacl/scale.h" -#include "nnacl/fp32/gatherNd.h" -#include "nnacl/resize_parameter.h" -#include "nnacl/scatter_nd.h" -#include "nnacl/batch_to_space.h" -#include "nnacl/fp32/crop.h" -#include "fp32/flatten.h" -#include "nnacl/fp32/unsqueeze.h" -#include "nnacl/fp32/one_hot.h" -#include "nnacl/strided_slice.h" -#include "base/prior_box.h" -#include "nnacl/fp32/space_to_depth.h" -#include "nnacl/fp32/space_to_batch.h" -#include "nnacl/int8/quant_dtype_cast.h" -#include "nnacl/fp32/lstm.h" -#include "nnacl/fp32/embedding_lookup.h" -#include "nnacl/fp32/elu.h" -#include "mindspore/lite/nnacl/fp32/sparse_to_dense.h" -#include "nnacl/l2_norm_parameter.h" -#include "nnacl/detection_post_process_parameter.h" -#include "nnacl/fp32/exp.h" -#include "nnacl/fp32/skip_gram.h" -#include "nnacl/predict_parameter.h" -#include "nnacl/layer_norm_parameter.h" - -namespace mindspore::kernel { - -OpParameter *PopulateROIPoolingParameter(const mindspore::lite::PrimitiveC *primitive) { - const auto param = - reinterpret_cast(const_cast(primitive)); - ROIPoolingParameter *roi_pooling_param = reinterpret_cast(malloc(sizeof(ROIPoolingParameter))); - if (roi_pooling_param == nullptr) { - MS_LOG(ERROR) << "malloc ROIPoolingParameter failed."; - return nullptr; - } - memset(roi_pooling_param, 0, sizeof(ROIPoolingParameter)); - roi_pooling_param->op_parameter_.type_ = primitive->Type(); - roi_pooling_param->pooledH_ = param->GetPooledW(); - roi_pooling_param->pooledW_ = param->GetPooledW(); - roi_pooling_param->scale_ = param->GetScale(); - return reinterpret_cast(roi_pooling_param); -} - -OpParameter *PopulateBatchNorm(const mindspore::lite::PrimitiveC *primitive) { - const auto param = - reinterpret_cast(const_cast(primitive)); - BatchNormParameter *batch_norm_param = reinterpret_cast(malloc(sizeof(BatchNormParameter))); - if (batch_norm_param == nullptr) { - MS_LOG(ERROR) << "malloc BatchNormParameter failed."; - return nullptr; - } - memset(batch_norm_param, 0, sizeof(BatchNormParameter)); - batch_norm_param->op_parameter_.type_ = primitive->Type(); - batch_norm_param->epsilon_ = param->GetEpsilon(); - batch_norm_param->fused_ = false; - return reinterpret_cast(batch_norm_param); -} - -OpParameter *PopulateInstanceNorm(const mindspore::lite::PrimitiveC *primitive) { - const auto param = - reinterpret_cast(const_cast(primitive)); - InstanceNormParameter *instance_norm_param = - reinterpret_cast(malloc(sizeof(InstanceNormParameter))); - if (instance_norm_param == nullptr) { - MS_LOG(ERROR) << "malloc InstanceNormParameter failed."; - return nullptr; - } - memset(instance_norm_param, 0, sizeof(InstanceNormParameter)); - instance_norm_param->op_parameter_.type_ = primitive->Type(); - instance_norm_param->epsilon_ = param->GetEpsilon(); - instance_norm_param->fused_ = false; - return reinterpret_cast(instance_norm_param); -} - -OpParameter *PopulateFillParameter(const mindspore::lite::PrimitiveC *primitive) { - const auto param = reinterpret_cast(const_cast(primitive)); - FillParameter *fill_param = reinterpret_cast(malloc(sizeof(FillParameter))); - if (fill_param == nullptr) { - MS_LOG(ERROR) << "malloc FillParameter failed."; - return nullptr; - } - memset(fill_param, 0, sizeof(FillParameter)); - fill_param->op_parameter_.type_ = primitive->Type(); - auto flatDims = param->GetDims(); - fill_param->num_dims_ = flatDims.size(); - int i = 0; - for (auto iter = flatDims.begin(); iter != flatDims.end(); iter++) { - fill_param->dims_[i++] = *iter; - } - return reinterpret_cast(fill_param); -} - -OpParameter *PopulateExpandDimsParameter(const mindspore::lite::PrimitiveC *primitive) { - auto param = reinterpret_cast(const_cast(primitive)); - ExpandDimsParameter *expand_dims_param = reinterpret_cast(malloc(sizeof(ExpandDimsParameter))); - if (expand_dims_param == nullptr) { - MS_LOG(ERROR) << "malloc ExpandDimsParameter failed."; - return nullptr; - } - memset(expand_dims_param, 0, sizeof(ExpandDimsParameter)); - expand_dims_param->op_parameter_.type_ = primitive->Type(); - expand_dims_param->dim_ = param->GetDim(); - return reinterpret_cast(expand_dims_param); -} - -OpParameter *PopulatePReLUParameter(const mindspore::lite::PrimitiveC *primitive) { - auto param = reinterpret_cast(const_cast(primitive)); - PReluParameter *prelu_param = reinterpret_cast(malloc(sizeof(PReluParameter))); - if (prelu_param == nullptr) { - MS_LOG(ERROR) << "malloc PReluParameter failed."; - return nullptr; - } - memset(prelu_param, 0, sizeof(PReluParameter)); - prelu_param->op_parameter_.type_ = primitive->Type(); - prelu_param->channelShared = param->GetChannelShared(); - return reinterpret_cast(prelu_param); -} - -OpParameter *PopulatePoolingParameter(const mindspore::lite::PrimitiveC *primitive) { - auto pooling_primitive = - reinterpret_cast(const_cast(primitive)); - PoolingParameter *pooling_param = reinterpret_cast(malloc(sizeof(PoolingParameter))); - if (pooling_param == nullptr) { - MS_LOG(ERROR) << "malloc PoolingParameter failed."; - return nullptr; - } - memset(pooling_param, 0, sizeof(PoolingParameter)); - pooling_param->op_parameter_.type_ = primitive->Type(); - pooling_param->global_ = pooling_primitive->GetGlobal(); - pooling_param->window_w_ = pooling_primitive->GetWindowW(); - pooling_param->window_h_ = pooling_primitive->GetWindowH(); - auto pooling_lite_primitive = (lite::Pooling *)primitive; - pooling_param->pad_u_ = pooling_lite_primitive->PadUp(); - pooling_param->pad_d_ = pooling_lite_primitive->PadDown(); - pooling_param->pad_l_ = pooling_lite_primitive->PadLeft(); - pooling_param->pad_r_ = pooling_lite_primitive->PadRight(); - pooling_param->stride_w_ = pooling_primitive->GetStrideW(); - pooling_param->stride_h_ = pooling_primitive->GetStrideH(); - pooling_param->avg_mode_ = pooling_primitive->GetAvgMode(); - - auto is_global = pooling_primitive->GetGlobal(); - pooling_param->global_ = is_global; - auto pool_mode = pooling_primitive->GetPoolingMode(); - switch (pool_mode) { - case schema::PoolMode_MAX_POOLING: - pooling_param->pool_mode_ = PoolMode_MaxPool; - break; - case schema::PoolMode_MEAN_POOLING: - pooling_param->pool_mode_ = PoolMode_AvgPool; - break; - default: - pooling_param->pool_mode_ = PoolMode_No; - break; - } - - auto round_mode = pooling_primitive->GetRoundMode(); - switch (round_mode) { - case schema::RoundMode_FLOOR: - pooling_param->round_mode_ = RoundMode_Floor; - break; - case schema::RoundMode_CEIL: - pooling_param->round_mode_ = RoundMode_Ceil; - break; - default: - pooling_param->round_mode_ = RoundMode_No; - break; - } - - if (pooling_primitive->GetActivationType() == schema::ActivationType_RELU) { - pooling_param->act_type_ = ActType_Relu; - } else if (pooling_primitive->GetActivationType() == schema::ActivationType_RELU6) { - pooling_param->act_type_ = ActType_Relu6; - } else { - pooling_param->act_type_ = ActType_No; - } - return reinterpret_cast(pooling_param); -} - -OpParameter *PopulateFullconnectionParameter(const mindspore::lite::PrimitiveC *primitive) { - auto param = - reinterpret_cast(const_cast(primitive)); - MatMulParameter *matmul_param = reinterpret_cast(malloc(sizeof(MatMulParameter))); - if (matmul_param == nullptr) { - MS_LOG(ERROR) << "malloc MatMulParameter failed."; - return nullptr; - } - memset(matmul_param, 0, sizeof(MatMulParameter)); - matmul_param->op_parameter_.type_ = primitive->Type(); - matmul_param->b_transpose_ = true; - matmul_param->a_transpose_ = false; - matmul_param->has_bias_ = param->GetHasBias(); - if (param->GetActivationType() == schema::ActivationType_RELU) { - matmul_param->act_type_ = ActType_Relu; - } else if (param->GetActivationType() == schema::ActivationType_RELU6) { - matmul_param->act_type_ = ActType_Relu6; - } else { - matmul_param->act_type_ = ActType_No; - } - - return reinterpret_cast(matmul_param); -} - -OpParameter *PopulateMatMulParameter(const mindspore::lite::PrimitiveC *primitive) { - auto param = reinterpret_cast(const_cast(primitive)); - MatMulParameter *matmul_param = reinterpret_cast(malloc(sizeof(MatMulParameter))); - if (matmul_param == nullptr) { - MS_LOG(ERROR) << "malloc MatMulParameter failed."; - return nullptr; - } - memset(matmul_param, 0, sizeof(MatMulParameter)); - matmul_param->op_parameter_.type_ = primitive->Type(); - matmul_param->b_transpose_ = param->GetTransposeB(); - matmul_param->a_transpose_ = param->GetTransposeA(); - matmul_param->has_bias_ = false; - matmul_param->act_type_ = ActType_No; - return reinterpret_cast(matmul_param); -} - -OpParameter *PopulateConvParameter(const mindspore::lite::PrimitiveC *primitive) { - ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); - if (conv_param == nullptr) { - MS_LOG(ERROR) << "malloc ConvParameter failed."; - return nullptr; - } - memset(conv_param, 0, sizeof(ConvParameter)); - conv_param->op_parameter_.type_ = primitive->Type(); - auto conv_primitive = - reinterpret_cast(const_cast(primitive)); - conv_param->kernel_h_ = conv_primitive->GetKernelH(); - conv_param->kernel_w_ = conv_primitive->GetKernelW(); - conv_param->group_ = conv_primitive->GetGroup(); - conv_param->stride_h_ = conv_primitive->GetStrideH(); - conv_param->stride_w_ = conv_primitive->GetStrideW(); - - auto conv2d_lite_primitive = (lite::Conv2D *)primitive; - conv_param->pad_u_ = conv2d_lite_primitive->PadUp(); - conv_param->pad_d_ = conv2d_lite_primitive->PadDown(); - conv_param->pad_l_ = conv2d_lite_primitive->PadLeft(); - conv_param->pad_r_ = conv2d_lite_primitive->PadRight(); - conv_param->dilation_h_ = conv_primitive->GetDilateH(); - conv_param->dilation_w_ = conv_primitive->GetDilateW(); - conv_param->input_channel_ = conv_primitive->GetChannelIn(); - conv_param->output_channel_ = conv_primitive->GetChannelOut(); - conv_param->group_ = conv_primitive->GetGroup(); - auto act_type = conv_primitive->GetActivationType(); - switch (act_type) { - case schema::ActivationType_RELU: - conv_param->act_type_ = ActType_Relu; - break; - case schema::ActivationType_RELU6: - conv_param->act_type_ = ActType_Relu6; - break; - default: - conv_param->act_type_ = ActType_No; - break; - } - return reinterpret_cast(conv_param); -} - -OpParameter *PopulateConvDwParameter(const mindspore::lite::PrimitiveC *primitive) { - ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); - if (conv_param == nullptr) { - MS_LOG(ERROR) << "malloc ConvParameter failed."; - return nullptr; - } - memset(conv_param, 0, sizeof(ConvParameter)); - conv_param->op_parameter_.type_ = primitive->Type(); - - auto conv_primitive = - reinterpret_cast(const_cast(primitive)); - conv_param->kernel_h_ = conv_primitive->GetKernelH(); - conv_param->kernel_w_ = conv_primitive->GetKernelW(); - conv_param->stride_h_ = conv_primitive->GetStrideH(); - conv_param->stride_w_ = conv_primitive->GetStrideW(); - - auto convdw_lite_primitive = (lite::DepthwiseConv2D *)primitive; - conv_param->pad_u_ = convdw_lite_primitive->PadUp(); - conv_param->pad_d_ = convdw_lite_primitive->PadDown(); - conv_param->pad_l_ = convdw_lite_primitive->PadLeft(); - conv_param->pad_r_ = convdw_lite_primitive->PadRight(); - conv_param->input_channel_ = convdw_lite_primitive->GetInputChannel(); - conv_param->dilation_h_ = conv_primitive->GetDilateH(); - conv_param->dilation_w_ = conv_primitive->GetDilateW(); - auto act_type = conv_primitive->GetActivationType(); - switch (act_type) { - case schema::ActivationType_RELU: - conv_param->act_type_ = ActType_Relu; - break; - case schema::ActivationType_RELU6: - conv_param->act_type_ = ActType_Relu6; - break; - default: - conv_param->act_type_ = ActType_No; - break; - } - return reinterpret_cast(conv_param); -} - -OpParameter *PopulateDeconvDwParameter(const mindspore::lite::PrimitiveC *primitive) { - ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); - if (conv_param == nullptr) { - MS_LOG(ERROR) << "malloc ConvParameter failed."; - return nullptr; - } - memset(conv_param, 0, sizeof(ConvParameter)); - conv_param->op_parameter_.type_ = primitive->Type(); - auto conv_primitive = - reinterpret_cast(const_cast(primitive)); - conv_param->kernel_h_ = conv_primitive->GetKernelH(); - conv_param->kernel_w_ = conv_primitive->GetKernelW(); - conv_param->stride_h_ = conv_primitive->GetStrideH(); - conv_param->stride_w_ = conv_primitive->GetStrideW(); - - auto deconvdw_lite_primitive = (mindspore::lite::DeDepthwiseConv2D *)primitive; - conv_param->pad_u_ = deconvdw_lite_primitive->PadUp(); - conv_param->pad_d_ = deconvdw_lite_primitive->PadDown(); - conv_param->pad_l_ = deconvdw_lite_primitive->PadLeft(); - conv_param->pad_r_ = deconvdw_lite_primitive->PadRight(); - conv_param->dilation_h_ = conv_primitive->GetDilateH(); - conv_param->dilation_w_ = conv_primitive->GetDilateW(); - auto act_type = conv_primitive->GetActivationType(); - switch (act_type) { - case schema::ActivationType_RELU: - conv_param->act_type_ = ActType_Relu; - break; - case schema::ActivationType_RELU6: - conv_param->act_type_ = ActType_Relu6; - break; - default: - conv_param->act_type_ = ActType_No; - break; - } - return reinterpret_cast(conv_param); -} - -OpParameter *PopulateDeconvParameter(const mindspore::lite::PrimitiveC *primitive) { - ConvParameter *conv_param = reinterpret_cast(malloc(sizeof(ConvParameter))); - if (conv_param == nullptr) { - MS_LOG(ERROR) << "malloc ConvParameter failed."; - return nullptr; - } - memset(conv_param, 0, sizeof(ConvParameter)); - conv_param->op_parameter_.type_ = primitive->Type(); - auto conv_primitive = - reinterpret_cast(const_cast(primitive)); - conv_param->kernel_h_ = conv_primitive->GetKernelH(); - conv_param->kernel_w_ = conv_primitive->GetKernelW(); - conv_param->stride_h_ = conv_primitive->GetStrideH(); - conv_param->stride_w_ = conv_primitive->GetStrideW(); - - auto deconv_lite_primitive = (lite::DeConv2D *)primitive; - conv_param->pad_u_ = deconv_lite_primitive->PadUp(); - conv_param->pad_d_ = deconv_lite_primitive->PadDown(); - conv_param->pad_l_ = deconv_lite_primitive->PadLeft(); - conv_param->pad_r_ = deconv_lite_primitive->PadRight(); - conv_param->dilation_h_ = conv_primitive->GetDilateH(); - conv_param->dilation_w_ = conv_primitive->GetDilateW(); - auto act_type = conv_primitive->GetActivationType(); - switch (act_type) { - case schema::ActivationType_RELU: - conv_param->act_type_ = ActType_Relu; - break; - case schema::ActivationType_RELU6: - conv_param->act_type_ = ActType_Relu6; - break; - default: - conv_param->act_type_ = ActType_No; - break; - } - return reinterpret_cast(conv_param); -} - -OpParameter *PopulateSoftmaxParameter(const mindspore::lite::PrimitiveC *primitive) { - auto softmax_primitive = - reinterpret_cast(const_cast(primitive)); - SoftmaxParameter *softmax_param = reinterpret_cast(malloc(sizeof(SoftmaxParameter))); - if (softmax_param == nullptr) { - MS_LOG(ERROR) << "malloc SoftmaxParameter failed."; - return nullptr; - } - memset(softmax_param, 0, sizeof(SoftmaxParameter)); - softmax_param->op_parameter_.type_ = primitive->Type(); - softmax_param->axis_ = softmax_primitive->GetAxis(); - return reinterpret_cast(softmax_param); -} - -OpParameter *PopulateReduceParameter(const mindspore::lite::PrimitiveC *primitive) { - ReduceParameter *reduce_param = reinterpret_cast(malloc(sizeof(ReduceParameter))); - if (reduce_param == nullptr) { - MS_LOG(ERROR) << "malloc ReduceParameter failed."; - return nullptr; - } - memset(reduce_param, 0, sizeof(ReduceParameter)); - reduce_param->op_parameter_.type_ = primitive->Type(); - auto reduce = reinterpret_cast(const_cast(primitive)); - reduce_param->keep_dims_ = reduce->GetKeepDims(); - reduce_param->reduce_to_end_ = reduce->GetReduceToEnd(); - reduce_param->coeff = reduce->GetCoeff(); - auto axisVector = reduce->GetAxes(); - if (axisVector.size() > REDUCE_MAX_AXES_NUM) { - MS_LOG(ERROR) << "Reduce axes size " << axisVector.size() << " exceed limit " << REDUCE_MAX_AXES_NUM; - free(reduce_param); - return nullptr; - } - reduce_param->num_axes_ = static_cast(axisVector.size()); - int i = 0; - for (auto iter = axisVector.begin(); iter != axisVector.end(); iter++) { - reduce_param->axes_[i++] = *iter; - } - reduce_param->mode_ = static_cast(reduce->GetMode()); - return reinterpret_cast(reduce_param); -} - -OpParameter *PopulateMeanParameter(const mindspore::lite::PrimitiveC *primitive) { - ReduceParameter *mean_param = reinterpret_cast(malloc(sizeof(ReduceParameter))); - if (mean_param == nullptr) { - MS_LOG(ERROR) << "malloc ReduceParameter failed."; - return nullptr; - } - memset(mean_param, 0, sizeof(ReduceParameter)); - mean_param->op_parameter_.type_ = primitive->Type(); - auto mean = reinterpret_cast(const_cast(primitive)); - mean_param->keep_dims_ = mean->GetKeepDims(); - auto axisVector = mean->GetAxis(); - if (axisVector.size() > REDUCE_MAX_AXES_NUM) { - MS_LOG(ERROR) << "Reduce axes size " << axisVector.size() << " exceed limit " << REDUCE_MAX_AXES_NUM; - free(mean_param); - return nullptr; - } - mean_param->num_axes_ = static_cast(axisVector.size()); - int i = 0; - for (auto iter = axisVector.begin(); iter != axisVector.end(); iter++) { - mean_param->axes_[i++] = *iter; - } - mean_param->mode_ = static_cast(schema::ReduceMode_ReduceMean); - return reinterpret_cast(mean_param); -} - -OpParameter *PopulatePadParameter(const mindspore::lite::PrimitiveC *primitive) { - PadParameter *pad_param = reinterpret_cast(malloc(sizeof(PadParameter))); - if (pad_param == nullptr) { - MS_LOG(ERROR) << "malloc PadParameter failed."; - return nullptr; - } - memset(pad_param, 0, sizeof(PadParameter)); - pad_param->op_parameter_.type_ = primitive->Type(); - auto pad_node = reinterpret_cast(const_cast(primitive)); - pad_param->pad_mode_ = pad_node->GetPaddingMode(); - if (pad_param->pad_mode_ == static_cast(schema::PaddingMode_CONSTANT)) { - pad_param->constant_value_ = pad_node->GetConstantValue(); - auto size = pad_node->GetPaddings().size(); - if (size > MAX_PAD_SIZE) { - MS_LOG(ERROR) << "Invalid padding size: " << size; - free(pad_param); - return nullptr; - } - - for (size_t i = 0; i < MAX_PAD_SIZE - size; ++i) { - pad_param->paddings_[i] = 0; - } - for (size_t i = 0; i < size; i++) { - pad_param->paddings_[MAX_PAD_SIZE - size + i] = pad_node->GetPaddings()[i]; - } - pad_param->padding_length = MAX_PAD_SIZE; - } - - return reinterpret_cast(pad_param); -} - -OpParameter *PopulateActivationParameter(const mindspore::lite::PrimitiveC *primitive) { - ActivationParameter *act_param = reinterpret_cast(malloc(sizeof(ActivationParameter))); - if (act_param == nullptr) { - MS_LOG(ERROR) << "malloc ActivationParameter failed."; - return nullptr; - } - memset(act_param, 0, sizeof(ActivationParameter)); - act_param->op_parameter_.type_ = primitive->Type(); - auto activation = - reinterpret_cast(const_cast(primitive)); - act_param->type_ = static_cast(activation->GetType()); - act_param->alpha_ = activation->GetAlpha(); - act_param->min_val_ = activation->GetMinVal(); - act_param->max_val_ = activation->GetMaxVal(); - return reinterpret_cast(act_param); -} - -OpParameter *PopulateClipParameter(const mindspore::lite::PrimitiveC *primitive) { - ClipParameter *act_param = reinterpret_cast(malloc(sizeof(ClipParameter))); - if (act_param == nullptr) { - MS_LOG(ERROR) << "malloc ClipParameter failed."; - return nullptr; - } - memset(act_param, 0, sizeof(ClipParameter)); - act_param->op_parameter_.type_ = primitive->Type(); - auto activation = reinterpret_cast(const_cast(primitive)); - act_param->min_val_ = activation->GetMin(); - act_param->max_val_ = activation->GetMax(); - return reinterpret_cast(act_param); -} - -OpParameter *PopulateFusedBatchNorm(const mindspore::lite::PrimitiveC *primitive) { - BatchNormParameter *batch_norm_param = reinterpret_cast(malloc(sizeof(BatchNormParameter))); - if (batch_norm_param == nullptr) { - MS_LOG(ERROR) << "malloc BatchNormParameter failed."; - return nullptr; - } - memset(batch_norm_param, 0, sizeof(BatchNormParameter)); - batch_norm_param->op_parameter_.type_ = primitive->Type(); - auto param = - reinterpret_cast(const_cast(primitive)); - batch_norm_param->epsilon_ = param->GetEpsilon(); - batch_norm_param->momentum_ = param->GetMomentum(); - batch_norm_param->fused_ = true; - return reinterpret_cast(batch_norm_param); -} - -OpParameter *PopulateArithmetic(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); - if (arithmetic_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; - return nullptr; - } - memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); - arithmetic_param->op_parameter_.type_ = primitive->Type(); - arithmetic_param->broadcasting_ = ((lite::Arithmetic *)primitive)->Broadcasting(); - arithmetic_param->ndim_ = ((lite::Arithmetic *)primitive)->NDims(); - switch (primitive->Type()) { - case schema::PrimitiveType_Add: - arithmetic_param->activation_type_ = - reinterpret_cast(const_cast(primitive)) - ->GetActivationType(); - break; - case schema::PrimitiveType_Sub: - arithmetic_param->activation_type_ = - reinterpret_cast(const_cast(primitive)) - ->GetActivationType(); - break; - case schema::PrimitiveType_Mul: - arithmetic_param->activation_type_ = - reinterpret_cast(const_cast(primitive)) - ->GetActivationType(); - break; - case schema::PrimitiveType_Div: - arithmetic_param->activation_type_ = - reinterpret_cast(const_cast(primitive)) - ->GetActivationType(); - break; - default: - arithmetic_param->activation_type_ = 0; - break; - } - auto tmp_shape = ((lite::Arithmetic *)primitive)->InShape0(); - memcpy(arithmetic_param->in_shape0_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->InShape1(); - memcpy(arithmetic_param->in_shape1_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - tmp_shape = ((lite::Arithmetic *)primitive)->OutputShape(); - memcpy(arithmetic_param->out_shape_, static_cast(tmp_shape.data()), tmp_shape.size() * sizeof(int)); - return reinterpret_cast(arithmetic_param); -} - -OpParameter *PopulateEltwiseParameter(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); - if (arithmetic_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; - return nullptr; - } - memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); - auto eltwise = reinterpret_cast(const_cast(primitive)); - switch (eltwise->GetMode()) { - case schema::EltwiseMode_PROD: - arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Mul; - break; - case schema::EltwiseMode_SUM: - arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Add; - break; - case schema::EltwiseMode_MAXIMUM: - arithmetic_param->op_parameter_.type_ = schema::PrimitiveType_Maximum; - break; - default: - free(arithmetic_param); - return nullptr; - } - return reinterpret_cast(arithmetic_param); -} - -OpParameter *PopulateArithmeticSelf(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticSelfParameter *arithmetic_self_param = - reinterpret_cast(malloc(sizeof(ArithmeticSelfParameter))); - if (arithmetic_self_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticSelfParameter failed."; - return nullptr; - } - memset(arithmetic_self_param, 0, sizeof(ArithmeticSelfParameter)); - arithmetic_self_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(arithmetic_self_param); -} - -OpParameter *PopulatePowerParameter(const mindspore::lite::PrimitiveC *primitive) { - PowerParameter *power_param = reinterpret_cast(malloc(sizeof(PowerParameter))); - if (power_param == nullptr) { - MS_LOG(ERROR) << "malloc PowerParameter failed."; - return nullptr; - } - memset(power_param, 0, sizeof(PowerParameter)); - power_param->op_parameter_.type_ = primitive->Type(); - auto power = reinterpret_cast(const_cast(primitive)); - power_param->power_ = power->GetPower(); - power_param->scale_ = power->GetScale(); - power_param->shift_ = power->GetShift(); - return reinterpret_cast(power_param); -} - -OpParameter *PopulateArgMaxParameter(const mindspore::lite::PrimitiveC *primitive) { - ArgMinMaxParameter *arg_param = reinterpret_cast(malloc(sizeof(ArgMinMaxParameter))); - if (arg_param == nullptr) { - MS_LOG(ERROR) << "malloc ArgMinMaxParameter failed."; - return nullptr; - } - memset(arg_param, 0, sizeof(ArgMinMaxParameter)); - arg_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - arg_param->axis_ = param->GetAxis(); - arg_param->topk_ = param->GetTopK(); - arg_param->axis_type_ = param->GetAxisType(); - arg_param->out_value_ = param->GetOutMaxValue(); - arg_param->keep_dims_ = param->GetKeepDims(); - return reinterpret_cast(arg_param); -} - -OpParameter *PopulateArgMinParameter(const mindspore::lite::PrimitiveC *primitive) { - ArgMinMaxParameter *arg_param = reinterpret_cast(malloc(sizeof(ArgMinMaxParameter))); - if (arg_param == nullptr) { - MS_LOG(ERROR) << "malloc ArgMinMaxParameter failed."; - return nullptr; - } - memset(arg_param, 0, sizeof(ArgMinMaxParameter)); - arg_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - arg_param->axis_ = param->GetAxis(); - arg_param->topk_ = param->GetTopK(); - arg_param->axis_type_ = param->GetAxisType(); - arg_param->out_value_ = param->GetOutMaxValue(); - arg_param->keep_dims_ = param->GetKeepDims(); - return reinterpret_cast(arg_param); -} - -OpParameter *PopulateCastParameter(const mindspore::lite::PrimitiveC *primitive) { - CastParameter *cast_param = reinterpret_cast(malloc(sizeof(CastParameter))); - if (cast_param == nullptr) { - MS_LOG(ERROR) << "malloc CastParameter failed."; - return nullptr; - } - memset(cast_param, 0, sizeof(CastParameter)); - cast_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - cast_param->src_type_ = param->GetSrcT(); - cast_param->dst_type_ = param->GetDstT(); - return reinterpret_cast(cast_param); -} - -OpParameter *PopulateLocalResponseNormParameter(const mindspore::lite::PrimitiveC *primitive) { - auto local_response_norm_attr = reinterpret_cast( - const_cast(primitive)); - LocalResponseNormParameter *lrn_param = - reinterpret_cast(malloc(sizeof(LocalResponseNormParameter))); - if (lrn_param == nullptr) { - MS_LOG(ERROR) << "malloc LocalResponseNormParameter failed."; - return nullptr; - } - memset(lrn_param, 0, sizeof(LocalResponseNormParameter)); - lrn_param->op_parameter_.type_ = primitive->Type(); - lrn_param->depth_radius_ = local_response_norm_attr->GetDepthRadius(); - lrn_param->bias_ = local_response_norm_attr->GetBias(); - lrn_param->alpha_ = local_response_norm_attr->GetAlpha(); - lrn_param->beta_ = local_response_norm_attr->GetBeta(); - return reinterpret_cast(lrn_param); -} - -OpParameter *PopulateRangeParameter(const mindspore::lite::PrimitiveC *primitive) { - auto range_attr = reinterpret_cast(const_cast(primitive)); - RangeParameter *range_param = reinterpret_cast(malloc(sizeof(RangeParameter))); - if (range_param == nullptr) { - MS_LOG(ERROR) << "malloc RangeParameter failed."; - return nullptr; - } - memset(range_param, 0, sizeof(RangeParameter)); - range_param->op_parameter_.type_ = primitive->Type(); - range_param->start_ = range_attr->GetStart(); - range_param->limit_ = range_attr->GetLimit(); - range_param->delta_ = range_attr->GetDelta(); - range_param->dType_ = range_attr->GetDType(); - return reinterpret_cast(range_param); -} - -OpParameter *PopulateConcatParameter(const mindspore::lite::PrimitiveC *primitive) { - ConcatParameter *concat_param = reinterpret_cast(malloc(sizeof(ConcatParameter))); - if (concat_param == nullptr) { - MS_LOG(ERROR) << "malloc ConcatParameter failed."; - return nullptr; - } - memset(concat_param, 0, sizeof(ConcatParameter)); - concat_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - concat_param->axis_ = param->GetAxis(); - return reinterpret_cast(concat_param); -} - -OpParameter *PopulateTileParameter(const mindspore::lite::PrimitiveC *primitive) { - TileParameter *tile_param = reinterpret_cast(malloc(sizeof(TileParameter))); - if (tile_param == nullptr) { - MS_LOG(ERROR) << "malloc TileParameter failed."; - return nullptr; - } - memset(tile_param, 0, sizeof(TileParameter)); - tile_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - auto multiples = param->GetMultiples(); - tile_param->in_dim_ = multiples.size(); - for (int i = 0; i < tile_param->in_dim_; ++i) { - tile_param->multiples_[i] = multiples[i]; - } - return reinterpret_cast(tile_param); -} - -OpParameter *PopulateTopKParameter(const mindspore::lite::PrimitiveC *primitive) { - TopkParameter *topk_param = reinterpret_cast(malloc(sizeof(TopkParameter))); - if (topk_param == nullptr) { - MS_LOG(ERROR) << "malloc TopkParameter failed."; - return nullptr; - } - memset(topk_param, 0, sizeof(TopkParameter)); - topk_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - topk_param->k_ = param->GetK(); - topk_param->sorted_ = param->GetSorted(); - return reinterpret_cast(topk_param); -} - -OpParameter *PopulateNhwc2NchwParameter(const mindspore::lite::PrimitiveC *primitive) { - TransposeParameter *parameter = reinterpret_cast(malloc(sizeof(TransposeParameter))); - if (parameter == nullptr) { - MS_LOG(ERROR) << "malloc OpParameter failed."; - return nullptr; - } - memset(parameter, 0, sizeof(OpParameter)); - parameter->op_parameter_.type_ = primitive->Type(); - parameter->num_axes_ = 4; - parameter->perm_[0] = 0; - parameter->perm_[1] = 3; - parameter->perm_[2] = 1; - parameter->perm_[3] = 2; - return reinterpret_cast(parameter); -} - -OpParameter *PopulateNchw2NhwcParameter(const mindspore::lite::PrimitiveC *primitive) { - TransposeParameter *parameter = reinterpret_cast(malloc(sizeof(TransposeParameter))); - if (parameter == nullptr) { - MS_LOG(ERROR) << "malloc OpParameter failed."; - return nullptr; - } - memset(parameter, 0, sizeof(OpParameter)); - parameter->op_parameter_.type_ = primitive->Type(); - parameter->num_axes_ = 4; - parameter->perm_[0] = 0; - parameter->perm_[1] = 2; - parameter->perm_[2] = 3; - parameter->perm_[3] = 1; - return reinterpret_cast(parameter); -} - -OpParameter *PopulateTransposeParameter(const mindspore::lite::PrimitiveC *primitive) { - TransposeParameter *transpose_param = reinterpret_cast(malloc(sizeof(TransposeParameter))); - if (transpose_param == nullptr) { - MS_LOG(ERROR) << "malloc TransposeParameter failed."; - return nullptr; - } - memset(transpose_param, 0, sizeof(TransposeParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - transpose_param->op_parameter_.type_ = primitive->Type(); - auto perm_vector_ = param->GetPerm(); - int i = 0; - for (auto iter = perm_vector_.begin(); iter != perm_vector_.end(); iter++) { - transpose_param->perm_[i++] = *iter; - } - transpose_param->num_axes_ = i; - transpose_param->conjugate_ = param->GetConjugate(); - return reinterpret_cast(transpose_param); -} - -OpParameter *PopulateSplitParameter(const mindspore::lite::PrimitiveC *primitive) { - SplitParameter *split_param = reinterpret_cast(malloc(sizeof(SplitParameter))); - if (split_param == nullptr) { - MS_LOG(ERROR) << "malloc SplitParameter failed."; - return nullptr; - } - memset(split_param, 0, sizeof(SplitParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - split_param->op_parameter_.type_ = primitive->Type(); - split_param->num_split_ = param->GetNumberSplit(); - auto split_sizes_vector_ = param->GetSizeSplits(); - int i = 0; - for (auto iter = split_sizes_vector_.begin(); iter != split_sizes_vector_.end(); iter++) { - split_param->split_sizes_[i++] = *iter; - } - split_param->split_dim_ = param->GetSplitDim(); - split_param->num_split_ = param->GetNumberSplit(); - return reinterpret_cast(split_param); -} - -OpParameter *PopulateSqueezeParameter(const mindspore::lite::PrimitiveC *primitive) { - SqueezeParameter *squeeze_param = reinterpret_cast(malloc(sizeof(SqueezeParameter))); - if (squeeze_param == nullptr) { - MS_LOG(ERROR) << "malloc SqueezeParameter failed."; - return nullptr; - } - memset(squeeze_param, 0, sizeof(SqueezeParameter)); - squeeze_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(squeeze_param); -} - -OpParameter *PopulateScaleParameter(const mindspore::lite::PrimitiveC *primitive) { - if (primitive == nullptr) { - MS_LOG(ERROR) << "input primitive is nullptr"; - return nullptr; - } - ScaleParameter *scale_param = reinterpret_cast(malloc(sizeof(ScaleParameter))); - if (scale_param == nullptr) { - MS_LOG(ERROR) << "malloc ScaleParameter failed."; - return nullptr; - } - memset(scale_param, 0, sizeof(ScaleParameter)); - scale_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - scale_param->axis_ = param->GetAxis(); - scale_param->activation_type_ = param->GetActivationType(); - return reinterpret_cast(scale_param); -} - -OpParameter *PopulateGatherParameter(const mindspore::lite::PrimitiveC *primitive) { - auto gather_attr = reinterpret_cast(const_cast(primitive)); - GatherParameter *gather_param = reinterpret_cast(malloc(sizeof(GatherParameter))); - if (gather_param == nullptr) { - MS_LOG(ERROR) << "malloc GatherParameter failed."; - return nullptr; - } - memset(gather_param, 0, sizeof(GatherParameter)); - gather_param->op_parameter_.type_ = primitive->Type(); - gather_param->axis_ = gather_attr->GetAxis(); - gather_param->batchDims_ = gather_attr->GetBatchDims(); - return reinterpret_cast(gather_param); -} - -OpParameter *PopulateGatherNdParameter(const mindspore::lite::PrimitiveC *primitive) { - GatherNdParameter *gather_nd_param = reinterpret_cast(malloc(sizeof(GatherNdParameter))); - if (gather_nd_param == nullptr) { - MS_LOG(ERROR) << "malloc GatherNdParameter failed."; - return nullptr; - } - memset(gather_nd_param, 0, sizeof(GatherNdParameter)); - gather_nd_param->op_parameter_.type_ = primitive->Type(); - auto gatherNd_attr = - reinterpret_cast(const_cast(primitive)); - gather_nd_param->batchDims_ = gatherNd_attr->GetBatchDims(); - return reinterpret_cast(gather_nd_param); -} - -OpParameter *PopulateScatterNDParameter(const mindspore::lite::PrimitiveC *primitive) { - ScatterNDParameter *scatter_nd_param = reinterpret_cast(malloc(sizeof(ScatterNDParameter))); - if (scatter_nd_param == nullptr) { - MS_LOG(ERROR) << "malloc ScatterNDParameter failed."; - return nullptr; - } - memset(scatter_nd_param, 0, sizeof(ScatterNDParameter)); - scatter_nd_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(scatter_nd_param); -} - -OpParameter *PopulateSliceParameter(const mindspore::lite::PrimitiveC *primitive) { - SliceParameter *slice_param = reinterpret_cast(malloc(sizeof(SliceParameter))); - if (slice_param == nullptr) { - MS_LOG(ERROR) << "malloc SliceParameter failed."; - return nullptr; - } - memset(slice_param, 0, sizeof(SliceParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - slice_param->op_parameter_.type_ = primitive->Type(); - auto param_begin = param->GetPostProcessBegin(); - auto param_size = param->GetPostProcessSize(); - if (param_begin.size() != param_size.size()) { - free(slice_param); - return nullptr; - } - slice_param->param_length_ = static_cast(param_begin.size()); - for (int32_t i = 0; i < slice_param->param_length_; ++i) { - slice_param->begin_[i] = param_begin[i]; - slice_param->size_[i] = param_size[i]; - } - return reinterpret_cast(slice_param); -} - -OpParameter *PopulateSparseToDenseParameter(const mindspore::lite::PrimitiveC *primitive) { - SparseToDenseParameter *sparse_to_dense_param = - reinterpret_cast(malloc(sizeof(SparseToDenseParameter))); - if (sparse_to_dense_param == nullptr) { - MS_LOG(ERROR) << "malloc SparseToDenseParameter failed."; - return nullptr; - } - memset(sparse_to_dense_param, 0, sizeof(SparseToDenseParameter)); - sparse_to_dense_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - sparse_to_dense_param->validate_indices_ = param->GetValidateIndices(); - return reinterpret_cast(sparse_to_dense_param); -} - -OpParameter *PopulateBroadcastToParameter(const mindspore::lite::PrimitiveC *primitive) { - BroadcastToParameter *broadcast_param = - reinterpret_cast(malloc(sizeof(BroadcastToParameter))); - if (broadcast_param == nullptr) { - MS_LOG(ERROR) << "malloc BroadcastToParameter failed."; - return nullptr; - } - memset(broadcast_param, 0, sizeof(BroadcastToParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - broadcast_param->op_parameter_.type_ = primitive->Type(); - auto dst_shape = param->GetDstShape(); - broadcast_param->shape_size_ = dst_shape.size(); - for (size_t i = 0; i < broadcast_param->shape_size_; ++i) { - broadcast_param->shape_[i] = dst_shape[i]; - } - return reinterpret_cast(broadcast_param); -} - -OpParameter *PopulateReshapeParameter(const mindspore::lite::PrimitiveC *primitive) { - ReshapeParameter *reshape_param = reinterpret_cast(malloc(sizeof(ReshapeParameter))); - if (reshape_param == nullptr) { - MS_LOG(ERROR) << "malloc ReshapeParameter failed."; - return nullptr; - } - memset(reshape_param, 0, sizeof(ReshapeParameter)); - reshape_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(reshape_param); -} - -OpParameter *PopulateShapeParameter(const mindspore::lite::PrimitiveC *primitive) { - ShapeParameter *shape_param = reinterpret_cast(malloc(sizeof(ShapeParameter))); - if (shape_param == nullptr) { - MS_LOG(ERROR) << "malloc ShapeParameter failed."; - return nullptr; - } - memset(shape_param, 0, sizeof(ShapeParameter)); - shape_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(shape_param); -} - -OpParameter *PopulateConstantOfShapeParameter(const mindspore::lite::PrimitiveC *primitive) { - auto attr = - reinterpret_cast(const_cast(primitive)); - ConstantOfShapeParameter *param = - reinterpret_cast(malloc(sizeof(ConstantOfShapeParameter))); - if (param == nullptr) { - MS_LOG(ERROR) << "malloc ConstantOfShapeParameter failed."; - return nullptr; - } - memset(param, 0, sizeof(ConstantOfShapeParameter)); - param->op_parameter_.type_ = primitive->Type(); - param->value_ = attr->GetValue(); - return reinterpret_cast(param); -} - -OpParameter *PopulateReverseParameter(const mindspore::lite::PrimitiveC *primitive) { - auto reverse_attr = - reinterpret_cast(const_cast(primitive)); - ReverseParameter *reverse_param = reinterpret_cast(malloc(sizeof(ReverseParameter))); - if (reverse_param == nullptr) { - MS_LOG(ERROR) << "malloc ReverseParameter failed."; - return nullptr; - } - memset(reverse_param, 0, sizeof(ReverseParameter)); - reverse_param->op_parameter_.type_ = primitive->Type(); - auto flatAxis = reverse_attr->GetAxis(); - reverse_param->num_axis_ = flatAxis.size(); - int i = 0; - for (auto iter = flatAxis.begin(); iter != flatAxis.end(); iter++) { - reverse_param->axis_[i++] = *iter; - } - return reinterpret_cast(reverse_param); -} - -OpParameter *PopulateUnsqueezeParameter(const mindspore::lite::PrimitiveC *primitive) { - auto unsqueeze_attr = - reinterpret_cast(const_cast(primitive)); - UnsqueezeParameter *unsqueeze_param = reinterpret_cast(malloc(sizeof(UnsqueezeParameter))); - if (unsqueeze_param == nullptr) { - MS_LOG(ERROR) << "malloc UnsqueezeParameter failed."; - return nullptr; - } - memset(unsqueeze_param, 0, sizeof(UnsqueezeParameter)); - unsqueeze_param->op_parameter_.type_ = primitive->Type(); - auto flatAxis = unsqueeze_attr->GetAxis(); - unsqueeze_param->num_dim_ = flatAxis.size(); - int i = 0; - for (auto iter = flatAxis.begin(); iter != flatAxis.end(); iter++) { - unsqueeze_param->dims_[i++] = *iter; - } - return reinterpret_cast(unsqueeze_param); -} - -OpParameter *PopulateStackParameter(const mindspore::lite::PrimitiveC *primitive) { - StackParameter *stack_param = reinterpret_cast(malloc(sizeof(StackParameter))); - if (stack_param == nullptr) { - MS_LOG(ERROR) << "malloc StackParameter failed."; - return nullptr; - } - memset(stack_param, 0, sizeof(StackParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - stack_param->op_parameter_.type_ = primitive->Type(); - stack_param->axis_ = param->GetAxis(); - return reinterpret_cast(stack_param); -} - -OpParameter *PopulateUnstackParameter(const mindspore::lite::PrimitiveC *primitive) { - UnstackParameter *unstack_param = reinterpret_cast(malloc(sizeof(UnstackParameter))); - if (unstack_param == nullptr) { - MS_LOG(ERROR) << "malloc UnstackParameter failed."; - return nullptr; - } - memset(unstack_param, 0, sizeof(UnstackParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - unstack_param->op_parameter_.type_ = primitive->Type(); - unstack_param->num_ = param->GetNum(); - unstack_param->axis_ = param->GetAxis(); - return reinterpret_cast(unstack_param); -} - -OpParameter *PopulateReverseSequenceParameter(const mindspore::lite::PrimitiveC *primitive) { - ReverseSequenceParameter *reverse_sequence_param = - reinterpret_cast(malloc(sizeof(ReverseSequenceParameter))); - if (reverse_sequence_param == nullptr) { - MS_LOG(ERROR) << "malloc ReverseSequenceParameter failed."; - return nullptr; - } - memset(reverse_sequence_param, 0, sizeof(ReverseSequenceParameter)); - auto param = - reinterpret_cast(const_cast(primitive)); - reverse_sequence_param->op_parameter_.type_ = primitive->Type(); - reverse_sequence_param->seq_axis_ = param->GetSeqAxis(); - reverse_sequence_param->batch_axis_ = param->GetBatchAxis(); - return reinterpret_cast(reverse_sequence_param); -} - -OpParameter *PopulateUniqueParameter(const mindspore::lite::PrimitiveC *primitive) { - UniqueParameter *unique_param = reinterpret_cast(malloc(sizeof(UniqueParameter))); - if (unique_param == nullptr) { - MS_LOG(ERROR) << "malloc UniqueParameter failed."; - return nullptr; - } - memset(unique_param, 0, sizeof(UniqueParameter)); - unique_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(unique_param); -} - -OpParameter *PopulateDepthToSpaceParameter(const mindspore::lite::PrimitiveC *primitive) { - DepthToSpaceParameter *depth_space_param = - reinterpret_cast(malloc(sizeof(DepthToSpaceParameter))); - if (depth_space_param == nullptr) { - MS_LOG(ERROR) << "malloc DepthToSpaceParameter failed."; - return nullptr; - } - memset(depth_space_param, 0, sizeof(DepthToSpaceParameter)); - auto param = reinterpret_cast(const_cast(primitive)); - depth_space_param->op_parameter_.type_ = primitive->Type(); - depth_space_param->block_size_ = param->GetBlockSize(); - return reinterpret_cast(depth_space_param); -} - -OpParameter *PopulateSpaceToDepthParameter(const mindspore::lite::PrimitiveC *primitive) { - SpaceToDepthParameter *space_depth_param = - reinterpret_cast(malloc(sizeof(SpaceToDepthParameter))); - if (space_depth_param == nullptr) { - MS_LOG(ERROR) << "malloc SpaceToDepthParameter failed."; - return nullptr; - } - memset(space_depth_param, 0, sizeof(SpaceToDepthParameter)); - space_depth_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - space_depth_param->op_parameter_.type_ = primitive->Type(); - space_depth_param->block_size_ = param->GetBlockSize(); - if (param->GetFormat() != schema::Format::Format_NHWC) { - MS_LOG(ERROR) << "Currently only NHWC format is supported."; - free(space_depth_param); - return nullptr; - } - return reinterpret_cast(space_depth_param); -} - -OpParameter *PopulateSpaceToBatchParameter(const mindspore::lite::PrimitiveC *primitive) { - SpaceToBatchParameter *space_batch_param = - reinterpret_cast(malloc(sizeof(SpaceToBatchParameter))); - if (space_batch_param == nullptr) { - MS_LOG(ERROR) << "malloc SpaceToBatchParameter failed."; - return nullptr; - } - memset(space_batch_param, 0, sizeof(SpaceToBatchParameter)); - space_batch_param->op_parameter_.type_ = primitive->Type(); - auto block_sizes = ((mindspore::lite::SpaceToBatch *)primitive)->BlockSizes(); - memcpy(space_batch_param->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int)); - auto paddings = ((mindspore::lite::SpaceToBatch *)primitive)->Paddings(); - memcpy(space_batch_param->paddings_, (paddings.data()), paddings.size() * sizeof(int)); - return reinterpret_cast(space_batch_param); -} - -OpParameter *PopulateSpaceToBatchNDParameter(const mindspore::lite::PrimitiveC *primitive) { - auto *space_batch_param_nd = new (std::nothrow) SpaceToBatchParameter(); - if (space_batch_param_nd == nullptr) { - MS_LOG(ERROR) << "new SpaceToBatchParameter failed."; - return nullptr; - } - - space_batch_param_nd->op_parameter_.type_ = primitive->Type(); - auto block_sizes = ((mindspore::lite::SpaceToBatchND *)primitive)->GetBlockShape(); - memcpy(space_batch_param_nd->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int)); - auto paddings = ((mindspore::lite::SpaceToBatchND *)primitive)->GetPaddings(); - memcpy(space_batch_param_nd->paddings_, (paddings.data()), paddings.size() * sizeof(int)); - return reinterpret_cast(space_batch_param_nd); -} - -OpParameter *PopulateResizeParameter(const mindspore::lite::PrimitiveC *primitive) { - ResizeParameter *resize_param = reinterpret_cast(malloc(sizeof(ResizeParameter))); - if (resize_param == nullptr) { - MS_LOG(ERROR) << "malloc ResizeParameter failed."; - return nullptr; - } - memset(resize_param, 0, sizeof(ResizeParameter)); - resize_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - resize_param->method_ = static_cast(param->GetMethod()); - resize_param->new_height_ = param->GetNewHeight(); - resize_param->new_width_ = param->GetNewWidth(); - resize_param->align_corners_ = param->GetAlignCorners(); - resize_param->preserve_aspect_ratio_ = param->GetPreserveAspectRatio(); - return reinterpret_cast(resize_param); -} - -OpParameter *PopulateBatchToSpaceParameter(const mindspore::lite::PrimitiveC *primitive) { - BatchToSpaceParameter *batch_space_param = - reinterpret_cast(malloc(sizeof(BatchToSpaceParameter))); - if (batch_space_param == nullptr) { - MS_LOG(ERROR) << "malloc BatchToSpaceParameter failed."; - return nullptr; - } - memset(batch_space_param, 0, sizeof(BatchToSpaceParameter)); - batch_space_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - auto block_shape = param->GetBlockShape(); - if (block_shape.size() != BATCH_TO_SPACE_BLOCK_SHAPE_SIZE) { - MS_LOG(ERROR) << "batch_to_space blockShape size should be " << BATCH_TO_SPACE_BLOCK_SHAPE_SIZE; - free(batch_space_param); - return nullptr; - } - - auto crops = param->GetCrops(); - if (crops.size() != BATCH_TO_SPACE_CROPS_SIZE) { - MS_LOG(ERROR) << "batch_to_space crops size should be " << BATCH_TO_SPACE_CROPS_SIZE; - free(batch_space_param); - return nullptr; - } - - for (int i = 0; i < BATCH_TO_SPACE_BLOCK_SHAPE_SIZE; ++i) { - batch_space_param->block_shape_[i] = block_shape[i]; - } - - for (int i = 0; i < BATCH_TO_SPACE_CROPS_SIZE; ++i) { - batch_space_param->crops_[i] = crops[i]; - } - return reinterpret_cast(batch_space_param); -} - -OpParameter *PopulateCropParameter(const mindspore::lite::PrimitiveC *primitive) { - auto param = reinterpret_cast(const_cast(primitive)); - auto param_offset = param->GetOffsets(); - if (param_offset.size() > CROP_OFFSET_MAX_SIZE) { - MS_LOG(ERROR) << "crop_param offset size(" << param_offset.size() << ") should <= " << CROP_OFFSET_MAX_SIZE; - return nullptr; - } - CropParameter *crop_param = reinterpret_cast(malloc(sizeof(CropParameter))); - if (crop_param == nullptr) { - MS_LOG(ERROR) << "malloc CropParameter failed."; - return nullptr; - } - memset(crop_param, 0, sizeof(CropParameter)); - crop_param->op_parameter_.type_ = primitive->Type(); - crop_param->axis_ = param->GetAxis(); - crop_param->offset_size_ = param_offset.size(); - for (size_t i = 0; i < param_offset.size(); ++i) { - crop_param->offset_[i] = param_offset[i]; - } - return reinterpret_cast(crop_param); -} - -OpParameter *PopulateLshProjectionParameter(const mindspore::lite::PrimitiveC *primitive) { - LshProjectionParameter *lsh_project_param = - reinterpret_cast(malloc(sizeof(LshProjectionParameter))); - if (lsh_project_param == nullptr) { - MS_LOG(ERROR) << "malloc LshProjectionParameter failed."; - return nullptr; - } - memset(lsh_project_param, 0, sizeof(LshProjectionParameter)); - lsh_project_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - lsh_project_param->lsh_type_ = param->GetLshType(); - return reinterpret_cast(lsh_project_param); -} - -OpParameter *PopulateOneHotParameter(const mindspore::lite::PrimitiveC *primitive) { - OneHotParameter *one_hot_param = reinterpret_cast(malloc(sizeof(OneHotParameter))); - if (one_hot_param == nullptr) { - MS_LOG(ERROR) << "malloc OneHotParameter failed."; - return nullptr; - } - memset(one_hot_param, 0, sizeof(OneHotParameter)); - one_hot_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - if (param == nullptr) { - free(one_hot_param); - MS_LOG(ERROR) << "get OneHot param nullptr."; - return nullptr; - } - one_hot_param->axis_ = param->GetAxis(); - return reinterpret_cast(one_hot_param); -} - -OpParameter *PopulateFlattenParameter(const mindspore::lite::PrimitiveC *primitive) { - FlattenParameter *flatten_param = reinterpret_cast(malloc(sizeof(FlattenParameter))); - if (flatten_param == nullptr) { - MS_LOG(ERROR) << "malloc FlattenParameter failed."; - return nullptr; - } - memset(flatten_param, 0, sizeof(FlattenParameter)); - flatten_param->op_parameter_.type_ = primitive->Type(); - return reinterpret_cast(flatten_param); -} - -OpParameter *PopulateQuantDTypeCastParameter(const mindspore::lite::PrimitiveC *primitive) { - QuantDTypeCastParameter *parameter = - reinterpret_cast(malloc(sizeof(QuantDTypeCastParameter))); - if (parameter == nullptr) { - MS_LOG(ERROR) << "malloc QuantDTypeCastParameter failed."; - return nullptr; - } - memset(parameter, 0, sizeof(QuantDTypeCastParameter)); - parameter->op_parameter_.type_ = primitive->Type(); - auto quant_dtype_cast_param = - reinterpret_cast(const_cast(primitive)); - parameter->srcT = quant_dtype_cast_param->GetSrcT(); - parameter->dstT = quant_dtype_cast_param->GetDstT(); - return reinterpret_cast(parameter); -} - -OpParameter *PopulateStridedSliceParameter(const mindspore::lite::PrimitiveC *primitive) { - StridedSliceParameter *strided_slice_param = - reinterpret_cast(malloc(sizeof(StridedSliceParameter))); - if (strided_slice_param == nullptr) { - MS_LOG(ERROR) << "malloc StridedSliceParameter failed."; - return nullptr; - } - memset(strided_slice_param, 0, sizeof(StridedSliceParameter)); - strided_slice_param->op_parameter_.type_ = primitive->Type(); - auto n_dims = ((lite::StridedSlice *)primitive)->NDims(); - strided_slice_param->num_axes_ = n_dims; - auto begin = ((lite::StridedSlice *)primitive)->GetBegins(); - memcpy(strided_slice_param->begins_, (begin.data()), begin.size() * sizeof(int)); - auto end = ((lite::StridedSlice *)primitive)->GetEnds(); - memcpy(strided_slice_param->ends_, (end.data()), end.size() * sizeof(int)); - auto stride = ((lite::StridedSlice *)primitive)->GetStrides(); - memcpy(strided_slice_param->strides_, (stride.data()), stride.size() * sizeof(int)); - auto in_shape = ((lite::StridedSlice *)primitive)->GetInShape(); - memcpy(strided_slice_param->in_shape_, (in_shape.data()), in_shape.size() * sizeof(int)); - return reinterpret_cast(strided_slice_param); -} - -OpParameter *PopulateAddNParameter(const mindspore::lite::PrimitiveC *primitive) { - OpParameter *addn_param = reinterpret_cast(malloc(sizeof(OpParameter))); - if (addn_param == nullptr) { - MS_LOG(ERROR) << "malloc OpParameter failed."; - return nullptr; - } - memset(addn_param, 0, sizeof(OpParameter)); - addn_param->type_ = primitive->Type(); - return reinterpret_cast(addn_param); -} - -OpParameter *PopulatePriorBoxParameter(const mindspore::lite::PrimitiveC *primitive) { - PriorBoxParameter *prior_box_param = reinterpret_cast(malloc(sizeof(PriorBoxParameter))); - if (prior_box_param == nullptr) { - MS_LOG(ERROR) << "malloc PriorBoxParameter failed."; - return nullptr; - } - memset(prior_box_param, 0, sizeof(PriorBoxParameter)); - prior_box_param->op_parameter_.type_ = primitive->Type(); - auto prior_box_attr = - reinterpret_cast(const_cast(primitive)); - - if (prior_box_attr->GetMinSizes().size() > PRIOR_BOX_MAX_NUM) { - MS_LOG(ERROR) << "PriorBox min_sizes size exceeds max num " << PRIOR_BOX_MAX_NUM << ", got " - << prior_box_attr->GetMinSizes(); - free(prior_box_param); - return nullptr; - } - prior_box_param->min_sizes_size = prior_box_attr->GetMinSizes().size(); - if (prior_box_attr->GetMaxSizes().size() > PRIOR_BOX_MAX_NUM) { - MS_LOG(ERROR) << "PriorBox max_sizes size exceeds max num " << PRIOR_BOX_MAX_NUM << ", got " - << prior_box_attr->GetMaxSizes(); - free(prior_box_param); - return nullptr; - } - prior_box_param->max_sizes_size = prior_box_attr->GetMaxSizes().size(); - memcpy(prior_box_param->max_sizes, prior_box_attr->GetMaxSizes().data(), - prior_box_attr->GetMaxSizes().size() * sizeof(int32_t)); - memcpy(prior_box_param->min_sizes, prior_box_attr->GetMinSizes().data(), - prior_box_attr->GetMinSizes().size() * sizeof(int32_t)); - - if (prior_box_attr->GetAspectRatios().size() > PRIOR_BOX_MAX_NUM) { - MS_LOG(ERROR) << "PriorBox aspect_ratios size exceeds max num " << PRIOR_BOX_MAX_NUM << ", got " - << prior_box_attr->GetAspectRatios(); - free(prior_box_param); - return nullptr; - } - prior_box_param->aspect_ratios_size = prior_box_attr->GetAspectRatios().size(); - memcpy(prior_box_param->aspect_ratios, prior_box_attr->GetAspectRatios().data(), - prior_box_attr->GetAspectRatios().size() * sizeof(float)); - if (prior_box_attr->GetVariances().size() != PRIOR_BOX_VAR_NUM) { - MS_LOG(ERROR) << "PriorBox variances size should be " << PRIOR_BOX_VAR_NUM << ", got " - << prior_box_attr->GetVariances().size(); - free(prior_box_param); - return nullptr; - } - memcpy(prior_box_param->variances, prior_box_attr->GetVariances().data(), PRIOR_BOX_VAR_NUM * sizeof(float)); - prior_box_param->flip = prior_box_attr->GetFlip(); - prior_box_param->clip = prior_box_attr->GetClip(); - prior_box_param->offset = prior_box_attr->GetOffset(); - prior_box_param->image_size_h = prior_box_attr->GetImageSizeH(); - prior_box_param->image_size_w = prior_box_attr->GetImageSizeW(); - prior_box_param->step_h = prior_box_attr->GetStepH(); - prior_box_param->step_w = prior_box_attr->GetStepW(); - return reinterpret_cast(prior_box_param); -} - -OpParameter *PopulateLstmParameter(const mindspore::lite::PrimitiveC *primitive) { - LstmParameter *lstm_param = reinterpret_cast(malloc(sizeof(LstmParameter))); - if (lstm_param == nullptr) { - MS_LOG(ERROR) << "malloc LstmParameter failed."; - return nullptr; - } - memset(lstm_param, 0, sizeof(LstmParameter)); - lstm_param->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - if (param == nullptr) { - free(lstm_param); - MS_LOG(ERROR) << "get Lstm param nullptr."; - return nullptr; - } - lstm_param->bidirectional_ = param->GetBidirection(); - return reinterpret_cast(lstm_param); -} - -OpParameter *PopulateEmbeddingLookupParameter(const mindspore::lite::PrimitiveC *primitive) { - EmbeddingLookupParameter *embedding_lookup_parameter = - reinterpret_cast(malloc(sizeof(EmbeddingLookupParameter))); - if (embedding_lookup_parameter == nullptr) { - MS_LOG(ERROR) << "malloc EmbeddingLookupParameter failed."; - return nullptr; - } - memset(embedding_lookup_parameter, 0, sizeof(EmbeddingLookupParameter)); - embedding_lookup_parameter->op_parameter_.type_ = primitive->Type(); - auto param = - reinterpret_cast(const_cast(primitive)); - embedding_lookup_parameter->max_norm_ = param->GetMaxNorm(); - if (embedding_lookup_parameter->max_norm_ < 0) { - MS_LOG(ERROR) << "Embedding lookup max norm should be positive number, got " - << embedding_lookup_parameter->max_norm_; - free(embedding_lookup_parameter); - return nullptr; - } - return reinterpret_cast(embedding_lookup_parameter); -} - -OpParameter *PopulateBiasAddParameter(const mindspore::lite::PrimitiveC *primitive) { - ArithmeticParameter *arithmetic_param = reinterpret_cast(malloc(sizeof(ArithmeticParameter))); - if (arithmetic_param == nullptr) { - MS_LOG(ERROR) << "malloc ArithmeticParameter failed."; - return nullptr; - } - memset(arithmetic_param, 0, sizeof(ArithmeticParameter)); - arithmetic_param->op_parameter_.type_ = primitive->Type(); - - return reinterpret_cast(arithmetic_param); -} - -OpParameter *PopulateEluParameter(const mindspore::lite::PrimitiveC *primitive) { - EluParameter *elu_parameter = reinterpret_cast(malloc(sizeof(EluParameter))); - if (elu_parameter == nullptr) { - MS_LOG(ERROR) << "malloc EluParameter failed."; - return nullptr; - } - memset(elu_parameter, 0, sizeof(EluParameter)); - elu_parameter->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - elu_parameter->alpha_ = param->GetAlpha(); - return reinterpret_cast(elu_parameter); -} - -OpParameter *PopulateL2NormParameter(const mindspore::lite::PrimitiveC *primitive) { - L2NormParameter *l2_norm_parameter = reinterpret_cast(malloc(sizeof(L2NormParameter))); - if (l2_norm_parameter == nullptr) { - MS_LOG(ERROR) << "malloc L2NormParameter failed."; - return nullptr; - } - memset(l2_norm_parameter, 0, sizeof(L2NormParameter)); - l2_norm_parameter->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - auto axis_vec = param->GetAxis(); - l2_norm_parameter->axis_num_ = axis_vec.size(); - l2_norm_parameter->axis_ = reinterpret_cast(malloc(axis_vec.size() * sizeof(int))); - if (l2_norm_parameter->axis_ == nullptr) { - MS_LOG(ERROR) << "malloc axis_ data failed"; - free(l2_norm_parameter); - return nullptr; - } - for (size_t i = 0; i < axis_vec.size(); i++) { - l2_norm_parameter->axis_[i] = axis_vec[i]; - } - if (param->GetEpsilon() < 1e-6) { - l2_norm_parameter->epsilon_ = 1e-6; - } else { - l2_norm_parameter->epsilon_ = param->GetEpsilon(); - } - if (param->GetActivationType() == static_cast(schema::ActivationType_RELU)) { - l2_norm_parameter->act_type_ = ActType_Relu; - } else if (param->GetActivationType() == static_cast(schema::ActivationType_RELU6)) { - l2_norm_parameter->act_type_ = ActType_Relu6; - } else { - l2_norm_parameter->act_type_ = ActType_No; - } - return reinterpret_cast(l2_norm_parameter); -} - -OpParameter *PopulateDetectionPostProcessParameter(const mindspore::lite::PrimitiveC *primitive) { - DetectionPostProcessParameter *detection_post_process_parameter = - reinterpret_cast(malloc(sizeof(DetectionPostProcessParameter))); - if (detection_post_process_parameter == nullptr) { - MS_LOG(ERROR) << "malloc EluParameter failed."; - return nullptr; - } - memset(detection_post_process_parameter, 0, sizeof(DetectionPostProcessParameter)); - detection_post_process_parameter->op_parameter_.type_ = primitive->Type(); - auto param = - reinterpret_cast(const_cast(primitive)); - detection_post_process_parameter->h_scale_ = param->GetHScale(); - detection_post_process_parameter->w_scale_ = param->GetWScale(); - detection_post_process_parameter->x_scale_ = param->GetXScale(); - detection_post_process_parameter->y_scale_ = param->GetYScale(); - detection_post_process_parameter->nms_iou_threshold_ = param->GetNmsIouThreshold(); - detection_post_process_parameter->nms_score_threshold_ = param->GetNmsScoreThreshold(); - detection_post_process_parameter->max_detections_ = param->GetMaxDetections(); - detection_post_process_parameter->detections_per_class_ = param->GetDetectionsPerClass(); - detection_post_process_parameter->max_classes_per_detection_ = param->GetMaxClassesPerDetection(); - detection_post_process_parameter->num_classes_ = param->GetNumClasses(); - detection_post_process_parameter->use_regular_nms_ = param->GetUseRegularNms(); - return reinterpret_cast(detection_post_process_parameter); -} - -OpParameter *PopulateExpParameter(const mindspore::lite::PrimitiveC *primitive) { - ExpParameter *exp_parameter = reinterpret_cast(malloc(sizeof(ExpParameter))); - if (exp_parameter == nullptr) { - MS_LOG(ERROR) << "malloc ExpParameter failed."; - return nullptr; - } - memset(exp_parameter, 0, sizeof(ExpParameter)); - exp_parameter->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - exp_parameter->base_ = param->GetBase(); - exp_parameter->scale_ = param->GetScale(); - exp_parameter->shift_ = param->GetShift(); - if (exp_parameter->base_ != -1 && exp_parameter->base_ <= 0) { - MS_LOG(ERROR) << "Exp base must be strictly positive, got " << exp_parameter->base_; - free(exp_parameter); - return nullptr; - } - return reinterpret_cast(exp_parameter); -} - -OpParameter *PopulateSkipGramParameter(const mindspore::lite::PrimitiveC *primitive) { - SkipGramParameter *skipGramParameter = reinterpret_cast(malloc(sizeof(SkipGramParameter))); - if (skipGramParameter == nullptr) { - MS_LOG(ERROR) << "malloc SkipGramParameter failed."; - return nullptr; - } - memset(skipGramParameter, 0, sizeof(SkipGramParameter)); - skipGramParameter->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - skipGramParameter->ngram_size = param->GetNgramSize(); - skipGramParameter->max_skip_size = param->GetMaxSkipSize(); - skipGramParameter->include_all_ngrams = param->GetIncludeAllNgrams(); - return reinterpret_cast(skipGramParameter); -} - -OpParameter *PopulateCommonOpParameter(const mindspore::lite::PrimitiveC *primitive) { - OpParameter *param = reinterpret_cast(malloc(sizeof(OpParameter))); - if (param == nullptr) { - MS_LOG(ERROR) << "new OpParameter failed."; - return nullptr; - } - memset(param, 0, sizeof(OpParameter)); - param->type_ = primitive->Type(); - return param; -} - -OpParameter *PopulateCustomPredictParameter(const mindspore::lite::PrimitiveC *primitive) { - PredictParameter *param = reinterpret_cast(malloc(sizeof(PredictParameter))); - if (param == nullptr) { - MS_LOG(ERROR) << "malloc param failed."; - return nullptr; - } - memset(param, 0, sizeof(PredictParameter)); - param->op_parameter_.type_ = primitive->Type(); - auto prim = reinterpret_cast(const_cast(primitive)); - param->output_num = prim->GetOutputNum(); - param->weight_threshold = prim->GetWeightThreshold(); - return reinterpret_cast(param); -} - -OpParameter *PopulateLayerNormParameter(const mindspore::lite::PrimitiveC *primitive) { - auto layer_norm_parameter = reinterpret_cast(malloc(sizeof(LayerNormParameter))); - if (layer_norm_parameter == nullptr) { - MS_LOG(ERROR) << "malloc LayerNormParameter failed."; - return nullptr; - } - memset(layer_norm_parameter, 0, sizeof(LayerNormParameter)); - layer_norm_parameter->op_parameter_.type_ = primitive->Type(); - auto param = reinterpret_cast(const_cast(primitive)); - auto normalized_shape = param->GetNormalizedShape(); - layer_norm_parameter->normalized_dims_ = normalized_shape.size(); - layer_norm_parameter->normalized_shape_ = reinterpret_cast(malloc(normalized_shape.size() * sizeof(int))); - for (size_t i = 0; i < normalized_shape.size(); i++) { - layer_norm_parameter->normalized_shape_[i] = normalized_shape[i]; - } - layer_norm_parameter->epsilon_ = param->GetEpsilon(); - layer_norm_parameter->elementwise_affine_ = param->GetElementwiseAffine(); - - return reinterpret_cast(layer_norm_parameter); -} - -PopulateParameterRegistry::PopulateParameterRegistry() { - populate_parameter_funcs_[schema::PrimitiveType_SparseToDense] = PopulateSparseToDenseParameter; - populate_parameter_funcs_[schema::PrimitiveType_SoftMax] = PopulateSoftmaxParameter; - populate_parameter_funcs_[schema::PrimitiveType_Activation] = PopulateActivationParameter; - populate_parameter_funcs_[schema::PrimitiveType_Clip] = PopulateClipParameter; - populate_parameter_funcs_[schema::PrimitiveType_Conv2D] = PopulateConvParameter; - populate_parameter_funcs_[schema::PrimitiveType_Reduce] = PopulateReduceParameter; - populate_parameter_funcs_[schema::PrimitiveType_Mean] = PopulateMeanParameter; - populate_parameter_funcs_[schema::PrimitiveType_Pooling] = PopulatePoolingParameter; - populate_parameter_funcs_[schema::PrimitiveType_ROIPooling] = PopulateROIPoolingParameter; - populate_parameter_funcs_[schema::PrimitiveType_DepthwiseConv2D] = PopulateConvDwParameter; - populate_parameter_funcs_[schema::PrimitiveType_DeDepthwiseConv2D] = PopulateDeconvDwParameter; - populate_parameter_funcs_[schema::PrimitiveType_DeConv2D] = PopulateDeconvParameter; - populate_parameter_funcs_[schema::PrimitiveType_FusedBatchNorm] = PopulateFusedBatchNorm; - populate_parameter_funcs_[schema::PrimitiveType_BatchNorm] = PopulateBatchNorm; - populate_parameter_funcs_[schema::PrimitiveType_FullConnection] = PopulateFullconnectionParameter; - populate_parameter_funcs_[schema::PrimitiveType_Power] = PopulatePowerParameter; - populate_parameter_funcs_[schema::PrimitiveType_LocalResponseNormalization] = PopulateLocalResponseNormParameter; - populate_parameter_funcs_[schema::PrimitiveType_Range] = PopulateRangeParameter; - populate_parameter_funcs_[schema::PrimitiveType_Transpose] = PopulateTransposeParameter; - populate_parameter_funcs_[schema::PrimitiveType_Mul] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_Add] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_Sub] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_Div] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_RealDiv] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_LogicalAnd] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_LogicalOr] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_Equal] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_Less] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_Greater] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_NotEqual] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_LessEqual] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_GreaterEqual] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_Maximum] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_Minimum] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_FloorDiv] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_FloorMod] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_SquaredDifference] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_BiasAdd] = PopulateBiasAddParameter; - populate_parameter_funcs_[schema::PrimitiveType_Eltwise] = PopulateEltwiseParameter; - populate_parameter_funcs_[schema::PrimitiveType_ExpandDims] = PopulateExpandDimsParameter; - populate_parameter_funcs_[schema::PrimitiveType_Abs] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_Cos] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_Sin] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_Exp] = PopulateExpParameter; - populate_parameter_funcs_[schema::PrimitiveType_Log] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_Neg] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_NegGrad] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_LogGrad] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_Square] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_Sqrt] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_Rsqrt] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_LogicalNot] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_Floor] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_Ceil] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_Round] = PopulateArithmeticSelf; - populate_parameter_funcs_[schema::PrimitiveType_ArgMax] = PopulateArgMaxParameter; - populate_parameter_funcs_[schema::PrimitiveType_ArgMin] = PopulateArgMinParameter; - populate_parameter_funcs_[schema::PrimitiveType_Cast] = PopulateCastParameter; - populate_parameter_funcs_[schema::PrimitiveType_Scale] = PopulateScaleParameter; - populate_parameter_funcs_[schema::PrimitiveType_Reshape] = PopulateReshapeParameter; - populate_parameter_funcs_[schema::PrimitiveType_ConstantOfShape] = PopulateConstantOfShapeParameter; - populate_parameter_funcs_[schema::PrimitiveType_Shape] = PopulateShapeParameter; - populate_parameter_funcs_[schema::PrimitiveType_Concat] = PopulateConcatParameter; - populate_parameter_funcs_[schema::PrimitiveType_Tile] = PopulateTileParameter; - populate_parameter_funcs_[schema::PrimitiveType_TopK] = PopulateTopKParameter; - populate_parameter_funcs_[schema::PrimitiveType_Fill] = PopulateFillParameter; - populate_parameter_funcs_[schema::PrimitiveType_Gather] = PopulateGatherParameter; - populate_parameter_funcs_[schema::PrimitiveType_GatherNd] = PopulateGatherNdParameter; - populate_parameter_funcs_[schema::PrimitiveType_Slice] = PopulateSliceParameter; - populate_parameter_funcs_[schema::PrimitiveType_BroadcastTo] = PopulateBroadcastToParameter; - populate_parameter_funcs_[schema::PrimitiveType_Reverse] = PopulateReverseParameter; - populate_parameter_funcs_[schema::PrimitiveType_Stack] = PopulateStackParameter; - populate_parameter_funcs_[schema::PrimitiveType_Unstack] = PopulateUnstackParameter; - populate_parameter_funcs_[schema::PrimitiveType_ReverseSequence] = PopulateReverseSequenceParameter; - populate_parameter_funcs_[schema::PrimitiveType_Unique] = PopulateUniqueParameter; - populate_parameter_funcs_[schema::PrimitiveType_DepthToSpace] = PopulateDepthToSpaceParameter; - populate_parameter_funcs_[schema::PrimitiveType_Nchw2Nhwc] = PopulateNchw2NhwcParameter; - populate_parameter_funcs_[schema::PrimitiveType_Nhwc2Nchw] = PopulateNhwc2NchwParameter; - populate_parameter_funcs_[schema::PrimitiveType_Pad] = PopulatePadParameter; - populate_parameter_funcs_[schema::PrimitiveType_Resize] = PopulateResizeParameter; - populate_parameter_funcs_[schema::PrimitiveType_BatchToSpace] = PopulateBatchToSpaceParameter; - populate_parameter_funcs_[schema::PrimitiveType_BatchToSpaceND] = PopulateBatchToSpaceParameter; - populate_parameter_funcs_[schema::PrimitiveType_SpaceToDepth] = PopulateSpaceToDepthParameter; - populate_parameter_funcs_[schema::PrimitiveType_SpaceToBatch] = PopulateSpaceToBatchParameter; - populate_parameter_funcs_[schema::PrimitiveType_SpaceToBatchND] = PopulateSpaceToBatchNDParameter; - populate_parameter_funcs_[schema::PrimitiveType_Crop] = PopulateCropParameter; - populate_parameter_funcs_[schema::PrimitiveType_Unsqueeze] = PopulateUnsqueezeParameter; - populate_parameter_funcs_[schema::PrimitiveType_Flatten] = PopulateFlattenParameter; - populate_parameter_funcs_[schema::PrimitiveType_MatMul] = PopulateMatMulParameter; - populate_parameter_funcs_[schema::PrimitiveType_OneHot] = PopulateOneHotParameter; - populate_parameter_funcs_[schema::PrimitiveType_AddN] = PopulateAddNParameter; - populate_parameter_funcs_[schema::PrimitiveType_StridedSlice] = PopulateStridedSliceParameter; - populate_parameter_funcs_[schema::PrimitiveType_ScatterND] = PopulateScatterNDParameter; - populate_parameter_funcs_[schema::PrimitiveType_Squeeze] = PopulateSqueezeParameter; - populate_parameter_funcs_[schema::PrimitiveType_Split] = PopulateSplitParameter; - populate_parameter_funcs_[schema::PrimitiveType_PReLU] = PopulatePReLUParameter; - populate_parameter_funcs_[schema::PrimitiveType_PriorBox] = PopulatePriorBoxParameter; - populate_parameter_funcs_[schema::PrimitiveType_QuantDTypeCast] = PopulateQuantDTypeCastParameter; - populate_parameter_funcs_[schema::PrimitiveType_Lstm] = PopulateLstmParameter; - populate_parameter_funcs_[schema::PrimitiveType_EmbeddingLookup] = PopulateEmbeddingLookupParameter; - populate_parameter_funcs_[schema::PrimitiveType_Elu] = PopulateEluParameter; - populate_parameter_funcs_[schema::PrimitiveType_L2Norm] = PopulateL2NormParameter; - populate_parameter_funcs_[schema::PrimitiveType_DetectionPostProcess] = PopulateDetectionPostProcessParameter; - populate_parameter_funcs_[schema::PrimitiveType_CustomNormalize] = PopulateCommonOpParameter; - populate_parameter_funcs_[schema::PrimitiveType_SkipGram] = PopulateSkipGramParameter; - populate_parameter_funcs_[schema::PrimitiveType_CustomExtractFeatures] = PopulateCommonOpParameter; - populate_parameter_funcs_[schema::PrimitiveType_LshProjection] = PopulateLshProjectionParameter; - populate_parameter_funcs_[schema::PrimitiveType_CustomPredict] = PopulateCustomPredictParameter; - populate_parameter_funcs_[schema::PrimitiveType_HashtableLookup] = PopulateCommonOpParameter; - populate_parameter_funcs_[schema::PrimitiveType_LayerNorm] = PopulateLayerNormParameter; -} - -PopulateParameterRegistry *PopulateParameterRegistry::GetInstance() { - static PopulateParameterRegistry populate_parameter_instance; - return &populate_parameter_instance; -} - -PopulateParameterFunc PopulateParameterRegistry::GetParameterFunc(int type) { - return populate_parameter_funcs_[schema::PrimitiveType(type)]; -} - -int PopulateParameterRegistry::AddPopulateParameterFunc(const schema::PrimitiveType &type, PopulateParameterFunc func) { - if ((type < schema::PrimitiveType_MIN) || (type > schema::PrimitiveType_MAX)) return -1; - populate_parameter_funcs_[type] = func; - return 0; -} - -OpParameter *PopulateParameter(const mindspore::lite::PrimitiveC *primitive) { - if (primitive == nullptr) { - MS_LOG(ERROR) << "Primitive is nullptr when populating parameter for op."; - return nullptr; - } - - auto op_type = primitive->Type(); - auto func = PopulateParameterRegistry::GetInstance()->GetParameterFunc(op_type); - if (func == nullptr) { - MS_LOG(ERROR) << "Get nullptr for Op Parameter Func."; - return nullptr; - } - - auto *parameter = func(primitive); - if (parameter == nullptr) { - MS_LOG(ERROR) << "Get nullptr for Op Parameter."; - return nullptr; - } - return parameter; -} -} // namespace mindspore::kernel diff --git a/mindspore/lite/src/populate_parameter.h b/mindspore/lite/src/populate_parameter.h deleted file mode 100644 index de994dfc65..0000000000 --- a/mindspore/lite/src/populate_parameter.h +++ /dev/null @@ -1,45 +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_POPULATE_PARAMETER_H_ -#define MINDSPORE_LITE_SRC_POPULATE_PARAMETER_H_ - -#include "src/ops/primitive_c.h" -#include "schema/model_generated.h" -#include "nnacl/op_base.h" - -namespace mindspore::kernel { -typedef OpParameter *(*PopulateParameterFunc)(const mindspore::lite::PrimitiveC *); - -class PopulateParameterRegistry { - public: - PopulateParameterRegistry(); - ~PopulateParameterRegistry() = default; - - static PopulateParameterRegistry *GetInstance(); - int AddPopulateParameterFunc(const schema::PrimitiveType &type, PopulateParameterFunc func); - PopulateParameterFunc GetParameterFunc(int type); - - protected: - PopulateParameterFunc populate_parameter_funcs_[schema::PrimitiveType_MAX + 1]; -}; - -OpParameter *PopulateActivationParameter(const lite::PrimitiveC *primitive); -OpParameter *PopulateArithmetic(const lite::PrimitiveC *primitive); - -OpParameter *PopulateParameter(const mindspore::lite::PrimitiveC *primitive); -} // namespace mindspore::kernel -#endif // MINDSPORE_LITE_SRC_POPULATE_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc index 92517f03a9..410fdcfa08 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc @@ -15,14 +15,12 @@ */ #include "src/runtime/kernel/arm/fp32/arithmetic.h" - #include "include/errorcode.h" #include "schema/model_generated.h" #include "src/kernel_registry.h" #include "src/runtime/kernel/arm/int8/add_int8.h" -#include "src/runtime/kernel/arm/int8/mul_int8.h" #include "src/runtime/runtime_api.h" -#include "src/populate_parameter.h" +#include "src/ops/populate/populate_register.h" using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; @@ -50,7 +48,7 @@ int ArithmeticCPUKernel::PreProcess() { MS_LOG(ERROR) << "InferShape fail!"; return ret; } - arithmeticParameter_ = reinterpret_cast(kernel::PopulateArithmetic(primitive_)); + arithmeticParameter_ = reinterpret_cast(PopulateArithmetic(primitive_)); ret = ReSize(); if (ret != 0) { MS_LOG(ERROR) << "ReSize fail!ret: " << ret; diff --git a/mindspore/lite/src/train/train_populate_parameter.cc b/mindspore/lite/src/train/train_populate_parameter.cc index f856c406aa..e0ba28a391 100644 --- a/mindspore/lite/src/train/train_populate_parameter.cc +++ b/mindspore/lite/src/train/train_populate_parameter.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/populate_parameter.h" #include "src/train/train_populate_parameter.h" +#include "src/ops/populate/populate_register.h" #include "src/ops/pooling_grad.h" #include "nnacl/pooling_parameter.h" #include "src/ops/softmax_cross_entropy.h" @@ -377,23 +377,25 @@ OpParameter *PopulateBNGradParameter(const mindspore::lite::PrimitiveC *primitiv } void PopulateTrainParameters() { - auto ppr = PopulateParameterRegistry::GetInstance(); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_ApplyMomentum, PopulateApplyMomentumParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_BiasGrad, PopulateBiasGradParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_SoftmaxCrossEntropy, PopulateSoftmaxCrossEntropyParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_ActivationGrad, PopulateActivationGradParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_TupleGetItem, DefaultPopulateParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_Depend, DefaultPopulateParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_BNGrad, DefaultPopulateParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_Conv2DGradFilter, PopulateConvolutionGradFilterParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_Conv2DGradInput, PopulateConvolutionGradInputParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_GroupConv2DGradInput, PopulateGroupConvolutionGradInputParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_PoolingGrad, PopulatePoolingGradParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_PowerGrad, PopulatePowerGradParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_Sgd, PopulateSgdParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_BNGrad, PopulateBNGradParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_Adam, PopulateAdamParameter); - ppr->AddPopulateParameterFunc(schema::PrimitiveType_Assign, DefaultPopulateParameter); + lite::Registry ApplyMomentumParameterRegistry(schema::PrimitiveType_ApplyMomentum, PopulateApplyMomentumParameter); + lite::Registry BiasGradParameterRegistry(schema::PrimitiveType_BiasGrad, PopulateBiasGradParameter); + lite::Registry SoftmaxCrossEntropyParameterRegistry(schema::PrimitiveType_SoftmaxCrossEntropy, + PopulateSoftmaxCrossEntropyParameter); + lite::Registry ActivationParameterRegistry(schema::PrimitiveType_ActivationGrad, PopulateActivationGradParameter); + lite::Registry TupleGetItemParameterRegistry(schema::PrimitiveType_TupleGetItem, DefaultPopulateParameter); + lite::Registry DependParameterRegistry(schema::PrimitiveType_Depend, DefaultPopulateParameter); + lite::Registry Conv2DGradFilterParameterRegistry(schema::PrimitiveType_Conv2DGradFilter, + PopulateConvolutionGradFilterParameter); + lite::Registry Conv2DGradInputParameterRegistry(schema::PrimitiveType_Conv2DGradInput, + PopulateConvolutionGradInputParameter); + lite::Registry GroupConv2DGradInputParameterRegistry(schema::PrimitiveType_GroupConv2DGradInput, + PopulateGroupConvolutionGradInputParameter); + lite::Registry PoolingParameterRegistry(schema::PrimitiveType_PoolingGrad, PopulatePoolingGradParameter); + lite::Registry PowerGradParameterRegistry(schema::PrimitiveType_PowerGrad, PopulatePowerGradParameter); + lite::Registry SgdParameterRegistry(schema::PrimitiveType_Sgd, PopulateSgdParameter); + lite::Registry BNGradParameterRegistry(schema::PrimitiveType_BNGrad, PopulateBNGradParameter); + lite::Registry AdamParameterRegistry(schema::PrimitiveType_Adam, PopulateAdamParameter); + lite::Registry AssignParameterRegistry(schema::PrimitiveType_Assign, DefaultPopulateParameter); } } // namespace mindspore::kernel diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index 9fcea8a0f4..1e4dda9b75 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -101,7 +101,7 @@ if (BUILD_MINDDATA STREQUAL "lite") elseif (BUILD_MINDDATA STREQUAL "full") endif() ### runtime framework -file(GLOB_RECURSE OPS_SRC ${LITE_DIR}/src/ops/*.cc) +file(GLOB_RECURSE OPS_SRC ${LITE_DIR}/src/ops/*.cc ${LITE_DIR}/src/ops/populate/*.cc) set(TEST_LITE_SRC ${TEST_LITE_SRC} ${CCSRC_SRC} @@ -121,7 +121,6 @@ set(TEST_LITE_SRC ${LITE_DIR}/src/sub_graph_kernel.cc ${LITE_DIR}/src/model.cc ${LITE_DIR}/src/model_common.cc - ${LITE_DIR}/src/populate_parameter.cc ${LITE_DIR}/src/scheduler.cc ${LITE_DIR}/src/common/graph_util.cc ${LITE_DIR}/src/common/file_utils.cc diff --git a/mindspore/lite/tools/converter/CMakeLists.txt b/mindspore/lite/tools/converter/CMakeLists.txt index d8610213de..a94e90ab8b 100644 --- a/mindspore/lite/tools/converter/CMakeLists.txt +++ b/mindspore/lite/tools/converter/CMakeLists.txt @@ -5,11 +5,12 @@ set(CCSRC_SRC ${CCSRC_DIR}/backend/optimizer/common/pattern_engine.cc ${CCSRC_DIR}/backend/optimizer/common/visit.cc ${CCSRC_DIR}/backend/optimizer/common/optimizer.cc -) + ) include(${TOP_DIR}/cmake/external_libs/glog.cmake) -file(GLOB_RECURSE OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/*.cc) +file(GLOB_RECURSE OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/*.cc + ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/populate/*.cc) file(GLOB_RECURSE CONVERTER_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../flag/flag_parser.cc @@ -68,7 +69,6 @@ set(LITE_SRC ${SRC_DIR}/tensor.cc ${SRC_DIR}/kernel_registry.cc ${SRC_DIR}/lite_kernel.cc - ${SRC_DIR}/populate_parameter.cc ${SRC_DIR}/scheduler.cc ${SRC_DIR}/sub_graph_kernel.cc ${SRC_DIR}/lite_session.cc @@ -77,9 +77,9 @@ set(LITE_SRC ${SRC_DIR}/model_common.cc ) if (SUPPORT_TRAIN) -set(LITE_SRC - ${LITE_SRC} - ) + set(LITE_SRC + ${LITE_SRC} + ) endif () set(ARM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/kernel/arm) @@ -153,17 +153,17 @@ if (NOT PLATFORM_ARM64 AND NOT PLATFORM_ARM32) RUNTIME DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME}) if (WIN32) get_filename_component(CXX_DIR ${CMAKE_CXX_COMPILER} PATH) - file(GLOB LIB_LIST ${CXX_DIR}/libstdc++-6.dll ${CXX_DIR}/libwinpthread-1.dll ${CXX_DIR}/libssp-0.dll ${CXX_DIR}/libgcc_s_seh-1.dll) + file(GLOB LIB_LIST ${CXX_DIR}/libstdc++-6.dll ${CXX_DIR}/libwinpthread-1.dll ${CXX_DIR}/libssp-0.dll ${CXX_DIR}/libgcc_s_seh-1.dll) install(FILES ${LIB_LIST} DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME}) install(FILES ${TOP_DIR}/build/mindspore/tools/converter/mindspore_core/gvar/libmindspore_gvar.dll DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME}) install(FILES ${glog_LIBPATH}/../bin/libglog.dll DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME}) - else() + else () install(FILES ${TOP_DIR}/mindspore/lite/build/tools/converter/mindspore_core/gvar/libmindspore_gvar.so DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/lib COMPONENT ${COMPONENT_NAME}) install(FILES ${glog_LIBPATH}/libglog.so.0.4.0 DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/third_party/glog/lib RENAME libglog.so.0 COMPONENT ${COMPONENT_NAME}) endif () -endif() +endif () diff --git a/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc b/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc index 1d3631beb0..ffbafa4113 100644 --- a/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc +++ b/mindspore/lite/tools/optimizer/fusion/constant_folding_fusion.cc @@ -22,9 +22,9 @@ #include "tools/anf_exporter/anf_exporter.h" #include "src/kernel_registry.h" #include "src/inner_context.h" -#include "src/populate_parameter.h" #include "src/ops/primitive_c.h" #include "src/tensor.h" +#include "src/ops/populate/populate_register.h" using mindspore::lite::KernelRegistry; using mindspore::lite::PrimitiveC; @@ -233,7 +233,10 @@ const AnfNodePtr ConstFoldPass::Process(const FuncGraphPtr &func_graph, const An } } lite_primitive->InferShape(input_tensors, output_tensors); - auto parameter = kernel::PopulateParameter(lite_primitive.get()); + auto primitive = lite_primitive.get(); + auto parameter = + lite::PopulateRegistry::GetInstance()->getParameterCreator(schema::PrimitiveType(primitive->Type()))(primitive); + if (parameter == nullptr) { MS_LOG(ERROR) << "PopulateParameter return nullptr, type: " << schema::EnumNamePrimitiveType((schema::PrimitiveType)(lite_primitive->Type()));