This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Tensor] Introduce a pattern to propagate through `tensor.pad`
ClosedPublic

Authored by chelini on Feb 13 2023, 5:52 AM.

Details

Summary

Introduce a pattern to 'push down' a tensor.unpack through a
tensor.pad. The propagation happens if the unpack does not touch the
padded dimensions.

Diff Detail

Event Timeline

chelini created this revision.Feb 13 2023, 5:52 AM
chelini requested review of this revision.Feb 13 2023, 5:52 AM

Let me know if you want to move this pattern as part of the tensor dialect. Currently, here as I did not want add another test pass just for this single pattern.

hanchung requested changes to this revision.Feb 13 2023, 11:13 AM
hanchung added inline comments.
mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp
468

nit: tensor.pad

471

Should we rename it to PushDownUnPackThroughPadOp or BubbleUpPadThroughUnPack?

476–477

The inputPad is only used here. I think padOp.getSource() contains a solid meaning, so we don't have to declare a variable for it.

506

I think we should add a matching check for padOp.getConstantPaddingValue() because we assume that the pad op has constant padding value in the pattern.

This revision now requires changes to proceed.Feb 13 2023, 11:13 AM
chelini updated this revision to Diff 497265.Feb 14 2023, 3:38 AM
  • Check for getConstantPaddingValue
  • Rename pattern
chelini marked 4 inline comments as done.Feb 14 2023, 3:38 AM
chelini added inline comments.Feb 14 2023, 3:44 AM
mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp
506

I think the method getConstantPaddingValue is a bit misleading. Constant here means 1) a constant-like value, 2) a bb argument from a different block, or 3) a value defined outside the pad block. Looking at the method, it can fail only if: 1) there is no yield in the pad bb or 2) the padding is defined within the block. I never saw these two conditions, and I am not even sure we want allow them in tensor.pad.

hanchung accepted this revision.Feb 14 2023, 12:09 PM
This revision is now accepted and ready to land.Feb 14 2023, 12:09 PM