Issue 233408
Summary [mlir][vector] Refactor vector unrolling logic
Labels mlir
Assignees
Reporter banach-space
    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 consistent of 3 key components:

* **Patterns for unrolling `Vector` Ops** (located in "mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp" and collected under
[populateVectorUnrollPatterns](https://github.com/llvm/llvm-project/blob/e4fe1207314dd6caed046a5d5fa64b1c76394a17/mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp?plain=1#L1729-L1742)). 
* **Unrolling interface**: [VectorUnrollOpInterface](https://github.com/llvm/llvm-project/blob/e4fe1207314dd6caed046a5d5fa64b1c76394a17/mlir/include/mlir/Interfaces/VectorInterfaces.td?plain=1#L18-L47) (rather basic and used much at the moment).
* **Default configurations for unrolling** (implemented in [TestVectorUnrollingPatterns::runOnOperation](https://github.com/llvm/llvm-project/blob/e4fe1207314dd6caed046a5d5fa64b1c76394a17/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp?plain=1#L160-L301)).

In addition:
* [ApplyUnrollToElementsPatternsOp](https://github.com/llvm/llvm-project/blob/e4fe1207314dd6caed046a5d5fa64b1c76394a17/mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td?plain=1#L394-L403) + [ApplyUnrollContractPatternsOp](https://github.com/llvm/llvm-project/blob/e4fe1207314dd6caed046a5d5fa64b1c76394a17/mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td?plain=1#L373-L392) + [ApplyMultiReductionUnrollingPatternsOp](https://github.com/llvm/llvm-project/blob/e4fe1207314dd6caed046a5d5fa64b1c76394a17/mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td?plain=1#L311-L335) + [ApplyUnrollFromElementsPatternsOp](https://github.com/llvm/llvm-project/blob/e4fe1207314dd6caed046a5d5fa64b1c76394a17/mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td?plain=1#L362-L371) (`Vector` dialect TD Ops)
* [ApplyUnrollVectorsSubgroupMmaOp](https://github.com/llvm/llvm-project/blob/e4fe1207314dd6caed046a5d5fa64b1c76394a17/mlir/include/mlir/Dialect/GPU/TransformOps/GPUTransformOps.td?plain=1#L94-L115) (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 `ApplyUnroll` TD Ops. One TD op should be sufficient to encapsulate this functionality.
* Underused "unrolling" interface.
* The implementation of `TestVectorUnrollingPatterns` is hard to follow and does not scale.

### SOLUTION

1. Lean more on `VectorUnrollOpInterface`.
2. Replace all TD ops with one Op.- `transform.vector.unroll` 
3. Make the interface of `transform.vector.unroll` follow `transform.strucutured.vectorize` (to e.g. specify target shapes).
4. To enable the above, Introduce one central entry point, `unroll`, for all unrolliing logic. This will mimic [vectorize](https://github.com/llvm/llvm-project/blob/e4fe1207314dd6caed046a5d5fa64b1c76394a17/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h?plain=1#L1007-L1013) from Linalg.

### PRs

- [ ] https://github.com/llvm/llvm-project/pull/232648
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to