llvm / Polygeist

C/C++ frontend for MLIR. Also features polyhedral optimizations, parallel optimizations, and more!
https://polygeist.llvm.org
Other
494 stars 121 forks source link

compiling OpenMP programs #137

Open tipparajuv opened 2 years ago

tipparajuv commented 2 years ago

Hello, I get an error compiling a simple OpenMP program. Could you please help?

vinodt@m2000host0:/localdata/vinod/Polygeist/Heat3DOpenMP$ mlir-clang -I../llvm-project/clang/lib/Headers main.c mlir-clang: /localdata/vinod/Polygeist/lib/polygeist/Passes/LoopRestructure.cpp:647: void {anonymous}::LoopRestructure::runOnRegion(mlir::DominanceInfo&, mlir::Region&): Assertion `loop.before().getBlocks().size() == 1' failed. PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace. Stack dump:

  1. Program arguments: mlir-clang -I ../llvm-project/clang/lib/Headers main.c

    0 0x00005582c9fca00a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /localdata/vinod/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:0

    1 0x00005582c9fca0c1 PrintStackTraceSignalHandler(void*) /localdata/vinod/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:0

    2 0x00005582c9fc7d75 llvm::sys::RunSignalHandlers() /localdata/vinod/Polygeist/llvm-project/llvm/lib/Support/Signals.cpp:97:0

    3 0x00005582c9fc998b SignalHandler(int) /localdata/vinod/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:0

    4 0x00007fe4c613b980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)

    5 0x00007fe4c4decfb7 raise /build/glibc-S9d2JN/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0

    6 0x00007fe4c4dee921 abort /build/glibc-S9d2JN/glibc-2.27/stdlib/abort.c:81:0

    7 0x00007fe4c4dde48a __assert_fail_base /build/glibc-S9d2JN/glibc-2.27/assert/assert.c:89:0

    8 0x00007fe4c4dde502 (/lib/x86_64-linux-gnu/libc.so.6+0x30502)

    9 0x00005582ca899740 (anonymous namespace)::LoopRestructure::runOnRegion(mlir::DominanceInfo&, mlir::Region&) /localdata/vinod/Polygeist/lib/polygeist/Passes/LoopRestructure.cpp:648:0

    10 0x00005582ca8962d9 (anonymous namespace)::LoopRestructure::runOnFunction() /localdata/vinod/Polygeist/lib/polygeist/Passes/LoopRestructure.cpp:283:0

    11 0x00005582ca816edf mlir::FunctionPass::runOnOperation() /localdata/vinod/Polygeist/llvm-project/mlir/include/mlir/Pass/Pass.h:395:0

    12 0x00005582ccdc53d9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass, mlir::Operation, mlir::AnalysisManager, bool, unsigned int) /localdata/vinod/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:393:0

    13 0x00005582ccdc56ab mlir::detail::OpToOpPassAdaptor::runPipeline(llvm::iterator_range<llvm::pointee_iterator<std::unique_ptr<mlir::Pass, std::default_delete >, mlir::Pass> >, mlir::Operation, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor, mlir::PassInstrumentation::PipelineParentInfo const) /localdata/vinod/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:452:0

    14 0x00005582ccdc611d mlir::detail::OpToOpPassAdaptor::runOnOperationImpl(bool) /localdata/vinod/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:548:0

    15 0x00005582ccdc5e71 mlir::detail::OpToOpPassAdaptor::runOnOperation(bool) /localdata/vinod/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:530:0

    16 0x00005582ccdc53ba mlir::detail::OpToOpPassAdaptor::run(mlir::Pass, mlir::Operation, mlir::AnalysisManager, bool, unsigned int) /localdata/vinod/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:390:0

    17 0x00005582ccdc56ab mlir::detail::OpToOpPassAdaptor::runPipeline(llvm::iterator_range<llvm::pointee_iterator<std::unique_ptr<mlir::Pass, std::default_delete >, mlir::Pass> >, mlir::Operation, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor, mlir::PassInstrumentation::PipelineParentInfo const) /localdata/vinod/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:452:0

    18 0x00005582ccdc6da0 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /localdata/vinod/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:697:0

    19 0x00005582ccdc6be8 mlir::PassManager::run(mlir::Operation*) /localdata/vinod/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:676:0

    20 0x00005582c843eb96 main /localdata/vinod/Polygeist/tools/mlir-clang/mlir-clang.cc:447:0

    21 0x00007fe4c4dcfbf7 __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:344:0

    22 0x00005582c840fb4a _start (/localdata/vinod/Polygeist/build/bin/mlir-clang+0x858b4a)

wsmoses commented 2 years ago

Hi, can you paste the code that triggered the error?

tipparajuv commented 2 years ago

here you go:

https://github.com/simehaa/IPU/blob/89f8a3a298a09ab011157366a9cfe05a042e2988/HeatEquation3D/cpu/main.c

Thank you, Vinod.

tipparajuv commented 2 years ago

I was trying to compile the program first without OpenMP. When I try to compile it with, here is the error:

vinodt@m2000host0:/localdata/vinod/Polygeist/Heat3DOpenMP$ mlir-clang -fopenmp -I../build/projects/openmp/runtime/src -I../llvm-project/clang/lib/Headers main.c mlir-clang: ../llvm-project/llvm/include/llvm/Support/Casting.h:269: typename llvm::cast_retty<X, Y>::ret_type llvm::cast(Y) [with X = clang::CastExpr; Y = clang::Expr; typename llvm::cast_retty<X, Y>::ret_type = clang::CastExpr]: Assertion `isa(Val) && "cast() argument of incompatible type!"' failed. PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace. Stack dump:

  1. Program arguments: mlir-clang -fopenmp -I ../build/projects/openmp/runtime/src -I ../llvm-project/clang/lib/Headers main.c
  2. parser at end of file #0 0x000055e199e8600a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /localdata/vinod/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:0 #1 0x000055e199e860c1 PrintStackTraceSignalHandler(void*) /localdata/vinod/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:0 #2 0x000055e199e83d75 llvm::sys::RunSignalHandlers() /localdata/vinod/Polygeist/llvm-project/llvm/lib/Support/Signals.cpp:97:0 #3 0x000055e199e8598b SignalHandler(int) /localdata/vinod/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:0 #4 0x00007fd96e3d0980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980) #5 0x00007fd96d081fb7 raise /build/glibc-S9d2JN/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0 #6 0x00007fd96d083921 abort /build/glibc-S9d2JN/glibc-2.27/stdlib/abort.c:81:0 #7 0x00007fd96d07348a __assert_fail_base /build/glibc-S9d2JN/glibc-2.27/assert/assert.c:89:0 #8 0x00007fd96d073502 (/lib/x86_64-linux-gnu/libc.so.6+0x30502) #9 0x000055e1983407f3 llvm::cast_retty::ret_type llvm::cast(clang::Expr*) /localdata/vinod/Polygeist/build/../llvm-project/llvm/include/llvm/Support/Casting.h:269:0 #10 0x000055e198389716 MLIRScanner::VisitOMPParallelForDirective(clang::OMPParallelForDirective*) /localdata/vinod/Polygeist/tools/mlir-clang/Lib/CGStmt.cc:295:0 #11 0x000055e198317413 clang::StmtVisitorBase::Visit(clang::Stmt*) /localdata/vinod/Polygeist/build/tools/clang/include/clang/AST/StmtNodes.inc:271:0 #12 0x000055e19838c946 MLIRScanner::VisitCompoundStmt(clang::CompoundStmt*) /localdata/vinod/Polygeist/tools/mlir-clang/Lib/CGStmt.cc:707:0 #13 0x000055e19831712b clang::StmtVisitorBase::Visit(clang::Stmt*) /localdata/vinod/Polygeist/build/tools/clang/include/clang/AST/StmtNodes.inc:73:0 #14 0x000055e1982ce677 MLIRScanner::MLIRScanner(MLIRASTConsumer&, mlir::FuncOp, clang::FunctionDecl const*, mlir::OwningOpRef&, LowerToInfo&) /localdata/vinod/Polygeist/tools/mlir-clang/Lib/clang-mlir.cc:307:0 #15 0x000055e1982f366b MLIRASTConsumer::run() /localdata/vinod/Polygeist/tools/mlir-clang/Lib/clang-mlir.cc:5080:0 #16 0x000055e1982f44b5 MLIRASTConsumer::HandleTopLevelDecl(clang::DeclGroupRef) /localdata/vinod/Polygeist/tools/mlir-clang/Lib/clang-mlir.cc:5232:0 #17 0x000055e19ea49126 clang::ParseAST(clang::Sema&, bool, bool) /localdata/vinod/Polygeist/llvm-project/clang/lib/Parse/ParseAST.cpp:162:0 #18 0x000055e19ba1c76d clang::ASTFrontendAction::ExecuteAction() /localdata/vinod/Polygeist/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1074:0 #19 0x000055e19ba1c036 clang::FrontendAction::Execute() /localdata/vinod/Polygeist/llvm-project/clang/lib/Frontend/FrontendAction.cpp:971:0 #20 0x000055e1982f9353 parseMLIR(char const*, std::vector, std::allocator >, std::allocator, std::allocator > > >, std::__cxx11::basic_string, std::allocator >, std::vector, std::allocator >, std::allocator, std::allocator > > >, std::vector, std::allocator >, std::allocator, std::allocator > > >, mlir::OwningOpRef&, llvm::Triple&, llvm::DataLayout&) /localdata/vinod/Polygeist/tools/mlir-clang/Lib/clang-mlir.cc:5900:0 #21 0x000055e1982fa351 main /localdata/vinod/Polygeist/tools/mlir-clang/mlir-clang.cc:404:0 #22 0x00007fd96d064bf7 __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:344:0 #23 0x000055e1982cbb4a _start (/localdata/vinod/Polygeist/build/bin/mlir-clang+0x858b4a) Aborted (core dumped)
