[mlir][vector] Refactor vector unrolling logic
This is an umbrella ticket to provide rationale and to track work to refactor the vector unrolling logic in the Vector dialect.
WHAT
At the moment, the logic for unrolling Vector Ops consists of three key components:
- Patterns for unrolling
VectorOps (located in "mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp" and collected under populateVectorUnrollPatterns). - Unrolling interface: VectorUnrollOpInterface (currently exposes only a limited query).
- Default configurations for unrolling (implemented in TestVectorUnrollingPatterns::runOnOperation).
In addition:
- ApplyUnrollToElementsPatternsOp + ApplyUnrollContractPatternsOp + ApplyMultiReductionUnrollingPatternsOp + ApplyUnrollFromElementsPatternsOp (
Vectordialect TD Ops) - ApplyUnrollVectorsSubgroupMmaOp (GPU Dialect TD Ops).
PROBLEMS WITH THE CURRENT DESIGN
- The test pass,
TestVectorUnrollingPatterns, contains an expanding collection of hard-coded, operation-specific unrolling configurations, making tests harder to understand and extend. - Proliferation of
ApplyUnrollTD Ops. A single TD op should be sufficient to encapsulate this functionality. - Underused "unrolling" interface.
- The implementation of
TestVectorUnrollingPatternsis hard to follow and does not scale.
SOLUTION
- Lean more on
VectorUnrollOpInterfaceby adding methods likegetTargetShape,checkCondition,getUnrolledOp. - Replace all TD ops with one Op.-
transform.vector.unroll - Make the interface of
transform.vector.unrollfollowtransform.structured.vectorize(to e.g. specify target shapes). - To enable the above, Introduce one central entry point,
unroll, for all unrolling logic. This will mimic vectorize from Linalg.
PRs
- [x] https://github.com/llvm/llvm-project/pull/232648
- [x] https://github.com/llvm/llvm-project/pull/238070
- [x] https://github.com/llvm/llvm-project/pull/238010
- [x] https://github.com/llvm/llvm-project/pull/242315
- [x] https://github.com/llvm/llvm-project/pull/243460
@llvm/issue-subscribers-mlir
Author: Andrzej Warzyński (banach-space)
WHAT
At the moment, the logic for unrolling Vector Ops consistent of 3 key components:
- Patterns for unrolling
VectorOps (located in "mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp" and collected under populateVectorUnrollPatterns). - Unrolling interface: VectorUnrollOpInterface (rather basic and used much at the moment).
- Default configurations for unrolling (implemented in TestVectorUnrollingPatterns::runOnOperation).
In addition:
- ApplyUnrollToElementsPatternsOp + ApplyUnrollContractPatternsOp + ApplyMultiReductionUnrollingPatternsOp + ApplyUnrollFromElementsPatternsOp (
Vectordialect TD Ops) - ApplyUnrollVectorsSubgroupMmaOp (GPU Dialect TD Ops).
WHAT"S WRONG WITH THE CURRENT DESIGN?
- Default shapes for the unrolling logic are hard-coded in a test pass:
TestVectorUnrollingPatterns. - Proliferation of
ApplyUnrollTD Ops. One TD op should be sufficient to encapsulate this functionality. - Underused "unrolling" interface.
- The implementation of
TestVectorUnrollingPatternsis hard to follow and does not scale.
SOLUTION
- Lean more on
VectorUnrollOpInterface. - Replace all TD ops with one Op.-
transform.vector.unroll - Make the interface of
transform.vector.unrollfollowtransform.strucutured.vectorize(to e.g. specify target shapes). - To enable the above, Introduce one central entry point,
unroll, for all unrolliing logic. This will mimic vectorize from Linalg.
PRs
- [ ] https://github.com/llvm/llvm-project/pull/232648
@llvm/issue-subscribers-mlir-vectorops
Author: Andrzej Warzyński (banach-space)
WHAT
At the moment, the logic for unrolling Vector Ops consistent of three key components:
- Patterns for unrolling
VectorOps (located in "mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp" and collected under populateVectorUnrollPatterns). - Unrolling interface: VectorUnrollOpInterface (currently exposes only a limited query).
- Default configurations for unrolling (implemented in TestVectorUnrollingPatterns::runOnOperation).
In addition:
- ApplyUnrollToElementsPatternsOp + ApplyUnrollContractPatternsOp + ApplyMultiReductionUnrollingPatternsOp + ApplyUnrollFromElementsPatternsOp (
Vectordialect TD Ops) - ApplyUnrollVectorsSubgroupMmaOp (GPU Dialect TD Ops).
PROBLEMS WITH THE CURRENT DESIGN
- The test pass,
TestVectorUnrollingPatterns, contains an expanding collection of hard-coded, operation-specific unrolling configurations, making tests harder to understand and extend. - Proliferation of
ApplyUnrollTD Ops. A single TD op should be sufficient to encapsulate this functionality. - Underused "unrolling" interface.
- The implementation of
TestVectorUnrollingPatternsis hard to follow and does not scale.
SOLUTION
- Lean more on
VectorUnrollOpInterfaceby adding methods likegetTargetShape,checkCondition,getUnrolledOp. - Replace all TD ops with one Op.-
transform.vector.unroll - Make the interface of
transform.vector.unrollfollowtransform.structured.vectorize(to e.g. specify target shapes). - To enable the above, Introduce one central entry point,
unroll, for all unrolling logic. This will mimic vectorize from Linalg.
PRs
- [ ] https://github.com/llvm/llvm-project/pull/232648
I would like to work on vector.contract.
i'll move the hard-coded contraction default out of TestVectorUnrollingPatterns and into getTargetShape.
before that i have a question,
should the interface give a default target shape per op, or only interpret one the caller supplies?
Hi @StarOne01,
Thanks for your interest! I’m already working on this downstream, so there isn’t an implementation task to pick up here. Please hold off on making those changes.
I created this ticket to document the overall direction and give reviewers context for the patches I’ll be posting. Reviews of those patches would be welcome.
Thanks,
Andrzej
If you'd like to contribute to the Vector dialect, I think issue #227821 is a great place to start @StarOne01 :D