1 // RUN: %libomptarget-compile-run-and-check-generic
6 * Verify all three data transfer directions: H2D, D2D and D2H
13 #include "callbacks.h"
14 #include "register_emi.h"
17 int NumDevices
= omp_get_num_devices();
18 assert(NumDevices
> 0 && "No device(s) present.");
19 int Device
= omp_get_default_device();
20 int Host
= omp_get_initial_device();
21 // Note: Zero value depicts an OFFLOAD_SUCCESS
24 printf("Allocating Memory on Device\n");
25 int *DevPtr
= (int *)omp_target_alloc(sizeof(int), Device
);
26 assert(DevPtr
&& "Could not allocate memory on device.");
27 int *HstPtr
= (int *)malloc(sizeof(int));
30 printf("Testing: Host to Device\n");
31 Status
= omp_target_memcpy(DevPtr
, HstPtr
, sizeof(int), 0, 0, Device
, Host
);
32 assert(Status
== 0 && "H2D memory copy operation failed.\n");
34 printf("Testing: Device to Device\n");
35 Status
= omp_target_memcpy(DevPtr
, DevPtr
, sizeof(int), 0, 0, Device
, Device
);
36 assert(Status
== 0 && "D2D memory copy operation failed.\n");
38 printf("Testing: Device to Host\n");
39 Status
= omp_target_memcpy(HstPtr
, DevPtr
, sizeof(int), 0, 0, Host
, Device
);
40 assert(Status
== 0 && "D2H memory copy operation failed.\n");
42 printf("Checking Correctness\n");
43 assert(*HstPtr
== 42);
45 printf("Freeing Memory on Device\n");
47 omp_target_free(DevPtr
, Device
);
54 /// CHECK: Callback Init:
56 /// CHECK: Allocating Memory on Device
57 /// CHECK: Callback DataOp EMI: endpoint=1 optype=1
58 /// CHECK-SAME: src_device_num=[[HOST:[0-9]+]]
59 /// CHECK-SAME: dest_device_num=[[DEVICE:[0-9]+]]
60 /// CHECK: Callback DataOp EMI: endpoint=2 optype=1 {{.+}} src_device_num=[[HOST]] {{.+}} dest_device_num=[[DEVICE]]
62 /// CHECK: Testing: Host to Device
63 /// CHECK: Callback DataOp EMI: endpoint=1 optype=2 {{.+}} src_device_num=[[HOST]] {{.+}} dest_device_num=[[DEVICE]]
64 /// CHECK: Callback DataOp EMI: endpoint=2 optype=2 {{.+}} src_device_num=[[HOST]] {{.+}} dest_device_num=[[DEVICE]]
66 /// CHECK: Testing: Device to Device
67 /// CHECK: Callback DataOp EMI: endpoint=1 optype=3 {{.+}} src_device_num=[[DEVICE]] {{.+}} dest_device_num=[[DEVICE]]
68 /// CHECK: Callback DataOp EMI: endpoint=2 optype=3 {{.+}} src_device_num=[[DEVICE]] {{.+}} dest_device_num=[[DEVICE]]
70 /// CHECK: Testing: Device to Host
71 /// CHECK: Callback DataOp EMI: endpoint=1 optype=3 {{.+}} src_device_num=[[DEVICE]] {{.+}} dest_device_num=[[HOST]]
72 /// CHECK: Callback DataOp EMI: endpoint=2 optype=3 {{.+}} src_device_num=[[DEVICE]] {{.+}} dest_device_num=[[HOST]]
74 /// CHECK: Checking Correctness
76 /// CHECK: Freeing Memory on Device
77 /// CHECK: Callback DataOp EMI: endpoint=1 optype=4 {{.+}} src_device_num=[[DEVICE]]
78 /// CHECK: Callback DataOp EMI: endpoint=2 optype=4 {{.+}} src_device_num=[[DEVICE]]
80 /// CHECK: Callback Fini: