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] Type system stage3: add class Dialect #50959

Merged
merged 8 commits into from
Mar 2, 2023

Conversation

zhangbo9674
Copy link
Contributor

@zhangbo9674 zhangbo9674 commented Feb 27, 2023

PR types

New features

PR changes

APIs

Describe

Pcard-67160

Paddle 类型系统开发主要分为4个阶段:(1)Type基础数据结构开发(PR1)、(2)Type类型生成工具开发(PR2)、(3)IRContext(PR2)、Dialect数据结构开发(本PR)、(4)内置类型开发。

1. PR 主要内容:

本 PR 添加了 Dialect 数据结构,Dialect 的作用是:Type 注册进 Dialect、Dialect 注册进 IrContext。核心文件如下:

  • dialect.h/.cc:定义 class Dialect,用来接受类型的注册(后续 Dialect 还会接受算子、属性等的注册);
  • builtin_dialect.h/cc:定义内置 Dialect
  • ir_context.h/cc:在 class IrContext 中定义注册/缓存 Dialect 的成员函数、成员变量

图片

2. 应用示例:

// 自定义 CustomDialect、注册 CustomType
struct CustomDialect : ir::Dialect {
  CustomDialect(ir::IrContext *context) : ir::Dialect(name(), context, ir::TypeId::get<CustomDialect>()) {
    RegisterType<CustomType>();      // 注册 CustomType
  }
  static const std::string name() { return "custom"; }
};
// CustomDialect 注册进入 IrContext
ir::IrContext *ctx = ir::IrContext::Instance();
ctx->GetOrRegisterDialect<IntegerDialect>();     // CustomDialect 注册进入 IrContext
ir::Type int1 = IntegerType::get(ctx, 1, 0);             // 获取自定义类型

3. Todo:

  • 按需丰富 Type 接口:如 is_a、dyn_cast 等
  • 更多内置类型的定义、注册(第4阶段)

@paddle-bot
Copy link

paddle-bot bot commented Feb 27, 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.

@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Feb 27, 2023
@PaddlePaddle PaddlePaddle unlocked this conversation Feb 27, 2023
@zhangbo9674 zhangbo9674 reopened this Feb 27, 2023
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Feb 27, 2023
@PaddlePaddle PaddlePaddle unlocked this conversation Feb 27, 2023
///
/// \return The dialect this type was registered to.
///
Dialect &dialect() const { return const_cast<Dialect &>(dialect_); }
Copy link
Contributor

Choose a reason for hiding this comment

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

建议返回const Dialect&, 或者将成员变量改为 Dialect&。 目前的这种操作太不合理。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,我完善一下。

paddle/ir/dialect.cc Outdated Show resolved Hide resolved
paddle/ir/dialect.h Outdated Show resolved Hide resolved
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

Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

LGTM

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