This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg] Do not emit FillOp for tensor.pad with zero padding
ClosedPublic

Authored by springerm on Jun 27 2023, 7:24 AM.

Details

Summary

No need to fill the buffer if no padding is added. I.e., the tensor.pad is packing only.

Also improve tensor::createPadHighOp to use attributes instead of SSA values for high padding sizes when possible.

Depends On: D153555

Diff Detail

Event Timeline

springerm created this revision.Jun 27 2023, 7:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2023, 7:24 AM
springerm requested review of this revision.Jun 27 2023, 7:24 AM
mravishankar requested changes to this revision.Jun 28 2023, 9:15 PM
mravishankar added inline comments.
mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
183–188

This seems strange. Why is there even a pad op if we don't have low pad or high pad. That seems like that pad should be folded away.

This revision now requires changes to proceed.Jun 28 2023, 9:15 PM
springerm marked an inline comment as done.Jun 29 2023, 2:42 AM
springerm added inline comments.
mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
183–188

This is used for "packing" tensor.pad ops. I.e., tensor.pad ops that do not necessarily add any padding, but where a new buffer allocation is required (e.g., in shared memory on GPU). Such tensor.pad ops have a nofold attribute.

If `nofold` is set, the padding operation will not be folded away even
if the source type and the padded type have the same static shape. This can
be used, e.g., for packing or promotion to faster memory.

I'd like to remove the nofold attribute and this kind of use of tensor.pad, but it's used in quite a few places, so this will still take a while. The infrastructure that I've been adding in ConvertToDestinationStyle.cpp (in particular bufferizeToAllocation) over the last weeks will bring us closer to that. (The idea is that we generate a memref allocation right away and do not even have a tensor.pad if there's nothing to pad.)

springerm marked an inline comment as done.Jun 29 2023, 2:45 AM
springerm added inline comments.
mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
183–188

To clarify: We currently use tensor.pad with nofold to force a shared memory allocation (or any allocation in general). I'm working on using a different abstraction instead (memref.alloc). We could not do this until recently because bufferization of mixed tensor/memref IR was not supported.

mravishankar resigned from this revision.Jul 4 2023, 8:45 AM
This revision now requires review to proceed.Jul 4 2023, 8:45 AM
This revision is now accepted and ready to land.Jul 4 2023, 9:22 AM