| 1 |
/* { dg-skip-if "" { *-*-* } { "-DACC_MEM_SHARED=1" } } */ |
| 2 |
|
| 3 |
#include <openacc.h> |
| 4 |
#include <assert.h> |
| 5 |
|
| 6 |
#define N 1024 |
| 7 |
|
| 8 |
struct mystr { |
| 9 |
int *data; |
| 10 |
}; |
| 11 |
|
| 12 |
static void |
| 13 |
test (unsigned variant) |
| 14 |
{ |
| 15 |
int arr[N]; |
| 16 |
struct mystr s; |
| 17 |
|
| 18 |
s.data = arr; |
| 19 |
|
| 20 |
acc_copyin (&s, sizeof (s)); |
| 21 |
acc_create (s.data, N * sizeof (int)); |
| 22 |
|
| 23 |
for (int i = 0; i < 20; i++) |
| 24 |
{ |
| 25 |
if ((variant + i) % 1) |
| 26 |
{ |
| 27 |
#pragma acc enter data attach(s.data) |
| 28 |
} |
| 29 |
else |
| 30 |
acc_attach ((void **) &s.data); |
| 31 |
|
| 32 |
if ((variant + i) % 2) |
| 33 |
{ |
| 34 |
#pragma acc exit data detach(s.data) |
| 35 |
} |
| 36 |
else |
| 37 |
acc_detach ((void **) &s.data); |
| 38 |
} |
| 39 |
|
| 40 |
assert (acc_is_present (arr, N * sizeof (int))); |
| 41 |
assert (acc_is_present (&s, sizeof (s))); |
| 42 |
|
| 43 |
acc_delete (arr, N * sizeof (int)); |
| 44 |
|
| 45 |
assert (!acc_is_present (arr, N * sizeof (int))); |
| 46 |
|
| 47 |
acc_copyout (&s, sizeof (s)); |
| 48 |
|
| 49 |
assert (!acc_is_present (&s, sizeof (s))); |
| 50 |
assert (s.data == arr); |
| 51 |
} |
| 52 |
|
| 53 |
int |
| 54 |
main (int argc, char *argv[]) |
| 55 |
{ |
| 56 |
for (unsigned variant = 0; variant < 4; ++variant) |
| 57 |
test (variant); |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |