Skip to content

Commit

Permalink
[Snippets] Refactoring of transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
a-sidorova committed Apr 17, 2023
1 parent edd1216 commit 9e45f70
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ namespace lowered {
namespace pass {

/**
* @interface BufferAllocation
* @interface AllocateBuffers
* @brief The pass calculation common size of buffer scratchpad and propagates Buffer offsets to connected MemoryAccess operations.
* @ingroup snippets
*/

class BufferAllocation : public Transformation {
class AllocateBuffers : public Transformation {
public:
OPENVINO_RTTI("BufferAllocation", "Transformation")
OPENVINO_RTTI("AllocateBuffers", "Transformation")
bool run(lowered::LinearIR& linear_ir) override;

size_t get_scratchpad_size() const { return m_buffer_scratchpad_size; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace lowered {
namespace pass {

/**
* @interface LoopFusion
* @interface FuseLoops
* @brief The pass fuses marking Loops.
* @ingroup snippets
*/
class LoopFusion : public Transformation {
class FuseLoops : public Transformation {
public:
OPENVINO_RTTI("LoopFusion", "Transformation")
LoopFusion();
OPENVINO_RTTI("FuseLoops", "Transformation")
FuseLoops();
bool run(LinearIR& linear_ir) override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace lowered {
namespace pass {

/**
* @interface BufferIdentification
* @interface IdentifyBuffers
* @brief The pass set identifiers for Buffers in common Buffer system.
* The buffers with the same identifier has the same data register.
* The pass uses greedy graph coloring algorithm using adjacency matrix:
Expand All @@ -26,10 +26,10 @@ namespace pass {
* Note: should be called before ResetBuffer() pass to have correct offsets
* @ingroup snippets
*/
class BufferIdentification: public Transformation {
class IdentifyBuffers: public Transformation {
public:
OPENVINO_RTTI("BufferIdentification", "Transformation")
BufferIdentification() = default;
OPENVINO_RTTI("IdentifyBuffers", "Transformation")
IdentifyBuffers() = default;

bool run(LinearIR& linear_ir) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace lowered {
namespace pass {

/**
* @interface LoopInit
* @interface InitLoops
* @brief The pass explicitly insert LoadBegin and LoadEnd in Linear IR using Loop markup
* @ingroup snippets
*/
class LoopInit : public Transformation {
class InitLoops : public Transformation {
public:
OPENVINO_RTTI("InsertLoops", "Transformation")
LoopInit();
InitLoops();
bool run(LinearIR& linear_ir) override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ namespace lowered {
namespace pass {

/**
* @interface BufferInsertion
* @interface InsertBuffers
* @brief The pass inserts Buffer between exit points of one loop (or Brgemm) and
* entry points of another loop (or Brgemm) to store intermediate data.
* The pass should be called after LoopFusion.
* The pass should be called after FuseLoops.
* @param m_buffer_allocation_rank - rank of shape for memory allocation: shape[shape_rank - normalize(m_allocation_rank) : shape_rank]
* @ingroup snippets
*/
class BufferInsertion : public Transformation {
class InsertBuffers : public Transformation {
public:
OPENVINO_RTTI("BufferInsertion", "Transformation")
BufferInsertion(int32_t buffer_allocation_rank);
OPENVINO_RTTI("InsertBuffers", "Transformation")
InsertBuffers(int32_t buffer_allocation_rank);
bool run(LinearIR& linear_ir) override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ namespace lowered {
namespace pass {

/**
* @interface LoadStoreInsertion
* @interface InsertLoadStore
* @brief The pass inserts Load and Store expressions in Linear IR after Parameters, Buffers and before Results, Buffers accordingly.
* Note: The pass should be called after LoopFusion and BufferInsertion passes to have all possible data expressions.
* Note: The pass should be called after FuseLoops and InsertBuffers passes to have all possible data expressions.
* @param m_vector_size - the count of elements for loading/storing
* @ingroup snippets
*/
class LoadStoreInsertion : public Transformation {
class InsertLoadStore : public Transformation {
public:
explicit LoadStoreInsertion(size_t vector_size);
OPENVINO_RTTI("LoadStoreInsertion", "Transformation")
explicit InsertLoadStore(size_t vector_size);
OPENVINO_RTTI("InsertLoadStore", "Transformation")
bool run(LinearIR& linear_ir) override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ namespace lowered {
namespace pass {

/**
* @interface LoopMarkup
* @interface MarkLoops
* @brief The pass marks expressions with Loop IDs.
* The pass iterates expression by expression till the following conditions:
* - the layouts and subtensors them are the same
* - the consumer of the expression is explicitly after this expression - the pass marks the branches
* @ingroup snippets
*/
class LoopMarkup : public Transformation {
class MarkLoops : public Transformation {
public:
OPENVINO_RTTI("LoopMarkup", "Transformation")
LoopMarkup(size_t vector_size);
OPENVINO_RTTI("MarkLoops", "Transformation")
MarkLoops(size_t vector_size);
bool run(LinearIR& linear_ir) override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace lowered {
namespace pass {

/**
* @interface BufferReset
* @interface ResetBuffers
* @brief The pass `fuses` (reset) ptr increments and finalization offsets for ports of Loop
* with the same Buffers (with the same ID) to avoid double ptr shifts
* Note: Buffer always employ inplace logics by default. It means that if a loop has both
Expand All @@ -21,10 +21,10 @@ namespace pass {
* This condition should be removed when Buffers stop being inplace by default.
* @ingroup snippets
*/
class BufferReset: public Transformation {
class ResetBuffers: public Transformation {
public:
OPENVINO_RTTI("BufferReset", "Transformation")
BufferReset() = default;
OPENVINO_RTTI("ResetBuffers", "Transformation")
ResetBuffers() = default;

bool run(LinearIR& linear_ir) override;

Expand Down
36 changes: 18 additions & 18 deletions src/common/snippets/src/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
#include "snippets/lowered/linear_ir.hpp"
#include "snippets/lowered/pass/assign_registers.hpp"
#include "snippets/lowered/pass/insert_tail_loop.hpp"
#include "snippets/lowered/pass/loop_markup.hpp"
#include "snippets/lowered/pass/loop_fusion.hpp"
#include "snippets/lowered/pass/loop_init.hpp"
#include "snippets/lowered/pass/buffer_insertion.hpp"
#include "snippets/lowered/pass/load_store_insertion.hpp"
#include "snippets/lowered/pass/mark_loops.hpp"
#include "snippets/lowered/pass/fuse_loops.hpp"
#include "snippets/lowered/pass/init_loops.hpp"
#include "snippets/lowered/pass/insert_buffers.hpp"
#include "snippets/lowered/pass/insert_load_store.hpp"
#include "snippets/lowered/pass/vector_to_scalar.hpp"
#include "snippets/lowered/pass/load_movebroadcast_to_broadcastload.hpp"
#include "snippets/lowered/pass/buffer_allocation.hpp"
#include "snippets/lowered/pass/allocate_buffers.hpp"
#include "snippets/lowered/pass/propagate_layout.hpp"
#include "snippets/lowered/pass/cleanup_loop_offsets.hpp"
#include "snippets/lowered/pass/softmax_decomposition.hpp"
#include "snippets/lowered/pass/move_scalar_to_consumer.hpp"
#include "snippets/lowered/pass/move_result_out_of_loop.hpp"
#include "snippets/lowered/pass/buffer_reset.hpp"
#include "snippets/lowered/pass/buffer_identification.hpp"
#include "snippets/lowered/pass/reset_buffers.hpp"
#include "snippets/lowered/pass/indentify_buffers.hpp"

#include "snippets/op/kernel.hpp"
#include "snippets/tensor_descriptor.hpp"
Expand All @@ -41,18 +41,18 @@ Generator::LoweringResult Generator::generate(std::shared_ptr<ov::Model>& m, con
const size_t vector_size = get_target_machine()->get_lanes();
const int32_t buffer_allocation_rank = static_cast<int32_t>(config.m_loop_depth);

// Note: The pass LoopInit uses LoopInfo that contains entry and exit points of the corresponding Loop.
// Note: The pass InitLoops uses LoopInfo that contains entry and exit points of the corresponding Loop.
// To avoid the Loop information corruption, we should call the passes with Load/Store work
// (for example, LoadMoveBroadcastToBroadcastLoad()) after explicit Loop insertion (LoopInit())
// (for example, LoadMoveBroadcastToBroadcastLoad()) after explicit Loop insertion (InitLoops())
lowered::pass::TransformationPipeline common_pipeline;
common_pipeline.register_transformation<lowered::pass::LoopMarkup>(vector_size);
common_pipeline.register_transformation<lowered::pass::MarkLoops>(vector_size);
common_pipeline.register_transformation<lowered::pass::SoftmaxDecomposition>(vector_size);
common_pipeline.register_transformation<lowered::pass::LoopFusion>();
common_pipeline.register_transformation<lowered::pass::FuseLoops>();
common_pipeline.register_transformation<lowered::pass::MoveResultOutOfLoop>();
common_pipeline.register_transformation<lowered::pass::BufferInsertion>(buffer_allocation_rank);
common_pipeline.register_transformation<lowered::pass::LoadStoreInsertion>(vector_size);
common_pipeline.register_transformation<lowered::pass::InsertBuffers>(buffer_allocation_rank);
common_pipeline.register_transformation<lowered::pass::InsertLoadStore>(vector_size);
common_pipeline.register_transformation<lowered::pass::SetScalarCountForLoadStore>();
common_pipeline.register_transformation<lowered::pass::LoopInit>();
common_pipeline.register_transformation<lowered::pass::InitLoops>();
common_pipeline.register_transformation<lowered::pass::MoveScalarToConsumer>();
common_pipeline.register_transformation<lowered::pass::LoadMoveBroadcastToBroadcastLoad>();
common_pipeline.register_transformation<lowered::pass::PropagateLayout>(); // or should be in final?
Expand All @@ -65,10 +65,10 @@ Generator::LoweringResult Generator::generate(std::shared_ptr<ov::Model>& m, con
return get_op_reg_type(op);
};

const auto buffer_allocation_pass = std::make_shared<lowered::pass::BufferAllocation>();
const auto buffer_allocation_pass = std::make_shared<lowered::pass::AllocateBuffers>();
lowered::pass::TransformationPipeline buffer_pipeline;
buffer_pipeline.register_transformation<lowered::pass::BufferIdentification>();
buffer_pipeline.register_transformation<lowered::pass::BufferReset>();
buffer_pipeline.register_transformation<lowered::pass::IdentifyBuffers>();
buffer_pipeline.register_transformation<lowered::pass::ResetBuffers>();
buffer_pipeline.register_transformation(buffer_allocation_pass);
buffer_pipeline.run(linear_ir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "snippets/lowered/pass/buffer_allocation.hpp"
#include "snippets/lowered/pass/allocate_buffers.hpp"

#include "snippets/lowered/linear_ir.hpp"
#include "snippets/itt.hpp"
Expand All @@ -12,7 +12,7 @@ namespace snippets {
namespace lowered {
namespace pass {

void BufferAllocation::propagate_offset(const LinearIR& linear_ir, const ExpressionPtr& buffer_expr, const size_t offset) {
void AllocateBuffers::propagate_offset(const LinearIR& linear_ir, const ExpressionPtr& buffer_expr, const size_t offset) {
// If Buffer has offset We set this offset in the connected MemoryAccess ops
// to correctly read and write data because all Buffers has the common data pointer on buffer scratchpad

Expand Down Expand Up @@ -55,8 +55,8 @@ void BufferAllocation::propagate_offset(const LinearIR& linear_ir, const Express
}


bool BufferAllocation::run(LinearIR& linear_ir) {
OV_ITT_SCOPED_TASK(ngraph::pass::itt::domains::SnippetsTransform, "Snippets::BufferAllocation");
bool AllocateBuffers::run(LinearIR& linear_ir) {
OV_ITT_SCOPED_TASK(ngraph::pass::itt::domains::SnippetsTransform, "Snippets::AllocateBuffers");

bool modified = false;
size_t offset = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "snippets/lowered/pass/loop_fusion.hpp"
#include "snippets/lowered/pass/fuse_loops.hpp"

#include "snippets/lowered/linear_ir.hpp"
#include "snippets/lowered/loop_manager.hpp"
Expand All @@ -17,9 +17,9 @@ namespace pass {
using LoopManager = LinearIR::LoopManager;
using LoopInfoPtr = LoopManager::LoopInfoPtr;

LoopFusion::LoopFusion() : Transformation() {}
FuseLoops::FuseLoops() : Transformation() {}

bool LoopFusion::can_be_fused(const LoopInfoPtr& loop_current, const LoopInfoPtr& loop_target) {
bool FuseLoops::can_be_fused(const LoopInfoPtr& loop_current, const LoopInfoPtr& loop_target) {
auto current_work_amount = loop_current->work_amount;
auto current_increment = loop_current->increment;
auto target_work_amount = loop_target->work_amount;
Expand All @@ -29,7 +29,7 @@ bool LoopFusion::can_be_fused(const LoopInfoPtr& loop_current, const LoopInfoPtr
return supported_work_amount && supported_increment;
}

void LoopFusion::fuse_points(LinearIR& linear_ir, std::vector<ExpressionPort>& exit_points, std::vector<ExpressionPort>& entry_points,
void FuseLoops::fuse_points(LinearIR& linear_ir, std::vector<ExpressionPort>& exit_points, std::vector<ExpressionPort>& entry_points,
LinearIR::constExprIt loop_begin_pos, LinearIR::constExprIt loop_end_pos) {
std::vector<ExpressionPort> new_exit_points;
for (const auto& exit_point : exit_points) {
Expand Down Expand Up @@ -72,7 +72,7 @@ void LoopFusion::fuse_points(LinearIR& linear_ir, std::vector<ExpressionPort>& e
exit_points = new_exit_points;
}

bool LoopFusion::fuse_upper_into_current(LinearIR& linear_ir, const LinearIR::LoopManagerPtr& loop_manager,
bool FuseLoops::fuse_upper_into_current(LinearIR& linear_ir, const LinearIR::LoopManagerPtr& loop_manager,
const ExpressionPort& current_entry_point, const ExpressionPort& target_exit_point,
size_t current_loop_id, size_t target_loop_id, size_t dim_idx,
LinearIR::constExprIt& current_loop_begin_pos, LinearIR::constExprIt& current_loop_end_pos) {
Expand Down Expand Up @@ -146,7 +146,7 @@ bool LoopFusion::fuse_upper_into_current(LinearIR& linear_ir, const LinearIR::Lo
return true;
}

bool LoopFusion::fuse_lower_into_current(LinearIR& linear_ir, const LinearIR::LoopManagerPtr& loop_manager,
bool FuseLoops::fuse_lower_into_current(LinearIR& linear_ir, const LinearIR::LoopManagerPtr& loop_manager,
const ExpressionPort& current_exit_point, const ExpressionPort& target_entry_point,
size_t current_loop_id, size_t target_loop_id, size_t dim_idx,
LinearIR::constExprIt& current_loop_begin_pos, LinearIR::constExprIt& current_loop_end_pos) {
Expand Down Expand Up @@ -216,8 +216,8 @@ bool LoopFusion::fuse_lower_into_current(LinearIR& linear_ir, const LinearIR::Lo
return true;
}

bool LoopFusion::run(LinearIR& linear_ir) {
OV_ITT_SCOPED_TASK(ngraph::pass::itt::domains::SnippetsTransform, "Snippets::LoopFusion")
bool FuseLoops::run(LinearIR& linear_ir) {
OV_ITT_SCOPED_TASK(ngraph::pass::itt::domains::SnippetsTransform, "Snippets::FuseLoops")
if (linear_ir.empty())
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "snippets/lowered/pass/buffer_identification.hpp"
#include "snippets/lowered/pass/indentify_buffers.hpp"

#include "snippets/lowered/linear_ir.hpp"
#include "snippets/snippets_isa.hpp"
Expand All @@ -24,7 +24,7 @@ inline size_t index(size_t col_num, size_t row, size_t col) {
}
} // namespace

std::vector<bool> BufferIdentification::create_adjacency_matrix(const LinearIR& linear_ir, const BufferSet& buffers) const {
std::vector<bool> IdentifyBuffers::create_adjacency_matrix(const LinearIR& linear_ir, const BufferSet& buffers) const {
// The sync point to check for adjacency is Loop because only in Loop we increment pointers.
// So if some Buffers in the one Loop have conflict (cannot be inplace: the different ptr increment and data sizes)
// they are called as adjacent
Expand Down Expand Up @@ -111,7 +111,7 @@ std::vector<bool> BufferIdentification::create_adjacency_matrix(const LinearIR&
return adj;
}

auto BufferIdentification::coloring(BufferSet& buffers, std::vector<bool>& adj) -> std::map<size_t, BufferSet> {
auto IdentifyBuffers::coloring(BufferSet& buffers, std::vector<bool>& adj) -> std::map<size_t, BufferSet> {
size_t color = 0;
std::map<size_t, BufferSet> color_groups;
const auto size = buffers.size();
Expand Down Expand Up @@ -156,8 +156,8 @@ auto BufferIdentification::coloring(BufferSet& buffers, std::vector<bool>& adj)
return color_groups;
}

bool BufferIdentification::run(LinearIR& linear_ir) {
OV_ITT_SCOPED_TASK(ngraph::pass::itt::domains::SnippetsTransform, "Snippets::BufferIdentification")
bool IdentifyBuffers::run(LinearIR& linear_ir) {
OV_ITT_SCOPED_TASK(ngraph::pass::itt::domains::SnippetsTransform, "Snippets::IdentifyBuffers")
// Unite Buffers using Graph coloring algorithm.
// Notes: We identify only Buffer with Intermediate memory because Buffers with new memory are used only in Brgemm case
// so these Buffers are always IntermediateBuffer nonadjacent
Expand Down
Loading

0 comments on commit 9e45f70

Please sign in to comment.