| 1 | // RUN: %libomptarget-compile-generic |
| 2 | // RUN: %libomptarget-run-generic 2>&1 \ |
| 3 | // RUN: | %fcheck-generic |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | |
| 8 | #define N 1024 |
| 9 | #define FROM 64 |
| 10 | #define LENGTH 128 |
| 11 | |
| 12 | int main() { |
| 13 | float *A = (float *)malloc(N * sizeof(float)); |
| 14 | |
| 15 | #pragma omp target enter data map(to : A[FROM : LENGTH]) |
| 16 | |
| 17 | // A, has been mapped starting at index FROM, but inside the use_device_ptr |
| 18 | // clause it is captured by base so the library must look it up using the |
| 19 | // base address. |
| 20 | |
| 21 | float *A_dev = NULL; |
| 22 | #pragma omp target data use_device_ptr(A) |
| 23 | { A_dev = A; } |
| 24 | #pragma omp target exit data map(delete : A[FROM : LENGTH]) |
| 25 | |
| 26 | // CHECK: Success |
| 27 | if (A_dev == NULL || A_dev == A) |
| 28 | fprintf(stderr, format: "Failure\n" ); |
| 29 | else |
| 30 | fprintf(stderr, format: "Success\n" ); |
| 31 | |
| 32 | free(ptr: A); |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |