This is an archive of the discontinued LLVM Phabricator instance.

[mlir][memref] Improve type inference for rank-reducing subviews
ClosedPublic

Authored by springerm on Jul 5 2022, 6:29 AM.

Details

Summary

The result shape of a rank-reducing subview cannot be inferred in the general case. Just the result rank is not enough. The only thing that we can infer is the layout map.

This change also improves the bufferization patterns of tensor.extract_slice and tensor.insert_slice to fully support rank-reducing operations.

Depends On D129143

Diff Detail

Event Timeline

springerm created this revision.Jul 5 2022, 6:29 AM
Herald added a project: Restricted Project. · View Herald Transcript
springerm requested review of this revision.Jul 5 2022, 6:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2022, 6:29 AM
nicolasvasilache accepted this revision.Jul 5 2022, 7:18 AM

Nice!

LGTM conditioned on reusing helpers rather than reinventing.

mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
2165

Please use/adapt/evolve the helper available in BuiltinTypes.h

llvm::Optional<llvm::SmallDenseSet<unsigned>>
mlir::computeRankReductionMask(ArrayRef<int64_t> originalShape,
                               ArrayRef<int64_t> reducedShape);
mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
933

Note: I went through some cleanup and doc effort in https://reviews.llvm.org/D128803.

I haven't yet gone through it for SubViewOp, could you please do it in a followup PR?
I think after that this would still be called inferRankReducedResultType and not inferCanonicalRankReducedTesultType but I am not 100% sure, I'll let you decide.

mlir/lib/Dialect/Vector/Transforms/VectorTransferOpTransforms.cpp
220

Please use std/llvm::copy_if

This revision is now accepted and ready to land.Jul 5 2022, 7:18 AM
springerm updated this revision to Diff 442302.Jul 5 2022, 7:39 AM
springerm marked 2 inline comments as done.

address comments

This revision was landed with ongoing or failed builds.Jul 5 2022, 7:49 AM
This revision was automatically updated to reflect the committed changes.
springerm marked an inline comment as done.Jul 5 2022, 8:15 AM
springerm added inline comments.
mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
933

Yes, it should still be called inferRankReducedResultType. I added similar documentation (wrt. ambiguity) to the op, but I added it to inferRankReducedResultType instead of the op documentation, because it only affects the C++ API. I think the documentation is good, but let me know if you think something is missing.

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

We should have a similar section as https://reviews.llvm.org/D128803 in SubViewOp on differences between inference and verification (with a special discussion for layout).