Skip to content

Commit

Permalink
applied comment part
Browse files Browse the repository at this point in the history
  • Loading branch information
a-sidorova committed Nov 9, 2022
1 parent 2c79645 commit c32e7d6
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 102 deletions.
8 changes: 4 additions & 4 deletions src/common/snippets/include/snippets/op/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ namespace op {
/**
* @interface Buffer
* @brief The operation is for intermediate data storage
* Note: All buffers in a graph have the memory pointer. So if we have a few buffers,
* each buffer should have an own offset for common memory
* Note: All buffers in a graph have the same memory pointer. So if we have a few buffers,
* each buffer should have its own offset for common memory
* @ingroup snippets
*/
class Buffer : public ngraph::op::Op {
public:
OPENVINO_OP("Buffer", "SnippetsOpset");

Buffer(const Output<Node>& x, const size_t offset = 0);
Buffer(const Output<Node>& x);
Buffer() = default;

size_t get_offset() const { return m_offset; }
Expand All @@ -36,7 +36,7 @@ class Buffer : public ngraph::op::Op {
void validate_and_infer_types() override;

private:
size_t m_offset;
size_t m_offset = 0lu;
};

} // namespace op
Expand Down
15 changes: 9 additions & 6 deletions src/common/snippets/include/snippets/op/fill.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,31 @@ namespace op {
* @brief Generated in Tail Loop vector representation in code generation step for cases when we should
* refill regsiters by special numbers.
* For example, for cases with ReduceMax or ReduceSum in Softmax
* Where:
* - offset - is value shift for filling
* - fill_value - hexadecimal filling value
* @ingroup snippets
*/
class Fill : public ngraph::op::Op {
public:
OPENVINO_OP("Fill", "SnippetsOpset");

Fill(const Output<Node>& x, const int64_t offset, const std::string fill_value = "zero");
Fill(const Output<Node>& x, const size_t offset, const uint32_t fill_value = 0x0);
Fill() = default;

int64_t get_offset() const { return m_offset; }
std::string get_fill_value() const { return m_fill_value; }
size_t get_offset() const { return m_offset; }
uint32_t get_fill_value() const { return m_fill_value; }

void set_offset(const size_t offset) { m_offset = offset; }
void set_fill_value(const std::string fill_value) { m_fill_value = fill_value; }
void set_fill_value(const uint32_t fill_value) { m_fill_value = fill_value; }

bool visit_attributes(AttributeVisitor& visitor) override;
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
void validate_and_infer_types() override;

protected:
int64_t m_offset = 0lu;
std::string m_fill_value = "zero";
size_t m_offset = 0lu;
uint32_t m_fill_value = 0x0;
};

} // namespace op
Expand Down
4 changes: 2 additions & 2 deletions src/common/snippets/include/snippets/op/load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace op {

/**
* @interface Load
* @brief Generated by Canonicalization step where explicit instructions should be emitted for data loading
* @brief Generated during Lowering stage (convert_to_snippets_dialect) where explicit instructions should be emitted for data loading
* where number of elements to load is determined by "count" (Default value is "1" - to load one element)
* and memeory offset for loading is determined by "offset" (Default value is "0" - to load starting first element)
* and memory offset for loading is determined by "offset" (Default value is "0" - to load starting from the first element)
* @ingroup snippets
*/
class Load : public ngraph::op::Op {
Expand Down
6 changes: 3 additions & 3 deletions src/common/snippets/include/snippets/op/loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class LoopEnd : public LoopBase {
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;
const std::vector<bool>& get_forse_finalization_offsets() const;
const std::vector<bool>& get_force_finalization_offsets() const;
void set_finalization_offsets(std::vector<int64_t> offsets);
void set_apply_increment(std::vector<bool> apply_increment);
void set_forse_finalization_offsets(std::vector<bool> forse_finalizations_offsets);
void set_force_finalization_offsets(std::vector<bool> forse_finalizations_offsets);
void set_work_amount(size_t new_work_amount);
void set_increment(size_t new_increment);
void set_evaluate_once(bool once);
Expand All @@ -86,7 +86,7 @@ class LoopEnd : public LoopBase {
// pointer always should be reverted (for example, for buffers: we should store to buffer in first loop
// and we should load the same data from this buffer in the next loop)
// true by default, the optimizations enabled if it's false.
std::vector<bool> forse_finalization_offsets;
std::vector<bool> force_finalization_offsets;
std::vector<int64_t> finalization_offsets;
size_t loop_io_size;
};
Expand Down
2 changes: 1 addition & 1 deletion src/common/snippets/include/snippets/op/loop_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::shared_ptr<LoopEnd> insertLoopEndBeforeInputs(const std::vector<Input<Node>
size_t dimension, size_t work_amount, size_t increment,
std::vector<bool> apply_increment = {},
std::vector<int64_t> finalization_offsets = {},
std::vector<bool> forse_finalization_offsets = {});
std::vector<bool> force_finalization_offsets = {});

template<typename T, typename ...Args>
std::shared_ptr<LoopEnd> insertLoopEnd(const T& beforeTheseNodes, Args ...args) {
Expand Down
4 changes: 2 additions & 2 deletions src/common/snippets/include/snippets/op/store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace op {

/**
* @interface Store
* @brief Generated by Canonicalization step where explicit instructions should be emitted for data storing
* @brief Generated during Lowering stage (convert_to_snippets_dialect) where explicit instructions should be emitted for data storing
* where number of elements to store is determined by "count" (Default value is "1" - to store one element)
* and memeory offset for storing is determined by "offset" (Default value is "0" - to store starting at start memory ptr)
* and memory offset for storing is determined by "offset" (Default value is "0" - to store starting at start memory ptr)
* @ingroup snippets
*/
class Store : public ngraph::op::Op {
Expand Down
5 changes: 4 additions & 1 deletion src/common/snippets/include/snippets/op/vector_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ class VectorBuffer : public ngraph::op::Op {
public:
OPENVINO_OP("VectorBuffer", "SnippetsOpset");

VectorBuffer();
VectorBuffer(const ov::element::Type element_type = ov::element::f32);

bool visit_attributes(AttributeVisitor& visitor) override { return true;}
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
void validate_and_infer_types() override;

private:
ov::element::Type m_element_type;
};

} // namespace op
Expand Down
6 changes: 3 additions & 3 deletions src/common/snippets/src/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ auto tail_transformations(NodeVector& tail, const size_t tail_size, const bool n
auto& rt = input.get_rt_info();
auto fill_rt = rt.find("set_fill");
if (fill_rt != rt.end()) {
const std::string fill_value = fill_rt->second.as<std::string>();
const auto fill_value = fill_rt->second.as<uint32_t>();
fill = std::make_shared<ngraph::snippets::op::Fill>(input.get_source_output(), tail_size, fill_value);
input.get_node()->set_argument(input.get_index(), fill);
// we should explicitly copy reg info because we insert Fill after assign register
Expand Down Expand Up @@ -141,10 +141,10 @@ ngraph::snippets::code ngraph::snippets::Generator::generate(std::shared_ptr<ov:
loop->set_evaluate_once(true);
const auto increment = loop->get_increment();
const auto& apply_increments = loop->get_apply_increment();
const auto& forse_finalization_offsets = loop->get_forse_finalization_offsets();
const auto& force_finalization_offsets = loop->get_force_finalization_offsets();
std::vector<int64_t> new_finalization_offsets(loop->get_finalization_offsets());
for (auto i = 0; i < new_finalization_offsets.size(); i++) {
new_finalization_offsets[i] += increment * apply_increments[i] * (forse_finalization_offsets[i] || force_ptr_increment);
new_finalization_offsets[i] += increment * apply_increments[i] * (force_finalization_offsets[i] || force_ptr_increment);
}
loop->set_finalization_offsets(new_finalization_offsets);
return true;
Expand Down
7 changes: 4 additions & 3 deletions src/common/snippets/src/op/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
using namespace std;
using namespace ngraph;

snippets::op::Buffer::Buffer(const Output<Node>& x, const size_t offset) :
Op({x}), m_offset(offset) {
snippets::op::Buffer::Buffer(const Output<Node>& x) : Op({x}) {
constructor_validate_and_infer_types();
}

Expand All @@ -26,7 +25,9 @@ bool snippets::op::Buffer::visit_attributes(AttributeVisitor& visitor) {
std::shared_ptr<Node> snippets::op::Buffer::clone_with_new_inputs(const OutputVector& new_args) const {
INTERNAL_OP_SCOPE(Buffer_clone_with_new_inputs);
check_new_args_count(this, new_args);
return std::make_shared<Buffer>(new_args.at(0), m_offset);
auto new_buffer = std::make_shared<Buffer>(new_args.at(0));
new_buffer->set_offset(m_offset);
return new_buffer;
}

void snippets::op::Buffer::validate_and_infer_types() {
Expand Down
2 changes: 1 addition & 1 deletion src/common/snippets/src/op/fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using namespace std;
using namespace ngraph;

snippets::op::Fill::Fill(const Output<Node>& x, const int64_t offset, const std::string fill_value)
snippets::op::Fill::Fill(const Output<Node>& x, const size_t offset, const uint32_t fill_value)
: Op({x}), m_offset(offset), m_fill_value(fill_value) {
constructor_validate_and_infer_types();
}
Expand Down
28 changes: 14 additions & 14 deletions src/common/snippets/src/op/loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ std::shared_ptr<LoopEnd> LoopBegin::get_loop_end() {
}

LoopEnd::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, std::vector<bool> forse_finalization_offsets)
std::vector<bool> apply_increment, std::vector<int64_t> finalization_offsets, std::vector<bool> force_finalization_offsets)
: LoopBase(args, dimension, work_amount, increment), apply_increment(std::move(apply_increment)),
finalization_offsets(std::move(finalization_offsets)), forse_finalization_offsets(std::move(forse_finalization_offsets)) {
finalization_offsets(std::move(finalization_offsets)), force_finalization_offsets(std::move(force_finalization_offsets)) {
constructor_validate_and_infer_types();
}

std::shared_ptr<Node> LoopEnd::clone_with_new_inputs(const OutputVector& inputs) const {
return std::make_shared<LoopEnd>(inputs, dimension, work_amount, increment, apply_increment, finalization_offsets, forse_finalization_offsets);
return std::make_shared<LoopEnd>(inputs, dimension, work_amount, increment, apply_increment, finalization_offsets, force_finalization_offsets);
}

std::shared_ptr<LoopBegin> LoopEnd::get_loop_begin() {
Expand All @@ -111,8 +111,8 @@ const std::vector<bool>& LoopEnd::get_apply_increment() const {
return apply_increment;
}

const std::vector<bool>& LoopEnd::get_forse_finalization_offsets() const {
return forse_finalization_offsets;
const std::vector<bool>& LoopEnd::get_force_finalization_offsets() const {
return force_finalization_offsets;
}

void LoopEnd::set_finalization_offsets(std::vector<int64_t> offsets) {
Expand All @@ -127,10 +127,10 @@ void LoopEnd::set_apply_increment(std::vector<bool> allow_increment) {
apply_increment = std::move(allow_increment);
}

void LoopEnd::set_forse_finalization_offsets(std::vector<bool> forse_finalization_offsets) {
if (forse_finalization_offsets.size() != loop_io_size)
throw std::invalid_argument("LoopEnd set_forse_finalization_offsets is called with inconsistent forse_finalization_offsets.size()");
forse_finalization_offsets = std::move(forse_finalization_offsets);
void LoopEnd::set_force_finalization_offsets(std::vector<bool> force_finalization_offsets) {
if (force_finalization_offsets.size() != loop_io_size)
throw std::invalid_argument("LoopEnd set_force_finalization_offsets is called with inconsistent force_finalization_offsets.size()");
force_finalization_offsets = std::move(force_finalization_offsets);
}

void LoopEnd::set_work_amount(size_t new_work_amount) {
Expand Down Expand Up @@ -163,15 +163,15 @@ void LoopEnd::validate_and_infer_types() {
NODE_VALIDATION_CHECK(this, finalization_offsets.empty() || finalization_offsets.size() == loop_io_size,
"finalization_offsets must be either empty or defined per every input & output of joined Loop. Expected size: ",
loop_io_size, " got ", finalization_offsets.size());
NODE_VALIDATION_CHECK(this, forse_finalization_offsets.empty() || forse_finalization_offsets.size() == loop_io_size,
"forse_finalization_offsets must be either empty or defined per every input & output of joined Loop. Expected size: ",
loop_io_size, " got ", forse_finalization_offsets.size());
NODE_VALIDATION_CHECK(this, force_finalization_offsets.empty() || force_finalization_offsets.size() == loop_io_size,
"force_finalization_offsets must be either empty or defined per every input & output of joined Loop. Expected size: ",
loop_io_size, " got ", force_finalization_offsets.size());
if (apply_increment.empty())
apply_increment.resize(loop_io_size, true);
if (finalization_offsets.empty())
finalization_offsets.resize(loop_io_size, 0);
if (forse_finalization_offsets.empty())
forse_finalization_offsets.resize(loop_io_size, true);
if (force_finalization_offsets.empty())
force_finalization_offsets.resize(loop_io_size, true);
set_output_size(num_inputs - 1);
const auto& ins = inputs();
// All outputs are by-passed from inputs, except for the last one - it connects LoopBegin and LoopEnd
Expand Down
4 changes: 2 additions & 2 deletions src/common/snippets/src/op/loop_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ std::shared_ptr<LoopEnd> insertLoopEndBeforeInputs(const std::vector<Input<Node>
size_t dimension, size_t work_amount, size_t increment,
std::vector<bool> apply_increment,
std::vector<int64_t> finalization_offsets,
std::vector<bool> forse_finalization_offsets) {
std::vector<bool> force_finalization_offsets) {
OutputVector originalParentOutputs;
for (const auto& in : originalInputs) {
originalParentOutputs.push_back(in.get_source_output());
}
originalParentOutputs.push_back(loopBegin->output(loopBegin->get_output_size() - 1));
auto loop_end = std::make_shared<LoopEnd>(originalParentOutputs, dimension, work_amount, increment,
std::move(apply_increment), std::move(finalization_offsets), std::move(forse_finalization_offsets));
std::move(apply_increment), std::move(finalization_offsets), std::move(force_finalization_offsets));

for (int i = 0; i < originalInputs.size(); i++) {
originalInputs[i].replace_source_output(loop_end->output(i));
Expand Down
6 changes: 3 additions & 3 deletions src/common/snippets/src/op/vector_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
using namespace std;
using namespace ngraph;

snippets::op::VectorBuffer::VectorBuffer() : Op() {
snippets::op::VectorBuffer::VectorBuffer(const ov::element::Type element_type) : Op(), m_element_type(std::move(element_type)) {
constructor_validate_and_infer_types();
}

std::shared_ptr<Node> snippets::op::VectorBuffer::clone_with_new_inputs(const OutputVector& new_args) const {
INTERNAL_OP_SCOPE(VectorBuffer_clone_with_new_inputs);
check_new_args_count(this, new_args);
return std::make_shared<VectorBuffer>();
return std::make_shared<VectorBuffer>(m_element_type);
}

void snippets::op::VectorBuffer::validate_and_infer_types() {
INTERNAL_OP_SCOPE(VectorBuffer_validate_and_infer_types);
set_output_type(0, ov::element::f32, Shape{1lu});
set_output_type(0, m_element_type, Shape{1lu});
}
8 changes: 4 additions & 4 deletions src/common/snippets/src/pass/insert_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ngraph::snippets::pass::InsertBuffer::InsertBuffer() {
bool rewritten = false;

// check if already has Buffer, Parameter or Constant as an input
for (auto input : root->inputs()) {
for (const auto& input : root->inputs()) {
const auto input_node = input.get_source_output().get_node()->shared_from_this();
if (!ov::is_type<ngraph::snippets::op::Buffer>(input_node) &&
!ov::is_type<ngraph::op::v0::Parameter>(input_node) &&
Expand All @@ -38,10 +38,10 @@ ngraph::snippets::pass::InsertBuffer::InsertBuffer() {
}

// check if already has Buffer or outputs is Result
for (auto output : root->outputs()) {
for (const auto& output : root->outputs()) {
const auto target_inputs = output.get_target_inputs();
if (target_inputs.size() > 1) {
for (auto consumer : target_inputs) {
for (const auto& consumer : target_inputs) {
const auto output_node = consumer.get_node()->shared_from_this();
if (ov::is_type<ngraph::snippets::op::Buffer>(output_node)) {
// If some of children from one common port are different Buffers,
Expand All @@ -63,7 +63,7 @@ ngraph::snippets::pass::InsertBuffer::InsertBuffer() {
}

const auto buffer = std::make_shared<ngraph::snippets::op::Buffer>(output);
for (auto consumer : output.get_target_inputs()) {
for (const auto& consumer : output.get_target_inputs()) {
const auto output_node = consumer.get_node()->shared_from_this();
if (output_node != buffer &&
!ov::is_type<ngraph::snippets::op::Buffer>(output_node) &&
Expand Down
Loading

0 comments on commit c32e7d6

Please sign in to comment.