daphne-eu / daphne

DAPHNE: An Open and Extensible System Infrastructure for Integrated Data Analysis Pipelines
Apache License 2.0
67 stars 62 forks source link

vectorizedPipelineOp without outputs not supported #874

Open m-birke opened 4 weeks ago

m-birke commented 4 weeks ago

Executing the following script with --vec it gives the error msg below

a = as.matrix([0.506232,0.112481,0.277686,0.147521]);
points = cbind(a, a);
//print(points);
[error]: Lowering pipeline error.{}
PassManager failed module lowering, responsible IR written to module_fail.log.
LowerToLLVMPass failed with the following message [ vectorizedPipelineOp without outputs not supported at the moment! ]
    | Source file -> ".../cbind.daphne":2:9
    |
  2 | points = cbind(a, a);
    |                ^~~

Uncommenting print(points); resolves the problem.

In more complicated scripts which loads data from file and does kernel casts, this error message is not given. It runs into a seg fault instead. By just adding a print statement at the end of the mentioned script, it runs.

Stacktrace:

#0  0x00000000020f3293 in mlir::FileLineColLoc::getFilename() const ()
#1  0x000000000162bda9 in ErrorHandler::compilerError(mlir::Location, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
#2  0x000000000162c5fd in ErrorHandler::compilerError(mlir::Operation*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
#3  0x00000000016a0235 in VectorizedPipelineOpLowering::matchAndRewrite(mlir::daphne::VectorizedPipelineOp, mlir::daphne::VectorizedPipelineOpAdaptor, mlir::ConversionPatternRewriter&) const ()
#4  0x0000000001688273 in mlir::OpConversionPattern<mlir::daphne::VectorizedPipelineOp>::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const ()
#5  0x0000000001def638 in mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const ()
#6  0x0000000001e3e123 in mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) ()
#7  0x0000000001dfc6ea in (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) ()
#8  0x0000000001df22f4 in (anonymous namespace)::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>, llvm::function_ref<void (mlir::Diagnostic&)>) ()
#9  0x0000000001df2a73 in mlir::applyFullConversion(mlir::Operation*, mlir::ConversionTarget&, mlir::FrozenRewritePatternSet const&) ()
#10 0x00000000016993f9 in (anonymous namespace)::DaphneLowerToLLVMPass::runOnOperation() ()
#11 0x0000000001ed02c5 in mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) ()
#12 0x0000000001ed0917 in mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) ()
#13 0x0000000001ed3150 in mlir::PassManager::run(mlir::Operation*) ()
#14 0x000000000144880f in DaphneIrExecutor::runPasses(mlir::ModuleOp) ()
#15 0x00000000013c69ea in startDAPHNE(int, char const**, DaphneLibResult*, int*, DaphneUserConfig&) ()
#16 0x00000000013cbe88 in mainInternal(int, char const**, DaphneLibResult*) ()
#17 0x00007ffff49c4d85 in __libc_start_main () from /lib64/libc.so.6
#18 0x00000000013a5d6e in _start ()
philipportner commented 4 weeks ago

Thanks @m-birke .

Trying our internal script, I can confirm that the error there is the same. We already fail somewhere in the VectorizedPipelineOpLowering rewrite pattern. When we fail there we try to create a readable exception, similar to the one you posted above, but probably have incorrect mlir::FileLineColLoc information so we segfault when creating the error.

More specifically, this happens here.

philipportner commented 4 weeks ago

This is happening because the code that is being vectorized is not used afterwards, so the canonicalize method of the VectorizedPipelineOp is pruning away stuff, leaving something that looks as follows:

"daphne.vectorizedPipeline"(%757, %927, %921, %943, %955, %939, %282) ({
}, {
}) {combines = [], operand_segment_sizes = array<i32: 6, 0, 0, 1>, splits = [1, 0, 1, 0, 0, 0]} : (!daphne.Matrix<?x?xf64>, f64, !daphne.Matrix<?x?xf64>, f64, f64, f64, !daphne.DaphneContext) -> ()

This should be deleted properly so we don't run into the intended exception for this case.