未验证 提交 ca9045f7 编写于 作者: K kangguangli 提交者: GitHub

[NewIR] optimize GetNameById in check_gc (#56964)

* optimize GetNameById in check_gc

* remove debug code

* fix

* fix
上级 8c75039c
......@@ -1218,6 +1218,16 @@ std::unordered_set<std::string> GetSpecialOpNames() {
};
}
void BuildId2VarName(const std::map<std::string, int>& var_name_2_id,
std::unordered_map<int, std::string>* id_2_var_name) {
PADDLE_ENFORCE_NOT_NULL(
id_2_var_name,
phi::errors::InvalidArgument("id2_var_name can not be null"));
for (auto [var_name, id] : var_name_2_id) {
id_2_var_name->insert({id, var_name});
}
}
} // namespace interpreter
} // namespace framework
} // namespace paddle
......@@ -116,6 +116,8 @@ void BuildOpFuncList(
void BuildVariableScope(const framework::BlockDesc& block,
const ExecutionConfig& execution_config,
VariableScope* var_scope);
void BuildId2VarName(const std::map<std::string, int>& var_name_2_id,
std::unordered_map<int, std::string>* id_2_var_name);
void LogDeviceMemoryStats(const platform::Place& place);
......
......@@ -194,11 +194,10 @@ std::string NewIRInterpreter::GetNameById(int id) const {
// typically when the target variable is not existed in the original program
// desc, but created by interpretercore.
// For example, created and used by d2h_copy or h2d_copy operator.
auto it = std::find_if(var_name_2_id_.begin(),
var_name_2_id_.end(),
[id](const auto& pair) { return pair.second == id; });
if (it != var_name_2_id_.end()) {
return it->first;
auto it = id_2_var_name_.find(id);
if (it != id_2_var_name_.end()) {
return it->second;
}
return "";
}
......@@ -925,6 +924,9 @@ FetchList NewIRInterpreter::Run(const std::vector<std::string>& feed_names,
&variable_2_var_name_,
&var_name_2_id_,
&variable_list_);
interpreter::BuildId2VarName(var_name_2_id_, &id_2_var_name_);
VLOG(4) << "Done BuildScope";
VLOG(4) << DebugValueInfo();
......
......@@ -208,6 +208,7 @@ class NewIRInterpreter : public InterpreterBaseImpl {
variable_2_var_name_;
std::map<std::string, int> var_name_2_id_;
std::unordered_map<int, std::string> id_2_var_name_;
std::vector<Variable*> variable_list_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册