| 1 |
/* Verify that 'acc_map_data' does not copy data to, and 'acc_unmap_data' does |
| 2 |
not copy data from the device. */ |
| 3 |
|
| 4 |
/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */ |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
#include <string.h> |
| 8 |
#include <openacc.h> |
| 9 |
|
| 10 |
int |
| 11 |
main () |
| 12 |
{ |
| 13 |
const int c0 = 9; |
| 14 |
const int c1 = 40; |
| 15 |
const int c2 = 47; |
| 16 |
|
| 17 |
const size_t N = 256; |
| 18 |
|
| 19 |
unsigned char *h = (unsigned char *) malloc (N); |
| 20 |
|
| 21 |
void *d = acc_malloc (N); |
| 22 |
|
| 23 |
memset (h, c0, N); // H <- c0 |
| 24 |
acc_memcpy_to_device (d, h, N); // D <- H = c0 |
| 25 |
|
| 26 |
memset (h, c1, N); // H <- c1 |
| 27 |
acc_map_data (h, d, N); |
| 28 |
for (size_t i = 0; i < N; ++i) |
| 29 |
if (h[i] != c1) |
| 30 |
abort (); |
| 31 |
|
| 32 |
acc_memcpy_from_device (h, d, N); // H <- D = c0 |
| 33 |
for (size_t i = 0; i < N; ++i) |
| 34 |
if (h[i] != c0) |
| 35 |
abort (); |
| 36 |
|
| 37 |
memset (h, c2, N); // H <- c2 |
| 38 |
acc_unmap_data (h); |
| 39 |
for (size_t i = 0; i < N; ++i) |
| 40 |
if (h[i] != c2) |
| 41 |
abort (); |
| 42 |
|
| 43 |
acc_memcpy_from_device (h, d, N); // H <- D = c0 |
| 44 |
for (size_t i = 0; i < N; ++i) |
| 45 |
if (h[i] != c0) |
| 46 |
abort (); |
| 47 |
|
| 48 |
acc_free (d); |
| 49 |
|
| 50 |
free (h); |
| 51 |
|
| 52 |
return 0; |
| 53 |
} |