Skip to content

Commit

Permalink
Optimize function builders
Browse files Browse the repository at this point in the history
  • Loading branch information
v-Golubev committed Sep 29, 2024
1 parent eb2d864 commit b1f9254
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 56 deletions.
57 changes: 6 additions & 51 deletions src/tests/ov_helpers/ov_snippets_models/src/subgraph_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ std::shared_ptr<ov::Model> ConvertFunction::initOriginal() const {
}
std::shared_ptr<ov::Model> ConvertFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(inType, input_shapes[0]);
auto indata0 = std::make_shared<op::v0::Parameter>(inType, data0->get_shape());
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0},
std::make_shared<ov::Model>(NodeVector{std::make_shared<op::v0::Convert>(indata0, outType)},
ParameterVector{indata0}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0});
}

Expand All @@ -41,13 +38,7 @@ std::shared_ptr<ov::Model> ConvertInputFunction::initOriginal() const {
std::shared_ptr<ov::Model> ConvertInputFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(inType, input_shapes[0]);
auto data1 = std::make_shared<op::v0::Parameter>(outType, input_shapes[1]);
auto indata0 = std::make_shared<op::v0::Parameter>(inType, data0->get_shape());
auto indata1 = std::make_shared<op::v0::Parameter>(outType, data1->get_shape());
auto convert = std::make_shared<op::v0::Convert>(indata0, outType);
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1},
std::make_shared<ov::Model>(
NodeVector{std::make_shared<op::v1::Add>(convert, indata1)},
ParameterVector{indata0, indata1}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0, data1});
}

Expand All @@ -61,14 +52,7 @@ std::shared_ptr<ov::Model> ConvertOutputFunction::initOriginal() const {
std::shared_ptr<ov::Model> ConvertOutputFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(inType, input_shapes[0]);
auto data1 = std::make_shared<op::v0::Parameter>(inType, input_shapes[1]);
auto indata0 = std::make_shared<op::v0::Parameter>(inType, data0->get_shape());
auto indata1 = std::make_shared<op::v0::Parameter>(inType, data1->get_shape());
auto add = std::make_shared<op::v1::Add>(indata0, indata1);
auto convert = std::make_shared<op::v0::Convert>(add, outType);
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1},
std::make_shared<ov::Model>(
NodeVector{convert},
ParameterVector{indata0, indata1}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0, data1});
}

Expand Down Expand Up @@ -132,15 +116,7 @@ std::shared_ptr<ov::Model> ConvertManyOnInputsFunction::initOriginal() const {
}
std::shared_ptr<ov::Model> ConvertManyOnInputsFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(types[0], input_shapes[0]);
auto indata0 = std::make_shared<op::v0::Parameter>(types[0], data0->get_shape());
std::shared_ptr<ov::Node> out = indata0;
for (auto i = 1; i < types.size(); i++) {
auto convert = std::make_shared<op::v0::Convert>(out, types[i]);
out = convert;
}
auto relu = std::make_shared<op::v0::Relu>(out);
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0},
std::make_shared<ov::Model>(NodeVector{relu}, ParameterVector{indata0}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0});
}

Expand All @@ -156,15 +132,7 @@ std::shared_ptr<ov::Model> ConvertManyOnOutputsFunction::initOriginal() const {
}
std::shared_ptr<ov::Model> ConvertManyOnOutputsFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(types[0], input_shapes[0]);
auto indata0 = std::make_shared<op::v0::Parameter>(types[0], data0->get_shape());
auto relu = std::make_shared<op::v0::Relu>(indata0);
std::shared_ptr<ov::Node> out = relu;
for (auto i = 1; i < types.size(); i++) {
auto convert = std::make_shared<op::v0::Convert>(out, types[i]);
out = convert;
}
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0},
std::make_shared<ov::Model>(NodeVector{out}, ParameterVector{indata0}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0});
}

Expand All @@ -185,20 +153,7 @@ std::shared_ptr<ov::Model> ConvertManyOnInputOutputFunction::initOriginal() cons
}
std::shared_ptr<ov::Model> ConvertManyOnInputOutputFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(inTypes[0], input_shapes[0]);
auto indata0 = std::make_shared<op::v0::Parameter>(inTypes[0], data0->get_shape());
std::shared_ptr<ov::Node> out = indata0;
for (auto i = 1; i < inTypes.size(); i++) {
auto convert = std::make_shared<op::v0::Convert>(out, inTypes[i]);
out = convert;
}
auto relu = std::make_shared<op::v0::Relu>(data0);
out = relu;
for (auto i = 0; i < outTypes.size(); i++) {
auto convert = std::make_shared<op::v0::Convert>(out, outTypes[i]);
out = convert;
}
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0},
std::make_shared<ov::Model>(NodeVector{out}, ParameterVector{indata0}));
auto subgraph = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{subgraph}, ParameterVector{data0});
}
} // namespace snippets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ std::shared_ptr<ov::Model> AddFunction::initOriginal() const {
std::shared_ptr<ov::Model> AddFunction::initReference() const {
auto data0 = std::make_shared<op::v0::Parameter>(precision, input_shapes[0]);
auto data1 = std::make_shared<op::v0::Parameter>(precision, input_shapes[1]);
auto indata0 = std::make_shared<op::v0::Parameter>(precision, data0->get_shape());
auto indata1 = std::make_shared<op::v0::Parameter>(precision, data1->get_shape());
auto add = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1},
std::make_shared<ov::Model>(NodeVector{std::make_shared<op::v1::Add>(indata0, indata1)},
ParameterVector{indata0, indata1}));
auto add = std::make_shared<ov::snippets::op::Subgraph>(NodeVector{data0, data1}, getOriginal());
return std::make_shared<ov::Model>(NodeVector{add}, ParameterVector{data0, data1});
}
std::shared_ptr<ov::Model> ExpFunction::initOriginal() const {
Expand Down

0 comments on commit b1f9254

Please sign in to comment.