Skip to content

Commit

Permalink
[Snippets] [CPU] Serialization/Deserialization enabled (#14064)
Browse files Browse the repository at this point in the history
  • Loading branch information
v-Golubev authored Nov 30, 2022
1 parent a296a50 commit 9eb43bb
Show file tree
Hide file tree
Showing 31 changed files with 427 additions and 146 deletions.
13 changes: 0 additions & 13 deletions src/common/snippets/include/snippets/op/broadcastload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,9 @@ class BroadcastLoad : public BroadcastMove {
BroadcastLoad(const Output<Node>& x, Shape output_shape);
BroadcastLoad() = default;

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;

void set_broadcast_info(const Shape& bct) {
broadcast_info = bct;
}

bool is_broadcast(size_t idx) {
return broadcast_info[idx] == 1;
}

private:
Shape broadcast_info;
};

} // namespace op
Expand Down
1 change: 1 addition & 0 deletions src/common/snippets/include/snippets/op/powerstatic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace op {
class PowerStatic : public ov::op::util::UnaryElementwiseArithmetic {
public:
OPENVINO_OP("PowerStatic", "SnippetsOpset", ov::op::util::UnaryElementwiseArithmetic);
BWDCMP_RTTI_DECLARATION;

PowerStatic() = default;
PowerStatic(const Output <Node> &arg, float power) : UnaryElementwiseArithmetic(arg), power(power) {
Expand Down
3 changes: 3 additions & 0 deletions src/common/snippets/include/snippets/op/scalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace op {
class Scalar : public ov::op::v0::Constant {
public:
OPENVINO_OP("Scalar", "SnippetsOpset", ov::op::v0::Constant);
BWDCMP_RTTI_DECLARATION;

Scalar() = default;

template <class T, class = typename std::enable_if<std::is_fundamental<T>::value>::type>
Scalar(const element::Type& type, Shape shape, T value) : Constant(type, shape, value) {
Expand Down
34 changes: 28 additions & 6 deletions src/common/snippets/include/snippets/op/subgraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <memory>

#include <openvino/core/model.hpp>
#include <openvino/op/util/sub_graph_base.hpp>
#include <ngraph/op/op.hpp>
#include <ngraph/rt_info.hpp>
#include <ngraph/pass/manager.hpp>
Expand All @@ -22,9 +23,10 @@ namespace op {
* @brief An operation that is implemented by a model
* @ingroup snippets
*/
class Subgraph : public ngraph::op::Op {
class Subgraph : public ov::op::util::SubGraphOp {
public:
OPENVINO_OP("Subgraph", "SnippetsOpset");
OPENVINO_OP("Subgraph", "SnippetsOpset", ov::op::util::SubGraphOp);
BWDCMP_RTTI_DECLARATION;

// < 1, 42, 17, 15, 16> < 0, 1, 2, 3, 1>
// should be:
Expand Down Expand Up @@ -70,6 +72,8 @@ class Subgraph : public ngraph::op::Op {
using BlockedShape = std::tuple<ngraph::Shape, ngraph::AxisVector, ngraph::element::Type>;
using BlockedShapeVector = std::vector<BlockedShape>;

Subgraph() = default;

Subgraph(const OutputVector& args, std::shared_ptr<ov::Model> body);

Subgraph(const NodeVector& args, std::shared_ptr<ov::Model> body);
Expand All @@ -80,11 +84,29 @@ class Subgraph : public ngraph::op::Op {

std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& inputs) const override;

std::shared_ptr<ov::Model> get_body() const {
return m_body;
// we introduce this method instead of using SubGraphOp::get_function()
// to align naming with other methods
const std::shared_ptr<ov::Model> & body_ptr() const {
return m_bodies[0];
}

std::shared_ptr<ov::Model> & body_ptr() {
return m_bodies[0];
}

std::shared_ptr<ngraph::snippets::Generator> get_generator() const {
const ov::Model & body() const {
return *m_bodies[0];
}

ov::Model & body() {
return *m_bodies[0];
}

const std::shared_ptr<ngraph::snippets::Generator> & get_generator() const {
return m_generator;
}

std::shared_ptr<ngraph::snippets::Generator> & get_generator() {
return m_generator;
}

Expand Down Expand Up @@ -123,13 +145,13 @@ class Subgraph : public ngraph::op::Op {
private:
void align_element_types(const BlockedShapeVector& outputShapes, const BlockedShapeVector& inputShapes);
void convert_to_snippet_dialect();

// 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()),
// we should MANUALLY calculate it where it needed.
size_t m_non_scalar_constants_count = 0;
Shape exec_domain = {};
std::shared_ptr<ov::Model> m_body = nullptr;
std::shared_ptr<ngraph::snippets::Generator> m_generator = nullptr;

// TODO: Change logic of insert Converts. This exec element type can be different for plugins
Expand Down
10 changes: 2 additions & 8 deletions src/common/snippets/src/op/broadcastload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@ using namespace std;
using namespace ngraph;

snippets::op::BroadcastLoad::BroadcastLoad(const Output<Node>& x, Shape shape)
: BroadcastMove(x, shape), broadcast_info(x.get_shape().size(), 0) {
: BroadcastMove(x, shape) {
constructor_validate_and_infer_types();
}

bool snippets::op::BroadcastLoad::visit_attributes(AttributeVisitor& visitor) {
return true;
}

std::shared_ptr<Node> snippets::op::BroadcastLoad::clone_with_new_inputs(const OutputVector& new_args) const {
INTERNAL_OP_SCOPE(BroadcastLoad);
check_new_args_count(this, new_args);
auto other = std::make_shared<BroadcastLoad>(new_args.at(0), output_shape);
other->set_broadcast_info(this->broadcast_info);
return other;
return std::make_shared<BroadcastLoad>(new_args.at(0), output_shape);
}

void snippets::op::BroadcastLoad::validate_and_infer_types() {
Expand Down
1 change: 1 addition & 0 deletions src/common/snippets/src/op/broadcastmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ snippets::op::BroadcastMove::BroadcastMove(const Output<Node>& x, Shape shape) :
}

bool snippets::op::BroadcastMove::visit_attributes(AttributeVisitor& visitor) {
visitor.on_attribute("output_shape", output_shape);
return true;
}

Expand Down
15 changes: 15 additions & 0 deletions src/common/snippets/src/op/powerstatic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "snippets/op/powerstatic.hpp"

namespace ngraph {
namespace snippets {
namespace op {

BWDCMP_RTTI_DEFINITION(PowerStatic);

} // namespace op
} // namespace snippets
} // namespace ngraph
2 changes: 2 additions & 0 deletions src/common/snippets/src/op/scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

using namespace ngraph;

BWDCMP_RTTI_DEFINITION(snippets::op::Scalar);

std::shared_ptr<Node> snippets::op::Scalar::clone_with_new_inputs(const OutputVector& new_args) const {
check_new_args_count(this, new_args);
return std::make_shared<Scalar>(*this);
Expand Down
Loading

0 comments on commit 9eb43bb

Please sign in to comment.