-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Adding masked operation to OpenMP Dialect #96022
Conversation
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-flang-openmp Author: Anchu Rajendran S (anchuraj) ChangesAdding MLIR Op support for omp masked. Omp masked is introduced in 5.2 standard and allows a parallel region to be executed by threads specified by a programmer. This is achieved with the help of filter clause which helps to specify thread id expected to execute the region. Full diff: https://github.com/llvm/llvm-project/pull/96022.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 122abbe7cc975..08a89e18510a7 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -2179,4 +2179,25 @@ def ReductionOp : OpenMP_Op<"reduction"> {
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// [Spec 5.2] 10.5 masked Construct
+//===----------------------------------------------------------------------===//
+def MaskedOp : OpenMP_Op<"masked"> {
+ let summary = "masked construct";
+ let description = [{
+ Masked construct allows to specify a structured block to be executed by a subset of
+ threads of the current team. Filter clause allows to select the threads expected to
+ execute the region
+ }];
+
+ let arguments = (ins Optional<I32>:$filteredThreadId);
+ let regions = (region AnyRegion:$region);
+
+ let assemblyFormat = [{
+ oilist(
+ `filter` `(` $filteredThreadId `:` type($filteredThreadId) `)`
+ ) $region attr-dict
+ }];
+}
+
#endif // OPENMP_OPS
diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir
index 0d5fd9383a92f..fe24b6484f292 100644
--- a/mlir/test/Dialect/OpenMP/ops.mlir
+++ b/mlir/test/Dialect/OpenMP/ops.mlir
@@ -16,6 +16,21 @@ func.func @omp_master() -> () {
return
}
+// CHECK-LABEL: omp_masked
+func.func @omp_masked(%filtered_thread_id : i32) -> () {
+
+
+ // CHECK: omp.masked filter(%{{.*}} : i32)
+ "omp.masked" (%filtered_thread_id) ({
+ omp.terminator
+ }) : (i32) -> ()
+
+ // CHECK: omp.masked
+ "omp.masked" () ({
+ omp.terminator
+ }) : () -> ()
+ return
+}
func.func @omp_taskwait() -> () {
// CHECK: omp.taskwait
omp.taskwait
|
@llvm/pr-subscribers-mlir-openmp Author: Anchu Rajendran S (anchuraj) ChangesAdding MLIR Op support for omp masked. Omp masked is introduced in 5.2 standard and allows a parallel region to be executed by threads specified by a programmer. This is achieved with the help of filter clause which helps to specify thread id expected to execute the region. Full diff: https://github.com/llvm/llvm-project/pull/96022.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 122abbe7cc975..08a89e18510a7 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -2179,4 +2179,25 @@ def ReductionOp : OpenMP_Op<"reduction"> {
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// [Spec 5.2] 10.5 masked Construct
+//===----------------------------------------------------------------------===//
+def MaskedOp : OpenMP_Op<"masked"> {
+ let summary = "masked construct";
+ let description = [{
+ Masked construct allows to specify a structured block to be executed by a subset of
+ threads of the current team. Filter clause allows to select the threads expected to
+ execute the region
+ }];
+
+ let arguments = (ins Optional<I32>:$filteredThreadId);
+ let regions = (region AnyRegion:$region);
+
+ let assemblyFormat = [{
+ oilist(
+ `filter` `(` $filteredThreadId `:` type($filteredThreadId) `)`
+ ) $region attr-dict
+ }];
+}
+
#endif // OPENMP_OPS
diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir
index 0d5fd9383a92f..fe24b6484f292 100644
--- a/mlir/test/Dialect/OpenMP/ops.mlir
+++ b/mlir/test/Dialect/OpenMP/ops.mlir
@@ -16,6 +16,21 @@ func.func @omp_master() -> () {
return
}
+// CHECK-LABEL: omp_masked
+func.func @omp_masked(%filtered_thread_id : i32) -> () {
+
+
+ // CHECK: omp.masked filter(%{{.*}} : i32)
+ "omp.masked" (%filtered_thread_id) ({
+ omp.terminator
+ }) : (i32) -> ()
+
+ // CHECK: omp.masked
+ "omp.masked" () ({
+ omp.terminator
+ }) : () -> ()
+ return
+}
func.func @omp_taskwait() -> () {
// CHECK: omp.taskwait
omp.taskwait
|
e583690
to
7435881
Compare
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.
Thank you Anchu, this LGTM. I have added a small comment and also it would be good to add a couple of tests to invalid.mlir (located in the same directory as ops.mlir). Perhaps one test trying to pass a non-int value and one trying to pass multiple values to omp.masked
.
It will be relatively simple to do, but it's likely your PR will land first and I'll deal with that change. If not, I'll let you know and help out. |
Thank you @skatrak for guiding me offline. I have updated the PR consistent with your changes. |
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.
LGTM
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.
Thank you for working on my comments, it's looking good! There's just one piece missing, but otherwise this is almost ready to go.
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
Thank you for working on my feedback, LGTM! Just make sure to address formatting issues before merging.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/116/builds/889 Here is the relevant piece of the build log for the reference:
|
Adding MLIR Op support for omp masked. Omp masked is introduced in 5.2 standard and allows a region to be executed by threads specified by a programmer. This is achieved with the help of filter clause which helps to specify thread id expected to execute the region.
Adding MLIR Op support for omp masked. Omp masked is introduced in 5.2 standard and allows a parallel region to be executed by threads specified by a programmer. This is achieved with the help of filter clause which helps to specify thread id expected to execute the region.