From: 박천교/On-Device Lab(SR)/Engineer/삼성전자 Date: Mon, 25 Nov 2019 02:00:41 +0000 (+0900) Subject: [exo] Alternative helper for commutative args (#9140) X-Git-Tag: submit/tizen/20191205.083104~154 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2bf40b2f4bc2b69a354af7e3b941cc8357eecc49;p=platform%2Fcore%2Fml%2Fnnfw.git [exo] Alternative helper for commutative args (#9140) * [exo] Alternative helper for commutative args This commit introduces alternative helper to extract and set commutative argument of the node. Current: `bool ok = commutative_args_of(node).is(arg1, arg2);` Suggested alternative: `bool ok = set(&arg1, &arg2).with_commutative_args_of(node);` Signed-off-by: Cheongyo Bahk * Fill! --- diff --git a/compiler/exo/src/Pass/FuseInstanceNormPass.cpp b/compiler/exo/src/Pass/FuseInstanceNormPass.cpp index 0d3428c..7b2fa4c 100644 --- a/compiler/exo/src/Pass/FuseInstanceNormPass.cpp +++ b/compiler/exo/src/Pass/FuseInstanceNormPass.cpp @@ -118,6 +118,66 @@ bool CommutativeArgsGetter::is(ARG_TYPE_1 *&arg_1, ARG_TYPE_2 *&arg_2 return false; } +/** + * Alternative approach + * + * bool ok = fill(&arg1, &arg2).with_commutative_args_of(node); + */ + +template class NodeFiller final +{ +public: + NodeFiller(ARG_TYPE_1 **arg_1, ARG_TYPE_2 **arg_2) : _arg_1(arg_1), _arg_2(arg_2) + { + // DO NOTHING + } + + template bool with_commutative_args_of(const COMM_NODE *node); + +private: + ARG_TYPE_1 **_arg_1; + ARG_TYPE_2 **_arg_2; +}; + +template +inline NodeFiller fill(ARG_TYPE_1 **arg_1, ARG_TYPE_2 **arg_2) +{ + return NodeFiller{arg_1, arg_2}; +} + +template +template +bool NodeFiller::with_commutative_args_of(const COMM_NODE *node) +{ + // Case 1) X == ARG_TYPE_1 / Y == ARG_TYPE_2 + { + auto x = dynamic_cast(node->x()); + auto y = dynamic_cast(node->y()); + + if (x && y) + { + *_arg_1 = x; + *_arg_2 = y; + return true; + } + } + + // Case 2) X == ARG_TYPE_2 / Y == ARG_TYPE_1 + { + auto x = dynamic_cast(node->x()); + auto y = dynamic_cast(node->y()); + + if (x && y) + { + *_arg_1 = y; + *_arg_2 = x; + return true; + } + } + + return false; +} + } // namespace // Helper to check detail