Skip to content

Commit

Permalink
Moved Linear IR transformations from generator to Subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
a-sidorova committed May 16, 2023
1 parent 89f99e5 commit f71b552
Show file tree
Hide file tree
Showing 34 changed files with 229 additions and 212 deletions.
11 changes: 3 additions & 8 deletions src/common/snippets/include/snippets/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "snippets_isa.hpp"

#include "snippets/lowered/linear_ir.hpp"
#include "snippets/lowered/pass/transformation.hpp"
#include "snippets/lowered/pass/pass.hpp"

namespace ngraph {
namespace snippets {
Expand Down Expand Up @@ -73,11 +73,10 @@ class Generator {
* @return pointer to generated code
*/
struct LoweringResult {
LoweringResult(code c, size_t size) : binary_code(c), buffer_scratchpad_size(size) {}
LoweringResult(code c) : binary_code(c) {}
code binary_code = nullptr;
size_t buffer_scratchpad_size = 0;
};
LoweringResult generate(std::shared_ptr<ov::Model>& m, const lowered::Config& config, const void* compile_params = nullptr);
LoweringResult generate(lowered::LinearIR& linear_ir, const lowered::Config& config, const void* compile_params = nullptr);

/**
* @brief gets target machine
Expand Down Expand Up @@ -107,10 +106,6 @@ class Generator {
* @return register type
*/
virtual opRegType get_specific_op_reg_type(const std::shared_ptr<ov::Node>& op) const;
/**
* @brief gets target specific transformations for code generation
*/
virtual lowered::pass::TransformationPipeline target_specific_transformations() const;

std::shared_ptr<TargetMachine> target;
// todo: we need to save lowered code to access compiled brgemm kernels on execution time (normally lowered is destructed by then).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"
#include "snippets/snippets_isa.hpp"

namespace ngraph {
Expand All @@ -18,9 +18,9 @@ namespace pass {
* @ingroup snippets
*/

class AllocateBuffers : public Transformation {
class AllocateBuffers : public Pass {
public:
OPENVINO_RTTI("AllocateBuffers", "Transformation")
OPENVINO_RTTI("AllocateBuffers", "Pass")
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 @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"
#include "snippets/generator.hpp"

namespace ngraph {
Expand All @@ -18,9 +18,9 @@ namespace pass {
* Note that changing of the IR is likely to invalidate register assignment.
* @ingroup snippets
*/
class AssignRegisters : public Transformation {
class AssignRegisters : public Pass {
public:
OPENVINO_RTTI("AssignRegisters", "Transformation")
OPENVINO_RTTI("AssignRegisters", "Pass")
explicit AssignRegisters(const std::function<Generator::opRegType(const std::shared_ptr<Node>& op)>& mapper) : m_reg_type_mapper(mapper) {}
bool run(LinearIR& linear_ir) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

namespace ngraph {
namespace snippets {
Expand All @@ -21,9 +21,9 @@ namespace pass {
* This condition should be removed when Buffers stop being inplace by default.
* @ingroup snippets
*/
class CleanRepeatedDataPointerShifts: public Transformation {
class CleanRepeatedDataPointerShifts: public Pass {
public:
OPENVINO_RTTI("CleanRepeatedDataPointerShifts", "Transformation")
OPENVINO_RTTI("CleanRepeatedDataPointerShifts", "Pass")
CleanRepeatedDataPointerShifts() = default;

bool run(LinearIR& linear_ir) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

namespace ngraph {
namespace snippets {
Expand All @@ -17,9 +17,9 @@ namespace pass {
* This transformation "fuses" the offsets with an outer loop's ptr_increments, and zeroes the offsets before Results.
* @ingroup snippets
*/
class CleanupLoopOffsets : public Transformation {
class CleanupLoopOffsets : public Pass {
public:
OPENVINO_RTTI("CleanupLoopOffsets", "Transformation")
OPENVINO_RTTI("CleanupLoopOffsets", "Pass")
bool run(LinearIR& linear_ir) override;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

#include "snippets/lowered/loop_manager.hpp"

Expand Down Expand Up @@ -36,9 +36,9 @@ namespace pass {
* The main conditions of possible fusion is the equal increments and the equal/broadcastable work amounts.
* @ingroup snippets
*/
class FuseLoops : public Transformation {
class FuseLoops : public Pass {
public:
OPENVINO_RTTI("FuseLoops", "Transformation")
OPENVINO_RTTI("FuseLoops", "Pass")
FuseLoops();
bool run(LinearIR& linear_ir) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

#include "snippets/op/buffer.hpp"

Expand All @@ -28,9 +28,9 @@ namespace pass {
* Note: should be called before ResetBuffer() pass to have correct offsets
* @ingroup snippets
*/
class IdentifyBuffers: public Transformation {
class IdentifyBuffers: public Pass {
public:
OPENVINO_RTTI("IdentifyBuffers", "Transformation")
OPENVINO_RTTI("IdentifyBuffers", "Pass")
IdentifyBuffers() = default;

bool run(LinearIR& linear_ir) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

#include "snippets/lowered/loop_manager.hpp"

Expand All @@ -18,9 +18,9 @@ namespace pass {
* @brief The pass explicitly insert LoadBegin and LoadEnd in Linear IR using LoopManager::LoopInfo from Loop markup algorithm
* @ingroup snippets
*/
class InitLoops : public Transformation {
class InitLoops : public Pass {
public:
OPENVINO_RTTI("InsertLoops", "Transformation")
OPENVINO_RTTI("InsertLoops", "Pass")
InitLoops();
bool run(LinearIR& linear_ir) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

namespace ngraph {
namespace snippets {
Expand All @@ -19,9 +19,9 @@ namespace pass {
* @param m_buffer_allocation_rank - rank of shape for memory allocation: shape[shape_rank - normalize(m_allocation_rank) : shape_rank]
* @ingroup snippets
*/
class InsertBuffers : public Transformation {
class InsertBuffers : public Pass {
public:
OPENVINO_RTTI("InsertBuffers", "Transformation")
OPENVINO_RTTI("InsertBuffers", "Pass")
InsertBuffers(int32_t buffer_allocation_rank);
bool run(LinearIR& linear_ir) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

#include "snippets/lowered/loop_manager.hpp"

Expand All @@ -20,10 +20,10 @@ namespace pass {
* @param m_vector_size - the count of elements for loading/storing
* @ingroup snippets
*/
class InsertLoadStore : public Transformation {
class InsertLoadStore : public Pass {
public:
explicit InsertLoadStore(size_t vector_size);
OPENVINO_RTTI("InsertLoadStore", "Transformation")
OPENVINO_RTTI("InsertLoadStore", "Pass")
bool run(LinearIR& linear_ir) override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

namespace ngraph {
namespace snippets {
Expand All @@ -17,13 +17,13 @@ namespace pass {
* Additional optimizations are performed if a loop body is executed only once.
* @ingroup snippets
*/
class InsertTailLoop : public Transformation {
class InsertTailLoop : public Pass {
static void tail_transformations(LinearIR& linear_ir,
LinearIR::container::const_iterator tail_begin,
LinearIR::container::const_iterator tail_end,
size_t tail_size);
public:
OPENVINO_RTTI("InsertTailLoop", "Transformation")
OPENVINO_RTTI("InsertTailLoop", "Pass")
bool run(LinearIR& linear_ir) override;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

namespace ngraph {
namespace snippets {
Expand All @@ -16,10 +16,10 @@ namespace pass {
* @brief Fuses consecutive Load and MoveBroadcast into a single load insctruction.
* @ingroup snippets
*/
class LoadMoveBroadcastToBroadcastLoad: public Transformation {
class LoadMoveBroadcastToBroadcastLoad: public Pass {
public:
LoadMoveBroadcastToBroadcastLoad() = default;
OPENVINO_RTTI("LoadMoveBroadcastToBroadcastLoad", "Transformation")
OPENVINO_RTTI("LoadMoveBroadcastToBroadcastLoad", "Pass")
bool run(LinearIR& linear_ir) override;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"


namespace ngraph {
Expand All @@ -20,9 +20,9 @@ namespace pass {
* - the consumer of the expression is explicitly after this expression - the pass marks the branches
* @ingroup snippets
*/
class MarkLoops : public Transformation {
class MarkLoops : public Pass {
public:
OPENVINO_RTTI("MarkLoops", "Transformation")
OPENVINO_RTTI("MarkLoops", "Pass")
MarkLoops(size_t vector_size);
bool run(LinearIR& linear_ir) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

namespace ngraph {
namespace snippets {
Expand All @@ -19,9 +19,9 @@ namespace pass {
* The pass extracts Result expressions from Loop and insert after.
* @ingroup snippets
*/
class MoveResultOutOfLoop : public Transformation {
class MoveResultOutOfLoop : public Pass {
public:
OPENVINO_RTTI("MoveResultOutOfLoop", "Transformation")
OPENVINO_RTTI("MoveResultOutOfLoop", "Pass")
MoveResultOutOfLoop() = default;
bool run(LinearIR& linear_ir) override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "transformation.hpp"
#include "pass.hpp"

namespace ngraph {
namespace snippets {
Expand All @@ -22,9 +22,9 @@ namespace pass {
* To avoid such cases, we move Constants to the places in Linear IR before right Consumer to execute Scalar on each Loop iteration.
* @ingroup snippets
*/
class MoveScalarToConsumer : public Transformation {
class MoveScalarToConsumer : public Pass {
public:
OPENVINO_RTTI("MoveScalarsToConsumer", "Transformation")
OPENVINO_RTTI("MoveScalarsToConsumer", "Pass")
MoveScalarToConsumer() = default;
bool run(LinearIR& linear_ir) override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ namespace lowered {
namespace pass {

/**
* @interface Transformation
* @interface Pass
* @brief Base class for transformations on linear IR
* @ingroup snippets
*/
class Transformation {
class Pass {
public:
Transformation() = default;
virtual ~Transformation() = default;
Pass() = default;
virtual ~Pass() = default;
// Note that get_type_info_static and get_type_info are needed to mimic OPENVINO_RTTI interface,
// so the standard OPENVINO_RTTI(...) macros could be used in derived classes.
_OPENVINO_HIDDEN_METHOD static const ::ov::DiscreteTypeInfo& get_type_info_static() {
static ::ov::DiscreteTypeInfo type_info_static {"Transformation"};
static ::ov::DiscreteTypeInfo type_info_static {"Pass"};
type_info_static.hash();
return type_info_static;
}
Expand All @@ -42,23 +42,23 @@ class Transformation {
virtual bool run(lowered::LinearIR& linear_ir) = 0;
};

class TransformationPipeline {
class PassPipeline {
public:
TransformationPipeline() = default;
PassPipeline() = default;

void register_transformation(const std::shared_ptr<Transformation>& transformation);
void register_pass(const std::shared_ptr<Pass>& pass);

template<typename T, class... Args>
void register_transformation(Args&&... args) {
static_assert(std::is_base_of<Transformation, T>::value, "Transformation not derived from lowered::Transformation");
auto transformation = std::make_shared<T>(std::forward<Args>(args)...);
register_transformation(transformation);
void register_pass(Args&&... args) {
static_assert(std::is_base_of<Pass, T>::value, "Pass not derived from lowered::Pass");
auto pass = std::make_shared<T>(std::forward<Args>(args)...);
register_pass(pass);
}

void run(lowered::LinearIR& linear_ir);

private:
std::vector<std::shared_ptr<Transformation>> m_transformations;
std::vector<std::shared_ptr<Pass>> m_passes;
};

} // namespace pass
Expand Down
Loading

0 comments on commit f71b552

Please sign in to comment.