forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CONFORMANCE] Extend Graph Cache by Fused names based extractor (open…
…vinotoolkit#18601) * Add fused names based subgraph extractor * fix test build
- Loading branch information
Showing
4 changed files
with
172 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ctional/plugin/conformance/subgraphs_dumper_new/include/matchers/subgraph/fused_names.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <utility> | ||
|
||
#include "matchers/subgraph/subgraph.hpp" | ||
|
||
namespace ov { | ||
namespace tools { | ||
namespace subgraph_dumper { | ||
|
||
class FusedNamesExtractor : public SubgraphExtractor { | ||
public: | ||
std::list<ExtractedPattern> extract(const std::shared_ptr<ov::Model> &model, | ||
bool is_extract_body = true) override; | ||
|
||
protected: | ||
std::unordered_set<std::string> extract_compiled_model_names(const std::shared_ptr<ov::Model>& model); | ||
}; | ||
|
||
} // namespace subgraph_dumper | ||
} // namespace tools | ||
} // namespace ov |
84 changes: 84 additions & 0 deletions
84
.../functional/plugin/conformance/subgraphs_dumper_new/src/matchers/subgraph/fused_names.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<std::string> | ||
FusedNamesExtractor::extract_compiled_model_names(const std::shared_ptr<ov::Model>& model) { | ||
auto core = ov::test::utils::PluginCache::get().core(); | ||
auto compiled_model = core->compile_model(model); | ||
std::unordered_set<std::string> 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<std::string>()); | ||
} | ||
} | ||
return compiled_op_name; | ||
} | ||
|
||
std::list<ExtractedPattern> | ||
FusedNamesExtractor::extract(const std::shared_ptr<ov::Model> &model, | ||
bool is_extract_body) { | ||
auto compiled_op_name = extract_compiled_model_names(model); | ||
std::list<ExtractedPattern> matched_patterns; | ||
std::unordered_set<std::string> checked_ops; | ||
std::set<std::shared_ptr<ov::Node>> nodes; | ||
std::shared_ptr<ov::Node> 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<ov::op::v0::TensorIterator>(op)) { | ||
auto ti = ov::as_type_ptr<ov::op::v0::TensorIterator>(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<ov::op::v5::Loop>(op)) { | ||
auto loop = ov::as_type_ptr<ov::op::v5::Loop>(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<ov::op::v8::If>(op)) { | ||
auto if_op = ov::as_type_ptr<ov::op::v8::If>(op); | ||
std::vector<std::shared_ptr<ov::Model>> 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; | ||
} |
57 changes: 57 additions & 0 deletions
57
...unctional/plugin/conformance/subgraphs_dumper_new/tests/matchers/subgraph/fused_names.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ov::Model>& model) { | ||
auto compiled_names = extract_compiled_model_names(model); | ||
std::set<std::string> 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 |