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

Function GraphFuseConvBN

executor/lib/graph_optimizer.cpp:449–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

447}
448
449static bool GraphFuseConvBN(Graph* graph, GraphOptimizer* opt)
450{
451 int node_number = graph->seq_nodes.size();
452 std::vector<Subgraph*> orig_sub;
453
454 /*get all bn_scale chain*/
455 for(int i = 0; i < node_number; i++)
456 {
457 Node* Bn_node = graph->seq_nodes[i];
458 Operator* op = Bn_node->GetOp();
459
460 if(op->GetName() != "BatchNormalization")
461 continue;
462
463 /*Check if it is a Conv-->Bn*/
464 Tensor* input_tensor;
465 Node* Conv_node;
466
467 input_tensor = Bn_node->GetInputTensor(0);
468 Conv_node = input_tensor->producer->owner;
469 op = Conv_node->GetOp();
470
471 if(op->GetName() != "Convolution")
472 continue;
473
474 /*Create a subgrah represent the chain*/
475 Subgraph* sub = new Subgraph("ConvBn_chain");
476
477 sub->seq_nodes.push_back(Conv_node);
478 sub->seq_nodes.push_back(Bn_node);
479
480 sub->input_nodes.push_back(Conv_node);
481 sub->output_nodes.push_back(Bn_node);
482
483 /* add const node into seq nodes */
484 for(unsigned int i = 1; i < Conv_node->GetInputNum(); i++)
485 {
486 Tensor* tensor = Conv_node->GetInputTensor(i);
487 sub->seq_nodes.push_back(tensor->producer->owner);
488 }
489
490 for(unsigned int i = 1; i < Bn_node->GetInputNum(); i++)
491 {
492 Tensor* tensor = Bn_node->GetInputTensor(i);
493 sub->seq_nodes.push_back(tensor->producer->owner);
494 }
495 orig_sub.push_back(sub);
496 }
497
498 /*replace the nodes of the graph*/
499 for(unsigned int i = 0; i < orig_sub.size(); i++)
500 {
501 Subgraph fused("fused");
502 Subgraph* orig = orig_sub[i];
503
504 Node* orig_output = orig->output_nodes[0];
505 Node* orig_input = orig->input_nodes[0];
506

Callers

nothing calls this directly

Calls 15

AddConstNodeToSubGraphFunction · 0.85
get_tensor_memFunction · 0.85
Weight_BnFunction · 0.85
GetOpMethod · 0.80
GetNameMethod · 0.80
IsDynamicShapeMethod · 0.80
MergeAttrMethod · 0.80
SetOpMethod · 0.80
GetParamMethod · 0.80
AddOutputTensorMethod · 0.80
AddInputTensorMethod · 0.80
SetNodeOwnerMethod · 0.80

Tested by

no test coverage detected