/* * 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. */ #ifndef NEURAL_NETWORK_RUNTIME_INNER_MODEL_H #define NEURAL_NETWORK_RUNTIME_INNER_MODEL_H #include #include #include "mindir.h" #include "ops_builder.h" #include "interfaces/kits/c/neural_network_runtime.h" namespace OHOS { namespace NeuralNetworkRuntime { class InnerModel { public: InnerModel(); bool IsBuild() const; OH_NN_ReturnCode BuildFromLiteGraph(const mindspore::lite::LiteGraph* liteGraph); OH_NN_ReturnCode AddTensor(const OH_NN_Tensor& nnTensor); OH_NN_ReturnCode SetTensorValue(uint32_t index, const void* buffer, size_t length); OH_NN_ReturnCode AddOperation(OH_NN_OperationType opType, const OH_NN_UInt32Array& paramIndices, const OH_NN_UInt32Array& inputIndices, const OH_NN_UInt32Array& outputIndices); OH_NN_ReturnCode GetSupportedOperations(size_t deviceID, const bool** isSupported, uint32_t& opCount); OH_NN_ReturnCode SpecifyInputsAndOutputs( const OH_NN_UInt32Array& inputIndices, const OH_NN_UInt32Array& outputIndices); OH_NN_ReturnCode Build(); std::vector> GetInputTensors() const; std::vector> GetOutputTensors() const; std::shared_ptr GetLiteGraphs() const; private: void AddTensorsToLiteGraph(std::unordered_map& modelIDToGraphID); OH_NN_ReturnCode AddNodesToLiteGraph(const std::unordered_map& modelIDToGraphID); OH_NN_ReturnCode ValidateInputAndOutput( const OH_NN_UInt32Array& inputIndices, const OH_NN_UInt32Array& outputIndices) const; OH_NN_ReturnCode ValidateTensorArray(const OH_NN_UInt32Array& indices) const; private: std::vector m_supportedOperations; // std::vector not support data(), use std::vector instead. std::vector m_inputIndices; std::vector m_outputIndices; std::vector> m_ops; std::vector> m_allTensors; std::vector> m_inputTensors; // Used to pass input tensors to compilation. std::vector> m_outputTensors; // Used to pass output tensors to compilation. std::shared_ptr m_liteGraph {nullptr}; }; } // namespace NeuralNetworkRuntime } // namespace OHOS #endif // NEURAL_NETWORK_RUNTIME_INNER_MODEL_H