未验证 提交 3f87464e 编写于 作者: Z Zeng Jinle 提交者: GitHub

refine executor_gc_helper codes, test=develop (#19814)

上级 6d72a86b
...@@ -44,7 +44,8 @@ struct ExecutorPrepareContext { ...@@ -44,7 +44,8 @@ struct ExecutorPrepareContext {
std::vector<std::unique_ptr<OperatorBase>> ops_; std::vector<std::unique_ptr<OperatorBase>> ops_;
std::unordered_map<OperatorBase*, std::vector<std::string>> unused_vars_; std::unordered_map<const OperatorBase*, std::vector<std::string>>
unused_vars_;
bool force_disable_gc_{false}; bool force_disable_gc_{false};
}; };
......
...@@ -89,8 +89,8 @@ static bool VarCanBeDeleted(const std::string &name, const BlockDesc &block, ...@@ -89,8 +89,8 @@ static bool VarCanBeDeleted(const std::string &name, const BlockDesc &block,
type == proto::VarType::LOD_TENSOR_ARRAY; type == proto::VarType::LOD_TENSOR_ARRAY;
} }
std::unordered_map<OperatorBase *, std::vector<std::string>> GetUnusedVars( std::unordered_map<const OperatorBase *, std::vector<std::string>>
const BlockDesc &block, GetUnusedVars(const BlockDesc &block,
const std::vector<std::unique_ptr<OperatorBase>> &ops, const std::vector<std::unique_ptr<OperatorBase>> &ops,
const std::vector<std::string> &skip_var_list) { const std::vector<std::string> &skip_var_list) {
std::unordered_set<std::string> skip_vars(skip_var_list.begin(), std::unordered_set<std::string> skip_vars(skip_var_list.begin(),
...@@ -134,7 +134,7 @@ std::unordered_map<OperatorBase *, std::vector<std::string>> GetUnusedVars( ...@@ -134,7 +134,7 @@ std::unordered_map<OperatorBase *, std::vector<std::string>> GetUnusedVars(
} }
} }
std::unordered_map<OperatorBase *, std::vector<std::string>> result; std::unordered_map<const OperatorBase *, std::vector<std::string>> result;
for (auto &name_op_idx_pair : var_op_idx_map) { for (auto &name_op_idx_pair : var_op_idx_map) {
auto &name = name_op_idx_pair.first; auto &name = name_op_idx_pair.first;
size_t op_idx = name_op_idx_pair.second; size_t op_idx = name_op_idx_pair.second;
...@@ -144,8 +144,8 @@ std::unordered_map<OperatorBase *, std::vector<std::string>> GetUnusedVars( ...@@ -144,8 +144,8 @@ std::unordered_map<OperatorBase *, std::vector<std::string>> GetUnusedVars(
} }
void DeleteUnusedTensors( void DeleteUnusedTensors(
const Scope &scope, OperatorBase *op, const Scope &scope, const OperatorBase *op,
const std::unordered_map<OperatorBase *, std::vector<std::string>> const std::unordered_map<const OperatorBase *, std::vector<std::string>>
&delete_vars_map, &delete_vars_map,
GarbageCollector *gc) { GarbageCollector *gc) {
auto iter = delete_vars_map.find(op); auto iter = delete_vars_map.find(op);
......
...@@ -26,15 +26,15 @@ namespace paddle { ...@@ -26,15 +26,15 @@ namespace paddle {
namespace framework { namespace framework {
// Result map: op -> variable names that can be deleted after op runs // Result map: op -> variable names that can be deleted after op runs
std::unordered_map<OperatorBase *, std::vector<std::string>> GetUnusedVars( std::unordered_map<const OperatorBase *, std::vector<std::string>>
const BlockDesc &block, GetUnusedVars(const BlockDesc &block,
const std::vector<std::unique_ptr<OperatorBase>> &ops, const std::vector<std::unique_ptr<OperatorBase>> &ops,
const std::vector<std::string> &skip_vars); const std::vector<std::string> &skip_vars);
// Collect unused tensors after op runs // Collect unused tensors after op runs
void DeleteUnusedTensors( void DeleteUnusedTensors(
const Scope &scope, OperatorBase *op, const Scope &scope, const OperatorBase *op,
const std::unordered_map<OperatorBase *, std::vector<std::string>> const std::unordered_map<const OperatorBase *, std::vector<std::string>>
&delete_vars_map, &delete_vars_map,
GarbageCollector *gc); GarbageCollector *gc);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册