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

Function GraphFuseBNScale

executor/lib/graph_optimizer.cpp:232–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

230}
231
232static bool GraphFuseBNScale(Graph* graph, GraphOptimizer* opt)
233{
234 int node_number = graph->seq_nodes.size();
235 std::vector<Subgraph*> orig_sub;
236
237 /*get all bn_scale chain*/
238 for(int i = 0; i < node_number; i++)
239 {
240 Node* Scale_node = graph->seq_nodes[i];
241 Operator* op = Scale_node->GetOp();
242
243 if(op->GetName() != "Scale")
244 continue;
245
246 /*Check if it is a bn-->Scale*/
247 Tensor* input_tensor;
248 Node* Bn_node;
249
250 input_tensor = Scale_node->GetInputTensor(0);
251 Bn_node = input_tensor->producer->owner;
252 op = Bn_node->GetOp();
253
254 if(op->GetName() != "BatchNormalization")
255 continue;
256
257 /*Create a subgrah represent the chain*/
258 Subgraph* sub = new Subgraph("BnScale_chain");
259
260 sub->seq_nodes.push_back(Bn_node);
261 sub->seq_nodes.push_back(Scale_node);
262
263 sub->input_nodes.push_back(Bn_node);
264 sub->output_nodes.push_back(Scale_node);
265
266 /* add const node into seq nodes */
267 for(unsigned int i = 1; i < Bn_node->GetInputNum(); i++)
268 {
269 Tensor* tensor = Bn_node->GetInputTensor(i);
270 sub->seq_nodes.push_back(tensor->producer->owner);
271 }
272
273 for(unsigned int i = 1; i < Scale_node->GetInputNum(); i++)
274 {
275 Tensor* tensor = Scale_node->GetInputTensor(i);
276 sub->seq_nodes.push_back(tensor->producer->owner);
277 }
278 orig_sub.push_back(sub);
279 }
280
281 /*replace the nodes of the grah*/
282 for(unsigned int i = 0; i < orig_sub.size(); i++)
283 {
284 Subgraph fused("fused");
285 Subgraph* orig = orig_sub[i];
286
287 Node* orig_output = orig->output_nodes[0];
288 Node* orig_input = orig->input_nodes[0];
289

Callers

nothing calls this directly

Calls 15

AddConstNodeToSubGraphFunction · 0.85
GetOpMethod · 0.80
GetNameMethod · 0.80
IsDynamicShapeMethod · 0.80
MergeAttrMethod · 0.80
SetOpMethod · 0.80
AddOutputTensorMethod · 0.80
AddInputTensorMethod · 0.80
SetNodeOwnerMethod · 0.80
GetParamMethod · 0.80
sizeMethod · 0.45
GetInputTensorMethod · 0.45

Tested by

no test coverage detected