1 | // RUN: %libomptarget-compile-run-and-check-generic |
2 | // REQUIRES: ompt |
3 | // UNSUPPORTED: aarch64-unknown-linux-gnu |
4 | // UNSUPPORTED: aarch64-unknown-linux-gnu-LTO |
5 | // UNSUPPORTED: x86_64-pc-linux-gnu |
6 | // UNSUPPORTED: x86_64-pc-linux-gnu-LTO |
7 | // UNSUPPORTED: s390x-ibm-linux-gnu |
8 | // UNSUPPORTED: s390x-ibm-linux-gnu-LTO |
9 | |
10 | /* |
11 | * Verify that for the target OpenMP APIs, the return address is non-null and |
12 | * distinct. |
13 | */ |
14 | |
15 | #include <omp.h> |
16 | #include <stdlib.h> |
17 | |
18 | #include "callbacks.h" |
19 | #include "register_non_emi.h" |
20 | |
21 | int main() { |
22 | int dev = omp_get_default_device(); |
23 | int host = omp_get_initial_device(); |
24 | |
25 | int host_var1 = 42; |
26 | int host_var2 = 0; |
27 | void *dev_ptr = NULL; |
28 | |
29 | // Allocate space on the device |
30 | dev_ptr = omp_target_alloc(sizeof(int), dev); |
31 | if (dev_ptr == NULL) |
32 | abort(); |
33 | |
34 | // H2D transfer |
35 | if (omp_target_memcpy(dev_ptr, &host_var1, sizeof(int), 0, 0, dev, host)) |
36 | abort(); |
37 | |
38 | // D2D transfer |
39 | if (omp_target_memcpy(dev_ptr, dev_ptr, sizeof(int), 0, 0, dev, dev)) |
40 | abort(); |
41 | |
42 | // D2H transfer |
43 | if (omp_target_memcpy(&host_var2, dev_ptr, sizeof(int), 0, 0, host, dev)) |
44 | abort(); |
45 | |
46 | // Free the device location |
47 | omp_target_free(dev_ptr, dev); |
48 | |
49 | // Both host variables should have the same value. |
50 | return host_var1 != host_var2; |
51 | } |
52 | |
53 | // clang-format off |
54 | /// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=1 |
55 | /// CHECK-SAME: src_device_num=[[HOST:[0-9]+]] |
56 | /// CHECK-SAME: dest_device_num=[[DEVICE:[0-9]+]] |
57 | /// CHECK-NOT: code=(nil) |
58 | /// CHECK: code=[[CODE1:0x[0-f]+]] |
59 | /// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=2 |
60 | /// CHECK-SAME: src_device_num=[[HOST]] {{.+}} dest_device_num=[[DEVICE]] |
61 | /// CHECK-NOT: code=(nil) |
62 | /// CHECK-NOT: code=[[CODE1]] |
63 | /// CHECK: code=[[CODE2:0x[0-f]+]] |
64 | /// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=3 |
65 | /// CHECK-SAME: src_device_num=[[DEVICE]] {{.+}} dest_device_num=[[DEVICE]] |
66 | /// CHECK-NOT: code=(nil) |
67 | /// CHECK-NOT: code=[[CODE2]] |
68 | /// CHECK: code=[[CODE3:0x[0-f]+]] |
69 | /// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=3 |
70 | /// CHECK-SAME: src_device_num=[[DEVICE]] {{.+}} dest_device_num=[[HOST]] |
71 | /// CHECK-NOT: code=(nil) |
72 | /// CHECK-NOT: code=[[CODE3]] |
73 | /// CHECK: code=[[CODE4:0x[0-f]+]] |
74 | /// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=4 |
75 | /// CHECK-NOT: code=(nil) |
76 | /// CHECK-NOT: code=[[CODE4]] |
77 | |