mirror of
https://github.com/openharmony/neural_network_runtime.git
synced 2026-07-19 20:13:36 -04:00
7f4a0afc68
* add neural network runtime
77 lines
2.6 KiB
C++
77 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) 2022 Huawei Device 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 "maximum_builder.h"
|
|
|
|
#include "mindir.h"
|
|
|
|
#include "frameworks/native/ops_registry.h"
|
|
|
|
namespace OHOS {
|
|
namespace NeuralNetworkRuntime {
|
|
namespace Ops {
|
|
static const int INPUT_NUM = 2;
|
|
static const int OUTPUT_NUM = 1;
|
|
static const std::string OP_NAME = "Maximum";
|
|
|
|
MaximumBuilder::MaximumBuilder() {}
|
|
|
|
MaximumBuilder::~MaximumBuilder() {}
|
|
|
|
OH_NN_ReturnCode MaximumBuilder::Build(const std::vector<uint32_t>& paramsIndex,
|
|
const std::vector<uint32_t>& inputsIndex,
|
|
const std::vector<uint32_t>& outputsIndex,
|
|
const std::vector<std::shared_ptr<NNTensor>>& allTensors)
|
|
{
|
|
if (m_isBuild) {
|
|
LOGE("[Maximum] Maximum Build failed. operation has been build, cannot build again.");
|
|
return OH_NN_OPERATION_FORBIDDEN;
|
|
}
|
|
|
|
OH_NN_ReturnCode ret = CheckIOIndex(inputsIndex, outputsIndex, allTensors, INPUT_NUM, OUTPUT_NUM);
|
|
if (ret != OH_NN_SUCCESS) {
|
|
LOGE("[Maximum] Maximum Build failed. The input or output index of Maximum operation is invalid.");
|
|
return ret;
|
|
}
|
|
|
|
if (!paramsIndex.empty()) {
|
|
LOGW("[Maximum] Maximum Build failed. Maximum expects no parameters, but receive %zu", paramsIndex.size());
|
|
return OH_NN_INVALID_PARAMETER;
|
|
}
|
|
|
|
m_inputsIndex = inputsIndex;
|
|
m_outputsIndex = outputsIndex;
|
|
|
|
m_isBuild = true;
|
|
m_name = OP_NAME;
|
|
return OH_NN_SUCCESS;
|
|
}
|
|
|
|
LiteGraphPrimitvePtr MaximumBuilder::GetPrimitive()
|
|
{
|
|
if (!m_isBuild) {
|
|
LOGE("[Maximum] Maximum GetPrimitive failed. Cannot get primitive before call build.");
|
|
return {nullptr, DestroyLiteGraphPrimitive};
|
|
}
|
|
|
|
void* primitive = mindspore::lite::MindIR_Maximum_CreatePrimitive();
|
|
LiteGraphPrimitvePtr graphPrimitivePtr(primitive, DestroyLiteGraphPrimitive);
|
|
return graphPrimitivePtr;
|
|
}
|
|
|
|
REGISTER_OPS(MaximumBuilder, OH_NN_OPS_MAXIMUM);
|
|
} // namespace Ops
|
|
} // namespace NeuralNetworkRuntime
|
|
} // namespace OHOS
|