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][TOSA] --tosa-validate crashed with assertion failure "cannot query rank of unranked shaped type" #67760

Closed
ghost opened this issue Sep 29, 2023 · 0 comments · Fixed by #68509

Comments

@ghost
Copy link

ghost commented Sep 29, 2023

git version: 8c12707

system: Ubuntu 20.04.6 LTS (Focal Fossa)

reproduced with: mlir-opt --tosa-validate a.mlir

a.mlir:

func.func @func2()  {
  %56 = tensor.empty() : tensor<25xi1>
  %82 = tosa.slice %56 {size = array<i64>, start = array<i64>} : (tensor<25xi1>) -> tensor<*xi1>
  return 
}
// Crash will disappear when func.func removed

trace:

mlir-opt: /data/bin/llvm-project/build/tools/mlir/include/mlir/IR/BuiltinTypeInterfaces.h.inc:156: int64_t mlir::ShapedType::getRank() const: Assertion `(*this).hasRank() && "cannot query rank of unranked shaped type"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
 #0 0x000055d5cfd14d4f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x157cd4f)
 #1 0x000055d5cfd11de4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fd5a1fd3420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007fd5a1abe00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007fd5a1a9d859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007fd5a1a9d729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007fd5a1aaefd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x000055d5d1a48907 (anonymous namespace)::TosaValidation::levelCheckRank(mlir::Operation*, mlir::Value const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) (.isra.0) TosaValidation.cpp:0:0
 #8 0x000055d5d1a4da01 bool (anonymous namespace)::TosaValidation::levelCheckRanksFor<mlir::tosa::SliceOp>(mlir::Operation*) TosaValidation.cpp:0:0
 #9 0x000055d5d1a50b00 (anonymous namespace)::TosaValidation::levelCheckRanks(mlir::Operation*) TosaValidation.cpp:0:0
#10 0x000055d5d1a531d3 (anonymous namespace)::TosaValidation::applyLevelCheck(mlir::Operation*) TosaValidation.cpp:0:0
#11 0x000055d5d1a54067 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<(anonymous namespace)::TosaValidation::runOnOperation()::'lambda'(mlir::Operation*)>(long, mlir::Operation*) TosaValidation.cpp:0:0
#12 0x000055d5d1a55d65 (anonymous namespace)::TosaValidation::runOnOperation() TosaValidation.cpp:0:0
#13 0x000055d5d2747e8e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x3fafe8e)
#14 0x000055d5d274836a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/bin/llvm-project/build/bin/mlir-opt+0x3fb036a)
#15 0x000055d5d2748d6c mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::'lambda'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&)::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&) const Pass.cpp:0:0
#16 0x000055d5d2748f5f std::_Function_handler<void (), mlir::LogicalResult mlir::failableParallelForEach<__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)::'lambda'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&)&>(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)::'lambda'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&)&)::'lambda'()>::_M_invoke(std::_Any_data const&) Pass.cpp:0:0
#17 0x000055d5d273c762 std::_Function_handler<void (), llvm::ThreadPool::createTaskAndFuture(std::function<void ()>)::'lambda'()>::_M_invoke(std::_Any_data const&) (/data/bin/llvm-project/build/bin/mlir-opt+0x3fa4762)
#18 0x000055d5d55ca298 llvm::ThreadPool::processTasks(llvm::ThreadPoolTaskGroup*) (/data/bin/llvm-project/build/bin/mlir-opt+0x6e32298)
#19 0x000055d5d55cb0d9 void* llvm::thread::ThreadProxy<std::tuple<llvm::ThreadPool::grow(int)::'lambda'()>>(void*) ThreadPool.cpp:0:0
#20 0x00007fd5a1fc7609 start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8609)
#21 0x00007fd5a1b9a133 __clone (/lib/x86_64-linux-gnu/libc.so.6+0x11f133)
Aborted (core dumped)
@github-actions github-actions bot added the mlir label Sep 29, 2023
gptsarthak added a commit to gptsarthak/llvm-project that referenced this issue Oct 11, 2023
levelCheckRank ensures that the tensors for tosa operations are not unranked
Fixes llvm#67760
GeorgeARM pushed a commit that referenced this issue Oct 23, 2023
Fixes #67760
`levelCheckRank` ensures that the tensors for tosa operations are not
unranked

During tosa validation in `levelCheckRank`, we were trying to get the
rank of a tensor without checking if it is ranked or unranked, which
leads to an `assert` error. I see two ways to fix this:

- Only check `type.getRank() > tosa_level.MAX_RANK` if the tensor is
ranked, and then proceed as usual.
(like `if (type.hasRank() && type.getRank() > tosa_level.MAX_RANK)` , OR
- Throw an error for unranked tensors as result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant