Skip to content

Commit 0540c1d

Browse files
committed
[L0]: Fix Out Event in Enqueue Wait Events to prevent reuse
- 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 <neil.r.spruit@intel.com>
1 parent a3d36c1 commit 0540c1d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

source/adapters/level_zero/event.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ ur_result_t urEnqueueEventsWait(
147147
}
148148
if (OutEvent && (*OutEvent)->Completed) {
149149
UR_CALL(CleanupCompletedEvent((*OutEvent), false, false));
150+
// This event cannot be cached and cannot be deleted until the user is done
151+
// with the event handle.
152+
(*OutEvent)->CannotCache = true;
150153
UR_CALL(urEventReleaseInternal((*OutEvent)));
151154
}
152155

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

800803
ze_event_handle_t ZeHostVisibleEvent;
801804
if (auto Res = Event->getOrCreateHostVisibleEvent(ZeHostVisibleEvent))
@@ -1137,7 +1140,8 @@ ur_result_t urEventReleaseInternal(ur_event_handle_t Event) {
11371140
if (DisableEventsCaching || !Event->OwnNativeHandle) {
11381141
delete Event;
11391142
} else {
1140-
Event->Context->addEventToContextCache(Event);
1143+
if (!Event->CannotCache)
1144+
Event->Context->addEventToContextCache(Event);
11411145
}
11421146

11431147
// We intentionally incremented the reference counter when an event is

source/adapters/level_zero/event.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ struct ur_event_handle_t_ : _ur_object {
256256
bool CounterBasedEventsEnabled = false;
257257
// Keeps track of whether we are using Interrupt-based Events.
258258
bool InterruptBasedEventsEnabled = false;
259+
// Indicates if this event can be cached or if the event needs to exist until
260+
// the handle is released.
261+
bool CannotCache = false;
259262
};
260263

261264
// Helper function to implement zeHostSynchronize.

0 commit comments

Comments
 (0)