This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tensor][bufferize] Bufferize tensor.pad
ClosedPublic

Authored by springerm on Aug 22 2022, 1:41 AM.

Details

Summary

tensor.pad is lowered to tensor.generate + tensor.insert_slice during bufferization. For best performance with constant padding values, users should vectorize the IR before bufferizing it.

This change also relaxes tje restriction that no new ops that bufferize to a memory write should be added during bufferization. Since bufferization has been split into two steps a while ago (tensor copy insertion + bufferization), it is reasonable to allow this now.

Diff Detail

Event Timeline

springerm created this revision.Aug 22 2022, 1:41 AM
springerm requested review of this revision.Aug 22 2022, 1:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2022, 1:41 AM
tpopp accepted this revision.Aug 22 2022, 7:34 AM

Nice!

mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
789–790

These methods recompute a vector of values every time, so ideally move them out of the loop. Alternatively, you could only obtain the dynamic values and keep a separate variable for indexing into them, but I like this more.

800

Would it be better to move over all attributes except the few that are PadOp specific? I've seen some place in MLIR provide a filter function for this.

This revision is now accepted and ready to land.Aug 22 2022, 7:34 AM
springerm updated this revision to Diff 454507.Aug 22 2022, 7:59 AM
springerm marked 2 inline comments as done.

address comments

mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
800

Not sure, it's not clear if these attributes would have any meaning on the GenerateOp. (Should they be added to the GenerateOp or the InsertSliceOp, or both?) The escape attribute is very specific to bufferization and only makes sense for the GenerateOp.

This revision was landed with ongoing or failed builds.Aug 22 2022, 8:05 AM
This revision was automatically updated to reflect the committed changes.
mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
746

Some comments and warnings that this will bufferize to tensor.generate which in turn will jump the abstraction gap and bufferize to loops.

Also a // TODO: Reevaluate when we have a higher-level representation on buffers for generate we can avoid that jump.

775

This feels like it should be a first-class citizen of StaticValueUtils.

793

AffineApply of 2 symbols would generally be better and more composable.

811

Can we hoist this into a properly named helper in a some util file close to a notional BuiltinTypeUtils.h ?

springerm marked an inline comment as done.Aug 23 2022, 3:18 AM
springerm added inline comments.
mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
775

That would require a dependency of StaticValueUtils (part of DialectUtils) on a dialect (Arith in this case).

tpopp added inline comments.Aug 23 2022, 3:49 AM
mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
811

I feel like there is a missing method that should exist on the Op similar to getMixedLowPad()

springerm marked 2 inline comments as done.Aug 23 2022, 11:58 PM