Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependence analysis #37231

Merged
merged 7 commits into from
Nov 17, 2021
Merged

Conversation

2742195759
Copy link
Contributor

@2742195759 2742195759 commented Nov 16, 2021

PR types

Others

PR changes

Others

Describe

这个PR修复了新执行器的依赖分析算法。之前的新执行器对于多次write和read write的依赖关系分析有漏洞,现在的PR重写了Op依赖分析逻辑。具体算法和问题来源可以参考文档: http://agroup.baidu.com/share/md/839f7c5eb0d543cc9245084d9eecab22 [执行器控制流静态分析存在的一类问题【已定位】] 。上面列举了分析算法伪代码和实现逻辑。应该比代码容易理解。

  1. 完善了op依赖的分析。
  2. 重构了依赖分析的代码,抽出为单独的函数。
  3. 添加了一个write after write 的单例。
  4. 修复了4个因为依赖分析错误导致错误的单测。

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

void InterpreterCore::BuildOperatorDependences() {
// set the dependecy_count_ and Call Schedule
// refer to http://agroup.baidu.com/share/md/92946214aa4c4785a2cc4c1f361a023c
// for pesudo code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要在代码里添加百度内部的文档链接,可以参看graph.h那样,在这里添加整体的方案思路描述

std::set<int> remove_duplicate;

// reserve
for (size_t op = 0; op < vec_instruction_.size(); ++op) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (size_t op = 0; op < vec_instruction_.size(); ++op) {
for (size_t i = 0; i < op_nums; ++i) {

}
dependecy_count_.resize(op_nums);

for (size_t op = 0; op < vec_instruction_.size(); ++op) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (size_t op = 0; op < vec_instruction_.size(); ++op) {
for (size_t op_idx = 0; op_idx < op_nums; ++op_idx) {

}
}

auto op2downstream = get_downstream_map(op2dependences);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议把上述逻辑单独放到utils.ccl里

@@ -289,7 +282,7 @@ void InterpreterCore::BuildSkipShareLoDInfo() {
void InterpreterCore::RunInstruction(const Instruction& instr_node) {
auto* op = instr_node.OpBase();
auto place = instr_node.DeviceContext().GetPlace();
VLOG(4) << place << " " << op->DebugStringEx(global_scope_);
VLOG(4) << "Start run" << place << " " << op->DebugStringEx(global_scope_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
VLOG(4) << "Start run" << place << " " << op->DebugStringEx(global_scope_);
VLOG(4) << "Start run " << place << " " << op->DebugStringEx(global_scope_);

@@ -320,7 +313,7 @@ void InterpreterCore::RunInstruction(const Instruction& instr_node) {
instr_node.KernelFunc()(*instr_node.InnerExecutionContext().get());
}

VLOG(3) << place << " " << op->DebugStringEx(global_scope_);
VLOG(4) << "End run" << place << " " << op->DebugStringEx(global_scope_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
VLOG(4) << "End run" << place << " " << op->DebugStringEx(global_scope_);
VLOG(4) << "End run " << place << " " << op->DebugStringEx(global_scope_);

@@ -77,6 +77,23 @@ paddle::framework::FetchList InterpreterCore::Run(
return *(fetch_var->GetMutable<framework::FetchList>());
}

void InterpreterCore::BuildOperatorDependences() {
// analysis the dependences between ops, set the dependecy_count_ and Call
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call -> call

@wanghuancoder wanghuancoder merged commit d943459 into PaddlePaddle:develop Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants