2 // RUN: %libomptarget-compilexx-generic
3 // RUN: env OMPX_APU_MAPS=1 HSA_XNACK=1 LIBOMPTARGET_INFO=60 %libomptarget-run-generic 2>&1 \
4 // RUN: | %fcheck-generic -check-prefix=CHECK
7 // REQUIRES: unified_shared_memory
14 /// Test for globals under automatic zero-copy.
15 /// Because we are building without unified_shared_memory
16 /// requirement pragma, all globals are allocated in the device
17 /// memory of all used GPUs. To ensure those globals contain the intended
18 /// values, we need to execute H2D and D2H memory copies even if we are running
19 /// in automatic zero-copy. This only applies to globals. Local variables (their
20 /// host pointers) are passed to the kernels by-value, according to the
21 /// automatic zero-copy behavior.
23 #pragma omp begin declare target
25 int32_t z
[10]; // 40 bytes
26 int32_t *k
; // 20 bytes
27 #pragma omp end declare target
30 int32_t *dev_k
= nullptr;
33 for (size_t t
= 0; t
< 10; t
++)
37 printf("Host pointer for k = %p\n", k
);
38 for (size_t t
= 0; t
< 5; t
++)
41 /// target update to forces a copy between host and device global, which we must
42 /// execute to keep the two global copies consistent. CHECK: Copying data from
43 /// host to device, HstPtr={{.*}}, TgtPtr={{.*}}, Size=40, Name=z
44 #pragma omp target update to(z[ : 10])
46 /// target map with always modifier (for x) forces a copy between host and
47 /// device global, which we must execute to keep the two global copies
48 /// consistent. k's content (host address) is passed by-value to the kernel
49 /// (Size=20 case). y, being a local variable, is also passed by-value to the
50 /// kernel (Size=4 case) CHECK: Return HstPtrBegin {{.*}} Size=4 for unified
51 /// shared memory CHECK: Return HstPtrBegin {{.*}} Size=20 for unified shared
52 /// memory CHECK: Copying data from host to device, HstPtr={{.*}},
53 /// TgtPtr={{.*}}, Size=4, Name=x
54 #pragma omp target map(to : k[ : 5]) map(always, tofrom : x) map(tofrom : y) \
59 for (size_t t
= 0; t
< 10; t
++)
63 /// CHECK-NOT: Copying data from device to host, TgtPtr={{.*}}, HstPtr={{.*}},
66 /// CHECK: Copying data from device to host, TgtPtr={{.*}}, HstPtr={{.*}},
69 /// CHECK: Copying data from device to host, TgtPtr={{.*}}, HstPtr={{.*}},
71 #pragma omp target update from(z[ : 10])
73 /// CHECK-NOT: k pointer not correctly passed to kernel
75 printf("k pointer not correctly passed to kernel\n");