Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / test / unified_shared_memory / close_modifier.c
blob47902a9a298dd80e14948131bd081145e74c530f
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
9 #include <omp.h>
10 #include <stdio.h>
12 #pragma omp requires unified_shared_memory
14 #define N 1024
16 int main(int argc, char *argv[]) {
17 int fails;
18 void *host_alloc, *device_alloc;
19 void *host_data, *device_data;
20 int *alloc = (int *)malloc(N * sizeof(int));
21 int data[N];
23 for (int i = 0; i < N; ++i) {
24 alloc[i] = 10;
25 data[i] = 1;
28 host_data = &data[0];
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++) {
42 alloc[i] += 1;
43 data[i] += 1;
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
57 fails = 0;
58 for (int i = 0; i < N; i++) {
59 if (alloc[i] != 10)
60 fails++;
62 printf("Alloc host values not updated: %s\n",
63 (fails == 0) ? "Succeeded" : "Failed");
65 // CHECK: Data host values not updated: Succeeded
66 fails = 0;
67 for (int i = 0; i < N; i++) {
68 if (data[i] != 1)
69 fails++;
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++) {
80 alloc[i] += 1;
81 data[i] += 1;
84 #pragma omp target map(close, tofrom : alloc[ : N], data[ : N])
86 // CHECK: Alloc device values are correct: Succeeded
87 fails = 0;
88 for (int i = 0; i < N; i++) {
89 if (alloc[i] != 11)
90 fails++;
92 printf("Alloc device values are correct: %s\n",
93 (fails == 0) ? "Succeeded" : "Failed");
94 // CHECK: Data device values are correct: Succeeded
95 fails = 0;
96 for (int i = 0; i < N; i++) {
97 if (data[i] != 2)
98 fails++;
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++) {
105 alloc[i] += 1;
106 data[i] += 1;
110 // CHECK: Alloc host values updated: Succeeded
111 fails = 0;
112 for (int i = 0; i < N; i++) {
113 if (alloc[i] != 12)
114 fails++;
116 printf("Alloc host values updated: %s\n",
117 (fails == 0) ? "Succeeded" : "Failed");
119 // CHECK: Data host values updated: Succeeded
120 fails = 0;
121 for (int i = 0; i < N; i++) {
122 if (data[i] != 3)
123 fails++;
125 printf("Data host values updated: %s\n",
126 (fails == 0) ? "Succeeded" : "Failed");
128 free(alloc);
130 // CHECK: Done!
131 printf("Done!\n");
133 return 0;