1 // RUN: %libomptarget-compile-run-and-check-generic
3 // REQUIRES: unified_shared_memory
5 // amdgpu runtime crash
6 // UNSUPPORTED: amdgcn-amd-amdhsa
11 // ---------------------------------------------------------------------------
12 // Various definitions copied from OpenMP RTL
14 extern void __tgt_register_requires(int64_t);
16 // End of definitions copied from OpenMP RTL.
17 // ---------------------------------------------------------------------------
19 #pragma omp requires unified_shared_memory
23 int main(int argc
, char *argv
[]) {
25 void *host_alloc
, *device_alloc
;
26 void *host_data
, *device_data
;
27 int *alloc
= (int *)malloc(N
* sizeof(int));
30 // Manual registration of requires flags for Clang versions
31 // that do not support requires.
32 __tgt_register_requires(8);
34 for (int i
= 0; i
< N
; ++i
) {
40 host_alloc
= &alloc
[0];
42 // implicit mapping of data
43 #pragma omp target map(tofrom : device_data, device_alloc)
45 device_data
= &data
[0];
46 device_alloc
= &alloc
[0];
48 for (int i
= 0; i
< N
; i
++) {
54 // CHECK: Address of alloc on device matches host address.
55 if (device_alloc
== host_alloc
)
56 printf("Address of alloc on device matches host address.\n");
58 // CHECK: Address of data on device matches host address.
59 if (device_data
== host_data
)
60 printf("Address of data on device matches host address.\n");
62 // On the host, check that the arrays have been updated.
63 // CHECK: Alloc device values updated: Succeeded
65 for (int i
= 0; i
< N
; i
++) {
69 printf("Alloc device values updated: %s\n",
70 (fails
== 0) ? "Succeeded" : "Failed");
72 // CHECK: Data device values updated: Succeeded
74 for (int i
= 0; i
< N
; i
++) {
78 printf("Data device values updated: %s\n",
79 (fails
== 0) ? "Succeeded" : "Failed");
82 // Test that updates on the host snd on the device are both visible.
85 // Update on the host.
86 for (int i
= 0; i
< N
; ++i
) {
93 // CHECK: Alloc host values updated: Succeeded
95 for (int i
= 0; i
< N
; i
++) {
99 printf("Alloc host values updated: %s\n",
100 (fails
== 0) ? "Succeeded" : "Failed");
101 // CHECK: Data host values updated: Succeeded
103 for (int i
= 0; i
< N
; i
++) {
107 printf("Data host values updated: %s\n",
108 (fails
== 0) ? "Succeeded" : "Failed");