From 043cd86449f59e2c78a27ea28ca980a87069b919 Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Tue, 15 Aug 2023 17:24:17 +0400 Subject: [PATCH] [CONFORMANCE] Fix memory leak in Subgraphs Dumper (#19172) * [CONFORMANCE] Fix memory leak in Subgraphs Dumper * Update fused_names.cpp * Change inheritance of extractors * Check graph cache * Enable Op cache --- .../include/cache/graph_cache.hpp | 4 ++-- .../include/matchers/single_op/config.hpp | 20 ++++++++++--------- .../include/matchers/subgraph/fused_names.hpp | 4 +++- .../matchers/subgraph/repeat_pattern.hpp | 2 +- .../src/matchers/subgraph/fused_names.cpp | 4 ++++ .../tests/matchers/subgraph/fused_names.cpp | 9 +++++---- .../matchers/subgraph/repeat_pattern.cpp | 13 ++++++------ 7 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/graph_cache.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/graph_cache.hpp index 198afd52803dff..dcd72018004c8e 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/graph_cache.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/cache/graph_cache.hpp @@ -49,8 +49,8 @@ class GraphCache : public ICache { GraphCache() { ExtractorsManager::ExtractorsMap matchers = { // temporary disabling according mem leaks in CI and not using swap mem - // { "fused_names", FusedNamesExtractor::Ptr(new FusedNamesExtractor) }, - // { "repeat_pattern", RepeatPatternExtractor::Ptr(new RepeatPatternExtractor) }, + { "fused_names", FusedNamesExtractor::Ptr(new FusedNamesExtractor) }, + { "repeat_pattern", RepeatPatternExtractor::Ptr(new RepeatPatternExtractor) }, }; m_manager.set_extractors(matchers); } diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/config.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/config.hpp index b037de93ad91dc..ccec23b90d4807 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/config.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/single_op/config.hpp @@ -20,14 +20,14 @@ class iMatcherConfig { explicit iMatcherConfig(bool is_fallback_config) : is_fallback_config(is_fallback_config) {} iMatcherConfig( - std::vector ignored_attributes, - std::vector ignored_ports, + const std::vector& ignored_attributes, + const std::vector& ignored_ports, bool is_fallback_config, - bool ignore_matching = false) - : ignored_attributes(std::move(ignored_attributes)), - ignored_ports(std::move(ignored_ports)), - is_fallback_config(is_fallback_config), - ignore_matching(ignore_matching) {} + bool ignore_matching = false) : + ignored_attributes(ignored_attributes), + ignored_ports(ignored_ports), + is_fallback_config(is_fallback_config), + ignore_matching(ignore_matching) {} // Empty vectors stands for any of possible values std::vector ignored_attributes; @@ -43,8 +43,10 @@ struct MatcherConfig : public iMatcherConfig { public: MatcherConfig() : iMatcherConfig(sizeof...(OPTypes) == 0) {} - MatcherConfig(std::vector ignored_attributes, std::vector ignored_ports, bool ignore_matching = false) : - iMatcherConfig(std::move(ignored_attributes), std::move(ignored_ports), sizeof...(OPTypes) == 0, ignore_matching) {} + MatcherConfig(const std::vector& ignored_attributes, + const std::vector& ignored_ports, + bool ignore_matching = false) : + iMatcherConfig(ignored_attributes, ignored_ports, sizeof...(OPTypes) == 0, ignore_matching) {} MatcherConfig(bool ignore_matching) : iMatcherConfig({}, {}, sizeof...(OPTypes) == 0, ignore_matching) {} diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/fused_names.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/fused_names.hpp index dfc2a7dc995a08..60cacf3a753e17 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/fused_names.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/fused_names.hpp @@ -12,9 +12,11 @@ namespace ov { namespace tools { namespace subgraph_dumper { -class FusedNamesExtractor : public SubgraphExtractor { +class FusedNamesExtractor final : public SubgraphExtractor { public: FusedNamesExtractor(); + ~FusedNamesExtractor(); + std::list extract(const std::shared_ptr &model, bool is_extract_body = true) override; void set_target_device(const std::string& _device) { device = _device; } diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/repeat_pattern.hpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/repeat_pattern.hpp index de6c18e85940d8..e003a94ba61d57 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/repeat_pattern.hpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/include/matchers/subgraph/repeat_pattern.hpp @@ -14,7 +14,7 @@ namespace ov { namespace tools { namespace subgraph_dumper { -class RepeatPatternExtractor : public SubgraphExtractor { +class RepeatPatternExtractor final : public SubgraphExtractor { public: RepeatPatternExtractor() { MatchersManager::MatchersMap matchers = { diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/fused_names.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/fused_names.cpp index 3eef3eb5b5b896..a00361ab322b12 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/fused_names.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/matchers/subgraph/fused_names.cpp @@ -31,6 +31,10 @@ FusedNamesExtractor::FusedNamesExtractor() { device = *(core->get_available_devices().begin()); } +FusedNamesExtractor::~FusedNamesExtractor() { + core.reset(); +} + std::list FusedNamesExtractor::extract(const std::shared_ptr &model, bool is_extract_body) { diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/fused_names.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/fused_names.cpp index 591f01c66cd52f..f83c34bbe9ce43 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/fused_names.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/fused_names.cpp @@ -20,12 +20,13 @@ using namespace ov::tools::subgraph_dumper; // ======================= ExtractorsManagerTest Unit tests ======================= -class FusedNamesExtractorTest : public FusedNamesExtractor, - public SubgraphsDumperBaseTest { +class FusedNamesExtractorTest : public SubgraphsDumperBaseTest { + FusedNamesExtractor extractor; + protected: void is_match(const std::shared_ptr& model) { - auto models_1 = this->extract(model); - auto models_2 = this->extract(model); + auto models_1 = extractor.extract(model); + auto models_2 = extractor.extract(model); ASSERT_EQ(models_1.size(), models_2.size()); auto it_model_1 = models_1.begin(); auto it_model_2 = models_2.begin(); diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/repeat_pattern.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/repeat_pattern.cpp index a9da7845f1098c..7bb49decaeaab7 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/repeat_pattern.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/tests/matchers/subgraph/repeat_pattern.cpp @@ -18,16 +18,17 @@ using namespace ov::tools::subgraph_dumper; // ======================= ExtractorsManagerTest Unit tests ======================= -class RepeatPatternExtractorTest : public RepeatPatternExtractor, - public SubgraphsDumperBaseTest { +class RepeatPatternExtractorTest : public SubgraphsDumperBaseTest { protected: + RepeatPatternExtractor extractor; + bool is_match(const std::list& models, const std::vector>& ref_models) { size_t match_numbers = 0; for (const auto& model : models) { bool is_match = false; for (const auto& ref_model : ref_models) { - if (this->match(std::get<0>(model), ref_model)) { + if (extractor.match(std::get<0>(model), ref_model)) { is_match = true; ++match_numbers; break; @@ -43,21 +44,21 @@ class RepeatPatternExtractorTest : public RepeatPatternExtractor, TEST_F(RepeatPatternExtractorTest, extract_0) { auto test_model = Model_0(); - auto models = this->extract(test_model.get()); + auto models = extractor.extract(test_model.get()); auto ref = test_model.get_repeat_pattern_ref(); ASSERT_TRUE(is_match(models, ref)); } TEST_F(RepeatPatternExtractorTest, extract_1) { auto test_model = Model_1(); - auto models = this->extract(test_model.get()); + auto models = extractor.extract(test_model.get()); auto ref = test_model.get_repeat_pattern_ref(); ASSERT_TRUE(is_match(models, ref)); } TEST_F(RepeatPatternExtractorTest, extract_2) { auto test_model = Model_2(); - auto models = this->extract(test_model.get()); + auto models = extractor.extract(test_model.get()); auto ref = test_model.get_repeat_pattern_ref(); ASSERT_TRUE(is_match(models, ref)); }