[llvm-branch-commits] [llvm] [offload][omp] Manage events through liboffload (PR #226444)
Alex Duran via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Sep 25 07:59:49 PDT 2026
https://github.com/adurang updated https://github.com/llvm/llvm-project/pull/226444
>From a19558d209315d8a859bcc3fca659697c6be76f2 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Mon, 7 Sep 2026 08:27:58 -0700
Subject: [PATCH] [offload][omp] Manage events through liboffload
---
offload/include/device.h | 9 +--
offload/libompaccsupport/device.cpp | 53 +++++++++-----
.../common/include/PluginInterface.h | 21 ------
.../common/src/PluginInterface.cpp | 73 -------------------
4 files changed, 39 insertions(+), 117 deletions(-)
diff --git a/offload/include/device.h b/offload/include/device.h
index 8b656dd681f8a..9959ee7856e80 100644
--- a/offload/include/device.h
+++ b/offload/include/device.h
@@ -139,12 +139,11 @@ struct DeviceTy {
/// Event related interfaces.
/// {
- /// Create an event.
- int32_t createEvent(void **Event);
-
/// Record the event based on status in AsyncInfo->Queue at the moment the
- /// function is called.
- int32_t recordEvent(void *Event, AsyncInfoTy &AsyncInfo);
+ /// function is called. If \p Event already holds an event, it is replaced
+ /// with a new one representing the current queue state and the old event
+ /// is destroyed.
+ int32_t recordEvent(void **Event, AsyncInfoTy &AsyncInfo);
/// Wait for an event. This function can be blocking or non-blocking,
/// depending on the implementation. It is expected to set a dependence on the
diff --git a/offload/libompaccsupport/device.cpp b/offload/libompaccsupport/device.cpp
index e4a9ec10d5e3a..aad46e435add1 100644
--- a/offload/libompaccsupport/device.cpp
+++ b/offload/libompaccsupport/device.cpp
@@ -47,23 +47,16 @@ int HostDataToTargetTy::addEventIfNecessary(DeviceTy &Device,
if (!MappingConfig::get().UseEventsForAtomicTransfers)
return OFFLOAD_SUCCESS;
- void *Event = getEvent();
- bool NeedNewEvent = Event == nullptr;
- if (NeedNewEvent && Device.createEvent(&Event) != OFFLOAD_SUCCESS) {
- REPORT() << "Failed to create event";
- return OFFLOAD_FAIL;
- }
-
// We cannot assume the event should not be nullptr because we don't
// know if the target support event. But if a target doesn't,
// recordEvent should always return success.
- if (Device.recordEvent(Event, AsyncInfo) != OFFLOAD_SUCCESS) {
+ void *Event = getEvent();
+ if (Device.recordEvent(&Event, AsyncInfo) != OFFLOAD_SUCCESS) {
REPORT() << "Failed to set dependence on event " << Event;
return OFFLOAD_FAIL;
}
- if (NeedNewEvent)
- setEvent(Event);
+ setEvent(Event);
return OFFLOAD_SUCCESS;
}
@@ -528,24 +521,48 @@ int32_t DeviceTy::queryAsync(AsyncInfoTy &AsyncInfo) {
return OFFLOAD_SUCCESS;
}
-int32_t DeviceTy::createEvent(void **Event) {
- return RTL->create_event(RTLDeviceID, Event);
-}
+int32_t DeviceTy::recordEvent(void **Event, AsyncInfoTy &AsyncInfo) {
+ ol_event_handle_t NewEvent;
+ if (auto Res =
+ olCreateEvent(AsyncInfo.getQueue(), OL_EVENT_FLAGS_NONE, &NewEvent)) {
+ REPORT() << "Failure to record event: " << Res->Details;
+ return OFFLOAD_FAIL;
+ }
-int32_t DeviceTy::recordEvent(void *Event, AsyncInfoTy &AsyncInfo) {
- return RTL->record_event(RTLDeviceID, Event, AsyncInfo);
+ if (*Event) {
+ if (auto Res = olDestroyEvent(static_cast<ol_event_handle_t>(*Event)))
+ REPORT() << "Failure to destroy previous event " << *Event << ": "
+ << Res->Details;
+ }
+
+ *Event = NewEvent;
+ return OFFLOAD_SUCCESS;
}
int32_t DeviceTy::waitEvent(void *Event, AsyncInfoTy &AsyncInfo) {
- return RTL->wait_event(RTLDeviceID, Event, AsyncInfo);
+ ol_event_handle_t E = static_cast<ol_event_handle_t>(Event);
+ if (auto Res = olWaitEvents(AsyncInfo.getQueue(), &E, 1)) {
+ REPORT() << "Failure to wait for event " << Event << ": " << Res->Details;
+ return OFFLOAD_FAIL;
+ }
+ return OFFLOAD_SUCCESS;
}
int32_t DeviceTy::syncEvent(void *Event) {
- return RTL->sync_event(RTLDeviceID, Event);
+ if (auto Res = olSyncEvent(static_cast<ol_event_handle_t>(Event))) {
+ REPORT() << "Failure to synchronize event " << Event << ": "
+ << Res->Details;
+ return OFFLOAD_FAIL;
+ }
+ return OFFLOAD_SUCCESS;
}
int32_t DeviceTy::destroyEvent(void *Event) {
- return RTL->destroy_event(RTLDeviceID, Event);
+ if (auto Res = olDestroyEvent(static_cast<ol_event_handle_t>(Event))) {
+ REPORT() << "Failure to destroy event " << Event << ": " << Res->Details;
+ return OFFLOAD_FAIL;
+ }
+ return OFFLOAD_SUCCESS;
}
void DeviceTy::dumpOffloadEntries() {
diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h
index 5815e2c39f033..fe5327a76ca08 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -1789,27 +1789,6 @@ struct GenericPluginTy {
/// Prints information about the given devices supported by the plugin.
void print_device_info(int32_t DeviceId);
- /// Creates an event in the given plugin if supported.
- int32_t create_event(int32_t DeviceId, void **EventPtr);
-
- /// Records an event that has occurred.
- int32_t record_event(int32_t DeviceId, void *EventPtr,
- __tgt_async_info *AsyncInfoPtr);
-
- /// Wait until an event has occurred.
- int32_t wait_event(int32_t DeviceId, void *EventPtr,
- __tgt_async_info *AsyncInfoPtr);
-
- /// Synchronize execution until an event is done.
- int32_t sync_event(int32_t DeviceId, void *EventPtr);
-
- /// Get the elapsed time in milliseconds between two events.
- int32_t get_event_elapsed_time(int32_t DeviceId, void *StartEventPtr,
- void *EndEventPtr, float *ElapsedTime);
-
- /// Remove the event from the plugin.
- int32_t destroy_event(int32_t DeviceId, void *EventPtr);
-
/// Remove the event from the plugin.
void set_info_flag(uint32_t NewInfoLevel);
diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp
index 64cb559cca246..79b964a801e78 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -1677,79 +1677,6 @@ void GenericPluginTy::print_device_info(int32_t DeviceId) {
<< " info: " << toString(std::move(Err));
}
-int32_t GenericPluginTy::create_event(int32_t DeviceId, void **EventPtr) {
- auto Err = getDevice(DeviceId).createEvent(EventPtr);
- if (Err) {
- REPORT() << "Failure to create event: " << toString(std::move(Err));
- return OFFLOAD_FAIL;
- }
-
- return OFFLOAD_SUCCESS;
-}
-
-int32_t GenericPluginTy::record_event(int32_t DeviceId, void *EventPtr,
- __tgt_async_info *AsyncInfoPtr) {
- auto Err = getDevice(DeviceId).recordEvent(EventPtr, AsyncInfoPtr);
- if (Err) {
- REPORT() << "Failure to record event " << EventPtr << ": "
- << toString(std::move(Err));
- return OFFLOAD_FAIL;
- }
-
- return OFFLOAD_SUCCESS;
-}
-
-int32_t GenericPluginTy::wait_event(int32_t DeviceId, void *EventPtr,
- __tgt_async_info *AsyncInfoPtr) {
- auto Err = getDevice(DeviceId).waitEvent(EventPtr, AsyncInfoPtr);
- if (Err) {
- REPORT() << "Failure to wait event " << EventPtr << ": "
- << toString(std::move(Err));
- return OFFLOAD_FAIL;
- }
-
- return OFFLOAD_SUCCESS;
-}
-
-int32_t GenericPluginTy::sync_event(int32_t DeviceId, void *EventPtr) {
- auto Err = getDevice(DeviceId).syncEvent(EventPtr);
- if (Err) {
- REPORT() << "Failure to synchronize event " << EventPtr << ": "
- << toString(std::move(Err));
- return OFFLOAD_FAIL;
- }
-
- return OFFLOAD_SUCCESS;
-}
-
-int32_t GenericPluginTy::get_event_elapsed_time(int32_t DeviceId,
- void *StartEventPtr,
- void *EndEventPtr,
- float *ElapsedTime) {
- auto ElapsedTimeOrErr =
- getDevice(DeviceId).getEventElapsedTime(StartEventPtr, EndEventPtr);
- if (!ElapsedTimeOrErr) {
- REPORT() << "Failure to get elapsed time between events " << StartEventPtr
- << " and " << EndEventPtr << ": "
- << toString(ElapsedTimeOrErr.takeError());
- return OFFLOAD_FAIL;
- }
-
- *ElapsedTime = *ElapsedTimeOrErr;
- return OFFLOAD_SUCCESS;
-}
-
-int32_t GenericPluginTy::destroy_event(int32_t DeviceId, void *EventPtr) {
- auto Err = getDevice(DeviceId).destroyEvent(EventPtr);
- if (Err) {
- REPORT() << "Failure to destroy event " << EventPtr << ": "
- << toString(std::move(Err));
- return OFFLOAD_FAIL;
- }
-
- return OFFLOAD_SUCCESS;
-}
-
void GenericPluginTy::set_info_flag(uint32_t NewInfoLevel) {
std::atomic<uint32_t> &InfoLevel = getInfoLevelInternal();
InfoLevel.store(NewInfoLevel);
More information about the llvm-branch-commits
mailing list