[Mlir-commits] [mlir] [mlir][linalg] Restrict linalg.pack to not have extra padding sizes. (PR #149624)

Andrzej WarzyƄski llvmlistbot at llvm.org
Mon Jul 21 06:40:07 PDT 2025


banach-space wrote:

Thanks for drafting and sharing this, @hanhanW !

Let me make sure that I understand correctly :) Below is your original example with a small modification - the input tensor has **9** rather than **8** elements. This way, we need exactly **two** tiles to pack it.
```mlir
func.func @foo(%src: tensor<9xf32>) -> tensor<2x8xf32> {
  %cst = arith.constant 0.000000e+00 : f32
  %dest = tensor.empty() : tensor<2x8xf32>
  %pack = linalg.pack %src
    padding_value(%cst : f32)
    inner_dims_pos = [0]
    inner_tiles = [8] into %dest
    : tensor<8xf32> -> tensor<2x8xf32>
  return %pack : tensor<2x8xf32>
}
```
The 2nd tile will require padding, so `%pack` will look like this:
```bash
// x - original value from %src
// * = %cst
x x x x x x x x
x * * * * * * *
```
This fine and how I expect `linalg.pack` to work.

Now, any tile beyond those 2 tiles above (so, e.g., the additional **98 tiles** "requested" in your original example) would lead to even more "artificial" padding ("artificial" as not strictly required by `linalg.pack`) and you want to disallow that. Is this correct?

I agree that `linalg.pack` should require that there are exactly 2 tiles in the example above. Is that what you had in mind?

https://github.com/llvm/llvm-project/pull/149624


More information about the Mlir-commits mailing list