Skip to content

Commit c149951

Browse files
committed
[L0] Fix recursive lock with host visible events during wait
Signed-off-by: Neil R. Spruit <[email protected]>
1 parent cd3e6ec commit c149951

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

source/adapters/level_zero/event.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent(
600600
this->Mutex);
601601

602602
if (!HostVisibleEvent) {
603+
this->IsCreatingHostProxyEvent = true;
603604
if (UrQueue->ZeEventsScope != OnDemandHostVisibleProxy)
604605
die("getOrCreateHostVisibleEvent: missing host-visible event");
605606

@@ -628,6 +629,7 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent(
628629
(CommandList->first, HostVisibleEvent->ZeEvent));
629630

630631
UR_CALL(UrQueue->executeCommandList(CommandList, false, OkToBatch))
632+
this->IsCreatingHostProxyEvent = false;
631633
}
632634

633635
ZeHostVisibleEvent = HostVisibleEvent->ZeEvent;
@@ -938,7 +940,12 @@ ur_result_t CleanupCompletedEvent(ur_event_handle_t Event, bool QueueLocked,
938940
std::list<ur_event_handle_t> EventsToBeReleased;
939941
ur_queue_handle_t AssociatedQueue = nullptr;
940942
{
941-
std::scoped_lock<ur_shared_mutex> EventLock(Event->Mutex);
943+
// If the Event is already locked, then continue with the cleanup, otherwise
944+
// block on locking the event.
945+
std::unique_lock<ur_shared_mutex> EventLock(Event->Mutex, std::try_to_lock);
946+
if (!EventLock.owns_lock() && !Event->IsCreatingHostProxyEvent) {
947+
EventLock.lock();
948+
}
942949
if (SetEventCompleted)
943950
Event->Completed = true;
944951
// Exit early of event was already cleanedup.

source/adapters/level_zero/event.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,12 @@ struct ur_event_handle_t_ : _ur_object {
196196
// performance
197197
bool IsMultiDevice = {false};
198198

199+
// Indicates inner batched event which was not used as a signal event.
199200
bool IsInnerBatchedEvent = {false};
200201

202+
// Indicates within creation of proxy event.
203+
bool IsCreatingHostProxyEvent = {false};
204+
201205
// Besides each PI object keeping a total reference count in
202206
// _ur_object::RefCount we keep special track of the event *external*
203207
// references. This way we are able to tell when the event is not referenced

0 commit comments

Comments
 (0)