Skip to content

Commit c0a1597

Browse files
[mlir][acc] Consistency between acc.loop and acc compute ops (#114549)
- GangPrivate and GangFirstPrivate renamed to just Private and Firstprivate respectively. This is makes compute ops consistent with the loop op (and also with the acc spec wording for the clause). - Added getBody to all compute ops - Verifier for firstprivate ops / recipes is enabled
1 parent c5a254c commit c0a1597

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,9 @@ def OpenACC_ParallelOp : OpenACC_Op<"parallel",
11141114
UnitAttr:$selfAttr,
11151115
Variadic<AnyType>:$reductionOperands,
11161116
OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes,
1117-
Variadic<OpenACC_PointerLikeTypeInterface>:$gangPrivateOperands,
1117+
Variadic<OpenACC_PointerLikeTypeInterface>:$privateOperands,
11181118
OptionalAttr<SymbolRefArrayAttr>:$privatizations,
1119-
Variadic<OpenACC_PointerLikeTypeInterface>:$gangFirstPrivateOperands,
1119+
Variadic<OpenACC_PointerLikeTypeInterface>:$firstprivateOperands,
11201120
OptionalAttr<SymbolRefArrayAttr>:$firstprivatizations,
11211121
Variadic<OpenACC_PointerLikeTypeInterface>:$dataClauseOperands,
11221122
OptionalAttr<DefaultValueAttr>:$defaultAttr,
@@ -1134,8 +1134,8 @@ def OpenACC_ParallelOp : OpenACC_Op<"parallel",
11341134
CArg<"mlir::Value", "{}">:$ifCond,
11351135
CArg<"mlir::Value", "{}">:$selfCond,
11361136
CArg<"mlir::ValueRange", "{}">:$reductionOperands,
1137-
CArg<"mlir::ValueRange", "{}">:$gangPrivateOperands,
1138-
CArg<"mlir::ValueRange", "{}">:$gangFirstPrivateOperands,
1137+
CArg<"mlir::ValueRange", "{}">:$privateOperands,
1138+
CArg<"mlir::ValueRange", "{}">:$firstprivateOperands,
11391139
CArg<"mlir::ValueRange", "{}">:$dataClauseOperands)>];
11401140

