Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir] Linalg crashes with assertion failure "incorrect # of replacement values" #64067

Open
Colloportus0 opened this issue Jul 24, 2023 · 4 comments
Assignees
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir

Comments

@Colloportus0
Copy link

MLIR built at commit 585cbe3
Reproduced with:
mlir-opt -sparse-compiler=vl=8 temp.mlir

temp.mlir:

module {
  func.func private @func1(%arg0: tensor<?xf16>) { 
    %c0 = arith.constant 0 : index
    %c2 = arith.constant 2 : index  
    %alloc_9 = memref.alloc(%c0, %c2, %c2) : memref<?x?x?xi16>  
    %53 = tensor.empty(%c2, %c2, %c2) : tensor<?x?x?x24xi16>
    %broadcasted = linalg.broadcast ins(%alloc_9 : memref<?x?x?xi16>) outs(%53 : tensor<?x?x?x24xi16>) dimensions = [3] 
    %62 = scf.index_switch %c2 -> index 
    default {
      %141 = memref.alloca_scope  -> (index) { 
        %alloc_33 = memref.alloc(%c2, %c2, %c2) : memref<?x?x24x?xi16>
        linalg.transpose ins(%broadcasted : tensor<?x?x?x24xi16>) outs(%alloc_33 : memref<?x?x24x?xi16>) permutation = [2, 0, 3, 1]  
        memref.alloca_scope.return %c2 : index
      } 
      scf.yield %c2 : index
    } 
    return
  }
}

trace:

Assertion failed: (op->getNumResults() == newValues.size() && "incorrect # of replacement values"), function replaceOp, file PatternMatch.cpp, line 268.
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 -sparse-compiler=vl=8 temp.mlir
 #0 0x0000000102ae0f18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/workspace/build/bin/mlir-opt+0x1002f8f18)
 #1 0x0000000102adf1b4 llvm::sys::RunSignalHandlers() (/workspace/build/bin/mlir-opt+0x1002f71b4)
 #2 0x0000000102ae15c4 SignalHandler(int) (/workspace/build/bin/mlir-opt+0x1002f95c4)
 #3 0x00000001be7894c4 (/usr/lib/system/libsystem_platform.dylib+0x1803414c4)
 #4 0x00000001be771ee0 (/usr/lib/system/libsystem_pthread.dylib+0x180329ee0)
 #5 0x00000001be6ac340 (/usr/lib/system/libsystem_c.dylib+0x180264340)
 #6 0x00000001be6ab754 (/usr/lib/system/libsystem_c.dylib+0x180263754)
 #7 0x00000001070dd614 mlir::RewriterBase::replaceOp(mlir::Operation*, mlir::Operation*) (.cold.1) (/workspace/build/bin/mlir-opt+0x1048f5614)
 #8 0x000000010529b18c mlir::RewriterBase::replaceOp(mlir::Operation*, mlir::ValueRange) (/workspace/build/bin/mlir-opt+0x102ab318c)
 #9 0x000000010357e4d8 mlir::linalg::generalizeNamedOp(mlir::RewriterBase&, mlir::linalg::LinalgOp) (/workspace/build/bin/mlir-opt+0x100d964d8)
#10 0x000000010357ed54 mlir::linalg::LinalgGeneralizationPattern::matchAndRewrite(mlir::linalg::LinalgOp, mlir::PatternRewriter&) const (/workspace/build/bin/mlir-opt+0x100d96d54)
#11 0x00000001067630f0 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&)>)::$_2::operator()() const (/workspace/build/bin/mlir-opt+0x103f7b0f0)
#12 0x00000001067603ec 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&)>) (/workspace/build/bin/mlir-opt+0x103f783ec)
#13 0x000000010518f420 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() (/workspace/build/bin/mlir-opt+0x1029a7420)
#14 0x000000010518cc50 mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/workspace/build/bin/mlir-opt+0x1029a4c50)
#15 0x000000010357efc8 (anonymous namespace)::LinalgGeneralizationPass::runOnOperation() (/workspace/build/bin/mlir-opt+0x100d96fc8)
#16 0x00000001051302a8 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/workspace/build/bin/mlir-opt+0x1029482a8)
#17 0x0000000105130998 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/workspace/build/bin/mlir-opt+0x102948998)
#18 0x0000000105131a4c mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/workspace/build/bin/mlir-opt+0x102949a4c)
#19 0x0000000105130404 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/workspace/build/bin/mlir-opt+0x102948404)
#20 0x0000000105130998 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/workspace/build/bin/mlir-opt+0x102948998)
#21 0x000000010513282c mlir::PassManager::run(mlir::Operation*) (/workspace/build/bin/mlir-opt+0x10294a82c)
#22 0x000000010512ad14 performActions(llvm::raw_ostream&, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) (/workspace/build/bin/mlir-opt+0x102942d14)
#23 0x000000010512a368 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>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_1>(long, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) (/workspace/build/bin/mlir-opt+0x102942368)
#24 0x00000001051a834c 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) (/workspace/build/bin/mlir-opt+0x1029c034c)
#25 0x0000000105124d1c mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/workspace/build/bin/mlir-opt+0x10293cd1c)
#26 0x000000010512518c mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/workspace/build/bin/mlir-opt+0x10293d18c)
#27 0x00000001027eb510 main (/workspace/build/bin/mlir-opt+0x100003510)
#28 0x000000010df11088 
@EugeneZelenko EugeneZelenko added mlir crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Jul 24, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 24, 2023

@llvm/issue-subscribers-mlir

@joker-eph joker-eph added the mlir:sparse Sparse compiler in MLIR label Jul 25, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 25, 2023

@llvm/issue-subscribers-mlir-sparse

@aartbik
Copy link
Contributor

aartbik commented Jul 31, 2023

Thanks for reporting and sorry for the delay (I just got back from a "sparse" holiday ;-)
I can confirm the bug and will work on a fix.

F0000 00:00:1690834996.709801 174973 logging.cc:56] assert.h assertion failed at third_party/llvm/llvm-project/mlir/lib/IR/PatternMatch.cpp:268 in virtual void mlir::RewriterBase::replaceOp(Operation *, ValueRange): op->getNumResults() == newValues.size() && "incorrect # of replacement values"

@aartbik
Copy link
Contributor

aartbik commented Aug 1, 2023

Actually, even though the crash happens in the sparse compiler pipeline (since this is one of the few projects that actually defines a pipeline), it does not seem related to sparse compiler at all. Just running

mlir-opt --linalg-generalize-named-ops temp.mlir

crashes the same way, in LinalgGeneralizationPass.

@aartbik aartbik changed the title [mlir] Sparse Compiler crashed with assertion failure "incorrect # of replacement values" [mlir] Linalg crashes with assertion failure "incorrect # of replacement values" Aug 1, 2023
@aartbik aartbik removed the mlir:sparse Sparse compiler in MLIR label Aug 1, 2023
@aartbik aartbik assigned nicolasvasilache and unassigned aartbik Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir
Projects
None yet
Development

No branches or pull requests

6 participants