llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

[MLIR]`-pass-pipeline="builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))"` triggers Assertion Failure `isIntOrFloat() && "only integers and floats have a bitwidth"' #116342

Open xisang0 opened 3 days ago

xisang0 commented 3 days ago

Test on commit: https://github.com/llvm/llvm-project/commit/6548b6354d1d990e1c98736f5e7c3de876bedc8e steps to reproduce:

mlir-opt test.mlir  --pass-pipeline="builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))"

test case:

module{
  func.func @test_cast3(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3x!quant.uniform<i16:f32, 0.078431375324726104:128>> {
    %0 = tosa.cast %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3x!quant.uniform<i16:f32, 0.078431375324726104:128>>
    return %0 : tensor<13x21x3x!quant.uniform<i16:f32, 0.078431375324726104:128>>
  }
}

crash trace:

mlir-opt: /home/workdir/llvm-project-19/mlir/lib/IR/Types.cpp:134: unsigned int mlir::Type::getIntOrFloatBitWidth() const: Assertion `isIntOrFloat() && "only integers and floats have a bitwidth"' failed.
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 /home/workdir/test.mlir --pass-pipeline=builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))
 #0 0x00005691117503b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x10723b8)
 #1 0x000056911174dede llvm::sys::RunSignalHandlers() (./mlir-opt+0x106fede)
 #2 0x0000569111750dc8 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007dd08e360520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007dd08e3b49fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007dd08e360476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007dd08e3467f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007dd08e34671b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007dd08e357e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000569114b8b555 mlir::Type::getIntOrFloatBitWidth() const (./mlir-opt+0x44ad555)
#10 0x0000569114387756 createLinalgBodyCalculationForElementwiseOp(mlir::Operation*, mlir::ValueRange, llvm::ArrayRef<mlir::Type>, mlir::ConversionPatternRewriter&) TosaToLinalg.cpp:0:0
#11 0x000056911438536d void llvm::function_ref<void (mlir::OpBuilder&, mlir::Location, mlir::ValueRange)>::callback_fn<emitElementwiseComputation(mlir::ConversionPatternRewriter&, mlir::Location, mlir::Operation*, mlir::ValueRange, llvm::ArrayRef<mlir::OpFoldResult>, mlir::TypeConverter const&)::$_1>(long, mlir::OpBuilder&, mlir::Location, mlir::ValueRange) TosaToLinalg.cpp:0:0
#12 0x0000569111fd9fbe buildGenericRegion(mlir::OpBuilder&, mlir::Location, mlir::Region&, mlir::ValueRange, mlir::ValueRange, llvm::function_ref<void (mlir::OpBuilder&, mlir::Location, mlir::ValueRange)>) LinalgOps.cpp:0:0
#13 0x0000569111fda305 mlir::linalg::GenericOp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::TypeRange, mlir::ValueRange, mlir::ValueRange, llvm::ArrayRef<mlir::AffineMap>, llvm::ArrayRef<mlir::utils::IteratorType>, llvm::StringRef, llvm::StringRef, llvm::function_ref<void (mlir::OpBuilder&, mlir::Location, mlir::ValueRange)>, llvm::ArrayRef<mlir::NamedAttribute>) (./mlir-opt+0x18fc305)
#14 0x0000569111fda5ef mlir::linalg::GenericOp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::TypeRange, mlir::ValueRange, mlir::ValueRange, llvm::ArrayRef<mlir::AffineMap>, llvm::ArrayRef<mlir::utils::IteratorType>, llvm::function_ref<void (mlir::OpBuilder&, mlir::Location, mlir::ValueRange)>, llvm::ArrayRef<mlir::NamedAttribute>) (./mlir-opt+0x18fc5ef)
#15 0x0000569114383207 elementwiseMatchAndRewriteHelper(mlir::Operation*, mlir::ValueRange, mlir::ConversionPatternRewriter&, mlir::TypeConverter const&) TosaToLinalg.cpp:0:0
#16 0x00005691143989a6 mlir::OpConversionPattern<mlir::tosa::CastOp>::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const (./mlir-opt+0x3cba9a6)
#17 0x0000569114a29521 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (./mlir-opt+0x434b521)
#18 0x0000569116a3518a 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
#19 0x0000569116a31dcf 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&)>) (./mlir-opt+0x6353dcf)
#20 0x0000569114a2a51d (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#21 0x0000569114a295b7 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (./mlir-opt+0x434b5b7)
#22 0x0000569114a2a75f mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (./mlir-opt+0x434c75f)
#23 0x0000569114a3217e mlir::applyFullConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (./mlir-opt+0x435417e)
#24 0x000056911436f823 (anonymous namespace)::TosaToLinalg::runOnOperation() TosaToLinalgPass.cpp:0:0
#25 0x00005691149cc6df mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x42ee6df)
#26 0x00005691149ccec2 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x42eeec2)
#27 0x00005691149d25de 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
#28 0x00005691149ce6cb mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (./mlir-opt+0x42f06cb)
#29 0x00005691149cc83c mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x42ee83c)
#30 0x00005691149ccec2 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x42eeec2)
#31 0x00005691149cf66e mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0x42f166e)
#32 0x00005691149c8192 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#33 0x00005691149c7dfb 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
#34 0x0000569114a71ae5 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) (./mlir-opt+0x4393ae5)
#35 0x00005691149c2ff2 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x42e4ff2)
#36 0x00005691149c32a3 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x42e52a3)
#37 0x00005691149c34b2 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x42e54b2)
#38 0x000056911172f5d7 main (./mlir-opt+0x10515d7)
#39 0x00007dd08e347d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#40 0x00007dd08e347e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
chioni16 commented 6 hours ago

Hello @xisang0 , I wanted to understand what the expectation here is. Currently the dialect conversion function (createLinalgBodyCalculationForElementwiseOp requires that both the source and destination types be IntegerType or FloatType, that are both Builtin types. But the target type in the above example is !quant.uniform that is not a Builtin type. So, is it a possible solution to lower the !quant.uniform type to some type that the current tosa dialect conversion functions can handle, before running tosa-to-linalg-named,tosa-to-linalg passes?

Or did you expect the dialect conversion function to rely on some generic interface that returns bitwidth?