| 1 |
// { dg-do run { target offload_device_nonshared_as } } |
| 2 |
|
| 3 |
#include <stdio.h> |
| 4 |
#include <string.h> |
| 5 |
#include <stdint.h> |
| 6 |
extern "C" void abort (); |
| 7 |
|
| 8 |
struct S |
| 9 |
{ |
| 10 |
int * ptr; |
| 11 |
int ptr_len; |
| 12 |
|
| 13 |
int *&refptr; |
| 14 |
int refptr_len; |
| 15 |
|
| 16 |
bool set_ptr (int n) |
| 17 |
{ |
| 18 |
bool mapped; |
| 19 |
uintptr_t hostptr = (uintptr_t) ptr; |
| 20 |
#pragma omp target map(from:mapped) |
| 21 |
{ |
| 22 |
if (ptr != (int *) hostptr) |
| 23 |
for (int i = 0; i < ptr_len; i++) |
| 24 |
ptr[i] = n; |
| 25 |
mapped = (ptr != (int *) hostptr); |
| 26 |
} |
| 27 |
return mapped; |
| 28 |
} |
| 29 |
|
| 30 |
bool set_refptr (int n) |
| 31 |
{ |
| 32 |
bool mapped; |
| 33 |
uintptr_t hostrefptr = (uintptr_t) refptr; |
| 34 |
#pragma omp target map(from:mapped) |
| 35 |
{ |
| 36 |
if (refptr != (int *) hostrefptr) |
| 37 |
for (int i = 0; i < refptr_len; i++) |
| 38 |
refptr[i] = n; |
| 39 |
mapped = (refptr != (int *) hostrefptr); |
| 40 |
} |
| 41 |
return mapped; |
| 42 |
} |
| 43 |
}; |
| 44 |
|
| 45 |
int main (void) |
| 46 |
{ |
| 47 |
#define N 10 |
| 48 |
int *ptr1 = new int[N]; |
| 49 |
int *ptr2 = new int[N]; |
| 50 |
|
| 51 |
memset (ptr1, 0, sizeof (int) * N); |
| 52 |
memset (ptr2, 0, sizeof (int) * N); |
| 53 |
|
| 54 |
S s = { ptr1, N, ptr2, N }; |
| 55 |
|
| 56 |
bool mapped; |
| 57 |
int val = 123; |
| 58 |
|
| 59 |
mapped = s.set_ptr (val); |
| 60 |
if (mapped) |
| 61 |
abort (); |
| 62 |
if (s.ptr != ptr1) |
| 63 |
abort (); |
| 64 |
for (int i = 0; i < N; i++) |
| 65 |
if (ptr1[i] != 0) |
| 66 |
abort (); |
| 67 |
|
| 68 |
mapped = s.set_refptr (val); |
| 69 |
if (mapped) |
| 70 |
abort (); |
| 71 |
if (s.refptr != ptr2) |
| 72 |
abort (); |
| 73 |
for (int i = 0; i < N; i++) |
| 74 |
if (ptr2[i] != 0) |
| 75 |
abort (); |
| 76 |
|
| 77 |
#pragma omp target data map(ptr1[:N]) |
| 78 |
mapped = s.set_ptr (val); |
| 79 |
|
| 80 |
if (!mapped) |
| 81 |
abort (); |
| 82 |
if (s.set_refptr (0)) |
| 83 |
abort (); |
| 84 |
if (s.ptr != ptr1 || s.refptr != ptr2) |
| 85 |
abort (); |
| 86 |
for (int i = 0; i < N; i++) |
| 87 |
if (ptr1[i] != val) |
| 88 |
abort (); |
| 89 |
|
| 90 |
#pragma omp target data map(ptr2[:N]) |
| 91 |
mapped = s.set_refptr (val); |
| 92 |
|
| 93 |
if (!mapped) |
| 94 |
abort (); |
| 95 |
if (s.set_ptr (0)) |
| 96 |
abort (); |
| 97 |
if (s.ptr != ptr1 || s.refptr != ptr2) |
| 98 |
abort (); |
| 99 |
for (int i = 0; i < N; i++) |
| 100 |
if (ptr2[i] != val) |
| 101 |
abort (); |
| 102 |
|
| 103 |
return 0; |
| 104 |
} |