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] Support custom op printer #54499

Merged

Conversation

kangguangli
Copy link
Contributor

@kangguangli kangguangli commented Jun 9, 2023

PR types

Others

PR changes

Others

Description

This PR supports custom op printer, which allows custom dialects to define their own style to print an operation. For example, looks at test/cpp/ir/core/ir_op_test.cc.

Meanwhile, we does the following changes:

  1. rename IRPrinter to IrPrinter
  2. when print a top level op like module op, we print it self and its regions, not only its regions.
  3. when print a program, however, we print its module op's regions only.

Others

Pcard-67164

@paddle-bot
Copy link

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

PrintGeneralOperation(op);
}

void IrPrinter::PrintGeneralOperation(Operation* op) {
Copy link
Contributor

Choose a reason for hiding this comment

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

PrintGeneralOperation的实现是不是直接放在PrintOperation里就可以了?这样就可以把PrintGeneralOperation去掉,这俩函数定位理解起来有点儿不清晰。毕竟print_fn(op, *this); 后直接return了;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里PrintOperation事实上用于分发选择具体的print函数,我加注释说明下吧,个人认为还是分开比较好。

os << newline;
}
os << "}\n";
void IrPrinter::PrintProgram(Program* program) {
Copy link
Contributor

Choose a reason for hiding this comment

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

PrintProgram不可以直接调用PrintFullOperation吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里的意图是在print program时不输出顶层的builtin.module,不然会显得有点多余。后续会把region和block分拆到新函数,复用这部分代码

test/cpp/ir/core/program_translator_test.cc Show resolved Hide resolved
Copy link
Contributor

@zhangbo9674 zhangbo9674 left a comment

Choose a reason for hiding this comment

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

LGTM

phi::IntArray int_array =
attr.dyn_cast<paddle::dialect::IntArrayAttribute>().data();

ir::Builder builder = ir::Builder::AtBlockEnd(ctx, program->block());
Copy link
Contributor

Choose a reason for hiding this comment

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

这儿直接用 ir::Builder builder(ctx, program->block);就可以。 AtBlockEnd接口准备删除,

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修改一下。


void PrintType(Type type);

void PrintAttribute(const Attribute& attr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Attribute和Type的类型保持一致吧,要么都用const& ,要么都用临时值。

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修改一下,之后统一用临时值。

void IrPrinter::PrintProgram(Program* program) {
auto top_level_op = program->module_op();
for (size_t i = 0; i < top_level_op->num_regions(); ++i) {
auto& region = top_level_op->GetRegion(i);
Copy link
Contributor

Choose a reason for hiding this comment

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

这里为什么没有调用printRegion/printBlock函数?

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修改下

@kangguangli kangguangli merged commit 7d68887 into PaddlePaddle:develop Jun 12, 2023
@kangguangli kangguangli deleted the support_custom_op_printer branch June 26, 2023 12:35
@kangguangli kangguangli mentioned this pull request Jun 30, 2023
@kangguangli kangguangli restored the support_custom_op_printer branch January 29, 2024 07:01
@kangguangli kangguangli deleted the support_custom_op_printer branch January 30, 2024 09:11
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