This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Vector]Lower vector.contract to llvm.intr.matrix_multiply
ClosedPublic

Authored by nicolasvasilache on Mar 11 2020, 11:15 AM.

Details

Summary

This revision adds lowering of vector.contract to llvm.intr.matrix_multiply.
Note that there is currently a mismatch between the MLIR vector dialect which expects row-major layout and the LLVM matrix intrinsics which expect column major layout.

As a consequence, we currently only match a vector.contract with indexing maps
that express column-major matrix multiplication.
Other cases would require additional transposes and it is better to wait for
LLVM intrinsics to provide a per-operation attribute that would specify which layout is expected.

A separate integration test, not submitted to MLIR core, has independently verified that correct execution occurs on a 2x2x2 matrix multiplication.

Diff Detail

Event Timeline

aartbik added inline comments.Mar 11 2020, 12:58 PM
mlir/include/mlir/Dialect/Utils/StructuredOpsUtils.h
42

note that we also have two "transposed" versions, ie. with either {m,n} or {n.m} but then the position of the k's swapped

mlir/lib/Dialect/VectorOps/VectorTransforms.cpp
970

can this test every fail? if so, shouldn't we move it a bit up to avoid doing some work first?

mlir/test/Dialect/VectorOps/vector-contract-transforms.mlir
1–2

note that in the pending CL, I have renamed this flag and file, since it started to become less and less about contract only :-)

One of us will have to rebase and merge

rriddle added inline comments.Mar 11 2020, 1:13 PM
mlir/lib/Dialect/VectorOps/VectorTransforms.cpp
46

Can we please avoid global cl opts?

971

This check is duplicated, are you trying to check elementType.isa<IntegerType>()

nicolasvasilache marked 7 inline comments as done.Mar 12 2020, 7:31 AM
nicolasvasilache added inline comments.
mlir/include/mlir/Dialect/Utils/StructuredOpsUtils.h
42

I didn't want to invest too much in column major patterns in this PR, can we keep as a followup to add more patterns on a per need basis?
We can also do much more with transposes once we have them in MLIR + retargeting LLVM intrinsics.

mlir/test/Dialect/VectorOps/vector-contract-transforms.mlir
1–2

Ack

nicolasvasilache marked 2 inline comments as done.

Address review comments.

Thanks for the reviews!

aartbik accepted this revision.Mar 12 2020, 1:42 PM
This revision is now accepted and ready to land.Mar 12 2020, 1:42 PM
This revision was automatically updated to reflect the committed changes.