Skip to content

Commit 93081e1

Browse files
authored
[SYCL][L0]: Check Queue refcnt prior to using members in event wait/release (#2471)
- If the Queue was cleared of L0 data structures ie Refcnt == 0 then all L0 data structures in the pi_queue can no longer be used. - Prevent EventWait and EventRelease from using invalid data structures if the Queue has already been cleared. Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com>
1 parent 3833943 commit 93081e1

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,16 +3018,18 @@ pi_result piEventsWait(pi_uint32 NumEvents, const pi_event *EventList) {
30183018
// Event has been signaled: If the fence for the associated command list
30193019
// is signalled, then reset the fence and command list and add them to the
30203020
// available list for reuse in PI calls.
3021-
EventList[I]->Queue->ZeCommandListFenceMapMutex.lock();
3022-
ze_result_t ZeResult = ZE_CALL_NOCHECK(zeFenceQueryStatus(
3023-
EventList[I]
3024-
->Queue->ZeCommandListFenceMap[EventList[I]->ZeCommandList]));
3025-
if (ZeResult == ZE_RESULT_SUCCESS) {
3026-
EventList[I]->Queue->resetCommandListFenceEntry(
3027-
EventList[I]->ZeCommandList, true);
3028-
EventList[I]->ZeCommandList = nullptr;
3021+
if (EventList[I]->Queue->RefCount > 0) {
3022+
EventList[I]->Queue->ZeCommandListFenceMapMutex.lock();
3023+
ze_result_t ZeResult = ZE_CALL_NOCHECK(zeFenceQueryStatus(
3024+
EventList[I]
3025+
->Queue->ZeCommandListFenceMap[EventList[I]->ZeCommandList]));
3026+
if (ZeResult == ZE_RESULT_SUCCESS) {
3027+
EventList[I]->Queue->resetCommandListFenceEntry(
3028+
EventList[I]->ZeCommandList, true);
3029+
EventList[I]->ZeCommandList = nullptr;
3030+
}
3031+
EventList[I]->Queue->ZeCommandListFenceMapMutex.unlock();
30293032
}
3030-
EventList[I]->Queue->ZeCommandListFenceMapMutex.unlock();
30313033
}
30323034
}
30333035
return PI_SUCCESS;
@@ -3059,7 +3061,7 @@ pi_result piEventRelease(pi_event Event) {
30593061
// If the fence associated with this command list has signalled, then
30603062
// Reset the Command List Used in this event and put it back on the
30613063
// available list.
3062-
if (Event->Queue->ZeCommandQueue) {
3064+
if (Event->Queue->RefCount > 0) {
30633065
Event->Queue->ZeCommandListFenceMapMutex.lock();
30643066
ze_result_t ZeResult = ZE_CALL_NOCHECK(zeFenceQueryStatus(
30653067
Event->Queue->ZeCommandListFenceMap[Event->ZeCommandList]));

0 commit comments

Comments
 (0)