llvm/llvm-project

[MLIR][affine] Illegal affine loop fusion with vector types

Open

#115.849 geöffnet am 12. Nov. 2024

Auf GitHub ansehen
 (13 Kommentare) (0 Reaktionen) (1 zugewiesene Person)C++ (10.782 Forks)batch import
good first issuemlir:affine

Repository-Metriken

Stars
 (26.378 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 1T 2h) (1.000 gemergte PRs in 30 T)

Beschreibung

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.

Contributor Guide