[libcxx-commits] [libcxx] [clang-tools-extra] [clang] [libc] [compiler-rt] [flang] [mlir] [llvm] [mlir][Linalg] Support dynamic tiles in `lower_pack` transform (PR #76003)

lorenzo chelini via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 4 10:43:11 PST 2024


chelini wrote:

> It was suggested to me by @chelini to only have the `reshape` op to handle all cases and get rid of the `expand_shape` op. We can then implement a canonicalizer to convert when valid. I'm all for this, however want to make sure this is the direction we want to go before I start making test changes. Because there will be a lot. For each test there will be several extra lines for populating the `shape` operand of `reshape`, like (from the test i added in this PR)
> 
> ```
> // CHECK-DAG:   %[[C1:.*]] = arith.constant 1 : index
> // CHECK-DAG:   %[[C0:.*]] = arith.constant 0 : index
> // CHECK-DAG:   %[[DIM0:.*]] = tensor.dim %[[ARG1]], %[[C0]]
> // CHECK-DAG:  %[[DIM1:.*]] = tensor.dim %[[ARG1]], %[[C1]]
> // CHECK-DAG:   %[[C3:.*]] = arith.constant 3 : index
> // CHECK-DAG:   %[[C2:.*]] = arith.constant 2 : index
> // CHECK-DAG:  %[[DIM2:.*]] = tensor.dim %[[ARG1]], %[[C2]]
> // CHECK-DAG:  %[[DIM3:.*]] = tensor.dim %[[ARG1]], %[[C3]]
> // CHECK-NEXT:  %[[INIT_SHAPE:.*]] = tensor.empty() : tensor<4xindex>
> // CHECK-NEXT:  %[[SHAPE0:.*]] = tensor.insert %[[DIM0]] into %[[INIT_SHAPE]][%[[C0]]]
> // CHECK-NEXT:  %[[SHAPE1:.*]] = tensor.insert %[[DIM2]] into %[[SHAPE0]][%[[C1]]]
> // CHECK-NEXT:  %[[SHAPE2:.*]] = tensor.insert %[[DIM1]] into %[[SHAPE1]][%[[C2]]]
> // CHECK-NEXT:  %[[SHAPE3:.*]] = tensor.insert %[[DIM3]] into %[[SHAPE2]][%[[C3]]]
> // CHECK-NEXT:  %[[EXPANDED:.*]] = tensor.reshape %[[PADDED]](%[[SHAPE3]])
> ```
> 
> Since this is a relatively expensive change, I'd like to get opinions before I do it.


Thank you @srcarroll for pushing on this. Indeed, to generalize the lowering, we would need to emit a reshape operation, and I think it would be better to consistently emit the reshape and then "strength" reduce it to an expanded shape when possible. What folks think here @nicolasvasilache and @hanhanW? Thanks!

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


More information about the libcxx-commits mailing list