Page MenuHomePhabricator

[mlir][linalg] Add control to pad-slice swap pattern

Authored by antiagainst on Jan 11 2022, 5:50 AM.



The pad-slice swap pattern generates scf.if and tensor.generate
to guard against zero-sized slices if it cannot prove the slice is
always non-zero. This is safe but quite conservative. It can be
unnecessary for cases where we know by problem definition such cases
does not exist, even if with dynamic shaped ops or unknown tile/slice
sizes, e.g., convolution padding size = 1 with kernel dim size = 3.

So this commit introduces a control to the pattern to specify
whether to generate the if constructs to handle such cases better,
given that once the if constructs is materialized, it's very hard
to analyze and simplify.

Diff Detail

Event Timeline

antiagainst created this revision.Jan 11 2022, 5:50 AM
antiagainst requested review of this revision.Jan 11 2022, 5:50 AM

Drop commits from later patches

mravishankar requested changes to this revision.Feb 7 2022, 9:55 AM
mravishankar added inline comments.

Not sure we want to expose such functions as API. This should be added as a general mechansim to the pattern itself. The pattern that does the swap should contain the control function.

This revision now requires changes to proceed.Feb 7 2022, 9:55 AM
antiagainst marked an inline comment as done.Feb 7 2022, 10:24 AM
antiagainst added inline comments.

The swap pattern does expose the control. Here it's meant to pass that control down to the real implementation. Previously the swap pattern directly calls TilingInterface::getTiledImplementation, which hides this implementation. If we don't want to expose this utility, it would mean changing TilingInterface::getTiledImplementation to pass the extra parameter down. That way doesn't feel proper to me..

mravishankar added inline comments.Feb 8 2022, 1:25 PM

Its very hard to control transformations this way. Its avoid a very specific use case that is not ideal. To me it comes down to shape propagation. The decision of whether the zero-slice guard is needed or not should come from just looking at shapes. It will work for static case and wont work for dynamic case, but there are other ways of handling this. This very low level control exposed through the API and is inherently unstable.

mravishankar accepted this revision.Feb 9 2022, 11:29 PM

Had an offline conversation about this. Withdrawing my objection.

This revision is now accepted and ready to land.Feb 9 2022, 11:29 PM
This revision was automatically updated to reflect the committed changes.
antiagainst marked an inline comment as done.