This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg] Convert tensor.pad to destination style
ClosedPublic

Authored by springerm on Jan 20 2023, 5:58 AM.

Details

Summary

This can be a pre-processing for bufferization and allows for more efficient lowerings without an alloc.

Depends On: D142206

Diff Detail

Event Timeline

springerm created this revision.Jan 20 2023, 5:58 AM
springerm requested review of this revision.Jan 20 2023, 5:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2023, 5:58 AM
mravishankar requested changes to this revision.Jan 20 2023, 9:38 AM
mravishankar added inline comments.
mlir/lib/Dialect/Tensor/Transforms/ConvertToDestinationStyle.cpp
164 ↗(On Diff #490803)

This logic is implemented on the pad op using the reifyResultShapes interface...Could we just reuse that?

187 ↗(On Diff #490803)

I am not sure I want to go down this path. This linalg.generic isnt vectorizable AFAIK. We could use a slice and insert, etc. but tahts too cumbersome. For now maybe just handle the zero-padded case....

This revision now requires changes to proceed.Jan 20 2023, 9:38 AM
springerm added inline comments.Jan 20 2023, 12:27 PM
mlir/lib/Dialect/Tensor/Transforms/ConvertToDestinationStyle.cpp
187 ↗(On Diff #490803)

OK then I'm going to add a default linalg.fill lowering here, so that it can vectorize. In the unlikely case that it is not a constant, it will still lower to linalg,generic.

springerm updated this revision to Diff 491275.Jan 23 2023, 3:04 AM

address comments

springerm marked 2 inline comments as done.Jan 23 2023, 3:05 AM
springerm retitled this revision from [mlir][tensor] Convert tensor.pad to destination style to [mlir][linalg] Convert tensor.pad to destination style.Jan 23 2023, 3:57 AM
mravishankar accepted this revision.Jan 23 2023, 12:27 PM

Unblocking, but have one comment remaining.

mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
114

First, I am not sure we need to make this distinction.... constant yielded value is already outside the op.

Even if we need to, could this be made simpler by just having

if (matchPattern(yieldedValue, m_Constant(...)) {
  yieldedValue = ...
}
auto fillOp = rewriter.create<linalg::FillOp>(..., yieldeValue, ...);
This revision is now accepted and ready to land.Jan 23 2023, 12:27 PM
This revision was automatically updated to reflect the committed changes.