74 lines · c
1// clang-format off2// RUN: %libomptarget-compile-run-and-check-generic3// REQUIRES: ompt4// REQUIRES: gpu5// clang-format on6 7/*8 * Verify that for the target OpenMP APIs, the return address is non-null and9 * distinct.10 */11 12#include <omp.h>13#include <stdlib.h>14 15#include "callbacks.h"16#include "register_non_emi.h"17 18int main() {19 int dev = omp_get_default_device();20 int host = omp_get_initial_device();21 22 int host_var1 = 42;23 int host_var2 = 0;24 void *dev_ptr = NULL;25 26 // Allocate space on the device27 dev_ptr = omp_target_alloc(sizeof(int), dev);28 if (dev_ptr == NULL)29 abort();30 31 // H2D transfer32 if (omp_target_memcpy(dev_ptr, &host_var1, sizeof(int), 0, 0, dev, host))33 abort();34 35 // D2D transfer36 if (omp_target_memcpy(dev_ptr, dev_ptr, sizeof(int), 0, 0, dev, dev))37 abort();38 39 // D2H transfer40 if (omp_target_memcpy(&host_var2, dev_ptr, sizeof(int), 0, 0, host, dev))41 abort();42 43 // Free the device location44 omp_target_free(dev_ptr, dev);45 46 // Both host variables should have the same value.47 return host_var1 != host_var2;48}49 50// clang-format off51/// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=ompt_target_data_alloc52/// CHECK-SAME: src_device_num=[[HOST:[0-9]+]]53/// CHECK-SAME: dest_device_num=[[DEVICE:[0-9]+]]54/// CHECK-NOT: code=(nil)55/// CHECK: code=[[CODE1:0x[0-f]+]]56/// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=ompt_target_data_transfer_to_device57/// CHECK-SAME: src_device_num=[[HOST]] {{.+}} dest_device_num=[[DEVICE]]58/// CHECK-NOT: code=(nil)59/// CHECK-NOT: code=[[CODE1]]60/// CHECK: code=[[CODE2:0x[0-f]+]]61/// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=ompt_target_data_transfer_from_device62/// CHECK-SAME: src_device_num=[[DEVICE]] {{.+}} dest_device_num=[[DEVICE]]63/// CHECK-NOT: code=(nil)64/// CHECK-NOT: code=[[CODE2]]65/// CHECK: code=[[CODE3:0x[0-f]+]]66/// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=ompt_target_data_transfer_from_device67/// CHECK-SAME: src_device_num=[[DEVICE]] {{.+}} dest_device_num=[[HOST]]68/// CHECK-NOT: code=(nil)69/// CHECK-NOT: code=[[CODE3]]70/// CHECK: code=[[CODE4:0x[0-f]+]]71/// CHECK: Callback DataOp: target_id=[[TARGET_ID:[0-9]+]] host_op_id=[[HOST_OP_ID:[0-9]+]] optype=ompt_target_data_delete72/// CHECK-NOT: code=(nil)73/// CHECK-NOT: code=[[CODE4]]74