Skip to content

[mlir] [sparse_tensor] -lower-sparse-ops-to-foreach crashes in decltype(auto) llvm::cast(const From &) [To = mlir::RankedTensorType, From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed. #107807

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

Closed
axeabc opened this issue Sep 9, 2024 · 4 comments · Fixed by #109435
Assignees
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir:sparse Sparse compiler in MLIR

Comments

@axeabc
Copy link

axeabc commented Sep 9, 2024

git version: 0f50330

system: Ubuntu 18.04.6 LTS

reproduce with: mlir-opt -lower-sparse-ops-to-foreach a.mlir

a.mlir:

module {
  func.func private @tensor_dimtolvl_reduction_maxui(%arg0: tensor<*xi32>, %arg1: tensor<?xi1>) -> index {
    %c0 = arith.constant 0 : index
    %dim = tensor.dim %arg0, %c0 : tensor<*xi32>
    return %dim : index
  }
}

stack trace:

mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From &) [To = mlir::RankedTensorType, From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
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-opt -lower-sparse-ops-to-foreach a.mlir
 #0 0x000056450b0d7ff8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d3ff8)
 #1 0x000056450b0d5b0e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d1b0e)
 #2 0x000056450b0d898d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fa6df673420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fa6decb000b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007fa6dec8f859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007fa6dec8f729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007fa6dec8f729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007fa6deca0fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x000056450ceb9cb9 (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2eb5cb9)
#10 0x0000564510ba4aa1 void llvm::function_ref<void ()>::callback_fn<mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>)::$_0>(long) PatternApplicator.cpp:0:0
#11 0x0000564510ba175b mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x6b9d75b)
#12 0x000056450e24028f (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#13 0x000056450e23cabf mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4238abf)
#14 0x000056450ce9f9bb (anonymous namespace)::LowerSparseOpsToForeachPass::runOnOperation() SparseTensorPasses.cpp:0:0
#15 0x000056450e1c4e26 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c0e26)
#16 0x000056450e1c5790 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c1790)
#17 0x000056450e1c7dd2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c3dd2)
#18 0x000056450e1c0601 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#19 0x000056450e1c025b 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
#20 0x000056450e26cef5 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) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4268ef5)
#21 0x000056450e1bb685 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b7685)
#22 0x000056450e1bb92f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b792f)
#23 0x000056450e1bbc5e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b7c5e)
#24 0x000056450b0b8c37 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10b4c37)
#25 0x00007fa6dec91083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#26 0x000056450b0b87be _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10b47be)
@github-actions github-actions bot added the mlir label Sep 9, 2024
@EugeneZelenko EugeneZelenko added the crash Prefer [crash-on-valid] or [crash-on-invalid] label Sep 9, 2024
@CoTinker
Copy link
Contributor

tensor<*xi32> is weird, the correct expression should be tensor<?xi32>.

module {
  func.func private @tensor_dimtolvl_reduction_maxui(%arg0: tensor<?xi32>) -> index {
    %c0 = arith.constant 0 : index
    %dim = tensor.dim %arg0, %c0 : tensor<?xi32>
    return %dim : index
  }
}

@axeabc
Copy link
Author

axeabc commented Sep 11, 2024

Certainly, you're correct. However, in this case, I think that the compiler should report an error rather than crashing.

@CoTinker CoTinker self-assigned this Sep 18, 2024
@CoTinker
Copy link
Contributor

struct SparseTensorDimOpRewriter : public OpRewritePattern<tensor::DimOp> {
using OpRewritePattern::OpRewritePattern;
LogicalResult matchAndRewrite(tensor::DimOp op,
PatternRewriter &rewriter) const override {
std::optional<int64_t> dim = op.getConstantIndex();
auto stt = getSparseTensorType(op.getSource());
if (!dim || !stt.hasEncoding())
return failure();

getSparseTensorType should be replaced with tryGetSparseTensorType.

CoTinker added a commit that referenced this issue Sep 30, 2024
…Type` (#109435)

This PR fixes a bug in `SparseTensorDimOpRewriter` when `tensor.dim` has
an unranked tensor type. To prevent crashes, we now use
`tryGetSparseTensorType` instead of `getSparseTensorType`. Fixes
#107807.
@EugeneZelenko EugeneZelenko added mlir:sparse Sparse compiler in MLIR and removed mlir labels Sep 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 30, 2024

@llvm/issue-subscribers-mlir-sparse

Author: None (axeabc)

git version: 0f50330

system: Ubuntu 18.04.6 LTS

reproduce with: mlir-opt -lower-sparse-ops-to-foreach a.mlir

a.mlir:

module {
  func.func private @<!-- -->tensor_dimtolvl_reduction_maxui(%arg0: tensor&lt;*xi32&gt;, %arg1: tensor&lt;?xi1&gt;) -&gt; index {
    %c0 = arith.constant 0 : index
    %dim = tensor.dim %arg0, %c0 : tensor&lt;*xi32&gt;
    return %dim : index
  }
}

stack trace:

mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From &amp;) [To = mlir::RankedTensorType, From = mlir::Type]: Assertion `isa&lt;To&gt;(Val) &amp;&amp; "cast&lt;Ty&gt;() argument of incompatible type!"' failed.
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-opt -lower-sparse-ops-to-foreach a.mlir
 #<!-- -->0 0x000056450b0d7ff8 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d3ff8)
 #<!-- -->1 0x000056450b0d5b0e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d1b0e)
 #<!-- -->2 0x000056450b0d898d SignalHandler(int) Signals.cpp:0:0
 #<!-- -->3 0x00007fa6df673420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #<!-- -->4 0x00007fa6decb000b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #<!-- -->5 0x00007fa6dec8f859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #<!-- -->6 0x00007fa6dec8f729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #<!-- -->7 0x00007fa6dec8f729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #<!-- -->8 0x00007fa6deca0fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #<!-- -->9 0x000056450ceb9cb9 (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2eb5cb9)
#<!-- -->10 0x0000564510ba4aa1 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&amp;, llvm::function_ref&lt;bool (mlir::Pattern const&amp;)&gt;, llvm::function_ref&lt;void (mlir::Pattern const&amp;)&gt;, llvm::function_ref&lt;llvm::LogicalResult (mlir::Pattern const&amp;)&gt;)::$_0&gt;(long) PatternApplicator.cpp:0:0
#<!-- -->11 0x0000564510ba175b mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&amp;, llvm::function_ref&lt;bool (mlir::Pattern const&amp;)&gt;, llvm::function_ref&lt;void (mlir::Pattern const&amp;)&gt;, llvm::function_ref&lt;llvm::LogicalResult (mlir::Pattern const&amp;)&gt;) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x6b9d75b)
#<!-- -->12 0x000056450e24028f (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#<!-- -->13 0x000056450e23cabf mlir::applyPatternsAndFoldGreedily(mlir::Region&amp;, mlir::FrozenRewritePatternSet const&amp;, mlir::GreedyRewriteConfig, bool*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4238abf)
#<!-- -->14 0x000056450ce9f9bb (anonymous namespace)::LowerSparseOpsToForeachPass::runOnOperation() SparseTensorPasses.cpp:0:0
#<!-- -->15 0x000056450e1c4e26 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c0e26)
#<!-- -->16 0x000056450e1c5790 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c1790)
#<!-- -->17 0x000056450e1c7dd2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c3dd2)
#<!-- -->18 0x000056450e1c0601 performActions(llvm::raw_ostream&amp;, std::shared_ptr&lt;llvm::SourceMgr&gt; const&amp;, mlir::MLIRContext*, mlir::MlirOptMainConfig const&amp;) MlirOptMain.cpp:0:0
#<!-- -->19 0x000056450e1c025b llvm::LogicalResult llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;)&gt;::callback_fn&lt;mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;)::$_0&gt;(long, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;) MlirOptMain.cpp:0:0
#<!-- -->20 0x000056450e26cef5 mlir::splitAndProcessBuffer(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;)&gt;, llvm::raw_ostream&amp;, llvm::StringRef, llvm::StringRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4268ef5)
#<!-- -->21 0x000056450e1bb685 mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b7685)
#<!-- -->22 0x000056450e1bb92f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&amp;) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b792f)
#<!-- -->23 0x000056450e1bbc5e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&amp;) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b7c5e)
#<!-- -->24 0x000056450b0b8c37 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10b4c37)
#<!-- -->25 0x00007fa6dec91083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#<!-- -->26 0x000056450b0b87be _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10b47be)

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:sparse Sparse compiler in MLIR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants