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] Refine IR builder and throw methods #54396

Merged
merged 19 commits into from
Jun 9, 2023

Conversation

zhangbo9674
Copy link
Contributor

@zhangbo9674 zhangbo9674 commented Jun 6, 2023

PR types

New features

PR changes

Others

Description

PR 主要内容:

  • 新增 IR_THROW 及 IR_ENFORCE 宏,规范 IR 代码中部分 throw 的用法
  • 优化可变 Attribute 支持机制
    • 优化 Op::Build 函数,支持利用 full 及 full_int_array op 将 phi::Scalar 及 phi::IntArray 类型的可变 Attribute 自动生成 OpResult
    • 新增 Op::Build 函数,支持将可变 Attribute 作为输入(OpResult)传入
  • 优化组网代码写法
    • 优化 ir_exe_test 中的组网写法,改为基于 builder 实现

Op::Build示例:

void UniformOp::Build(ir::Builder &builder, ir::OperationArgument &argument, std::vector<int64_t> shape, phi::DataType dtype, float min, float max, int seed, phi::Place place) {
  // Generate int_array mutable attribute: shape
  paddle::dialect::FullIntArrayOp full_shape_op = builder.Build<paddle::dialect::FullIntArrayOp>(shape, phi::DataType::INT64, phi::CPUPlace());
  ir::OpResult shape_ = full_shape_op->GetResultByIndex(0);
      // Generate scalar mutable attribute: min
  paddle::dialect::FullOp full_min_op = builder.Build<paddle::dialect::FullOp>(std::vector<int64_t>{1}, min, phi::DataType::FLOAT32, phi::CPUPlace());
  ir::OpResult min_ = full_min_op->GetResultByIndex(0);
      // Generate scalar mutable attribute: max
  paddle::dialect::FullOp full_max_op = builder.Build<paddle::dialect::FullOp>(std::vector<int64_t>{1}, max, phi::DataType::FLOAT32, phi::CPUPlace());
  ir::OpResult max_ = full_max_op->GetResultByIndex(0);
   ...
}

Todo:

  • 对于 Op::Build 函数,需要支持可变 Attribute 作为输入(OpResult)传入,但当前存在的问题是:如果该 OP 的 infer_meta 需要使用该可变 Attribute 的值,但是 OpResult 目前无法拿到值。该问题后续需要继续适配

Others

Pcard-67164

@paddle-bot
Copy link

paddle-bot bot commented Jun 6, 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.

"Unsupported ir attribute when casting it into "
"phi scalar."));
}
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

不要内联

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

- op : full_int_array
args : (IntArray value, DataType dtype=DataType::FLOAT32, Place place=CPUPlace())
output: Tensor(out)
infer_meta :
Copy link
Contributor

Choose a reason for hiding this comment

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

建议将新增op添加到ops.yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,单独提 pr 完善该问题

@zhangbo9674 zhangbo9674 merged commit 3a452e4 into PaddlePaddle:develop Jun 9, 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.

3 participants