Skip to content

Commit 66f201e

Browse files
razvanlupusoruvinay-deshmukh
authored andcommitted
[mlir][acc] Add ACCImplicitData pass for implicit data attributes (llvm#166472)
This change adds the ACCImplicitData pass which implements the OpenACC specification for "Variables with Implicitly Determined Data Attributes" (OpenACC 3.4 spec, section 2.6.2). The pass automatically generates data clause operations (copyin, copyout, present, firstprivate, etc.) for variables used within OpenACC compute constructs (parallel, kernels, serial) that do not already have explicit data clauses. Key features: - Respects default(none) and default(present) clauses - Handles scalar vs. aggregate variables with different semantics: * Aggregates: present clause (if default(present)) or copy clause * Scalars: copy clause (kernels) or firstprivate (parallel/serial) - Generates privatization recipes when needed for firstprivate clauses - Performs alias analysis to avoid redundant data mappings - Ensures proper data clause ordering for partial entity access - Generates exit operations (copyout, delete) to match entry operations Requirements: - Types must implement acc::MappableType and/or acc::PointerLikeType interfaces to be considered candidates. - Operations accessing partial entities or creating subviews should implement acc::PartialEntityAccess and/or mlir::ViewLikeOpInterface for proper clause ordering. - Optionally pre-register acc::OpenACCSupport and mlir::AliasAnalysis if custom alias analysis, variable name determination, or error reporting is needed.
1 parent f6f41ec commit 66f201e

File tree

6 files changed

+1256
-0
lines changed

6 files changed

+1256
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#ifndef MLIR_DIALECT_OPENACC_TRANSFORMS_PASSES_H
1010
#define MLIR_DIALECT_OPENACC_TRANSFORMS_PASSES_H
1111

12+
#include "mlir/Dialect/Arith/IR/Arith.h"
13+
#include "mlir/Dialect/MemRef/IR/MemRef.h"
14+
#include "mlir/Dialect/OpenACC/OpenACC.h"
1215
#include "mlir/Pass/Pass.h"
1316

1417
namespace mlir {

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,40 @@ def LegalizeDataValuesInRegion : Pass<"openacc-legalize-data-values", "mlir::fun
2727
];
2828
}
2929

30+
def ACCImplicitData : Pass<"acc-implicit-data", "mlir::ModuleOp"> {
31+
let summary = "Generate implicit data attributes for OpenACC compute constructs";
32+
let description = [{
33+
This pass implements the OpenACC specification for "Variables with
34+
Implicitly Determined Data Attributes" (OpenACC 3.4 spec, section 2.6.2).
35+
36+
The pass automatically generates data clause operations for variables used
37+
within OpenACC compute constructs (parallel, kernels, serial) that do not
38+
already have explicit data clauses. The semantics follow these rules:
39+
40+
1. If there is a default(none) clause visible, no implicit data actions
41+
apply.
42+
43+
2. An aggregate variable (arrays, derived types, etc.) will be treated as:
44+
- In a present clause when default(present) is visible.
45+
- In a copy clause otherwise.
46+
47+
3. A scalar variable will be treated as if it appears in:
48+
- A copy clause if the compute construct is a kernels construct.
49+
- A firstprivate clause otherwise (parallel, serial).
50+
}];
51+
let dependentDialects = ["mlir::acc::OpenACCDialect",
52+
"mlir::memref::MemRefDialect",
53+
"mlir::arith::ArithDialect"];
54+
let options = [
55+
Option<"enableImplicitReductionCopy", "enable-implicit-reduction-copy",
56+
"bool", "true",
57+
"Enable applying implicit copy in lieu of implicit firstprivate for "
58+
"reduction variables. This allows uniform treatment of reduction "
59+
"variables between combined constructs (e.g., 'parallel loop') and "
60+
"separate constructs (e.g., 'parallel' followed by 'loop'), where "
61+
"the OpenACC spec requires copy semantics for the former but "
62+
"firstprivate would normally apply for the latter.">
63+
];
64+
}
65+
3066
#endif // MLIR_DIALECT_OPENACC_TRANSFORMS_PASSES

0 commit comments

Comments
 (0)