[Mlir-commits] [mlir] [mlir][tensor][NFC] Improve documentation of pack/unpack (PR #72201)
lorenzo chelini
llvmlistbot at llvm.org
Tue Nov 14 00:15:54 PST 2023
================
@@ -1751,42 +1751,66 @@ def Tensor_PackOp : Tensor_RelayoutOp<"pack", [
AttrSizedOperandSegments]> {
let summary = "tensor pack operation";
let description = [{
- The pack operation converts an input tensor to a higher-dimensional tensor
- with a tiled and packed layout. The mandatory `inner_dims_pos` attribute
- specifies a permutation for the original dimensions, while `inner_tiles` is the
- tiling factor for each dimension. The optional attribute `outer_dims_perm`
- specifies the order for the tiled data dimension, while the attribute
- `padding_value` specifies a padding value at the boundary on non-perfectly
- divisible dimensions. Padding is optional:
- - If absent, it is UB if the tile does not perfectly divide the dimension.
- - If present, it will pad along high dimensions (high-padding) to make the
- tile complete.
+ The "pack" operation converts a source tensor of rank `n` into a result
+ tensor of rank `n + k` with a tiled and packed layout (maybe with padding)
+ and optionally transposes some dimensions.
+
+ `inner_dims_pos` (mandatory) specifies `k` source tensor dimensions that are
+ being tiled, where `0 < k <= n`. The order of the dimensions matters: the
+ tiled dimensions (of size `inner_tiles`) are added to the end of the result
+ tensor in the order in which they appear in `inner_dims_pos`.
- Example NC_to_NCnc:
+ `inner_tiles` (mandatory) specifies `k` tile sizes. These tile sizes
+ correspond to the least significant ("inner") result tensor dimension sizes.
+ Tile sizes can be static or dynamic.
+ Example: If `inner_tiles = [16, 32]`, the result tensor has shape
+ `...x16x32`. If `inner_dims_pos = [0, 1]`, the 0th source dimension is tiled
+ by 16 and the 1st source dimension is tiled by 32. Other source dimensions
+ (if any) are not tiled. If `inner_dims_pos = [1, 0]`, the 1st dimension is
+ tiled by 16 and the 0th dimension is tiled by 32.
+
+ Example:
```mlir
- %0 = tensor.pack %source inner_dims_pos = [0, 1]
- inner_tiles = [8, 32] into %dest : tensor<128x256xf32> -> tensor<16x8x8x32xf32>
+ // NC to NCnc
+ %0 = tensor.pack %source inner_dims_pos = [0, 1] inner_tiles = [8, 32]
+ into %dest : tensor<128x256xf32> -> tensor<16x8 x 8x32 xf32>
+ // \ / \ /
+ // outer dims inner dims
----------------
chelini wrote:
nice :)
https://github.com/llvm/llvm-project/pull/72201
More information about the Mlir-commits
mailing list