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

[IR] Add Construct event for new ir interpretercore #55555

Merged
merged 24 commits into from
Jul 30, 2023

Conversation

zhangbo9674
Copy link
Contributor

PR types

New features

PR changes

Others

Description

基于新 IR InstructionBase 体系,支持 ConstructEvent 模块。

后续工作:

  • 基于当前 Instruction 体系,重构 Gc 的模块
  • Execution、Trace 执行逻辑接入

Others

Pcard-67164

@paddle-bot
Copy link

paddle-bot bot commented Jul 19, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

winter-wang
winter-wang previously approved these changes Jul 26, 2023
Copy link
Contributor

@winter-wang winter-wang left a comment

Choose a reason for hiding this comment

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

LGTM

Aurelius84
Aurelius84 previously approved these changes Jul 26, 2023
Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

LGTM

VLOG(6) << "finish process device context";

Scope* inner_scope = local_scope == nullptr ? scope : local_scope;
InitInputsOutputsIds(
op, inner_scope, value_2_var_name, var_name_2_id, variable_2_var_name);
VLOG(6) << "finish process inputs outputs index";

auto no_need_buffer_ids = yaml_info_parser.NoNeedBufferIds();
Copy link
Contributor

Choose a reason for hiding this comment

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

auto 会隐式触发copy,如果接口返回的是引用,这里建议用auto &

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已完善

Copy link
Contributor

@From00 From00 left a comment

Choose a reason for hiding this comment

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

stream_analyzer的代码基本是重复拷贝了一份,这块目前正在被完善,且在不久的未来可能被重构,值得考虑通过抽象和复用公共逻辑,减少重复代码的数量,否则会给后续多流机制的迭代带来较大的负担。


std::unordered_map<ir::Value, std::vector<int>> output_index_;
std::unordered_set<::ir::Value> no_need_buffer_;
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
std::unordered_set<::ir::Value> no_need_buffer_;
std::unordered_set<::ir::Value> no_need_buffer_values_;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已完善

@@ -32,6 +34,114 @@
namespace paddle {
namespace framework {

using DeviceContext = paddle::platform::DeviceContext;

class IrContextManager {
Copy link
Contributor

Choose a reason for hiding this comment

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

ContextManager并不依赖新IR,为何也需要重复一份?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已复用

auto no_need_buffer_ids = yaml_info_parser.NoNeedBufferIds();
std::unordered_set<::ir::Value> no_need_buffer_values;
for (size_t id = 0; id < no_need_buffer_ids.size(); id++) {
no_need_buffer_values.insert(op->operand(id));
Copy link
Contributor

Choose a reason for hiding this comment

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

no_need_buffer_ids里的元素一定是从0开始连续递增的吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

逻辑有问题,已修正

@@ -550,8 +550,7 @@ void DependencyBuilder::ShrinkDownstreamMap() {
/// For new ir ///
/// ======================== ///
const std::map<size_t, std::set<size_t>>& IrDependencyBuilder::Build(
const std::vector<std::unique_ptr<paddle::framework::InstructionBase>>&
instructions) {
const std::vector<paddle::framework::InstructionBase*>& instructions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

为什么要把unique_ptr改成裸指针?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已改回

@@ -173,6 +178,10 @@ bool IsMemcpyH2D(const Instruction& instr) {
return instr.OpBase()->Type() == kMemcpyH2D;
}

bool IsMemcpyH2D(const paddle::framework::InstructionBase* instr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

InstructionBase的命名容易被误认为是两套Insturction的公共基类,但其实现却是针对新IR的,且同文件下又有一个以Instruction对象作为入参的IsMemcpyH2D函数,令人困惑。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

由于是中间态,最终态下 NewIR 的执行器中,将不会存在 Instruction 的相关信息

@zhangbo9674 zhangbo9674 dismissed stale reviews from Aurelius84 and winter-wang via 9f6b218 July 27, 2023 01:48
Copy link
Contributor

@From00 From00 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhangbo9674 zhangbo9674 merged commit 345de9a into PaddlePaddle:develop Jul 30, 2023
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