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 op attribute and refactor for new op definition #54068

Merged

Conversation

kangguangli
Copy link
Contributor

@kangguangli kangguangli commented May 23, 2023

PR types

New features

PR changes

Others

Description

This PR does the following thing:

  1. Adapt new op definition and refactor the logic of translator for better compatibility.
  2. Support transcribing op attributes to new IR system. Now we still cannot print attribute in new IR, which will be implemented next.

Others

Pcard-67164

@paddle-bot
Copy link

paddle-bot bot commented May 23, 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.

@paddle-bot
Copy link

paddle-bot bot commented May 23, 2023

✅ This PR's description meets the template requirements!
Please wait for other CI results.

@kangguangli kangguangli changed the title [IR] Support op attribute in program translator [IR] Support op attribute And Refactor May 31, 2023
@kangguangli kangguangli changed the title [IR] Support op attribute And Refactor [IR] Support op attribute and refactor May 31, 2023
@kangguangli kangguangli changed the title [IR] Support op attribute and refactor [IR] Support op attribute and refactor for new op definition May 31, 2023
heavyrain-lzy
heavyrain-lzy previously approved these changes Jun 1, 2023
Copy link
Contributor

@heavyrain-lzy heavyrain-lzy left a comment

Choose a reason for hiding this comment

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

LGTM


static const char *name() { return "builtin.constant"; }

static constexpr uint32_t attributes_num = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

constant是有属性的吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

目前没有用到,先添加了Op,不确定要加什么属性。有建议吗?

Copy link
Contributor

Choose a reason for hiding this comment

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

我后面会再支持可变 attribute 的时候重新设计一下 constOp

@@ -18,7 +18,9 @@ namespace paddle {
namespace dialect {
phi::IntArray IntArrayAttribute::data() const { return storage()->GetAsKey(); }

phi::Scalar ScalarAttribute::data() const { return storage()->GetAsKey(); }
paddle::experimental::Scalar ScalarAttribute::data() const {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个从phi::改为 paddle::experimental::是有什么必要的原因吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

它们是两个不同的类型,在OpDesc中的Attribute类型是paddle::experimental::Scalar,所以这里做了修改。后面根据新讨论的ScalarAttribute重新适配下。

@@ -36,7 +36,10 @@ class GetOpInfoInterface : public ir::OpInterfaceBase<GetOpInfoInterface> {
struct Model : public Concept {
static OpInfoTuple GetOpInfo() { return ConcreteOp::GetOpInfo(); }

Model() : Concept(GetOpInfo) {}
Model() : Concept(GetOpInfo) {
static_assert(sizeof(Model) == sizeof(Concept),
Copy link
Contributor

Choose a reason for hiding this comment

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

这个static_assert(sizeof(Model) == sizeof(Concept)已经不需要了,可以在下个pr中删除。

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

// ops.size() = op size in BlockDesc + get_parameter_op + combine op
EXPECT_EQ(op_size, p.Block(0).OpSize() + program->parameters_num() + 21);

std::cout << *program << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

这行会出现编译错误

/paddle/test/cpp/ir/core/program_translator_test.cc:62:13: error: no match for ‘operator<< (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘ir::Program’)
   std::cout << *program << std::endl;

cmake 参数是 cmake .. -DPY_VERSION=3.7 -DWITH_GPU=OFF -DWITH_TESTING=ON

Copy link
Contributor

@zhangbo9674 zhangbo9674 Jun 4, 2023

Choose a reason for hiding this comment

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

有隐形冲突,目前已解决,可以拉取最新代码 / rerun 一下任务

Copy link
Contributor

Choose a reason for hiding this comment

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

好的了解

@kangguangli kangguangli deleted the support_translating_op_attribute branch June 8, 2023 06:25
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.

5 participants