-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Snippets] Moved infrastructure to Linear Intermediate Representation #16402
Merged
dmitry-gorokhov
merged 28 commits into
openvinotoolkit:master
from
a-sidorova:feature/snippets/lin_ir/loop_fusion_insert
May 19, 2023
Merged
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
1377883
Introduce linear IR and disable obsolete tests
IvanNovoselov d5f8fb5
[Snippets] Added Loop markup and Loop Fusion on Linear IR Level
a-sidorova b675bef
Added support of custom Plugin ops in Linear IR
a-sidorova feb7bfc
[Snippets] Added Buffer identification
a-sidorova 7d4ce5c
[Snippets] Refactoring
a-sidorova 1fada21
Fixes after rebasing
a-sidorova c530927
Removed work around for StoreEmitter
a-sidorova 467c7aa
[Snippets] Refactoring of transformations
a-sidorova 508a34b
[Snippets] Rebased on the latest master
a-sidorova 7440994
[Snippets] Added support of Port Descriptor (#106)
a-sidorova 43936a3
Applied comments by Ivan #1
a-sidorova e7ee0d5
Fixed Loads with the same Parent: CleanRepeatedPtrShifts
a-sidorova 5ef7227
Updated Buffer Identification logic
a-sidorova 2ea1bf3
Cleaned cmake lists
a-sidorova 9b45cfb
fixes after rebase
a-sidorova 979b673
fixed lin build
a-sidorova ef6717e
fixed build 2
a-sidorova dd0a4e1
added missed file
a-sidorova f5d59ce
fixed snippets test build
a-sidorova 1eb736a
Applied comments by Ivan #2
a-sidorova 89f99e5
[Snippets] Moved reg_info from Expression to PortDescriptor
a-sidorova f71b552
Moved Linear IR transformations from generator to Subgraph
a-sidorova ec5920b
Fixed InsertStore for Buffer wo inputs
a-sidorova 14b8709
Removed incorrect extra copy rt_info which break PortDescriptors
a-sidorova 13d956f
[Snippets] Moved namespace from ngraph to ov
a-sidorova d81287e
Applied comments by Dmitry
a-sidorova dbfe69a
[Snippets] Tensor -> PortConnector
a-sidorova 0e04ae1
[Snippets] Added link to doc
a-sidorova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
99 changes: 99 additions & 0 deletions
99
src/common/snippets/include/snippets/lowered/expression.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,99 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <openvino/core/node.hpp> | ||
#include <openvino/opsets/opset1.hpp> | ||
|
||
#include "snippets/emitter.hpp" | ||
#include "snippets/target_machine.hpp" | ||
#include "snippets/lowered/tensor.hpp" | ||
#include "snippets/lowered/expression_port.hpp" | ||
|
||
|
||
namespace ngraph { | ||
namespace snippets { | ||
namespace lowered { | ||
|
||
class LinearIR; | ||
|
||
class Expression : public std::enable_shared_from_this<Expression> { | ||
friend class LinearIR; | ||
friend class ExpressionPort; | ||
|
||
public: | ||
static size_t LOOP_NULL_ID; | ||
|
||
Expression() = default; | ||
virtual ~Expression() = default; | ||
|
||
std::shared_ptr<Node> get_node() const; | ||
std::shared_ptr<Emitter> get_emitter() const; | ||
|
||
RegInfo get_reg_info() const; | ||
void set_reg_info(RegInfo rinfo); | ||
|
||
const TensorPtr& get_input_tensor(size_t i) const; | ||
const TensorPtr& get_output_tensor(size_t i) const; | ||
std::vector<TensorPtr> get_input_tensors() const { return m_input_tensors; } | ||
std::vector<TensorPtr> get_output_tensors() const { return m_output_tensors; } | ||
|
||
const PortDescriptorPtr& get_input_port_descriptor(size_t i) const; | ||
const PortDescriptorPtr& get_output_port_descriptor(size_t i) const; | ||
std::vector<PortDescriptorPtr> get_input_port_descriptors() const { return m_input_port_descriptors; } | ||
std::vector<PortDescriptorPtr> get_output_port_descriptors() const { return m_output_port_descriptors; } | ||
|
||
size_t get_input_count() const { return m_input_tensors.size(); } | ||
size_t get_output_count() const { return m_output_tensors.size(); } | ||
|
||
std::vector<size_t> get_loop_ids() const { return m_loop_ids; } | ||
void set_loop_ids(const std::vector<size_t>& loops) { m_loop_ids = loops; } | ||
void set_loop_id(size_t id, size_t idx); | ||
void remove_loop_id(size_t id); | ||
|
||
void validate() const; | ||
void init_emitter(const std::shared_ptr<const TargetMachine>& target); | ||
|
||
ExpressionPort get_input_port(size_t i); | ||
ExpressionPort get_output_port(size_t i); | ||
|
||
protected: | ||
// Note: The constructor and tensor initialization are private since an expression can be created only by Linear IR. | ||
// These methods must be used only by Linear IR builder of expressions! | ||
explicit Expression(const std::shared_ptr<Node>& n); | ||
|
||
void replace_input(size_t port, TensorPtr to); | ||
|
||
std::shared_ptr<Node> m_source_node{nullptr}; | ||
std::shared_ptr<Emitter> m_emitter{nullptr}; | ||
std::vector<TensorPtr> m_input_tensors{}; | ||
std::vector<TensorPtr> m_output_tensors{}; | ||
std::vector<PortDescriptorPtr> m_input_port_descriptors{}; | ||
std::vector<PortDescriptorPtr> m_output_port_descriptors{}; | ||
// The order Loops identifies: Outer ---> Inner | ||
std::vector<size_t> m_loop_ids; | ||
}; | ||
using ExpressionPtr = std::shared_ptr<Expression>; | ||
|
||
class IOExpression : public Expression { | ||
friend class LinearIR; | ||
|
||
public: | ||
enum class io_type {INPUT, OUTPUT, UNDEFINED}; | ||
|
||
int64_t get_index() const { return m_index; } | ||
io_type get_type() const { return m_type; } | ||
|
||
private: | ||
explicit IOExpression(const std::shared_ptr<ov::opset1::Parameter>& n, int64_t index); | ||
explicit IOExpression(const std::shared_ptr<ov::opset1::Result>& n, int64_t index); | ||
|
||
int64_t m_index = -1; | ||
io_type m_type = io_type::UNDEFINED; | ||
}; | ||
|
||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ngraph |
55 changes: 55 additions & 0 deletions
55
src/common/snippets/include/snippets/lowered/expression_factory.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,55 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "linear_ir.hpp" | ||
|
||
#include "snippets/snippets_isa.hpp" | ||
|
||
namespace ngraph { | ||
namespace snippets { | ||
namespace lowered { | ||
|
||
class LinearIR::ExpressionFactory { | ||
public: | ||
template<class... Args> | ||
static ExpressionPtr build(const std::shared_ptr<Node>& n, Args&&... params) { | ||
if (const auto par = ov::as_type_ptr<ov::op::v0::Parameter>(n)) { | ||
return create(par, params...); | ||
} else if (const auto res = ov::as_type_ptr<ov::op::v0::Result>(n)) { | ||
return create(res, params...); | ||
} else if (const auto loop_begin = ov::as_type_ptr<op::LoopBegin>(n)) { | ||
return create(loop_begin, params...); | ||
} else if (const auto loop_end = ov::as_type_ptr<op::LoopEnd>(n)) { | ||
return create(loop_end, params...); | ||
} | ||
return create(n, params...); | ||
} | ||
|
||
private: | ||
/* -- Default Builders - initialize input tensors from parents and create new output tensors themselves */ | ||
static ExpressionPtr create(const std::shared_ptr<ngraph::op::v0::Parameter>& par, const LinearIR& linear_ir, | ||
const std::shared_ptr<ov::Model>& model); | ||
static ExpressionPtr create(const std::shared_ptr<ngraph::op::v0::Result>& res, const LinearIR& linear_ir, | ||
const std::shared_ptr<ov::Model>& model); | ||
static ExpressionPtr create(const std::shared_ptr<ov::Node>& n, const LinearIR& linear_ir, | ||
const std::shared_ptr<ov::Model>& model); | ||
|
||
/* -- Input Builders - get input tensors from method parameters and create new output tensors themselves */ | ||
static ExpressionPtr create(const std::shared_ptr<op::LoopBegin>& n, const std::vector<TensorPtr>& inputs); | ||
static ExpressionPtr create(const std::shared_ptr<op::LoopEnd>& n, const std::vector<TensorPtr>& inputs); | ||
static ExpressionPtr create(const std::shared_ptr<ov::Node>& n, const std::vector<TensorPtr>& inputs); | ||
|
||
// Creates inputs for expression using parent output tensors | ||
static void create_expression_inputs(const LinearIR& linear_ir, const ExpressionPtr& expr); | ||
// Creates new output tensors | ||
static void create_expression_outputs(const ExpressionPtr& expr); | ||
// The method verifies of input tensors to availability of the expression as consumer and add it if missed | ||
static void init_expression_inputs(const ExpressionPtr& expr, const std::vector<TensorPtr>& inputs); | ||
}; | ||
|
||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ngraph |
51 changes: 51 additions & 0 deletions
51
src/common/snippets/include/snippets/lowered/expression_port.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,51 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include "port_descriptor.hpp" | ||
|
||
|
||
namespace ngraph { | ||
namespace snippets { | ||
namespace lowered { | ||
|
||
class Tensor; | ||
class Expression; | ||
class ExpressionPort { | ||
public: | ||
enum Type { | ||
Input, | ||
Output | ||
}; | ||
|
||
ExpressionPort() = default; | ||
explicit ExpressionPort(const std::shared_ptr<Expression>& expr, Type type, size_t port); | ||
|
||
const std::shared_ptr<Expression>& get_expr() const { return m_expr; } | ||
Type get_type() const { return m_type; } | ||
size_t get_index() const { return m_port_index; } | ||
|
||
const PortDescriptorPtr& get_descriptor_ptr() const; | ||
const std::shared_ptr<Tensor>& get_tensor_ptr() const; | ||
// Returns connected ports to the current: | ||
// - Input port returns one source (parent) port | ||
// - Output port returns all consumer ports (children) | ||
std::set<ExpressionPort> get_connected_ports() const; | ||
|
||
friend bool operator==(const ExpressionPort& lhs, const ExpressionPort& rhs); | ||
friend bool operator!=(const ExpressionPort& lhs, const ExpressionPort& rhs); | ||
friend bool operator<(const ExpressionPort& lhs, const ExpressionPort& rhs); | ||
|
||
private: | ||
std::shared_ptr<Expression> m_expr; | ||
Type m_type = Type::Output; | ||
size_t m_port_index = 0; | ||
}; | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ngraph |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Folders structure looks unaligned a little bit. Maybe we can do smt like:
Also bot sure about
lowered
naming. Maybelinear_ir
fits better, but @IvanNovoselov this is up-to you to decide.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lowering is a rather vague term, so I like the idea to distinguish the workflow steps based on the IR's they use.
In fact, I'm already using this distinction in the documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets do in separate PR then