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

Adding masked operation to OpenMP Dialect #96022

Merged
merged 5 commits into from
Jul 4, 2024
Merged

Conversation

anchuraj
Copy link
Contributor

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.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 19, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-flang-openmp

Author: Anchu Rajendran S (anchuraj)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/96022.diff

2 Files Affected:

  • (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+21)
  • (modified) mlir/test/Dialect/OpenMP/ops.mlir (+15)
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

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 19, 2024

@llvm/pr-subscribers-mlir-openmp

Author: Anchu Rajendran S (anchuraj)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/96022.diff

2 Files Affected:

  • (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+21)
  • (modified) mlir/test/Dialect/OpenMP/ops.mlir (+15)
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

@kiranchandramohan
Copy link
Contributor

@skatrak is in the process of moving to clause-based representation for OpenMP operations. So this will have to be done differently with filter and the region information coming in as template arguments or traits. Please sync with him.

#92519
#92523

@anchuraj anchuraj changed the title Adding masked operations to OpenMP Dialect Adding masked operation to OpenMP Dialect Jun 20, 2024
@anchuraj anchuraj force-pushed the ompMaskedMLIR branch 2 times, most recently from e583690 to 7435881 Compare June 20, 2024 05:42
@anchuraj
Copy link
Contributor Author

@skatrak is in the process of moving to clause-based representation for OpenMP operations. So this will have to be done differently with filter and the region information coming in as template arguments or traits. Please sync with him.

#92519 #92523

Sure. Thank you!

Copy link
Contributor

@skatrak skatrak left a 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.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td Outdated Show resolved Hide resolved
@skatrak
Copy link
Contributor

skatrak commented Jun 26, 2024

@skatrak is in the process of moving to clause-based representation for OpenMP operations. So this will have to be done differently with filter and the region information coming in as template arguments or traits. Please sync with him.
#92519 #92523

Sure. Thank you!

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.

@anchuraj
Copy link
Contributor Author

anchuraj commented Jul 2, 2024

@skatrak is in the process of moving to clause-based representation for OpenMP operations. So this will have to be done differently with filter and the region information coming in as template arguments or traits. Please sync with him.
#92519 #92523

Sure. Thank you!

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.

@anchuraj anchuraj requested a review from mjklemm July 2, 2024 21:09
Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@skatrak skatrak left a 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.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td Outdated Show resolved Hide resolved
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td Show resolved Hide resolved
@anchuraj anchuraj requested a review from skatrak July 4, 2024 14:58
Copy link

github-actions bot commented Jul 4, 2024

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

Copy link
Contributor

@skatrak skatrak left a 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.

@anchuraj anchuraj merged commit 7a9ef0f into llvm:main Jul 4, 2024
7 checks passed
@anchuraj anchuraj deleted the ompMaskedMLIR branch July 4, 2024 23:06
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 4, 2024

LLVM Buildbot has detected a new failure on builder mlir-nvidia-gcc7 running on mlir-nvidia while building mlir at step 5 "build-check-mlir-build-only".

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:

Step 5 (build-check-mlir-build-only) failure: build (failure)
...
53.640 [68/16/4394] Building CXX object tools/mlir/examples/minimal-opt/CMakeFiles/mlir-minimal-opt.dir/mlir-minimal-opt.cpp.o
53.828 [67/16/4395] Linking CXX executable bin/mlir-minimal-opt
53.862 [66/16/4396] Building CXX object tools/mlir/examples/transform/Ch4/lib/CMakeFiles/MyExtensionCh4.dir/MyExtension.cpp.o
/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/examples/transform/Ch4/lib/MyExtension.cpp: In instantiation of ‘bool implementSameInterface(mlir::Type, mlir::Type) [with Tys = {mlir::transform::TransformHandleTypeInterface, mlir::transform::TransformParamTypeInterface, mlir::transform::TransformValueHandleTypeInterface}]’:
/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/examples/transform/Ch4/lib/MyExtension.cpp:72:65:   required from here
/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/examples/transform/Ch4/lib/MyExtension.cpp:63:31: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
   return ((llvm::isa<Tys>(t1) && llvm::isa<Tys>(t2)) || ... || false);
           ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/examples/transform/Ch4/lib/MyExtension.cpp:63:31: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/examples/transform/Ch4/lib/MyExtension.cpp:63:31: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
command timed out: 1200 seconds without output running [b'ninja', b'-j', b'16', b'check-mlir-build-only'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1709.642227

kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants