https://github.com/adurang updated https://github.com/llvm/llvm-project/pull/221760
>From 9b50e2959f79b1b7d950ab9dd200597d72afa3bb Mon Sep 17 00:00:00 2001 From: "Duran, Alex" <[email protected]> Date: Mon, 7 Sep 2026 08:27:58 -0700 Subject: [PATCH] [offload][omp] Manage events through liboffload --- offload/include/device.h | 9 +-- offload/liboffload/exports | 5 -- offload/libompaccsupport/device.cpp | 53 +++++++++----- .../common/include/PluginInterface.h | 21 ------ .../common/src/PluginInterface.cpp | 73 ------------------- 5 files changed, 39 insertions(+), 122 deletions(-) diff --git a/offload/include/device.h b/offload/include/device.h index a7293013e0daf..58b8198a4f9ac 100644 --- a/offload/include/device.h +++ b/offload/include/device.h @@ -142,12 +142,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/liboffload/exports b/offload/liboffload/exports index 31173205a5076..21efd24dc3021 100644 --- a/offload/liboffload/exports +++ b/offload/liboffload/exports @@ -9,7 +9,6 @@ global: "error::OffloadErrCategory()"; "llvm::omp::target::RPCServerTy::registerCallback(unsigned int (*)(void*, unsigned int))"; "llvm::omp::target::plugin::GenericPluginTy::async_barrier(omp_interop_val_t*)"; - "llvm::omp::target::plugin::GenericPluginTy::create_event(int, void**)"; "llvm::omp::target::plugin::GenericPluginTy::create_interop(int, int, interop_spec_t*)"; "llvm::omp::target::plugin::GenericPluginTy::data_alloc(int, long, void*, int)"; "llvm::omp::target::plugin::GenericPluginTy::data_delete(int, void*, int)"; @@ -18,7 +17,6 @@ global: "llvm::omp::target::plugin::GenericPluginTy::data_notify_mapped(int, void*, long)"; "llvm::omp::target::plugin::GenericPluginTy::data_notify_unmapped(int, void*)"; "llvm::omp::target::plugin::GenericPluginTy::data_unlock(int, void*)"; - "llvm::omp::target::plugin::GenericPluginTy::destroy_event(int, void*)"; "llvm::omp::target::plugin::GenericPluginTy::flush_queue(omp_interop_val_t*)"; "llvm::omp::target::plugin::GenericPluginTy::get_function(__tgt_device_binary, char const*, void**)"; "llvm::omp::target::plugin::GenericPluginTy::get_global(__tgt_device_binary, unsigned long, char const*, void**)"; @@ -31,13 +29,10 @@ global: "llvm::omp::target::plugin::GenericPluginTy::number_of_devices()"; "llvm::omp::target::plugin::GenericPluginTy::obtain_device_info(int)"; "llvm::omp::target::plugin::GenericPluginTy::print_device_info(int)"; - "llvm::omp::target::plugin::GenericPluginTy::record_event(int, void*, __tgt_async_info*)"; "llvm::omp::target::plugin::GenericPluginTy::release_interop(int, omp_interop_val_t*)"; "llvm::omp::target::plugin::GenericPluginTy::set_device_identifier(int, int)"; "llvm::omp::target::plugin::GenericPluginTy::sync_barrier(omp_interop_val_t*)"; - "llvm::omp::target::plugin::GenericPluginTy::sync_event(int, void*)"; "llvm::omp::target::plugin::GenericPluginTy::use_auto_zero_copy(int)"; - "llvm::omp::target::plugin::GenericPluginTy::wait_event(int, void*, __tgt_async_info*)"; llvm::omp::target::ompt::Initialized; llvm::omp::target::ompt::lookupCallbackByCode; llvm::omp::target::ompt::lookupCallbackByName; diff --git a/offload/libompaccsupport/device.cpp b/offload/libompaccsupport/device.cpp index 7de4b23e91cfe..94d9d701d1019 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; } @@ -522,24 +515,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 719e4d5501843..9de2698546e85 100644 --- a/offload/plugins-nextgen/common/include/PluginInterface.h +++ b/offload/plugins-nextgen/common/include/PluginInterface.h @@ -1757,27 +1757,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 390c0d266aa9b..2c3bbd7acbdce 100644 --- a/offload/plugins-nextgen/common/src/PluginInterface.cpp +++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp @@ -1657,79 +1657,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); _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
