Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Code style #5

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div align="center">
<div align="center">
<img src="docs/sphinx_setup/_static/images/img/openvino-logo-purple-black.png" width="400px">

[![PyPI Status](https://badge.fury.io/py/openvino.svg)](https://badge.fury.io/py/openvino)
Expand Down
130 changes: 61 additions & 69 deletions src/core/tests/pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "openvino/op/reduce_sum.hpp"
#include "openvino/op/relu.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/strided_slice.hpp"
#include "openvino/op/transpose.hpp"
#include "openvino/op/util/op_types.hpp"
#include "openvino/pass/graph_rewrite.hpp"
#include "openvino/pass/manager.hpp"
Expand Down Expand Up @@ -72,7 +74,7 @@ static std::shared_ptr<pattern::op::Label> construct_mean_graph() {
return mean_label;
}

class TestGraphRewrite : public ov::pass::GraphRewrite {
class testGraphRewrite : public ov::pass::GraphRewrite {
public:
void construct_multiply_by_one() {
// pattern #1 : a * 1 = a
Expand Down Expand Up @@ -191,7 +193,7 @@ class TestGraphRewrite : public ov::pass::GraphRewrite {
this->add_matcher(match_pass);
}

TestGraphRewrite() : GraphRewrite() {
testGraphRewrite() : GraphRewrite() {
construct_multiply_by_one();
construct_add_zero();
}
Expand All @@ -207,7 +209,7 @@ static void run_passes(pass::Manager& pass_manager,
TEST(pattern, graph_rewrite) {
Shape shape{};
pass::Manager pass_manager;
pass_manager.register_pass<TestGraphRewrite>();
pass_manager.register_pass<testGraphRewrite>();

{
auto a = make_shared<op::v0::Parameter>(element::i32, shape);
Expand Down Expand Up @@ -487,7 +489,7 @@ TEST(pattern, matcher) {
}
}

TEST(pattern, matching_optional) {
TEST(pattern, optional_single_in) {
Shape shape{};
auto a = make_shared<op::v0::Parameter>(element::i32, shape);
auto b = make_shared<op::v0::Parameter>(element::i32, shape);
Expand All @@ -501,94 +503,84 @@ TEST(pattern, matching_optional) {
ASSERT_TRUE(n.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Relu>(d), std::make_shared<op::v0::Relu>(c)));
ASSERT_TRUE(n.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Relu>(d), std::make_shared<op::v0::Abs>(c)));
ASSERT_FALSE(
n.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Relu>(d), std::make_shared<op::v0::Result>(c)));
n.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Relu>(d), std::make_shared<op::v0::Exp>(c)));
ASSERT_FALSE(
n.match(ov::pass::pattern::optional<op::v0::Exp, op::v0::Cos>(d), std::make_shared<op::v0::Abs>(c)));

const auto predicate = [](const Output<Node>& output) {
return false;
};
ASSERT_FALSE(n.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Relu>(d, predicate),
ASSERT_FALSE(n.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Relu>({d}, predicate),
std::make_shared<op::v0::Abs>(c)));
}

// Optional is not working properly yet CVS-136454
TEST(pattern, DISABLED_optional_full_match) {
TEST(pattern, optional_multi_in_cumulative_op) {
Shape shape{};
auto model_input = std::make_shared<op::v0::Parameter>(element::i32, shape);
auto model_relu = std::make_shared<op::v0::Relu>(model_input);
auto model_relu1 = std::make_shared<op::v0::Relu>(model_relu->output(0));

auto pattern_relu = ov::pass::pattern::optional<op::v0::Relu>();
auto pattern_relu1 = std::make_shared<op::v0::Relu>(pattern_relu->output(0));

TestMatcher tm;
auto a = make_shared<op::v0::Parameter>(element::i32, shape);
auto b = make_shared<op::v0::Parameter>(element::i32, shape);
auto c = std::make_shared<op::v1::Add>(a, b);

ASSERT_TRUE(tm.match(pattern_relu1, model_relu1));
TestMatcher n;
ASSERT_TRUE(n.match(ov::pass::pattern::optional<op::v1::Add>(ov::OutputVector{a,b}), c));
ASSERT_TRUE(n.match(ov::pass::pattern::optional<op::v1::Add>(ov::OutputVector{b, a}), c));
ASSERT_FALSE(n.match(ov::pass::pattern::optional<op::v1::Add>(ov::OutputVector{a}), c));
ASSERT_FALSE(n.match(ov::pass::pattern::optional<op::v1::Add>(ov::OutputVector{b}), c));
ASSERT_TRUE(n.match(ov::pass::pattern::optional<op::v1::Add>(ov::OutputVector{a,b}), a));
ASSERT_TRUE(n.match(ov::pass::pattern::optional<op::v1::Add>(ov::OutputVector{a,b}), b));
}

// Optional is not working properly yet CVS-136454
TEST(pattern, DISABLED_optional_half_match) {
Shape shape{};
auto model_input = std::make_shared<op::v0::Parameter>(element::i32, shape);
auto model_relu = std::make_shared<op::v0::Relu>(model_input);
auto model_relu1 = std::make_shared<op::v0::Relu>(model_relu->output(0));

auto pattern_abs = ov::pass::pattern::optional<op::v0::Abs>();
auto pattern_relu = std::make_shared<op::v0::Relu>(pattern_abs->output(0));
TEST(pattern, optional_multi_in_order_important) {
Shape shape{2, 3, 4};
auto a = make_shared<op::v0::Parameter>(element::f32, shape);
auto b = make_shared<op::v0::Constant>(element::i32, ov::Shape{3}, std::vector<int>{2, 0, 1});
auto c = std::make_shared<op::v1::Transpose>(a, b);

TestMatcher tm;

ASSERT_TRUE(tm.match(pattern_relu, model_relu1));
TestMatcher n;
ASSERT_TRUE(n.match(ov::pass::pattern::optional<op::v1::Transpose>(ov::OutputVector{a,b}), c));
ASSERT_FALSE(n.match(ov::pass::pattern::optional<op::v1::Transpose>(ov::OutputVector{b, a}), c));
ASSERT_FALSE(n.match(ov::pass::pattern::optional<op::v1::Transpose>(ov::OutputVector{a}), c));
ASSERT_FALSE(n.match(ov::pass::pattern::optional<op::v1::Transpose>(ov::OutputVector{b}), c));
ASSERT_TRUE(n.match(ov::pass::pattern::optional<op::v1::Transpose>(ov::OutputVector{a,b}), a));
ASSERT_TRUE(n.match(ov::pass::pattern::optional<op::v1::Transpose>(ov::OutputVector{a,b}), b));
}

// Optional is not working properly yet CVS-136454
TEST(pattern, DISABLED_optional_testing) {
TEST(pattern, optional_multi_in_pattern_matching) {
Shape shape{};
auto model_input1 = std::make_shared<op::v0::Parameter>(element::i32, shape);
auto model_input2 = std::make_shared<op::v0::Parameter>(element::i32, shape);
auto model_add = std::make_shared<op::v1::Add>(model_input1->output(0), model_input2->output(0));
auto model_relu = std::make_shared<op::v0::Relu>(model_add->output(0));
auto model_abs = std::make_shared<op::v0::Abs>(model_add->output(0));
auto model_input_0 = std::make_shared<op::v0::Parameter>(element::i32, shape);
auto model_input_1 = std::make_shared<op::v0::Parameter>(element::i32, shape);
auto model_add = std::make_shared<op::v1::Add>(model_input_0, model_input_1);
auto model_add_reverse = std::make_shared<op::v1::Add>(model_input_1, model_input_0);
auto model_relu_with_add = std::make_shared<op::v0::Relu>(model_add);
auto model_relu_with_add_reverse = std::make_shared<op::v0::Relu>(model_add_reverse);
auto model_relu_without_add_0 = std::make_shared<op::v0::Relu>(model_input_0);
auto model_relu_without_add_1 = std::make_shared<op::v0::Relu>(model_input_1);

auto pattern_input_0 = ov::pass::pattern::any_input();
auto pattern_input_1 = ov::pass::pattern::any_input();
auto pattern_add = ov::pass::pattern::optional<op::v1::Add>(ov::OutputVector{pattern_input_0, pattern_input_1});
auto pattern_relu = std::make_shared<op::v0::Relu>(pattern_add->output(0));

TestMatcher tm;

ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Exp, op::v0::Relu>(model_add), model_add));
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Relu>(model_add), model_add));
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Exp>(model_add), model_add));
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Exp, op::v0::Cos>(model_add), model_add));

ASSERT_TRUE(
tm.match(ov::pass::pattern::optional<op::v0::Abs>(model_abs), std::make_shared<op::v0::Abs>(model_abs)));
ASSERT_FALSE(
tm.match(ov::pass::pattern::optional<op::v0::Abs>(model_abs), std::make_shared<op::v0::Relu>(model_abs)));
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Relu>(model_abs),
std::make_shared<op::v0::Relu>(model_abs)));

