1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_HDI_NNR_NODE_REGISTRY_H 17 #define OHOS_HDI_NNR_NODE_REGISTRY_H 18 19 #include <memory> 20 #include <functional> 21 #include <unordered_map> 22 23 #include "v1_0/nnrt_types.h" 24 #include "mindspore_schema/model_generated.h" 25 26 namespace OHOS { 27 namespace HDI { 28 namespace Nnrt { 29 namespace V1_0 { 30 using PrimUniquePtr = std::unique_ptr<mindspore::schema::PrimitiveT>; 31 class NodeRegistry { 32 public: 33 struct Registrar { 34 Registrar() = delete; 35 Registrar(NodeType type, std::function<PrimUniquePtr(const std::vector<int8_t>&)> nodeFunc); 36 }; 37 38 public: 39 static NodeRegistry& GetSingleton(); 40 std::function<PrimUniquePtr(const std::vector<int8_t>&)> GetNodeFunc(NodeType type) const; 41 bool IsNodeTypeExist(NodeType type) const; 42 43 private: NodeRegistry()44 NodeRegistry() {}; 45 NodeRegistry(const NodeRegistry&) = delete; 46 NodeRegistry& operator=(const NodeRegistry&) = delete; 47 48 private: 49 std::unordered_map<NodeType, std::function<PrimUniquePtr(const std::vector<int8_t>&)>> m_nodeRegs; 50 }; 51 52 #define REGISTER_NODE(nodeName, nodeType, funcPtr) static NodeRegistry::Registrar g_##nodeName(nodeType, funcPtr) 53 } // namespace V1_0 54 } // namespace Nnrt 55 } // namespace HDI 56 } // namespace OHOS 57 #endif // OHOS_HDI_NNR_NODE_REGISTRY_H