| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */ |
| 3 |
|
| 4 |
/* Fortran testcase is at libgomp.oacc-fortran/acc_host_device_ptr.f90. */ |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
#include <openacc.h> |
| 8 |
#include <stdint.h> |
| 9 |
|
| 10 |
int |
| 11 |
main (int argc, char **argv) |
| 12 |
{ |
| 13 |
const int N = 256; |
| 14 |
int i; |
| 15 |
unsigned char *h; |
| 16 |
void *d; |
| 17 |
|
| 18 |
h = (unsigned char *) malloc (N); |
| 19 |
|
| 20 |
d = acc_malloc (N); |
| 21 |
|
| 22 |
acc_map_data (h, d, N); |
| 23 |
|
| 24 |
for (i = 0; i < N; i++) |
| 25 |
{ |
| 26 |
if (acc_hostptr ((void *)((uintptr_t) d + (uintptr_t) i)) != |
| 27 |
(void *)((uintptr_t) h + (uintptr_t) i)) |
| 28 |
abort (); |
| 29 |
} |
| 30 |
|
| 31 |
for (i = 0; i < N; i++) |
| 32 |
{ |
| 33 |
if (acc_deviceptr ((void *)((uintptr_t) h + (uintptr_t) i)) != |
| 34 |
(void *)((uintptr_t) d + (uintptr_t) i)) |
| 35 |
abort (); |
| 36 |
} |
| 37 |
|
| 38 |
acc_unmap_data (h); |
| 39 |
|
| 40 |
for (i = 0; i < N; i++) |
| 41 |
{ |
| 42 |
if (acc_hostptr ((void *)((uintptr_t) d + (uintptr_t) i)) != 0) |
| 43 |
abort (); |
| 44 |
} |
| 45 |
|
| 46 |
for (i = 0; i < N; i++) |
| 47 |
{ |
| 48 |
if (acc_deviceptr (h + i) != 0) |
| 49 |
abort (); |
| 50 |
} |
| 51 |
|
| 52 |
acc_free (d); |
| 53 |
|
| 54 |
free (h); |
| 55 |
|
| 56 |
return 0; |
| 57 |
} |