Skip to content

Commit

Permalink
[CONFORMANCE] Fix memory leak in Subgraphs Dumper (#19172)
Browse files Browse the repository at this point in the history
* [CONFORMANCE] Fix memory leak in Subgraphs Dumper

* Update fused_names.cpp

* Change inheritance of extractors

* Check graph cache

* Enable Op cache
  • Loading branch information
iefode authored Aug 15, 2023
1 parent 5ff67fc commit 043cd86
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class iMatcherConfig {
explicit iMatcherConfig(bool is_fallback_config) : is_fallback_config(is_fallback_config) {}

iMatcherConfig(
std::vector<std::string> ignored_attributes,
std::vector<size_t> ignored_ports,
const std::vector<std::string>& ignored_attributes,
const std::vector<size_t>& 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<std::string> ignored_attributes;
Expand All @@ -43,8 +43,10 @@ struct MatcherConfig : public iMatcherConfig {
public:
MatcherConfig() : iMatcherConfig(sizeof...(OPTypes) == 0) {}

MatcherConfig(std::vector<std::string> ignored_attributes, std::vector<size_t> ignored_ports, bool ignore_matching = false) :
iMatcherConfig(std::move(ignored_attributes), std::move(ignored_ports), sizeof...(OPTypes) == 0, ignore_matching) {}
MatcherConfig(const std::vector<std::string>& ignored_attributes,
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) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtractedPattern> extract(const std::shared_ptr<ov::Model> &model,
bool is_extract_body = true) override;
void set_target_device(const std::string& _device) { device = _device; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ FusedNamesExtractor::FusedNamesExtractor() {
device = *(core->get_available_devices().begin());
}

FusedNamesExtractor::~FusedNamesExtractor() {
core.reset();
}

std::list<ExtractedPattern>
FusedNamesExtractor::extract(const std::shared_ptr<ov::Model> &model,
bool is_extract_body) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ov::Model>& 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtractedPattern>& models,
const std::vector<std::shared_ptr<ov::Model>>& 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;
Expand All @@ -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));
}
Expand Down

0 comments on commit 043cd86

Please sign in to comment.