diff --git a/inference-engine/src/transformations/include/transformations/mul_add_squence_fusion.hpp b/inference-engine/src/transformations/include/transformations/mul_add_squence_fusion.hpp deleted file mode 100644 index b5e61749b5c4a2..00000000000000 --- a/inference-engine/src/transformations/include/transformations/mul_add_squence_fusion.hpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (C) 2018-2020 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include -#include - -#include - -#include - -#include "ngraph/pattern/matcher.hpp" - -#include - -#include "ngraph/op/util/binary_elementwise_arithmetic.hpp" - -#include -#include -#include - -namespace ngraph { -namespace pass { - -class TRANSFORMATIONS_API MulAddFusion; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::MulAddFusion: public ngraph::pass::GraphRewrite { -public: - MulAddFusion() : GraphRewrite() { - mul_add_fusion(); - mul_add_fusion(); - } - -private: - template - void mul_add_fusion(); -}; - - -template -std::pair, std::shared_ptr> parse_eltwise_inputs(std::shared_ptr node) { - auto eltwise = std::dynamic_pointer_cast(node->input(0).get_source_output().get_node_shared_ptr()); - auto constant = std::dynamic_pointer_cast(node->input(1).get_source_output().get_node_shared_ptr()); - - if (!eltwise) { - eltwise = std::dynamic_pointer_cast(node->input(1).get_source_output().get_node_shared_ptr()); - constant = std::dynamic_pointer_cast(node->input(0).get_source_output().get_node_shared_ptr()); - } - - if (!eltwise || !constant) { - return {nullptr, nullptr}; - } - - return {eltwise, constant}; -} - -template -bool fusion(std::shared_ptr m_eltwise) { - using namespace ngraph; - - auto m_attrs = op::util::EltwiseAttrs::get_op_attrs(std::static_pointer_cast(m_eltwise)); - if (!m_attrs || !m_attrs->can_be_fused()) { - return false; - } - - std::shared_ptr eltwise, add, mul; - std::shared_ptr constant, constant1, constant2; - std::tie(add, constant1) = parse_eltwise_inputs(m_eltwise); - std::tie(mul, constant2) = parse_eltwise_inputs(m_eltwise); - - if (add && add->output(0).get_target_inputs().size() != 1) { - return false; - } - - if (mul && mul->output(0).get_target_inputs().size() != 1) { - return false; - } - - if (add || mul) { - std::tie(eltwise, constant) = (add ? std::make_tuple(add, constant1) : std::make_tuple(mul, constant2)); - auto res = parse_eltwise_inputs(eltwise); - - auto attrs = op::util::EltwiseAttrs::get_op_attrs(eltwise); - if (!attrs || !attrs->can_be_fused()) { - return false; - } - - // res.first should be data input and res.second should be constant - if (attrs->get_const_input_id() == 0) { - swap(res.first, res.second); - } - - // Mul->Mul => Mul, Add->Add => Add - if (std::dynamic_pointer_cast(eltwise) && std::dynamic_pointer_cast(m_eltwise)) { - auto new_const = std::make_shared(constant, res.second); - auto new_eltwise = std::make_shared(res.first, new_const); - - copy_runtime_info(m_eltwise, {new_const, new_eltwise}); - replace_node(m_eltwise, new_eltwise); - new_eltwise->set_op_annotations(std::make_shared(m_attrs)); - new_eltwise->set_friendly_name(m_eltwise->get_friendly_name()); - return true; - } - - // Add->Mul => Mul->Add - if (std::dynamic_pointer_cast(eltwise) && std::dynamic_pointer_cast(m_eltwise)) { - auto new_mul = std::make_shared(res.first, constant); - auto new_const = std::make_shared(constant, res.second); - auto new_add = std::make_shared (new_mul, new_const); - - copy_runtime_info(m_eltwise, {new_mul, new_const, new_add}); - replace_node(m_eltwise, new_add); - - // We need to preserve op annotations and namings - new_mul->set_op_annotations(std::make_shared(attrs)); - new_add->set_op_annotations(std::make_shared(m_attrs)); - new_add->set_friendly_name(m_eltwise->get_friendly_name()); - fusion(new_mul); - return true; - } - } - - return false; -} - -template -void ngraph::pass::MulAddFusion::mul_add_fusion() { - auto input1 = std::make_shared(element::f32, Shape{}); - auto input2 = std::make_shared(element::f32, Shape{}); - auto eltwise = std::make_shared(input1, input2); - - ngraph::graph_rewrite_callback callback = [&](ngraph::pattern::Matcher &m) { - static_assert(std::is_same() || std::is_same(), - "Unsupported template parameter. Only Add or Multiply allowed!"); - - if (auto m_eltwise = std::dynamic_pointer_cast(m.get_match_root())) { - return fusion(m_eltwise); - } - - return false; - }; - - auto m = std::make_shared(eltwise, "MulAddFusion"); - this->add_matcher(m, callback, PassProperty::CHANGE_DYNAMIC_STATE); -} diff --git a/inference-engine/src/transformations/include/transformations/mul_add_verification.hpp b/inference-engine/src/transformations/include/transformations/mul_add_verification.hpp deleted file mode 100644 index f491b66a640720..00000000000000 --- a/inference-engine/src/transformations/include/transformations/mul_add_verification.hpp +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) 2018-2020 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -#include - -#include - -#include "ngraph/pattern/matcher.hpp" -#include "ngraph/op/broadcast.hpp" -#include "ngraph/op/reshape.hpp" -#include "ngraph/op/add.hpp" - -#include "ngraph/op/group_conv.hpp" - -#include - -#include "mul_add_squence_fusion.hpp" -#include - -namespace ngraph { -namespace pass { - -class TRANSFORMATIONS_API MulAddVerification; - -} // namespace pass -} // namespace ngraph - -class ngraph::pass::MulAddVerification: public ngraph::pass::GraphRewrite { -public: - /* - * This transformation aligns all Multiply and Add operations to have the same order of inputs - * In case if one of inputs is Constant it should be placed to the second input - */ - MulAddVerification() : GraphRewrite() { - mul_add_verification(); - mul_add_verification(); - } - -private: - template - void mul_add_verification(); -}; - -template -void ngraph::pass::MulAddVerification::mul_add_verification() { - Shape shape{}; - using std::make_shared; - using std::dynamic_pointer_cast; - auto input1 = make_shared(element::f32, shape); - auto input2 = make_shared(element::f32, shape); - auto eltwise = make_shared(input1, input2); - - ngraph::graph_rewrite_callback callback = [](ngraph::pattern::Matcher &m) { - if (auto eltwise = dynamic_pointer_cast(m.get_match_root())) { - auto in0 = std::dynamic_pointer_cast(eltwise->input(0).get_source_output().get_node_shared_ptr()); - auto in1 = std::dynamic_pointer_cast(eltwise->input(1).get_source_output().get_node_shared_ptr()); - - auto attrs = make_shared(); - if (in0) { - attrs->set_const_input_id(0); - } - - if (in1) { - attrs->set_const_input_id(1); - } - - attrs->set_consumers_count(eltwise->output(0).get_target_inputs().size()); - - eltwise->set_op_annotations(attrs); - return true; - } - - return false; - }; - - auto m = std::make_shared(eltwise, "MulAddVerification"); - this->add_matcher(m, callback, PassProperty::CHANGE_DYNAMIC_STATE); -}