11411141
let extraClassDeclaration = [{
@@ -1145,6 +1145,9 @@ def OpenACC_ParallelOp : OpenACC_Op<"parallel",
11451145
/// The i-th data operand passed.
11461146
Value getDataOperand(unsigned i);
11471147

1148+
/// Used to retrieve the block inside the op's region.
1149+
Block &getBody() { return getRegion().front(); }
1150+
11481151
/// Return true if the op has the async attribute for the
11491152
/// mlir::acc::DeviceType::None device_type.
11501153
bool hasAsyncOnly();
@@ -1202,15 +1205,15 @@ def OpenACC_ParallelOp : OpenACC_Op<"parallel",
12021205
`dataOperands` `(` $dataClauseOperands `:` type($dataClauseOperands) `)`
12031206
| `async` `(` custom<DeviceTypeOperands>($asyncOperands,
12041207
type($asyncOperands), $asyncOperandsDeviceType) `)`
1205-
| `firstprivate` `(` custom<SymOperandList>($gangFirstPrivateOperands,
1206-
type($gangFirstPrivateOperands), $firstprivatizations)
1208+
| `firstprivate` `(` custom<SymOperandList>($firstprivateOperands,
1209+
type($firstprivateOperands), $firstprivatizations)
12071210
`)`
12081211
| `num_gangs` `(` custom<NumGangs>($numGangs,
12091212
type($numGangs), $numGangsDeviceType, $numGangsSegments) `)`
12101213
| `num_workers` `(` custom<DeviceTypeOperands>($numWorkers,
12111214
type($numWorkers), $numWorkersDeviceType) `)`
12121215
| `private` `(` custom<SymOperandList>(
1213-
$gangPrivateOperands, type($gangPrivateOperands), $privatizations)
1216+
$privateOperands, type($privateOperands), $privatizations)
12141217
`)`
12151218
| `vector_length` `(` custom<DeviceTypeOperands>($vectorLength,
12161219
type($vectorLength), $vectorLengthDeviceType) `)`
@@ -1271,9 +1274,9 @@ def OpenACC_SerialOp : OpenACC_Op<"serial",
12711274
UnitAttr:$selfAttr,
12721275
Variadic<AnyType>:$reductionOperands,
12731276
OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes,
1274-
Variadic<OpenACC_PointerLikeTypeInterface>:$gangPrivateOperands,
1277+
Variadic<OpenACC_PointerLikeTypeInterface>:$privateOperands,
12751278
OptionalAttr<SymbolRefArrayAttr>:$privatizations,
1276-
Variadic<OpenACC_PointerLikeTypeInterface>:$gangFirstPrivateOperands,
1279+
Variadic<OpenACC_PointerLikeTypeInterface>:$firstprivateOperands,
12771280
OptionalAttr<SymbolRefArrayAttr>:$firstprivatizations,
12781281
Variadic<OpenACC_PointerLikeTypeInterface>:$dataClauseOperands,
12791282
OptionalAttr<DefaultValueAttr>:$defaultAttr,
@@ -1288,6 +1291,9 @@ def OpenACC_SerialOp : OpenACC_Op<"serial",
12881291
/// The i-th data operand passed.
12891292
Value getDataOperand(unsigned i);
12901293

1294+
/// Used to retrieve the block inside the op's region.
1295+
Block &getBody() { return getRegion().front(); }
1296+
12911297
/// Return true if the op has the async attribute for the
12921298
/// mlir::acc::DeviceType::None device_type.
12931299
bool hasAsyncOnly();
@@ -1326,11 +1332,11 @@ def OpenACC_SerialOp : OpenACC_Op<"serial",
13261332
`dataOperands` `(` $dataClauseOperands `:` type($dataClauseOperands) `)`
13271333
| `async` `(` custom<DeviceTypeOperands>($asyncOperands,
13281334
type($asyncOperands), $asyncOperandsDeviceType) `)`
1329-
| `firstprivate` `(` custom<SymOperandList>($gangFirstPrivateOperands,
1330-
type($gangFirstPrivateOperands), $firstprivatizations)
1335+
| `firstprivate` `(` custom<SymOperandList>($firstprivateOperands,
1336+
type($firstprivateOperands), $firstprivatizations)
13311337
`)`
13321338
| `private` `(` custom<SymOperandList>(
1333-
$gangPrivateOperands, type($gangPrivateOperands), $privatizations)
1339+
$privateOperands, type($privateOperands), $privatizations)
13341340
`)`
13351341
| `wait` `` custom<WaitClause>($waitOperands, type($waitOperands),
13361342
$waitOperandsDeviceType, $waitOperandsSegments, $hasWaitDevnum,
@@ -1410,6 +1416,9 @@ def OpenACC_KernelsOp : OpenACC_Op<"kernels",
14101416
/// The i-th data operand passed.
14111417
Value getDataOperand(unsigned i);
14121418

1419+
/// Used to retrieve the block inside the op's region.
1420+
Block &getBody() { return getRegion().front(); }
1421+
14131422
/// Return true if the op has the async attribute for the
14141423
/// mlir::acc::DeviceType::None device_type.
14151424
bool hasAsyncOnly();
@@ -1824,6 +1833,7 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
18241833
/// The i-th data operand passed.
18251834
Value getDataOperand(unsigned i);
18261835

1836+
/// Used to retrieve the block inside the op's region.
18271837
Block &getBody() { return getLoopRegions().front()->front(); }
18281838

18291839
/// Return true if the op has the auto attribute for the

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,8 @@ checkSymOperandList(Operation *op, std::optional<mlir::ArrayAttr> attributes,
730730
}
731731

732732
unsigned ParallelOp::getNumDataOperands() {
733-
return getReductionOperands().size() + getGangPrivateOperands().size() +
734-
getGangFirstPrivateOperands().size() + getDataClauseOperands().size();
733+
return getReductionOperands().size() + getPrivateOperands().size() +
734+
getFirstprivateOperands().size() + getDataClauseOperands().size();
735735
}
736736

737737
Value ParallelOp::getDataOperand(unsigned i) {
@@ -783,9 +783,13 @@ static LogicalResult verifyDeviceTypeAndSegmentCountMatch(
783783

784784
LogicalResult acc::ParallelOp::verify() {
785785
if (failed(checkSymOperandList<mlir::acc::PrivateRecipeOp>(
786-
*this, getPrivatizations(), getGangPrivateOperands(), "private",
786+
*this, getPrivatizations(), getPrivateOperands(), "private",
787787
"privatizations", /*checkOperandType=*/false)))
788788
return failure();
789+
if (failed(checkSymOperandList<mlir::acc::FirstprivateRecipeOp>(
790+
*this, getFirstprivatizations(), getFirstprivateOperands(),
791+
"firstprivate", "firstprivatizations", /*checkOperandType=*/false)))
792+
return failure();
789793
if (failed(checkSymOperandList<mlir::acc::ReductionRecipeOp>(
790794
*this, getReductionRecipes(), getReductionOperands(), "reduction",
791795
"reductions", false)))
@@ -1361,8 +1365,8 @@ printCombinedConstructsLoop(mlir::OpAsmPrinter &p, mlir::Operation *op,
13611365
//===----------------------------------------------------------------------===//
13621366

13631367
unsigned SerialOp::getNumDataOperands() {
1364-
return getReductionOperands().size() + getGangPrivateOperands().size() +
1365-
getGangFirstPrivateOperands().size() + getDataClauseOperands().size();
1368+
return getReductionOperands().size() + getPrivateOperands().size() +
1369+
getFirstprivateOperands().size() + getDataClauseOperands().size();
13661370
}
13671371

13681372
Value SerialOp::getDataOperand(unsigned i) {
@@ -1420,9 +1424,13 @@ mlir::Value SerialOp::getWaitDevnum(mlir::acc::DeviceType deviceType) {
14201424

14211425
LogicalResult acc::SerialOp::verify() {
14221426
if (failed(checkSymOperandList<mlir::acc::PrivateRecipeOp>(
1423-
*this, getPrivatizations(), getGangPrivateOperands(), "private",
1427+
*this, getPrivatizations(), getPrivateOperands(), "private",
14241428
"privatizations", /*checkOperandType=*/false)))
14251429
return failure();
1430+
if (failed(checkSymOperandList<mlir::acc::FirstprivateRecipeOp>(
1431+
*this, getFirstprivatizations(), getFirstprivateOperands(),
1432+
"firstprivate", "firstprivatizations", /*checkOperandType=*/false)))
1433+
return failure();
14261434
if (failed(checkSymOperandList<mlir::acc::ReductionRecipeOp>(
14271435
*this, getReductionRecipes(), getReductionOperands(), "reduction",
14281436
"reductions", false)))

mlir/lib/Dialect/OpenACC/Transforms/LegalizeDataValues.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ static void collectAndReplaceInRegion(Op &op, bool hostToDevice) {
8383
!std::is_same_v<Op, acc::DataOp> &&
8484
!std::is_same_v<Op, acc::DeclareOp>) {
8585
collectPtrs(op.getReductionOperands(), values, hostToDevice);
86-
collectPtrs(op.getGangPrivateOperands(), values, hostToDevice);
87-
collectPtrs(op.getGangFirstPrivateOperands(), values, hostToDevice);
86+
collectPtrs(op.getPrivateOperands(), values, hostToDevice);
87+
collectPtrs(op.getFirstprivateOperands(), values, hostToDevice);
8888
}
8989
}
9090

0 commit comments

Comments
 (0)