[Openmp-commits] [openmp] [OpenMP][OMPT] Add OMPT callback for device data exchange 'Device-to-Device' (PR #81991)

via Openmp-commits openmp-commits at lists.llvm.org
Wed Feb 21 00:33:59 PST 2024


================
@@ -0,0 +1,79 @@
+// RUN: %libomptarget-compile-run-and-check-generic
+// REQUIRES: ompt
+// UNSUPPORTED: aarch64-unknown-linux-gnu
+// UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+// UNSUPPORTED: x86_64-pc-linux-gnu
+// UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+/*
+ * Verify all three data transfer directions: H2D, D2D and D2H
+ */
+
+#include <omp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "callbacks.h"
+#include "register_emi.h"
+
+int main(void) {
+  int NumDevices = omp_get_num_devices();
+  assert(NumDevices > 0);
+  int Device = 0;
+  int Host = omp_get_initial_device();
+
+  printf("Allocating Memory on Device\n");
+  int *DevPtr = (int *)omp_target_alloc(sizeof(int), Device);
+  int *HstPtr = (int *)malloc(sizeof(int));
+  *HstPtr = 42;
+
+  printf("Testing: Host to Device\n");
+  omp_target_memcpy(DevPtr, HstPtr, sizeof(int), 0, 0, Device, Host);
----------------
dhruvachak wrote:

Check the return value of all calls to omp_target_memcpy. Otherwise, if it fails, the host value could remain 42 but the program still failed.

https://github.com/llvm/llvm-project/pull/81991


More information about the Openmp-commits mailing list