Skip to content

Commit

Permalink
Eltwise cases are OK: run memory access ops updates in both cases
Browse files Browse the repository at this point in the history
  • Loading branch information
v-Golubev committed Nov 12, 2023
1 parent 04ea871 commit f546fbd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class DefaultTailLoopHandler : public SpecificIterHandler {
bool copy_body_modification(LinearIR::constExprIt begin, LinearIR::constExprIt end) const override;
bool need_to_modify_main_loop(const std::shared_ptr<ov::snippets::op::LoopEnd>& loop_end) const override;
bool need_to_copy_loop(const std::shared_ptr<ov::snippets::op::LoopEnd>& loop_end) const override;

private:
void update_memory_access_ops(LinearIR::constExprIt begin, LinearIR::constExprIt end, size_t tail_size) const;
};
} // namespace lowered
} // namespace snippets
Expand Down
20 changes: 13 additions & 7 deletions src/common/snippets/src/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ void Generator::generate(lowered::LinearIR& linear_ir, LoweringResult& result, c
std::function<opRegType(const std::shared_ptr<Node>& op)> reg_type_mapper = [&](const std::shared_ptr<Node>& op) -> opRegType {
return get_op_reg_type(op);
};
lowered::pass::PassPipeline pre_pipeline;
pre_pipeline.register_pass<lowered::pass::AssignRegisters>(reg_type_mapper);
pre_pipeline.run(linear_ir);

// auto clone = *linear_ir.clone();
// lowered::pass::PassPipeline reference_pipeline;
// reference_pipeline.register_pass<lowered::pass::InsertTailLoop>();
// reference_pipeline.run(clone);
// clone.serialize("/home/vgolubev/models/specific_iteration_reference.xml", "");

lowered::pass::PassPipeline lowered_pipeline;
lowered_pipeline.register_pass<lowered::pass::AssignRegisters>(reg_type_mapper);
// lowered_pipeline.register_pass<lowered::pass::InsertTailLoop>();
lowered_pipeline.register_pass<lowered::pass::InsertSpecificIterations>();
lowered_pipeline.register_pass<lowered::pass::CleanupLoopOffsets>();
lowered_pipeline.register_pass<lowered::pass::OptimizeLoopSingleEvaluation>();
std::cout << "before\n";
// lowered_pipeline.register_pass<lowered::pass::CleanupLoopOffsets>();
// lowered_pipeline.register_pass<lowered::pass::OptimizeLoopSingleEvaluation>();
lowered_pipeline.run(linear_ir);
std::cout << "after\n";
linear_ir.serialize("specific_iteration.xml", "");
linear_ir.serialize("/home/vgolubev/models/specific_iteration.xml", "");
linear_ir.init_emitters(target);

OV_ITT_TASK_NEXT(GENERATE, "::EmitCode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool InsertSpecificIterations::run(LinearIR& linear_ir) {
// We can't skip tail loop because we need to handle inner loops of the tail loop
auto call_handlers = [&](const std::vector<SpecificIterHandlerPtr>& handlers,
SpecificIterHandler::Mode mode,
const bool need_to_copy) {
bool need_to_copy) {
LinearIR::container copied_body;
if (need_to_copy) {
copied_body = copy_loop(linear_ir, loop_end->get_id());
Expand All @@ -100,11 +100,11 @@ bool InsertSpecificIterations::run(LinearIR& linear_ir) {
return handler->need_to_copy_loop(loop_end);
};
// TODO: handlers must be taken from loop info
std::vector<SpecificIterHandlerPtr> first_iter_handlers{};
// std::vector<SpecificIterHandlerPtr> first_iter_handlers{};
std::vector<SpecificIterHandlerPtr> last_iter_handlers{std::make_shared<DefaultTailLoopHandler>(linear_ir)};
const bool copy_first_iter = std::any_of(first_iter_handlers.begin(), first_iter_handlers.end(), need_copy);
// const bool copy_first_iter = std::any_of(first_iter_handlers.begin(), first_iter_handlers.end(), need_copy);
const bool copy_last_iter = std::any_of(last_iter_handlers.begin(), last_iter_handlers.end(), need_copy);
call_handlers(first_iter_handlers, SpecificIterHandler::FIRST_ITERATION, copy_first_iter);
// call_handlers(first_iter_handlers, SpecificIterHandler::FIRST_ITERATION, copy_first_iter);
call_handlers(last_iter_handlers, SpecificIterHandler::LAST_ITERATION, copy_last_iter);
std::cout << "Specific iter handlers called for node " << loop_end << std::endl;
}
Expand Down
13 changes: 10 additions & 3 deletions src/common/snippets/src/lowered/pass/iter_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ namespace lowered {
bool DefaultTailLoopHandler::need_to_modify_main_loop(const std::shared_ptr<ov::snippets::op::LoopEnd>& loop_end) const {
const auto work_amount = loop_end->get_work_amount();
const auto increment = loop_end->get_increment();
return work_amount >= increment && work_amount % increment != 0;
return work_amount % increment != 0;
}

bool DefaultTailLoopHandler::need_to_copy_loop(const std::shared_ptr<ov::snippets::op::LoopEnd>& loop_end) const {
const auto work_amount = loop_end->get_work_amount();
const auto increment = loop_end->get_increment();
return work_amount >= increment;
return work_amount > increment && work_amount % increment != 0;
}

bool DefaultTailLoopHandler::main_body_modification(LinearIR::constExprIt begin, LinearIR::constExprIt end) const {
Expand All @@ -38,7 +38,7 @@ bool DefaultTailLoopHandler::main_body_modification(LinearIR::constExprIt begin,

const auto& loop_manager = get_linear_ir().get_loop_manager();
const auto& loop_info = loop_manager->get_loop_info(loop_end->get_id());
if (work_amount >= increment) {
if (work_amount > increment) {
loop_end->set_work_amount(work_amount - tail_size);
loop_end->set_finalization_offsets(std::vector<int64_t>(loop_end->get_finalization_offsets().size(), 0));
loop_info->set_work_amount(work_amount - tail_size);
Expand All @@ -47,7 +47,9 @@ bool DefaultTailLoopHandler::main_body_modification(LinearIR::constExprIt begin,
loop_end->set_increment(tail_size);
loop_info->set_work_amount(tail_size);
loop_info->set_increment(tail_size);
update_memory_access_ops(begin, end, tail_size);
}
return true;
}

bool DefaultTailLoopHandler::copy_body_modification(LinearIR::constExprIt begin, LinearIR::constExprIt end) const {
Expand All @@ -66,6 +68,11 @@ bool DefaultTailLoopHandler::copy_body_modification(LinearIR::constExprIt begin,
loop_info->set_work_amount(tail_size);
loop_info->set_increment(tail_size);

update_memory_access_ops(begin, end, tail_size);
return true;
}

void DefaultTailLoopHandler::update_memory_access_ops(LinearIR::constExprIt begin, LinearIR::constExprIt end, size_t tail_size) const {
for (auto expr_it = std::next(begin); expr_it != end; expr_it++) {
// Skip inner Loops
const auto loop_begin = ov::as_type_ptr<op::LoopBegin>(expr_it->get()->get_node());
Expand Down

0 comments on commit f546fbd

Please sign in to comment.