From 8dc3403e8eb078998bb4d3e0f8be6b33fd346d83 Mon Sep 17 00:00:00 2001 From: Jitendra Patil Date: Wed, 8 Jan 2020 15:10:16 -0800 Subject: [PATCH 1/3] fix for mem leak --- ngraph_bridge/enable_variable_ops/ngraph_rewrite_pass.cc | 8 ++++++-- ngraph_bridge/grappler/ngraph_optimizer.cc | 9 ++++++--- ngraph_bridge/ngraph_rewrite_pass.cc | 8 ++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ngraph_bridge/enable_variable_ops/ngraph_rewrite_pass.cc b/ngraph_bridge/enable_variable_ops/ngraph_rewrite_pass.cc index ea97ff417..ee1dae9fa 100644 --- a/ngraph_bridge/enable_variable_ops/ngraph_rewrite_pass.cc +++ b/ngraph_bridge/enable_variable_ops/ngraph_rewrite_pass.cc @@ -226,8 +226,12 @@ class NGraphEncapsulationPass : public NGraphRewritePass { // 4. Encapsulate clusters then, if requested, dump the graphs. FunctionDefLibrary* fdeflib_new = new FunctionDefLibrary(); - TF_RETURN_IF_ERROR(EncapsulateClusters(options.graph->get(), idx, - fdeflib_new, config_map, {0, {}})); + auto status = EncapsulateClusters(options.graph->get(), idx, + fdeflib_new, config_map, {0, {}}); + if(status != Status::OK()){ + delete (fdeflib_new); + return status; + } // TODO: not using fdeflib_new in this path. Only grappler path uses it free(fdeflib_new); if (DumpEncapsulatedGraphs()) { diff --git a/ngraph_bridge/grappler/ngraph_optimizer.cc b/ngraph_bridge/grappler/ngraph_optimizer.cc index 279388bc1..b8bed45b9 100644 --- a/ngraph_bridge/grappler/ngraph_optimizer.cc +++ b/ngraph_bridge/grappler/ngraph_optimizer.cc @@ -260,9 +260,12 @@ Status NgraphOptimizer::Optimize(tensorflow::grappler::Cluster* cluster, // 4. Encapsulate clusters then, if requested, dump the graphs. FunctionDefLibrary* fdeflib_new = new FunctionDefLibrary(); - TF_RETURN_IF_ERROR( - // TODO: right now _ngraph_aot_requested is passed along in config_map. - EncapsulateClusters(&graph, idx, fdeflib_new, config_map, aot_info)); + // TODO: right now _ngraph_aot_requested is passed along in config_map. + auto status = EncapsulateClusters(&graph, idx, fdeflib_new, config_map, aot_info); + if (status != Status::OK()) { + delete (fdeflib_new); + return status; + } if (DumpEncapsulatedGraphs()) { DumpGraphs(graph, idx, "encapsulated", "Graph with Clusters Encapsulated"); } diff --git a/ngraph_bridge/ngraph_rewrite_pass.cc b/ngraph_bridge/ngraph_rewrite_pass.cc index 4af428980..3e1fcf2a0 100644 --- a/ngraph_bridge/ngraph_rewrite_pass.cc +++ b/ngraph_bridge/ngraph_rewrite_pass.cc @@ -230,8 +230,12 @@ class NGraphEncapsulationPass : public NGraphRewritePass { // 4. Encapsulate clusters then, if requested, dump the graphs. FunctionDefLibrary* fdeflib_new = new FunctionDefLibrary(); - TF_RETURN_IF_ERROR(EncapsulateClusters(options.graph->get(), idx, - fdeflib_new, config_map, {0, {}})); + auto status = EncapsulateClusters(options.graph->get(), idx, + fdeflib_new, config_map, {0, {}}); + if(status != Status::OK){ + delete (fdeflib_new); + return status; + } // TODO: not using fdeflib_new in this path. Only grappler path uses it delete (fdeflib_new); if (DumpEncapsulatedGraphs()) { From 96f105cf6eaeb500212fc5dc6f1189aa5eb59391 Mon Sep 17 00:00:00 2001 From: Jitendra Patil Date: Wed, 8 Jan 2020 15:21:55 -0800 Subject: [PATCH 2/3] minor fix --- ngraph_bridge/ngraph_rewrite_pass.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngraph_bridge/ngraph_rewrite_pass.cc b/ngraph_bridge/ngraph_rewrite_pass.cc index 3e1fcf2a0..a45c5b768 100644 --- a/ngraph_bridge/ngraph_rewrite_pass.cc +++ b/ngraph_bridge/ngraph_rewrite_pass.cc @@ -232,7 +232,7 @@ class NGraphEncapsulationPass : public NGraphRewritePass { FunctionDefLibrary* fdeflib_new = new FunctionDefLibrary(); auto status = EncapsulateClusters(options.graph->get(), idx, fdeflib_new, config_map, {0, {}}); - if(status != Status::OK){ + if(status != Status::OK()){ delete (fdeflib_new); return status; } From 70e64774e861be8557d9c3cf5c090656b2e3f764 Mon Sep 17 00:00:00 2001 From: "Patil, Jitendra" Date: Wed, 8 Jan 2020 15:32:30 -0800 Subject: [PATCH 3/3] code format fix --- ngraph_bridge/enable_variable_ops/ngraph_rewrite_pass.cc | 6 +++--- ngraph_bridge/grappler/ngraph_optimizer.cc | 3 ++- ngraph_bridge/ngraph_rewrite_pass.cc | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ngraph_bridge/enable_variable_ops/ngraph_rewrite_pass.cc b/ngraph_bridge/enable_variable_ops/ngraph_rewrite_pass.cc index ee1dae9fa..bc5ead221 100644 --- a/ngraph_bridge/enable_variable_ops/ngraph_rewrite_pass.cc +++ b/ngraph_bridge/enable_variable_ops/ngraph_rewrite_pass.cc @@ -226,9 +226,9 @@ class NGraphEncapsulationPass : public NGraphRewritePass { // 4. Encapsulate clusters then, if requested, dump the graphs. FunctionDefLibrary* fdeflib_new = new FunctionDefLibrary(); - auto status = EncapsulateClusters(options.graph->get(), idx, - fdeflib_new, config_map, {0, {}}); - if(status != Status::OK()){ + auto status = EncapsulateClusters(options.graph->get(), idx, fdeflib_new, + config_map, {0, {}}); + if (status != Status::OK()) { delete (fdeflib_new); return status; } diff --git a/ngraph_bridge/grappler/ngraph_optimizer.cc b/ngraph_bridge/grappler/ngraph_optimizer.cc index b8bed45b9..a9551d1b6 100644 --- a/ngraph_bridge/grappler/ngraph_optimizer.cc +++ b/ngraph_bridge/grappler/ngraph_optimizer.cc @@ -261,7 +261,8 @@ Status NgraphOptimizer::Optimize(tensorflow::grappler::Cluster* cluster, // 4. Encapsulate clusters then, if requested, dump the graphs. FunctionDefLibrary* fdeflib_new = new FunctionDefLibrary(); // TODO: right now _ngraph_aot_requested is passed along in config_map. - auto status = EncapsulateClusters(&graph, idx, fdeflib_new, config_map, aot_info); + auto status = + EncapsulateClusters(&graph, idx, fdeflib_new, config_map, aot_info); if (status != Status::OK()) { delete (fdeflib_new); return status; diff --git a/ngraph_bridge/ngraph_rewrite_pass.cc b/ngraph_bridge/ngraph_rewrite_pass.cc index a45c5b768..340001c28 100644 --- a/ngraph_bridge/ngraph_rewrite_pass.cc +++ b/ngraph_bridge/ngraph_rewrite_pass.cc @@ -230,9 +230,9 @@ class NGraphEncapsulationPass : public NGraphRewritePass { // 4. Encapsulate clusters then, if requested, dump the graphs. FunctionDefLibrary* fdeflib_new = new FunctionDefLibrary(); - auto status = EncapsulateClusters(options.graph->get(), idx, - fdeflib_new, config_map, {0, {}}); - if(status != Status::OK()){ + auto status = EncapsulateClusters(options.graph->get(), idx, fdeflib_new, + config_map, {0, {}}); + if (status != Status::OK()) { delete (fdeflib_new); return status; }