This is an archive of the discontinued LLVM Phabricator instance.

[mlir][vector][nvgpu] Move MMA contraction preparation to VectorUtils
ClosedPublic

Authored by kuhar on Mar 8 2023, 6:41 PM.

Details

Summary

This pattern is not specific to nvgpu; I intend to use in SPIR-V codegen. VectorTransforms seems like a more generally useful place.

In addition:

  • Fix a bug in the second condition (the dimensions were swapped for RHS).
  • Add tests.
  • Add support for externally provided filter functions, similar to other vector transforms.
  • Prefer to transpose before zero/sign-extending inputs.

Diff Detail

Event Timeline

kuhar created this revision.Mar 8 2023, 6:41 PM
Herald added a project: Restricted Project. · View Herald Transcript
kuhar requested review of this revision.Mar 8 2023, 6:41 PM
kuhar edited the summary of this revision. (Show Details)Mar 8 2023, 6:41 PM
kuhar edited the summary of this revision. (Show Details)Mar 8 2023, 6:48 PM

Thanks for the clean up!

mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h
556

can we expose a populate* function instead of having the class in the public header?

kuhar added inline comments.Mar 8 2023, 6:58 PM
mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h
556

I wanted to keep this move simple and decided to follow the way this pattern was implemented (and also how the neighboring vector patterns are exposed). I wanted to move it to a 'populate' function in a subsequent review, but I can do it in one step if that's prefered. WDYT?

dcaballe added inline comments.Mar 8 2023, 7:14 PM
mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h
544

Excuse my ignorance... What is MMT and TNT? Perhaps adding a comment would help.

kuhar added inline comments.Mar 8 2023, 7:36 PM
mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h
544

It's probably my ignorance, I wasn't sure if there's some standard nomenclature for this. The goal is to have the contraction in the matrix x matrix-transposed form (LHS row-major, RHS col-major, OUT row-major).

The original code called it MMA (matrix multiply-accumulate), but I thought that was too nvidia-specific because it doesn't suggest anything about the canonical form outside of the context of the nvidia isa, IIUC.

Do you have any concrete suggestions or pointers to relevant documentation/literature?

ThomasRaoux added inline comments.Mar 9 2023, 7:22 AM
mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h
544

Since it is an important piece I would spell it out and expand MMT to matmul with rhs transpose and the following IR example should be enough to explain what the transformation does.

556

Since it is better to not change what we expose publicly multiple times I would suggest adding the populate function right away. It should be a minimal amount a changes.

kuhar updated this revision to Diff 503772.Mar 9 2023, 8:07 AM
kuhar marked an inline comment as done.

Address review comments.

kuhar marked an inline comment as done.Mar 9 2023, 8:07 AM
kuhar marked 2 inline comments as done.
ThomasRaoux accepted this revision.Mar 9 2023, 8:27 AM

LGTM, added one more nit about file name.

mlir/test/Dialect/Vector/vector-contract-matmul-canonicalization.mlir
1 ↗(On Diff #503772)

Can we change the name of this file to something else than canonicalization since this is not really a canonicalization it is just transforming into a given representation but there is nothing more canonical about it.

This revision is now accepted and ready to land.Mar 9 2023, 8:27 AM
kuhar updated this revision to Diff 503793.Mar 9 2023, 8:39 AM

Rename test

kuhar marked an inline comment as done.Mar 9 2023, 8:39 AM
ThomasRaoux accepted this revision.Mar 9 2023, 8:43 AM
kuhar updated this revision to Diff 503868.Mar 9 2023, 11:53 AM

Fix op argument names in the comment. Fix function definition order.

This revision was landed with ongoing or failed builds.Mar 9 2023, 11:57 AM
This revision was automatically updated to reflect the committed changes.