[Mlir-commits] [mlir] [mlir][acc] Fixed side effects for [first]private/reduction. (PR #180791)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Feb 10 09:51:00 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Slava Zakharin (vzakhari)
<details>
<summary>Changes</summary>
This patch moves the definitions of memory effects for the data
entry/exit operations into C++ code. The main reason for this
is to modify the effects of [first]private and reduction
operations: they should not access `CurrentDeviceIdResource`
when they are located inside a compute construct.
The ODS to C++ migration was done with AI assistance. I reviewed
these changes and made sure it was an NFC change. After that
I modified [first]private and reduction implementations.
---
Patch is 31.30 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/180791.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/OpenACC/OpenACCCGOps.td (+5-4)
- (modified) mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td (+79-85)
- (modified) mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp (+264)
``````````diff
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCCGOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCCGOps.td
index ee249bb7c3c99..8f7c8c2a89be9 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCCGOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCCGOps.td
@@ -79,9 +79,10 @@ def OpenACC_KernelEnvironmentOp
// acc.firstprivate_map
//===----------------------------------------------------------------------===//
-def OpenACC_FirstprivateMapInitialOp : OpenACC_DataEntryOp<"firstprivate_map",
- "mlir::acc::DataClause::acc_firstprivate", "", [],
- (ins Arg<OpenACC_AnyPointerOrMappableType,"Host variable",[MemRead]>:$var)> {
+def OpenACC_FirstprivateMapInitialOp
+ : OpenACC_DataEntryOp<
+ "firstprivate_map", "mlir::acc::DataClause::acc_firstprivate", "", [],
+ (ins Arg<OpenACC_AnyPointerOrMappableType, "Host variable">:$var)> {
let summary = "Represents the mapping of the initial value for firstprivate "
"semantics.";
let description = [{
@@ -97,7 +98,7 @@ def OpenACC_FirstprivateMapInitialOp : OpenACC_DataEntryOp<"firstprivate_map",
being accessed directly
}];
let results = (outs Arg<OpenACC_AnyPointerOrMappableType,
- "Accelerator mapped variable",[MemWrite]>:$accVar);
+ "Accelerator mapped variable">:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
}
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
index 0a146db767760..b64cf50b4dba7 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -646,11 +646,13 @@ def OpenACC_GetExtentOp : OpenACC_Op<"get_extent", [NoMemoryEffect]> {
// The bounds are represented in rank order. Rank 0 (inner-most dimension) is
// the first.
//
-class OpenACC_DataEntryOp<string mnemonic, string clause, string extraDescription,
- list<Trait> traits = [], dag additionalArgs = (ins)> :
- OpenACC_Op<mnemonic, !listconcat(traits,
- [AttrSizedOperandSegments,
- MemoryEffects<[MemRead<OpenACC_CurrentDeviceIdResource>]>])> {
+class OpenACC_DataEntryOp<string mnemonic, string clause,
+ string extraDescription, list<Trait> traits = [],
+ dag additionalArgs = (ins)>
+ : OpenACC_Op<mnemonic,
+ !listconcat(traits, [AttrSizedOperandSegments,
+ DeclareOpInterfaceMethods<
+ MemoryEffectsOpInterface>])> {
let arguments = !con(
additionalArgs,
(ins TypeAttr:$varType,
@@ -836,42 +838,43 @@ def OpenACC_PrivateOp : OpenACC_DataEntryOp<"private",
(ins OpenACC_AnyPointerOrMappableType:$var)> {
let summary = "Represents private semantics for acc private clause.";
let results = (outs Arg<OpenACC_AnyPointerOrMappableType,
- "Accelerator mapped variable",[MemWrite]>:$accVar);
+ "Accelerator mapped variable">:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
}
//===----------------------------------------------------------------------===//
// 2.5.14 firstprivate clause
//===----------------------------------------------------------------------===//
-def OpenACC_FirstprivateOp : OpenACC_DataEntryOp<"firstprivate",
- "mlir::acc::DataClause::acc_firstprivate", "", [],
- (ins Arg<OpenACC_AnyPointerOrMappableType,"Host variable",[MemRead]>:$var)> {
+def OpenACC_FirstprivateOp
+ : OpenACC_DataEntryOp<
+ "firstprivate", "mlir::acc::DataClause::acc_firstprivate", "", [],
+ (ins Arg<OpenACC_AnyPointerOrMappableType, "Host variable">:$var)> {
let summary = "Represents firstprivate semantic for the acc firstprivate "
"clause.";
let results = (outs Arg<OpenACC_AnyPointerOrMappableType,
- "Accelerator mapped variable",[MemWrite]>:$accVar);
+ "Accelerator mapped variable">:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
}
//===----------------------------------------------------------------------===//
// 2.5.15 reduction clause
//===----------------------------------------------------------------------===//
-def OpenACC_ReductionOp : OpenACC_DataEntryOp<"reduction",
- "mlir::acc::DataClause::acc_reduction", "", [],
- (ins Arg<OpenACC_AnyPointerOrMappableType,"Host variable",[MemRead]>:$var)> {
+def OpenACC_ReductionOp
+ : OpenACC_DataEntryOp<
+ "reduction", "mlir::acc::DataClause::acc_reduction", "", [],
+ (ins Arg<OpenACC_AnyPointerOrMappableType, "Host variable">:$var)> {
let summary = "Represents reduction semantics for acc reduction clause.";
let results = (outs Arg<OpenACC_AnyPointerOrMappableType,
- "Accelerator mapped variable",[MemWrite]>:$accVar);
+ "Accelerator mapped variable">:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
}
//===----------------------------------------------------------------------===//
// 2.7.4 deviceptr clause
//===----------------------------------------------------------------------===//
-def OpenACC_DevicePtrOp : OpenACC_DataEntryOp<"deviceptr",
- "mlir::acc::DataClause::acc_deviceptr", "",
- [MemoryEffects<[MemRead<OpenACC_RuntimeCounters>]>],
- (ins OpenACC_AnyPointerOrMappableType:$var)> {
+def OpenACC_DevicePtrOp
+ : OpenACC_DataEntryOp<"deviceptr", "mlir::acc::DataClause::acc_deviceptr",
+ "", [], (ins OpenACC_AnyPointerOrMappableType:$var)> {
let summary = "Specifies that the variable pointer is a device pointer.";
let results = (outs OpenACC_AnyPointerOrMappableType:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
@@ -880,11 +883,9 @@ def OpenACC_DevicePtrOp : OpenACC_DataEntryOp<"deviceptr",
//===----------------------------------------------------------------------===//
// 2.7.5 present clause
//===----------------------------------------------------------------------===//
-def OpenACC_PresentOp : OpenACC_DataEntryOp<"present",
- "mlir::acc::DataClause::acc_present", "",
- [MemoryEffects<[MemRead<OpenACC_RuntimeCounters>,
- MemWrite<OpenACC_RuntimeCounters>]>],
- (ins OpenACC_AnyPointerOrMappableType:$var)> {
+def OpenACC_PresentOp
+ : OpenACC_DataEntryOp<"present", "mlir::acc::DataClause::acc_present",
+ "", [], (ins OpenACC_AnyPointerOrMappableType:$var)> {
let summary = "Specifies that the variable is already present on device.";
let results = (outs OpenACC_AnyPointerOrMappableType:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
@@ -893,15 +894,14 @@ def OpenACC_PresentOp : OpenACC_DataEntryOp<"present",
//===----------------------------------------------------------------------===//
// 2.7.7 copyin clause
//===----------------------------------------------------------------------===//
-def OpenACC_CopyinOp : OpenACC_DataEntryOp<"copyin",
- "mlir::acc::DataClause::acc_copyin", "",
- [MemoryEffects<[MemRead<OpenACC_RuntimeCounters>,
- MemWrite<OpenACC_RuntimeCounters>]>],
- (ins Arg<OpenACC_AnyPointerOrMappableType,"Host variable",[MemRead]>:$var)> {
+def OpenACC_CopyinOp
+ : OpenACC_DataEntryOp<
+ "copyin", "mlir::acc::DataClause::acc_copyin", "", [],
+ (ins Arg<OpenACC_AnyPointerOrMappableType, "Host variable">:$var)> {
let summary = "Represents copyin semantics for acc data clauses like acc "
"copyin and acc copy.";
let results = (outs Arg<OpenACC_AnyPointerOrMappableType,
- "Accelerator mapped variable",[MemWrite]>:$accVar);
+ "Accelerator mapped variable">:$accVar);
let extraClassDeclaration = extraClassDeclarationBase # [{
/// Check if this is a copyin with readonly modifier.
@@ -912,15 +912,13 @@ def OpenACC_CopyinOp : OpenACC_DataEntryOp<"copyin",
//===----------------------------------------------------------------------===//
// 2.7.9 create clause
//===----------------------------------------------------------------------===//
-def OpenACC_CreateOp : OpenACC_DataEntryOp<"create",
- "mlir::acc::DataClause::acc_create", "",
- [MemoryEffects<[MemRead<OpenACC_RuntimeCounters>,
- MemWrite<OpenACC_RuntimeCounters>]>],
- (ins OpenACC_AnyPointerOrMappableType:$var)> {
+def OpenACC_CreateOp
+ : OpenACC_DataEntryOp<"create", "mlir::acc::DataClause::acc_create", "", [],
+ (ins OpenACC_AnyPointerOrMappableType:$var)> {
let summary = "Represents create semantics for acc data clauses like acc "
"create and acc copyout.";
let results = (outs Arg<OpenACC_AnyPointerOrMappableType,
- "Accelerator mapped variable",[MemWrite]>:$accVar);
+ "Accelerator mapped variable">:$accVar);
let extraClassDeclaration = extraClassDeclarationBase # [{
/// Check if this is a create with zero modifier.
@@ -931,11 +929,9 @@ def OpenACC_CreateOp : OpenACC_DataEntryOp<"create",
//===----------------------------------------------------------------------===//
// 2.7.10 no_create clause
//===----------------------------------------------------------------------===//
-def OpenACC_NoCreateOp : OpenACC_DataEntryOp<"nocreate",
- "mlir::acc::DataClause::acc_no_create", "",
- [MemoryEffects<[MemRead<OpenACC_RuntimeCounters>,
- MemWrite<OpenACC_RuntimeCounters>]>],
- (ins OpenACC_AnyPointerOrMappableType:$var)> {
+def OpenACC_NoCreateOp
+ : OpenACC_DataEntryOp<"nocreate", "mlir::acc::DataClause::acc_no_create",
+ "", [], (ins OpenACC_AnyPointerOrMappableType:$var)> {
let summary = "Represents acc no_create semantics.";
let results = (outs OpenACC_AnyPointerOrMappableType:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
@@ -944,11 +940,10 @@ def OpenACC_NoCreateOp : OpenACC_DataEntryOp<"nocreate",
//===----------------------------------------------------------------------===//
// 2.7.12 attach clause
//===----------------------------------------------------------------------===//
-def OpenACC_AttachOp : OpenACC_DataEntryOp<"attach",
- "mlir::acc::DataClause::acc_attach", "",
- [MemoryEffects<[MemRead<OpenACC_RuntimeCounters>,
- MemWrite<OpenACC_RuntimeCounters>]>],
- (ins Arg<OpenACC_AnyPointerOrMappableType,"Host variable",[MemRead]>:$var)> {
+def OpenACC_AttachOp
+ : OpenACC_DataEntryOp<
+ "attach", "mlir::acc::DataClause::acc_attach", "", [],
+ (ins Arg<OpenACC_AnyPointerOrMappableType, "Host variable">:$var)> {
let summary = "Represents acc attach semantics which updates a pointer in "
"device memory with the corresponding device address of the "
"pointee.";
@@ -964,15 +959,16 @@ def OpenACC_AttachOp : OpenACC_DataEntryOp<"attach",
// It is also useful for providing the device address for unstructured construct
// exit_data since unlike structured constructs, there is no matching data entry
// operation.
-def OpenACC_GetDevicePtrOp : OpenACC_DataEntryOp<"getdeviceptr",
- "mlir::acc::DataClause::acc_getdeviceptr", [{
+def OpenACC_GetDevicePtrOp
+ : OpenACC_DataEntryOp<"getdeviceptr",
+ "mlir::acc::DataClause::acc_getdeviceptr", [{
This operation is used to get the `accPtr` for a variable. This is often
used in conjunction with data exit operations when the data entry
operation is not visible. This operation can have a `dataClause` argument
that is any of the valid `mlir::acc::DataClause` entries.
\
- }], [MemoryEffects<[MemRead<OpenACC_RuntimeCounters>]>],
- (ins OpenACC_AnyPointerOrMappableType:$var)> {
+ }],
+ [], (ins OpenACC_AnyPointerOrMappableType:$var)> {
let summary = "Gets device address if variable exists on device.";
let results = (outs OpenACC_AnyPointerOrMappableType:$accVar);
let hasVerifier = 0;
@@ -982,22 +978,22 @@ def OpenACC_GetDevicePtrOp : OpenACC_DataEntryOp<"getdeviceptr",
//===----------------------------------------------------------------------===//
// 2.14.4 device clause
//===----------------------------------------------------------------------===//
-def OpenACC_UpdateDeviceOp : OpenACC_DataEntryOp<"update_device",
- "mlir::acc::DataClause::acc_update_device", "", [],
- (ins Arg<OpenACC_AnyPointerOrMappableType,"Host variable",[MemRead]>:$var)> {
+def OpenACC_UpdateDeviceOp
+ : OpenACC_DataEntryOp<
+ "update_device", "mlir::acc::DataClause::acc_update_device", "", [],
+ (ins Arg<OpenACC_AnyPointerOrMappableType, "Host variable">:$var)> {
let summary = "Represents acc update device semantics.";
let results = (outs Arg<OpenACC_AnyPointerOrMappableType,
- "Accelerator mapped variable",[MemWrite]>:$accVar);
+ "Accelerator mapped variable">:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
}
//===----------------------------------------------------------------------===//
// 2.8 use_device clause
//===----------------------------------------------------------------------===//
-def OpenACC_UseDeviceOp : OpenACC_DataEntryOp<"use_device",
- "mlir::acc::DataClause::acc_use_device", "",
- [MemoryEffects<[MemRead<OpenACC_RuntimeCounters>]>],
- (ins OpenACC_AnyPointerOrMappableType:$var)> {
+def OpenACC_UseDeviceOp
+ : OpenACC_DataEntryOp<"use_device", "mlir::acc::DataClause::acc_use_device",
+ "", [], (ins OpenACC_AnyPointerOrMappableType:$var)> {
let summary = "Represents acc use_device semantics.";
let results = (outs OpenACC_AnyPointerOrMappableType:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
@@ -1006,10 +1002,11 @@ def OpenACC_UseDeviceOp : OpenACC_DataEntryOp<"use_device",
//===----------------------------------------------------------------------===//
// 2.13.1 device_resident clause
//===----------------------------------------------------------------------===//
-def OpenACC_DeclareDeviceResidentOp : OpenACC_DataEntryOp<"declare_device_resident",
- "mlir::acc::DataClause::acc_declare_device_resident", "",
- [MemoryEffects<[MemWrite<OpenACC_RuntimeCounters>]>],
- (ins Arg<OpenACC_AnyPointerOrMappableType,"Host variable",[MemRead]>:$var)> {
+def OpenACC_DeclareDeviceResidentOp
+ : OpenACC_DataEntryOp<
+ "declare_device_resident",
+ "mlir::acc::DataClause::acc_declare_device_resident", "", [],
+ (ins Arg<OpenACC_AnyPointerOrMappableType, "Host variable">:$var)> {
let summary = "Represents acc declare device_resident semantics.";
let results = (outs OpenACC_AnyPointerOrMappableType:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
@@ -1018,10 +1015,10 @@ def OpenACC_DeclareDeviceResidentOp : OpenACC_DataEntryOp<"declare_device_reside
//===----------------------------------------------------------------------===//
// 2.13.3 link clause
//===----------------------------------------------------------------------===//
-def OpenACC_DeclareLinkOp : OpenACC_DataEntryOp<"declare_link",
- "mlir::acc::DataClause::acc_declare_link", "",
- [MemoryEffects<[MemWrite<OpenACC_RuntimeCounters>]>],
- (ins Arg<OpenACC_AnyPointerOrMappableType,"Host variable",[MemRead]>:$var)> {
+def OpenACC_DeclareLinkOp
+ : OpenACC_DataEntryOp<
+ "declare_link", "mlir::acc::DataClause::acc_declare_link", "", [],
+ (ins Arg<OpenACC_AnyPointerOrMappableType, "Host variable">:$var)> {
let summary = "Represents acc declare link semantics.";
let results = (outs OpenACC_AnyPointerOrMappableType:$accVar);
let extraClassDeclaration = extraClassDeclarationBase;
@@ -1030,9 +1027,9 @@ def OpenACC_DeclareLinkOp : OpenACC_DataEntryOp<"declare_link",
//===----------------------------------------------------------------------===//
// 2.10 cache directive
//===----------------------------------------------------------------------===//
-def OpenACC_CacheOp : OpenACC_DataEntryOp<"cache",
- "mlir::acc::DataClause::acc_cache", "", [NoMemoryEffect],
- (ins OpenACC_AnyPointerOrMappableType:$var)> {
+def OpenACC_CacheOp
+ : OpenACC_DataEntryOp<"cache", "mlir::acc::DataClause::acc_cache", "", [],
+ (ins OpenACC_AnyPointerOrMappableType:$var)> {
let summary = "Represents the cache directive that is associated with a "
"loop.";
let results = (outs OpenACC_AnyPointerOrMappableType:$accVar);
@@ -1047,11 +1044,13 @@ def OpenACC_CacheOp : OpenACC_DataEntryOp<"cache",
// terminology used in this dialect. It refers to data operations that will appear
// after data or compute region. It will be used as the base of acc dialect
// operations for the following OpenACC data clauses: copyout, detach, delete.
-class OpenACC_DataExitOp<string mnemonic, string clause, string extraDescription,
- list<Trait> traits = [], dag additionalArgs = (ins)> :
- OpenACC_Op<mnemonic, !listconcat(traits,
- [AttrSizedOperandSegments,
- MemoryEffects<[MemRead<OpenACC_CurrentDeviceIdResource>]>])> {
+class OpenACC_DataExitOp<string mnemonic, string clause,
+ string extraDescription, list<Trait> traits = [],
+ dag additionalArgs = (ins)>
+ : OpenACC_Op<mnemonic,
+ !listconcat(traits, [AttrSizedOperandSegments,
+ DeclareOpInterfaceMethods<
+ MemoryEffectsOpInterface>])> {
let arguments = !con(additionalArgs,
(ins Variadic<OpenACC_DataBoundsType>:$bounds,
Variadic<IntOrIndex>:$asyncOperands,
@@ -1135,13 +1134,10 @@ class OpenACC_DataExitOp<string mnemonic, string clause, string extraDescription
class OpenACC_DataExitOpWithVarPtr<string mnemonic, string clause>
: OpenACC_DataExitOp<
mnemonic, clause,
- "- `varPtr`: The address of variable to copy back to.",
- [MemoryEffects<[MemRead<OpenACC_RuntimeCounters>,
- MemWrite<OpenACC_RuntimeCounters>]>],
+ "- `varPtr`: The address of variable to copy back to.", [],
(ins Arg<OpenACC_AnyPointerOrMappableType,
- "Accelerator mapped variable", [MemRead]>:$accVar,
- Arg<OpenACC_AnyPointerOrMappableType,
- "Host variable", [MemWrite]>:$var,
+ "Accelerator mapped variable">:$accVar,
+ Arg<OpenACC_AnyPointerOrMappableType, "Host variable">:$var,
TypeAttr:$varType)> {
let assemblyFormat = [{
custom<AccVar>($accVar, type($accVar))
@@ -1212,12 +1208,10 @@ class OpenACC_DataExitOpWithVarPtr<string mnemonic, string clause>
}];
}
-class OpenACC_DataExitOpNoVarPtr<string mnemonic, string clause> :
- OpenACC_DataExitOp<mnemonic, clause, "",
- [MemoryEffects<[MemRead<OpenACC_RuntimeCounters>,
- MemWrite<OpenACC_RuntimeCounters>]>],
- (ins Arg<OpenACC_AnyPointerOrMappableType,"Accelerator mapped variable",
- [MemRead]>:$accVar)> {
+class OpenACC_DataExitOpNoVarPtr<string mnemonic, string clause>
+ : OpenACC_DataExitOp<mnemonic, clause, "", [],
+ (ins Arg<OpenACC_AnyPointerOrMappableType,
+ "Accelerator mapped variable">:$accVar)> {
let assemblyFormat = [{
custom<AccVar>($accVar, type($accVar))
(`bounds` `(` $bounds^ `)` )?
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index f405fbbbd838d..460314f8f678f 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -1224,6 +1224,270 @@ bool acc::CacheOp::isCacheReadonly() {
acc::DataClauseModifier::readonly);
}
+//===----------------------------------------------------------------------===//
+// Data entry/exit operations - getEffects implementations
+//===----------------------------------------------------------------------===//
+
+// This function returns true iff the given operation is enclosed
+// in any ACC_COMPU...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/180791
More information about the Mlir-commits
mailing list