Skip to content

Commit

Permalink
exclude changes that is not relavent
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhu-wang committed Feb 25, 2025
1 parent cb45c6d commit 492f9da
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 51 deletions.
5 changes: 0 additions & 5 deletions src/common/snippets/include/snippets/lowered/loop_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(LoopPort&)>& updater);
void update_exit_points(const std::function<void(LoopPort&)>& updater);

private:
size_t m_work_amount = 0;
size_t m_increment = 0;
Expand Down Expand Up @@ -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<size_t>& 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<size_t, LoopInfoPtr> m_map = {};
size_t next_id = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 2 additions & 19 deletions src/common/snippets/src/lowered/loop_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(LoopPort&)>& updater) {
std::for_each(m_entry_points.begin(), m_entry_points.end(), updater);
}

void LoopInfo::update_exit_points(const std::function<void(LoopPort&)>& 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;
Expand Down Expand Up @@ -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<op::LoopBegin>(loop_begin_pos->get()->get_node());
const auto is_bound_explicit_loop_end = ov::is_type<op::LoopEnd>(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;

Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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));
Expand All @@ -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
49 changes: 29 additions & 20 deletions src/common/snippets/src/lowered/pass/init_loops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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<int64_t>(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<int64_t>(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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<snippets::op::LoopBegin>(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<snippets::op::LoopBegin>(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());
Expand Down

0 comments on commit 492f9da

Please # to comment.