-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LIR] OptimizeLoopSingleEvaluation moved to a separate pass
- Loading branch information
Showing
8 changed files
with
118 additions
and
65 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/common/snippets/include/snippets/lowered/pass/optimize_loop_single_evaluation.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "pass.hpp" | ||
|
||
namespace ov { | ||
namespace snippets { | ||
namespace lowered { | ||
namespace pass { | ||
|
||
/** | ||
* @interface OptimizeLoopSingleEvaluation | ||
* @brief Does the following optimizations if the Loop body can be executed only once: | ||
* - sets evaluate_once parameter to true | ||
* - moves all ptr arithmetic to finalization offsets | ||
* @ingroup snippets | ||
*/ | ||
class OptimizeLoopSingleEvaluation : public Pass { | ||
public: | ||
OPENVINO_RTTI("OptimizeLoopSingleEvaluation", "Pass") | ||
bool run(LinearIR& linear_ir) override; | ||
}; | ||
|
||
} // namespace pass | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/common/snippets/src/lowered/pass/optimize_loop_single_evaluation.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "snippets/lowered/pass/optimize_loop_single_evaluation.hpp" | ||
|
||
#include "snippets/lowered/linear_ir.hpp" | ||
#include "snippets/snippets_isa.hpp" | ||
#include "snippets/itt.hpp" | ||
|
||
namespace ov { | ||
namespace snippets { | ||
namespace lowered { | ||
namespace pass { | ||
|
||
bool OptimizeLoopSingleEvaluation::run(LinearIR& linear_ir) { | ||
OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::OptimizeLoopSingleEvaluation") | ||
if (linear_ir.empty()) | ||
return false; | ||
|
||
bool is_modified = false; | ||
for (auto expr_it = linear_ir.begin(); expr_it != linear_ir.end(); expr_it++) { | ||
if (auto loop_end = ov::as_type_ptr<op::LoopEnd>(expr_it->get()->get_node())) { | ||
// *1* solo vector/tail loop + empty outer loop | ||
// => skip increments (both counter & ptr) : set evaluate_once flag | ||
// *2* solo vector/tail loop + non-empty outer loop | ||
// => skip counter increments but perform ptr increments : set evaluate_once, | ||
// and perform pointer increments through finalization offsets | ||
// *3* vector loop(s) + one tail loop | ||
// => vector as usual, tail depends on outer loop, see *1* and *2* | ||
if (loop_end->get_work_amount() >= 2 * loop_end->get_increment()) | ||
continue; | ||
|
||
auto new_finalization_offsets = loop_end->get_finalization_offsets(); | ||
const auto& ptr_increments = loop_end->get_ptr_increments(); | ||
const auto work_amount_incr = static_cast<int64_t>(loop_end->get_increment()); | ||
for (size_t i = 0; i < new_finalization_offsets.size(); i++) { | ||
new_finalization_offsets[i] += ptr_increments[i] * work_amount_incr; | ||
} | ||
loop_end->set_finalization_offsets(new_finalization_offsets); | ||
loop_end->set_ptr_increments(std::vector<int64_t>(new_finalization_offsets.size(), 0)); | ||
loop_end->set_evaluate_once(true); | ||
is_modified = true; | ||
} | ||
} | ||
return is_modified; | ||
} | ||
|
||
} // namespace pass | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ov | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters