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

[MLIR] Inconsistent output when executing MLIR program with and without `-tosa-test-quant-utils`

Open Lambor24 opened this issue 1 year ago • 2 comments

My git version is 55fdecc.

Description:

I am experiencing an inconsistent result when executing the same MLIR program with and without the -tosa-test-quant-utils.

Steps to Reproduce:

1. MLIR Program (test.mlir):

test.mlir:

module {
  func.func private @printMemrefI32(tensor<*xi32>)
  func.func @main() -> () {
    %arg0 = "tosa.const"() {value = dense<-4636> : tensor<52x3x2xi64>} : () -> tensor<52x3x2xi64>
    %0 = tosa.reduce_sum %arg0 {axis = 0 : i32} : (tensor<52x3x2xi64>) -> tensor<1x3x2xi64>
    %1 = tosa.equal %0, %0 : (tensor<1x3x2xi64>, tensor<1x3x2xi64>) -> tensor<1x3x2xi1>
    %2 = tosa.cast %1 : (tensor<1x3x2xi1>) -> tensor<1x3x2xi32>
    %rtn2 = tensor.cast %2 : tensor<1x3x2xi32> to tensor<*xi32>
    call @printMemrefI32(%rtn2) : (tensor<*xi32>) -> ()
    return
  }
}

2. Command to Run Without -tosa-test-quant-utils:

/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-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 -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 -tosa-test-quant-utils:

[[[1,    1], 
  [1,    1], 
  [1,    1]]]

4. Command to Run With -tosa-test-quant-utils:

/path/llvm-project/build/bin/mlir-opt test.mlir -tosa-test-quant-utils | \
/path/llvm-project/build/bin/mlir-opt -pass-pipeline='builtin.module(func.func(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 -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 -tosa-test-quant-utils:

[[[-1,    -1], 
  [-1,    -1], 
  [-1,    -1]]]

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 Mar 03 '25 13:03 Lambor24

@llvm/issue-subscribers-mlir

Author: None (Lambor24)

My git version is [55fdecc](https://github.com/llvm/llvm-project/commit/55fdeccc4567bcd4e3f8df0d177195880a194a6a).

Description:

I am experiencing an inconsistent result when executing the same MLIR program with and without the -tosa-test-quant-utils.

Steps to Reproduce:

1. MLIR Program (test.mlir):

test.mlir:

module {
  func.func private @<!-- -->printMemrefI32(tensor&lt;*xi32&gt;)
  func.func @<!-- -->main() -&gt; () {
    %arg0 = "tosa.const"() {value = dense&lt;-4636&gt; : tensor&lt;52x3x2xi64&gt;} : () -&gt; tensor&lt;52x3x2xi64&gt;
    %0 = tosa.reduce_sum %arg0 {axis = 0 : i32} : (tensor&lt;52x3x2xi64&gt;) -&gt; tensor&lt;1x3x2xi64&gt;
    %1 = tosa.equal %0, %0 : (tensor&lt;1x3x2xi64&gt;, tensor&lt;1x3x2xi64&gt;) -&gt; tensor&lt;1x3x2xi1&gt;
    %2 = tosa.cast %1 : (tensor&lt;1x3x2xi1&gt;) -&gt; tensor&lt;1x3x2xi32&gt;
    %rtn2 = tensor.cast %2 : tensor&lt;1x3x2xi32&gt; to tensor&lt;*xi32&gt;
    call @<!-- -->printMemrefI32(%rtn2) : (tensor&lt;*xi32&gt;) -&gt; ()
    return
  }
}

2. Command to Run Without -tosa-test-quant-utils:

/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-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 -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 -tosa-test-quant-utils:

[[[1,    1], 
  [1,    1], 
  [1,    1]]]

4. Command to Run With -tosa-test-quant-utils:

/path/llvm-project/build/bin/mlir-opt test.mlir -tosa-test-quant-utils | \
/path/llvm-project/build/bin/mlir-opt -pass-pipeline='builtin.module(func.func(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 -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 -tosa-test-quant-utils:

[[[-1,    -1], 
  [-1,    -1], 
  [-1,    -1]]]

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

llvmbot avatar Mar 03 '25 13:03 llvmbot

This issue has been fixed.

Lambor24 avatar Jan 04 '26 12:01 Lambor24