diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper_new/include/cache/graph_cache.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper_new/include/cache/graph_cache.hpp index e9bb0733b7a..34152237203 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper_new/include/cache/graph_cache.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper_new/include/cache/graph_cache.hpp @@ -9,6 +9,7 @@ #include "cache/meta/input_info.hpp" #include "matchers/subgraph/manager.hpp" #include "matchers/subgraph/subgraph.hpp" +#include "matchers/subgraph/fused_names.hpp" namespace ov { namespace tools { @@ -16,8 +17,7 @@ namespace subgraph_dumper { class GraphCache : public ICache { public: - void update_cache(const std::shared_ptr& model, - const std::string& model_meta_data, + void update_cache(const std::shared_ptr& model, const std::string& model_meta_data, bool extract_body = true) override; void serialize_cache() override; @@ -43,7 +43,9 @@ protected: static std::shared_ptr m_cache_instance; GraphCache() { - ExtractorsManager::ExtractorsMap matchers = {}; + ExtractorsManager::ExtractorsMap matchers = { + { "fused_names", FusedNamesExtractor::Ptr(new FusedNamesExtractor) }, + }; m_manager.set_extractors(matchers); } diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper_new/include/matchers/subgraph/fused_names.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper_new/include/matchers/subgraph/fused_names.hpp new file mode 100644 index 00000000000..84e5a88bd87 --- /dev/null +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper_new/include/matchers/subgraph/fused_names.hpp @@ -0,0 +1,26 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include "matchers/subgraph/subgraph.hpp" + +namespace ov { +namespace tools { +namespace subgraph_dumper { + +class FusedNamesExtractor : public SubgraphExtractor { +public: + std::list extract(const std::shared_ptr &model, + bool is_extract_body = true) override; + +protected: + std::unordered_set extract_compiled_model_names(const std::shared_ptr& model); +}; + +} // namespace subgraph_dumper +} // namespace tools +} // namespace ov diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper_new/src/matchers/subgraph/fused_names.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper_new/src/matchers/subgraph/fused_names.cpp new file mode 100644 index 00000000000..876e520cb67 --- /dev/null +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper_new/src/matchers/subgraph/fused_names.cpp @@ -0,0 +1,84 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/op/lstm_cell.hpp" +#include "openvino/op/tensor_iterator.hpp" +#include "openvino/op/if.hpp" + +#include "functional_test_utils/ov_plugin_cache.hpp" + +#include "matchers/subgraph/fused_names.hpp" +#include "utils/model.hpp" + +using namespace ov::tools::subgraph_dumper; + +std::unordered_set +FusedNamesExtractor::extract_compiled_model_names(const std::shared_ptr& model) { + auto core = ov::test::utils::PluginCache::get().core(); + auto compiled_model = core->compile_model(model); + std::unordered_set compiled_op_name; + for (const auto& compiled_op : compiled_model.get_runtime_model()->get_ordered_ops()) { + const auto& rt_info = compiled_op->get_rt_info(); + if (rt_info.count("originalLayersNames")) { + compiled_op_name.insert(rt_info.find("originalLayersNames")->second.as()); + } + } + return compiled_op_name; +} + +std::list +FusedNamesExtractor::extract(const std::shared_ptr &model, + bool is_extract_body) { + auto compiled_op_name = extract_compiled_model_names(model); + std::list matched_patterns; + std::unordered_set checked_ops; + std::set> nodes; + std::shared_ptr start_node = nullptr; + for (const auto& op : model->get_ordered_ops()) { + auto op_name = op->get_friendly_name(); + if (is_node_to_skip(op) || checked_ops.count(op_name)) { + continue; + } + if (start_node == nullptr) { + start_node = op; + } + nodes.insert(op); + if (is_extract_body) { + if (std::dynamic_pointer_cast(op)) { + auto ti = ov::as_type_ptr(op); + auto ti_body = ti->get_function(); + auto tmp_res = extract(ti_body); + matched_patterns.insert(matched_patterns.end(), tmp_res.begin(), tmp_res.end()); + } else if (std::dynamic_pointer_cast(op)) { + auto loop = ov::as_type_ptr(op); + auto loop_body = loop->get_function(); + auto tmp_res = extract(loop_body); + matched_patterns.insert(matched_patterns.end(), tmp_res.begin(), tmp_res.end()); + } else if (std::dynamic_pointer_cast(op)) { + auto if_op = ov::as_type_ptr(op); + std::vector> bodies; + for (size_t i = 0; i < if_op->get_internal_subgraphs_size(); i++) { + auto if_body = if_op->get_function(i); + auto tmp_res = extract(if_body); + matched_patterns.insert(matched_patterns.end(), tmp_res.begin(), tmp_res.end()); + } + } + } + if (!compiled_op_name.count(op_name)) { + try { + matched_patterns.push_back(generate_model(nodes, start_node, checked_ops)); + } catch(std::exception& e) { + std::cout << e.what() << std::endl; + } + start_node = nullptr; + nodes.clear(); + } + } + try { + matched_patterns.push_back(generate_model(nodes, start_node, checked_ops)); + } catch(std::exception& e) { + std::cout << e.what() << std::endl; + } + return matched_patterns; +} diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper_new/tests/matchers/subgraph/fused_names.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper_new/tests/matchers/subgraph/fused_names.cpp new file mode 100644 index 00000000000..73d037cfcd4 --- /dev/null +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper_new/tests/matchers/subgraph/fused_names.cpp @@ -0,0 +1,57 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +//// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "gtest/gtest.h" + +#include "matchers/subgraph/fused_names.hpp" +#include "utils/model.hpp" + +#include "test_models/model_0.hpp" +#include "test_models/model_1.hpp" +#include "test_models/model_2.hpp" + +namespace { + +using namespace ov::tools::subgraph_dumper; + + +// ======================= ExtractorsManagerTest Unit tests ======================= +class FusedNamesExtractorTest : public FusedNamesExtractor, + public ::testing::Test { +protected: + bool is_match(const std::shared_ptr& model) { + auto compiled_names = extract_compiled_model_names(model); + std::set diff; + for (const auto& op : model->get_ordered_ops()) { + auto op_name = op->get_friendly_name(); + if (!compiled_names.count(op_name)) { + diff.insert(op_name); + } + } + auto models = this->extract(model); + return diff.size() == 0 ? true : models.size() + 2 == diff.size(); + } +}; + +TEST_F(FusedNamesExtractorTest, extract_0) { + auto test_model = Model_0(); + auto model = test_model.get(); + ASSERT_TRUE(is_match(model)); +} + +TEST_F(FusedNamesExtractorTest, extract_1) { + auto test_model = Model_1(); + auto model = test_model.get(); + ASSERT_TRUE(is_match(model)); +} + +TEST_F(FusedNamesExtractorTest, extract_2) { + auto test_model = Model_2(); + auto model = test_model.get(); + ASSERT_TRUE(is_match(model)); +} + +} // namespace