llvm / llvm/llvm-project

[MLIR]Inconsistent Results When Using the `-affine-loop-fusion` Pass

Open
#174,580 4 comments 0 reactions 1 assignee Claimed by @ItsGunjit View on GitHub
mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

**test commit**: [5cfd02](https://github.com/llvm/llvm-project/commit/5cfd02f44a43a2e2a085a633b022a62f64ba2b93)

## Description:
I observed an inconsistency in the results depending on whether the `-affine-loop-fusion` pass is used.

## test case
```
module {
func.func private @printMemrefF32(tensor<*xf32>)
func.func @main() {
%0 = "tosa.const"() <{values = dense<4.000000e+00> : tensor<3x7x5xf32>}> : () -> tensor<3x7x5xf32>
%1 = tosa.rsqrt %0 : (tensor<3x7x5xf32>) -> tensor<3x7x5xf32>
%2 = tosa.reduce_sum %1 {axis = 0 : i32} : (tensor<3x7x5xf32>) -> tensor<1x7x5xf32>
%3 = tosa.sigmoid %2 : (tensor<1x7x5xf32>) -> tensor<1x7x5xf32>
%cast = tensor.cast %3 : tensor<1x7x5xf32> to tensor<*xf32>
call @printMemrefF32(%cast) : (tensor<*xf32>) -> ()
return
}
}
```

## Command:
### 1. Without `-affine-loop-fusion`
#### cmd:
```
mlir-opt test.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" | mlir-opt -linalg-fuse-elementwise-ops \
-one-shot-bufferize="bufferize-function-boundaries=1" -expand-strided-metadata -convert-linalg-to-affine-loops \
-lower-affine -convert-scf-to-cf -convert-to-llvm | mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project-latest/build/lib/libmlir_runner_utils.so

```

#### output:
```
[[[0.817574, 0.817574, 0.817574, 0.817574, 0.817574], ...]]]
```
### 2. With `-affine-loop-fusion`:
#### cmd:
```
mlir-opt test.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" | mlir-opt -linalg-fuse-elementwise-ops \
-one-shot-bufferize="bufferize-function-boundaries=1" -expand-strided-metadata -convert-linalg-to-affine-loops \
-affine-loop-fusion -lower-affine -convert-scf-to-cf -convert-to-llvm | mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project-latest/build/lib/libmlir_runner_utils.so

```
#### output:
```
[[[0.952574, 0.952574, 0.952574, 0.952574, 0.952574], ...]]]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.