diff options
| author | Ross Brunton <ross@codeplay.com> | 2025-07-24 14:31:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-24 14:31:06 +0100 |
| commit | 690c3ee5be51bf0b6598b1a202ceb7dec6acebbd (patch) | |
| tree | 64fdf52df0a4991f805723a0d9eead64ed33d7b2 /offload/liboffload | |
| parent | 675d7e19a73143cc624092c7ed12fd5f89416d47 (diff) | |
[Offload] Replace "EventOut" parameters with `olCreateEvent` (#150217)
Rather than having every "enqueue"-type function have an output pointer
specifically for an output event, just provide an `olCreateEvent`
entrypoint which pushes an event to the queue.
For example, replace:
```cpp
olMemcpy(Queue, ..., EventOut);
```
with
```cpp
olMemcpy(Queue, ...);
olCreateEvent(Queue, EventOut);
```
Diffstat (limited to 'offload/liboffload')
| -rw-r--r-- | offload/liboffload/API/Event.td | 13 | ||||
| -rw-r--r-- | offload/liboffload/API/Kernel.td | 2 | ||||
| -rw-r--r-- | offload/liboffload/API/Memory.td | 5 | ||||
| -rw-r--r-- | offload/liboffload/src/OffloadImpl.cpp | 32 |
4 files changed, 24 insertions, 28 deletions
diff --git a/offload/liboffload/API/Event.td b/offload/liboffload/API/Event.td index ea38b82ee145..9d217ae23038 100644 --- a/offload/liboffload/API/Event.td +++ b/offload/liboffload/API/Event.td @@ -11,6 +11,19 @@ //===----------------------------------------------------------------------===// def : Function { + let name = "olCreateEvent"; + let desc = "Enqueue an event to `Queue` and return it."; + let details = [ + "This event can be used with `olSyncEvent` and `olWaitEvents` and will be complete once all enqueued work prior to the `olCreateEvent` call is complete.", + ]; + let params = [ + Param<"ol_queue_handle_t", "Queue", "queue to create the event for", PARAM_IN>, + Param<"ol_event_handle_t*", "Event", "output pointer for the created event", PARAM_OUT> + ]; + let returns = []; +} + +def : Function { let name = "olDestroyEvent"; let desc = "Destroy the event and free all underlying resources."; let details = []; diff --git a/offload/liboffload/API/Kernel.td b/offload/liboffload/API/Kernel.td index 1e9537452820..502fb36467db 100644 --- a/offload/liboffload/API/Kernel.td +++ b/offload/liboffload/API/Kernel.td @@ -35,10 +35,8 @@ def : Function { Param<"const void*", "ArgumentsData", "pointer to the kernel argument struct", PARAM_IN_OPTIONAL>, Param<"size_t", "ArgumentsSize", "size of the kernel argument struct", PARAM_IN>, Param<"const ol_kernel_launch_size_args_t*", "LaunchSizeArgs", "pointer to the struct containing launch size parameters", PARAM_IN>, - Param<"ol_event_handle_t*", "EventOut", "optional recorded event for the enqueued operation", PARAM_OUT_OPTIONAL> ]; let returns = [ - Return<"OL_ERRC_INVALID_ARGUMENT", ["`Queue == NULL && EventOut != NULL`"]>, Return<"OL_ERRC_INVALID_ARGUMENT", ["`ArgumentsSize > 0 && ArgumentsData == NULL`"]>, Return<"OL_ERRC_INVALID_DEVICE", ["If Queue is non-null but does not belong to Device"]>, Return<"OL_ERRC_SYMBOL_KIND", ["The provided symbol is not a kernel"]>, diff --git a/offload/liboffload/API/Memory.td b/offload/liboffload/API/Memory.td index 029975c44829..5f7158588bc7 100644 --- a/offload/liboffload/API/Memory.td +++ b/offload/liboffload/API/Memory.td @@ -60,9 +60,6 @@ def : Function { Param<"const void*", "SrcPtr", "pointer to copy from", PARAM_IN>, Param<"ol_device_handle_t", "SrcDevice", "device that SrcPtr belongs to", PARAM_IN>, Param<"size_t", "Size", "size in bytes of data to copy", PARAM_IN>, - Param<"ol_event_handle_t*", "EventOut", "optional recorded event for the enqueued operation", PARAM_OUT_OPTIONAL> - ]; - let returns = [ - Return<"OL_ERRC_INVALID_ARGUMENT", ["`Queue == NULL && EventOut != NULL`"]> ]; + let returns = []; } diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp index 87f924168272..8f316b87fc47 100644 --- a/offload/liboffload/src/OffloadImpl.cpp +++ b/offload/liboffload/src/OffloadImpl.cpp @@ -591,26 +591,21 @@ Error olGetEventInfoSize_impl(ol_event_handle_t Event, ol_event_info_t PropName, return olGetEventInfoImplDetail(Event, PropName, 0, nullptr, PropSizeRet); } -ol_event_handle_t makeEvent(ol_queue_handle_t Queue) { - auto EventImpl = std::make_unique<ol_event_impl_t>(nullptr, Queue); - if (auto Res = Queue->Device->Device->createEvent(&EventImpl->EventInfo)) { - llvm::consumeError(std::move(Res)); - return nullptr; - } +Error olCreateEvent_impl(ol_queue_handle_t Queue, ol_event_handle_t *EventOut) { + *EventOut = new ol_event_impl_t(nullptr, Queue); + if (auto Res = Queue->Device->Device->createEvent(&(*EventOut)->EventInfo)) + return Res; - if (auto Res = Queue->Device->Device->recordEvent(EventImpl->EventInfo, - Queue->AsyncInfo)) { - llvm::consumeError(std::move(Res)); - return nullptr; - } + if (auto Res = Queue->Device->Device->recordEvent((*EventOut)->EventInfo, + Queue->AsyncInfo)) + return Res; - return EventImpl.release(); + return Plugin::success(); } Error olMemcpy_impl(ol_queue_handle_t Queue, void *DstPtr, ol_device_handle_t DstDevice, const void *SrcPtr, - ol_device_handle_t SrcDevice, size_t Size, - ol_event_handle_t *EventOut) { + ol_device_handle_t SrcDevice, size_t Size) { auto Host = OffloadContext::get().HostDevice(); if (DstDevice == Host && SrcDevice == Host) { if (!Queue) { @@ -641,9 +636,6 @@ Error olMemcpy_impl(ol_queue_handle_t Queue, void *DstPtr, return Res; } - if (EventOut) - *EventOut = makeEvent(Queue); - return Error::success(); } @@ -690,8 +682,7 @@ Error olDestroyProgram_impl(ol_program_handle_t Program) { Error olLaunchKernel_impl(ol_queue_handle_t Queue, ol_device_handle_t Device, ol_symbol_handle_t Kernel, const void *ArgumentsData, size_t ArgumentsSize, - const ol_kernel_launch_size_args_t *LaunchSizeArgs, - ol_event_handle_t *EventOut) { + const ol_kernel_launch_size_args_t *LaunchSizeArgs) { auto *DeviceImpl = Device->Device; if (Queue && Device != Queue->Device) { return createOffloadError( @@ -729,9 +720,6 @@ Error olLaunchKernel_impl(ol_queue_handle_t Queue, ol_device_handle_t Device, if (Err) return Err; - if (EventOut) - *EventOut = makeEvent(Queue); - return Error::success(); } |
