Skip to content

Commit 4847bd5

Browse files
[mlir][acc] Add support for data clause modifiers (#144806)
The OpenACC data clause operations have been updated to support the OpenACC 3.4 data clause modifiers. This includes ensuring verifiers check that only supported ones are used on relevant operations. In order to support a seamless update from encoding the modifiers in the data clause to this attribute, the following considerations were made: - Ensure that modifier builders which do not take modifier are still available. - All data clause enum values are left in place until a complete transition is made to the new modifiers.
1 parent 2767ff4 commit 4847bd5

File tree

4 files changed

+197
-15
lines changed

4 files changed

+197
-15
lines changed

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

Lines changed: 92 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,41 @@ def OpenACC_DataClauseEnum : I64EnumAttr<"DataClause",
199199
def OpenACC_DataClauseAttr : EnumAttr<OpenACC_Dialect, OpenACC_DataClauseEnum,
200200
"data_clause">;
201201

202+
// Data clause modifiers:
203+
// * readonly: Added in OpenACC 2.7 to copyin and cache.
204+
// * zero: Added in OpenACC 3.0 for create and copyout.
205+
// * always, alwaysin, alwaysout: Added in OpenACC 3.4 for
206+
// copy, copyin, and copyout clauses.
207+
// * capture: Added in OpenACC 3.4 for copy, copyin, copyout and create clauses.
208+
def OpenACC_DataClauseModifierNone : I32BitEnumAttrCaseNone<"none">;
209+
// All of the modifiers below are bit flags - so the value noted is `1 << bit`.
210+
// Thus the `zero` modifier is `1 << 0` = 1, `readonly` is `1 << 1` = 2, etc.
211+
def OpenACC_DataClauseModifierZero : I32BitEnumAttrCaseBit<"zero", 0>;
212+
def OpenACC_DataClauseModifierReadonly : I32BitEnumAttrCaseBit<"readonly", 1>;
213+
def OpenACC_DataClauseModifierAlwaysIn : I32BitEnumAttrCaseBit<"alwaysin", 2>;
214+
def OpenACC_DataClauseModifierAlwaysOut : I32BitEnumAttrCaseBit<"alwaysout", 3>;
215+
def OpenACC_DataClauseModifierAlways : I32BitEnumAttrCaseGroup<"always",
216+
[OpenACC_DataClauseModifierAlwaysIn, OpenACC_DataClauseModifierAlwaysOut]>;
217+
def OpenACC_DataClauseModifierCapture : I32BitEnumAttrCaseBit<"capture", 4>;
218+
219+
def OpenACC_DataClauseModifierEnum : I32BitEnumAttr<
220+
"DataClauseModifier",
221+
"Captures data clause modifiers",
222+
[
223+
OpenACC_DataClauseModifierNone, OpenACC_DataClauseModifierZero,
224+
OpenACC_DataClauseModifierReadonly, OpenACC_DataClauseModifierAlwaysIn,
225+
OpenACC_DataClauseModifierAlwaysOut, OpenACC_DataClauseModifierAlways,
226+
OpenACC_DataClauseModifierCapture]> {
227+
let separator = ",";
228+
let cppNamespace = "::mlir::acc";
229+
let genSpecializedAttr = 0;
230+
let printBitEnumPrimaryGroups = 1;
231+
}
232+
233+
def OpenACC_DataClauseModifierAttr : EnumAttr<OpenACC_Dialect,
234+
OpenACC_DataClauseModifierEnum,
235+
"data_clause_modifier">;
236+
202237
class OpenACC_Attr<string name, string attrMnemonic,
203238
list<Trait> traits = [],
204239
string baseCppClass = "::mlir::Attribute">
@@ -477,6 +512,8 @@ class OpenACC_DataEntryOp<string mnemonic, string clause, string extraDescriptio
477512
DefaultValuedAttr<OpenACC_DataClauseAttr, clause>:$dataClause,
478513
DefaultValuedAttr<BoolAttr, "true">:$structured,
479514
DefaultValuedAttr<BoolAttr, "false">:$implicit,
515+
DefaultValuedAttr<OpenACC_DataClauseModifierAttr,
516+
"mlir::acc::DataClauseModifier::none">:$modifiers,
480517
OptionalAttr<StrAttr>:$name));
481518

