[llvm] [Offload][OMPT][NFC] Add test for `host_op_id` consistency (PR #201144)

Jan André Reuter via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 00:24:34 PDT 2026


================
@@ -0,0 +1,99 @@
+// clang-format off
+// RUN: %libomptarget-compile-run-and-check-generic
+// REQUIRES: ompt
+// REQUIRES: gpu
+// clang-format on
+
+/*
+ * Example OpenMP program that checks if EMI callbacks
+ * correctly pass host_op_id between ompt_scope_begin and ompt_scope_end
+ */
+
+#include <assert.h>
+#include <omp.h>
+#include <stdio.h>
+
+#include "callbacks.h"
+#include "register_emi.h"
+
+int main(void) {
+  int NumDevices = omp_get_num_devices();
+  assert(NumDevices > 0 && "No device(s) present.");
+  int Device = omp_get_default_device();
+  int Host = omp_get_initial_device();
+  // Note: Zero value depicts an OFFLOAD_SUCCESS
+  int Status;
+
+  printf("Allocating Memory on Device\n");
+  int *DevPtr = (int *)omp_target_alloc(sizeof(int), Device);
+  assert(DevPtr && "Could not allocate memory on device.");
+  int *HstPtr = (int *)malloc(sizeof(int));
+  *HstPtr = 42;
+
+  printf("Testing: Host to Device\n");
+  Status = omp_target_memcpy(DevPtr, HstPtr, sizeof(int), 0, 0, Device, Host);
+  assert(Status == 0 && "H2D memory copy operation failed.\n");
+
+  printf("Testing: Device to Device\n");
+  Status = omp_target_memcpy(DevPtr, DevPtr, sizeof(int), 0, 0, Device, Device);
----------------
Thyre wrote:

Thanks for the suggestion. I think this makes sense, yes.
While `omp_target_memcpy` doesn't check if the same pointer with the same offset is used and copies the data over itself, this could change in the future so that e.g. the data transfer is omitted.

Using two device-allocated pointers ensures that the test still works even if the underlying implementation changes. I'll adapt the test.

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


More information about the llvm-commits mailing list