OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[Snippets] Support multiple consumers for Scalar operation (#30275)
Arseniy Obolenskiydc0eed8ed769
diff --git a/src/common/snippets/src/lowered/pass/move_scalar_to_consumer.cpp b/src/common/snippets/src/lowered/pass/move_scalar_to_consumer.cppindex 60274798b2e..6fac8eaaced 100644--- a/src/common/snippets/src/lowered/pass/move_scalar_to_consumer.cpp+++ b/src/common/snippets/src/lowered/pass/move_scalar_to_consumer.cpp@@ -26,9 +26,17 @@ bool MoveScalarToConsumer::run(LinearIR& linear_ir) {const auto expr = expr_it->get();if (ov::is_type<op::Scalar>(expr->get_node())) {const auto consumers = expr->get_output_port_connector(0)->get_consumers();- OPENVINO_ASSERT(consumers.size() == 1, "Scalar expression is expected to have a single consumer");+ OPENVINO_ASSERT(!consumers.empty(), "Scalar expression should have at least one consumer");+ auto consumer_expr = consumers.begin()->get_expr();+ const auto& loop_ids = consumer_expr->get_loop_ids();+ for (const auto& consumer : consumers) {+ OPENVINO_ASSERT(consumer.get_expr()->get_loop_ids() == loop_ids,+ "All consumers of a Scalar expression are expected to have the same loop IDs");+ if (consumer.get_expr()->get_exec_num() < consumer_expr->get_exec_num()) {+ consumer_expr = consumer.get_expr();+ }+ }- const auto& consumer_expr = consumers.begin()->get_expr();// Move something only if// - Consumer is not already the next one (previous since the iterator is a reverse one)// - The next operation is not already a Scalar (since it was just moved there on the previous iteration)diff --git a/src/common/snippets/tests/src/lowered/pass/move_scalar_to_consumer.cpp b/src/common/snippets/tests/src/lowered/pass/move_scalar_to_consumer.cppnew file mode 100644index 00000000000..9e8f2993f80--- /dev/null+++ b/src/common/snippets/tests/src/lowered/pass/move_scalar_to_consumer.cpp@@ -0,0 +1,43 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "lir_test_utils.hpp"++#include "openvino/opsets/opset10.hpp"+#include "snippets/lowered/pass/move_scalar_to_consumer.hpp"+#include "snippets/op/load.hpp"+#include "snippets/op/store.hpp"+#include "snippets/op/scalar.hpp"++namespace ov {+namespace test {+namespace snippets {++using namespace ov::snippets::lowered;+using namespace ov::snippets::lowered::pass;++TEST_F(LoweredPassTestsF, MoveScalarToConsumer) {+ const auto input_precision = ov::element::i8;+ const ov::Shape scalar_shape{1};+ {+ auto relu_scalar = linear_ir->push_node<ov::snippets::op::Scalar>(input_precision, scalar_shape, 0.f);+ auto add_scalar = linear_ir->push_node<ov::snippets::op::Scalar>(input_precision, scalar_shape, 42.f);+ auto relu = linear_ir->push_node<ov::opset10::Relu>(relu_scalar.second);+ auto add1 = linear_ir->push_node<ov::opset10::Add>(add_scalar.second, add_scalar.second);+ auto add2 = linear_ir->push_node<ov::opset10::Add>(add1.second, add_scalar.second);+ auto result = linear_ir->push_node<ov::opset10::Result>(add2.second);+ }+ pipeline.register_pass<MoveScalarToConsumer>();+ {+ auto relu_scalar = linear_ir_ref->push_node<ov::snippets::op::Scalar>(input_precision, scalar_shape, 0.f);+ auto relu = linear_ir_ref->push_node<ov::opset10::Relu>(relu_scalar.second);+ auto add_scalar = linear_ir_ref->push_node<ov::snippets::op::Scalar>(input_precision, scalar_shape, 42.f);+ auto add1 = linear_ir_ref->push_node<ov::opset10::Add>(add_scalar.second, add_scalar.second);+ auto add2 = linear_ir_ref->push_node<ov::opset10::Add>(add1.second, add_scalar.second);+ auto result = linear_ir_ref->push_node<ov::opset10::Result>(add2.second);+ }+}+} // namespace snippets+} // namespace test+} // namespace ov