ONE - On-device Neural Engine
Loading...
Searching...
No Matches
GraphBuilderContext.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "GraphBuilderContext.h"
18
19namespace moco
20{
21namespace onnx
22{
23
24void SymbolTable::enroll(const std::string &node_name, loco::Node *node)
25{
26 MapNameNode_t::iterator iter = _namenode.find(node_name);
27
28 if (iter != _namenode.end())
29 {
30 throw std::runtime_error{"Error: Duplicate node name in Graph: " + node_name};
31 }
32
33 _namenode[node_name] = node;
34}
35
36loco::Node *SymbolTable::node(const std::string &node_name)
37{
38 MapNameNode_t::iterator iter = _namenode.find(node_name);
39
40 if (iter == _namenode.end())
41 {
42 throw std::runtime_error{"Error: Cannot find node with name in Graph: " + node_name};
43 }
44
45 return iter->second;
46}
47
48void SymbolTable::list(loco::Node *node, const std::string &name)
49{
50 MapNodeNames_t::iterator iter = _nodenames.find(node);
51
52 if (iter == _nodenames.end())
53 {
54 // add a new vector for the first name
55 _nodenames[node] = {name};
56 return;
57 }
58
59 _nodenames[node].push_back(name);
60}
61
63{
64 MapNodeNames_t::iterator iter = _nodenames.find(node);
65
66 if (iter == _nodenames.end())
67 {
68 return 0;
69 }
70
71 return iter->second.size();
72}
73
74const std::string &SymbolTable::name(loco::Node *node, unsigned index)
75{
76 MapNodeNames_t::iterator iter = _nodenames.find(node);
77
78 if (iter == _nodenames.end())
79 {
80 throw std::runtime_error{"Error: Cannot find names given node"};
81 }
82
83 if (index >= iter->second.size())
84 {
85 throw std::runtime_error{"Error: Invalid name index for given node"};
86 }
87
88 return iter->second.at(index);
89}
90
91} // namespace onnx
92} // namespace moco
Logical unit of computation.
Definition Node.h:54
const std::string & name(loco::Node *node, unsigned index)
Queries listed(registered) with node and index(from 0 to size-1) Will throw runtime_error if node is ...
void enroll(const std::string &node_name, loco::Node *node)
Registers one node for a name.
loco::Node * node(const std::string &node_name)
Queries enrolled(registered) with name and return node if found Will throw runtime_error if not found...
unsigned size(loco::Node *node)
Returns number of listed(registered) names for a node.
void list(loco::Node *node, const std::string &name)
Registers multiple (appends) names for a node Table is independent with registering with enroll()
Definition Log.h:23
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54