llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.42k stars 12.15k forks source link

[Mlir][TOSA] Execution crash in mlir-cpu-runner #118264

Open axeabc opened 1 day ago

axeabc commented 1 day ago

I have the following MLIR program:

tosa.mlir

module {
  func.func private @printMemrefI32(tensor<*xi32>)
  func.func private @printMemrefF32(tensor<*xf32>)
  func.func @main() {
    %0 = "tosa.const"() <{value = dense<2> : tensor<1x30x1xi32>}> : () -> tensor<1x30x1xi32>
    %6 = "tosa.const"() <{value = dense<11> : tensor<1x30x1xi32>}> : () -> tensor<1x30x1xi32>
    %7 = "tosa.const"() <{value = dense<55> : tensor<1x30x1xi32>}> : () -> tensor<1x30x1xi32>
    %8 = "tosa.const"() <{value = dense<17> : tensor<1x30x1xi32>}> : () -> tensor<1x30x1xi32>
    %11 = tosa.logical_right_shift %0, %8 : (tensor<1x30x1xi32>, tensor<1x30x1xi32>) -> tensor<1x30x1xi32>
    %25 = tosa.bitwise_and %6, %7 : (tensor<1x30x1xi32>, tensor<1x30x1xi32>) -> tensor<1x30x1xi32>
    %32 = tosa.logical_right_shift %11, %0 : (tensor<1x30x1xi32>, tensor<1x30x1xi32>) -> tensor<1x30x1xi32>
    %42 = tosa.logical_left_shift %32, %25 : (tensor<1x30x1xi32>, tensor<1x30x1xi32>) -> tensor<1x30x1xi32>
    %48 = tosa.bitwise_not %11 : (tensor<1x30x1xi32>) -> tensor<1x30x1xi32>
    %55 = tosa.int_div %48, %42 : (tensor<1x30x1xi32>, tensor<1x30x1xi32>) -> tensor<1x30x1xi32>
    %cast = tensor.cast %6 : tensor<1x30x1xi32> to tensor<*xi32>
    call @printMemrefI32(%cast) : (tensor<*xi32>) -> ()
    return
  }
}

I want to use the following options to print the result of the above program:

/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt tosa.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -tosa-to-arith -convert-math-to-llvm -one-shot-bufferize="bufferize-function-boundaries" -finalize-memref-to-llvm  -convert-linalg-to-loops -convert-scf-to-cf -convert-arith-to-llvm  -finalize-memref-to-llvm  -convert-func-to-llvm -reconcile-unrealized-casts | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so

However, the mlir-cpu-runner will crash:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so
 #0 0x0000558c1cdfa9f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner+0xe069f8)
 #1 0x0000558c1cdf850e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner+0xe0450e)
 #2 0x0000558c1cdfb34d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fdd8d385420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fdd8d3df305 
 #5 0x00007fdd8d3df3dd 
 #6 0x0000558c1d2ffb19 compileAndExecute((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, void**, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) JitRunner.cpp:0:0
 #7 0x0000558c1d2fd122 compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) JitRunner.cpp:0:0
 #8 0x0000558c1d2fb42a mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner+0x130742a)
 #9 0x0000558c1cbc45c7 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner+0xbd05c7)
#10 0x00007fdd8c9a3083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#11 0x0000558c1cbc41ee _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner+0xbd01ee)
llvmbot commented 1 day ago

@llvm/issue-subscribers-mlir

Author: None (axeabc)

I have the following MLIR program: `tosa.mlir` ```mlir module { func.func private @printMemrefI32(tensor<*xi32>) func.func private @printMemrefF32(tensor<*xf32>) func.func @main() { %0 = "tosa.const"() <{value = dense<2> : tensor<1x30x1xi32>}> : () -> tensor<1x30x1xi32> %6 = "tosa.const"() <{value = dense<11> : tensor<1x30x1xi32>}> : () -> tensor<1x30x1xi32> %7 = "tosa.const"() <{value = dense<55> : tensor<1x30x1xi32>}> : () -> tensor<1x30x1xi32> %8 = "tosa.const"() <{value = dense<17> : tensor<1x30x1xi32>}> : () -> tensor<1x30x1xi32> %11 = tosa.logical_right_shift %0, %8 : (tensor<1x30x1xi32>, tensor<1x30x1xi32>) -> tensor<1x30x1xi32> %25 = tosa.bitwise_and %6, %7 : (tensor<1x30x1xi32>, tensor<1x30x1xi32>) -> tensor<1x30x1xi32> %32 = tosa.logical_right_shift %11, %0 : (tensor<1x30x1xi32>, tensor<1x30x1xi32>) -> tensor<1x30x1xi32> %42 = tosa.logical_left_shift %32, %25 : (tensor<1x30x1xi32>, tensor<1x30x1xi32>) -> tensor<1x30x1xi32> %48 = tosa.bitwise_not %11 : (tensor<1x30x1xi32>) -> tensor<1x30x1xi32> %55 = tosa.int_div %48, %42 : (tensor<1x30x1xi32>, tensor<1x30x1xi32>) -> tensor<1x30x1xi32> %cast = tensor.cast %6 : tensor<1x30x1xi32> to tensor<*xi32> call @printMemrefI32(%cast) : (tensor<*xi32>) -> () return } } ``` I want to use the following options to print the result of the above program: ```shell /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt tosa.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -tosa-to-arith -convert-math-to-llvm -one-shot-bufferize="bufferize-function-boundaries" -finalize-memref-to-llvm -convert-linalg-to-loops -convert-scf-to-cf -convert-arith-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so ``` However, the mlir-cpu-runner will crash: ```console PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so #0 0x0000558c1cdfa9f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner+0xe069f8) #1 0x0000558c1cdf850e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner+0xe0450e) #2 0x0000558c1cdfb34d SignalHandler(int) Signals.cpp:0:0 #3 0x00007fdd8d385420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420) #4 0x00007fdd8d3df305 #5 0x00007fdd8d3df3dd #6 0x0000558c1d2ffb19 compileAndExecute((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, void**, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) JitRunner.cpp:0:0 #7 0x0000558c1d2fd122 compileAndExecuteVoidFunction((anonymous namespace)::Options&, mlir::Operation*, llvm::StringRef, (anonymous namespace)::CompileAndExecuteConfig, std::unique_ptr<llvm::TargetMachine, std::default_delete<llvm::TargetMachine>>) JitRunner.cpp:0:0 #8 0x0000558c1d2fb42a mlir::JitRunnerMain(int, char**, mlir::DialectRegistry const&, mlir::JitRunnerConfig) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner+0x130742a) #9 0x0000558c1cbc45c7 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner+0xbd05c7) #10 0x00007fdd8c9a3083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3 #11 0x0000558c1cbc41ee _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner+0xbd01ee) ```