MCPcopy Create free account
hub / github.com/OAID/Tengine / MergeSubgraph

Method MergeSubgraph

executor/lib/graph_task.cpp:116–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116Graph* GraphTask::MergeSubgraph(Graph* origin_graph, const std::vector<Subgraph*>& sub_list)
117{
118 std::string graph_name = origin_graph->GetName() + ".optimized";
119
120 Graph* graph = new Graph(graph_name);
121 int subgraph_number = sub_list.size();
122
123 /* first: search the graph input nodes and graph output nodes
124 and collect all nodes and tensors */
125
126 graph->input_nodes = origin_graph->input_nodes;
127
128 for(int i = 0; i < subgraph_number; i++)
129 {
130 Subgraph* sub = sub_list[i];
131
132 graph->seq_nodes.insert(graph->seq_nodes.end(), sub->seq_nodes.begin(), sub->seq_nodes.end());
133
134 for(unsigned int k = 0; k < sub->output_nodes.size(); k++)
135 {
136 Node* node = sub->output_nodes[k];
137
138 unsigned int l;
139
140 for(l = 0; l < node->GetOutputNum(); l++)
141 {
142 Tensor* tensor = node->GetOutputTensor(l);
143
144 if(tensor->consumer.size() == 0)
145 break;
146 }
147
148 if(l < node->GetOutputNum())
149 graph->output_nodes.push_back(node);
150 }
151 }
152
153 /*second: setup the tensor map */
154
155 for(unsigned int i = 0; i < graph->seq_nodes.size(); i++)
156 {
157 Node* node = graph->seq_nodes[i];
158 node->SetNodeIndex(i);
159
160 for(unsigned int l = 0; l < node->GetOutputNum(); l++)
161 {
162 Tensor* tensor = node->GetOutputTensor(l);
163 graph->AddTensorMap(tensor->GetName(), tensor);
164 }
165 }
166
167 /*third: get the output nodes order*/
168
169 if(graph->output_nodes.size() > 1)
170 {
171 graph->output_nodes = origin_graph->output_nodes;
172 }
173

Callers

nothing calls this directly

Calls 9

GetNameMethod · 0.80
endMethod · 0.80
beginMethod · 0.80
SetNodeIndexMethod · 0.80
AddTensorMapMethod · 0.80
SanitizeGraphMethod · 0.80
sizeMethod · 0.45
GetOutputNumMethod · 0.45
GetOutputTensorMethod · 0.45

Tested by

no test coverage detected