iree-org / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.
http://iree.dev/
Apache License 2.0
2.58k stars 579 forks source link

support llvm-ir backend codegen for dynamic shape #2013

Closed qqsun8819 closed 3 years ago

qqsun8819 commented 4 years ago

now llvm-ir backend can not support dynamic shape codegen for example for code

func @dynamic_tensor(%arg0: tensor<?xf32>) -> tensor<?xf32>
      attributes { iree.module.export } {
  %0 = "xla_hlo.abs"(%arg0) : (tensor<?xf32>) -> tensor<?xf32>
  return %0 : tensor<?xf32>
}

1 will cause a coredump

iree-run-mlir: external/llvm-project/mlir/include/mlir/IR/Value.h:81: bool mlir::Value::isa() const [U = mlir::BlockArgument]: Assertion `*this
 && "isa<> used on a null type."' failed.
PLEASE submit a bug report to  and include the crash backtrace.
Stack dump:
0.      Program arguments: bazel-bin/iree/tools/iree-run-mlir -iree-hal-target-backends=llvm-ir /tmp/dynabs.mlir -input-value=3xf32=[-1.0, 2.0,
 -3.0]
1.       #0 0x00000000024a934d llvm::sys::PrintStackTrace(llvm::raw_ostream&) (bazel-bin/iree/tools/iree-run-mlir+0x24a934d)
 #1 0x00000000024a7455 llvm::sys::RunSignalHandlers() (bazel-bin/iree/tools/iree-run-mlir+0x24a7455)
 #2 0x00000000024a967a SignalHandler(int) (bazel-bin/iree/tools/iree-run-mlir+0x24a967a)
 #3 0x00007f9577cb16d0 __restore_rt (/lib64/libpthread.so.0+0xf6d0)
 #4 0x00007f95776f3277 raise (/lib64/libc.so.6+0x36277)
 #5 0x00007f95776f4968 abort (/lib64/libc.so.6+0x37968)
 #6 0x00007f95776ec096 __assert_fail_base (/lib64/libc.so.6+0x2f096)
 #7 0x00007f95776ec142 (/lib64/libc.so.6+0x2f142)
 #8 0x0000000000e0cc48 mlir::Value::getType() const (bazel-bin/iree/tools/iree-run-mlir+0xe0cc48)
 #9 0x00000000006ba96f mlir::ValueTypeIterator<llvm::detail::indexed_accessor_range_base<mlir::OperandRange, mlir::OpOperand*, mlir::Value, mli
r::Value, mlir::Value>::iterator>::unwrap(mlir::Value) /proc/self/cwd/external/llvm-project/mlir/include/mlir/IR/OperationSupport.h:692:50
#10 0x00000000006ba96f mlir::ValueTypeIterator<llvm::detail::indexed_accessor_range_base<mlir::OperandRange, mlir::OpOperand*, mlir::Value, mli
r::Value, mlir::Value>::iterator>::operator*() const /proc/self/cwd/external/llvm-project/mlir/include/mlir/IR/OperationSupport.h:698:35
#11 0x00000000006ba96f void llvm::interleave<mlir::ValueTypeIterator<llvm::detail::indexed_accessor_range_base<mlir::OperandRange, mlir::OpOper
and*, mlir::Value, mlir::Value, mlir::Value>::iterator>, void llvm::interleaveComma<mlir::ValueTypeRange<mlir::OperandRange>, mlir::OpAsmPrinte
r, mlir::Type>(mlir::ValueTypeRange<mlir::OperandRange> const&, mlir::OpAsmPrinter&)::'lambda'(mlir::Type const&), void llvm::interleave<mlir::
ValueTypeRange<mlir::OperandRange>, void llvm::interleaveComma<mlir::ValueTypeRange<mlir::OperandRange>, mlir::OpAsmPrinter, mlir::Type>(mlir::
ValueTypeRange<mlir::OperandRange> const&, mlir::OpAsmPrinter&)::'lambda'(mlir::Type const&), mlir::OpAsmPrinter, mlir::Type>(mlir::ValueTypeRa
nge<mlir::OperandRange> const&, mlir::OpAsmPrinter&, mlir::OpAsmPrinter, llvm::StringRef const&)::'lambda'(), void>(mlir::ValueTypeRange<mlir::
OperandRange>, mlir::ValueTypeRange<mlir::OperandRange>, mlir::OpAsmPrinter, mlir::OpAsmPrinter) /proc/self/cwd/external/llvm-project/llvm/incl
ude/llvm/ADT/STLExtras.h:1695:11
#12 0x00000000006972ce llvm::raw_ostream::operator<<(llvm::StringRef) /proc/self/cwd/external/llvm-project/llvm/include/llvm/Support/raw_ostrea
m.h:186:37
#13 0x00000000006972ce llvm::raw_ostream::operator<<(char const*) /proc/self/cwd/external/llvm-project/llvm/include/llvm/Support/raw_ostream.h:
200:18
#14 0x00000000006972ce void mlir::OpAsmPrinter::printFunctionalType<mlir::ValueTypeRange<mlir::OperandRange>, llvm::ArrayRef<mlir::Type> >(mlir::ValueTypeRange<mlir::OperandRange>&&, llvm::ArrayRef<mlir::Type>&&) /proc/self/cwd/external/llvm-project/mlir/include/mlir/IR/OpImplementation.h:135:8
#15 0x0000000000e6268a (anonymous namespace)::OperationPrinter::printGenericOp(mlir::Operation*) (bazel-bin/iree/tools/iree-run-mlir+0xe6268a)
#16 0x0000000000e5c9ae (anonymous namespace)::OperationPrinter::print(mlir::Operation*) (bazel-bin/iree/tools/iree-run-mlir+0xe5c9ae)
#17 0x0000000000e5d757 (anonymous namespace)::OperationPrinter::print(mlir::Block*, bool, bool) (bazel-bin/iree/tools/iree-run-mlir+0xe5d757)
#18 0x0000000000e6286d (anonymous namespace)::OperationPrinter::printRegion(mlir::Region&, bool, bool) (bazel-bin/iree/tools/iree-run-mlir+0xe6286d)
#19 0x0000000000e625b8 (anonymous namespace)::OperationPrinter::printGenericOp(mlir::Operation*) (bazel-bin/iree/tools/iree-run-mlir+0xe625b8)
#20 0x0000000000e5c9ae (anonymous namespace)::OperationPrinter::print(mlir::Operation*) (bazel-bin/iree/tools/iree-run-mlir+0xe5c9ae)
#21 0x0000000000e5c192 mlir::Operation::print(llvm::raw_ostream&, mlir::OpPrintingFlags) (bazel-bin/iree/tools/iree-run-mlir+0xe5c192)
#22 0x0000000000e214df mlir::Operation::emitError(llvm::Twine const&) (bazel-bin/iree/tools/iree-run-mlir+0xe214df)
#23 0x0000000000cf14f2 (anonymous namespace)::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>, mlir::TypeConverter*) (bazel-bin/iree/tools/iree-run-mlir+0xcf14f2)
#24 0x0000000000cf1b09 mlir::applyFullConversion(llvm::ArrayRef<mlir::Operation*>, mlir::ConversionTarget&, mlir::OwningRewritePatternList const&, mlir::TypeConverter*) (bazel-bin/iree/tools/iree-run-mlir+0xcf1b09)
#25 0x0000000000cf1b93 mlir::applyFullConversion(mlir::Operation*, mlir::ConversionTarget&, mlir::OwningRewritePatternList const&, mlir::TypeConverter*) (bazel-bin/iree/tools/iree-run-mlir+0xcf1b93)
#26 0x0000000000480abd mlir::failed(mlir::LogicalResult) /proc/self/cwd/external/llvm-project/mlir/include/mlir/Support/LogicalResult.h:46:23
#27 0x0000000000480abd mlir::iree_compiler::(anonymous namespace)::HALInterfaceToMemrefArgumentsPass::runOnOperation() /proc/self/cwd/iree/compiler/Conversion/LinalgToLLVM/HALInterfaceToMemrefArguments.cpp:201:9
#28 0x0000000000d10c0f mlir::Pass::run(mlir::Operation*, mlir::AnalysisManager) (bazel-bin/iree/tools/iree-run-mlir+0xd10c0f)
#29 0x0000000000d14d71 mlir::PassManager::run(mlir::ModuleOp) (bazel-bin/iree/tools/iree-run-mlir+0xd14d71)
#30 0x00000000009af875 mlir::failed(mlir::LogicalResult) /proc/self/cwd/external/llvm-project/mlir/include/mlir/Support/LogicalResult.h:46:23
#31 0x00000000009af875 mlir::iree_compiler::IREE::HAL::TranslateExecutablesPass::runOnOperation() /proc/self/cwd/iree/compiler/Dialect/HAL/Transforms/TranslateExecutables.cpp:58:13

this is caused by not processing hal.interface.load.constant in HALInterfaceToMemrefArgumentsPass , also with a todo in code: https://github.com/google/iree/blob/master/iree/compiler/Conversion/LinalgToLLVM/HALInterfaceToMemrefArguments.cpp#L81

2 shapex dialect is not processed before converting to llvm ir

MaheshRavishankar commented 3 years ago

Fairly old bug. I think this is fixed now. Closing. Please reopen if needed.