Skip to content

[MLIR][OpenMP] NFC: Update parallel workshare loop reduction tests #105835

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

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

skatrak
Copy link
Member

@skatrak skatrak commented Aug 23, 2024

This patch updates MLIR tests for omp.parallel + omp.wsloop reductions to move the reduction clause into omp.wsloop rather than the parent omp.parallel, as mandated by the spec for these cases and also to match what Flang is already producing for parallel do reduction(...) combined constructs.

From the OpenMP Spec version 5.2, section 17.2:

The effect of the reduction clause is as if it is applied to all leaf constructs that permit the clause, except for the following constructs:

  • The parallel construct, when combined with the sections, worksharing-loop, loop, or taskloop construct; [...]

This patch updates MLIR tests for `omp.parallel` + `omp.wsloop` reductions to
move the reduction clause into `omp.wsloop` rather than the parent
`omp.parallel`, as mandated by the spec for these cases and also to match what
Flang is already producing for `parallel do reduction(...)` combined
constructs.

From the OpenMP Spec version 5.2, section 17.2:

> The effect of the reduction clause is as if it is applied to all leaf constructs that permit the clause, except for the following constructs:
>   - The `parallel` construct, when combined with the `sections`, worksharing-loop, `loop`, or `taskloop` construct; [...]
@llvmbot
Copy link
Member

llvmbot commented Aug 23, 2024

@llvm/pr-subscribers-mlir-llvm
@llvm/pr-subscribers-mlir-openmp
@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-mlir

Author: Sergio Afonso (skatrak)

Changes

This patch updates MLIR tests for omp.parallel + omp.wsloop reductions to move the reduction clause into omp.wsloop rather than the parent omp.parallel, as mandated by the spec for these cases and also to match what Flang is already producing for parallel do reduction(...) combined constructs.

From the OpenMP Spec version 5.2, section 17.2:

> The effect of the reduction clause is as if it is applied to all leaf constructs that permit the clause, except for the following constructs:
> - The parallel construct, when combined with the sections, worksharing-loop, loop, or taskloop construct; [...]


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

2 Files Affected:

  • (modified) mlir/test/Dialect/OpenMP/ops.mlir (+8-8)
  • (modified) mlir/test/Target/LLVMIR/openmp-reduction.mlir (+2-2)
diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir
index 9c308cc0108493..7ba55fc957a473 100644
--- a/mlir/test/Dialect/OpenMP/ops.mlir
+++ b/mlir/test/Dialect/OpenMP/ops.mlir
@@ -1019,10 +1019,10 @@ func.func @parallel_reduction_byref() {
 func.func @parallel_wsloop_reduction(%lb : index, %ub : index, %step : index) {
   %c1 = arith.constant 1 : i32
   %0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr
-  // CHECK: omp.parallel reduction(@add_f32 %{{.*}} -> %{{.+}} : !llvm.ptr) {
-  omp.parallel reduction(@add_f32 %0 -> %prv : !llvm.ptr) {
-    // CHECK: omp.wsloop {
-    omp.wsloop {
+  // CHECK: omp.parallel {
+  omp.parallel {
+    // CHECK: omp.wsloop reduction(@add_f32 %{{.*}} -> %{{.+}} : !llvm.ptr) {
+    omp.wsloop reduction(@add_f32 %0 -> %prv : !llvm.ptr) {
       // CHECK: omp.loop_nest (%{{.+}}) : index = (%{{.+}}) to (%{{.+}}) step (%{{.+}}) {
       omp.loop_nest (%iv) : index = (%lb) to (%ub) step (%step) {
         %1 = arith.constant 2.0 : f32
@@ -1216,10 +1216,10 @@ func.func @parallel_reduction2() {
 func.func @parallel_wsloop_reduction2(%lb : index, %ub : index, %step : index) {
   %c1 = arith.constant 1 : i32
   %0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr
-  // CHECK: omp.parallel reduction(@add2_f32 %{{.*}} -> %{{.+}} : !llvm.ptr) {
-  omp.parallel reduction(@add2_f32 %0 -> %prv : !llvm.ptr) {
-    // CHECK: omp.wsloop {
-    omp.wsloop {
+  // CHECK: omp.parallel {
+  omp.parallel {
+    // CHECK: omp.wsloop reduction(@add2_f32 %{{.*}} -> %{{.+}} : !llvm.ptr) {
+    omp.wsloop reduction(@add2_f32 %0 -> %prv : !llvm.ptr) {
       // CHECK: omp.loop_nest (%{{.+}}) : index = (%{{.+}}) to (%{{.+}}) step (%{{.+}}) {
       omp.loop_nest (%iv) : index = (%lb) to (%ub) step (%step) {
         %1 = arith.constant 2.0 : f32
diff --git a/mlir/test/Target/LLVMIR/openmp-reduction.mlir b/mlir/test/Target/LLVMIR/openmp-reduction.mlir
index bfdad8c19335e1..1d4b4915bcc399 100644
--- a/mlir/test/Target/LLVMIR/openmp-reduction.mlir
+++ b/mlir/test/Target/LLVMIR/openmp-reduction.mlir
@@ -540,8 +540,8 @@ llvm.func @parallel_nested_workshare_reduction(%ub : i64) {
   %lb = llvm.mlir.constant(1 : i64) : i64
   %step = llvm.mlir.constant(1 : i64) : i64
   
-  omp.parallel reduction(@add_i32 %0 -> %prv : !llvm.ptr) {
-    omp.wsloop {
+  omp.parallel {
+    omp.wsloop reduction(@add_i32 %0 -> %prv : !llvm.ptr) {
       omp.loop_nest (%iv) : i64 = (%lb) to (%ub) step (%step) {
         %ival = llvm.trunc %iv : i64 to i32
         %lprv = llvm.load %prv : !llvm.ptr -> i32

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

@tblah tblah left a comment

Choose a reason for hiding this comment

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

Thanks!

@skatrak skatrak merged commit 6f62757 into llvm:main Aug 27, 2024
13 checks passed
@skatrak skatrak deleted the wsloop-reduction-tests branch August 27, 2024 11:57
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.

4 participants