diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/reshape_fc_fusion.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/reshape_fc_fusion.cpp deleted file mode 100644 index bacc0bbef6e7ab..00000000000000 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/reshape_fc_fusion.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "reshape_fc_fusion.hpp" -#include "transformations/cpu_opset/common/op/fully_connected.hpp" -#include -#include -#include -#include -#include - -#include "itt.hpp" - -ov::intel_cpu::ReshapeFullyConnectedFusion::ReshapeFullyConnectedFusion() { - MATCHER_SCOPE(ReshapeFullyConnectedFusion); - auto m_reshape = ngraph::pattern::wrap_type({ngraph::pattern::any_input(ov::pass::pattern::has_static_shape()), - ngraph::pattern::any_input()}, - ngraph::pattern::has_static_shape()); - ngraph::OutputVector fcInputs = {m_reshape, ngraph::pattern::any_input()}; - auto fc = ngraph::pattern::wrap_type(fcInputs, ngraph::pattern::has_static_shape()); - - ngraph::matcher_pass_callback callback = [](ngraph::pattern::Matcher &m) { - auto fc = std::dynamic_pointer_cast(m.get_match_root()); - if (!fc) - return false; - auto reshape = std::dynamic_pointer_cast(fc->get_input_node_shared_ptr(0)); - if (!reshape) - return false; - - // Check that Reshape reshapes 4D tensor to 2D or input shape = output shape - auto shape_in = reshape->input_value(0).get_shape(); - auto shape_out = reshape->get_shape(); - if (!((shape_in.size() == 4 && reshape->get_shape().size() == 2) || (shape_in == shape_out && !shape_in.empty()))) { - return false; - } - - // Check that Weights[O, C*H*W] consistent with Input[N, C, H, W] - auto shape_w = fc->input_value(1).get_shape(); - if (shape_in[0] != shape_out[0] || std::accumulate(shape_in.begin() + 1, shape_in.end(), size_t{1}, std::multiplies()) != shape_w[1]) { - return false; - } - - ngraph::NodeVector new_ops; - auto weightInput = fc->input(1).get_source_output(); - ngraph::Shape newWeightsShape; - const auto outShape = fc->get_shape(); - if (shape_in.size() == 3) { - newWeightsShape = ngraph::Shape({outShape[2], shape_in[2]}); - } else { - newWeightsShape.push_back(outShape[1]); - for (size_t i = 1; i < shape_in.size(); i++) - newWeightsShape.push_back(shape_in[i]); - } - - if (newWeightsShape != weightInput.get_shape()) { - auto newShape = std::make_shared(ngraph::element::i64, ngraph::Shape{newWeightsShape.size()}, newWeightsShape); - weightInput = std::make_shared(weightInput, newShape, true); - new_ops.push_back(weightInput.get_node_shared_ptr()); - } - - std::shared_ptr new_fc = std::make_shared( - reshape->input_value(0), - weightInput, - ngraph::Rank(outShape.size()), - fc->output(0).get_element_type()); - new_ops.push_back(new_fc); - new_fc->set_friendly_name(fc->get_friendly_name()); - ngraph::copy_runtime_info({reshape, fc}, new_ops); - ngraph::replace_node(fc, new_fc); - return true; - }; - - auto m = std::make_shared(fc, matcher_name); - register_matcher(m, callback); -} diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/reshape_fc_fusion.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/reshape_fc_fusion.hpp deleted file mode 100644 index 61c16353356179..00000000000000 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/reshape_fc_fusion.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include - -namespace ov { -namespace intel_cpu { - -class ReshapeFullyConnectedFusion : public ov::pass::MatcherPass { -public: - OPENVINO_RTTI("ReshapeFullyConnectedFusion", "0"); - ReshapeFullyConnectedFusion(); -}; - -} // namespace intel_cpu -} // namespace ov diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/convert_to_cpu_specific_opset.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/convert_to_cpu_specific_opset.hpp index 2836f0ea4f1aa7..ab6018346f8b5d 100644 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/convert_to_cpu_specific_opset.hpp +++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/convert_to_cpu_specific_opset.hpp @@ -5,7 +5,6 @@ #include #include "ngraph/op/fake_quantize.hpp" #include "ngraph/pass/manager.hpp" -#include "common/pass/reshape_fc_fusion.hpp" #include "common/pass/align_matmul_input_ranks.hpp" #include "transformations/common_optimizations/reshape_prelu.hpp" #include "common/pass/convert_broadcast_to_tiles.hpp" @@ -41,9 +40,6 @@ inline void ConvertToCPUSpecificOpset(std::shared_ptr &nGraphF CPU_REGISTER_PASS_COMMON(manager, ConvertToLeakyRelu); CPU_REGISTER_PASS_COMMON(manager, ConvertToSwishCPU); CPU_REGISTER_PASS_COMMON(manager, OptimizeSequenceTransposes); - if (!ov::op::util::has_op_with_type(nGraphFunc)) { - CPU_REGISTER_PASS_COMMON(manager, ReshapeFullyConnectedFusion); - } // after transformation "MoveEltwiseUpThroughDataMov" there can be reshaped sequences that should be eliminated or fused CPU_REGISTER_PASS_COMMON(manager, ov::pass::ReshapeSequenceFusion); CPU_REGISTER_PASS_COMMON(manager, ov::pass::ConstantFolding);