Skip to content

Commit 6763f59

Browse files
committed
[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
1 parent 4305f64 commit 6763f59

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,8 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
10461046
Variadic<IntOrIndex>:$tileOperands,
10471047
Variadic<OpenACC_PointerLikeTypeInterface>:$privateOperands,
10481048
OptionalAttr<SymbolRefArrayAttr>:$privatizations,
1049-
OptionalAttr<OpenACC_ReductionOperatorAttr>:$reductionOp,
1050-
Variadic<AnyType>:$reductionOperands);
1049+
Variadic<AnyType>:$reductionOperands,
1050+
OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes);
10511051

10521052
let results = (outs Variadic<AnyType>:$results);
10531053

@@ -1069,7 +1069,9 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
10691069
$privateOperands, type($privateOperands), $privatizations)
10701070
`)`
10711071
| `tile` `(` $tileOperands `:` type($tileOperands) `)`
1072-
| `reduction` `(` $reductionOperands `:` type($reductionOperands) `)`
1072+
| `reduction` `(` custom<SymOperandList>(
1073+
$reductionOperands, type($reductionOperands), $reductionRecipes)
1074+
`)`
10731075
)
10741076
$region
10751077
( `(` type($results)^ `)` )?

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,11 @@ LogicalResult acc::LoopOp::verify() {
749749
"privatizations")))
750750
return failure();
751751

752+
if (failed(checkSymOperandList<mlir::acc::ReductionRecipeOp>(
753+
*this, getReductionRecipes(), getReductionOperands(), "reduction",
754+
"reductions")))
755+
return failure();
756+
752757
// Check non-empty body().
753758
if (getRegion().empty())
754759
return emitError("expected non-empty body.");

mlir/test/Dialect/OpenACC/ops.mlir

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,13 +1412,13 @@ acc.private.recipe @privatization_struct_i32_i64 : !llvm.struct<(i32, i32)> init
14121412
// -----
14131413

14141414
acc.reduction.recipe @reduction_add_i64 : i64 reduction_operator<add> init {
1415-
^bb0(%0: i64):
1416-
%1 = arith.constant 0 : i64
1417-
acc.yield %1 : i64
1415+
^bb0(%arg0: i64):
1416+
%0 = arith.constant 0 : i64
1417+
acc.yield %0 : i64
14181418
} combiner {
1419-
^bb0(%0: i64, %1: i64):
1420-
%2 = arith.addi %0, %1 : i64
1421-
acc.yield %2 : i64
1419+
^bb0(%arg0: i64, %arg1: i64):
1420+
%0 = arith.addi %arg0, %arg1 : i64
1421+
acc.yield %0 : i64
14221422
}
14231423

14241424
// CHECK-LABEL: acc.reduction.recipe @reduction_add_i64 : i64 reduction_operator <add> init {
@@ -1433,13 +1433,18 @@ acc.reduction.recipe @reduction_add_i64 : i64 reduction_operator<add> init {
14331433

14341434
func.func @acc_reduc_test(%a : i64) -> () {
14351435
acc.parallel reduction(@reduction_add_i64 -> %a : i64) {
1436+
acc.loop reduction(@reduction_add_i64 -> %a : i64) {
1437+
acc.yield
1438+
}
1439+
acc.yield
14361440
}
14371441
return
14381442
}
14391443

14401444
// CHECK-LABEL: func.func @acc_reduc_test(
14411445
// CHECK-SAME: %[[ARG0:.*]]: i64)
14421446
// CHECK: acc.parallel reduction(@reduction_add_i64 -> %[[ARG0]] : i64)
1447+
// CHECK: acc.loop reduction(@reduction_add_i64 -> %[[ARG0]] : i64)
14431448

14441449
// -----
14451450

0 commit comments

Comments
 (0)