1 | // RUN: %libomptarget-compile-and-run-generic |
---|---|
2 | |
3 | #include <assert.h> |
4 | #include <omp.h> |
5 | #include <stdlib.h> |
6 | |
7 | #define N 1024 |
8 | #define OFFSET 16 |
9 | |
10 | int main(int argc, char *argv[]) { |
11 | int *host_data = (int *)malloc(size: sizeof(int) * N); |
12 | void *device_ptr = omp_get_mapped_ptr(host_data, 0); |
13 | |
14 | assert(device_ptr == NULL && "the pointer should not be mapped right now"); |
15 | |
16 | #pragma omp target enter data map(to: host_data[:N]) |
17 | |
18 | device_ptr = omp_get_mapped_ptr(host_data, 0); |
19 | |
20 | assert(device_ptr && "the pointer should be mapped now"); |
21 | |
22 | void *ptr = NULL; |
23 | |
24 | #pragma omp target map(from: ptr) |
25 | { ptr = host_data; } |
26 | |
27 | assert(ptr == device_ptr && "wrong pointer mapping"); |
28 | |
29 | device_ptr = omp_get_mapped_ptr(host_data + OFFSET, 0); |
30 | |
31 | assert(device_ptr && "the pointer with offset should be mapped"); |
32 | |
33 | #pragma omp target map(from: ptr) |
34 | { ptr = host_data + OFFSET; } |
35 | |
36 | assert(ptr == device_ptr && "wrong pointer mapping"); |
37 | |
38 | return 0; |
39 | } |
40 |