[MLIR][affine] Illegal affine loop fusion with vector types
#115,849 建立於 2024年11月12日
倉庫指標
- Star
- (26,378 star)
- PR 合併指標
- (平均合併 1天 2小時) (30 天內合併 1,000 個 PR)
描述
Hi, I was playing around with affine fusion with affine.vector_load/store operations inside loop and came across this particular case:
`func.func @main(%a: memref<64x512xf32>, %b: memref<64x512xf32>, %c: memref<64x512xf32>, %d: memref<64x4096xf32>, %e: memref<64x4096xf32>) {
affine.for %j = 0 to 8 {
%lhs = affine.vector_load %a[0, %j * 64] : memref<64x512xf32>, vector<64x64xf32>
%rhs = affine.vector_load %b[0, %j * 64] : memref<64x512xf32>, vector<64x64xf32>
%res = arith.addf %lhs, %rhs : vector<64x64xf32>
affine.vector_store %res, %c[0, %j * 64] : memref<64x512xf32>, vector<64x64xf32>
}
affine.for %j = 0 to 8 {
%lhs = affine.vector_load %c[0, 0] : memref<64x512xf32>, vector<64x512xf32>
%rhs = affine.vector_load %d[0, %j * 512] : memref<64x4096xf32>, vector<64x512xf32>
%res = arith.subf %lhs, %rhs : vector<64x512xf32>
affine.vector_store %res, %d[0, %j * 512] : memref<64x4096xf32>, vector<64x512xf32>
}
func.return
}`
Upon invoking affine-fusion on this IR with the following command:
mlir-opt --pass-pipeline='builtin.module(affine-loop-fusion)' test.mlir
I see that the loops are getting fused for the above case. Fusion here is illegal since 2nd loop can only be executed once 1st loop completely finishes all its iterations and produces the result to be consumed in 2nd loop. I'm attaching the llvm discourse thread here for further reading about the issue.
https://discourse.llvm.org/t/affine-fusion-legality-for-vector-types/83079
As per the discussion, we should have a bailout in the presence of different-sized element types in the producer/consumer validity checking.