This is an archive of the discontinued LLVM Phabricator instance.

[mlir][vector] Add pattern to drop lead unit dim for Contraction Op
ClosedPublic

Authored by nirvedhmeshram on Feb 7 2022, 5:38 PM.

Details

Summary

If the result operand has a unit leading dim it is removed from all operands. Two special cases arise.

  1. The dim to be dropped may not be leading in the lhs and/or rhs operand. In this case a transpose is first applied to make the dim leading and then it can be dropped.
  2. The dim to be dropped does not exist in the lhs and/or rhs operands. In this case we do not change the corresponding operands.

Test: Added tests in vector-dropleadunitdim-transforms.mlir. Also, moved other tests related to dropping lead unit dim from vector-transforms.mlir to vector-dropleadunitdim-transforms.mlir

Diff Detail

Event Timeline

nirvedhmeshram created this revision.Feb 7 2022, 5:38 PM
nirvedhmeshram requested review of this revision.Feb 7 2022, 5:38 PM
nirvedhmeshram edited the summary of this revision. (Show Details)Feb 7 2022, 5:39 PM
mravishankar resigned from this revision.Feb 8 2022, 8:25 PM

Looks good, overall, added a few style related comments.

mlir/lib/Dialect/Vector/Transforms/VectorDropLeadUnitDim.cpp
9

do you need this?

224

nit, make those ///, here is the mlir rule:
"Uses Doxygen-style (///) comments for top-level and class member definitions, regardless of them being visible as public APIs."
https://mlir.llvm.org/getting_started/DeveloperGuide/#style-guide

227

nit: add a . at the end of the comment

235

nit, getAccType() cannot be null, just use dyn_cast

245–246

Move the comment on top here and below to be consistent with the style in the rest of the file.

263

nit: remove braces for single line if

269

nit: Make it SmallVector<Value>

nirvedhmeshram edited the summary of this revision. (Show Details)
nirvedhmeshram removed a reviewer: mravishankar.
nirvedhmeshram marked 7 inline comments as done.Feb 9 2022, 6:37 AM
nirvedhmeshram added inline comments.
mlir/lib/Dialect/Vector/Transforms/VectorDropLeadUnitDim.cpp
9

Yes, the function isParallelIterator is in this.

nirvedhmeshram marked an inline comment as done and an inline comment as not done.Feb 9 2022, 6:39 AM
nirvedhmeshram added inline comments.
mlir/lib/Dialect/Vector/Transforms/VectorDropLeadUnitDim.cpp
235

I changed dyn_cast_or_null to dyn_cast, do you want me to remove this check as well?

nirvedhmeshram marked an inline comment as not done.Feb 9 2022, 6:39 AM
nirvedhmeshram marked an inline comment as done.Feb 9 2022, 6:51 AM
nirvedhmeshram added inline comments.
mlir/lib/Dialect/Vector/Transforms/VectorDropLeadUnitDim.cpp
235

If it cannot be null then I should not need that check so I have removed it.

ThomasRaoux added inline comments.Feb 9 2022, 10:56 AM
mlir/lib/Dialect/Vector/Transforms/VectorDropLeadUnitDim.cpp
235

contractOp.getAccType() cannot be null but the dynamic cast result can be null so you do need to check if oldAccType is null.

ThomasRaoux added inline comments.Feb 9 2022, 10:58 AM
mlir/lib/Dialect/Vector/Transforms/VectorDropLeadUnitDim.cpp
267

nit: Make it SmallVector<Value> as well here and below.

nirvedhmeshram marked an inline comment as done.
nirvedhmeshram marked an inline comment as done.
nirvedhmeshram edited the summary of this revision. (Show Details)
ThomasRaoux accepted this revision.Feb 9 2022, 1:47 PM
This revision is now accepted and ready to land.Feb 9 2022, 1:47 PM