-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir][tensor] Generalize/restrict `GeneralizeOuterUnitDimsPackOpPatt…
…ern` This PR _restricts_ `GeneralizeOuterUnitDimsPackOpPattern` by making it follow its intended use (as per the documentation), i.e. to: > require all outer dims of tensor.pack to be 1. There was one test in-tree that violated that assumption (and, happened to work), see `@simple_KCRS_to_KRSCsr` in "generalize-tensor-pack.mlir". That test has been updated to satisfy the updated requirements of the pattern. By making the pattern follow its intended design (i.e. making it stricter), the calculation of shapes and sizes for various Ops that the pattern generates (PadOp + ExtractSliceOp + EmptyOp + TensorOp + InsertSliceOp) becomes much simpler and easier to document. It also helped _generalize_ the pattern to support cases like the one below: ```mlir func.func @simple_pad_and_pack_dynamic_tile_cst( %src: tensor<5x1xf32>, %dest: tensor<1x1x?x2xf32>, %pad: f32) -> tensor<1x1x?x2xf32> { %tile_dim_0 = arith.constant 8 : index %0 = tensor.pack %src padding_value(%pad : f32) inner_dims_pos = [0, 1] inner_tiles = [%tile_dim_0, 2] into %dest : tensor<5x1xf32> -> tensor<1x1x?x2xf32> return %0 : tensor<1x1x?x2xf32> } ``` Note that the inner tile slice is dynamic, but compile-time constant. `getPackOpSourceOrPaddedSource` - that's used to generated PadOp - is able to see that and generates PadOp with static shapes. This a good optimization, but it means that all shapes/sizes for Ops generated by `GeneralizeOuterUnitDimsPackOpPattern` also have to be updated to be constant/static. By _restricting_ the pattern and making the size/shape calculation more straightforward, supporting the case above becomes much easier. Notable implementation changes: * PadOp processes the original source (no change in dimensions/rank). ExtractSliceOp extracts the tile to pack and it may reduce the rank. All ops that follow operate on the tile extracted by ExtractSliceOp (possibly rank-reducded). * All shape/size calculations assume that trailing dims match `inner_tiles` from `tensor.pack`. All the leading dims (i.e. outer dims) are assumed to be 1. * Dynamic sizes for ops like ExtractSliceOp are taken from `inner_tiles` rather than computed as e.g. `tensor.dim %dest, 2`. It's for "producers" of `tensor.pack` to make sure that the dimensions in `%dest` match the specified tile sizes.
- Loading branch information
1 parent
e61a7dc
commit 7f79675
Showing
3 changed files
with
239 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.