llvm/llvm-project

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

Open

#115,849 创建于 2024年11月12日

在 GitHub 查看
 (13 评论) (0 反应) (1 负责人)C++ (10,782 fork)batch import
good first issuemlir:affine

仓库指标

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.

贡献者指南