This is an archive of the discontinued LLVM Phabricator instance.

[mlir][transform] Extend `MaskedVectorizeOp` to work for regular vectorization too
ClosedPublic

Authored by awarzynski on Aug 12 2023, 4:20 AM.

Details

Summary

This patch extends MaskedVectorizeOp so that it can be used for "regular" (as opposed to "masked") vectorization as well. While we can already use VectorizeOp for "regular" vectorization, that Op will also apply various patterns on top of vectorization. That means that at the moment, when testing the vectorizer with VectorizeOp, we are effectively testing "vectorization + patterns", i.e. 2 things at a time.

With these updates, you can trigger "regular" vectorization with MaskedVectorizeOp by simply skipping the vector sizes:

transform.structured.masked_vectorize %target : !transform.any_op

Following this change we should probably also rename this Op.

Diff Detail

Event Timeline

awarzynski created this revision.Aug 12 2023, 4:20 AM
Herald added a project: Restricted Project. · View Herald Transcript
awarzynski requested review of this revision.Aug 12 2023, 4:20 AM

@nicolasvasilache , mostly following-up on https://reviews.llvm.org/D153687#inline-1486109. Happy to refine this further if it's still the direction that you'd like for us to take.

I also have related https://reviews.llvm.org/D150006 to handle the unroll. Together they allow vectorize + unroll in one go, which is a massive improvement over the current state of things where vector unroll must be applied with a call back post-vectorization. In particular, if we have a Transform op to extract LinalgOp static iteration space sizes then that can be used to inform unroll shape in a natural manner.

Nice! Would it make sense for this op to optionally take vector_sizes? That would unify unmasked and masked vectorization into one op. There's no reason to keep them separate.

Nice! Would it make sense for this op to optionally take vector_sizes? That would unify unmasked and masked vectorization into one op. There's no reason to keep them separate.

Yup, we can do that. That basically means merging VectorizeOneOp with MaskedVectorizeOp. Let me do that first. If we are happy with the result, we can rename MaskedVectorizeOp as something more generic - perhaps VectorizeOneOp :)

Merge VectorizeOneOp into MaskedVectorizeOp

dcaballe accepted this revision.Aug 27 2023, 9:17 PM

LGTM and the change is minor but probably good to give some time to someone more familiar with TD.

This revision is now accepted and ready to land.Aug 27 2023, 9:17 PM
awarzynski retitled this revision from [mlir][transform] Add VectorizeOneOp operation to [mlir][transform] Extend `MaskedVectorizeOp` to work for regular vectorization too.Aug 28 2023, 12:21 AM
awarzynski edited the summary of this revision. (Show Details)

LGTM and the change is minor but probably good to give some time to someone more familiar with TD.

Thanks! I've just updated the summary to match the current version. Will wait for more reviews before landing this.

nicolasvasilache accepted this revision.Aug 29 2023, 4:35 AM

In principle this looks good to me, thanks for this!

Can we update masked_vectorize to vectorize_one_op and be consistent with the doc or will this happen in a followup ?

mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td
2086

typo "vectorization" (according to the other spellings)

2092

can we call this attribute masked_vector_sizes to clarify the intent?

2094

The example does not match the op.

Also, can we drop the vector_sizes spec when inferred ?

2129–2130

Can we make vectorize_nd_extract part of the oilist ?

Free dictionary attributes are always tricky to debug when misspelled.

I also have related https://reviews.llvm.org/D150006 to handle the unroll. Together they allow vectorize + unroll in one go, which is a massive improvement over the current state of things where vector unroll must be applied with a call back post-vectorization. In particular, if we have a Transform op to extract LinalgOp static iteration space sizes then that can be used to inform unroll shape in a natural manner.

@christopherbate I apologize, I completely missed this .. looking

awarzynski marked 4 inline comments as done.Sep 1 2023, 8:18 AM

Can we update masked_vectorize to vectorize_one_op and be consistent with the doc or will this happen in a followup ?

Let me do that in a follow-up patch. I will also address all the other comments before landing this.

mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td
2129–2130

As discussed with @nicolasvasilache, I have started to rename the ops here. That PR is still work in progress but feedback on the new names is already welcome. (Current suggestion: Vectorize => VectorizeChildren and MaskedVectorize => Vectorize.)

As discussed with @nicolasvasilache, I have started to rename the ops here. That PR is still work in progress but feedback on the new names is already welcome. (Current suggestion: Vectorize => VectorizeChildren and MaskedVectorize => Vectorize.

Apologies to Nicolas for the delay with the renaming - it was the next item on my bucket list :(

@ingomueller-net , thanks for taking this on! MaskedVectorize -> Vectorize makes sense to me. Not sure about VectorizeChildren - that op does quite a bit more than plain vectorization.