diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 3b0e82c55a5f2..118b3687e3ee7 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -7319,6 +7319,11 @@ pi_result piextUSMEnqueuePrefetch(pi_queue Queue, const void *Ptr, size_t Size, // Lock automatically releases when this goes out of scope. std::lock_guard lock(Queue->PiQueueMutex); + /** + * @brief Please note that the following code should be run before the + * subsequent getAvailableCommandList() call so that there is no + * dead-lock from waiting unsubmitted events in an open batch. + */ _pi_ze_event_list_t TmpWaitList; if (auto Res = TmpWaitList.createAndRetainPiZeEventList(NumEventsInWaitList, EventWaitList, Queue)) @@ -7339,10 +7344,7 @@ pi_result piextUSMEnqueuePrefetch(pi_queue Queue, const void *Ptr, size_t Size, if (Res != PI_SUCCESS) return Res; ZeEvent = (*Event)->ZeEvent; - - if (auto Res = (*Event)->WaitList.createAndRetainPiZeEventList( - NumEventsInWaitList, EventWaitList, Queue)) - return Res; + (*Event)->WaitList = TmpWaitList; const auto &WaitList = (*Event)->WaitList; const auto &ZeCommandList = CommandList->first;