482519
let description = !strconcat(extraDescription, [{
@@ -506,6 +543,7 @@ class OpenACC_DataEntryOp<string mnemonic, string clause, string extraDescriptio
506543
counters (2.6.7).
507544
- `implicit`: Whether this is an implicitly generated operation, such as copies
508545
done to satisfy "Variables with Implicitly Determined Data Attributes" in 2.6.2.
546+
- `modifiers`: Keeps track of the data clause modifiers (eg zero, readonly, etc)
509547
- `name`: Holds the name of variable as specified in user clause (including bounds).
510548

511549
The async values attached to the data entry operation imply that the data
@@ -584,7 +622,8 @@ class OpenACC_DataEntryOp<string mnemonic, string clause, string extraDescriptio
584622
/*asyncOperandsDeviceType=*/nullptr,
585623
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
586624
/*structured=*/$_builder.getBoolAttr(structured),
587-
/*implicit=*/$_builder.getBoolAttr(implicit), /*name=*/nullptr);
625+
/*implicit=*/$_builder.getBoolAttr(implicit), /*modifiers=*/nullptr,
626+
/*name=*/nullptr);
588627
}]>,
589628
OpBuilder<(ins "::mlir::Value":$var,
590629
"bool":$structured, "bool":$implicit,
@@ -601,9 +640,23 @@ class OpenACC_DataEntryOp<string mnemonic, string clause, string extraDescriptio
601640
/*asyncOperandsDeviceType=*/nullptr,
602641
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
603642
/*structured=*/$_builder.getBoolAttr(structured),
604-
/*implicit=*/$_builder.getBoolAttr(implicit),
643+
/*implicit=*/$_builder.getBoolAttr(implicit), /*modifiers=*/nullptr,
605644
/*name=*/$_builder.getStringAttr(name));
606-
}]>];
645+
}]>,
646+
OpBuilder<(ins "::mlir::Type":$accVarType, "::mlir::Value":$var,
647+
"::mlir::Type":$varType, "::mlir::Value":$varPtrPtr,
648+
"::mlir::ValueRange":$bounds,
649+
"::mlir::ValueRange":$asyncOperands,
650+
"::mlir::ArrayAttr":$asyncOperandsDeviceType,
651+
"::mlir::ArrayAttr":$asyncOnly,
652+
"::mlir::acc::DataClause":$dataClause, "bool":$structured,
653+
"bool":$implicit, "::mlir::StringAttr":$name),
654+
[{
655+
build($_builder, $_state, accVarType, var, varType, varPtrPtr, bounds,
656+
asyncOperands, asyncOperandsDeviceType, asyncOnly, dataClause,
657+
structured, implicit, ::mlir::acc::DataClauseModifier::none, name);
658+
}]>,
659+
];
607660
}
608661

609662
//===----------------------------------------------------------------------===//
@@ -817,9 +870,7 @@ def OpenACC_CacheOp : OpenACC_DataEntryOp<"cache",
817870

818871
let extraClassDeclaration = extraClassDeclarationBase # [{
819872
/// Check if this is a cache with readonly modifier.
820-
bool isCacheReadonly() {
821-
return getDataClause() == acc::DataClause::acc_cache_readonly;
822-
}
873+
bool isCacheReadonly();
823874
}];
824875
}
825876

@@ -840,6 +891,8 @@ class OpenACC_DataExitOp<string mnemonic, string clause, string extraDescription
840891
DefaultValuedAttr<OpenACC_DataClauseAttr,clause>:$dataClause,
841892
DefaultValuedAttr<BoolAttr, "true">:$structured,
842893
DefaultValuedAttr<BoolAttr, "false">:$implicit,
894+
DefaultValuedAttr<OpenACC_DataClauseModifierAttr,
895+
"mlir::acc::DataClauseModifier::none">:$modifiers,
843896
OptionalAttr<StrAttr>:$name));
844897

