Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][OpenMP] Initial implementation of taskwait, taskyield and barrier #510

Closed
wants to merge 0 commits into from

Conversation

eZWALT
Copy link
Contributor

@eZWALT eZWALT commented Mar 14, 2024

I wanted to let you know that due to some issues with my local Git setup, I had to close the last PR and reopen it. I apologize for any inconvenience this may cause. Some of the features mentioned in #499 have been thoroughly reviewed and are ready to go. Thank you for your patience!

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks for working on openmp support.

PR looks mostly good!

We try to follow the LLVM codegen skeleton as much as possible, that means that as part of adding these small functionalities, we have to add the skeleton as we go, so it becomes pretty clear where to continue development. See my comments for buildDependences and CIRGenOpenMPRuntime below. You should start mocking those up, shortcuting with llvm_unreacheable and assert(!UnimplementedFeature::someMissingFeature()) for all paths that are not yet available. If you look those up in the CIR codebase you'll find many examples. Let me know if you have questions!


mlir::LogicalResult
CIRGenFunction::buildOMPTaskwaitDirective(const OMPTaskwaitDirective &S) {
mlir::LogicalResult res = mlir::success();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the traditional LLVM codegen in Clang, I see:

  OMPTaskDataTy Data;
  // Build list of dependences
  buildDependences(S, Data);
  Data.HasNowaitClause = S.hasClausesOfKind<OMPNowaitClause>();
  CGM.getOpenMPRuntime().emitTaskwaitCall(*this, S.getBeginLoc(), Data);

For the most part, the CIRGen code should look very similar to this, with the core of buildDependences and emitTaskwaitCall doing the actual MLIR based openMP support in CIR. A good start is to add a simple version of buildDependences and implement the minimal CIRGenOpenMPRuntime needed for a emitTaskwaitCall to build the omp dialect operations.

Copy link
Contributor Author

@eZWALT eZWALT Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey now I'm understanding the underlying issue of my implementation. OpenMP has a runtime library that has to perform some checks before emitting certain instructions like taskwait. To continue the implementation I wanted to ask you If it would be a better idea to reimplement data structures like OMPTaskDataTy on ClangIR or to just include them. I would personally include those said structures, but I'm not sure at all. So my question is: Do i add the CGOpenMPRuntime.h to the clang/include dir, or do I rewrite the data structures from scratch inside ClangIR?

Also I wanted to point out that almost every PR's is bugged for some reason.
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To continue the implementation I wanted to ask you If it would be a better idea to reimplement data structures like OMPTaskDataTy on ClangIR or to just include them

Reimplement, CIR doesn't have access to lib/CodeGen. The idea is to add the minimal skeleton for OMPTaskDataTy you need for this PR, and for other data structures and pieces you might need for CGOpenMPRuntime.h. The idea is not to blindly copy it, but add the pieces incrementally in each PR, as the need appears.

Do i add the CGOpenMPRuntime.h to the clang/include dir, or do I rewrite the data structures from scratch inside ClangIR?

Rewrite them, we already do that a bunch, so you can look at the existing stuff for inspiration.

Also I wanted to point out that almost every PR's is bugged for some reason

This happens when we rebase the clangir repo against LLVM upstream. You need to rebase your local work against our repo and force push the PR to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been trying to rebase for a while, but I think I got thinks mixed up, is there any guide or documentation to understand your workflow approach? I've been trying to do the following, but I'm still getting the same message of thousands of commits behind and forward (Less than before). I think i'm missing something.

git rebase upstream/main
git push --force-with-lease

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally got to rebase the branch correctly, but now It seems that there is some duplicity on the commits. I'm trying to address this issue using git rebase -i and squashing the commits together but for some reason I can't do that without getting merge conflicts. Appart from that, could you @bcardosolopes review the last minor changes I've uploaded for OpenMPRuntime? I kept them to minimals except for buildDependences, which I thought that was convenient to use the original Clang one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, not sure what's going on - people do it all the time and it usually works, make sure you are rebasing against clangir's repo upstream, not LLVM's main repo upstream.

If you cannot make the rebase happen, feel free to start a new PR (after you apply the requested changes).

Appart from that, could you @bcardosolopes review the last minor changes I've uploaded for OpenMPRuntime?

I rather look into a clean PR instead.

@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp -fclangir-enable -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a subdir for these tests? CIR/CodeGen/OpenMP/barrier.cpp, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my original intention. On a second thought, moving and renaming the openmp.cpp file that @fabianmcg created for parallel, may cause version issues for him, so first I want to ask for permission. @fabianmcg what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fine, he can rebase and move it down to the subdir, this is normal github workflow :)

@@ -0,0 +1,14 @@
// RUN: cir-translate %s -cir-to-llvmir | FileCheck %s

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably good to add a OpenMP subdir here too.

Copy link

github-actions bot commented Mar 21, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@bcardosolopes
Copy link
Member

Gentle ping: any updates on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants