Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / api / omp_host_pinned_memory.c
blob7a6a00d489d5aa04a717c101f964556eaf78975f
1 // RUN: %libomptarget-compile-run-and-check-generic
3 #include <omp.h>
4 #include <stdio.h>
6 // Allocate pinned memory on the host
7 void *llvm_omp_target_alloc_host(size_t, int);
8 void llvm_omp_target_free_host(void *, int);
10 int main() {
11 const int N = 64;
12 const int device = omp_get_default_device();
13 const int host = omp_get_initial_device();
15 int *hst_ptr = llvm_omp_target_alloc_host(N * sizeof(int), device);
17 for (int i = 0; i < N; ++i)
18 hst_ptr[i] = 2;
20 #pragma omp target teams distribute parallel for device(device) \
21 map(tofrom : hst_ptr[0 : N])
22 for (int i = 0; i < N; ++i)
23 hst_ptr[i] -= 1;
25 int sum = 0;
26 for (int i = 0; i < N; ++i)
27 sum += hst_ptr[i];
29 llvm_omp_target_free_host(hst_ptr, device);
30 // CHECK: PASS
31 if (sum == N)
32 printf("PASS\n");