Skip to content

Commit

Permalink
[Snippets] Added Softmax support
Browse files Browse the repository at this point in the history
  • Loading branch information
a-sidorova committed Oct 12, 2022
1 parent d4e9547 commit f3760b3
Show file tree
Hide file tree
Showing 41 changed files with 1,408 additions and 153 deletions.
38 changes: 38 additions & 0 deletions src/common/snippets/include/snippets/op/buffer.hpp
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 Buffer
* @brief TODO
* @ingroup snippets
*/
class Buffer : public ngraph::op::Op {
public:
OPENVINO_OP("Buffer", "SnippetsOpset");

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

size_t get_offset() const;
void set_offset(const size_t offset);

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:
size_t offset;
};

} // namespace op
} // namespace snippets
} // namespace ngraph
44 changes: 44 additions & 0 deletions src/common/snippets/include/snippets/op/fill.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 Fill
* @brief TODO
* @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() = default;

int64_t get_offset() const { return m_offset; }
std::string 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; }

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";
};

} // namespace op
} // namespace snippets
} // namespace ngraph
33 changes: 33 additions & 0 deletions src/common/snippets/include/snippets/op/horizon_max.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 HorizonMax
* @brief TODO
* @ingroup snippets
*/
class HorizonMax : public ngraph::op::Op {
public:
OPENVINO_OP("HorizonMax", "SnippetsOpset");

HorizonMax(const Output<Node>& x);
HorizonMax() = default;

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;
};

} // namespace op
} // namespace snippets
} // namespace ngraph
32 changes: 32 additions & 0 deletions src/common/snippets/include/snippets/op/horizon_sum.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 HorizonSum
* @brief TODO
* @ingroup snippets
*/
class HorizonSum : public ngraph::op::Op {
public:
OPENVINO_OP("HorizonSum", "SnippetsOpset");

HorizonSum(const Output<Node>& x);
HorizonSum() = default;

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;
};

} // namespace op
} // namespace snippets
} // namespace ngraph
6 changes: 5 additions & 1 deletion src/common/snippets/include/snippets/op/load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ namespace op {
* @brief Generated by Canonicalization step 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
* TODO: ADD DESCRIPTION OF PARAMS
* @ingroup snippets
*/
class Load : public ngraph::op::Op {
public:
OPENVINO_OP("Load", "SnippetsOpset");

Load(const Output<Node>& x, const size_t count = 1lu);
Load(const Output<Node>& x, const size_t count = 1lu, const size_t offset = 0lu);
Load() = default;

size_t get_count() const { return m_count; }
size_t get_offset() const { return m_offset; }

void set_count(const size_t count) { m_count = count; }
void set_offset(const size_t offset) { m_offset = offset; }

bool visit_attributes(AttributeVisitor& visitor) override;

Expand All @@ -40,6 +43,7 @@ class Load : public ngraph::op::Op {

protected:
size_t m_count = 0lu;
size_t m_offset = 0lu;
};

} // namespace op
Expand Down
5 changes: 4 additions & 1 deletion src/common/snippets/include/snippets/op/store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class Store : public ngraph::op::Op {
public:
OPENVINO_OP("Store", "SnippetsOpset");

Store(const Output<Node>& x, const size_t count = 1lu);
Store(const Output<Node>& x, const size_t count = 1lu, const size_t offset = 0lu);
Store() = default;

size_t get_count() const { return m_count; }
size_t get_offset() const { return m_offset; }

void set_count(const size_t count) { m_count = count; }
void set_offset(const size_t offset) { m_offset = offset; }

bool visit_attributes(AttributeVisitor& visitor) override;

Expand All @@ -40,6 +42,7 @@ class Store : public ngraph::op::Op {

protected:
size_t m_count = 0lu;
size_t m_offset = 0lu;
};

} // namespace op
Expand Down
18 changes: 7 additions & 11 deletions src/common/snippets/include/snippets/op/subgraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,10 @@ class Subgraph : public ngraph::op::Op {
return m_generator;
}

size_t get_non_scalar_constants_count() const {
return m_non_scalar_constants_count;
}

bool is_quantized() const {
return config.m_is_quantized;
}

bool has_type_relaxed_ops() const {
return config.m_has_type_relaxed_ops;
}
size_t get_buffer_scratchpad_size() const;
size_t get_non_scalar_constants_count() const { return m_non_scalar_constants_count; }
bool is_quantized() const { return config.m_is_quantized; }
bool has_type_relaxed_ops() const { return config.m_has_type_relaxed_ops; }

snippets::Schedule generate(const BlockedShapeVector& output_shapes, const BlockedShapeVector& input_shapes, ngraph::pass::Manager& opt,
const void* compile_params = nullptr);
Expand Down Expand Up @@ -128,6 +121,7 @@ class Subgraph : public ngraph::op::Op {
private:
void align_element_types(const BlockedShapeVector& outputShapes, const BlockedShapeVector& inputShapes);
void convert_to_snippet_dialect();
void init_config();
// Count of potentional non-scalar Consants that will be created after some tranformations
// At the moment it's relevant only for FakeQuantize decomposition
// NOTE: To avoid overheads in each calcution of this count (for example, in validate_and_type_infer()),
Expand All @@ -150,6 +144,8 @@ class Subgraph : public ngraph::op::Op {
// True if Subgraph contains TypeRelaxed nodes -> for several streams in tp mode we should copy body using mutexes
// because TypeRelaxed::copy_with_new_inputs() isn't save-thread method
bool m_has_type_relaxed_ops = false;
// True if we should check runtime info for nodes to call specific needed transformations
bool m_check_rt_info = false;
} config;

ov::PartialShape master_shape;
Expand Down
31 changes: 31 additions & 0 deletions src/common/snippets/include/snippets/op/vector_buffer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 Buffer
* @brief TODO
* @ingroup snippets
*/
class VectorBuffer : public ngraph::op::Op {
public:
OPENVINO_OP("VectorBuffer", "SnippetsOpset");

VectorBuffer();

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;
};

} // namespace op
} // namespace snippets
} // namespace ngraph
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <ngraph/pass/graph_rewrite.hpp>
#include <ngraph/pattern/matcher.hpp>

namespace ngraph {
namespace snippets {
namespace pass {

/**
* @interface SoftmaxDecomposition
* @brief TODO
* @ingroup snippets
*/
class SoftmaxDecomposition: public ngraph::pass::MatcherPass {
public:
SoftmaxDecomposition(const size_t vector_size);
};

} // namespace pass
} // namespace snippets
} // namespace ngraph
5 changes: 5 additions & 0 deletions src/common/snippets/include/snippets/snippets_isa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

#include "op/broadcastload.hpp"
#include "op/broadcastmove.hpp"
#include "op/buffer.hpp"
#include "op/convert_saturation.hpp"
#include "op/convert_truncation.hpp"
#include "op/horizon_max.hpp"
#include "op/horizon_sum.hpp"
#include "op/fill.hpp"
#include "op/kernel.hpp"
#include "op/load.hpp"
#include "op/nop.hpp"
Expand All @@ -19,6 +23,7 @@
#include "op/store.hpp"
#include "op/tile.hpp"
#include "op/tile_scheduler.hpp"
#include "op/vector_buffer.hpp"

namespace ngraph {
namespace snippets {
Expand Down
Loading

0 comments on commit f3760b3

Please sign in to comment.