Skip to content

Commit

Permalink
Delete outdated pass::patterns: Skip, Branch, Capture (openvinotoolki…
Browse files Browse the repository at this point in the history
…t#25223)

### Details:
Branch, Capture, Skip pass::patterns are outdated and not really applied
in the project

### Tickets:
N/A
  • Loading branch information
itikhono authored Jun 27, 2024
1 parent 107bbdd commit b80e30c
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 275 deletions.
1 change: 0 additions & 1 deletion src/core/include/openvino/pass/pattern/matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "openvino/pass/pattern/op/any_of.hpp"
#include "openvino/pass/pattern/op/any_output.hpp"
#include "openvino/pass/pattern/op/label.hpp"
#include "openvino/pass/pattern/op/skip.hpp"

namespace ov {
namespace pass {
Expand Down
52 changes: 0 additions & 52 deletions src/core/include/openvino/pass/pattern/op/branch.hpp

This file was deleted.

43 changes: 0 additions & 43 deletions src/core/include/openvino/pass/pattern/op/capture.hpp

This file was deleted.

43 changes: 0 additions & 43 deletions src/core/include/openvino/pass/pattern/op/skip.hpp

This file was deleted.

13 changes: 0 additions & 13 deletions src/core/src/pattern/op/branch.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions src/core/src/pattern/op/capture.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions src/core/src/pattern/op/skip.cpp

This file was deleted.

93 changes: 0 additions & 93 deletions src/core/tests/pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "openvino/pass/graph_rewrite.hpp"
#include "openvino/pass/manager.hpp"
#include "openvino/pass/pattern/matcher.hpp"
#include "openvino/pass/pattern/op/branch.hpp"
#include "openvino/pass/pattern/op/label.hpp"
#include "openvino/pass/pattern/op/optional.hpp"
#include "openvino/pass/pattern/op/or.hpp"
Expand Down Expand Up @@ -310,16 +309,10 @@ TEST(pattern, matcher) {
ASSERT_EQ(n.get_matched_nodes(), (NodeVector{a}));

auto abs = make_shared<op::v0::Abs>(a);
auto any = std::make_shared<pattern::op::Skip>(a);
ASSERT_TRUE(n.match(any, abs));
ASSERT_EQ(n.get_matched_nodes(), (NodeVector{abs, a}));

auto false_pred = [](std::shared_ptr<Node> /* no */) {
return false;
};
auto any_false = std::make_shared<pattern::op::Skip>(a, false_pred);
ASSERT_TRUE(n.match(any_false, a));
ASSERT_EQ(n.get_matched_nodes(), (NodeVector{a, a}));

auto pattern = std::make_shared<pattern::op::Label>(a);
ASSERT_TRUE(n.match(pattern, a));
Expand Down Expand Up @@ -371,39 +364,6 @@ TEST(pattern, matcher) {
ASSERT_FALSE(n.match(std::make_shared<op::v1::Add>(abs, b), std::make_shared<op::v1::Add>(b, b)));
ASSERT_EQ(n.get_matched_nodes(), (NodeVector{}));

auto add_absb = std::make_shared<op::v1::Add>(abs, b);
ASSERT_TRUE(n.match(std::make_shared<op::v1::Add>(any, b), add_absb));
ASSERT_EQ(n.get_matched_nodes(), (NodeVector{add_absb, abs, a, b}));

ASSERT_TRUE(n.match(std::make_shared<op::v1::Add>(pattern, b), add_absb));
ASSERT_EQ(n.get_pattern_map()[pattern], abs);
ASSERT_EQ(n.get_matched_nodes(), (NodeVector{add_absb, abs, b}));

ASSERT_TRUE(n.match(std::make_shared<op::v1::Add>(b, pattern), add_absb));
ASSERT_EQ(n.get_pattern_map()[pattern], abs);
ASSERT_EQ(n.get_matched_nodes(), (NodeVector{add_absb, abs, b}));

auto c = make_shared<op::v0::Parameter>(element::i32, shape);
auto mul_add_absb = std::make_shared<op::v1::Multiply>(c, add_absb);
ASSERT_TRUE(
n.match(std::make_shared<op::v1::Multiply>(c, std::make_shared<op::v1::Add>(b, pattern)), mul_add_absb));
ASSERT_EQ(n.get_pattern_map()[pattern], abs);
ASSERT_EQ(n.get_matched_nodes(), (NodeVector{mul_add_absb, c, add_absb, abs, b}));

ASSERT_TRUE(n.match(std::make_shared<op::v1::Multiply>(c, std::make_shared<op::v1::Add>(any, b)),
mul_add_absb)); // nested any
ASSERT_EQ(n.get_matched_nodes(), (NodeVector{mul_add_absb, c, add_absb, abs, a, b}));
ASSERT_TRUE(n.match(std::make_shared<op::v1::Multiply>(c, std::make_shared<op::v1::Add>(any, b)),
std::make_shared<op::v1::Multiply>(std::make_shared<op::v1::Add>(b, abs),
c))); // permutations w/ any
auto mul_c_add_ab = make_shared<op::v1::Multiply>(c, add_ab);
ASSERT_TRUE(n.match(std::make_shared<op::v1::Multiply>(c, std::make_shared<op::v1::Add>(any_false, b)),
std::make_shared<op::v1::Multiply>(c, std::make_shared<op::v1::Add>(a, b)))); //
// nested any
ASSERT_TRUE(n.match(std::make_shared<op::v1::Multiply>(c, std::make_shared<op::v1::Add>(any_false, b)),
mul_c_add_ab)); // permutations w/ any_false
ASSERT_EQ(n.get_matched_nodes(), (NodeVector{mul_c_add_ab, c, add_ab, a, a, b}));

auto iconst1_0 = construct_constant_node(1);
auto iconst1_1 = construct_constant_node(1);
ASSERT_TRUE(n.match(make_shared<op::v1::Multiply>(pattern, iconst1_0),
Expand Down Expand Up @@ -462,18 +422,6 @@ TEST(pattern, matcher) {
std::make_shared<op::v1::Subtract>(a, b)}),
std::make_shared<op::v1::Subtract>(a, b)));

// Branch
{
auto branch = std::make_shared<pattern::op::Branch>();
auto star = std::make_shared<pattern::op::Or>(OutputVector{branch, std::make_shared<pattern::op::True>()});
auto pattern = std::make_shared<op::v1::Add>(star, star);
branch->set_destination(pattern);
auto arg =
std::make_shared<op::v1::Add>(std::make_shared<op::v1::Add>(a, b), std::make_shared<op::v1::Add>(b, a));
ASSERT_TRUE(n.match(pattern, std::make_shared<op::v1::Add>(arg, a)));
ASSERT_EQ(n.get_matched_nodes().size(), 4);
}

// strict mode
{
TestMatcher sm(Output<Node>{}, "TestMatcher", true);
Expand Down Expand Up @@ -959,47 +907,6 @@ TEST(pattern, test_sort) {
}
}

TEST(pattern, label_on_skip) {
const auto zero = std::string{"0"};
const auto is_zero = [&zero](const Output<Node>& node) {
if (const auto c = as_type_ptr<op::v0::Constant>(node.get_node_shared_ptr())) {
return (c->get_all_data_elements_bitwise_identical() && c->convert_value_to_string(0) == zero);
} else {
return false;
}
};

Shape shape{2, 2};
auto a = make_shared<op::v0::Parameter>(element::i32, shape);
auto b = make_shared<op::v0::Parameter>(element::i32, Shape{});
auto iconst = op::v0::Constant::create(element::i32, Shape{}, {0.0f});
auto label = std::make_shared<pattern::op::Label>(iconst);
auto const_label = std::make_shared<pattern::op::Label>(iconst, is_zero, NodeVector{iconst});

auto bcst_pred = [](std::shared_ptr<Node> n) {
return ov::as_type_ptr<op::v1::Broadcast>(n) != nullptr;
};

auto shape_const = ov::op::v0::Constant::create(element::u64, Shape{shape.size()}, shape);
auto axes_const = ov::op::v0::Constant::create(element::u8, Shape{}, {0});
auto bcst = std::make_shared<pattern::op::Skip>(OutputVector{const_label, shape_const, axes_const}, bcst_pred);
auto bcst_label = std::make_shared<pattern::op::Label>(bcst, nullptr, NodeVector{bcst});
auto matcher =
std::make_shared<pattern::Matcher>(std::make_shared<op::v1::Multiply>(label, bcst_label), "label_on_skip");

auto const_broadcast = make_shared<op::v1::Broadcast>(iconst, shape_const);
std::shared_ptr<Node> mul = std::make_shared<op::v1::Multiply>(a, const_broadcast);
std::shared_ptr<Node> mul_scalar = std::make_shared<op::v1::Multiply>(b, iconst);
ASSERT_TRUE(matcher->match(mul));
ASSERT_EQ(matcher->get_pattern_map()[bcst_label], const_broadcast);
ASSERT_EQ(matcher->get_pattern_map()[const_label], iconst);
ASSERT_EQ(matcher->get_pattern_map()[label], a);
ASSERT_TRUE(matcher->match(mul_scalar));
ASSERT_EQ(matcher->get_pattern_map()[bcst_label], iconst);
ASSERT_EQ(matcher->get_pattern_map()[const_label], iconst);
ASSERT_EQ(matcher->get_pattern_map()[label], b);
}

TEST(pattern, is_contained_match) {
Shape shape{};
auto a = make_shared<op::v0::Parameter>(element::i32, shape);
Expand Down

0 comments on commit b80e30c

Please sign in to comment.