Skip to content

Commit 82f794b

Browse files
committed
add test for target groupprivate usage
1 parent a1b3851 commit 82f794b

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,9 +2236,9 @@ def GroupprivateOp : OpenMP_Op<"groupprivate",
22362236
each group having its own copy.
22372237

22382238
This operation takes in the address of a symbol that represents the original
2239-
variable and returns the address of its groupprivate copy. All occurrences of
2240-
groupprivate variables in a parallel region should use the groupprivate copy
2241-
returned by this operation.
2239+
variable, optional DeviceTypeAttr and returns the address of its groupprivate copy.
2240+
All occurrences of groupprivate variables in a parallel region should
2241+
use the groupprivate copy returned by this operation.
22422242

22432243
The `sym_addr` refers to the address of the symbol, which is a pointer to
22442244
the original variable.

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,3 +3392,5 @@ func.func @omp_groupprivate_device_type() {
33923392

33933393
return
33943394
}
3395+
3396+
llvm.mlir.global internal @_QFgpEx() : i32
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
2+
3+
module attributes {omp.is_target_device = true, llvm.target_triple = "amdgcn-amd-amdhsa",
4+
dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.alloca_memory_space", 5 : ui32>>} {
5+
llvm.func @_QQmain() attributes {fir.bindc_name = "main"} {
6+
7+
%ga = llvm.mlir.addressof @global_a : !llvm.ptr
8+
%map_a = omp.map.info var_ptr(%ga : !llvm.ptr, i32) map_clauses(tofrom) capture(ByCopy) -> !llvm.ptr {name = "i"}
9+
omp.target map_entries(%map_a -> %arg1 : !llvm.ptr) {
10+
%loaded = llvm.load %arg1 : !llvm.ptr -> i32
11+
12+
%any_addr = llvm.mlir.addressof @global_any : !llvm.ptr
13+
%any_gp = omp.groupprivate %any_addr : !llvm.ptr, device_type(any) -> !llvm.ptr
14+
llvm.store %loaded, %any_gp : i32, !llvm.ptr
15+
16+
%host_addr = llvm.mlir.addressof @global_host : !llvm.ptr
17+
%host_gp = omp.groupprivate %host_addr : !llvm.ptr, device_type(host) -> !llvm.ptr
18+
llvm.store %loaded, %host_gp : i32, !llvm.ptr
19+
20+
%nohost_addr = llvm.mlir.addressof @global_nohost : !llvm.ptr
21+
%nohost_gp = omp.groupprivate %nohost_addr : !llvm.ptr, device_type(nohost) -> !llvm.ptr
22+
llvm.store %loaded, %nohost_gp : i32, !llvm.ptr
23+
24+
omp.terminator
25+
}
26+
llvm.return
27+
}
28+
llvm.mlir.global internal @global_a() : i32
29+
llvm.mlir.global internal @global_any() : i32
30+
llvm.mlir.global internal @global_host() : i32
31+
llvm.mlir.global internal @global_nohost() : i32
32+
}
33+
34+
// CHECK: define {{.*}} amdgpu_kernel void @__omp_offloading_{{.*}}_{{.*}}__QQmain_{{.*}}(ptr %{{.*}}, ptr %{{.*}}) #{{[0-9]+}} {
35+
// CHECK-LABEL: omp.target:
36+
// CHECK-NEXT : %[[LOAD:.*]] = load i32, ptr %3, align 4
37+
// CHECK-NEXT : %[[ALLOC_any:.*]] = call ptr @__kmpc_alloc_shared(i64 4)
38+
// CHECK-NEXT : store i32 %[[LOAD]], ptr %[[ALLOC_any]], align 4
39+
// CHECK-NEXT : store i32 %[[LOAD]], ptr @global_host, align 4
40+
// CHECK-NEXT : %[[ALLOC_NOHOST:.*]] = call ptr @__kmpc_alloc_shared(i64 4)
41+
// CHECK-NEXT : store i32 %[[LOAD]], ptr %[[ALLOC_NOHOST]], align 4

0 commit comments

Comments
 (0)