brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 0e9d25c Raw
34 lines · c
1// RUN: %libomptarget-compile-run-and-check-generic2 3// REQUIRES: unified_shared_memory4// UNSUPPORTED: clang-6, clang-7, clang-8, clang-95 6#include <assert.h>7#include <omp.h>8#include <stdio.h>9 10#pragma omp requires unified_shared_memory11 12int main(int argc, char *argv[]) {13  int dev = omp_get_default_device();14  int x = 10;15  int *x_dev = (int *)omp_target_alloc(sizeof x, dev);16  assert(x_dev && "expected omp_target_alloc to succeed");17  int rc = omp_target_associate_ptr(&x, x_dev, sizeof x, 0, dev);18  assert(!rc && "expected omp_target_associate_ptr to succeed");19 20// To determine whether x needs to be transferred, the runtime cannot simply21// check whether unified shared memory is enabled and the 'close' modifier is22// specified.  It must check whether x was previously placed in device memory23// by, for example, omp_target_associate_ptr.24#pragma omp target map(always, tofrom : x)25  x += 1;26 27  // CHECK: x=1128  printf("x=%d\n", x);29  // CHECK: present: 130  printf("present: %d\n", omp_target_is_present(&x, dev));31 32  return 0;33}34