From 1daad56fd157be41e3238c843427a9cc3185d615 Mon Sep 17 00:00:00 2001 From: yvetteliu Date: Wed, 27 May 2020 16:30:57 +0800 Subject: [PATCH] perf_opt(manager): avoid generate anonymous function in every acquire node loop. --- mindspore/ccsrc/ir/manager.cc | 6 +++--- mindspore/ccsrc/ir/manager.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mindspore/ccsrc/ir/manager.cc b/mindspore/ccsrc/ir/manager.cc index a21a794fee2..2e47ce3f5a5 100644 --- a/mindspore/ccsrc/ir/manager.cc +++ b/mindspore/ccsrc/ir/manager.cc @@ -87,6 +87,8 @@ void FuncGraphManager::Reset() { func_graphs_used_total_ = std::make_shared(this); recursive_ = std::make_shared(this); j_total_ = std::make_shared(this); + + limit_ = std::bind(&FuncGraphManager::Limit, this, std::placeholders::_1); } void FuncGraphManager::Init() { @@ -359,9 +361,7 @@ IncludeType FuncGraphManager::Limit(const AnfNodePtr &node) { void FuncGraphManager::AcquireNodes(const std::vector &nodes) { AnfNodeSet acq; for (auto &node : nodes) { - std::function limit = std::bind(&FuncGraphManager::Limit, this, std::placeholders::_1); - - AnfNodeSet new_nodes = AnfNodeSet(DeepScopedGraphSearch(node, limit)); + AnfNodeSet new_nodes = AnfNodeSet(DeepScopedGraphSearch(node, limit_)); all_nodes_.update(new_nodes); acq.update(new_nodes); diff --git a/mindspore/ccsrc/ir/manager.h b/mindspore/ccsrc/ir/manager.h index d748a08593f..8c7524bb642 100644 --- a/mindspore/ccsrc/ir/manager.h +++ b/mindspore/ccsrc/ir/manager.h @@ -515,6 +515,7 @@ class FuncGraphManager : public std::enable_shared_from_this { std::shared_ptr j_total_; bool is_manage_; + std::function limit_; }; class FuncGraphTransaction {