Open bondhugula opened 5 years ago
The LLVM conversion pass is currently a partial conversion, so no error is emitted if an operation is failed to convert.
But isn't an assertion always a bug? The pass is expected to fail if the conversion fails instead of asserting?
The problem is that the conversion hasn't "failed" in the sense that you expect. A partial conversion allows for unconverted operations to exist the IR (by design). You are expecting a full conversion, in which the conversion fails if any operation is not legalized successfully. I originally intended to mark the llvm conversion as a "full" conversion when I added support for that, but the mlir-cuda-runner currently relies on a partial conversion (it converts some GPU operations to the NVVM dialect).
But isn't an assertion always a bug?
Yes it is.
The pass is expected to fail if the conversion fails instead of asserting?
In case what River wrote above isn't clear: it should do what you expect, it does not for no good reason and the CUDA runner thing should be fixed instead.
But isn't an assertion always a bug?
Yes it is.
The pass is expected to fail if the conversion fails instead of asserting?
In case what River wrote above isn't clear: it should do what you expect, it does not for no good reason and the CUDA runner thing should be fixed instead.
I see - thanks. River's comment gave me the impression that the assertion here was the expected behavior and there wasn't a bug here!
Yes sorry, it is currently expected behavior, but not the desired behavior.
Took another look here: the failure occurs here due to the memory space of the memref (which is 2 in the generated IR). The lowering of the dealloc op succeeds (and the crash is gone) if the memory space is changed to the default (zero). So, there are multiple issues here.
$ mlir-opt -affine-dma-generate -lower-affine -lower-to-llvm nest_3d.mlir
yields the assertion below. I was expecting an error (emitError) if something wasn't supported. Input file appended below.
mlir-opt: /home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Types.h:277: U mlir::Type::cast() const [with U = mlir::LLVM::LLVMType]: Assertion `isa()' failed. Stack dump:
0 0x00000000008dd8be llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:494:22
1 0x00000000008dd951 PrintStackTraceSignalHandler(void*) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:558:1
2 0x00000000008dbc21 llvm::sys::RunSignalHandlers() /home/uday/llvm-project/llvm/lib/Support/Signals.cpp:68:20
3 0x00000000008dd3b5 SignalHandler(int) /home/uday/llvm-project/llvm/lib/Support/Unix/Signals.inc:357:1
4 0x00007ff7f108de80 __restore_rt (/lib64/libpthread.so.0+0x12e80)
5 0x00007ff7f0b52e75 __GI_raise (/lib64/libc.so.6+0x37e75)
6 0x00007ff7f0b3d895 __GI_abort (/lib64/libc.so.6+0x22895)
7 0x00007ff7f0b3d769 _nl_load_domain.cold (/lib64/libc.so.6+0x22769)
8 0x00007ff7f0b4b566 (/lib64/libc.so.6+0x30566)
9 0x000000000053f1a7 mlir::LLVM::LLVMType mlir::Type::cast() const /home/uday/llvm-project/llvm/projects/mlir/include/mlir/IR/Types.h:278:12
10 0x0000000000697d3d (anonymous namespace)::DeallocOpLowering::matchAndRewrite(mlir::Operation, llvm::ArrayRef<mlir::Value>, mlir::PatternRewriter&) const /home/uday/llvm-project/llvm/projects/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp:515:64
11 0x00000000006cce3b mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:547:50
12 0x00000000006cd63d (anonymous namespace)::OperationLegalizer::legalizePattern(mlir::Operation, mlir::RewritePattern, (anonymous namespace)::DialectConversionRewriter&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:694:45
13 0x00000000006cd37b (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, (anonymous namespace)::DialectConversionRewriter&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:659:18
14 0x00000000006ce47a (anonymous namespace)::FunctionConverter::convertBlock((anonymous namespace)::DialectConversionRewriter&, mlir::Block, llvm::DenseSet<mlir::Block, llvm::DenseMapInfo<mlir::Block*> >&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:912:21
15 0x00000000006ce513 (anonymous namespace)::FunctionConverter::convertBlock((anonymous namespace)::DialectConversionRewriter&, mlir::Block, llvm::DenseSet<mlir::Block, llvm::DenseMapInfo<mlir::Block*> >&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:918:15
16 0x00000000006ce513 (anonymous namespace)::FunctionConverter::convertBlock((anonymous namespace)::DialectConversionRewriter&, mlir::Block, llvm::DenseSet<mlir::Block, llvm::DenseMapInfo<mlir::Block*> >&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:918:15
17 0x00000000006ce733 (anonymous namespace)::FunctionConverter::convertRegion((anonymous namespace)::DialectConversionRewriter&, mlir::Region&, bool) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:949:13
18 0x00000000006ce8e3 (anonymous namespace)::FunctionConverter::convertFunction(mlir::FuncOp, mlir::TypeConverter::SignatureConversion*) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:974:13
19 0x00000000006cf637 mlir::applyConversionPatterns(llvm::MutableArrayRef, mlir::ConversionTarget&, mlir::TypeConverter&, std::vector<std::unique_ptr<mlir::RewritePattern, std::default_delete >, std::allocator<std::unique_ptr<mlir::RewritePattern, std::default_delete > > >&&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:1166:15
20 0x00000000006cf3bd mlir::applyConversionPatterns(mlir::ModuleOp, mlir::ConversionTarget&, mlir::TypeConverter&, std::vector<std::unique_ptr<mlir::RewritePattern, std::default_delete >, std::allocator<std::unique_ptr<mlir::RewritePattern, std::default_delete > > >&&) /home/uday/llvm-project/llvm/projects/mlir/lib/Transforms/DialectConversion.cpp:1136:53
21 0x000000000069a224 (anonymous namespace)::LLVMLoweringPass::runOnModule() /home/uday/llvm-project/llvm/projects/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp:1045:15
22 0x00000000005cffb6 mlir::ModulePassBase::run(mlir::ModuleOp, mlir::ModuleAnalysisManager&) /home/uday/llvm-project/llvm/projects/mlir/lib/Pass/Pass.cpp:87:27
23 0x00000000005d0243 mlir::detail::ModulePassExecutor::run(mlir::ModuleOp, mlir::ModuleAnalysisManager&) /home/uday/llvm-project/llvm/projects/mlir/lib/Pass/Pass.cpp:127:15
24 0x00000000005d0a0b mlir::PassManager::run(mlir::ModuleOp) /home/uday/llvm-project/llvm/projects/mlir/lib/Pass/Pass.cpp:261:30
25 0x000000000059d8de performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext, std::vector<mlir::PassRegistryEntry const, std::allocator<mlir::PassRegistryEntry const*> > const&) /home/uday/llvm-project/llvm/projects/mlir/lib/Support/MlirOptMain.cpp:65:13
26 0x000000000059da3e processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete >, bool, bool, std::vector<mlir::PassRegistryEntry const, std::allocator<mlir::PassRegistryEntry const> > const&) /home/uday/llvm-project/llvm/projects/mlir/lib/Support/MlirOptMain.cpp:91:45
27 0x000000000059def5 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete >, std::vector<mlir::PassRegistryEntry const, std::allocator<mlir::PassRegistryEntry const> > const&, bool, bool, bool) /home/uday/llvm-project/llvm/projects/mlir/lib/Support/MlirOptMain.cpp:154:32
28 0x00000000007ad0bf main /home/uday/llvm-project/llvm/projects/mlir/tools/mlir-opt/mlir-opt.cpp:89:16
29 0x00007ff7f0b3ef33 __libc_start_main (/lib64/libc.so.6+0x23f33)
30 0x000000000040b5ce _start (/home/uday/llvm-project/build/bin/mlir-opt+0x40b5ce)
Aborted (core dumped)
func @nest_3d(%A: memref<1024 x 1024 x vector<512 x f32>>, %B: memref<1024 x 1024 x vector<512 x f32>>, %C: memref<1024 x 1024 x vector<512 x f32>>) -> memref<1024 x 1024 x vector<512 x f32>> { affine.for %i = 0 to 1024 { affine.for %j = 0 to 1024 { affine.for %k = 0 to 1024 { %5 = affine.load %A[%i, %k] : memref<1024 x 1024 x vector<512 x f32>> %6 = affine.load %B[%k, %j] : memref<1024 x 1024 x vector<512 x f32>> %7 = affine.load %C[%i, %j] : memref<1024 x 1024 x vector<512 x f32>> %8 = mulf %5, %6 : vector<512xf32> %9 = addf %7, %8 : vector<512xf32> affine.store %9, %C[%i, %j] : memref<1024 x 1024 x vector<512 x f32>> } } } return %C : memref<1024 x 1024 x vector<512 x f32>> }