[Mlir-commits] [mlir] 6763f59 - [mlir][openacc] Use new reduction design in acc.loop

Valentin Clement llvmlistbot at llvm.org
Wed May 24 10:54:50 PDT 2023


Author: Valentin Clement
Date: 2023-05-24T10:51:39-07:00
New Revision: 6763f5918c926f5013cfac8b2472d77c06d48226

URL: https://github.com/llvm/llvm-project/commit/6763f5918c926f5013cfac8b2472d77c06d48226
DIFF: https://github.com/llvm/llvm-project/commit/6763f5918c926f5013cfac8b2472d77c06d48226.diff

LOG: [mlir][openacc] Use new reduction design in acc.loop

Use the new reduction design in acc.loop operation.

Depends on D151146

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D151164

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
    mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
    mlir/test/Dialect/OpenACC/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
index a662ad95a93e..097d01e9dd60 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -1046,8 +1046,8 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
                        Variadic<IntOrIndex>:$tileOperands,
                        Variadic<OpenACC_PointerLikeTypeInterface>:$privateOperands,
                        OptionalAttr<SymbolRefArrayAttr>:$privatizations,
-                       OptionalAttr<OpenACC_ReductionOperatorAttr>:$reductionOp,
-                       Variadic<AnyType>:$reductionOperands);
+                       Variadic<AnyType>:$reductionOperands,
+                       OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes);
 
   let results = (outs Variadic<AnyType>:$results);
 
@@ -1069,7 +1069,9 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
             $privateOperands, type($privateOperands), $privatizations)
         `)`
       | `tile` `(` $tileOperands `:` type($tileOperands) `)`
-      | `reduction` `(` $reductionOperands `:` type($reductionOperands) `)`
+      | `reduction` `(` custom<SymOperandList>(
+            $reductionOperands, type($reductionOperands), $reductionRecipes)
+        `)`
     )
     $region
     ( `(` type($results)^ `)` )?

diff  --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index e5d7888efb55..714bf26c6772 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -749,6 +749,11 @@ LogicalResult acc::LoopOp::verify() {
           "privatizations")))
     return failure();
 
+  if (failed(checkSymOperandList<mlir::acc::ReductionRecipeOp>(
+          *this, getReductionRecipes(), getReductionOperands(), "reduction",
+          "reductions")))
+    return failure();
+
   // Check non-empty body().
   if (getRegion().empty())
     return emitError("expected non-empty body.");

diff  --git a/mlir/test/Dialect/OpenACC/ops.mlir b/mlir/test/Dialect/OpenACC/ops.mlir
index fca5a5ffe1a2..17a6cbdfdc9e 100644
--- a/mlir/test/Dialect/OpenACC/ops.mlir
+++ b/mlir/test/Dialect/OpenACC/ops.mlir
@@ -1412,13 +1412,13 @@ acc.private.recipe @privatization_struct_i32_i64 : !llvm.struct<(i32, i32)> init
 // -----
 
 acc.reduction.recipe @reduction_add_i64 : i64 reduction_operator<add> init {
-^bb0(%0: i64):
-  %1 = arith.constant 0 : i64
-  acc.yield %1 : i64
+^bb0(%arg0: i64):
+  %0 = arith.constant 0 : i64
+  acc.yield %0 : i64
 } combiner {
-^bb0(%0: i64, %1: i64):
-  %2 = arith.addi %0, %1 : i64
-  acc.yield %2 : i64
+^bb0(%arg0: i64, %arg1: i64):
+  %0 = arith.addi %arg0, %arg1 : i64
+  acc.yield %0 : i64
 }
 
 // CHECK-LABEL: acc.reduction.recipe @reduction_add_i64 : i64 reduction_operator <add> init {
@@ -1433,6 +1433,10 @@ acc.reduction.recipe @reduction_add_i64 : i64 reduction_operator<add> init {
 
 func.func @acc_reduc_test(%a : i64) -> () {
   acc.parallel reduction(@reduction_add_i64 -> %a : i64) {
+    acc.loop reduction(@reduction_add_i64 -> %a : i64) {
+      acc.yield
+    }
+    acc.yield
   }
   return
 }
@@ -1440,6 +1444,7 @@ func.func @acc_reduc_test(%a : i64) -> () {
 // CHECK-LABEL: func.func @acc_reduc_test(
 // CHECK-SAME:    %[[ARG0:.*]]: i64)
 // CHECK:         acc.parallel reduction(@reduction_add_i64 -> %[[ARG0]] : i64)
+// CHECK:           acc.loop reduction(@reduction_add_i64 -> %[[ARG0]] : i64)
 
 // -----
 


        


More information about the Mlir-commits mailing list