[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
This commit is contained in:
Irina Efode 2023-08-15 17:24:17 +04:00 committed by GitHub
parent 5ff67fca40
commit 043cd86449
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 23 deletions

View File

@ -49,8 +49,8 @@ protected:
GraphCache() { GraphCache() {
ExtractorsManager::ExtractorsMap matchers = { ExtractorsManager::ExtractorsMap matchers = {
// temporary disabling according mem leaks in CI and not using swap mem // temporary disabling according mem leaks in CI and not using swap mem
// { "fused_names", FusedNamesExtractor::Ptr(new FusedNamesExtractor) }, { "fused_names", FusedNamesExtractor::Ptr(new FusedNamesExtractor) },
// { "repeat_pattern", RepeatPatternExtractor::Ptr(new RepeatPatternExtractor) }, { "repeat_pattern", RepeatPatternExtractor::Ptr(new RepeatPatternExtractor) },
}; };
m_manager.set_extractors(matchers); m_manager.set_extractors(matchers);
} }

View File

@ -20,14 +20,14 @@ public:
explicit iMatcherConfig(bool is_fallback_config) : is_fallback_config(is_fallback_config) {} explicit iMatcherConfig(bool is_fallback_config) : is_fallback_config(is_fallback_config) {}
iMatcherConfig( iMatcherConfig(
std::vector<std::string> ignored_attributes, const std::vector<std::string>& ignored_attributes,
std::vector<size_t> ignored_ports, const std::vector<size_t>& ignored_ports,
bool is_fallback_config, bool is_fallback_config,
bool ignore_matching = false) bool ignore_matching = false) :
: ignored_attributes(std::move(ignored_attributes)), ignored_attributes(ignored_attributes),
ignored_ports(std::move(ignored_ports)), ignored_ports(ignored_ports),
is_fallback_config(is_fallback_config), is_fallback_config(is_fallback_config),
ignore_matching(ignore_matching) {} ignore_matching(ignore_matching) {}
// Empty vectors stands for any of possible values // Empty vectors stands for any of possible values
std::vector<std::string> ignored_attributes; std::vector<std::string> ignored_attributes;
@ -43,8 +43,10 @@ struct MatcherConfig : public iMatcherConfig {
public: public:
MatcherConfig() : iMatcherConfig(sizeof...(OPTypes) == 0) {} MatcherConfig() : iMatcherConfig(sizeof...(OPTypes) == 0) {}
MatcherConfig(std::vector<std::string> ignored_attributes, std::vector<size_t> ignored_ports, bool ignore_matching = false) : MatcherConfig(const std::vector<std::string>& ignored_attributes,
iMatcherConfig(std::move(ignored_attributes), std::move(ignored_ports), sizeof...(OPTypes) == 0, ignore_matching) {} const std::vector<size_t>& 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) {} MatcherConfig(bool ignore_matching) : iMatcherConfig({}, {}, sizeof...(OPTypes) == 0, ignore_matching) {}

View File

@ -12,9 +12,11 @@ namespace ov {
namespace tools { namespace tools {
namespace subgraph_dumper { namespace subgraph_dumper {
class FusedNamesExtractor : public SubgraphExtractor { class FusedNamesExtractor final : public SubgraphExtractor {
public: public:
FusedNamesExtractor(); FusedNamesExtractor();
~FusedNamesExtractor();
std::list<ExtractedPattern> extract(const std::shared_ptr<ov::Model> &model, std::list<ExtractedPattern> extract(const std::shared_ptr<ov::Model> &model,
bool is_extract_body = true) override; bool is_extract_body = true) override;
void set_target_device(const std::string& _device) { device = _device; } void set_target_device(const std::string& _device) { device = _device; }

View File

@ -14,7 +14,7 @@ namespace ov {
namespace tools { namespace tools {
namespace subgraph_dumper { namespace subgraph_dumper {
class RepeatPatternExtractor : public SubgraphExtractor { class RepeatPatternExtractor final : public SubgraphExtractor {
public: public:
RepeatPatternExtractor() { RepeatPatternExtractor() {
MatchersManager::MatchersMap matchers = { MatchersManager::MatchersMap matchers = {

View File

@ -31,6 +31,10 @@ FusedNamesExtractor::FusedNamesExtractor() {
device = *(core->get_available_devices().begin()); device = *(core->get_available_devices().begin());
} }
FusedNamesExtractor::~FusedNamesExtractor() {
core.reset();
}
std::list<ExtractedPattern> std::list<ExtractedPattern>
FusedNamesExtractor::extract(const std::shared_ptr<ov::Model> &model, FusedNamesExtractor::extract(const std::shared_ptr<ov::Model> &model,
bool is_extract_body) { bool is_extract_body) {

View File

@ -20,12 +20,13 @@ using namespace ov::tools::subgraph_dumper;
// ======================= ExtractorsManagerTest Unit tests ======================= // ======================= ExtractorsManagerTest Unit tests =======================
class FusedNamesExtractorTest : public FusedNamesExtractor, class FusedNamesExtractorTest : public SubgraphsDumperBaseTest {
public SubgraphsDumperBaseTest { FusedNamesExtractor extractor;
protected: protected:
void is_match(const std::shared_ptr<ov::Model>& model) { void is_match(const std::shared_ptr<ov::Model>& model) {
auto models_1 = this->extract(model); auto models_1 = extractor.extract(model);
auto models_2 = this->extract(model); auto models_2 = extractor.extract(model);
ASSERT_EQ(models_1.size(), models_2.size()); ASSERT_EQ(models_1.size(), models_2.size());
auto it_model_1 = models_1.begin(); auto it_model_1 = models_1.begin();
auto it_model_2 = models_2.begin(); auto it_model_2 = models_2.begin();

View File

@ -18,16 +18,17 @@ using namespace ov::tools::subgraph_dumper;
// ======================= ExtractorsManagerTest Unit tests ======================= // ======================= ExtractorsManagerTest Unit tests =======================
class RepeatPatternExtractorTest : public RepeatPatternExtractor, class RepeatPatternExtractorTest : public SubgraphsDumperBaseTest {
public SubgraphsDumperBaseTest {
protected: protected:
RepeatPatternExtractor extractor;
bool is_match(const std::list<ExtractedPattern>& models, bool is_match(const std::list<ExtractedPattern>& models,
const std::vector<std::shared_ptr<ov::Model>>& ref_models) { const std::vector<std::shared_ptr<ov::Model>>& ref_models) {
size_t match_numbers = 0; size_t match_numbers = 0;
for (const auto& model : models) { for (const auto& model : models) {
bool is_match = false; bool is_match = false;
for (const auto& ref_model : ref_models) { 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; is_match = true;
++match_numbers; ++match_numbers;
break; break;
@ -43,21 +44,21 @@ protected:
TEST_F(RepeatPatternExtractorTest, extract_0) { TEST_F(RepeatPatternExtractorTest, extract_0) {
auto test_model = Model_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(); auto ref = test_model.get_repeat_pattern_ref();
ASSERT_TRUE(is_match(models, ref)); ASSERT_TRUE(is_match(models, ref));
} }
TEST_F(RepeatPatternExtractorTest, extract_1) { TEST_F(RepeatPatternExtractorTest, extract_1) {
auto test_model = Model_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(); auto ref = test_model.get_repeat_pattern_ref();
ASSERT_TRUE(is_match(models, ref)); ASSERT_TRUE(is_match(models, ref));
} }
TEST_F(RepeatPatternExtractorTest, extract_2) { TEST_F(RepeatPatternExtractorTest, extract_2) {
auto test_model = Model_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(); auto ref = test_model.get_repeat_pattern_ref();
ASSERT_TRUE(is_match(models, ref)); ASSERT_TRUE(is_match(models, ref));
} }