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

[PIR][Inference] add layout_transformation_interface for later transfer_layout_pass #63286

Merged

Conversation

kangguangli
Copy link
Contributor

@kangguangli kangguangli commented Apr 7, 2024

PR Category

Execute Infrastructure

PR Types

Devs

Description

This PR adds LayoutTransformationInterface, which is used for transfer_layout_pass to determine which layout allows an operation to achieve the best performance.

LayoutTransformationInterface has four member functions:

  1. PreferLayout, receives an operation as input and judges the layout that this operation will perform best by its attributes、inputs or operation kind and so on. This can be overloaded. If not, its result is AllLayout which means it can be modified freely.
  2. RewriteByLayout, receives an operation and a new layout as input, exectutes after we choose a new layout and rewrite the operation's attributes. This must be overloaded, otherwise it throws an error.
  3. RelevantInputs, receives an operation as input, returns the part of op's inputs that affects its kernel layout. This can be overloaded. If not, its result is all inputs of the op.
  4. RelevantOutputs, receives an operation as input, returns the part of op's outputs that are affected by its kernel layout. This can be overloaded. If not, its result is all outputs of the op.

To register this inferface for an op after this PR, you will need to modify 3 files:

  1. ops.yaml, to add following code: interfaces : paddle::dialect::LayoutTransformationInterface
  2. paddle/fluid/pir/dialect/operator/interface/layout_transformation.hpp, to add the template declaration. Note that you need a forward declaration to avoid circular reference and only declare those members that you need to overload.
class FusedConv2dAddActOp;
template <> common::DataLayout PreferLayoutImpl<FusedConv2dAddActOp>(pir::Operation*);
extern template common::DataLayout PreferLayoutImpl<FusedConv2dAddActOp>(pir::Operation*);
template <>void RewriteByLayoutImpl<FusedConv2dAddActOp>(pir::Operation*,  common::DataLayout);
extern template void RewriteByLayoutImpl<FusedConv2dAddActOp>(pir::Operation*, common::DataLayout);
  1. paddle/fluid/pir/dialect/operator/interface/layout_transformation.cc, to add the specialized template implementation

Others

Pcard-67164

Copy link

paddle-bot bot commented Apr 7, 2024

你的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.

template <>
void RewriteByLayoutImpl<FusedConv2dAddActOp>(pir::Operation* op,
common::DataLayout new_layout) {
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.

暂时留空,后面写pass的时候补上

winter-wang
winter-wang previously approved these changes Apr 7, 2024
zhangbo9674
zhangbo9674 previously approved these changes Apr 7, 2024
@kangguangli kangguangli dismissed stale reviews from zhangbo9674 and winter-wang via 1e1327e April 8, 2024 08:20
@kangguangli kangguangli merged commit e7a515b into PaddlePaddle:develop Apr 9, 2024
29 of 30 checks passed
@kangguangli kangguangli deleted the layout_transformation_interface branch April 9, 2024 02:59
co63oc pushed a commit to co63oc/Paddle that referenced this pull request Apr 9, 2024
…er_layout_pass (PaddlePaddle#63286)

* add layout_transformation_interface for later transfer_layout_pass

* remove comment

* refine

* fix windows ci

* fix windows ci
co63oc pushed a commit to co63oc/Paddle that referenced this pull request Apr 10, 2024
…er_layout_pass (PaddlePaddle#63286)

* add layout_transformation_interface for later transfer_layout_pass

* remove comment

* refine

* fix windows ci

* fix windows ci
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