This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Extract DestinationStyleOpInterface from LinalgStructuredInterface.
ClosedPublic

Authored by akuegel on Aug 18 2022, 4:15 AM.

Details

Summary

There are several use cases where a destination style operation needs an interface
that contains a subset of the methods from LinalgStructuredInterface.
In this change, we move all such methods to a new interface, and add forwarding
methods to LinalgStructuredInterface to make the change the less invasive.
It may be possible to refactor the code later to get rid of (some or all) of the
forwarding methods.
This change also removes the cloneWithMapper interface methods, as it is not used anywhere.

RFC:
https://discourse.llvm.org/t/rfc-interface-for-destination-style-ops/64056

Diff Detail

Event Timeline

akuegel created this revision.Aug 18 2022, 4:15 AM
akuegel requested review of this revision.Aug 18 2022, 4:15 AM
akuegel updated this revision to Diff 453628.Aug 18 2022, 5:26 AM

Fix casts, and rebase.

Just to make sure, no review required yet, I just wanted to show how it would look like if we add casts to the Linalg code. See also discussion in https://discourse.llvm.org/t/rfc-interface-for-destination-style-ops/64056/

akuegel updated this revision to Diff 454460.Aug 22 2022, 5:17 AM

Add forwarding methods.

akuegel edited the summary of this revision. (Show Details)Aug 22 2022, 5:17 AM
akuegel added a reviewer: pifon2a.

This should be ready for review now.

akuegel updated this revision to Diff 454462.Aug 22 2022, 5:20 AM

Fix comment.

nicolasvasilache accepted this revision.Aug 23 2022, 2:14 AM

Thank you for splitting this out @akuegel !

The cast + forwarding seems like it's the best we can do right now in the absence of a dedicated solution for the general problem of interface dependence/composition/inheritance.
If someone else has a better solution, by all means, speak up.

mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
347–353

Please add a comment at each such "cast" along the lines of:

MLIR currently does not support dependent interfaces or interface inheritance.
By construction all ops with StructuredOpInterface must implement DestinationStyleOpInterface.
// TODO: reevaluate the need for a cast when a better mechanism exists.
733

I'd use the same language as above to easily grep through occurrences that will need to be updated when something better exists.

980

comment is off here.

This revision is now accepted and ready to land.Aug 23 2022, 2:14 AM
akuegel updated this revision to Diff 454773.Aug 23 2022, 3:35 AM
akuegel marked an inline comment as done.

Address review comments.

mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
347–353

Thanks for the suggestion :) Done.

980

Already fixed in another upload.

akuegel updated this revision to Diff 454774.Aug 23 2022, 3:41 AM

Fix whitespace issues in comments.

akuegel updated this revision to Diff 454776.Aug 23 2022, 3:48 AM

Fix comment to refer to StructuredOpInterface instead of LinalgStructuredOpInterface.

pifon2a accepted this revision.Aug 23 2022, 3:50 AM

Thank you, Adrian!

mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
889

nit: actually if every DPS op implements getNumInputs() then inputs() and outputs() can be implemented using just the number of inputs. We can make this change later though.

akuegel added inline comments.Aug 23 2022, 3:53 AM
mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
889

Acknowledged.
I think there are also additional cleanups which can be done as a followup.

This revision was landed with ongoing or failed builds.Aug 23 2022, 4:27 AM
This revision was automatically updated to reflect the committed changes.