• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "node_registry.h"
17 
18 #include "utils/hdf_log.h"
19 
20 namespace OHOS {
21 namespace HDI {
22 namespace Nnrt {
23 namespace V1_0 {
GetSingleton()24 NodeRegistry& NodeRegistry::GetSingleton()
25 {
26     static NodeRegistry registry;
27     return registry;
28 }
29 
Registrar(NodeType type,std::function<PrimUniquePtr (const std::vector<int8_t> &)> nodeFunc)30 NodeRegistry::Registrar::Registrar(NodeType type, std::function<PrimUniquePtr(const std::vector<int8_t>&)> nodeFunc)
31 {
32     auto& registry = NodeRegistry::GetSingleton();
33     if (registry.m_nodeRegs.find(type) != registry.m_nodeRegs.end()) {
34         HDF_LOGW("Node has been registered. nodeType=%d", type);
35     } else {
36         registry.m_nodeRegs[type] = nodeFunc;
37     }
38 }
39 
GetNodeFunc(NodeType type) const40 std::function<PrimUniquePtr(const std::vector<int8_t>&)> NodeRegistry::GetNodeFunc(NodeType type) const
41 {
42     if (m_nodeRegs.find(type) == m_nodeRegs.end()) {
43         HDF_LOGW("Node type is not found. nodeType=%d", type);
44         return nullptr;
45     }
46 
47     return m_nodeRegs.at(type);
48 }
49 
IsNodeTypeExist(NodeType type) const50 bool NodeRegistry::IsNodeTypeExist(NodeType type) const
51 {
52     if (m_nodeRegs.find(type) == m_nodeRegs.end()) {
53         return false;
54     }
55     return true;
56 }
57 } // namespace V1_0
58 } // namespace Nnrt
59 } // namespace HDI
60 } // namespace OHOS