Skip to content

[SYCL] Fix crash and deadlock in level0 plugin when using multiple threads #2550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ _pi_device::getAvailableCommandList(pi_queue Queue,
// Initally, we need to check if a command list has already been created
// on this device that is available for use. If so, then reuse that
// Level-Zero Command List and Fence for this PI call.
Queue->ZeCommandListFenceMapMutex.lock();
Queue->Device->ZeCommandListCacheMutex.lock();
if (Queue->Device->ZeCommandListCache.size() > 0) {
Queue->Device->ZeCommandListCacheMutex.lock();
*ZeCommandList = Queue->Device->ZeCommandListCache.front();
Queue->ZeCommandListFenceMapMutex.lock();
*ZeFence = Queue->ZeCommandListFenceMap[*ZeCommandList];
if (*ZeFence == nullptr) {
// If there is a command list available on this device, but no fence yet
Expand All @@ -452,11 +452,13 @@ _pi_device::getAvailableCommandList(pi_queue Queue,
ZE_CALL(zeFenceCreate(Queue->ZeCommandQueue, &ZeFenceDesc, ZeFence));
Queue->ZeCommandListFenceMap[*ZeCommandList] = *ZeFence;
}
Queue->ZeCommandListFenceMapMutex.unlock();
Queue->Device->ZeCommandListCache.pop_front();
Queue->Device->ZeCommandListCacheMutex.unlock();
Queue->ZeCommandListFenceMapMutex.unlock();
return PI_SUCCESS;
}
Queue->Device->ZeCommandListCacheMutex.unlock();
Queue->ZeCommandListFenceMapMutex.unlock();

// If there are no available command lists in the cache, then we check for
// command lists that have already signalled, but have not been added to the
Expand Down Expand Up @@ -3062,12 +3064,12 @@ pi_result piEventsWait(pi_uint32 NumEvents, const pi_event *EventList) {

// NOTE: we are destroying associated command lists here to free
// resources sooner in case RT is not calling piEventRelease soon enough.
if (EventList[I]->ZeCommandList) {
// Event has been signaled: If the fence for the associated command list
// is signalled, then reset the fence and command list and add them to the
// available list for reuse in PI calls.
if (EventList[I]->Queue->RefCount > 0) {
EventList[I]->Queue->ZeCommandListFenceMapMutex.lock();
// Event has been signaled: If the fence for the associated command list
// is signalled, then reset the fence and command list and add them to the
// available list for reuse in PI calls.
if (EventList[I]->Queue->RefCount > 0) {
EventList[I]->Queue->ZeCommandListFenceMapMutex.lock();
if (EventList[I]->ZeCommandList) {
ze_result_t ZeResult = ZE_CALL_NOCHECK(zeFenceQueryStatus(
EventList[I]
->Queue->ZeCommandListFenceMap[EventList[I]->ZeCommandList]));
Expand All @@ -3076,8 +3078,8 @@ pi_result piEventsWait(pi_uint32 NumEvents, const pi_event *EventList) {
EventList[I]->ZeCommandList, true);
EventList[I]->ZeCommandList = nullptr;
}
EventList[I]->Queue->ZeCommandListFenceMapMutex.unlock();
}
EventList[I]->Queue->ZeCommandListFenceMapMutex.unlock();
}
}
return PI_SUCCESS;
Expand Down