1// RUN: %libomptarget-compile-run-and-check-generic
2
3#include <omp.h>
4#include <stdio.h>
5
6// Allocate pinned memory on the host
7void *llvm_omp_target_alloc_host(size_t, int);
8void llvm_omp_target_free_host(void *, int);
9
10int main() {
11 const int N = 64;
12 const int device = omp_get_default_device();
13 const int host = omp_get_initial_device();
14
15 int *hst_ptr = llvm_omp_target_alloc_host(N * sizeof(int), device);
16
17 for (int i = 0; i < N; ++i)
18 hst_ptr[i] = 2;
19
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;
24
25 int sum = 0;
26 for (int i = 0; i < N; ++i)
27 sum += hst_ptr[i];
28
29 llvm_omp_target_free_host(hst_ptr, device);
30 // CHECK: PASS
31 if (sum == N)
32 printf(format: "PASS\n");
33}
34

source code of offload/test/api/omp_host_pinned_memory.c