14 Commits

Author SHA1 Message Date
srcarroll
b26ee97537
[MLIR][Linalg] Support dynamic sizes in lower_unpack (#75494) 2023-12-18 19:02:04 +01:00
lorenzo chelini
06c4f78b07
[MLIR][Linalg] improve silenceable failure msg for lower_pack (NFC) (#75053)
Adjust the silenceable failure message as we lower `tensor.unpack` as a
combination of `linalg.transpose` + `tensor.collapse_shape` and
`tensor.extract_slice`.
2023-12-12 13:06:17 +01:00
Oleksandr "Alex" Zinenko
e4384149b5
[mlir] use transform-interpreter in test passes (#70040)
Update most test passes to use the transform-interpreter pass instead of
the test-transform-dialect-interpreter-pass. The new "main" interpreter
pass has a named entry point instead of looking up the top-level op with
`PossibleTopLevelOpTrait`, which is arguably a more understandable
interface. The change is mechanical, rewriting an unnamed sequence into
a named one and wrapping the transform IR in to a module when necessary.

Add an option to the transform-interpreter pass to target a tagged
payload op instead of the root anchor op, which is also useful for repro
generation.

Only the test in the transform dialect proper and the examples have not
been updated yet. These will be updated separately after a more careful
consideration of testing coverage of the transform interpreter logic.
2023-10-24 16:12:34 +02:00
qcolombet
7050ff4615
[mlir] Fix lower_unpack when dynamic dimensions are involved (#68423)
When lowering `tensor.unpack`, we need to use the sizes of the
destination tensor in the final `tensor.extract_slice` operation. Prior
to this patch, when the destination tensor had dynamic dimensions, we
would compute them from the result of the `tensor.unpack` operation
instead of its destination argument.

This would produce invalid IR because the `tensor.dim` operations would
need to appear before the `tensor.extract_slice` operation, but the
input of the `tensor.dim` operations would consume the final result of
the lowering of `tensor.unpack`, which happens after the
`tensor.extract_slice` operation. In other words, the definition
wouldn't dominate its uses.

I.e., we were generating:
```
%dynDim = tensor.dim %defLater, ... <-- %defLater defined below
%res = tensor.extract_slice ..., %dynDim, ...
%defLater = linalg.copy (ins %res)
```

Note: I checked the implementation of `lower_pack` and the code is
correct as far as I can tell.
2023-10-06 22:09:58 +02:00
Spenser Bauman
f32427e044 [mlir][linalg] Fix lowering of tensor.pack operations
Tensor pack operations are optimistically lowered to pad + insert_slice
when the pack operation only pads the input tensor. The existing
lowering emits insert_slice operations which do not meet the
rank-reducibility requirements of insert_slice.

This change updates the logic in linalg::lowerPack to first check the
rank-reducibility requirement. When the requirement is not met, the
lowering will emit the full sequence of pad + expand + transpose.

Reviewed By: chelini

Differential Revision: https://reviews.llvm.org/D159382
2023-09-05 21:08:13 +02:00
Lorenzo Chelini
d2f2ef84e8 [MLIR][Linalg] Respect DPS in lower_unpack
`tensor.unpack` implements the DPS (Destination Passing Style) interface
and expects the result to be "stored" in the `outs` operand, but this is
not the case with the current decomposition as the final operation is a
`tensor.extract_slice` that does not implement DPS. Add a `linalg.copy`
to fix the problem.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D158393
2023-08-22 09:38:48 +02:00
Hanhan Wang
58e4231b34 [mlir][linalg] Fix tensor.pad sizes computation in lowerPack.
The padded sizes should be derived from destination tensor, not source
tensor. There could be more than one incomplete tile in padding domain.

Reviewed By: qedawkins

Differential Revision: https://reviews.llvm.org/D150726
2023-05-18 15:36:50 -07:00
Alex Zinenko
f52b6381be [mlir] update types in remaining Linalg TransformOps test
All ops now support explicit type specification, update types to use
`!transform.any_op` instead of `!pdl.operation` for consistency.

Depends On D144515

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D150592
2023-05-16 08:16:59 +00:00
Hanhan Wang
9d3057c1cf [mlir][Linalg] Add support for lowerPack on dynamic outer shapes.
The revision adds support for tensor.pack op decomposition when all
inner tile sizes are static. The generated tensor.expand_shape op is
still valid because only one of the expanding dimension is dynamic.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D150233
2023-05-11 10:47:19 -07:00
Hanhan Wang
6f87b50be6 [mlir][linalg] Add support for lowering pack with outer_dims_perm.
Reviewed By: chelini, qcolombet

Differential Revision: https://reviews.llvm.org/D148845
2023-04-24 10:39:37 -07:00
Hanhan Wang
5ddff0d8cd [mlir][linalg] Fix a bug in lower_pack when there are no padding values.
Reviewed By: chelini

Differential Revision: https://reviews.llvm.org/D148061
2023-04-14 11:27:00 -07:00
Quentin Colombet
0bfbecf52e [mlir][TransformDialect] Simplify the lowering of pack/unpack when these are just pad/unpad
This patch recognizes when tensor.pack/unpack operations are simple
tensor.pad/unpad (a.k.a. tensor.extract_slice) and lowers them in a simpler
sequence of instruction.

For pack, instead of doing:
```
pad
expand_shape
transpose
```
we do
```
pad
insert_slice
```

For unpack, instead of doing:
```
transpose
collapse_shape
extract_slice
```
we do
```
extract_slice
```

Note: returning nullptr for the transform dialect is fine. The related
handles are just ignored by the following transformation.

Differential Revision: https://reviews.llvm.org/D148159
2023-04-13 10:46:36 +00:00
Nicolas Vasilache
7cedd956d0 [mlir][Linalg] Add a transform.structured.lower_unpack op
This revision introduces `transform.structured.lower_unpack` which allows
rewriting a `tensor.unpack` to `transpose` (`linalg.generic`) + `tensor.empty` + `tensor.collapse_shape` + `tensor.extract_slice`

The implementation is currently limited to static pack ops that do not have outer_dims permutations.

Differential Revision: https://reviews.llvm.org/D142889
2023-02-01 02:26:44 -08:00
Nicolas Vasilache
4ca52c6e7e [mlir][Linalg] Add a transform.structured.lower_pack op
This revision introduces `transform.structured.lower_pack` which allows
rewriting a `tensor.pack` to `tensor.pad` + `tensor.expand_shape` + `linalg.transpose`.

The implementation is currently limited to static pack ops that do not have outer_dims permutations.

Differential Revision: https://reviews.llvm.org/D142881
2023-01-31 10:06:08 -08:00