diff --git a/mindspore/lite/examples/converter_extend/CMakeLists.txt b/mindspore/lite/examples/converter_extend/CMakeLists.txt index f73849129a..27b184fd9c 100644 --- a/mindspore/lite/examples/converter_extend/CMakeLists.txt +++ b/mindspore/lite/examples/converter_extend/CMakeLists.txt @@ -16,5 +16,5 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/third_party) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/third_party/eigen3) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/third_party/securec) -file(GLOB_RECURSE CONVERTER_REGISTRY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc) +file(GLOB_RECURSE CONVERTER_REGISTRY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) add_library(converter_extend_tutorial SHARED ${CONVERTER_REGISTRY_SRC}) diff --git a/mindspore/lite/examples/converter_extend/src/custom_add_infer.cc b/mindspore/lite/examples/converter_extend/infer/custom_add_infer.cc similarity index 94% rename from mindspore/lite/examples/converter_extend/src/custom_add_infer.cc rename to mindspore/lite/examples/converter_extend/infer/custom_add_infer.cc index f1034c2188..69be034479 100644 --- a/mindspore/lite/examples/converter_extend/src/custom_add_infer.cc +++ b/mindspore/lite/examples/converter_extend/infer/custom_add_infer.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/custom_common.h" +#include "infer/custom_common.h" #include "include/errorcode.h" #include "include/registry/register_kernel_interface.h" @@ -33,10 +33,10 @@ class CustomAddInfer : public kernel::KernelInterface { (*outputs)[0].SetFormat((*inputs)[0].format()); (*outputs)[0].SetDataType((*inputs)[0].DataType()); auto ret = common::CheckInputs(*inputs); - if (ret == lite::RET_INFER_INVALID) { + if (ret == kLiteInferInvalid) { (*outputs)[0].SetShape({-1}); // shape{-1} shows that shape need to be inferred when running. return kLiteInferInvalid; - } else if (ret != lite::RET_OK) { + } else if (ret != kSuccess) { return kLiteError; } (*outputs)[0].SetShape((*inputs)[0].Shape()); diff --git a/mindspore/lite/examples/converter_extend/src/custom_common.cc b/mindspore/lite/examples/converter_extend/infer/custom_common.cc similarity index 84% rename from mindspore/lite/examples/converter_extend/src/custom_common.cc rename to mindspore/lite/examples/converter_extend/infer/custom_common.cc index fa83b784ec..32dee3d2c5 100644 --- a/mindspore/lite/examples/converter_extend/src/custom_common.cc +++ b/mindspore/lite/examples/converter_extend/infer/custom_common.cc @@ -14,19 +14,19 @@ * limitations under the License. */ -#include "src/custom_common.h" +#include "infer/custom_common.h" #include namespace mindspore { namespace common { -int CheckInputs(const std::vector &inputs) { +Status CheckInputs(const std::vector &inputs) { for (auto &input : inputs) { auto input_shape = input.Shape(); if (std::find(input_shape.begin(), input_shape.end(), -1) != input_shape.end()) { - return lite::RET_INFER_INVALID; + return kLiteInferInvalid; } } - return lite::RET_OK; + return kSuccess; } } // namespace common } // namespace mindspore diff --git a/mindspore/lite/examples/converter_extend/src/custom_common.h b/mindspore/lite/examples/converter_extend/infer/custom_common.h similarity index 73% rename from mindspore/lite/examples/converter_extend/src/custom_common.h rename to mindspore/lite/examples/converter_extend/infer/custom_common.h index ea23a96736..c28439a3c0 100644 --- a/mindspore/lite/examples/converter_extend/src/custom_common.h +++ b/mindspore/lite/examples/converter_extend/infer/custom_common.h @@ -14,18 +14,18 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_EXAMPLES_RUNTIME_REGISTRY_SRC_CUSTOM_COMMON_H -#define MINDSPORE_LITE_EXAMPLES_RUNTIME_REGISTRY_SRC_CUSTOM_COMMON_H +#ifndef MINDSPORE_LITE_EXAMPLES_CONVERTER_EXTEND_INFER_CUSTOM_COMMON_H +#define MINDSPORE_LITE_EXAMPLES_CONVERTER_EXTEND_INFER_CUSTOM_COMMON_H #include #include "include/api/types.h" -#include "include/errorcode.h" +#include "include/api/status.h" #include "include/ms_tensor.h" namespace mindspore { namespace common { // verify that the inputs' shape is inferred successfully when inferring current node. -int CheckInputs(const std::vector &inputs); +Status CheckInputs(const std::vector &inputs); } // namespace common } // namespace mindspore -#endif // MINDSPORE_LITE_EXAMPLES_RUNTIME_REGISTRY_SRC_CUSTOM_COMMON_H +#endif // MINDSPORE_LITE_EXAMPLES_CONVERTER_EXTEND_INFER_CUSTOM_COMMON_H diff --git a/mindspore/lite/examples/converter_extend/node_parser/add_parser_tutorial.cc b/mindspore/lite/examples/converter_extend/node_parser/add_parser_tutorial.cc new file mode 100644 index 0000000000..d8a73cbc0e --- /dev/null +++ b/mindspore/lite/examples/converter_extend/node_parser/add_parser_tutorial.cc @@ -0,0 +1,38 @@ +/** + * 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 "node_parser/add_parser_tutorial.h" +#include +#include "include/registry/node_parser_registry.h" +#include "ops/fusion/add_fusion.h" +#include "schema/schema_generated.h" + +namespace mindspore { +namespace converter { +ops::PrimitiveC *AddParserTutorial::Parse(const std::unique_ptr &tflite_op, + const std::unique_ptr &tflite_subgraph, + const std::unique_ptr &tflite_model) { + auto prim = std::make_unique(); + if (prim == nullptr) { + return nullptr; + } + prim->set_activation_type(mindspore::NO_ACTIVATION); // user need to analyze tflite_op's attr. + return prim.release(); +} + +REG_NODE_PARSER(kFmkTypeTflite, ADD, std::make_shared()); +} // namespace converter +} // namespace mindspore diff --git a/mindspore/lite/examples/converter_extend/node_parser/add_parser_tutorial.h b/mindspore/lite/examples/converter_extend/node_parser/add_parser_tutorial.h new file mode 100644 index 0000000000..6c6c185d1e --- /dev/null +++ b/mindspore/lite/examples/converter_extend/node_parser/add_parser_tutorial.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_LITE_EXAMPLES_CONVERTER_EXTEND_NODE_PARSER_ADD_PARSER_TUTORIAL_H +#define MINDSPORE_LITE_EXAMPLES_CONVERTER_EXTEND_NODE_PARSER_ADD_PARSER_TUTORIAL_H + +#include +#include "include/registry/node_parser.h" + +namespace mindspore { +namespace converter { +class AddParserTutorial : public NodeParser { + public: + AddParserTutorial() = default; + ~AddParserTutorial() = default; + ops::PrimitiveC *Parse(const std::unique_ptr &tflite_op, + const std::unique_ptr &tflite_subgraph, + const std::unique_ptr &tflite_model) override; +}; +} // namespace converter +} // namespace mindspore + +#endif // MINDSPORE_LITE_EXAMPLES_CONVERTER_EXTEND_NODE_PARSER_ADD_PARSER_TUTORIAL_H diff --git a/mindspore/lite/examples/converter_extend/src/pass_registry_tutorial.cc b/mindspore/lite/examples/converter_extend/pass/pass_registry_tutorial.cc similarity index 98% rename from mindspore/lite/examples/converter_extend/src/pass_registry_tutorial.cc rename to mindspore/lite/examples/converter_extend/pass/pass_registry_tutorial.cc index 84f00ee2b1..5c0747e365 100644 --- a/mindspore/lite/examples/converter_extend/src/pass_registry_tutorial.cc +++ b/mindspore/lite/examples/converter_extend/pass/pass_registry_tutorial.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/pass_registry_tutorial.h" +#include "pass/pass_registry_tutorial.h" #include #include #include diff --git a/mindspore/lite/examples/converter_extend/src/pass_registry_tutorial.h b/mindspore/lite/examples/converter_extend/pass/pass_registry_tutorial.h similarity index 81% rename from mindspore/lite/examples/converter_extend/src/pass_registry_tutorial.h rename to mindspore/lite/examples/converter_extend/pass/pass_registry_tutorial.h index aa11b18cb1..eb2797a51d 100644 --- a/mindspore/lite/examples/converter_extend/src/pass_registry_tutorial.h +++ b/mindspore/lite/examples/converter_extend/pass/pass_registry_tutorial.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_EXAMPLES_CONVERTER_REGISTER_SRC_PASS_REGISTRY_TUTORIAL_H -#define MINDSPORE_LITE_EXAMPLES_CONVERTER_REGISTER_SRC_PASS_REGISTRY_TUTORIAL_H +#ifndef MINDSPORE_LITE_EXAMPLES_CONVERTER_EXTEND_PASS_PASS_REGISTRY_TUTORIAL_H +#define MINDSPORE_LITE_EXAMPLES_CONVERTER_EXTEND_PASS_PASS_REGISTRY_TUTORIAL_H #include "include/registry/pass_base.h" @@ -34,4 +34,4 @@ class PassTutorial : public registry::PassBase { }; } // namespace opt } // namespace mindspore -#endif // MINDSPORE_LITE_EXAMPLES_CONVERTER_REGISTER_SRC_PASS_REGISTRY_TUTORIAL_H +#endif // MINDSPORE_LITE_EXAMPLES_CONVERTER_EXTEND_PASS_PASS_REGISTRY_TUTORIAL_H diff --git a/mindspore/lite/examples/runtime_extend/src/custom_add_infer.cc b/mindspore/lite/examples/runtime_extend/src/custom_add_infer.cc index 3b11d737e5..d61489a374 100644 --- a/mindspore/lite/examples/runtime_extend/src/custom_add_infer.cc +++ b/mindspore/lite/examples/runtime_extend/src/custom_add_infer.cc @@ -15,7 +15,7 @@ */ #include "src/custom_common.h" -#include "include/errorcode.h" +#include "include/api/status.h" #include "include/registry/register_kernel_interface.h" namespace mindspore { @@ -33,10 +33,10 @@ class CustomAddInfer : public kernel::KernelInterface { (*outputs)[0].SetFormat((*inputs)[0].format()); (*outputs)[0].SetDataType((*inputs)[0].DataType()); auto ret = common::CheckInputs(*inputs); - if (ret == lite::RET_INFER_INVALID) { + if (ret == kLiteInferInvalid) { (*outputs)[0].SetShape({-1}); // shape{-1} shows that shape need to be inferred when running. return kLiteInferInvalid; - } else if (ret != lite::RET_OK) { + } else if (ret != kSuccess) { return kLiteError; } (*outputs)[0].SetShape((*inputs)[0].Shape()); diff --git a/mindspore/lite/examples/runtime_extend/src/custom_add_kernel.cc b/mindspore/lite/examples/runtime_extend/src/custom_add_kernel.cc index 045ed2a330..58bfa367c7 100644 --- a/mindspore/lite/examples/runtime_extend/src/custom_add_kernel.cc +++ b/mindspore/lite/examples/runtime_extend/src/custom_add_kernel.cc @@ -61,9 +61,9 @@ class CustomAddKernel : public Kernel { private: // if output shape exists value -1, need to be inferred before applying memory for output tensor. int PreProcess() { - if (common::CheckOutputs(outputs_) != lite::RET_OK) { - auto status = - registry::RegisterKernelInterface::GetKernelInterface({}, primitive_)->Infer(&inputs_, &outputs_, primitive_); + if (common::CheckOutputs(outputs_) != kSuccess) { + auto status = registry::RegisterKernelInterface::GetKernelInterface(std::string{}, primitive_, this) + ->Infer(&inputs_, &outputs_, primitive_); if (status != kSuccess) { std::cerr << "infer failed." << std::endl; return lite::RET_ERROR; diff --git a/mindspore/lite/examples/runtime_extend/src/custom_common.cc b/mindspore/lite/examples/runtime_extend/src/custom_common.cc index 06064c4f97..4a4a044254 100644 --- a/mindspore/lite/examples/runtime_extend/src/custom_common.cc +++ b/mindspore/lite/examples/runtime_extend/src/custom_common.cc @@ -19,24 +19,24 @@ namespace mindspore { namespace common { -int CheckInputs(const std::vector &inputs) { +Status CheckInputs(const std::vector &inputs) { for (auto &input : inputs) { auto input_shape = input.Shape(); if (std::find(input_shape.begin(), input_shape.end(), -1) != input_shape.end()) { - return lite::RET_INFER_INVALID; + return kLiteInferInvalid; } } - return lite::RET_OK; + return kSuccess; } -int CheckOutputs(const std::vector &outputs) { +Status CheckOutputs(const std::vector &outputs) { for (auto &output : outputs) { auto output_shape = output.Shape(); if (std::find(output_shape.begin(), output_shape.end(), -1) != output_shape.end()) { - return lite::RET_INFER_INVALID; + return kLiteInferInvalid; } } - return lite::RET_OK; + return kSuccess; } } // namespace common } // namespace mindspore diff --git a/mindspore/lite/examples/runtime_extend/src/custom_common.h b/mindspore/lite/examples/runtime_extend/src/custom_common.h index c784d796f4..9dccf8e7e1 100644 --- a/mindspore/lite/examples/runtime_extend/src/custom_common.h +++ b/mindspore/lite/examples/runtime_extend/src/custom_common.h @@ -19,16 +19,16 @@ #include #include "include/api/types.h" -#include "include/errorcode.h" +#include "include/api/status.h" #include "include/ms_tensor.h" namespace mindspore { namespace common { // verify that the inputs' shape is inferred successfully when inferring current node. -int CheckInputs(const std::vector &inputs); +Status CheckInputs(const std::vector &inputs); // versify that the outputs' shape is inferred successfully when running current node. -int CheckOutputs(const std::vector &inputs); +Status CheckOutputs(const std::vector &inputs); } // namespace common } // namespace mindspore #endif // MINDSPORE_LITE_EXAMPLES_RUNTIME_REGISTRY_SRC_CUSTOM_COMMON_H