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

Function GraphFuseRelu6

executor/lib/graph_optimizer.cpp:350–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348}
349
350static bool GraphFuseRelu6(Graph* graph, GraphOptimizer* opt)
351{
352 int node_number = graph->seq_nodes.size();
353 std::vector<Subgraph*> orig_sub;
354
355 /*get all relu_minimum chain*/
356 for(int i = 0; i < node_number; i++)
357 {
358 Node* min_node = graph->seq_nodes[i];
359 Operator* op = min_node->GetOp();
360
361 if(op->GetName() != "Eltwise")
362 continue;
363
364 Eltwise* eltwise_op = dynamic_cast<Eltwise*>(op);
365 EltwiseParam* param = eltwise_op->GetParam();
366 if(param->type != ELT_MIN_SCALAR)
367 continue; // todo: verify 6
368
369 /*Check if it is a relu + minimum*/
370 Tensor* input_tensor;
371 Node* relu_node;
372
373 input_tensor = min_node->GetInputTensor(0);
374 relu_node = input_tensor->producer->owner;
375 op = relu_node->GetOp();
376
377 if(op->GetName() != "ReLu")
378 continue;
379
380 /*Create a subgrah represent the chain*/
381 Subgraph* sub = new Subgraph("relu6_chain");
382
383 sub->seq_nodes.push_back(relu_node);
384 sub->seq_nodes.push_back(min_node);
385
386 sub->input_nodes.push_back(relu_node);
387 sub->output_nodes.push_back(min_node);
388
389 /* add const node into seq nodes */
390 for(unsigned int i = 1; i < relu_node->GetInputNum(); i++)
391 {
392 Tensor* tensor = relu_node->GetInputTensor(i);
393 sub->seq_nodes.push_back(tensor->producer->owner);
394 }
395
396 for(unsigned int i = 1; i < min_node->GetInputNum(); i++)
397 {
398 Tensor* tensor = min_node->GetInputTensor(i);
399 sub->seq_nodes.push_back(tensor->producer->owner);
400 }
401 orig_sub.push_back(sub);
402 }
403
404 /*replace the nodes of the grah*/
405 for(unsigned int i = 0; i < orig_sub.size(); i++)
406 {
407 Subgraph fused("fused");

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected