Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[Snippets] Remove unused InsertMoveBroadcast pass (#32301)

Arseniy Obolenskiy5cb69a37f22c
diff --git a/src/common/snippets/include/snippets/pass/insert_movebroadcast.hpp b/src/common/snippets/include/snippets/pass/insert_movebroadcast.hpp
deleted file mode 100644
index 26576f4888f..00000000000
--- a/src/common/snippets/include/snippets/pass/insert_movebroadcast.hpp
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2018-2025 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#pragma once
-
-#include "openvino/core/node.hpp"
-#include "openvino/core/node_output.hpp"
-#include "openvino/core/partial_shape.hpp"
-#include "openvino/pass/matcher_pass.hpp"
-
-namespace ov::snippets::pass {
-
-/**
- * @interface InsertMoveBroadcast
- * @brief Inserts explicit MoveBroadcast instruction if broadcasting by most varying dimension is needed.
- * The pass is used to convert model to a canonical form for code generation
- * @ingroup snippets
- */
-class InsertMoveBroadcast : public ov::pass::MatcherPass {
-public:
- OPENVINO_MATCHER_PASS_RTTI("snippets::pass::InsertMoveBroadcast");
- InsertMoveBroadcast();
-
- static Output<ov::Node> BroadcastNodeLastDim(const ov::Output<ov::Node>& value,
- const ov::PartialShape& target_shape,
- const ov::PartialShape& normalized_shape);
-};
-
-} // namespace ov::snippets::pass
diff --git a/src/common/snippets/src/pass/insert_movebroadcast.cpp b/src/common/snippets/src/pass/insert_movebroadcast.cpp
deleted file mode 100644
index dbb986a61ff..00000000000
--- a/src/common/snippets/src/pass/insert_movebroadcast.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-// Copyright (C) 2018-2025 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include "snippets/pass/insert_movebroadcast.hpp"
-
-#include <cstddef>
-#include <memory>
-#include <utility>
-#include <vector>
-
-#include "openvino/core/except.hpp"
-#include "openvino/core/node.hpp"
-#include "openvino/core/node_output.hpp"
-#include "openvino/core/node_vector.hpp"
-#include "openvino/core/partial_shape.hpp"
-#include "openvino/core/rt_info.hpp"
-#include "openvino/core/type.hpp"
-#include "openvino/op/mod.hpp"
-#include "openvino/op/prelu.hpp"
-#include "openvino/op/squared_difference.hpp"
-#include "openvino/op/util/attr_types.hpp"
-#include "openvino/op/util/op_types.hpp"
-#include "openvino/pass/matcher_pass.hpp"
-#include "openvino/pass/pattern/matcher.hpp"
-#include "openvino/pass/pattern/op/label.hpp"
-#include "snippets/itt.hpp"
-#include "snippets/op/broadcastmove.hpp"
-#include "snippets/op/vector_buffer.hpp"
-#include "snippets/utils/utils.hpp"
-
-namespace {
-
-std::pair<ov::PartialShape, std::vector<ov::PartialShape>> get_numpy_broadcast_partial_shapes(
- const std::vector<ov::PartialShape>& input_shapes) {
- ov::PartialShape target_shape = input_shapes.front();
- for (size_t i = 1; i < input_shapes.size(); i++) {
- if (!ov::PartialShape::broadcast_merge_into(target_shape, input_shapes[i], ov::op::AutoBroadcastType::NUMPY)) {
- OPENVINO_THROW("InsertMoveBroadcast: Failed broadcast-merge input shapes");
- }
- }
- std::vector<ov::PartialShape> normalized_shapes;
- for (const auto& input : input_shapes) {
- ov::PartialShape padded_shape{input};
- padded_shape.insert(padded_shape.begin(), target_shape.size() - padded_shape.size(), 1);
- normalized_shapes.push_back(std::move(padded_shape));
- }
-
- return {target_shape, normalized_shapes};
-}
-
-} // namespace
-
-ov::Output<ov::Node> ov::snippets::pass::InsertMoveBroadcast::BroadcastNodeLastDim(
- const ov::Output<ov::Node>& value,
- const ov::PartialShape& target_shape,
- const ov::PartialShape& normalized_shape) {
- if (target_shape == value.get_partial_shape()) {
- return value;
- }
-
- // Insert BroadcastMove only if the last dimension needs to be broadcasted. Higher-level dims broadcasting
- // will be handled by pointer arithmetics inside outer LoopEmitter
- if (*target_shape.rbegin() != *normalized_shape.rbegin()) {
- const auto broadcast_node = std::make_shared<ov::snippets::op::BroadcastMove>(value, *target_shape.rbegin());
- copy_runtime_info(value.get_node_shared_ptr(), broadcast_node);
-
- return broadcast_node->output(0);
- }
-
- return value;
-}
-
-ov::snippets::pass::InsertMoveBroadcast::InsertMoveBroadcast() {
- MATCHER_SCOPE(InsertMoveBroadcast);
- ov::graph_rewrite_callback callback = [](ov::pass::pattern::Matcher& m) {
- OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::op::InsertMoveBroadcast")
- auto root = m.get_match_root();
- const auto& values = root->input_values();
- if (values.empty()) {
- return false;
- }
-
- auto is_ignored_node = [](const ov::Output<ov::Node>& v) {
- // We don't need to insert BroadcastMove after the following operations:
- // - Scalar has emitter with explicit broadcasting
- // - VectorBuffer has scalar output shape to avoid broadcast conflicts and manually shape insertion.
- return utils::is_scalar_constant(v.get_node_shared_ptr()) ||
- ov::is_type<ov::snippets::op::VectorBuffer>(v.get_node_shared_ptr());
- };
- std::vector<ov::PartialShape> input_shapes;
- std::vector<bool> is_ignored;
- for (const auto& val : values) {
- input_shapes.emplace_back(val.get_partial_shape());
- is_ignored.push_back(is_ignored_node(val));
- // Do not insert MoveBroadcast if any of the last dims is dynamic,
- // since we don't know if we really need it. In these cases, broadcasting will be performed
- // by outer Loop based on runtime shapes.
- if (!is_ignored.back() && !input_shapes.back().rbegin()->is_static()) {
- return false;
- }
- }
-
- // find the output tensor's shape, then broadcast all inputs so that they are compatible with respect to the
- // last dim
- auto bcast_shapes = get_numpy_broadcast_partial_shapes(input_shapes);
-
- ov::OutputVector broadcasted_inputs;
- for (size_t i = 0; i < values.size(); ++i) {
- if (is_ignored[i]) {
- broadcasted_inputs.push_back(values[i]);
- } else {
- auto node = BroadcastNodeLastDim(values[i], bcast_shapes.first, bcast_shapes.second[i]);
- broadcasted_inputs.push_back(node);
- }
- }
-
- auto new_args = ov::as_node_vector(broadcasted_inputs);
- for (size_t i = 0; i < new_args.size(); i++) {
- root->input(i).replace_source_output(new_args[i]->output(0));
- }
- return true;
- };
-
- // only numpy broadcast type is supported currently
- auto any = std::make_shared<ov::pass::pattern::op::Label>(
- ov::pass::pattern::any_input(),
- [](const std::shared_ptr<Node>& n) {
- // should add supports_auto_broadcast to SquaredDifference
- return ((ov::op::util::supports_auto_broadcast(n) || is_type<ov::op::v0::SquaredDifference>(n) ||
- is_type<ov::op::v1::Mod>(n)) &&
- n->get_autob().m_type == ov::op::AutoBroadcastType::NUMPY) ||
- is_type<ov::op::v0::PRelu>(n);
- });
-
- register_matcher(std::make_shared<ov::pass::pattern::Matcher>(any, matcher_name), callback);
-}
diff --git a/src/common/snippets/tests/include/pass/movebroadcast.hpp b/src/common/snippets/tests/include/pass/movebroadcast.hpp
deleted file mode 100644
index 4a02639d39d..00000000000
--- a/src/common/snippets/tests/include/pass/movebroadcast.hpp
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (C) 2025 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#pragma once
-
-#include <common_test_utils/ov_test_utils.hpp>
-
-namespace ov {
-namespace test {
-namespace snippets {
-
-class MoveBroadcastTests : public TransformationTestsF {
-protected:
- void SetUp() override;
-};
-
-} // namespace snippets
-} // namespace test
-} // namespace ov
diff --git a/src/common/snippets/tests/src/pass/movebroadcast.cpp b/src/common/snippets/tests/src/pass/movebroadcast.cpp
deleted file mode 100644
index 83583852f00..00000000000
--- a/src/common/snippets/tests/src/pass/movebroadcast.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (C) 2018-2025 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include <gtest/gtest.h>
-
-#include "openvino/op/add.hpp"
-#include "snippets/op/broadcastmove.hpp"
-#include "snippets/pass/insert_movebroadcast.hpp"
-#include "subgraph_movebroadcast.hpp"
-
-#include "pass/movebroadcast.hpp"
-
-using namespace testing;
-using namespace ov;
-
-namespace ov {
-namespace test {
-namespace snippets {
-
-void MoveBroadcastTests::SetUp() {
- TransformationTestsF::SetUp();
- manager.register_pass<::snippets::pass::InsertMoveBroadcast>();
-}
-
-TEST_F(MoveBroadcastTests, InsertBroadcastMove) {
- std::vector<PartialShape> input_shapes = {Shape{2, 3}, Shape{1, 2, 1}};
- MoveBroadcastFunction function(input_shapes);
- model = function.getOriginal();
- model_ref = function.getReference();
-}
-
-} // namespace snippets
-} // namespace test
-} // namespace ov
diff --git a/src/tests/ov_helpers/ov_snippets_models/include/subgraph_movebroadcast.hpp b/src/tests/ov_helpers/ov_snippets_models/include/subgraph_movebroadcast.hpp
deleted file mode 100644
index ecbf475b973..00000000000
--- a/src/tests/ov_helpers/ov_snippets_models/include/subgraph_movebroadcast.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2025 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-#pragma once
-
-#include "snippets_helpers.hpp"
-
-namespace ov {
-namespace test {
-namespace snippets {
-
-class MoveBroadcastFunction : public SnippetsFunctionBase {
-public:
- MoveBroadcastFunction(const std::vector<ov::PartialShape>& inputShapes,
- ov::element::Type_t precision = ov::element::f32);
-
-protected:
- std::shared_ptr<ov::Model> initOriginal() const override;
- std::shared_ptr<ov::Model> initReference() const override;
-};
-
-} // namespace snippets
-} // namespace test
-} // namespace ov
\ No newline at end of file
diff --git a/src/tests/ov_helpers/ov_snippets_models/src/subgraph_movebroadcast.cpp b/src/tests/ov_helpers/ov_snippets_models/src/subgraph_movebroadcast.cpp
deleted file mode 100644
index 6d4dda2c9df..00000000000
--- a/src/tests/ov_helpers/ov_snippets_models/src/subgraph_movebroadcast.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (C) 2025 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-//
-#include "subgraph_movebroadcast.hpp"
-
-#include "openvino/op/add.hpp"
-#include "openvino/op/parameter.hpp"
-#include "openvino/op/result.hpp"
-#include "openvino/pass/constant_folding.hpp"
-#include "snippets/op/broadcastmove.hpp"
-#include "transformations/init_node_info.hpp"
-
-namespace ov {
-namespace test {
-namespace snippets {
-
-MoveBroadcastFunction::MoveBroadcastFunction(const std::vector<ov::PartialShape>& inputShapes,
- ov::element::Type_t precision)
- : SnippetsFunctionBase(inputShapes, precision) {
- OPENVINO_ASSERT(input_shapes.size() == 2, "Got invalid number of input shapes");
-}
-
-std::shared_ptr<ov::Model> MoveBroadcastFunction::initOriginal() const {
- auto input0 = std::make_shared<ov::op::v0::Parameter>(precision, input_shapes[0]);
- auto input1 = std::make_shared<ov::op::v0::Parameter>(precision, input_shapes[1]);
- auto add = std::make_shared<ov::op::v1::Add>(input0, input1);
- auto result = std::make_shared<ov::op::v0::Result>(add);
- auto model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input0, input1});
-
- return model;
-}
-
-std::shared_ptr<ov::Model> MoveBroadcastFunction::initReference() const {
- auto ref_data0 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 3});
- auto ref_data1 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 2, 1});
- auto move1 = std::make_shared<ov::snippets::op::BroadcastMove>(ref_data1, ov::Dimension{3});
- auto add_ref = std::make_shared<ov::op::v1::Add>(ref_data0, move1);
- auto model = std::make_shared<Model>(OutputVector{add_ref}, ParameterVector{ref_data0, ref_data1});
-
- return model;
-}
-
-} // namespace snippets
-} // namespace test
-} // namespace ov
\ No newline at end of file