Skip to content

Commit 22568aa

Browse files
committed
back port fix
1 parent 3f57265 commit 22568aa

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

src/common/snippets/include/snippets/lowered/pass/insert_tail_loop.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class InsertTailLoop : public Pass {
2424
public:
2525
OPENVINO_RTTI("InsertTailLoop", "Pass")
2626
bool run(LinearIR& linear_ir) override;
27-
static LinearIR::container copy_loop(const LinearIR& linear_ir, const size_t loop_id);
27+
static LinearIR::constExprIt insert_copy_loop(LinearIR& linear_ir,
28+
const size_t loop_id,
29+
const LinearIR::constExprIt& insert_pos);
2830

2931
static constexpr size_t existing_subtensor_value = SIZE_MAX;
3032
static void propagate_updated_subtensor_through_loop(const LinearIR& linear_ir,

src/common/snippets/src/lowered/loop_manager.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,15 @@ size_t LinearIR::LoopManager::replace_with_new_loop(const LinearIR& linear_ir,
358358
for (auto expr_it = loop_begin_pos; expr_it != loop_end_pos; ++expr_it) {
359359
replace_loop_id(*expr_it, old_id, loop_id);
360360
}
361+
362+
const auto old_loop_info = this->get_loop_info(old_id);
363+
const auto old_loop_begin_pos = linear_ir.find(old_loop_info->get_entry_points().front().expr_port->get_expr());
364+
const auto old_loop_end_pos = linear_ir.find(old_loop_info->get_exit_points().back().expr_port->get_expr());
365+
// If new bounds are equal to old loop bounds, this means that old Loop is removed totally from LIR
366+
// In this case old loop info must be completely removed from loop manager
367+
if (loop_begin_pos == old_loop_begin_pos && loop_end_pos == old_loop_end_pos) {
368+
this->remove_loop_info(old_id);
369+
}
361370
return loop_id;
362371
}
363372

src/common/snippets/src/lowered/pass/insert_tail_loop.cpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ void InsertTailLoop::propagate_updated_subtensor_through_loop(const LinearIR& li
127127
(*expr_it)->updateShapes();
128128
}
129129

130-
LinearIR::container InsertTailLoop::copy_loop(const LinearIR& linear_ir, const size_t loop_id) {
130+
LinearIR::constExprIt InsertTailLoop::insert_copy_loop(LinearIR& linear_ir, const size_t loop_id, const LinearIR::constExprIt& insert_pos) {
131131
const auto& loop_manager = linear_ir.get_loop_manager();
132132
LinearIR::constExprIt loop_begin_pos, loop_end_pos;
133133
loop_manager->get_loop_bounds(linear_ir, loop_id, loop_begin_pos, loop_end_pos, true);
134134
ExressionMap expression_map;
135135
const auto& loop_copy_range = LinearIR::deep_copy_range(loop_begin_pos, std::next(loop_end_pos), expression_map);
136+
const auto new_loop_begin_pos = linear_ir.insert(insert_pos, loop_copy_range.begin(), loop_copy_range.end());
137+
const auto new_loop_end_pos = insert_pos;
136138

137139
const auto original_loop_info = loop_manager->get_loop_info(loop_id);
138140
std::vector<LinearIR::LoopManager::LoopPort> new_entry_points, new_exit_points;
@@ -156,11 +158,9 @@ LinearIR::container InsertTailLoop::copy_loop(const LinearIR& linear_ir, const s
156158
loop_manager->update_loops_port(outer_loop_ids, expr->get_output_port(i), {expr->get_output_port(i), new_expr->get_output_port(i)}, false);
157159
}
158160

159-
const auto new_loop_begin_pos = loop_copy_range.begin();
160-
const auto new_loop_end_pos = loop_copy_range.end();
161161
const auto new_id = loop_manager->replace_with_new_loop(linear_ir,
162-
std::next(new_loop_begin_pos),
163-
std::prev(new_loop_end_pos),
162+
new_loop_begin_pos,
163+
new_loop_end_pos,
164164
original_loop_info->get_work_amount(),
165165
original_loop_info->get_increment(),
166166
new_entry_points,
@@ -169,7 +169,7 @@ LinearIR::container InsertTailLoop::copy_loop(const LinearIR& linear_ir, const s
169169
const auto loop_end = ov::as_type_ptr<op::LoopEnd>(std::prev(new_loop_end_pos)->get()->get_node());
170170
OPENVINO_ASSERT(loop_end, "Cloned Loop does not contain LoopEnd op at the expected place.");
171171
loop_end->set_id(new_id);
172-
return loop_copy_range;
172+
return new_loop_begin_pos;
173173
}
174174

175175
void InsertTailLoop::create_tail_loop(LinearIR& linear_ir,
@@ -186,17 +186,16 @@ void InsertTailLoop::create_tail_loop(LinearIR& linear_ir,
186186
auto original_loop_info = loop_manager->get_loop_info(original_loop_id);
187187
auto tail_loop_info = original_loop_info;
188188
if (need_vector_loop) {
189-
const auto new_loop_range = copy_loop(linear_ir, original_loop_id);
190-
const auto new_loop_end = ov::as_type_ptr<op::LoopEnd>(std::prev(new_loop_range.end())->get()->get_node());
191-
OPENVINO_ASSERT(new_loop_end, "Cloned Loop does not contain LoopEnd op at the expected place.");
192-
tail_loop_info = original_loop_info;
193-
original_loop_info = loop_manager->get_loop_info(new_loop_end->get_id());
194-
195189
// Note: new loop body is inserted before the original loop
196190
// So new loop becomes a main vector loop, the original loop becomes tail loop
197191
// This is done in such way to have original ops from the main body at the end:
198192
// this allows us to conveniently interact with outer loops in further passes
199-
linear_ir.insert(begin, new_loop_range.begin(), new_loop_range.end());
193+
const auto new_loop_begin_pos = insert_copy_loop(linear_ir, original_loop_id, begin);
194+
const auto new_loop_begin = ov::as_type_ptr<op::LoopBegin>(new_loop_begin_pos->get()->get_node());
195+
OPENVINO_ASSERT(new_loop_begin, "Cloned Loop does not contain LoopBegin op at the expected place.");
196+
const auto new_loop_end = new_loop_begin->get_loop_end();
197+
tail_loop_info = original_loop_info;
198+
original_loop_info = loop_manager->get_loop_info(new_loop_end->get_id());
200199

201200
const auto new_vector_loop_wa = original_loop_info->get_work_amount() - tail_size;
202201
original_loop_info->set_work_amount(new_vector_loop_wa);

src/plugins/intel_cpu/src/transformations/snippets/x64/pass/lowered/brgemm_blocking.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,18 @@ bool BrgemmBlocking::run(LinearIR& linear_ir) {
160160
if (work_amount <= increment)
161161
return false;
162162

163-
auto new_loop_range = snippets::lowered::pass::InsertTailLoop::copy_loop(linear_ir, loop_id);
164-
const auto firt_iter_loop_end = ov::as_type_ptr<snippets::op::LoopEnd>(std::prev(new_loop_range.end())->get()->get_node());
163+
const auto loop_begin_it = linear_ir.find(linear_ir.get_expr_by_node(loop_end->get_loop_begin()));
164+
const auto new_loop_begin_pos =
165+
snippets::lowered::pass::InsertTailLoop::insert_copy_loop(linear_ir, loop_id, loop_begin_it);
166+
const auto new_loop_begin =
167+
ov::as_type_ptr<snippets::op::LoopBegin>(new_loop_begin_pos->get()->get_node());
168+
OPENVINO_ASSERT(new_loop_begin, "Cloned Loop does not contain LoopBegin op at the expected place.");
169+
const auto firt_iter_loop_end = new_loop_begin->get_loop_end();
165170
auto first_iter_loop_info = loop_manager->get_loop_info(firt_iter_loop_end->get_id());
166171
firt_iter_loop_end->set_work_amount(increment);
167172
first_iter_loop_info->set_work_amount(increment);
168173
firt_iter_loop_end->set_finalization_offsets(std::vector<int64_t>(loop_end->get_finalization_offsets().size(), 0));
169174

170-
const auto loop_begin_it = linear_ir.find(linear_ir.get_expr_by_node(loop_end->get_loop_begin()));
171-
linear_ir.insert(loop_begin_it, new_loop_range.begin(), new_loop_range.end());
172-
173175
const auto new_work_amount = work_amount - increment;
174176
loop_info->set_work_amount(new_work_amount);
175177
loop_end->set_work_amount(new_work_amount);

0 commit comments

Comments
 (0)