forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Snippets][CPU] Explicit loop (openvinotoolkit#55)
* [Snippets] Dynamic loop snapshot * [Snippets] Explicit Loop implementation
- Loading branch information
1 parent
55b672b
commit 0075a5f
Showing
70 changed files
with
2,031 additions
and
1,235 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "ngraph/op/op.hpp" | ||
#include "snippets/emitter.hpp" | ||
#include "ngraph/op/parameter.hpp" | ||
|
||
namespace ngraph { | ||
namespace snippets { | ||
namespace op { | ||
|
||
/** | ||
* @interface LoopBase | ||
* @brief Inserted during scheduling generation and represents Loop in affine notation | ||
* @ingroup snippets | ||
*/ | ||
class LoopBase : public ngraph::op::Op { | ||
public: | ||
OPENVINO_OP("LoopBase", "SnippetsOpset"); | ||
LoopBase(const std::vector<Output<Node>>& args, size_t dimension, size_t work_amount, size_t increment); | ||
LoopBase() = delete; | ||
bool visit_attributes(AttributeVisitor& visitor) override; | ||
size_t get_work_amount() const; | ||
size_t get_increment() const; | ||
size_t get_dimension() const; | ||
bool get_evaluate_once() const; | ||
|
||
protected: | ||
size_t dimension; | ||
size_t work_amount; | ||
size_t increment; | ||
bool evaluate_once; // true if the Loop is executed only once, used to skip setting and testing the loop counter | ||
}; | ||
class LoopEnd; | ||
class LoopBegin : public LoopBase { | ||
friend LoopEnd; | ||
public: | ||
OPENVINO_OP("LoopBegin", "SnippetsOpset"); | ||
/// \brief Construct an Loop | ||
/// \param region The vector of pairs: emitters and the corresponding registers | ||
/// \param increment Loop size - count of elements to load and store. | ||
/// Vector Loop should have size of vector register and Scalar Loop should have 1 | ||
/// \param num_inputs Count of inputs | ||
/// \param num_outputs Count of outputs | ||
/// \param io_dims Vector of last dimensions of inputs and outputs | ||
/// \param io_data_sizes Vector of data type sizes of inputs and outputs | ||
explicit LoopBegin(const std::vector<Output<Node>>& args); | ||
LoopBegin() = delete; | ||
void validate_and_infer_types() override; | ||
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& inputs) const override; | ||
std::shared_ptr<LoopEnd> get_loop_end(); | ||
// begin_address and input_regs are needed to communicate information between LoopBegin and LoopEnd emitters | ||
const uint8_t* begin_address; | ||
std::vector<size_t> input_regs; | ||
private: | ||
void validate_and_infer_types_except_LoopEnd(); | ||
LoopBegin(const std::vector<Output<Node>>& args, size_t dimension, size_t work_amount, size_t increment); | ||
}; | ||
|
||
class LoopEnd : public LoopBase { | ||
public: | ||
OPENVINO_OP("LoopEnd", "SnippetsOpset"); | ||
LoopEnd(const std::vector<Output<Node>>& args, size_t dimension, size_t work_amount, size_t increment, | ||
std::vector<bool> apply_increment, std::vector<int64_t> finalization_offsets); | ||
LoopEnd() = delete; | ||
std::shared_ptr<LoopBegin> get_loop_begin(); | ||
void validate_and_infer_types() override; | ||
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& inputs) const override; | ||
const std::vector<int64_t>& get_finalization_offsets() const; | ||
const std::vector<bool>& get_apply_increment() const; | ||
void set_finalization_offsets(std::vector<int64_t> offsets); | ||
void set_apply_increment(std::vector<bool> apply_increment); | ||
void set_work_amount(size_t new_work_amount); | ||
void set_increment(size_t new_increment); | ||
void set_evaluate_once(bool once); | ||
// Used to propagate information about Loop structure, needed to simplify some optimizations. For example, | ||
// to skip pointer increments when outer Loop is empty, and work_amount == vector_size (one inner vector Loop) | ||
// true by default, the optimizations enabled if it's false; | ||
bool has_outer_loop; | ||
|
||
private: | ||
std::vector<bool> apply_increment; | ||
std::vector<int64_t> finalization_offsets; | ||
size_t loop_io_size; | ||
}; | ||
|
||
} // namespace op | ||
} // namespace snippets | ||
} // namespace ngraph |
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,67 @@ | ||
// Copyright (C) 2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "ngraph/op/op.hpp" | ||
#include "ngraph/op/parameter.hpp" | ||
#include "loop.hpp" | ||
|
||
namespace ngraph { | ||
namespace snippets { | ||
namespace op { | ||
|
||
/* ==== LoopBegin === */ | ||
std::shared_ptr<LoopBegin> insertLoopBeginAfterOutputs(const OutputVector& originalOutputs); | ||
|
||
template<typename T> | ||
std::shared_ptr<LoopBegin> insertLoopBegin(const T& afterTheseNodes) { | ||
static_assert(std::is_same<T, ParameterVector>() || std::is_same<T, NodeVector>(), | ||
"Unsupported template parameter for insertLoopBegin. Only ParameterVector or NodeVector is allowed"); | ||
OutputVector originalOutputs; | ||
std::vector<std::set<Input<Node>>> childInputs; | ||
for (const auto &n : afterTheseNodes) { | ||
const auto& nodeOutputs = n->outputs(); | ||
// Ignore the LoopBegin->LoopEnd edge to make it easier to construct enclosed Loops | ||
std::move(nodeOutputs.begin(), nodeOutputs.end() - 1 * ov::is_type<LoopBegin>(n), std::back_inserter(originalOutputs)); | ||
} | ||
|
||
return insertLoopBeginAfterOutputs(originalOutputs); | ||
} | ||
|
||
template<> | ||
inline std::shared_ptr<LoopBegin> insertLoopBegin(const OutputVector& afterTheseNodes) { | ||
return insertLoopBeginAfterOutputs(afterTheseNodes); | ||
} | ||
/* ============== */ | ||
|
||
/* ==== LoopEnd === */ | ||
std::shared_ptr<LoopEnd> insertLoopEndBeforeInputs(const std::vector<Input<Node>>& originalInputs, | ||
const std::shared_ptr<LoopBegin>& tileBegin, | ||
size_t dimension, size_t work_amount, size_t increment, | ||
std::vector<bool> apply_increment = {}, | ||
std::vector<int64_t> finalization_offsets = {}); | ||
|
||
template<typename T, typename ...Args> | ||
std::shared_ptr<LoopEnd> insertLoopEnd(const T& beforeTheseNodes, Args ...args) { | ||
static_assert(std::is_same<T, ResultVector>() || std::is_same<T, NodeVector>(), | ||
"Unsupported template parameter for insertLoopBegin. Only ParameterVector or NodeVector is allowed"); | ||
std::vector<Input<Node>> originalInputs; | ||
for (const auto &n : beforeTheseNodes) { | ||
const auto& nodeInputs = n->inputs(); | ||
// Ignore the LoopBegin->LoopEnd edge to facilitate enclosed Loops construction | ||
std::move(nodeInputs.begin(), nodeInputs.end() - 1 * ov::is_type<LoopEnd>(n), std::back_inserter(originalInputs)); | ||
} | ||
return insertLoopEndBeforeInputs(originalInputs, args...); | ||
} | ||
|
||
template<typename ...Args> | ||
std::shared_ptr<LoopEnd> insertLoopEnd(const std::vector<Input<Node>>& beforeTheseNodes, Args ...args) { | ||
return insertLoopEndBeforeInputs(beforeTheseNodes, args...); | ||
} | ||
/* ============== */ | ||
|
||
} // namespace op | ||
} // namespace snippets | ||
} // namespace ngraph |
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,38 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <ngraph/op/op.hpp> | ||
|
||
namespace ngraph { | ||
namespace snippets { | ||
namespace op { | ||
|
||
/** | ||
* @interface MemoryAccess | ||
* @brief This is an ubre | ||
* where number of elements to store is determined by "count" | ||
* Default value is "1" - to store one element | ||
* @ingroup snippets | ||
*/ | ||
|
||
class MemoryAccess : public ngraph::op::Op { | ||
public: | ||
OPENVINO_OP("MemoryAccess", "SnippetsOpset"); | ||
|
||
size_t get_count() const; | ||
void set_count(size_t count); | ||
bool visit_attributes(AttributeVisitor& visitor) override; | ||
void validate_and_infer_types() override; | ||
|
||
protected: | ||
explicit MemoryAccess(const Output<Node>& x, size_t count = 1lu); | ||
MemoryAccess() = default; | ||
size_t m_count = 0lu; | ||
}; | ||
|
||
} // namespace op | ||
} // namespace snippets | ||
} // namespace ngraph |
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
Oops, something went wrong.