Skip to content

[mlir][tosa] Tosa.Resize incorrect arguments assertion crash #142402

Open
@OMaghiarIMG

Description

@OMaghiarIMG

Hello,

Cross-posting from https://discourse.llvm.org/t/tosa-resize-incorrect-arguments-assertion-crash/86599
Using LLVM dec8f13

I have some examples for incorrect Tosa.Resize configurations which cause the pipeline to crash:
Border value is smaller than minimum allowed:

module {
  func.func @main(%arg0: tensor<1x7x5x9xf32> ) -> tensor<*xf32> {
    %0 = tosa.const_shape  {values = dense<[1, 3, 1, 1]> : tensor<4xindex>} : () -> !tosa.shape<4> 
    %1 = tosa.const_shape  {values = dense<[6, 1]> : tensor<2xindex>} : () -> !tosa.shape<2>
    %2 = tosa.const_shape  {values = dense<[-18, 0]> : tensor<2xindex>} : () -> !tosa.shape<2> 
    %3 = tosa.resize %arg0, %0, %1, %2 {mode = "NEAREST_NEIGHBOR"} : (tensor<1x7x5x9xf32>, !tosa.shape<4>, !tosa.shape<2>, !tosa.shape<2>) -> tensor<*xf32> 
    return %3 : tensor<*xf32>
  }
}

Offset value larger than maximum allowed:

module {
  func.func @main(%arg0: tensor<1x7x5x9xf32>) -> tensor<*xf32> {
    %0 = tosa.const_shape  {values = dense<[1, 3, 1, 1]> : tensor<4xindex>} : () -> !tosa.shape<4>
    %1 = tosa.const_shape  {values = dense<[17, 1]> : tensor<2xindex>} : () -> !tosa.shape<2> 
    %2 = tosa.const_shape  {values = dense<0> : tensor<2xindex>} : () -> !tosa.shape<2>
    %3 = tosa.resize %arg0, %0, %1, %2 {mode = "NEAREST_NEIGHBOR"} : (tensor<1x7x5x9xf32>, !tosa.shape<4>, !tosa.shape<2>, !tosa.shape<2>) -> tensor<*xf32> 
    return %3 : tensor<*xf32> 
  }
} 
$ mlir-opt test.mlir --tosa-validate="level=none" --tosa-infer-shapes
<unknown>:0: error: invalid tensor dimension size
mlir-opt: /llvm-project/mlir/include/mlir/IR/StorageUniquerSupport.h:180: static ConcreteT mlir::detail::StorageUserBase<mlir::RankedTensorType, mlir::TensorType, mlir::detail::RankedTensorTypeStorage, mlir::detail::TypeUniquer, mlir::ShapedType::Trait, mlir::ValueSemantics>::get(MLIRContext *, Args &&...) [ConcreteT = mlir::RankedTensorType, BaseT = mlir::TensorType, StorageT = mlir::detail::RankedTensorTypeStorage, UniquerT = mlir::detail::TypeUniquer, Traits = <mlir::ShapedType::Trait, mlir::ValueSemantics>, Args = <llvm::ArrayRef<long> &, mlir::Type &, mlir::Attribute &>]: Assertion `succeeded( ConcreteT::verifyInvariants(getDefaultDiagnosticEmitFn(ctx), args...))' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: build/bin/mlir-opt test.mlir --tosa-validate=level=none --tosa-infer-shapes
 #0 0x00005d0fa92037e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build/bin/mlir-opt+0x34477e8)
 #1 0x00005d0fa920137e llvm::sys::RunSignalHandlers() (build/bin/mlir-opt+0x344537e)
 #2 0x00005d0fa9204031 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007c46b1a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007c46b1a969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007c46b1a969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007c46b1a969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007c46b1a42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007c46b1a287f3 abort ./stdlib/abort.c:81:7
 #9 0x00007c46b1a2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007c46b1a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00005d0fac7fa0f3 (build/bin/mlir-opt+0x6a3e0f3)
#12 0x00005d0fac7fa018 mlir::RankedTensorType::get(llvm::ArrayRef<long>, mlir::Type, mlir::Attribute) (build/bin/mlir-opt+0x6a3e018)
#13 0x00005d0fabe400a6 (anonymous namespace)::propagateShapesInRegion(mlir::Region&, (anonymous namespace)::TypeModificationState&) TosaInferShapes.cpp:0:0
#14 0x00005d0fabe3d7e9 (anonymous namespace)::TosaInferShapes::runOnOperation() TosaInferShapes.cpp:0:0
#15 0x00005d0fac6c79ff mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (build/bin/mlir-opt+0x690b9ff)
#16 0x00005d0fac6c82a0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (build/bin/mlir-opt+0x690c2a0)
#17 0x00005d0fac6ce82e auto void mlir::parallelForEach<__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_0>(mlir::MLIRContext*, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_0&&)::'lambda'(__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>&&)::operator()<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&>(__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>&&) const Pass.cpp:0:0
#18 0x00005d0fac6c9afb mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (build/bin/mlir-opt+0x690dafb)
#19 0x00005d0fac6c7b58 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (build/bin/mlir-opt+0x690bb58)
#20 0x00005d0fac6c82a0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (build/bin/mlir-opt+0x690c2a0)
#21 0x00005d0fac6caa59 mlir::PassManager::run(mlir::Operation*) (build/bin/mlir-opt+0x690ea59)
#22 0x00005d0fac6c2f9b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#23 0x00005d0fac6c2c00 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#24 0x00005d0fac7785a5 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (build/bin/mlir-opt+0x69bc5a5)
#25 0x00005d0fac6bbe65 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (build/bin/mlir-opt+0x68ffe65)
#26 0x00005d0fac6bc118 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (build/bin/mlir-opt+0x6900118)
#27 0x00005d0fac6bc332 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (build/bin/mlir-opt+0x6900332)
#28 0x00005d0fa9151c67 main (build/bin/mlir-opt+0x3395c67)
#29 0x00007c46b1a29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#30 0x00007c46b1a29e40 call_init ./csu/../csu/libc-start.c:128:20
#31 0x00007c46b1a29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#32 0x00005d0fa91517a5 _start (build/bin/mlir-opt+0x33957a5)
Aborted (core dumped)

I believe these should return proper error messages.

Noticed that on compiler explorer the border example passes but infers the shape as 1x-5x4x9.

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashPrefer [crash-on-valid] or [crash-on-invalid]mlir

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions