-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
【静态图性能优化】图依赖信息复用 #55389
【静态图性能优化】图依赖信息复用 #55389
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
// first job to other jobs. The shared build result includes op dependency, | ||
// event analyzer, thread scheduling and GC. | ||
for (const auto& pair : type_to_id) { | ||
const auto& idx = pair.second; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto& idx = pair.second; | |
const auto& ids = pair.second; |
idx
是单数,ids
是复数。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -115,6 +117,10 @@ class ProgramInterpreter : public InterpreterBaseImpl { | |||
// workqueue | |||
std::shared_ptr<interpreter::AsyncWorkQueue> GetWorkQueue(); | |||
|
|||
// op dependences | |||
interpreter::DependencyBuilder* GetDependencyBuilder(); | |||
std::shared_ptr<std::vector<size_t>> GetDependecyCount(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::shared_ptr<std::vector<size_t>> GetDependecyCount(); | |
std::shared_ptr<std::vector<size_t>> GetDependencyCount(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -311,6 +322,17 @@ ProgramInterpreter::GetWorkQueue() { | |||
return async_work_queue_; | |||
} | |||
|
|||
interpreter::DependencyBuilder* ProgramInterpreter::GetDependencyBuilder() { | |||
return &dependency_builder_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要共享的数据,请用智能指针做生命周期管理。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是 dependency_builder_ 下的成员变量进行共享,dependency_builder_ 也需要进行生命周期管理吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, 换成了返回一个const引用
dependency_builder_.ShareDependencyFrom( | ||
reinterpret_cast<ProgramInterpreter*>(src)->GetDependencyBuilder()); | ||
dependecy_count_ = | ||
reinterpret_cast<ProgramInterpreter*>(src)->GetDependecyCount(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议GetDependencyBuilder
和GetDependecyCount
也通过虚函数的方式实现多态,避免使用reinterpret_cast
。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
std::shared_ptr<std::vector<size_t>> ProgramInterpreter::GetDependecyCount() { | ||
if (dependecy_count_ == nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dependecy_count_
不需要延迟创建,可以直接在构造函数中创建。这样GetDependencyBuilder
和GetDependencyCount
都可以声明成const函数。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -123,6 +129,7 @@ class ProgramInterpreter : public InterpreterBaseImpl { | |||
|
|||
bool is_build_{false}; | |||
bool static_build_{false}; | |||
bool is_shared_{false}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加个注释说明具体share了哪些东西
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -283,6 +283,17 @@ void ProgramInterpreter::ShareWorkQueueFrom(InterpreterBaseImpl* src) { | |||
<< ") to InterpreterCore(" << this << ")"; | |||
} | |||
|
|||
void ProgramInterpreter::ShareBuildResultsFrom(InterpreterBaseImpl* src) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void ProgramInterpreter::ShareBuildResultsFrom(InterpreterBaseImpl* src) { | |
void ProgramInterpreter::ShareBuildResultsFrom(const InterpreterBaseImpl& src) { |
非可选输入参数通常是值参或 const 引用, 非可选输出参数或输入/输出参数通常应该是引用 (不能为空).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
void ShareDependencyFrom(DependencyBuilder* src); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void ShareDependencyFrom(DependencyBuilder* src); | |
void ShareDependencyFrom(const DependencyBuilder& src); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
std::tuple<std::shared_ptr<std::map<size_t, std::set<size_t>>>, | ||
std::shared_ptr<std::vector<std::vector<bool>>>> | ||
DependencyBuilder::GetDependency() { | ||
if (op_downstream_map_ == nullptr || op_happens_before_ == nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没必要延迟创建
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
… share_build_results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* add share api for DependencyBuilder * add judge codes for sharing build results * add ShareBuildResultsFrom * update ShareDependencyFrom * fix error * add share codes * fix memory error * update according review * update notes * fix code style * remove const_cast * fix code style
* add share api for DependencyBuilder * add judge codes for sharing build results * add ShareBuildResultsFrom * update ShareDependencyFrom * fix error * add share codes * fix memory error * update according review * update notes * fix code style * remove const_cast * fix code style
* add share api for DependencyBuilder * add judge codes for sharing build results * add ShareBuildResultsFrom * update ShareDependencyFrom * fix error * add share codes * fix memory error * update according review * update notes * fix code style * remove const_cast * fix code style
PR types
Performance optimization
PR changes
Others
Description
在Paddle中,图依赖分析(op dependency)发生在Convert过程中,其依赖分析过程在BuildOperatorDependences 构建。图依赖分析的主要作用是分析 op 之间的依赖关系,对计算图进行解析和分析,构建出每个算子的调度关系和执行顺序,以保证正确的计算顺序和结果。对于一样的子图,图依赖分析的结果是一样的,因此可以进行复用。
详细介绍见Issue: