From 3f87464e9c40ed21fe0e7cddb1e482e8246a1182 Mon Sep 17 00:00:00 2001 From: Zeng Jinle <32832641+sneaxiy@users.noreply.github.com> Date: Wed, 18 Sep 2019 12:05:30 +0800 Subject: [PATCH] refine executor_gc_helper codes, test=develop (#19814) --- paddle/fluid/framework/executor.h | 3 ++- paddle/fluid/framework/executor_gc_helper.cc | 14 +++++++------- paddle/fluid/framework/executor_gc_helper.h | 12 ++++++------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/paddle/fluid/framework/executor.h b/paddle/fluid/framework/executor.h index d0d12b3072..a6db5c8d41 100644 --- a/paddle/fluid/framework/executor.h +++ b/paddle/fluid/framework/executor.h @@ -44,7 +44,8 @@ struct ExecutorPrepareContext { std::vector> ops_; - std::unordered_map> unused_vars_; + std::unordered_map> + unused_vars_; bool force_disable_gc_{false}; }; diff --git a/paddle/fluid/framework/executor_gc_helper.cc b/paddle/fluid/framework/executor_gc_helper.cc index 77b0977b5a..1712d66cf4 100644 --- a/paddle/fluid/framework/executor_gc_helper.cc +++ b/paddle/fluid/framework/executor_gc_helper.cc @@ -89,10 +89,10 @@ static bool VarCanBeDeleted(const std::string &name, const BlockDesc &block, type == proto::VarType::LOD_TENSOR_ARRAY; } -std::unordered_map> GetUnusedVars( - const BlockDesc &block, - const std::vector> &ops, - const std::vector &skip_var_list) { +std::unordered_map> +GetUnusedVars(const BlockDesc &block, + const std::vector> &ops, + const std::vector &skip_var_list) { std::unordered_set skip_vars(skip_var_list.begin(), skip_var_list.end()); @@ -134,7 +134,7 @@ std::unordered_map> GetUnusedVars( } } - std::unordered_map> result; + std::unordered_map> result; for (auto &name_op_idx_pair : var_op_idx_map) { auto &name = name_op_idx_pair.first; size_t op_idx = name_op_idx_pair.second; @@ -144,8 +144,8 @@ std::unordered_map> GetUnusedVars( } void DeleteUnusedTensors( - const Scope &scope, OperatorBase *op, - const std::unordered_map> + const Scope &scope, const OperatorBase *op, + const std::unordered_map> &delete_vars_map, GarbageCollector *gc) { auto iter = delete_vars_map.find(op); diff --git a/paddle/fluid/framework/executor_gc_helper.h b/paddle/fluid/framework/executor_gc_helper.h index 8553273f82..a4c71c5304 100644 --- a/paddle/fluid/framework/executor_gc_helper.h +++ b/paddle/fluid/framework/executor_gc_helper.h @@ -26,15 +26,15 @@ namespace paddle { namespace framework { // Result map: op -> variable names that can be deleted after op runs -std::unordered_map> GetUnusedVars( - const BlockDesc &block, - const std::vector> &ops, - const std::vector &skip_vars); +std::unordered_map> +GetUnusedVars(const BlockDesc &block, + const std::vector> &ops, + const std::vector &skip_vars); // Collect unused tensors after op runs void DeleteUnusedTensors( - const Scope &scope, OperatorBase *op, - const std::unordered_map> + const Scope &scope, const OperatorBase *op, + const std::unordered_map> &delete_vars_map, GarbageCollector *gc); -- GitLab