Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / ompt / target_memcpy.c
blobf244e0f418ed63ef7417e615ae72c08d72dfad1e
1 // RUN: %libomptarget-compile-run-and-check-generic
2 // REQUIRES: ompt
3 // REQUIRES: gpu
5 /*
6 * Verify that for the target OpenMP APIs, the return address is non-null and
7 * distinct.
8 */
10 #include <omp.h>
11 #include <stdlib.h>
13 #include "callbacks.h"
14 #include "register_non_emi.h"
16 int main() {
17 int dev = omp_get_default_device();
18 int host = omp_get_initial_device();
20 int host_var1 = 42;
21 int host_var2 = 0;
22 void *dev_ptr = NULL;
24 // Allocate space on the device
25 dev_ptr = omp_target_alloc(sizeof(int), dev);
26 if (dev_ptr == NULL)
27 abort();
29 // H2D transfer
30 if (omp_target_memcpy(dev_ptr, &host_var1, sizeof(int), 0, 0, dev, host))
31 abort();
33 // D2D transfer
34 if (omp_target_memcpy(dev_ptr, dev_ptr, sizeof(int), 0, 0, dev, dev))
35 abort();
37 // D2H transfer
38 if (omp_target_memcpy(&host_var2, dev_ptr, sizeof(int), 0, 0, host, dev))
39 abort();
41 // Free the device location
42 omp_target_free(dev_ptr, dev);
44 // Both host variables should have the same value.
45 return host_var1 != host_var2;
48 // clang-format off
49 /// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=1
50 /// CHECK-SAME: src_device_num=[[HOST:[0-9]+]]
51 /// CHECK-SAME: dest_device_num=[[DEVICE:[0-9]+]]
52 /// CHECK-NOT: code=(nil)
53 /// CHECK: code=[[CODE1:0x[0-f]+]]
54 /// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=2
55 /// CHECK-SAME: src_device_num=[[HOST]] {{.+}} dest_device_num=[[DEVICE]]
56 /// CHECK-NOT: code=(nil)
57 /// CHECK-NOT: code=[[CODE1]]
58 /// CHECK: code=[[CODE2:0x[0-f]+]]
59 /// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=3
60 /// CHECK-SAME: src_device_num=[[DEVICE]] {{.+}} dest_device_num=[[DEVICE]]
61 /// CHECK-NOT: code=(nil)
62 /// CHECK-NOT: code=[[CODE2]]
63 /// CHECK: code=[[CODE3: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=[[HOST]]
66 /// CHECK-NOT: code=(nil)
67 /// CHECK-NOT: code=[[CODE3]]
68 /// CHECK: code=[[CODE4:0x[0-f]+]]
69 /// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=4
70 /// CHECK-NOT: code=(nil)
71 /// CHECK-NOT: code=[[CODE4]]