[llvm] [OFFLOAD][L0] Implement Event APIs (PR #201306)

Kevin Sala Penades via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 3 23:07:55 PDT 2026


================
@@ -0,0 +1,124 @@
+//===--- Level Zero Target RTL Implementation -----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Level Zero Event and Event Pool abstractions.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0EVENT_H
+#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0EVENT_H
+
+#include <level_zero/ze_api.h>
+#include <memory>
+#include <mutex>
+
+#include "L0Defs.h"
+#include "L0Trace.h"
+
+namespace llvm::omp::target::plugin {
+
+class L0QueueTy;
+
+class L0EventTy {
+  ze_event_handle_t ZeEvent;
+  L0QueueTy *Queue = nullptr;
+
+public:
+  L0EventTy(ze_event_handle_t ZeEvent) : ZeEvent(ZeEvent) {}
+  ze_event_handle_t getZeEvent() const { return ZeEvent; }
+  L0QueueTy *getQueue() const { return Queue; }
+
+  Error reset() {
+    Queue = nullptr;
+    CALL_ZE_RET_ERROR(zeEventHostReset, ZeEvent);
+    return Plugin::success();
+  }
+
+  void recordQueue(L0QueueTy &Q) { Queue = &Q; }
+
+  Error synchronize() {
+    CALL_ZE_RET_ERROR(zeEventHostSynchronize, ZeEvent, L0DefaultTimeout);
+    return Plugin::success();
+  }
+
+  Expected<bool> isComplete() {
+    ze_result_t Result;
+
+    CALL_ZE(Result, zeEventQueryStatus, ZeEvent);
+    if (Result == ZE_RESULT_SUCCESS)
+      return true;
+    if (Result == ZE_RESULT_NOT_READY)
+      return false;
+    return Plugin::error(ErrorCode::UNKNOWN, "failed to query event status: %s",
+                         getZeErrorName(Result));
+  }
+};
+
+/// Common event pool used in the plugin. This event pool assumes all events
+/// from the pool are host-visible and use the same event pool flag.
+class EventPoolTy {
----------------
kevinsala wrote:

It would be nice to modify the generic manager to cover this use case as well. I will try it when I have some free time.

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


More information about the llvm-commits mailing list