This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Transform] Transform dialect support for affine
ClosedPublic

Authored by kaitingwang on Nov 14 2022, 6:10 PM.

Details

Summary

Create the directory and file structures to support transform ops for
the affine dialect in the future. Enable affine.unroll and affine.get_parent_for
transform operations in this first batch of check in.

Diff Detail

Event Timeline

kaitingwang created this revision.Nov 14 2022, 6:10 PM
kaitingwang requested review of this revision.Nov 14 2022, 6:10 PM
chelini added inline comments.Nov 15 2022, 11:38 AM
mlir/include/mlir/Dialect/Affine/TransformOps/AffineTransformOps.td
55

nit: please add a space between # and 'Return modes'.

59

nit: space before 'Otherwise'.

mlir/include/mlir/Dialect/Affine/TransformOps/CMakeLists.txt
7

I would rename AffineNewTransformOps to something else, maybe: AffineLoopTransformOps.

mlir/lib/Dialect/Affine/TransformOps/AffineTransformOps.cpp
16

nit: new line before using namespace mlir?

65

nullptr should not be needed. The callback is defaulted to nullptr.

ftynse added inline comments.Nov 16 2022, 12:54 PM
mlir/include/mlir/Dialect/Affine/TransformOps/AffineTransformOps.td
2

Nit: this looks 1 character too long (or the bottom one too short, I didn't count).

25

Please specify that this means the _affine_ for loop.

mlir/lib/Dialect/Affine/TransformOps/AffineTransformOps.cpp
86

Where is this generating the func dialect?

All comments are addressed. Much appreciated! Please let me know if there are further comments.

kaitingwang marked 5 inline comments as done.Nov 16 2022, 2:55 PM
kaitingwang added inline comments.
mlir/include/mlir/Dialect/Affine/TransformOps/CMakeLists.txt
7

Name changed as suggested.

mlir/lib/Dialect/Affine/TransformOps/AffineTransformOps.cpp
65

Removed.

86

Removed.

Clang-format causing Debian build to fail. Addressed in this patch.

@ftynse @chelini Thanks for the reviews. Would you be able to accept this revision? Much appreciated!

ftynse accepted this revision.Nov 18 2022, 5:13 AM
This revision is now accepted and ready to land.Nov 18 2022, 5:13 AM
This revision was automatically updated to reflect the committed changes.
mlir/include/mlir/Dialect/Affine/TransformOps/AffineTransformOps.td
21

I'd strongly prefer to see this implemented on LoopLike interface (with maybe a name attribute to catch a particular op type) and have a single more general transform than duplicating this op in the affine dialect.

46

I'd strongly prefer to see this implemented on LoopLike interface and have a single more general transform than duplicating this op in the affine dialect.

kaitingwang added inline comments.Nov 25 2022, 7:42 AM
mlir/include/mlir/Dialect/Affine/TransformOps/AffineTransformOps.td
21

I can merge these two TransformOps into SCF/SCFTransformOps.cpp and in the respective apply methods in SCFTransformOps.cpp, make a determination (base on a newly introduced parameter), whether to handle in a SCF way or an Affine way. For instance, to invoke SCF's unroll method, or Affine's unroll method. And in the event a matched ops is surrounded by both affine and scf.for's, which parents are to be returned.

Please advise if this is what you have in mind. I have two more affine TransformOps in an upcoming patch: affine.tile and affine.stripmine. Should we consolidate affine's TransformOps into SCF's going forward? Thank you!

mlir/include/mlir/Dialect/Affine/TransformOps/AffineTransformOps.td
21

I can merge these two TransformOps into SCF/SCFTransformOps.cpp and in the respective apply methods in SCFTransformOps.cpp, make a determination (base on a newly introduced parameter), whether to handle in a SCF way or an Affine way. For instance, to invoke SCF's unroll method, or Affine's unroll method. And in the event a matched ops is surrounded by both affine and scf.for's, which parents are to be returned.
Please advise if this is what you have in mind.

Yes, this would make sense to me and in the future we can continue extending to the Parallel flavor of ops and While loops etc as the need grows. I'll let @ftynse also chime in here.

I have two more affine TransformOps in an upcoming patch: affine.tile and affine.stripmine. Should we consolidate affine's TransformOps into SCF's going forward? Thank you!

These ones seem specific enough to affine that they make sense to be in the affine dialect.

Thanks!

kaitingwang added inline comments.Nov 29 2022, 9:47 PM
mlir/include/mlir/Dialect/Affine/TransformOps/AffineTransformOps.td
21

Thank you for the advice! Hopefully the patch https://reviews.llvm.org/D138980 addresses the concern.