42 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 <omp.h>7#include <stdio.h>8 9#pragma omp requires unified_shared_memory10 11struct S {12 int x;13 int y;14};15 16int main(int argc, char *argv[]) {17 int dev = omp_get_default_device();18 struct S s = {10, 20};19 20#pragma omp target enter data map(close, to : s)21#pragma omp target map(alloc : s)22 {23 s.x = 11;24 s.y = 21;25 }26// To determine whether x needs to be transferred or deleted, the runtime27// cannot simply check whether unified shared memory is enabled and the28// 'close' modifier is specified. It must check whether x was previously29// placed in device memory by, for example, a 'close' modifier that isn't30// specified here. The following struct member case checks a special code31// path in the runtime implementation where members are transferred before32// deletion of the struct.33#pragma omp target exit data map(from : s.x, s.y)34 35 // CHECK: s.x=11, s.y=2136 printf("s.x=%d, s.y=%d\n", s.x, s.y);37 // CHECK: present: 038 printf("present: %d\n", omp_target_is_present(&s, dev));39 40 return 0;41}42