From: 윤현식/On-Device Lab(SR)/Principal Engineer/삼성전자 Date: Thu, 17 Oct 2019 07:23:06 +0000 (+0900) Subject: [exo] adds loop to fuse the nodes for FuseReluPass (#8266) X-Git-Tag: submit/tizen/20191205.083104~724 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=75cf0a7b956bdb972ea5b8fc7917b197d4ec2aa8;p=platform%2Fcore%2Fml%2Fnnfw.git [exo] adds loop to fuse the nodes for FuseReluPass (#8266) This completes FuseReluPass.cpp by add loops that performs fusing selected nodes. Signed-off-by: Hyun Sik Yoon --- diff --git a/compiler/exo/src/Pass/FuseReluPass.cpp b/compiler/exo/src/Pass/FuseReluPass.cpp index b07e962..71f74c9 100644 --- a/compiler/exo/src/Pass/FuseReluPass.cpp +++ b/compiler/exo/src/Pass/FuseReluPass.cpp @@ -65,6 +65,37 @@ struct Collector final : public locoex::TFLNodeMutableVisitor std::set candidates; }; +void set_activation_fusion(loco::Node *node, locoex::FusedActFunc f) +{ + using namespace locoex; + + if (auto fusable_node = dynamic_cast *>(node)) + fusable_node->fusedActivationFunction(f); + else + assert(false); +} + +struct Performer final : public locoex::TFLNodeMutableVisitor +{ + void visit(locoex::TFLRelu *the_relu) final + { + set_activation_fusion(the_relu->features(), locoex::FusedActFunc::RELU); + + loco::replace(the_relu).with(the_relu->features()); + the_relu->features(nullptr); + } + + void visit(locoex::TFLRelu6 *the_relu6) final + { + set_activation_fusion(the_relu6->features(), locoex::FusedActFunc::RELU6); + + loco::replace(the_relu6).with(the_relu6->features()); + the_relu6->features(nullptr); + } + + void visit(locoex::TFLNode *) final { assert(false && "should not be called"); } +}; + } // namespace namespace exo @@ -83,9 +114,14 @@ bool FuseReluPass::run(loco::Graph *g) } } - // TODO write code for fusing + Performer performer; + + for (auto node : collector.candidates) + { + node->accept(&performer); + } - return false; + return collector.candidates.size() > 0; } } // namespace exo