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

[DT] Switch MaterializeEncodingIntoNop to use EncodingLayoutAttr. #19294

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hanhanW
Copy link
Contributor

@hanhanW hanhanW commented Nov 25, 2024

The revision introduces LayoutAttrInterface attribute interface and
implements the codegen attribute that discards the encodings for
lowering. It is used in the MaterializeEncodingIntoNop pass that turns
encodings into nop.

The new interface has two methods in the patch:

  • getEncodingInfo: It takes a ranked tensor type and returns the layout.
  • lowerOp: It takes the operation, converted operands and result types to lower the op.

The layout attributes for other backends are not implemented, so the
GPU/CPU materialization pass does not take it into account.

The revision also implements a isIdentityLayout method for the
MaterializeEncodingInfo struct and adds an unit test for it.

To support identity layout materialization, it adds a shortcut for lowering set/unset encodings ops to packing ops. If the relayout is not needed, the original source tensor value is returned. It is possible to add a folder for pack ops, but it is hard for unpack ops. Because the unpack ops have slicing semantics and it is not easy to identify it. Also, creating an operation is not cheap, so we have the shortcut in the two methods.

There are no new lit tests because the tests are covered by materialize_encoding_into_nop.mlir

@hanhanW hanhanW force-pushed the iree-codegen-interface branch 3 times, most recently from da0bd66 to ed7f415 Compare November 26, 2024 00:03
@hanhanW hanhanW marked this pull request as ready for review November 26, 2024 00:03
@hanhanW
Copy link
Contributor Author

hanhanW commented Nov 26, 2024

It depends on #19292, please take a look at the last commit. Technically, it is NFC because it only shuffle the codes and make few changes. So there are no new tests. However, I do update logics for some passes and methods and introduce new things, so I do not mark it NFC in PR title.

The revision introduces LayoutAttrInterface attribute interface and
implements the codegen attribute that discards the encodings for
lowering. It is used in the MaterializeEncodingIntoNop pass that turns
encodings into nop.

The layout attributes for other backends are not implemented, so the
GPU/CPU materialization pass does not take it into account.

The revision also implements a isIdentityLayout method for the
MaterializeEncodingInfo struct and adds an unit test for it.

Signed-off-by: hanhanW <hanhan0912@gmail.com>
Signed-off-by: hanhanW <hanhan0912@gmail.com>
// iree_codegen.encoding_layout
//===---------------------------------------------------------------------===//

def IREECodegen_EncodingLayoutAttr :
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should probably rename it to EncodingNopLayoutAttr, which is clearer.

Signed-off-by: hanhanW <hanhan0912@gmail.com>
@hanhanW
Copy link
Contributor Author

hanhanW commented Nov 26, 2024

This POC shows that we're able to implement the attribute for VMVX backend. There are some dup code in the POC though. I think my next step is moving most of methods from EncodingUtils.h to Dialect/Codegen/Utils/Utils.h, then we won't need to maintain two dup codes in the codebase.

Signed-off-by: hanhanW <hanhan0912@gmail.com>
Signed-off-by: hanhanW <hanhan0912@gmail.com>
Signed-off-by: hanhanW <hanhan0912@gmail.com>
Signed-off-by: hanhanW <hanhan0912@gmail.com>
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.

2 participants