Issue |
140543
|
Summary |
[MLIR] Inconsistent output when executing MLIR program with and without `-test-loop-permutation="permutation-map=1,2,0"`
|
Labels |
mlir
|
Assignees |
|
Reporter |
Lambor24
|
My git version is [992458d](https://github.com/llvm/llvm-project/commit/992458d26bbd2b8744408dbb4ab8d6b6058301d6).
## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the `-test-loop-permutation="permutation-map=1,2,0"`.
## Steps to Reproduce:
### 1. **MLIR Program (test.mlir)**:
test.mlir:
```
module {
func.func private @printMemrefI32(tensor<*xi32>)
func.func private @printMemrefF32(tensor<*xf32>)
func.func @main() {
%0 = "tosa.const"() <{values = dense<-6.978000e+01> : tensor<4x3x6x7xf32>}> : () -> tensor<4x3x6x7xf32>
%1 = "tosa.const"() <{values = dense<9.72999954> : tensor<2x3x1x7xf32>}> : () -> tensor<2x3x1x7xf32>
%2 = "tosa.const"() <{values = dense<7.650000e+01> : tensor<2xf32>}> : () -> tensor<2xf32>
%3 = "tosa.const"() <{values = dense<5.610000e+00> : tensor<3x5x2x2xf32>}> : () -> tensor<3x5x2x2xf32>
%4 = "tosa.const"() <{values = dense<-1.892300e+02> : tensor<4xf32>}> : () -> tensor<4xf32>
%5 = "tosa.const"() <{values = dense<0.000000e+00> : tensor<1xf32>}> : () -> tensor<1xf32>
%6 = "tosa.const"() <{values = dense<0.000000e+00> : tensor<1xf32>}> : () -> tensor<1xf32>
%7 = tosa.conv2d %0, %1, %2, %5, %6 {acc_type = f32, dilation = array<i64: 2, 1>, pad = array<i64: 2, 2, 2, 2>, stride = array<i64: 1, 1>} : (tensor<4x3x6x7xf32>, tensor<2x3x1x7xf32>, tensor<2xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<4x3x10x2xf32>
%8 = "tosa.const"() <{values = dense<0.000000e+00> : tensor<1xf32>}> : () -> tensor<1xf32>
%9 = "tosa.const"() <{values = dense<0.000000e+00> : tensor<1xf32>}> : () -> tensor<1xf32>
%10 = tosa.depthwise_conv2d %7, %3, %4, %8, %9 {acc_type = f32, dilation = array<i64: 1, 2>, pad = array<i64: 1, 2, 1, 2>, stride = array<i64: 1, 2>} : (tensor<4x3x10x2xf32>, tensor<3x5x2x2xf32>, tensor<4xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<4x4x3x4xf32>
%11 = tosa.abs %10 : (tensor<4x4x3x4xf32>) -> tensor<4x4x3x4xf32>
%12 = tosa.argmax %11 {axis = 2 : i32} : (tensor<4x4x3x4xf32>) -> tensor<4x4x4xi32>
%cast = tensor.cast %12 : tensor<4x4x4xi32> to tensor<*xi32>
call @printMemrefI32(%cast) : (tensor<*xi32>) -> ()
return
}
}
```
### 2. **Command to Run Without `-test-loop-permutation="permutation-map=1,2,0"`:**
```
/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-tensor -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -lower-affine -convert-scf-to-cf -expand-strided-metadata -convert-cf-to-llvm -convert-arith-to-llvm -convert-math-to-libm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \
/path/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void \
-shared-libs=/path/llvm-project/build/lib/libmlir_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_c_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_async_runtime.so
```
### 3. **Output Without `-test-loop-permutation="permutation-map=1,2,0"`:**
```
[[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]]
```
### 4. **Command to Run With `-test-loop-permutation="permutation-map=1,2,0"`:**
```
/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-tensor -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -test-loop-permutation="permutation-map=1,2,0" -lower-affine -convert-scf-to-cf -expand-strided-metadata -convert-cf-to-llvm -convert-arith-to-llvm -convert-math-to-libm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \
/path/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void \
-shared-libs=/path/llvm-project/build/lib/libmlir_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_c_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_async_runtime.so
```
### 5. **Output With `-test-loop-permutation="permutation-map=1,2,0"`:**
```
[[[0, 0, 0, 0],
[2, 2, 2, 2],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0, 0, 0, 0],
[2, 2, 2, 2],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0, 0, 0, 0],
[2, 2, 2, 2],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0, 0, 0, 0],
[2, 2, 2, 2],
[0, 0, 0, 0],
[0, 0, 0, 0]]]
```
I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused this result.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs