diff --git a/inference-engine/src/transformations/include/transformations/common_optimizations/hsigmoid_fusion.hpp b/inference-engine/src/transformations/include/transformations/common_optimizations/hsigmoid_fusion.hpp index e19da646a7d..854a31628cf 100644 --- a/inference-engine/src/transformations/include/transformations/common_optimizations/hsigmoid_fusion.hpp +++ b/inference-engine/src/transformations/include/transformations/common_optimizations/hsigmoid_fusion.hpp @@ -17,14 +17,15 @@ class TRANSFORMATIONS_API HSigmoidFusion; class TRANSFORMATIONS_API HSigmoidFusionWithReluDiv; class TRANSFORMATIONS_API HSigmoidFusionWithReluMul; class TRANSFORMATIONS_API HSigmoidFusionWithoutRelu; -class TRANSFORMATIONS_API HSigmoidFusionWithClamp; +class TRANSFORMATIONS_API HSigmoidFusionWithClampMul; +class TRANSFORMATIONS_API HSigmoidFusionWithClampDiv; } // namespace pass } // namespace ngraph /** * @ingroup ie_transformation_common_api - * @brief HSigmoidFusion transformation replaces a sub-graph (x * (min(Relu(x + 3), 6))) / 6 with a HSigmoid op. + * @brief HSigmoidFusion transformation replaces a sub-graph ((min(Relu(x + 3), 6)) / 6) with a HSigmoid op. */ class ngraph::pass::HSigmoidFusionWithReluDiv: public ngraph::pass::MatcherPass { public: @@ -34,7 +35,7 @@ public: /** * @ingroup ie_transformation_common_api - * @brief HSigmoidFusion transformation replaces a sub-graph (x * (min(Relu(x + 3), 6)) * const(1/6) with a HSigmoid op. + * @brief HSigmoidFusion transformation replaces a sub-graph ((min(Relu(x + 3), 6)) * const(1/6)) with a HSigmoid op. */ class ngraph::pass::HSigmoidFusionWithReluMul: public ngraph::pass::MatcherPass { public: @@ -44,7 +45,7 @@ public: /** * @ingroup ie_transformation_common_api - * @brief HSigmoidFusion transformation replaces a sub-graph x * (min(max(x + 3, 0), 6) / 6) with a HSigmoid op. + * @brief HSigmoidFusion transformation replaces a sub-graph (min(max(x + 3, 0), 6) / 6) with a HSigmoid op. */ class ngraph::pass::HSigmoidFusionWithoutRelu: public ngraph::pass::MatcherPass { public: @@ -54,12 +55,22 @@ public: /** * @ingroup ie_transformation_common_api - * @brief HSigmoidFusion transformation replaces a sub-graph x * (Clamp(x + 3, 0, 6) * const(1/6)) with a HSigmoid op. + * @brief HSigmoidFusion transformation replaces a sub-graph (Clamp(x + 3, 0, 6) * const(1/6)) with a HSigmoid op. */ -class ngraph::pass::HSigmoidFusionWithClamp: public ngraph::pass::MatcherPass { +class ngraph::pass::HSigmoidFusionWithClampMul: public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; - HSigmoidFusionWithClamp(); + HSigmoidFusionWithClampMul(); +}; + +/** + * @ingroup ie_transformation_common_api + * @brief HSigmoidFusion transformation replaces a sub-graph (Clamp(x + 3, 0, 6) * / 6) with a HSigmoid op. + */ +class ngraph::pass::HSigmoidFusionWithClampDiv: public ngraph::pass::MatcherPass { +public: + NGRAPH_RTTI_DECLARATION; + HSigmoidFusionWithClampDiv(); }; /** @@ -73,6 +84,7 @@ public: add_matcher(); add_matcher(); add_matcher(); - add_matcher(); + add_matcher(); + add_matcher(); } -}; \ No newline at end of file +}; diff --git a/inference-engine/src/transformations/include/transformations/common_optimizations/hswish_fusion.hpp b/inference-engine/src/transformations/include/transformations/common_optimizations/hswish_fusion.hpp index 296373c7484..94d76493be1 100644 --- a/inference-engine/src/transformations/include/transformations/common_optimizations/hswish_fusion.hpp +++ b/inference-engine/src/transformations/include/transformations/common_optimizations/hswish_fusion.hpp @@ -16,15 +16,12 @@ namespace pass { class TRANSFORMATIONS_API HSwishFusion; class TRANSFORMATIONS_API HSwishFusionWithReluDiv; class TRANSFORMATIONS_API HSwishFusionWithReluMul; -class TRANSFORMATIONS_API HSwishFusionWithoutRelu; -class TRANSFORMATIONS_API HSwishFusionWithClampMul; -class TRANSFORMATIONS_API HSwishFusionWithClampDiv; -class TRANSFORMATIONS_API HSwishFusionWithHSigmoidMul; - +class TRANSFORMATIONS_API HSwishFusionWithHSigmoid; } // namespace pass } // namespace ngraph + /** * @ingroup ie_transformation_common_api * @brief HSwishFusion transformation replaces a sub-graph (x * (min(Relu(x + 3), 6))) / 6 with a HSwish op. @@ -45,44 +42,14 @@ public: HSwishFusionWithReluMul(); }; -/** - * @ingroup ie_transformation_common_api - * @brief HSwishFusion transformation replaces a sub-graph x * (min(max(x + 3, 0), 6) / 6) with a HSwish op. - */ -class ngraph::pass::HSwishFusionWithoutRelu: public ngraph::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - HSwishFusionWithoutRelu(); -}; - -/** - * @ingroup ie_transformation_common_api - * @brief HSwishFusion transformation replaces a sub-graph x * (Clamp(x + 3, 0, 6) * const(1/6)) with a HSwish op. - */ -class ngraph::pass::HSwishFusionWithClampMul: public ngraph::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - HSwishFusionWithClampMul(); -}; - -/** - * @ingroup ie_transformation_common_api - * @brief HSwishFusion transformation replaces a sub-graph x * (Clamp(x + 3, 0, 6) / 6) with a HSwish op. - */ -class ngraph::pass::HSwishFusionWithClampDiv: public ngraph::pass::MatcherPass { -public: - NGRAPH_RTTI_DECLARATION; - HSwishFusionWithClampDiv(); -}; - /** * @ingroup ie_transformation_common_api * @brief HSwishFusion transformation replaces a sub-graph x * HSigmoid(x) with a HSwish op. */ -class ngraph::pass::HSwishFusionWithHSigmoidMul: public ngraph::pass::MatcherPass { +class ngraph::pass::HSwishFusionWithHSigmoid: public ngraph::pass::MatcherPass { public: NGRAPH_RTTI_DECLARATION; - HSwishFusionWithHSigmoidMul(); + HSwishFusionWithHSigmoid(); }; /** @@ -95,9 +62,6 @@ public: HSwishFusion() { add_matcher(); add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); - add_matcher(); + add_matcher(); } }; diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp index d90ed977e3f..a2f08f0706c 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include #include @@ -20,21 +20,21 @@ ngraph::pass::HSigmoidFusionWithReluDiv::HSigmoidFusionWithReluDiv() { MATCHER_SCOPE(HSigmoidFusionWithReluDiv); // Replaces a sub-graph ((min(Relu(x + 3), 6)) / 6 with a HSigmoid op. auto input = ngraph::pattern::any_input(); - auto add_constant = ngraph::pattern::wrap_type(); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::pattern::wrap_type(); - auto min = std::make_shared(relu, min_constant); - auto div_constant = ngraph::pattern::wrap_type(); - auto div = std::make_shared(min, div_constant); + auto add_constant = ngraph::pattern::wrap_type(); + auto add = ngraph::pattern::wrap_type({input, add_constant}); + auto relu = ngraph::pattern::wrap_type({add}); + auto min_constant = ngraph::pattern::wrap_type(); + auto min = ngraph::pattern::wrap_type({relu, min_constant}); + auto div_constant = ngraph::pattern::wrap_type(); + auto div = ngraph::pattern::wrap_type({min, div_constant}); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { auto &pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) && op::util::has_constant_value(min_const_value, 6.0) @@ -44,7 +44,7 @@ ngraph::pass::HSigmoidFusionWithReluDiv::HSigmoidFusionWithReluDiv() { return false; } - auto hsigmoid = std::make_shared(x_output); + auto hsigmoid = register_new_node(x_output); hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name()); ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), @@ -67,22 +67,21 @@ ngraph::pass::HSigmoidFusionWithReluMul::HSigmoidFusionWithReluMul() { MATCHER_SCOPE(HSigmoidFusionWithReluMul); // Replaces a sub-graph ((min(Relu(x + 3), 6)) * const(1/6) with a HSigmoid op. auto input = ngraph::pattern::any_input(); - auto add_constant = ngraph::pattern::wrap_type(); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::pattern::wrap_type(); - auto min = std::make_shared(relu, min_constant); - //auto mul_first = std::make_shared(input, min); - auto mul_constant = ngraph::pattern::wrap_type(); - auto mul_second = std::make_shared(min, mul_constant); + auto add_constant = ngraph::pattern::wrap_type(); + auto add = ngraph::pattern::wrap_type({input, add_constant}); + auto relu = ngraph::pattern::wrap_type({add}); + auto min_constant = ngraph::pattern::wrap_type(); + auto min = ngraph::pattern::wrap_type({relu, min_constant}); + auto mul_constant = ngraph::pattern::wrap_type(); + auto mul_second = ngraph::pattern::wrap_type({min, mul_constant}); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { auto &pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto mul_const_value = std::dynamic_pointer_cast(pattern_to_output.at(mul_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); + auto mul_const_value = std::dynamic_pointer_cast(pattern_to_output.at(mul_constant).get_node_shared_ptr()); bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0f) && op::util::has_constant_value(min_const_value, 6.0f) @@ -92,7 +91,7 @@ ngraph::pass::HSigmoidFusionWithReluMul::HSigmoidFusionWithReluMul() { return false; } - auto hsigmoid = std::make_shared(x_output); + auto hsigmoid = register_new_node(x_output); hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name()); ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), @@ -115,24 +114,24 @@ ngraph::pass::HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() { MATCHER_SCOPE(HSigmoidFusionWithoutRelu); // Replaces a sub-graph (min(max(x + 3, 0), 6) / 6) with a HSigmoid op. auto input = ngraph::pattern::any_input(); - auto add_constant = ngraph::pattern::wrap_type(); - auto add = std::make_shared(input, add_constant); - auto max_constant = ngraph::pattern::wrap_type(); - auto max = std::make_shared(add, max_constant); - auto min_constant = ngraph::pattern::wrap_type(); - auto min = std::make_shared(max, min_constant); - auto div_constant = ngraph::pattern::wrap_type(); - auto div = std::make_shared(min, div_constant); - auto mul = std::make_shared(input, div); + auto add_constant = ngraph::pattern::wrap_type(); + auto add = ngraph::pattern::wrap_type({input, add_constant}); + auto max_constant = ngraph::pattern::wrap_type(); + auto max = ngraph::pattern::wrap_type({add, max_constant}); + auto min_constant = ngraph::pattern::wrap_type(); + auto min = ngraph::pattern::wrap_type({max, min_constant}); + auto div_constant = ngraph::pattern::wrap_type(); + auto div = ngraph::pattern::wrap_type({min, div_constant}); + auto mul = ngraph::pattern::wrap_type({input, div}); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { auto &pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto max_const_value = std::dynamic_pointer_cast(pattern_to_output.at(max_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto max_const_value = std::dynamic_pointer_cast(pattern_to_output.at(max_constant).get_node_shared_ptr()); + auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0f) && op::util::has_constant_value(max_const_value, 0.0f) @@ -143,7 +142,7 @@ ngraph::pass::HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() { return false; } - auto hsigmoid = std::make_shared(x_output); + auto hsigmoid = register_new_node(x_output); hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name()); ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), @@ -160,24 +159,24 @@ ngraph::pass::HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() { register_matcher(m, callback); } -NGRAPH_RTTI_DEFINITION(ngraph::pass::HSigmoidFusionWithClamp, "HSigmoidFusionWithClamp", 0); +NGRAPH_RTTI_DEFINITION(ngraph::pass::HSigmoidFusionWithClampMul, "HSigmoidFusionWithClampMul", 0); -ngraph::pass::HSigmoidFusionWithClamp::HSigmoidFusionWithClamp() { - MATCHER_SCOPE(HSigmoidFusionWithClamp); +ngraph::pass::HSigmoidFusionWithClampMul::HSigmoidFusionWithClampMul() { + MATCHER_SCOPE(HSigmoidFusionWithClampMul); // Replaces a sub-graph (Clamp(x + 3, 0, 6) * const(1/6)) with a HSigmoid op. auto input = ngraph::pattern::any_input(); - auto add_constant = ngraph::pattern::wrap_type(); - auto add = std::make_shared(input, add_constant); - auto clamp = std::make_shared(add, 0.0f, 6.0f); - auto mul_constant = ngraph::pattern::wrap_type(); - auto mul_first = std::make_shared(clamp, mul_constant); + auto add_constant = ngraph::pattern::wrap_type(); + auto add = ngraph::pattern::wrap_type({input, add_constant}); + auto clamp = ngraph::pattern::wrap_type({add}); + auto mul_constant = ngraph::pattern::wrap_type(); + auto mul_first = ngraph::pattern::wrap_type({clamp, mul_constant}); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { auto &pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto mul_const_value = std::dynamic_pointer_cast(pattern_to_output.at(mul_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto mul_const_value = std::dynamic_pointer_cast(pattern_to_output.at(mul_constant).get_node_shared_ptr()); bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) && op::util::has_constant_value(mul_const_value, (1.0/6.0), 0.0001); @@ -186,7 +185,11 @@ ngraph::pass::HSigmoidFusionWithClamp::HSigmoidFusionWithClamp() { return false; } - auto hsigmoid = std::make_shared(x_output); + auto clamp_node = std::dynamic_pointer_cast(pattern_to_output.at(clamp).get_node_shared_ptr()); + if (!clamp_node || clamp_node->get_min() != 0 || clamp_node->get_max() != 6) + return false; + + auto hsigmoid = register_new_node(x_output); hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name()); ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), @@ -201,3 +204,49 @@ ngraph::pass::HSigmoidFusionWithClamp::HSigmoidFusionWithClamp() { auto m = std::make_shared(mul_first, matcher_name); register_matcher(m, callback); } + +NGRAPH_RTTI_DEFINITION(ngraph::pass::HSigmoidFusionWithClampDiv, "HSigmoidFusionWithClampDiv", 0); + +ngraph::pass::HSigmoidFusionWithClampDiv::HSigmoidFusionWithClampDiv() { + MATCHER_SCOPE(HSigmoidFusionWithClampDiv); + // Replaces a sub-graph (Clamp(x + 3, 0, 6) / 6) with a HSigmoid op. + auto input = ngraph::pattern::any_input(); + auto add_constant = ngraph::pattern::wrap_type(); + auto add = ngraph::pattern::wrap_type({input, add_constant}); + auto clamp = ngraph::pattern::wrap_type({add}); + auto div_constant = ngraph::pattern::wrap_type(); + auto div = ngraph::pattern::wrap_type({clamp, div_constant}); + + ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { + auto &pattern_to_output = m.get_pattern_value_map(); + auto x_output = pattern_to_output.at(input); + + auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); + + bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) + && op::util::has_constant_value(div_const_value, 6.0); + + if (!valid_constant_values) { + return false; + } + + auto clamp_node = std::dynamic_pointer_cast(pattern_to_output.at(clamp).get_node_shared_ptr()); + if (!clamp_node || clamp_node->get_min() != 0 || clamp_node->get_max() != 6) + return false; + + auto hsigmoid = register_new_node(x_output); + + hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name()); + ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), + pattern_to_output.at(clamp).get_node_shared_ptr(), + pattern_to_output.at(div).get_node_shared_ptr() + }, + hsigmoid); + ngraph::replace_node(m.get_match_root(), hsigmoid); + return true; + }; + + auto m = std::make_shared(div, matcher_name); + register_matcher(m, callback); +} diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/hswish_fusion.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/hswish_fusion.cpp index 0a95d0e76ce..038dbd2ae97 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/hswish_fusion.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/hswish_fusion.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include #include @@ -20,22 +20,22 @@ ngraph::pass::HSwishFusionWithReluDiv::HSwishFusionWithReluDiv() { MATCHER_SCOPE(HSwishFusionWithReluDiv); // Replaces a sub-graph (x * (min(Relu(x + 3), 6)) / 6 with a HSwish op. auto input = ngraph::pattern::any_input(); - auto add_constant = ngraph::pattern::wrap_type(); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::pattern::wrap_type(); - auto min = std::make_shared(relu, min_constant); - auto mul = std::make_shared(input, min); - auto div_constant = ngraph::pattern::wrap_type(); - auto div = std::make_shared(mul, div_constant); + auto add_constant = ngraph::pattern::wrap_type(); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::pattern::wrap_type(); + auto min = std::make_shared(relu, min_constant); + auto mul = std::make_shared(input, min); + auto div_constant = ngraph::pattern::wrap_type(); + auto div = std::make_shared(mul, div_constant); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { auto &pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); + auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) && op::util::has_constant_value(min_const_value, 6.0) @@ -45,7 +45,7 @@ ngraph::pass::HSwishFusionWithReluDiv::HSwishFusionWithReluDiv() { return false; } - auto hswish = std::make_shared(x_output); + auto hswish = std::make_shared(x_output); hswish->set_friendly_name(m.get_match_root()->get_friendly_name()); ngraph::copy_runtime_info({ pattern_to_output.at(add_constant).get_node_shared_ptr(), @@ -72,22 +72,22 @@ ngraph::pass::HSwishFusionWithReluMul::HSwishFusionWithReluMul() { MATCHER_SCOPE(HSwishFusionWithReluMul); // Replaces a sub-graph (x * (min(Relu(x + 3), 6)) * const(1/6) with a HSwish op. auto input = ngraph::pattern::any_input(); - auto add_constant = ngraph::pattern::wrap_type(); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::pattern::wrap_type(); - auto min = std::make_shared(relu, min_constant); - auto mul_first = std::make_shared(input, min); - auto mul_constant = ngraph::pattern::wrap_type(); - auto mul_second = std::make_shared(mul_first, mul_constant); + auto add_constant = ngraph::pattern::wrap_type(); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::pattern::wrap_type(); + auto min = std::make_shared(relu, min_constant); + auto mul_first = std::make_shared(input, min); + auto mul_constant = ngraph::pattern::wrap_type(); + auto mul_second = std::make_shared(mul_first, mul_constant); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { auto &pattern_to_output = m.get_pattern_value_map(); auto x_output = pattern_to_output.at(input); - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto mul_const_value = std::dynamic_pointer_cast(pattern_to_output.at(mul_constant).get_node_shared_ptr()); + auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); + auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); + auto mul_const_value = std::dynamic_pointer_cast(pattern_to_output.at(mul_constant).get_node_shared_ptr()); bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0f) && op::util::has_constant_value(min_const_value, 6.0f) @@ -97,7 +97,7 @@ ngraph::pass::HSwishFusionWithReluMul::HSwishFusionWithReluMul() { return false; } - auto hswish = std::make_shared(x_output); + auto hswish = std::make_shared(x_output); hswish->set_friendly_name(m.get_match_root()->get_friendly_name()); ngraph::copy_runtime_info({ pattern_to_output.at(add_constant).get_node_shared_ptr(), @@ -118,166 +118,21 @@ ngraph::pass::HSwishFusionWithReluMul::HSwishFusionWithReluMul() { register_matcher(m, callback); } -NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusionWithoutRelu, "HSwishFusionWithoutRelu", 0); +NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusionWithHSigmoid, "HSwishFusionWithHSigmoid", 0); -ngraph::pass::HSwishFusionWithoutRelu::HSwishFusionWithoutRelu() { - MATCHER_SCOPE(HSwishFusionWithoutRelu); - // Replaces a sub-graph x * (min(max(x + 3, 0), 6) / 6) with a HSwish op. - auto input = ngraph::pattern::any_input(); - auto add_constant = ngraph::pattern::wrap_type(); - auto add = std::make_shared(input, add_constant); - auto max_constant = ngraph::pattern::wrap_type(); - auto max = std::make_shared(add, max_constant); - auto min_constant = ngraph::pattern::wrap_type(); - auto min = std::make_shared(max, min_constant); - auto div_constant = ngraph::pattern::wrap_type(); - auto div = std::make_shared(min, div_constant); - auto mul = std::make_shared(input, div); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); - auto x_output = pattern_to_output.at(input); - - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto max_const_value = std::dynamic_pointer_cast(pattern_to_output.at(max_constant).get_node_shared_ptr()); - auto min_const_value = std::dynamic_pointer_cast(pattern_to_output.at(min_constant).get_node_shared_ptr()); - auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); - - bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0f) - && op::util::has_constant_value(max_const_value, 0.0f) - && op::util::has_constant_value(min_const_value, 6.0f) - && op::util::has_constant_value(div_const_value, 6.0f); - - if (!valid_constant_values) { - return false; - } - - auto hswish = std::make_shared(x_output); - - hswish->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add_constant).get_node_shared_ptr(), - pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(max_constant).get_node_shared_ptr(), - pattern_to_output.at(max).get_node_shared_ptr(), - pattern_to_output.at(min_constant).get_node_shared_ptr(), - pattern_to_output.at(min).get_node_shared_ptr(), - pattern_to_output.at(div_constant).get_node_shared_ptr(), - pattern_to_output.at(div).get_node_shared_ptr(), - pattern_to_output.at(mul).get_node_shared_ptr() - }, - hswish); - ngraph::replace_node(m.get_match_root(), hswish); - return true; - }; - - auto m = std::make_shared(mul, matcher_name); - register_matcher(m, callback); -} - -NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusionWithClampMul, "HSwishFusionWithClampMul", 0); - -ngraph::pass::HSwishFusionWithClampMul::HSwishFusionWithClampMul() { - MATCHER_SCOPE(HSwishFusionWithClampMul); - // Replaces a sub-graph x * (Clamp(x + 3, 0, 6) * const(1/6)) with a HSwish op. - auto input = ngraph::pattern::any_input(); - auto add_constant = ngraph::pattern::wrap_type(); - auto add = std::make_shared(input, add_constant); - auto clamp = std::make_shared(add, 0.0f, 6.0f); - auto mul_constant = ngraph::pattern::wrap_type(); - auto mul_first = std::make_shared(clamp, mul_constant); - auto mul_second = std::make_shared(input, mul_first); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); - auto x_output = pattern_to_output.at(input); - - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto mul_const_value = std::dynamic_pointer_cast(pattern_to_output.at(mul_constant).get_node_shared_ptr()); - - bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) - && op::util::has_constant_value(mul_const_value, (1.0/6.0), 0.0001); - - if (!valid_constant_values) { - return false; - } - - auto hswish = std::make_shared(x_output); - - hswish->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add_constant).get_node_shared_ptr(), - pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(clamp).get_node_shared_ptr(), - pattern_to_output.at(mul_constant).get_node_shared_ptr(), - pattern_to_output.at(mul_first).get_node_shared_ptr(), - pattern_to_output.at(mul_second).get_node_shared_ptr() - }, - hswish); - ngraph::replace_node(m.get_match_root(), hswish); - return true; - }; - - auto m = std::make_shared(mul_second, matcher_name); - register_matcher(m, callback); -} - -NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusionWithClampDiv, "HSwishFusionWithClampDiv", 0); - -ngraph::pass::HSwishFusionWithClampDiv::HSwishFusionWithClampDiv() { - MATCHER_SCOPE(HSwishFusionWithClampDiv); - // Replaces a sub-graph x * (Clamp(x + 3, 0, 6) / 6) with a HSwish op. - auto input = ngraph::pattern::any_input(); - auto add_constant = ngraph::pattern::wrap_type(); - auto add = std::make_shared(input, add_constant); - auto clamp = std::make_shared(add, 0.0f, 6.0f); - auto div_constant = ngraph::pattern::wrap_type(); - auto div = std::make_shared(clamp, div_constant); - auto mul = std::make_shared(input, div); - - ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { - auto &pattern_to_output = m.get_pattern_value_map(); - auto x_output = pattern_to_output.at(input); - - auto add_const_value = std::dynamic_pointer_cast(pattern_to_output.at(add_constant).get_node_shared_ptr()); - auto div_const_value = std::dynamic_pointer_cast(pattern_to_output.at(div_constant).get_node_shared_ptr()); - - bool valid_constant_values = op::util::has_constant_value(add_const_value, 3.0) - && op::util::has_constant_value(div_const_value, 6.0); - if (!valid_constant_values) { - return false; - } - - auto hswish = std::make_shared(x_output); - - hswish->set_friendly_name(m.get_match_root()->get_friendly_name()); - ngraph::copy_runtime_info({ pattern_to_output.at(add).get_node_shared_ptr(), - pattern_to_output.at(clamp).get_node_shared_ptr(), - pattern_to_output.at(div).get_node_shared_ptr(), - pattern_to_output.at(mul).get_node_shared_ptr() - }, - hswish); - ngraph::replace_node(m.get_match_root(), hswish); - return true; - }; - - auto m = std::make_shared(mul, matcher_name); - register_matcher(m, callback); -} - -NGRAPH_RTTI_DEFINITION(ngraph::pass::HSwishFusionWithHSigmoidMul, "HSwishFusionWithHSigmoidMul", 0); - -ngraph::pass::HSwishFusionWithHSigmoidMul::HSwishFusionWithHSigmoidMul() { - MATCHER_SCOPE(HSwishFusionWithHSigmoidMul); +ngraph::pass::HSwishFusionWithHSigmoid::HSwishFusionWithHSigmoid() { + MATCHER_SCOPE(HSwishFusionWithHSigmoid); // Replaces a sub-graph x * HSigmoid(x) with a HSwish op. - auto input = ngraph::pattern::any_input(); - auto hsigmoid_pattern = ngraph::pattern::wrap_type({input}, ngraph::pattern::consumers_count(1)); - auto mul_pattern = ngraph::pattern::wrap_type({input, hsigmoid_pattern}); + auto input = pattern::any_input(); + auto hsigmoid_pattern = pattern::wrap_type({input}, pattern::consumers_count(1)); + auto mul_pattern = pattern::wrap_type({input, hsigmoid_pattern}); ngraph::matcher_pass_callback callback = [=](ngraph::pattern::Matcher &m) { const auto& pattern_to_output = m.get_pattern_value_map(); auto hsigmoid = pattern_to_output.at(hsigmoid_pattern).get_node_shared_ptr(); auto mul = pattern_to_output.at(mul_pattern).get_node_shared_ptr(); - auto hswish = std::make_shared(pattern_to_output.at(input)); + auto hswish = std::make_shared(pattern_to_output.at(input)); hswish->set_friendly_name(mul->get_friendly_name()); ngraph::copy_runtime_info({hsigmoid, mul}, hswish); ngraph::replace_node(mul, hswish); diff --git a/inference-engine/tests/functional/inference_engine/transformations/hsigmoid_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/hsigmoid_fusion_test.cpp index 8a9bbbd82cb..3ed5fcdcbd2 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/hsigmoid_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/hsigmoid_fusion_test.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include @@ -21,14 +21,14 @@ using namespace testing; TEST(TransformationTests, HSigmoidFusionWithReluDivF16) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(relu, min_constant); - auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto div = std::make_shared(min, div_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(relu, min_constant); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto div = std::make_shared(min, div_constant); f = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); @@ -40,8 +40,8 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivF16) { } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hsigmoid = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hsigmoid = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input}); } @@ -53,14 +53,14 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivF16) { TEST(TransformationTests, HSigmoidFusionWithReluDivF32) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{}); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(relu, min_constant); - auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0}); - auto div = std::make_shared(min, div_constant); + auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{}); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(relu, min_constant); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0}); + auto div = std::make_shared(min, div_constant); f = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); @@ -72,8 +72,8 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivF32) { } { - auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{}); - auto hsigmoid = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{}); + auto hsigmoid = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input}); } @@ -85,14 +85,14 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivF32) { TEST(TransformationTests, HSigmoidFusionWithReluMul) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(relu, min_constant); - auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.1666666716}); - auto mul_second = std::make_shared(min, mul_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(relu, min_constant); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.1666666716}); + auto mul_second = std::make_shared(min, mul_constant); f = std::make_shared(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); @@ -104,8 +104,8 @@ TEST(TransformationTests, HSigmoidFusionWithReluMul) { } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hsigmoid = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hsigmoid = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input}); } @@ -117,15 +117,15 @@ TEST(TransformationTests, HSigmoidFusionWithReluMul) { TEST(TransformationTests, HSigmoidFusionWithoutRelu) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto max_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); - auto max = std::make_shared(add, max_constant); - auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(max, min_constant); - auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto div = std::make_shared(min, div_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); + auto max = std::make_shared(add, max_constant); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(max, min_constant); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto div = std::make_shared(min, div_constant); f = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); @@ -137,8 +137,8 @@ TEST(TransformationTests, HSigmoidFusionWithoutRelu) { } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hsigmoid = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hsigmoid = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input}); } @@ -147,15 +147,15 @@ TEST(TransformationTests, HSigmoidFusionWithoutRelu) { ASSERT_TRUE(res.first) << res.second; } -TEST(TransformationTests, HSigmoidFusionWithClamp) { +TEST(TransformationTests, HSigmoidFusionWithClampMul) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); auto clamp = std::make_shared(add, 0.0f, 6.0f); - auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {1.0 / 6.0}); - auto mul_first = std::make_shared(clamp, mul_constant); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {1.0 / 6.0}); + auto mul_first = std::make_shared(clamp, mul_constant); f = std::make_shared(ngraph::NodeVector{mul_first}, ngraph::ParameterVector{input}); @@ -167,8 +167,38 @@ TEST(TransformationTests, HSigmoidFusionWithClamp) { } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hsigmoid = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hsigmoid = std::make_shared(input); + + f_ref = std::make_shared(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input}); + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} + +TEST(TransformationTests, HSigmoidFusionWithClampDiv) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto clamp = std::make_shared(add, 0.0f, 6.0f); + auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto div = std::make_shared(clamp, div_constant); + + f = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); + + ngraph::pass::Manager manager; + manager.register_pass(); + manager.register_pass(); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + } + + { + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hsigmoid = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hsigmoid}, ngraph::ParameterVector{input}); } @@ -180,14 +210,14 @@ TEST(TransformationTests, HSigmoidFusionWithClamp) { TEST(TransformationTests, HSigmoidFusionWithReluMulWrongConstValue) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(relu, min_constant); - auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167}); - auto mul_second = std::make_shared(min, mul_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(relu, min_constant); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167}); + auto mul_second = std::make_shared(min, mul_constant); f = std::make_shared(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); @@ -199,14 +229,14 @@ TEST(TransformationTests, HSigmoidFusionWithReluMulWrongConstValue) { } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(relu, min_constant); - auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167}); - auto mul_second = std::make_shared(min, mul_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(relu, min_constant); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167}); + auto mul_second = std::make_shared(min, mul_constant); f_ref = std::make_shared(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); } @@ -218,14 +248,14 @@ TEST(TransformationTests, HSigmoidFusionWithReluMulWrongConstValue) { TEST(TransformationTests, HSigmoidFusionWithReluDivWrongConstValue) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::Shape{}); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); - auto min = std::make_shared(relu, min_constant); - auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); - auto div = std::make_shared(min, div_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::Shape{}); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); + auto min = std::make_shared(relu, min_constant); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); + auto div = std::make_shared(min, div_constant); f = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); @@ -237,14 +267,14 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivWrongConstValue) { } { - auto input = std::make_shared(ngraph::element::f16, ngraph::Shape{}); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); - auto min = std::make_shared(relu, min_constant); - auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); - auto div = std::make_shared(min, div_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::Shape{}); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); + auto min = std::make_shared(relu, min_constant); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); + auto div = std::make_shared(min, div_constant); f_ref = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); } @@ -256,15 +286,15 @@ TEST(TransformationTests, HSigmoidFusionWithReluDivWrongConstValue) { TEST(TransformationTests, HSigmoidFusionWithoutReluWrongConstValue) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); - auto add = std::make_shared(input, add_constant); - auto max_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22}); - auto max = std::make_shared(add, max_constant); - auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01}); - auto min = std::make_shared(max, min_constant); - auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); - auto div = std::make_shared(min, div_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); + auto add = std::make_shared(input, add_constant); + auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22}); + auto max = std::make_shared(add, max_constant); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01}); + auto min = std::make_shared(max, min_constant); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); + auto div = std::make_shared(min, div_constant); f = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); @@ -276,15 +306,15 @@ TEST(TransformationTests, HSigmoidFusionWithoutReluWrongConstValue) { } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); - auto add = std::make_shared(input, add_constant); - auto max_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22}); - auto max = std::make_shared(add, max_constant); - auto min_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01}); - auto min = std::make_shared(max, min_constant); - auto div_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); - auto div = std::make_shared(min, div_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); + auto add = std::make_shared(input, add_constant); + auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22}); + auto max = std::make_shared(add, max_constant); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01}); + auto min = std::make_shared(max, min_constant); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); + auto div = std::make_shared(min, div_constant); f_ref = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); } @@ -296,12 +326,12 @@ TEST(TransformationTests, HSigmoidFusionWithoutReluWrongConstValue) { TEST(TransformationTests, HSigmoidFusionWithClampWrongConstValue) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); - auto add = std::make_shared(input, add_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); + auto add = std::make_shared(input, add_constant); auto clamp = std::make_shared(add, 0.11f, 6.02f); - auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15}); - auto mul_first = std::make_shared(clamp, mul_constant); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15}); + auto mul_first = std::make_shared(clamp, mul_constant); f = std::make_shared(ngraph::NodeVector{mul_first}, ngraph::ParameterVector{input}); @@ -313,12 +343,12 @@ TEST(TransformationTests, HSigmoidFusionWithClampWrongConstValue) { } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); - auto add = std::make_shared(input, add_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); + auto add = std::make_shared(input, add_constant); auto clamp = std::make_shared(add, 0.11f, 6.02f); - auto mul_constant = ngraph::opset4::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15}); - auto mul_first = std::make_shared(clamp, mul_constant); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15}); + auto mul_first = std::make_shared(clamp, mul_constant); f_ref = std::make_shared(ngraph::NodeVector{mul_first}, ngraph::ParameterVector{input}); } diff --git a/inference-engine/tests/functional/inference_engine/transformations/hswish_fusion_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/hswish_fusion_test.cpp index ed73d064f46..7f3954656f3 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/hswish_fusion_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/hswish_fusion_test.cpp @@ -8,8 +8,9 @@ #include #include -#include +#include #include +#include "transformations/common_optimizations/hsigmoid_fusion.hpp" #include #include #include @@ -21,28 +22,28 @@ using namespace testing; TEST(TransformationTests, HSwishFusionWithReluDivF16) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(relu, min_constant); - auto mul = std::make_shared(input, min); - auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto div = std::make_shared(mul, div_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(relu, min_constant); + auto mul = std::make_shared(input, min); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto div = std::make_shared(mul, div_constant); f = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hswish = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hswish = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } @@ -54,28 +55,28 @@ TEST(TransformationTests, HSwishFusionWithReluDivF16) { TEST(TransformationTests, HSwishFusionWithReluDivF32) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{}); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f32, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(relu, min_constant); - auto mul = std::make_shared(input, min); - auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0}); - auto div = std::make_shared(mul, div_constant); + auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{}); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(relu, min_constant); + auto mul = std::make_shared(input, min); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0}); + auto div = std::make_shared(mul, div_constant); f = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{}); - auto hswish = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f32, ngraph::Shape{}); + auto hswish = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } @@ -87,28 +88,28 @@ TEST(TransformationTests, HSwishFusionWithReluDivF32) { TEST(TransformationTests, HSwishFusionWithReluMul) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(relu, min_constant); - auto mul_first = std::make_shared(input, min); - auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.1666666716}); - auto mul_second = std::make_shared(mul_first, mul_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(relu, min_constant); + auto mul_first = std::make_shared(input, min); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.1666666716}); + auto mul_second = std::make_shared(mul_first, mul_constant); f = std::make_shared(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hswish = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hswish = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } @@ -120,29 +121,31 @@ TEST(TransformationTests, HSwishFusionWithReluMul) { TEST(TransformationTests, HSwishFusionWithoutRelu) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto max_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); - auto max = std::make_shared(add, max_constant); - auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(max, min_constant); - auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto div = std::make_shared(min, div_constant); - auto mul = std::make_shared(input, div); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); + auto max = std::make_shared(add, max_constant); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(max, min_constant); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto div = std::make_shared(min, div_constant); + auto mul = std::make_shared(input, div); f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + auto gr = manager.register_pass(); + gr->add_matcher(); + gr->add_matcher(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hswish = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hswish = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } @@ -154,26 +157,28 @@ TEST(TransformationTests, HSwishFusionWithoutRelu) { TEST(TransformationTests, HSwishFusionWithClampMul) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto clamp = std::make_shared(add, 0.0f, 6.0f); - auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {1.0 / 6.0}); - auto mul_first = std::make_shared(clamp, mul_constant); - auto mul_second = std::make_shared(input, mul_first); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto clamp = std::make_shared(add, 0.0f, 6.0f); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {1.0 / 6.0}); + auto mul_first = std::make_shared(clamp, mul_constant); + auto mul_second = std::make_shared(input, mul_first); f = std::make_shared(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + auto gr = manager.register_pass(); + gr->add_matcher(); + gr->add_matcher(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hswish = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hswish = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } @@ -185,26 +190,28 @@ TEST(TransformationTests, HSwishFusionWithClampMul) { TEST(TransformationTests, HSwishFusionWithClampDiv) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto clamp = std::make_shared(add, 0.0f, 6.0f); - auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto div = std::make_shared(clamp, div_constant); - auto mul = std::make_shared(input, div); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto clamp = std::make_shared(add, 0.0f, 6.0f); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto div = std::make_shared(clamp, div_constant); + auto mul = std::make_shared(input, div); f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + auto gr = manager.register_pass(); + gr->add_matcher(); + gr->add_matcher(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hswish = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hswish = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } @@ -216,35 +223,35 @@ TEST(TransformationTests, HSwishFusionWithClampDiv) { TEST(TransformationTests, HSwishFusionWithReluMulWrongConstValue) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(relu, min_constant); - auto mul_first = std::make_shared(input, min); - auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167}); - auto mul_second = std::make_shared(mul_first, mul_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(relu, min_constant); + auto mul_first = std::make_shared(input, min); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167}); + auto mul_second = std::make_shared(mul_first, mul_constant); f = std::make_shared(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); - auto min = std::make_shared(relu, min_constant); - auto mul_first = std::make_shared(input, min); - auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167}); - auto mul_second = std::make_shared(mul_first, mul_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); + auto min = std::make_shared(relu, min_constant); + auto mul_first = std::make_shared(input, min); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167}); + auto mul_second = std::make_shared(mul_first, mul_constant); f_ref = std::make_shared(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); } @@ -256,35 +263,35 @@ TEST(TransformationTests, HSwishFusionWithReluMulWrongConstValue) { TEST(TransformationTests, HSwishFusionWithReluDivWrongConstValue) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::Shape{}); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); - auto min = std::make_shared(relu, min_constant); - auto mul = std::make_shared(input, min); - auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); - auto div = std::make_shared(mul, div_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::Shape{}); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); + auto min = std::make_shared(relu, min_constant); + auto mul = std::make_shared(input, min); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); + auto div = std::make_shared(mul, div_constant); f = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f16, ngraph::Shape{}); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01}); - auto add = std::make_shared(input, add_constant); - auto relu = std::make_shared(add); - auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); - auto min = std::make_shared(relu, min_constant); - auto mul = std::make_shared(input, min); - auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); - auto div = std::make_shared(mul, div_constant); + auto input = std::make_shared(ngraph::element::f16, ngraph::Shape{}); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01}); + auto add = std::make_shared(input, add_constant); + auto relu = std::make_shared(add); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); + auto min = std::make_shared(relu, min_constant); + auto mul = std::make_shared(input, min); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); + auto div = std::make_shared(mul, div_constant); f_ref = std::make_shared(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); } @@ -296,37 +303,39 @@ TEST(TransformationTests, HSwishFusionWithReluDivWrongConstValue) { TEST(TransformationTests, HSwishFusionWithoutReluWrongConstValue) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); - auto add = std::make_shared(input, add_constant); - auto max_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22}); - auto max = std::make_shared(add, max_constant); - auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01}); - auto min = std::make_shared(max, min_constant); - auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); - auto div = std::make_shared(min, div_constant); - auto mul = std::make_shared(input, div); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); + auto add = std::make_shared(input, add_constant); + auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22}); + auto max = std::make_shared(add, max_constant); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01}); + auto min = std::make_shared(max, min_constant); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); + auto div = std::make_shared(min, div_constant); + auto mul = std::make_shared(input, div); f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + auto gr = manager.register_pass(); + gr->add_matcher(); + gr->add_matcher(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); - auto add = std::make_shared(input, add_constant); - auto max_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22}); - auto max = std::make_shared(add, max_constant); - auto min_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01}); - auto min = std::make_shared(max, min_constant); - auto div_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); - auto div = std::make_shared(min, div_constant); - auto mul = std::make_shared(input, div); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); + auto add = std::make_shared(input, add_constant); + auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22}); + auto max = std::make_shared(add, max_constant); + auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01}); + auto min = std::make_shared(max, min_constant); + auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); + auto div = std::make_shared(min, div_constant); + auto mul = std::make_shared(input, div); f_ref = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); } @@ -338,31 +347,33 @@ TEST(TransformationTests, HSwishFusionWithoutReluWrongConstValue) { TEST(TransformationTests, HSwishFusionWithClampWrongConstValue) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); - auto add = std::make_shared(input, add_constant); - auto clamp = std::make_shared(add, 0.11f, 6.02f); - auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15}); - auto mul_first = std::make_shared(clamp, mul_constant); - auto mul_second = std::make_shared(input, mul_first); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); + auto add = std::make_shared(input, add_constant); + auto clamp = std::make_shared(add, 0.11f, 6.02f); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15}); + auto mul_first = std::make_shared(clamp, mul_constant); + auto mul_second = std::make_shared(input, mul_first); f = std::make_shared(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + auto gr = manager.register_pass(); + gr->add_matcher(); + gr->add_matcher(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto add_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); - auto add = std::make_shared(input, add_constant); - auto clamp = std::make_shared(add, 0.11f, 6.02f); - auto mul_constant = ngraph::opset6::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15}); - auto mul_first = std::make_shared(clamp, mul_constant); - auto mul_second = std::make_shared(input, mul_first); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); + auto add = std::make_shared(input, add_constant); + auto clamp = std::make_shared(add, 0.11f, 6.02f); + auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15}); + auto mul_first = std::make_shared(clamp, mul_constant); + auto mul_second = std::make_shared(input, mul_first); f_ref = std::make_shared(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); } @@ -374,22 +385,22 @@ TEST(TransformationTests, HSwishFusionWithClampWrongConstValue) { TEST(TransformationTests, HSwishFusionWithHSigmoidMul) { std::shared_ptr f(nullptr), f_ref(nullptr); { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hsigmoid = std::make_shared(input); - auto mul = std::make_shared(input, hsigmoid); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hsigmoid = std::make_shared(input); + auto mul = std::make_shared(input, hsigmoid); f = std::make_shared(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); ngraph::pass::Manager manager; manager.register_pass(); - manager.register_pass(); + manager.register_pass(); manager.run_passes(f); ASSERT_NO_THROW(check_rt_info(f)); } { - auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); - auto hswish = std::make_shared(input); + auto input = std::make_shared(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); + auto hswish = std::make_shared(input); f_ref = std::make_shared(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); }