This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tensor] Extend reshape utils.
ClosedPublic

Authored by herhut on Feb 14 2022, 8:55 AM.

Details

Summary

This change changes the handling of trailing dimensions with unknown
extent. Users of the changessociationIndicesForReshape helper should
see benefits when transforming reshape like operations into
expand/collapse pairs if the higher-rank type has trailing unknown
dimensions.

The motivating example is a reshape from tensor<16x1x?xi32> to
tensor<16xi32> that can be modeled as collapsing the three dimensions.

Diff Detail

Event Timeline

herhut created this revision.Feb 14 2022, 8:55 AM
herhut requested review of this revision.Feb 14 2022, 8:55 AM

I have always felt this method to be a bit ad-hoc. I wanted to replace this with the logic in this patch https://reviews.llvm.org/D119904 (at line 792 in LinalgOps.cpp). That logic is better defined and easier to follow I think. If you could adapt this to use that approach, that'd be great.

I have always felt this method to be a bit ad-hoc. I wanted to replace this with the logic in this patch https://reviews.llvm.org/D119904 (at line 792 in LinalgOps.cpp). That logic is better defined and easier to follow I think. If you could adapt this to use that approach, that'd be great.

I do not see the immediate connection here. The code you point to ensures that access patterns are identical modulo extent 1 dimensions, i.e., whether both tensors/iteration domains traverse elements in the same order. The code in this review is about deriving from a reshape whether there is a valid collapsing/expansion to model the reshape. This is independent of a potential underlying traversal order (the affine map of the source or target memref is not of concern). So it makes more sense for this code to operate on shapes.

mravishankar accepted this revision.Feb 17 2022, 2:27 PM
This revision is now accepted and ready to land.Feb 17 2022, 2:27 PM
This revision was automatically updated to reflect the committed changes.