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