!6465 fix issue about memory leak when while cases running together

Merge pull request !6465 from wenchunjiang/fix_memory_leak
This commit is contained in:
mindspore-ci-bot 2020-09-18 15:34:22 +08:00 committed by Gitee
commit 91f87d22f4
3 changed files with 15 additions and 0 deletions

View File

@ -565,6 +565,7 @@ void AscendControlParser::RecurseCall(NotNull<KernelGraphPtr> kg, NotNull<CNodeP
cur_node->set_inputs(new_inputs);
cur_node->set_abstract(nullptr);
AnfAlgo::SetNodeAttr(kAttrChildGraph, MakeValue<std::vector<KernelGraphPtr>>({call_kg}), cur_node.get());
kg->RemoveNodeFromGraph(origin_inputs[kCNodeCallArg]);
origin_inputs.assign(origin_inputs.begin() + kCNodeCallArg + 1, origin_inputs.end());
AttachOriginalInputsToGraph(kg, origin_inputs);
MS_LOG(INFO) << "Succeed processing call func " << cur_node->DebugString();

View File

@ -1188,6 +1188,19 @@ void KernelGraph::UpdateChildGraphOrder() {
child_graph_order_ = child_graph_order;
}
void KernelGraph::RemoveNodeFromGraph(const AnfNodePtr &node) {
if (backend_front_anf_map_.find(node) != backend_front_anf_map_.end()) {
auto front_node = backend_front_anf_map_[node];
(void)backend_front_anf_map_.erase(node);
(void)front_backend_anf_map_.erase(front_node);
}
if (node->isa<ValueNode>()) {
if (graph_value_nodes_.find(node->cast<ValueNodePtr>()) != graph_value_nodes_.end()) {
(void)graph_value_nodes_.erase(node->cast<ValueNodePtr>());
}
}
}
std::string KernelGraph::ToString() const { return std::string("kernel_graph_").append(std::to_string(graph_id_)); }
KernelGraph::~KernelGraph() {

View File

@ -174,6 +174,7 @@ class KernelGraph : public FuncGraph {
return nullptr;
}
}
void RemoveNodeFromGraph(const AnfNodePtr &node);
private:
// remove value node form graph