Skip to content

Commit 607872a

Browse files
razvanlupusoruGeneraluseAI
authored andcommitted
[mlir][acc] Introduce ACCImplicitDeclare pass for globals handling (llvm#169720)
This commit introduces the ACCImplicitDeclare pass to the OpenACC dialect, complementing ACCImplicitData by handling global variables referenced in OpenACC compute regions and routines. Overview: --------- The pass applies implicit `acc declare` actions to global variables referenced in OpenACC regions. While the OpenACC spec focuses on implicit data mapping (handled by ACCImplicitData), implicit declare is advantageous and required for specific cases: 1. Globals referenced in implicit `acc routine` - Since data mapping only applies to compute regions, globals in routines must use `acc declare`. 2. Compiler-generated globals - Type descriptors, runtime names, and error reporting strings introduced during compilation that wouldn't be visible for user-provided `acc declare` directives. 3. Constant globals - Constants like filename strings or initialization values benefit from being marked with `acc declare` rather than being mapped repeatedly (e.g., 1000 kernel launches shouldn't map the same constant 1000 times). Implementation: --------------- The pass performs this in two phases: 1. Hoisting: Non-constant globals in compute regions have their address-of operations hoisted out of the region when possible, allowing implicit data mapping instead of declare marking. 2. Declaration: Remaining that must be device available (constants, globals in routines, globals in recipe operations) are marked with the acc.declare attribute. The pass processes: - OpenACC compute constructs (parallel, kernels, serial) - Functions marked with acc routine - Private, firstprivate, and reduction recipes (when used) - Initialization regions of existing declared globals Requirements: ------------- The pass requires operations to implement: - acc::AddressOfGlobalOpInterface (for address-of ops) - acc::GlobalVariableOpInterface (for global definitions) - acc::IndirectGlobalAccessOpInterface (for indirect access)
1 parent dba25ec commit 607872a

File tree

5 files changed

+638
-0
lines changed

5 files changed

+638
-0
lines changed

mlir/include/mlir/Dialect/OpenACC/OpenACC.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ static constexpr StringLiteral getRoutineInfoAttrName() {
180180
return StringLiteral("acc.routine_info");
181181
}
182182

183+
/// Used to check whether the current operation is an `acc routine`
184+
inline bool isAccRoutineOp(mlir::Operation *op) {
185+
return op->hasAttr(mlir::acc::getRoutineInfoAttrName());
186+
}
187+
183188
static constexpr StringLiteral getFromDefaultClauseAttrName() {
184189
return StringLiteral("acc.from_default");
185190
}

mlir/include/mlir/Dialect/OpenACC/Transforms/Passes.td

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,34 @@ def ACCImplicitData : Pass<"acc-implicit-data", "mlir::ModuleOp"> {
6363
];
6464
}
6565

66+
def ACCImplicitDeclare : Pass<"acc-implicit-declare", "mlir::ModuleOp"> {
67+
let summary = "Applies implicit acc declare to globals referenced in compute and routine acc regions";
68+
let description = [{
69+
This pass applies implicit `acc declare` actions to global variables
70+
referenced in OpenACC compute regions and routine functions.
71+
72+
The pass performs the following actions:
73+
74+
1. Hoists address-of operations for non-constant globals out of OpenACC
75+
regions when they can be implicitly mapped rather than declared.
76+
77+
2. Collects global symbols referenced in:
78+
- OpenACC compute constructs (parallel, kernels, serial)
79+
- Functions marked with acc routine
80+
- Initialization regions of existing acc declare globals
81+
- Private/firstprivate/reduction recipe operations
82+
83+
3. Marks collected globals with the acc.declare attribute using the
84+
copyin data clause.
85+
86+
The pass avoids unnecessary declare marking by:
87+
- Skipping function symbols (which use acc routine instead)
88+
- Hoisting non-constant global references that can use implicit mapping
89+
- Only processing symbols that are not already valid in device regions
90+
}];
91+
let dependentDialects = ["mlir::acc::OpenACCDialect"];
92+
}
93+
6694
def ACCImplicitRoutine : Pass<"acc-implicit-routine", "mlir::ModuleOp"> {
6795
let summary = "Generate implicit acc routine for functions in acc regions";
6896
let description = [{

0 commit comments

Comments
 (0)