llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[mlir][vector] Refactor vector unrolling logic

Open banach-space opened this issue 1 month ago • 5 comments

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:

In addition:

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 ApplyUnroll TD Ops. A single 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 by adding methods like getTargetShape, checkCondition, getUnrolledOp.
  2. Replace all TD ops with one Op.- transform.vector.unroll
  3. Make the interface of transform.vector.unroll follow transform.structured.vectorize (to e.g. specify target shapes).
  4. 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

banach-space avatar Oct 19 '26 11:10 banach-space

@llvm/issue-subscribers-mlir

Author: Andrzej Warzyński (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:

In addition:

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 from Linalg.

PRs

  • [ ] https://github.com/llvm/llvm-project/pull/232648

@llvm/issue-subscribers-mlir-vectorops

Author: Andrzej Warzyński (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 three key components:

In addition:

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 ApplyUnroll TD Ops. A single 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 by adding methods like getTargetShape, checkCondition, getUnrolledOp.
  2. Replace all TD ops with one Op.- transform.vector.unroll
  3. Make the interface of transform.vector.unroll follow transform.structured.vectorize (to e.g. specify target shapes).
  4. 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?

StarOne01 avatar Oct 21 '26 11:10 StarOne01

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

banach-space avatar Oct 21 '26 14:10 banach-space

If you'd like to contribute to the Vector dialect, I think issue #227821 is a great place to start @StarOne01 :D

FedericoBruzzone avatar Oct 21 '26 14:10 FedericoBruzzone