forked from huawei/mindspore2022
adjust examples of southbound interface
This commit is contained in:
parent
432ce2c16e
commit
830895fd49
|
|
@ -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})
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
@ -14,19 +14,19 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "src/custom_common.h"
|
||||
#include "infer/custom_common.h"
|
||||
#include <vector>
|
||||
|
||||
namespace mindspore {
|
||||
namespace common {
|
||||
int CheckInputs(const std::vector<mindspore::MSTensor> &inputs) {
|
||||
Status CheckInputs(const std::vector<mindspore::MSTensor> &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
|
||||
|
|
@ -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 <vector>
|
||||
#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<mindspore::MSTensor> &inputs);
|
||||
Status CheckInputs(const std::vector<mindspore::MSTensor> &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
|
||||
|
|
@ -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 <memory>
|
||||
#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::OperatorT> &tflite_op,
|
||||
const std::unique_ptr<tflite::SubGraphT> &tflite_subgraph,
|
||||
const std::unique_ptr<tflite::ModelT> &tflite_model) {
|
||||
auto prim = std::make_unique<ops::AddFusion>();
|
||||
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<AddParserTutorial>());
|
||||
} // namespace converter
|
||||
} // namespace mindspore
|
||||
|
|
@ -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 <memory>
|
||||
#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::OperatorT> &tflite_op,
|
||||
const std::unique_ptr<tflite::SubGraphT> &tflite_subgraph,
|
||||
const std::unique_ptr<tflite::ModelT> &tflite_model) override;
|
||||
};
|
||||
} // namespace converter
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_LITE_EXAMPLES_CONVERTER_EXTEND_NODE_PARSER_ADD_PARSER_TUTORIAL_H
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "src/pass_registry_tutorial.h"
|
||||
#include "pass/pass_registry_tutorial.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
|
@ -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
|
||||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -19,24 +19,24 @@
|
|||
|
||||
namespace mindspore {
|
||||
namespace common {
|
||||
int CheckInputs(const std::vector<mindspore::MSTensor> &inputs) {
|
||||
Status CheckInputs(const std::vector<mindspore::MSTensor> &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<mindspore::MSTensor> &outputs) {
|
||||
Status CheckOutputs(const std::vector<mindspore::MSTensor> &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
|
||||
|
|
|
|||
|
|
@ -19,16 +19,16 @@
|
|||
|
||||
#include <vector>
|
||||
#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<mindspore::MSTensor> &inputs);
|
||||
Status CheckInputs(const std::vector<mindspore::MSTensor> &inputs);
|
||||
|
||||
// versify that the outputs' shape is inferred successfully when running current node.
|
||||
int CheckOutputs(const std::vector<mindspore::MSTensor> &inputs);
|
||||
Status CheckOutputs(const std::vector<mindspore::MSTensor> &inputs);
|
||||
} // namespace common
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_LITE_EXAMPLES_RUNTIME_REGISTRY_SRC_CUSTOM_COMMON_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue