1 // RUN: %libomptarget-compile-run-and-check-generic
3 // REQUIRES: unified_shared_memory
4 // UNSUPPORTED: clang-6, clang-7, clang-8, clang-9
6 // amdgpu runtime crash
7 // UNSUPPORTED: amdgcn-amd-amdhsa
12 #pragma omp requires unified_shared_memory
16 int main(int argc
, char *argv
[]) {
18 void *host_alloc
, *device_alloc
;
19 void *host_data
, *device_data
;
20 int *alloc
= (int *)malloc(N
* sizeof(int));
23 for (int i
= 0; i
< N
; ++i
) {
29 host_alloc
= &alloc
[0];
32 // Test that updates on the device are not visible to host
33 // when only a TO mapping is used.
35 #pragma omp target map(tofrom : device_data, device_alloc) \
36 map(close, to : alloc[ : N], data[ : N])
38 device_data
= &data
[0];
39 device_alloc
= &alloc
[0];
41 for (int i
= 0; i
< N
; i
++) {
47 // CHECK: Address of alloc on device different from host address.
48 if (device_alloc
!= host_alloc
)
49 printf("Address of alloc on device different from host address.\n");
51 // CHECK: Address of data on device different from host address.
52 if (device_data
!= host_data
)
53 printf("Address of data on device different from host address.\n");
55 // On the host, check that the arrays have been updated.
56 // CHECK: Alloc host values not updated: Succeeded
58 for (int i
= 0; i
< N
; i
++) {
62 printf("Alloc host values not updated: %s\n",
63 (fails
== 0) ? "Succeeded" : "Failed");
65 // CHECK: Data host values not updated: Succeeded
67 for (int i
= 0; i
< N
; i
++) {
71 printf("Data host values not updated: %s\n",
72 (fails
== 0) ? "Succeeded" : "Failed");
75 // Test that updates on the device are visible on host
76 // when a from is used.
79 for (int i
= 0; i
< N
; i
++) {
84 #pragma omp target map(close, tofrom : alloc[ : N], data[ : N])
86 // CHECK: Alloc device values are correct: Succeeded
88 for (int i
= 0; i
< N
; i
++) {
92 printf("Alloc device values are correct: %s\n",
93 (fails
== 0) ? "Succeeded" : "Failed");
94 // CHECK: Data device values are correct: Succeeded
96 for (int i
= 0; i
< N
; i
++) {
100 printf("Data device values are correct: %s\n",
101 (fails
== 0) ? "Succeeded" : "Failed");
103 // Update values on the device
104 for (int i
= 0; i
< N
; i
++) {
110 // CHECK: Alloc host values updated: Succeeded
112 for (int i
= 0; i
< N
; i
++) {
116 printf("Alloc host values updated: %s\n",
117 (fails
== 0) ? "Succeeded" : "Failed");
119 // CHECK: Data host values updated: Succeeded
121 for (int i
= 0; i
< N
; i
++) {
125 printf("Data host values updated: %s\n",
126 (fails
== 0) ? "Succeeded" : "Failed");