-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[openacc][openmp] Add dialect representation for acc atomic operations #65493
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
Conversation
The OpenACC standard specifies an `atomic` construct in section 2.12 (of 3.3 spec), used to ensure that a specific location is accessed or updated atomically. Four different clauses are allowed: `read`, `write`, `update`, or `capture`. If no clause appears, it is as if `update` is used. The OpenMP specification defines the same clauses for `omp atomic`. The types of expression and the clauses in the OpenACC spec match the OpenMP spec exactly. The main difference is that the OpenMP specification is a superset - it includes clauses for `hint` and `memory order`. It also allows conditional expression statements. But otherwise, the expression definition matches. Thus, for OpenACC, we refactor and reuse the OpenMP implementation as follows: * The atomic operations are duplicated in OpenACC dialect. This is preferable so that each language's semantics are precisely represented even if specs have divergence. * However, since semantics overlap, a common interface between the atomic operations is being added. The semantics for the interfaces are not generic enough to be used outside of OpenACC and OpenMP, and thus new folders were added to hold common pieces of the two dialects. * The atomic interfaces define common accessors (such as getting `x` or `v`) which match the OpenMP and OpenACC specs. It also adds common verifiers intended to be called by each dialect's operation verifier. * The OpenMP write operation was updated to use `x` and `expr` to be consistent with its other operations (that use naming based on spec). The frontend lowering necessary to generate the dialect can also be reused. This will be done in a follow up change. Differential Revision: https://reviews.llvm.org/D158768
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you for the changes! I have just minor remarks.
mlir/include/mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.td
Outdated
Show resolved
Hide resolved
mlir/include/mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.td
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok for me.
* Add RecursiveMemoryEffects to both acc and omp atomic caputre * Add newlines to the CMakeLists.txt files * Fix descriptions in atomic interfaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Thank you for working on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Changes have not been tested since I do not have a bazel build.
@aartbik Since I added new interfaces, several cmake files had to be updated. I attempted to do the same for the bazel build but did not test it. Would you mind looking through the changes? Thank you! |
It is very kind of you to include the bazel builds too (especially since this is not a requirement for submitting to MLIR), since it helps people integrating changes into bazel-based repos enormously. The changes look good to me (although indeed actually testing them will reveal any lingering issue) and will help integrators a lot! |
llvm#65493) The OpenACC standard specifies an `atomic` construct in section 2.12 (of 3.3 spec), used to ensure that a specific location is accessed or updated atomically. Four different clauses are allowed: `read`, `write`, `update`, or `capture`. If no clause appears, it is as if `update` is used. The OpenMP specification defines the same clauses for `omp atomic`. The types of expression and the clauses in the OpenACC spec match the OpenMP spec exactly. The main difference is that the OpenMP specification is a superset - it includes clauses for `hint` and `memory order`. It also allows conditional expression statements. But otherwise, the expression definition matches. Thus, for OpenACC, we refactor and reuse the OpenMP implementation as follows: * The atomic operations are duplicated in OpenACC dialect. This is preferable so that each language's semantics are precisely represented even if specs have divergence. * However, since semantics overlap, a common interface between the atomic operations is being added. The semantics for the interfaces are not generic enough to be used outside of OpenACC and OpenMP, and thus new folders were added to hold common pieces of the two dialects. * The atomic interfaces define common accessors (such as getting `x` or `v`) which match the OpenMP and OpenACC specs. It also adds common verifiers intended to be called by each dialect's operation verifier. * The OpenMP write operation was updated to use `x` and `expr` to be consistent with its other operations (that use naming based on spec). The frontend lowering necessary to generate the dialect can also be reused. This will be done in a follow up change.
Hey, I've just seen this PR, I understand the need for a common atomic interface between these two models. I am little concerned about the Would make sense to delete the |
Hi Guray! :) I agree with your point about it not seeming right being in the dialect folder but with no dialect definition. I did in fact struggle to find the right home for this interface. A couple of factors drove the decision to place it in its current location:
So, its current home seemed like an reasonable location. |
Hey Razvan - long time no chat :) It's great that you are improving the atomic support, nice progress! I trust your judgment that the interface being OpenMP/OpenACC specific. In that case, would it be a good idea creating I also gave a thought of placing the interface in either the OpenMP or OpenACC folder. But I completely agree with you that it might not be the best approach. |
Agreed! There will definitely be more interfaces! I also imagine not just operation interfaces - but type interfaces too.
Your suggestion makes sense! My main hesitation is just that it feels eventually we may share more than just interfaces. For example, utilities and ops. I don't want to move things around often - and the current home seems it can be a good home even for future expansion. |
The OpenACC standard specifies an
atomic
construct in section 2.12 (of 3.3 spec), used to ensure that a specific location is accessed or updated atomically. Four different clauses are allowed:read
,write
,update
, orcapture
. If no clause appears, it is as ifupdate
is used.The OpenMP specification defines the same clauses for
omp atomic
. The types of expression and the clauses in the OpenACC spec match the OpenMP spec exactly. The main difference is that the OpenMP specification is a superset - it includes clauses forhint
andmemory order
. It also allows conditional expression statements. But otherwise, the expression definition matches.Thus, for OpenACC, we refactor and reuse the OpenMP implementation as follows:
x
orv
) which match the OpenMP and OpenACC specs. It also adds common verifiers intended to be called by each dialect's operation verifier.x
andexpr
to be consistent with its other operations (that use naming based on spec).The frontend lowering necessary to generate the dialect can also be reused. This will be done in a follow up change.
Differential Revision: https://reviews.llvm.org/D158768