ASSERT_FALSE(tm.match(ov::pass::pattern::optional<op::v0::Exp>(model_add), model_abs));
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Exp, op::v0::Abs>(model_add), model_abs));

ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Relu>(model_relu),
std::make_shared<op::v0::Relu>(std::make_shared<op::v0::Relu>(model_add))));

ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Relu>(model_relu),
std::make_shared<op::v0::Relu>(std::make_shared<op::v0::Relu>(model_add))));
ASSERT_TRUE(tm.match(pattern_relu, model_relu_with_add));
ASSERT_TRUE(tm.match(pattern_relu, model_relu_with_add_reverse));
ASSERT_TRUE(tm.match(pattern_relu, model_relu_without_add_0));
ASSERT_TRUE(tm.match(pattern_relu, model_relu_without_add_1));
}

// Optional is not working properly yet CVS-136454
TEST(pattern, DISABLED_optional_one_node) {
TEST(pattern, optional_single_in_pattern_matching) {
Shape shape{};
auto model_input = std::make_shared<op::v0::Parameter>(element::i32, shape);
auto model_relu = std::make_shared<op::v0::Relu>(model_input);
auto model_abs = std::make_shared<op::v0::Abs>(model_input);

TestMatcher tm;
auto model_abs_with_relu = std::make_shared<op::v0::Abs>(model_relu);
auto model_abs_without_relu = std::make_shared<op::v0::Abs>(model_input);

ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Relu>(), model_relu));
ASSERT_FALSE(tm.match(ov::pass::pattern::optional<op::v0::Abs>(), model_relu));
auto pattern_input = ov::pass::pattern::any_input();
auto pattern_relu = ov::pass::pattern::optional<op::v0::Relu>(pattern_input);
auto pattern_abs = std::make_shared<op::v0::Abs>(pattern_relu);

ASSERT_FALSE(tm.match(ov::pass::pattern::optional<op::v0::Relu>(), model_abs));

ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Parameter>(), model_input));
ASSERT_FALSE(tm.match(ov::pass::pattern::optional<op::v0::Relu>(), model_input));
TestMatcher tm;
ASSERT_TRUE(tm.match(pattern_abs, model_abs_with_relu));
ASSERT_TRUE(tm.match(pattern_abs, model_abs_without_relu));
}

TEST(pattern, mean) {
Expand Down Expand Up @@ -813,4 +805,4 @@ TEST(pattern, wrap_type_multi_op) {
ASSERT_FALSE(matcher->match(static_pointer_cast<Node>(b)));
ASSERT_FALSE(matcher->match(static_pointer_cast<Node>(c)));
}
}
}
Loading