This is an archive of the discontinued LLVM Phabricator instance.

Added canonicalization for vector.multi_reduction
ClosedPublic

Authored by vmurali on Sep 30 2022, 4:08 PM.

Details

Summary

If there are reductions only along unit dimensions, then they are folded

Diff Detail

Event Timeline

vmurali created this revision.Sep 30 2022, 4:08 PM
vmurali requested review of this revision.Sep 30 2022, 4:08 PM

Thanks for adding this canonicalizer pattern! LGTM overall. Just a couple of comments.

mlir/lib/Dialect/Vector/IR/VectorOps.cpp
313

nit: Elide -> Fold? (I'm not the best one to provide this feedback but elide sounds more like skip to me)?

Can you also please add doc to this class about the cases that are folded and the ones that are not?

321

I understand this will only fold multi reductions when all the reduction dims are 1. Would it make sense to also support partial folding (e.g., [0, 1], vector<1x64>)?

mlir/test/Dialect/Vector/canonicalize.mlir
1360

I would add a test for the partial folding case even if we don't support it for now.

vmurali added inline comments.Sep 30 2022, 5:55 PM
mlir/lib/Dialect/Vector/IR/VectorOps.cpp
313

I used elide because of https://github.com/vmurali/llvm-project/blob/murali_llvm/mlir/lib/Dialect/Vector/IR/VectorOps.cpp#L452 (it's literally doing the same thing).

I will see about adding the documentation. I didn't bother earlier because it's literally mimicking ReductionOp's canonicalizer.

321

I don't think I understand what partial folding is. Can you give an example?

vmurali updated this revision to Diff 464468.Sep 30 2022, 9:48 PM

Addressed the review comments

vmurali marked 3 inline comments as done.Sep 30 2022, 9:49 PM

Explicitly state that this transform happens only if all the reduction dimensions are unit dimensions.

dcaballe accepted this revision.Oct 5 2022, 11:02 AM

LGTM, thanks!

mlir/lib/Dialect/Vector/IR/VectorOps.cpp
317

// -> /// for doc.

321

Sure, it would be something like:

%0 = vector.multi_reduction <mul>, %source, %acc [3] : vector<5x1x4x1x20xf32> to vector<5x4x20xf32>

Two unit sizes, only one reduced.

This revision is now accepted and ready to land.Oct 5 2022, 11:02 AM
This revision was automatically updated to reflect the committed changes.

I see this failure in some of our tests after this change. Any pointers?

assert.h assertion failed at third_party/llvm/llvm-project/mlir/include/mlir/IR/Value.h:434 in mlir::detail::TypedValue<mlir::VectorType>::TypedValue(Value) [Ty = mlir::VectorType]: !val || val.getType().template isa<Ty>()

I see this failure in some of our tests after this change. Any pointers?

assert.h assertion failed at third_party/llvm/llvm-project/mlir/include/mlir/IR/Value.h:434 in mlir::detail::TypedValue<mlir::VectorType>::TypedValue(Value) [Ty = mlir::VectorType]: !val || val.getType().template isa<Ty>()

On it.