From 492f9da58a61b84eec2cdc3e1ae6dc451b744b9e Mon Sep 17 00:00:00 2001 From: chenhu-wang Date: Tue, 25 Feb 2025 14:39:53 +0800 Subject: [PATCH] exclude changes that is not relavent --- .../include/snippets/lowered/loop_manager.hpp | 5 -- .../lowered/pass/insert_tail_loop.hpp | 4 +- .../snippets/src/lowered/loop_manager.cpp | 21 +------- .../snippets/src/lowered/pass/init_loops.cpp | 49 +++++++++++-------- .../x64/pass/lowered/brgemm_blocking.cpp | 6 +-- 5 files changed, 34 insertions(+), 51 deletions(-) diff --git a/src/common/snippets/include/snippets/lowered/loop_manager.hpp b/src/common/snippets/include/snippets/lowered/loop_manager.hpp index 602f5fcd49641b..f38fab34730e0c 100644 --- a/src/common/snippets/include/snippets/lowered/loop_manager.hpp +++ b/src/common/snippets/include/snippets/lowered/loop_manager.hpp @@ -85,10 +85,6 @@ class LinearIR::LoopManager { void set_outer_splited_loop(bool outer_splited_loop); void set_first_iter_handler(FirstIterHandler handler); - // Update the parameters of existing LoopPorts - void update_entry_points(const std::function& updater); - void update_exit_points(const std::function& updater); - private: size_t m_work_amount = 0; size_t m_increment = 0; @@ -254,7 +250,6 @@ class LinearIR::LoopManager { // for `before` the new Loop is the most outer Loop void insert_loop_id(const ExpressionPtr& expr, size_t new_id, bool before = true, size_t target_id = SIZE_MAX); void insert_loop_ids(const ExpressionPtr& expr, const std::vector& new_ids, bool before = true, size_t target_id = SIZE_MAX); - static bool is_loop_id_found(const ExpressionPtr& expr, size_t id); std::map m_map = {}; size_t next_id = 0; diff --git a/src/common/snippets/include/snippets/lowered/pass/insert_tail_loop.hpp b/src/common/snippets/include/snippets/lowered/pass/insert_tail_loop.hpp index bd255339543e01..5fe8634959fb51 100644 --- a/src/common/snippets/include/snippets/lowered/pass/insert_tail_loop.hpp +++ b/src/common/snippets/include/snippets/lowered/pass/insert_tail_loop.hpp @@ -24,9 +24,7 @@ class InsertTailLoop : public Pass { public: OPENVINO_RTTI("InsertTailLoop", "Pass") bool run(LinearIR& linear_ir) override; - static LinearIR::constExprIt insert_copy_loop(LinearIR& linear_ir, - const size_t loop_id, - const LinearIR::constExprIt& insert_pos); + static LinearIR::constExprIt insert_copy_loop(LinearIR& linear_ir, const size_t loop_id, const LinearIR::constExprIt& insert_pos); static constexpr size_t existing_subtensor_value = SIZE_MAX; static void propagate_updated_subtensor_through_loop(const LinearIR& linear_ir, diff --git a/src/common/snippets/src/lowered/loop_manager.cpp b/src/common/snippets/src/lowered/loop_manager.cpp index 5920f75197ff0f..6723b115d983fc 100644 --- a/src/common/snippets/src/lowered/loop_manager.cpp +++ b/src/common/snippets/src/lowered/loop_manager.cpp @@ -141,14 +141,6 @@ void LoopInfo::set_first_iter_handler(LoopInfo::FirstIterHandler first_iter_hand m_first_iter_handler = std::move(first_iter_handler); } -void LoopInfo::update_entry_points(const std::function& updater) { - std::for_each(m_entry_points.begin(), m_entry_points.end(), updater); -} - -void LoopInfo::update_exit_points(const std::function& updater) { - std::for_each(m_exit_points.begin(), m_exit_points.end(), updater); -} - bool operator==(const LinearIR::LoopManager::LoopPort& lhs, const LinearIR::LoopManager::LoopPort& rhs) { if (&lhs == &rhs) return true; @@ -366,8 +358,7 @@ size_t LinearIR::LoopManager::replace_with_new_loop(const LinearIR& linear_ir, const size_t old_id) { const auto is_bound_explicit_loop_begin = ov::is_type(loop_begin_pos->get()->get_node()); const auto is_bound_explicit_loop_end = ov::is_type(std::prev(loop_end_pos)->get()->get_node()); - OPENVINO_ASSERT((is_bound_explicit_loop_begin && is_bound_explicit_loop_end) || - (!is_bound_explicit_loop_begin && !is_bound_explicit_loop_end), + OPENVINO_ASSERT((is_bound_explicit_loop_begin && is_bound_explicit_loop_end) || (!is_bound_explicit_loop_begin && !is_bound_explicit_loop_end), "Incorrect LoopBounds!"); const auto explicit_loop_bounds = is_bound_explicit_loop_begin && is_bound_explicit_loop_end; @@ -379,8 +370,7 @@ size_t LinearIR::LoopManager::replace_with_new_loop(const LinearIR& linear_ir, replace_loop_id(*expr_it, old_id, loop_id); } - // Check that other expression in LinearIR doesn't have the old loop ID - otherwise completely removed from loop - // manager + // Check that other expression in LinearIR doesn't have the old loop ID - otherwise completely removed from loop manager const auto old_loop_bounds = get_loop_bounds(linear_ir, old_id); // If new bounds are equal to old loop bounds, this means that old Loop is removed totally from LIR // In this case old loop info must be completely removed from loop manager @@ -560,7 +550,6 @@ void LinearIR::LoopManager::sort_loop_ports(LinearIR::constExprIt& loop_begin_po void LinearIR::LoopManager::insert_loop_id(const ExpressionPtr& expr, size_t new_id, bool before, size_t target_id) { OPENVINO_ASSERT(m_map.count(new_id) == 1, "Failed marking expression by Loop ID: the Loop with this ID hasn't registered"); - OPENVINO_ASSERT(!is_loop_id_found(expr, new_id), "Expression cannot have several the same Loop IDs"); auto& loop_ids = expr->m_loop_ids; OPENVINO_ASSERT(std::find(loop_ids.cbegin(), loop_ids.cend(), new_id) == loop_ids.cend(), "Expression cannot have several the same Loop IDs"); @@ -588,7 +577,6 @@ void LinearIR::LoopManager::insert_loop_ids(const ExpressionPtr& expr, const std void LinearIR::LoopManager::replace_loop_id(const ExpressionPtr& expr, size_t prev_id, size_t new_id) { OPENVINO_ASSERT(m_map.count(new_id), "Failed marking expression by Loop ID: the Loop with this ID hasn't registered"); - OPENVINO_ASSERT(!is_loop_id_found(expr, new_id), "Expression cannot have several the same Loop IDs"); auto& loop_ids = expr->m_loop_ids; OPENVINO_ASSERT(std::find(loop_ids.cbegin(), loop_ids.cend(), new_id) == loop_ids.cend(), "Expression already has the Loop with ID " + std::to_string(new_id)); @@ -605,11 +593,6 @@ void LinearIR::LoopManager::remove_loop_id(const ExpressionPtr& expr, size_t id) loop_ids.erase(it); } -bool LinearIR::LoopManager::is_loop_id_found(const ExpressionPtr& expr, size_t id) { - const auto loop_ids = expr->get_loop_ids(); - return std::find(loop_ids.cbegin(), loop_ids.cend(), id) != loop_ids.cend(); -} - }// namespace lowered }// namespace snippets }// namespace ov diff --git a/src/common/snippets/src/lowered/pass/init_loops.cpp b/src/common/snippets/src/lowered/pass/init_loops.cpp index 6d014142de71b5..68e8cc7757e13f 100644 --- a/src/common/snippets/src/lowered/pass/init_loops.cpp +++ b/src/common/snippets/src/lowered/pass/init_loops.cpp @@ -39,12 +39,15 @@ InitLoops::InitLoops() : Pass() {} void InitLoops::init_ptr_increments(const LinearIR::LoopManager::LoopInfoPtr& loop_info) { const auto work_amount = loop_info->get_work_amount(); + auto loop_entries = loop_info->get_entry_points(); + auto loop_exits = loop_info->get_exit_points(); - auto init_entry_port_increment = [&work_amount](LoopPort& loop_entry) { + for (auto& loop_entry : loop_entries) { loop_entry.ptr_increment = 0; if (loop_entry.is_incremented) { const auto& port = loop_entry.expr_port; const auto source = *port->get_connected_ports().begin(); + const auto loop_ids = port->get_expr()->get_loop_ids(); const auto& layout = port->get_descriptor_ptr()->get_layout(); const auto& shape = port->get_descriptor_ptr()->get_shape(); const auto& dim = *(layout.rbegin() + loop_entry.dim_idx); @@ -54,11 +57,13 @@ void InitLoops::init_ptr_increments(const LinearIR::LoopManager::LoopInfoPtr& lo loop_entry.ptr_increment = get_input_stride(dim, source.get_descriptor_ptr()->get_layout(), shape); } } - }; - auto init_exit_port_increment = [&work_amount](LoopPort& loop_exit) { + } + + for (auto& loop_exit : loop_exits) { loop_exit.ptr_increment = 0; if (loop_exit.is_incremented) { const auto& port = loop_exit.expr_port; + const auto loop_ids = port->get_expr()->get_loop_ids(); const auto& layout = port->get_descriptor_ptr()->get_layout(); const auto& shape = port->get_descriptor_ptr()->get_shape(); const auto original_dim = layout.size() - 1 - loop_exit.dim_idx; @@ -69,34 +74,38 @@ void InitLoops::init_ptr_increments(const LinearIR::LoopManager::LoopInfoPtr& lo loop_exit.ptr_increment = get_output_stride(dim, shape); } } - }; - - loop_info->update_entry_points(init_entry_port_increment); - loop_info->update_exit_points(init_exit_port_increment); + } + loop_info->set_entry_points(loop_entries); + loop_info->set_exit_points(loop_exits); } void InitLoops::init_finalization_offsets(const LinearIR::LoopManager::LoopInfoPtr& loop_info) { const auto work_amount = loop_info->get_work_amount(); - auto init_port_finalization_offset = [&work_amount](LoopPort& loop_port) { - loop_port.finalization_offset = -1 * loop_port.ptr_increment * work_amount; - }; - - loop_info->update_entry_points(init_port_finalization_offset); - loop_info->update_exit_points(init_port_finalization_offset); + auto loop_entries = loop_info->get_entry_points(); + auto loop_exits = loop_info->get_exit_points(); + for (auto& loop_entry : loop_entries) { + loop_entry.finalization_offset = -1 * loop_entry.ptr_increment * work_amount; + } + for (auto& loop_exit : loop_exits) { + loop_exit.finalization_offset = -1 * loop_exit.ptr_increment * work_amount; + } + loop_info->set_entry_points(loop_entries); + loop_info->set_exit_points(loop_exits); } void InitLoops::init_element_type_sizes(const LinearIR::LoopManager::LoopInfoPtr& loop_info) { - auto init_entry_port_data_size = [](LoopPort& loop_entry) { + auto loop_entries = loop_info->get_entry_points(); + auto loop_exits = loop_info->get_exit_points(); + for (auto& loop_entry : loop_entries) { const auto& port = loop_entry.expr_port; loop_entry.data_size = static_cast(port->get_expr()->get_node()->get_input_element_type(port->get_index()).size()); - }; - auto init_exit_port_data_size = [](LoopPort& loop_exit) { + } + for (auto& loop_exit : loop_exits) { const auto& port = loop_exit.expr_port; loop_exit.data_size = static_cast(port->get_expr()->get_node()->get_output_element_type(port->get_index()).size()); - }; - - loop_info->update_entry_points(init_entry_port_data_size); - loop_info->update_exit_points(init_exit_port_data_size); + } + loop_info->set_entry_points(loop_entries); + loop_info->set_exit_points(loop_exits); } bool InitLoops::run(LinearIR& linear_ir) { diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/brgemm_blocking.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/brgemm_blocking.cpp index cf6752c8fb67e3..5a6236d1916b13 100644 --- a/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/brgemm_blocking.cpp +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/brgemm_blocking.cpp @@ -161,10 +161,8 @@ bool BrgemmBlocking::run(LinearIR& linear_ir) { return false; const auto loop_begin_it = linear_ir.find(linear_ir.get_expr_by_node(loop_end->get_loop_begin())); - const auto new_loop_begin_pos = - snippets::lowered::pass::InsertTailLoop::insert_copy_loop(linear_ir, loop_id, loop_begin_it); - const auto new_loop_begin = - ov::as_type_ptr(new_loop_begin_pos->get()->get_node()); + const auto new_loop_begin_pos = snippets::lowered::pass::InsertTailLoop::insert_copy_loop(linear_ir, loop_id, loop_begin_it); + const auto new_loop_begin = ov::as_type_ptr(new_loop_begin_pos->get()->get_node()); OPENVINO_ASSERT(new_loop_begin, "Cloned Loop does not contain LoopBegin op at the expected place."); const auto firt_iter_loop_end = new_loop_begin->get_loop_end(); auto first_iter_loop_info = loop_manager->get_loop_info(firt_iter_loop_end->get_id());