llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[MLIR] Inconsistent output when executing MLIR program with and without `-scf-for-loop-peeling=peel-front=true`

Open Lambor24 opened this issue 1 year ago • 1 comments

My git version is 32f7f00.

Description:

I am experiencing an inconsistent result when executing the same MLIR program with and without the -scf-for-loop-peeling=peel-front=true.

Steps to Reproduce:

1. MLIR Program (test.mlir):

test.mlir:

module {
  func.func private @printMemrefF32(tensor<*xf32>)
  func.func @main() -> () {
    %arg0 = "tosa.const"() {value = dense<3.88> : tensor<2x2xf32>} : () -> tensor<2x2xf32>
    %0 = tosa.floor %arg0 : (tensor<2x2xf32>) -> tensor<2x2xf32>
    %rtn1 = tensor.cast %0 : tensor<2x2xf32> to tensor<*xf32>
    call @printMemrefF32(%rtn1) : (tensor<*xf32>) -> ()
    return
  }
}

2. Command to Run Without -scf-for-loop-peeling=peel-front=true:

/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-loops -convert-scf-to-cf -expand-strided-metadata -convert-cf-to-llvm -convert-arith-to-llvm -convert-math-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \
/path/llvm-project/build/bin/mlir-cpu-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 -scf-for-loop-peeling=peel-front=true:

[[3,   3], 
 [3,   3]]

4. Command to Run With -scf-for-loop-peeling=peel-front=true:

/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-loops -scf-for-loop-peeling=peel-front=true -convert-scf-to-cf -expand-strided-metadata -convert-cf-to-llvm -convert-arith-to-llvm -convert-math-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \
/path/llvm-project/build/bin/mlir-cpu-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 -scf-for-loop-peeling=peel-front=true:

[[3,   0], 
 [3,   3]]

I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused this result.

Lambor24 avatar Dec 07 '24 09:12 Lambor24

This issue has been fixed.

Lambor24 avatar Jan 04 '26 12:01 Lambor24