Skip to content

Commit

Permalink
rm bad stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
akashchi committed Mar 25, 2024
1 parent 5995f9a commit 0e3f712
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 69 deletions.
4 changes: 1 addition & 3 deletions samples/cpp/build_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ usage() {
}

samples_type="$(basename "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")"
samples_build_dir=$HOME/openvino_${samples_type}_samples_build
samples_build_dir="$HOME/openvino_${samples_type}_samples_build"
sample_install_dir=""

somebadthing

# parse command line options
while [[ $# -gt 0 ]]
do
Expand Down
128 changes: 68 additions & 60 deletions src/core/tests/pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#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 @@ -74,7 +72,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 @@ -193,7 +191,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 @@ -209,7 +207,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 @@ -489,7 +487,7 @@ TEST(pattern, matcher) {
}
}

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

TEST(pattern, optional_multi_in_cumulative_op) {
// Optional is not working properly yet CVS-136454
TEST(pattern, DISABLED_optional_full_match) {
Shape shape{};
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);
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));

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

ASSERT_TRUE(tm.match(pattern_relu1, model_relu1));
}

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);
// 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));

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));
auto pattern_abs = ov::pass::pattern::optional<op::v0::Abs>();
auto pattern_relu = std::make_shared<op::v0::Relu>(pattern_abs->output(0));

TestMatcher tm;

ASSERT_TRUE(tm.match(pattern_relu, model_relu1));
}

TEST(pattern, optional_multi_in_pattern_matching) {
// Optional is not working properly yet CVS-136454
TEST(pattern, DISABLED_optional_testing) {
Shape shape{};
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));
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));

TestMatcher tm;
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));

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

TEST(pattern, optional_single_in_pattern_matching) {
// Optional is not working properly yet CVS-136454
TEST(pattern, DISABLED_optional_one_node) {
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_with_relu = std::make_shared<op::v0::Abs>(model_relu);
auto model_abs_without_relu = std::make_shared<op::v0::Abs>(model_input);

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);
auto model_abs = std::make_shared<op::v0::Abs>(model_input);

TestMatcher tm;
ASSERT_TRUE(tm.match(pattern_abs, model_abs_with_relu));
ASSERT_TRUE(tm.match(pattern_abs, model_abs_without_relu));

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

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

TEST(pattern, mean) {
Expand Down
12 changes: 6 additions & 6 deletions src/frontends/tensorflow/src/translate_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ namespace ov {
namespace frontend {
namespace tensorflow {

struct cachedBodyModelSignature {
struct CachedBodyModelSignature {
std::string body_name;
std::vector<ov::PartialShape> input_shapes;
std::vector<ov::element::Type> input_types;

bool operator==(const cachedBodyModelSignature& other) const {
bool operator==(const CachedBodyModelSignature& other) const {
return (body_name == other.body_name && input_shapes == other.input_shapes && input_types == other.input_types);
}
};

struct cachedBodyModelSignatureHasher {
std::size_t operator()(const cachedBodyModelSignature& k) const {
struct CachedBodyModelSignatureHasher {
std::size_t operator()(const CachedBodyModelSignature& k) const {
return std::hash<std::string>()(k.body_name);
}
};

using CachedBodyModelsType =
std::unordered_map<cachedBodyModelSignature, std::shared_ptr<const ov::Model>, cachedBodyModelSignatureHasher>;
std::unordered_map<CachedBodyModelSignature, std::shared_ptr<const ov::Model>, CachedBodyModelSignatureHasher>;

/// For one call of convert and decode method of Frontend, it creates one TranslateSession object to save data for the
/// translation session: telemetry statistics, cache of convrted body graph models, operation translators (including
Expand Down Expand Up @@ -63,7 +63,7 @@ class TranslateSession {
// the same topology can be converted with different shapes and types so it will be cached separately
std::shared_ptr<CachedBodyModelsType> m_cached_body_models;

void update_cached_body_models(const cachedBodyModelSignature& cached_body_model_signature,
void update_cached_body_models(const CachedBodyModelSignature& cached_body_model_signature,
const std::shared_ptr<const ov::Model>& cached_body_model) {
m_cached_body_models->insert(std::make_pair(cached_body_model_signature, cached_body_model));
}
Expand Down

0 comments on commit 0e3f712

Please sign in to comment.