From fd3154b717cb119522d15da66bf42f7a937ec172 Mon Sep 17 00:00:00 2001 From: mengyuanli Date: Mon, 29 Mar 2021 16:28:54 +0800 Subject: [PATCH] add call op --- mindspore/core/ops/call.cc | 24 +++++++++++++++ mindspore/core/ops/call.h | 36 +++++++++++++++++++++++ mindspore/lite/schema/ops.fbs | 4 +++ mindspore/lite/src/ops/ops_def.cc | 4 +++ mindspore/lite/src/ops/ops_func_declare.h | 2 ++ mindspore/lite/src/ops/ops_utils.cc | 6 ++++ 6 files changed, 76 insertions(+) create mode 100644 mindspore/core/ops/call.cc create mode 100644 mindspore/core/ops/call.h diff --git a/mindspore/core/ops/call.cc b/mindspore/core/ops/call.cc new file mode 100644 index 00000000000..5f6ad181060 --- /dev/null +++ b/mindspore/core/ops/call.cc @@ -0,0 +1,24 @@ +/** + * Copyright 2021 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 "ops/call.h" +#include "ops/op_utils.h" + +namespace mindspore { +namespace ops { +REGISTER_PRIMITIVE_C(kNameCall, Call); +} // namespace ops +} // namespace mindspore diff --git a/mindspore/core/ops/call.h b/mindspore/core/ops/call.h new file mode 100644 index 00000000000..a316b5dd0be --- /dev/null +++ b/mindspore/core/ops/call.h @@ -0,0 +1,36 @@ +/** + * Copyright 2021 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_CORE_OPS_CALL_H_ +#define MINDSPORE_CORE_OPS_CALL_H_ +#include "ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +namespace ops { +constexpr auto kNameCall = "call"; +class Call : public PrimitiveC { + public: + Call() : PrimitiveC(kNameCall) {} + ~Call() = default; + MS_DECLARE_PARENT(Call, PrimitiveC); + void Init() {} +}; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_CALL_H_ diff --git a/mindspore/lite/schema/ops.fbs b/mindspore/lite/schema/ops.fbs index 2af4e527cd3..b959d66e6dc 100644 --- a/mindspore/lite/schema/ops.fbs +++ b/mindspore/lite/schema/ops.fbs @@ -207,6 +207,7 @@ union PrimitiveType { ResizeGrad, Splice, LogSoftmax, + Call, } table Abs { @@ -1099,3 +1100,6 @@ table Splice { table LogSoftmax { axis: long; } + +table Call { +} diff --git a/mindspore/lite/src/ops/ops_def.cc b/mindspore/lite/src/ops/ops_def.cc index e5fd9335d79..4efb906c841 100644 --- a/mindspore/lite/src/ops/ops_def.cc +++ b/mindspore/lite/src/ops/ops_def.cc @@ -206,6 +206,7 @@ OP_TYPE(LayerNormGrad) OP_TYPE(ResizeGrad) OP_TYPE(Splice) OP_TYPE(LogSoftmax) +OP_TYPE(Call) OP_TYPE_DEF_END(PrimitiveType) OP_SCHEMA_DEF(Abs) @@ -1098,3 +1099,6 @@ OP_SCHEMA_DEF_END(Splice) OP_SCHEMA_DEF(LogSoftmax) OP_ATTR(axis, long) OP_SCHEMA_DEF_END(LogSoftmax) + +OP_SCHEMA_DEF(Call) +OP_SCHEMA_DEF_END(Call) diff --git a/mindspore/lite/src/ops/ops_func_declare.h b/mindspore/lite/src/ops/ops_func_declare.h index dba2a7d9b94..f768e0b43f7 100644 --- a/mindspore/lite/src/ops/ops_func_declare.h +++ b/mindspore/lite/src/ops/ops_func_declare.h @@ -244,6 +244,7 @@ #include "ops/grad/abs_grad.h" #include "ops/splice.h" #include "ops/log_softmax.h" +#include "ops/call.h" #define FUNC_MSOP2SCHEMAOP_DECLARE(OP) \ namespace mindspore::lite::ops { \ @@ -457,5 +458,6 @@ FUNC_MSOP2SCHEMAOP_DECLARE(LayerNormGrad); FUNC_MSOP2SCHEMAOP_DECLARE(ResizeGrad); FUNC_MSOP2SCHEMAOP_DECLARE(Splice); FUNC_MSOP2SCHEMAOP_DECLARE(LogSoftmax); +FUNC_MSOP2SCHEMAOP_DECLARE(Call); #endif #endif // MINDSPORE_LITE_SRC_OPS_OPS_FUNC_DECLARE_H_ diff --git a/mindspore/lite/src/ops/ops_utils.cc b/mindspore/lite/src/ops/ops_utils.cc index 68c8a2e8505..d2808e37323 100644 --- a/mindspore/lite/src/ops/ops_utils.cc +++ b/mindspore/lite/src/ops/ops_utils.cc @@ -755,6 +755,11 @@ schema::PrimitiveT *LogSoftmaxPrimitiveCreator(const AnfNodePtr &node) { return ms_primc != nullptr ? ops::MSOp2SchemaOp(ms_primc.get()) : nullptr; } +schema::PrimitiveT *CallPrimitiveCreator(const AnfNodePtr &node) { + auto ms_primc = GetValueNode>(node); + return ms_primc != nullptr ? ops::MSOp2SchemaOp(ms_primc.get()) : nullptr; +} + RegistryMSOps g_absPrimitiveCreatorRegistry("Abs", AbsPrimitiveCreator); RegistryMSOps g_absGradPrimitiveCreatorRegistry("AbsGrad", AbsGradPrimitiveCreator); RegistryMSOps g_activationPrimitiveCreatorRegistry("Activation", ActivationPrimitiveCreator); @@ -969,6 +974,7 @@ RegistryMSOps g_zerosLikePrimitiveCreatorRegistry("ZerosLike", ZerosLikePrimitiv RegistryMSOps g_erfPrimitiveCreatorRegistry("Erf", ErfPrimitiveCreator); RegistryMSOps g_SplicePrimitiveCreatorRegistry("Splice", SplicePrimitiveCreator); RegistryMSOps g_LogSoftmaxPrimitiveCreatorRegistry("LogSoftmax", LogSoftmaxPrimitiveCreator); +RegistryMSOps g_CallPrimitiveCreatorRegistry("call", CallPrimitiveCreator); } // namespace lite } // namespace mindspore