845898
let description = !strconcat(extraDescription, [{
@@ -861,6 +914,7 @@ class OpenACC_DataExitOp<string mnemonic, string clause, string extraDescription
861914
counters (2.6.7).
862915
- `implicit`: Whether this is an implicitly generated operation, such as copies
863916
done to satisfy "Variables with Implicitly Determined Data Attributes" in 2.6.2.
917+
- `modifiers`: Keeps track of the data clause modifiers (eg zero, always, etc)
864918
- `name`: Holds the name of variable as specified in user clause (including bounds).
865919

866920
The async values attached to the data exit operation imply that the data
@@ -944,7 +998,8 @@ class OpenACC_DataExitOpWithVarPtr<string mnemonic, string clause>
944998
bounds, /*asyncOperands=*/{}, /*asyncOperandsDeviceType=*/nullptr,
945999
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
9461000
/*structured=*/$_builder.getBoolAttr(structured),
947-
/*implicit=*/$_builder.getBoolAttr(implicit), /*name=*/nullptr);
1001+
/*implicit=*/$_builder.getBoolAttr(implicit), /*modifiers=*/nullptr,
1002+
/*name=*/nullptr);
9481003
}]>,
9491004
OpBuilder<(ins "::mlir::Value":$accVar,
9501005
"::mlir::Value":$var,
@@ -961,9 +1016,22 @@ class OpenACC_DataExitOpWithVarPtr<string mnemonic, string clause>
9611016
bounds, /*asyncOperands=*/{}, /*asyncOperandsDeviceType=*/nullptr,
9621017
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
9631018
/*structured=*/$_builder.getBoolAttr(structured),
964-
/*implicit=*/$_builder.getBoolAttr(implicit),
1019+
/*implicit=*/$_builder.getBoolAttr(implicit), /*modifiers=*/nullptr,
9651020
/*name=*/$_builder.getStringAttr(name));
966-
}]>];
1021+
}]>,
1022+
OpBuilder<(ins "::mlir::Value":$accVar, "::mlir::Value":$var,
1023+
"::mlir::Type":$varType, "::mlir::ValueRange":$bounds,
1024+
"::mlir::ValueRange":$asyncOperands,
1025+
"::mlir::ArrayAttr":$asyncOperandsDeviceType,
1026+
"::mlir::ArrayAttr":$asyncOnly,
1027+
"::mlir::acc::DataClause":$dataClause, "bool":$structured,
1028+
"bool":$implicit, "::mlir::StringAttr":$name),
1029+
[{
1030+
build($_builder, $_state, accVar, var, varType, bounds,
1031+
asyncOperands, asyncOperandsDeviceType, asyncOnly, dataClause,
1032+
structured, implicit, ::mlir::acc::DataClauseModifier::none, name);
1033+
}]>,
1034+
];
9671035

9681036
code extraClassDeclarationDataExit = [{
9691037
mlir::TypedValue<mlir::acc::PointerLikeType> getVarPtr() {
@@ -998,7 +1066,8 @@ class OpenACC_DataExitOpNoVarPtr<string mnemonic, string clause> :
9981066
bounds, /*asyncOperands=*/{}, /*asyncOperandsDeviceType=*/nullptr,
9991067
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
10001068
/*structured=*/$_builder.getBoolAttr(structured),
1001-
/*implicit=*/$_builder.getBoolAttr(implicit), /*name=*/nullptr);
1069+
/*implicit=*/$_builder.getBoolAttr(implicit), /*modifiers=*/nullptr,
1070+
/*name=*/nullptr);
10021071
}]>,
10031072
OpBuilder<(ins "::mlir::Value":$accVar,
10041073
"bool":$structured, "bool":$implicit,
@@ -1009,9 +1078,20 @@ class OpenACC_DataExitOpNoVarPtr<string mnemonic, string clause> :
10091078
bounds, /*asyncOperands=*/{}, /*asyncOperandsDeviceType=*/nullptr,
10101079
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
10111080
/*structured=*/$_builder.getBoolAttr(structured),
1012-
/*implicit=*/$_builder.getBoolAttr(implicit),
1081+
/*implicit=*/$_builder.getBoolAttr(implicit), /*modifiers=*/nullptr,
10131082
/*name=*/$_builder.getStringAttr(name));
1014-
}]>
1083+
}]>,
1084+
OpBuilder<(ins "::mlir::Value":$accVar, "::mlir::ValueRange":$bounds,
1085+
"::mlir::ValueRange":$asyncOperands,
1086+
"::mlir::ArrayAttr":$asyncOperandsDeviceType,
1087+
"::mlir::ArrayAttr":$asyncOnly,
1088+
"::mlir::acc::DataClause":$dataClause, "bool":$structured,
1089+
"bool":$implicit, "::mlir::StringAttr":$name),
1090+
[{
1091+
build($_builder, $_state, accVar, bounds, asyncOperands,
1092+
asyncOperandsDeviceType, asyncOnly, dataClause, structured,
1093+
implicit, ::mlir::acc::DataClauseModifier::none, name);
1094+
}]>,
10151095
];
10161096

10171097
code extraClassDeclarationDataExit = [{

0 commit comments

Comments
 (0)