diff --git a/src/common/snippets/src/pass/insert_loops.cpp b/src/common/snippets/src/pass/insert_loops.cpp index 7d513239765f87..4ed2b5b20374e4 100644 --- a/src/common/snippets/src/pass/insert_loops.cpp +++ b/src/common/snippets/src/pass/insert_loops.cpp @@ -71,7 +71,7 @@ void insert_explicitly_loops(const ov::NodeVector& ops, const ov::PartialShape& auto add_body_results = [](const std::shared_ptr& op, std::vector>& body_results) { for (auto output : op->outputs()) { for (auto target_input : output.get_target_inputs()) { - auto child = target_input.get_node()->shared_from_this(); + auto child = target_input.get_node(); if (ov::is_type(child) || ov::is_type(child) || ov::is_type(child) || @@ -111,8 +111,10 @@ void insert_explicitly_loops(const ov::NodeVector& ops, const ov::PartialShape& [](const ov::Input& in) { return in.get_partial_shape(); }); auto body_master_shape = body_shapes.front(); - for (const auto& shape : body_shapes) - PartialShape::broadcast_merge_into(body_master_shape, shape, ::ngraph::op::AutoBroadcastType::NUMPY); + for (const auto& shape : body_shapes) { + NGRAPH_CHECK(PartialShape::broadcast_merge_into(body_master_shape, shape, ::ngraph::op::AutoBroadcastType::NUMPY), + "Loop input and output must be numpy broadcastable"); + } const auto inner_work_amount = utils::get_inner_dim(body_master_shape).get_length(); const auto outer_work_amount = utils::get_outer_dim(body_master_shape).get_length(); diff --git a/src/common/snippets/src/pass/reset_buffer.cpp b/src/common/snippets/src/pass/reset_buffer.cpp index 26542d7d9980c8..4d0b5d6869dd9c 100644 --- a/src/common/snippets/src/pass/reset_buffer.cpp +++ b/src/common/snippets/src/pass/reset_buffer.cpp @@ -39,8 +39,7 @@ ngraph::snippets::pass::ResetBufferState::ResetBufferState() { // MatMul doesn't change Buffer memory pointer after execution auto m_loop_end = ngraph::pattern::wrap_type(); - register_matcher(std::make_shared(m_loop_end, matcher_name), - [=](ngraph::pattern::Matcher &m) { + auto callback = [=](ngraph::pattern::Matcher &m) { OV_ITT_SCOPED_TASK(ngraph::pass::itt::domains::SnippetsTransform, "Snippets::op::ResetBufferState") auto& pattern_to_output = m.get_pattern_value_map(); @@ -82,7 +81,7 @@ ngraph::snippets::pass::ResetBufferState::ResetBufferState() { for (size_t i = 0; i < o_size; ++i) { const auto result_shape = body_shapes[i_size + i].get_shape(); // check for first target input is enough for Buffer searching because operations can have only single Buffer per each output port as op - const auto consumer = loop_end->output(i).get_target_inputs().begin()->get_node()->shared_from_this(); + const auto consumer = loop_end->output(i).get_target_inputs().begin()->get_node(); if (ov::is_type(consumer)) { // To calculate finalization offset we should know index of nesting Loop auto loop_index = 0lu; @@ -108,5 +107,8 @@ ngraph::snippets::pass::ResetBufferState::ResetBufferState() { loop_end->set_ptr_increments(ptr_increments); return true; - }); + }; + + auto m = std::make_shared(m_loop_end, matcher_name); + register_matcher(m, callback); } diff --git a/src/common/snippets/src/pass/set_buffer_offset.cpp b/src/common/snippets/src/pass/set_buffer_offset.cpp index 07ef1d416527c8..6c72ab7df27c08 100644 --- a/src/common/snippets/src/pass/set_buffer_offset.cpp +++ b/src/common/snippets/src/pass/set_buffer_offset.cpp @@ -13,9 +13,10 @@ ngraph::snippets::pass::SetBufferOffset::SetBufferOffset() { MATCHER_SCOPE(SetBufferOffset); - register_matcher(std::make_shared( - ngraph::pattern::wrap_type(), matcher_name), - [&](ngraph::pattern::Matcher &m) { + + auto m_buffer = ngraph::pattern::wrap_type(); + + auto callback = [&](ngraph::pattern::Matcher &m) { OV_ITT_SCOPED_TASK(ngraph::pass::itt::domains::SnippetsTransform, "Snippets::op::SetBufferOffset") auto root = m.get_match_root(); const auto buffer = ov::as_type_ptr(root); @@ -29,7 +30,7 @@ ngraph::snippets::pass::SetBufferOffset::SetBufferOffset() { { auto parent = buffer->get_input_node_shared_ptr(0); auto idx = buffer->input(0).get_source_output().get_index(); - while (std::dynamic_pointer_cast(parent) != nullptr) { + while (std::dynamic_pointer_cast(parent)) { const auto source_output = parent->input_value(idx); parent = source_output.get_node_shared_ptr(); idx = source_output.get_index(); @@ -75,5 +76,8 @@ ngraph::snippets::pass::SetBufferOffset::SetBufferOffset() { current_offset += buffer->get_byte_size(); return true; - }); + }; + + auto m = std::make_shared(m_buffer, matcher_name); + register_matcher(m, callback); } diff --git a/src/common/snippets/src/pass/softmax_decomposition.cpp b/src/common/snippets/src/pass/softmax_decomposition.cpp index fb5ece8c363b1c..2dd4573edc2b25 100644 --- a/src/common/snippets/src/pass/softmax_decomposition.cpp +++ b/src/common/snippets/src/pass/softmax_decomposition.cpp @@ -20,9 +20,10 @@ ngraph::snippets::pass::SoftmaxDecomposition::SoftmaxDecomposition(const size_t vector_size, const int32_t buffer_allocation_rank) { MATCHER_SCOPE(SoftmaxDecomposition); - register_matcher(std::make_shared( - ngraph::pattern::wrap_type(), matcher_name), - [this, vector_size, buffer_allocation_rank](ngraph::pattern::Matcher &m) { + + auto m_softmax = ngraph::pattern::wrap_type(); + + auto callback = [=](ngraph::pattern::Matcher &m) { OV_ITT_SCOPED_TASK(ngraph::pass::itt::domains::SnippetsTransform, "Snippets::op::SoftmaxDecomposition") auto root = m.get_match_root(); const auto master_pshape = root->get_input_partial_shape(0); @@ -39,7 +40,7 @@ ngraph::snippets::pass::SoftmaxDecomposition::SoftmaxDecomposition(const size_t return false; } - const auto shape_rank = static_cast(rank.get_length()); + const auto shape_rank = rank.get_length(); if (axis != shape_rank - 1) return false; @@ -186,5 +187,8 @@ ngraph::snippets::pass::SoftmaxDecomposition::SoftmaxDecomposition(const size_t /* =========================================== */ return true; - }); + }; + + auto m = std::make_shared(m_softmax, matcher_name); + register_matcher(m, callback); } diff --git a/src/common/snippets/tests/src/pass/softmax_reshape_elimination.cpp b/src/common/snippets/tests/src/pass/softmax_reshape_elimination.cpp index 3f2f731c781331..c66ecce050707a 100644 --- a/src/common/snippets/tests/src/pass/softmax_reshape_elimination.cpp +++ b/src/common/snippets/tests/src/pass/softmax_reshape_elimination.cpp @@ -17,8 +17,7 @@ using namespace testing; using namespace ngraph; -TEST(TransformationTests, SoftmaxV1ReshapeElimination) { - std::shared_ptr f(nullptr), f_ref(nullptr); +TEST_F(TransformationTestsF, SoftmaxV1ReshapeElimination) { { auto data = std::make_shared(element::f32, Shape{2, 3, 240}); auto shape0 = std::make_shared(ov::element::i32, ov::Shape{2}, std::vector{6, 240}); @@ -26,26 +25,19 @@ TEST(TransformationTests, SoftmaxV1ReshapeElimination) { auto softmax_v1 = std::make_shared(reshape0, 1); auto shape1 = std::make_shared(ov::element::i32, ov::Shape{3}, std::vector{2, 3, 240}); auto reshape1 = std::make_shared(softmax_v1, shape1, false); - f = std::make_shared(NodeVector{reshape1}, ParameterVector{data}); + function = std::make_shared(NodeVector{reshape1}, ParameterVector{data}); - pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(f); - ASSERT_NO_THROW(check_rt_info(f)); + manager.register_pass(); + manager.register_pass(); } { auto data = std::make_shared(element::f32, Shape{2, 3, 240}); auto softmax_v1 = std::make_shared(data, 2); - f_ref = std::make_shared(NodeVector{softmax_v1}, ParameterVector{data}); + function_ref = std::make_shared(NodeVector{softmax_v1}, ParameterVector{data}); } - - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; } -TEST(TransformationTests, SoftmaxV8ReshapeElimination) { - std::shared_ptr f(nullptr), f_ref(nullptr); +TEST_F(TransformationTestsF, SoftmaxV8ReshapeElimination) { { auto data = std::make_shared(element::f32, Shape{1, 2, 340, 240}); auto shape0 = std::make_shared(ov::element::i32, ov::Shape{2}, std::vector{680, 240}); @@ -53,26 +45,20 @@ TEST(TransformationTests, SoftmaxV8ReshapeElimination) { auto softmax_v1 = std::make_shared(reshape0, -1); auto shape1 = std::make_shared(ov::element::i32, ov::Shape{4}, std::vector{1, 2, 340, 240}); auto reshape1 = std::make_shared(softmax_v1, shape1, false); - f = std::make_shared(NodeVector{reshape1}, ParameterVector{data}); + function = std::make_shared(NodeVector{reshape1}, ParameterVector{data}); - pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(f); - ASSERT_NO_THROW(check_rt_info(f)); + manager.register_pass(); + manager.register_pass(); } { auto data = std::make_shared(element::f32, Shape{1, 2, 340, 240}); auto softmax_v1 = std::make_shared(data, 3); - f_ref = std::make_shared(NodeVector{softmax_v1}, ParameterVector{data}); + function_ref =std::make_shared(NodeVector{softmax_v1}, ParameterVector{data}); } - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; } -TEST(TransformationTests, SoftmaxReshapeElimination_IncorrectReshape) { - std::shared_ptr f(nullptr), f_ref(nullptr); +TEST_F(TransformationTestsF, SoftmaxReshapeElimination_IncorrectReshape) { { auto data = std::make_shared(element::f32, Shape{1, 2, 340, 240}); auto shape0 = std::make_shared(ov::element::i32, ov::Shape{2}, std::vector{2, 81600}); @@ -80,13 +66,10 @@ TEST(TransformationTests, SoftmaxReshapeElimination_IncorrectReshape) { auto softmax_v1 = std::make_shared(reshape0, -1); auto shape1 = std::make_shared(ov::element::i32, ov::Shape{4}, std::vector{1, 2, 340, 240}); auto reshape1 = std::make_shared(softmax_v1, shape1, false); - f = std::make_shared(NodeVector{reshape1}, ParameterVector{data}); + function = std::make_shared(NodeVector{reshape1}, ParameterVector{data}); - pass::Manager m; - m.register_pass(); - m.register_pass(); - m.run_passes(f); - ASSERT_NO_THROW(check_rt_info(f)); + manager.register_pass(); + manager.register_pass(); } { auto data = std::make_shared(element::f32, Shape{1, 2, 340, 240}); @@ -95,9 +78,6 @@ TEST(TransformationTests, SoftmaxReshapeElimination_IncorrectReshape) { auto softmax_v1 = std::make_shared(reshape0, -1); auto shape1 = std::make_shared(ov::element::i32, ov::Shape{4}, std::vector{1, 2, 340, 240}); auto reshape1 = std::make_shared(softmax_v1, shape1, false); - f_ref = std::make_shared(NodeVector{reshape1}, ParameterVector{data}); + function_ref =std::make_shared(NodeVector{reshape1}, ParameterVector{data}); } - - auto res = compare_functions(f, f_ref); - ASSERT_TRUE(res.first) << res.second; }