Skip to content

Commit

Permalink
[L0]: Fix Out Event in Enqueue Wait Events to prevent reuse
Browse files Browse the repository at this point in the history
- Fix Out Event created in Enqueue Wait Events to ensure the event is
  not reused and is kept linked to the enqueue wait events even after
being completed.

Signed-off-by: Neil R. Spruit <[email protected]>
  • Loading branch information
nrspruit committed Jan 6, 2025
1 parent a3d36c1 commit 0540c1d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ ur_result_t urEnqueueEventsWait(
}
if (OutEvent && (*OutEvent)->Completed) {
UR_CALL(CleanupCompletedEvent((*OutEvent), false, false));
// This event cannot be cached and cannot be deleted until the user is done
// with the event handle.
(*OutEvent)->CannotCache = true;
UR_CALL(urEventReleaseInternal((*OutEvent)));
}

Expand Down Expand Up @@ -795,7 +798,7 @@ urEventWait(uint32_t NumEvents, ///< [in] number of events in the event list
//
ur_event_handle_t_ *Event = ur_cast<ur_event_handle_t_ *>(e);
if (!Event->hasExternalRefs())
die("urEventsWait must not be called for an internal event");
die("urEventWait must not be called for an internal event");

ze_event_handle_t ZeHostVisibleEvent;
if (auto Res = Event->getOrCreateHostVisibleEvent(ZeHostVisibleEvent))
Expand Down Expand Up @@ -1137,7 +1140,8 @@ ur_result_t urEventReleaseInternal(ur_event_handle_t Event) {
if (DisableEventsCaching || !Event->OwnNativeHandle) {
delete Event;
} else {
Event->Context->addEventToContextCache(Event);
if (!Event->CannotCache)
Event->Context->addEventToContextCache(Event);
}

// We intentionally incremented the reference counter when an event is
Expand Down
3 changes: 3 additions & 0 deletions source/adapters/level_zero/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ struct ur_event_handle_t_ : _ur_object {
bool CounterBasedEventsEnabled = false;
// Keeps track of whether we are using Interrupt-based Events.
bool InterruptBasedEventsEnabled = false;
// Indicates if this event can be cached or if the event needs to exist until
// the handle is released.
bool CannotCache = false;
};

// Helper function to implement zeHostSynchronize.
Expand Down

0 comments on commit 0540c1d

Please sign in to comment.