Skip to content

[MLIR] Inconsistent output when executing MLIR program with and without -test-math-polynomial-approximation="enable-avx2" #143335

Open
@Lambor24

Description

@Lambor24

My git version is 90beda2.

Description:

I am experiencing an inconsistent result when executing the same MLIR program with and without the -test-math-polynomial-approximation="enable-avx2".

Steps to Reproduce:

1. MLIR Program (test.mlir):

test.mlir:

module attributes {llvm.data_layout = ""} {
  func.func private @printMemrefI64(tensor<*xi64>)
  func.func private @printMemrefF32(tensor<*xf32>)
  func.func @main() {
    %0 = "tosa.const"() <{values = dense<0.000000e+00> : tensor<1xf32>}> : () -> tensor<1xf32>
    %1 = "tosa.const"() <{values = dense<-1.023950e+03> : tensor<1x1x6x3xf32>}> : () -> tensor<1x1x6x3xf32>
    %2 = "tosa.const"() <{values = dense<3.671420e+03> : tensor<4x4x3x1xf32>}> : () -> tensor<4x4x3x1xf32>
    %3 = "tosa.const"() <{values = dense<4.235330e+03> : tensor<3xf32>}> : () -> tensor<3xf32>
    %4 = tosa.depthwise_conv2d %1, %2, %3, %0, %0 {acc_type = f32, dilation = array<i64: 1, 2>, pad = array<i64: 1, 2, 2, 2>, stride = array<i64: 2, 1>} : (tensor<1x1x6x3xf32>, tensor<4x4x3x1xf32>, tensor<3xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x1x4x3xf32>
    %5 = tosa.cos %4 : (tensor<1x1x4x3xf32>) -> tensor<1x1x4x3xf32>
    %cast = tensor.cast %5 : tensor<1x1x4x3xf32> to tensor<*xf32>
    call @printMemrefF32(%cast) : (tensor<*xf32>) -> ()
    return
  }
}

2. Command to Run Without -test-math-polynomial-approximation="enable-avx2":

/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-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -test-lower-to-llvm | \
/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-math-polynomial-approximation="enable-avx2":

[[[[-0.290655,     -0.290655,     -0.290655], 
   [-0.290655,     -0.290655,     -0.290655], 
   [-0.290655,     -0.290655,     -0.290655], 
   [-0.290655,     -0.290655,     -0.290655]]]]

4. Command to Run With -test-math-polynomial-approximation="enable-avx2":

/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-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -test-math-polynomial-approximation="enable-avx2" -test-lower-to-llvm | \
/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-math-polynomial-approximation="enable-avx2":

[[[[-0.841471,     -0.841471,     -0.841471], 
   [-0.841471,     -0.841471,     -0.841471], 
   [-0.841471,     -0.841471,     -0.841471], 
   [-0.841471,     -0.841471,     -0.841471]]]]

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions