brintos

brintos / llvm-project-archived public Read only

0
0
Text · 807 B · 7a6a00d Raw
34 lines · c
1// RUN: %libomptarget-compile-run-and-check-generic2 3#include <omp.h>4#include <stdio.h>5 6// Allocate pinned memory on the host7void *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: PASS31  if (sum == N)32    printf("PASS\n");33}34