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

Han-Chung Wang llvmlistbot at llvm.org
Mon Jul 21 09:29:07 PDT 2025


hanhanW 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:
> 
> ```shell
> // 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?

Yes, it is what I meant; you have better example! I'll modify the PR description a bit.

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


More information about the Mlir-commits mailing list