Skip to content

Commit 621cbcd

Browse files
authored
[mlir][acc] Adds attr to acc.present to identify default clause origin (#169114)
The `acc.present` Op as generated by ACCImplicitData does not provide a way to differentiate between `acc.present` ops that are generated implicitly and the ones that are generated as result of an explicit `default(present)` clause in the source code. This differentiation would allow for better communication to the user on the decisions made by the compiler while managing data automatically between the host and the device. This commit adds this information as a discardable attribute on the `acc.present` op.
1 parent 9688f88 commit 621cbcd

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

flang/test/Transforms/OpenACC/acc-implicit-data.fir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func.func @test_fir_derivedtype_in_parallel_defaultpresent() {
133133
return
134134
}
135135

136-
// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref<!fir.type<_QFTaggr{field:f32}>>) -> !fir.ref<!fir.type<_QFTaggr{field:f32}>> {implicit = true, name = "aggrvar"}
136+
// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref<!fir.type<_QFTaggr{field:f32}>>) -> !fir.ref<!fir.type<_QFTaggr{field:f32}>> {acc.from_default, implicit = true, name = "aggrvar"}
137137
// CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref<!fir.type<_QFTaggr{field:f32}>>) {dataClause = #acc<data_clause acc_present>, implicit = true, name = "aggrvar"}
138138

139139
// -----
@@ -147,7 +147,7 @@ func.func @test_fir_derivedtype_in_kernels_defaultpresent() {
147147
return
148148
}
149149

150-
// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref<!fir.type<_QFTaggr{field:f32}>>) -> !fir.ref<!fir.type<_QFTaggr{field:f32}>> {implicit = true, name = "aggrvar"}
150+
// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref<!fir.type<_QFTaggr{field:f32}>>) -> !fir.ref<!fir.type<_QFTaggr{field:f32}>> {acc.from_default, implicit = true, name = "aggrvar"}
151151
// CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref<!fir.type<_QFTaggr{field:f32}>>) {dataClause = #acc<data_clause acc_present>, implicit = true, name = "aggrvar"}
152152

153153
// -----
@@ -161,7 +161,7 @@ func.func @test_fir_array_in_parallel_defaultpresent() {
161161
return
162162
}
163163

164-
// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref<!fir.array<10xf32>>) -> !fir.ref<!fir.array<10xf32>> {implicit = true, name = "arrayvar"}
164+
// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref<!fir.array<10xf32>>) -> !fir.ref<!fir.array<10xf32>> {acc.from_default, implicit = true, name = "arrayvar"}
165165
// CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref<!fir.array<10xf32>>) {dataClause = #acc<data_clause acc_present>, implicit = true, name = "arrayvar"}
166166

167167
// -----
@@ -175,7 +175,7 @@ func.func @test_fir_array_in_kernels_defaultpresent() {
175175
return
176176
}
177177

178-
// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref<!fir.array<10xf32>>) -> !fir.ref<!fir.array<10xf32>> {implicit = true, name = "arrayvar"}
178+
// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref<!fir.array<10xf32>>) -> !fir.ref<!fir.array<10xf32>> {acc.from_default, implicit = true, name = "arrayvar"}
179179
// CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref<!fir.array<10xf32>>) {dataClause = #acc<data_clause acc_present>, implicit = true, name = "arrayvar"}
180180

181181
// -----

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ static constexpr StringLiteral getRoutineInfoAttrName() {
177177
return StringLiteral("acc.routine_info");
178178
}
179179

180+
static constexpr StringLiteral getFromDefaultClauseAttrName() {
181+
return StringLiteral("acc.from_default");
182+
}
183+
180184
static constexpr StringLiteral getVarNameAttrName() {
181185
return VarNameAttr::name;
182186
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ Operation *ACCImplicitData::generateDataClauseOpForCandidate(
570570
newDataOp = acc::PresentOp::create(builder, loc, var,
571571
/*structured=*/true, /*implicit=*/true,
572572
accSupport.getVariableName(var));
573+
newDataOp->setAttr(acc::getFromDefaultClauseAttrName(),
574+
builder.getUnitAttr());
573575
} else {
574576
auto copyinOp =
575577
acc::CopyinOp::create(builder, loc, var,

mlir/test/Dialect/OpenACC/acc-implicit-data.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func.func @test_array_parallel_defaultpresent() {
110110
}
111111

112112
// CHECK-LABEL: func.func @test_array_parallel_defaultpresent
113-
// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : memref<10xf32>) -> memref<10xf32> {implicit = true, name = ""}
113+
// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : memref<10xf32>) -> memref<10xf32> {acc.from_default, implicit = true, name = ""}
114114
// CHECK: acc.delete accPtr(%[[PRESENT]] : memref<10xf32>) {dataClause = #acc<data_clause acc_present>, implicit = true, name = ""}
115115

116116
// -----

0 commit comments

Comments
 (0)