This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Refactor HoistPadding and add support for hoisting in the absence of packing loops.
ClosedPublic

Authored by nicolasvasilache on Feb 27 2023, 1:39 AM.

Details

Summary

This revision cleans up the implementation of hoist padding and extends it to also work in the
absence of packing loops.
This allows better composition when hoisting the padded result of a DPS operation.

A systematic usage of RewriterBase is applied to the implementation.

Depends on: D144856

Diff Detail

Event Timeline

nicolasvasilache requested review of this revision.Feb 27 2023, 1:39 AM
nicolasvasilache edited the summary of this revision. (Show Details)

Add dependence.

springerm added inline comments.Feb 27 2023, 2:03 AM
mlir/lib/Dialect/Linalg/Transforms/HoistPadding.cpp
45

I think this is not correct if the loop yields iter_args in a swapped order. Or if it yields a value that is not originating from the iter_arg.

Generally speaking, this function looks similar to AnalysisState::findvalueInReverseUseDefChain. In the long term, we could make that function independent of bufferization (make it a function that operates on DestinationStyleOpInterface). But we would also have to model loop bbArgs in DestinationStyleOpInterface, so that we can trace back values through loops.

Avoid potentially incorrect walk back to extractSliceOp.

mlir/lib/Dialect/Linalg/Transforms/HoistPadding.cpp
45

Good point, this indeed requires more thought.

For the particular use case we are interested in here there is a simpler solution which is to try and hoist the extractSlice if the dominance condition is not met.
Updated the PR along these lines.

springerm accepted this revision.Feb 28 2023, 12:02 AM
springerm added inline comments.
mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
2502–2508

I think these could stay asserts if there is a check for the number of low/high padding sizes in the verifier (before calling inferResultType). Functions like ExtractSliceOp::inferResultType also assert.

This revision is now accepted and ready to land.Feb 28 2023, 12:02 AM
nicolasvasilache marked 2 inline comments as done.Feb 28 2023, 4:00 AM
nicolasvasilache added inline comments.
mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
2502–2508

asserts that called by the verifier are a huge footgun as it becomes impossible to do inspect IR that is not well-formed.

nicolasvasilache marked an inline comment as done.Feb 28 2023, 4:02 AM

Rebase and add test.

This revision was landed with ongoing or failed builds.Feb 28 2023, 5:22 AM
This revision was automatically updated to reflect the committed changes.