llvm/llvm-project

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

Open

#115 849 ouverte le 12 nov. 2024

Voir sur GitHub
 (13 commentaires) (0 réactions) (1 assigné)C++ (10 782 forks)batch import
good first issuemlir:affine

Métriques du dépôt

Stars
 (26 378 stars)
Métriques de merge PR
 (Merge moyen 1j 2h) (1 000 PRs mergées en 30 j)

Description

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.

Guide contributeur