wsmoses commented 2 years ago

Without openmp this should build on main. With OpenMP does indeed still trigger issues, will look into.

tipparajuv commented 2 years ago

Thanks. Could you please share how you are building it without OpenMP?

It will be very useful if it were building with OpenMP :-)

wsmoses commented 2 years ago

Oh a large suite of fixes just landed to main, one of which fixed the issue you saw. But as for command line:

./bin/mlir-clang -resource-dir /home/wmoses/git/Polygeist/mlir-build/lib/clang/14.0.0 -o a.exe heat.c -O3
tipparajuv commented 2 years ago

Thanks. Should the OpenMP version be building error-free with the fixes that landed?

wsmoses commented 2 years ago

Not yet, but I've added support for the requisite OMP single and related in a current PR which should enable that code to run.

tipparajuv commented 2 years ago

thanks. I look forward to your PR being merged and trying it out.

wsmoses commented 2 years ago

Try now on the latest main.

tipparajuv commented 2 years ago

It works, thank you.

Is polymer not being used anymore?

wsmoses commented 2 years ago

Polymer is/can still be used, but it'll be a bit before it can be used on this as the polymer codebase will need to update to the latest llvm & Polygeist commits.

We also need to add scf.parallel raising to affine.parallel for it to work in this case (and probably polymer should take in affine.parallel).

cc @kumasento @ftynse