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

[mlir] Linalg-fold-unit-extent-dims crashes with assertion violation : N+M <= size() && "Invalid specifier"

Open Colloportus0 opened this issue 3 years ago • 4 comments

MLIR built at commit https://github.com/llvm/llvm-project/commit/a0138390 Reproduced with:
mlir-opt --linalg-fold-unit-extent-dims temp.mlir

temp.mlir:

module {
  func.func @func(%arg0: tensor<128x128x128x128xf32>, %arg1: tensor<1x?x1xf32>, %arg2: tensor<?xf32>, %arg3: index, %arg4: index) -> tensor<128x128x128x128xf32> {
    %inserted_slice = tensor.insert_slice %arg2 into %arg1[0, 0, 0] [1, %arg4, 1] [1, 1, 1] : tensor<?xf32> into tensor<1x?x1xf32>
    %inserted_slice_0 = tensor.insert_slice %inserted_slice into %arg0[6, 7, 8, %arg3] [1, 1, %arg4, 1] [1, 1, 1, 1] : tensor<1x?x1xf32> into tensor<128x128x128x128xf32>
    return %inserted_slice_0 : tensor<128x128x128x128xf32>
  }
}

trace:

Assertion failed: (N+M <= size() && "Invalid specifier"), function slice, file ArrayRef.h, line 194.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: mlir-opt --linalg-fold-unit-extent-dims temp.mlir
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  mlir-opt                 0x00000001042e05bc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  mlir-opt                 0x00000001042df624 llvm::sys::RunSignalHandlers() + 112
2  mlir-opt                 0x00000001042e0c54 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x00000001a56894c4 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001a5671ee0 pthread_kill + 288
5  libsystem_c.dylib        0x00000001a55ac340 abort + 168
6  libsystem_c.dylib        0x00000001a55ab754 err + 0
7  mlir-opt                 0x0000000105ad52f0 computeTensorReshapeCollapsedType(mlir::RankedTensorType, llvm::ArrayRef<mlir::AffineMap>) (.cold.2) + 0
8  mlir-opt                 0x0000000104e7d158 computeTensorReshapeCollapsedType(mlir::RankedTensorType, llvm::ArrayRef<mlir::AffineMap>) + 888
9  mlir-opt                 0x0000000104e7cc78 mlir::tensor::CollapseShapeOp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::Value, llvm::ArrayRef<llvm::SmallVector<long long, 2u>>, llvm::ArrayRef<mlir::NamedAttribute>) + 168
10 mlir-opt                 0x0000000104772150 mlir::tensor::CollapseShapeOp mlir::OpBuilder::create<mlir::tensor::CollapseShapeOp, mlir::detail::TypedValue<mlir::TensorType>, llvm::SmallVector<llvm::SmallVector<long long, 2u>, 1u>&>(mlir::Location, mlir::detail::TypedValue<mlir::TensorType>&&, llvm::SmallVector<llvm::SmallVector<long long, 2u>, 1u>&) + 148
11 mlir-opt                 0x0000000104771f04 (anonymous namespace)::RankReducedInsertSliceOp<mlir::tensor::InsertSliceOp>::matchAndRewrite(mlir::tensor::InsertSliceOp, mlir::PatternRewriter&) const + 484
12 mlir-opt                 0x000000010577fbd0 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) + 1440
13 mlir-opt                 0x000000010553a328 mlir::applyPatternsAndFoldGreedily(llvm::MutableArrayRef<mlir::Region>, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig) + 3808
14 mlir-opt                 0x00000001047753b0 (anonymous namespace)::LinalgFoldUnitExtentDimsPass::runOnOperation() + 900
15 mlir-opt                 0x00000001054eb4dc mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) + 420
16 mlir-opt                 0x00000001054eba0c mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) + 320
17 mlir-opt                 0x00000001054ed388 mlir::PassManager::run(mlir::Operation*) + 1148
18 mlir-opt                 0x00000001054e6840 performActions(llvm::raw_ostream&, bool, bool, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, bool, bool) + 504
19 mlir-opt                 0x00000001054e6410 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0>(long, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) + 704
20 mlir-opt                 0x000000010555102c mlir::splitAndProcessBuffer(std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) + 656
21 mlir-opt                 0x00000001054e4838 mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool) + 216
22 mlir-opt                 0x00000001054e4d2c mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) + 1208
23 mlir-opt                 0x00000001041830a0 main + 108
24 dyld                     0x0000000108b81088 start + 516

Colloportus0 avatar Jan 13 '23 06:01 Colloportus0

@llvm/issue-subscribers-mlir-linalg

llvmbot avatar Jan 13 '23 15:01 llvmbot

Fileless repro:

cat <<EOF | mlir-opt --linalg-fold-unit-extent-dims
func.func @func(%arg0: tensor<128x128x128x128xf32>, %arg1: tensor<1x?x1xf32>, %arg2: tensor<?xf32>, %arg3: index, %arg4: index) -> tensor<128x128x128x128xf32> {
  %inserted_slice = tensor.insert_slice %arg2 into %arg1[0, 0, 0] [1, %arg4, 1] [1, 1, 1] : tensor<?xf32> into tensor<1x?x1xf32>
  %inserted_slice_0 = tensor.insert_slice %inserted_slice into %arg0[6, 7, 8, %arg3] [1, 1, %arg4, 1] [1, 1, 1, 1] : tensor<1x?x1xf32> into tensor<128x128x128x128xf32>
  return %inserted_slice_0 : tensor<128x128x128x128xf32>
}
EOF

nicolasvasilache avatar Jan 20 '23 08:01 nicolasvasilache

still reproducible at 9c4f0d83

Colloportus0 avatar Feb 14 '23 11:02 Colloportus0

I confirmed that this crash is fixed by https://github.com/llvm/llvm-project/pull/74723.

Men-cotton avatar Mar 02 '26 10:03 Men-cotton