Skip to content

Commit 8573935

Browse files
[SYCL] Relax the mutex lock duration during piQueueFinish (#5406)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent aacf541 commit 8573935

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,19 +3227,28 @@ pi_result piQueueFinish(pi_queue Queue) {
32273227
// Wait until command lists attached to the command queue are executed.
32283228
PI_ASSERT(Queue, PI_INVALID_QUEUE);
32293229

3230-
// Lock automatically releases when this goes out of scope.
3231-
std::lock_guard<std::mutex> lock(Queue->PiQueueMutex);
3230+
std::vector<ze_command_queue_handle_t> ZeQueues;
3231+
{
3232+
// Lock automatically releases when this goes out of scope.
3233+
std::lock_guard<std::mutex> lock(Queue->PiQueueMutex);
32323234

3233-
// execute any command list that may still be open.
3234-
if (auto Res = Queue->executeAllOpenCommandLists())
3235-
return Res;
3235+
// execute any command list that may still be open.
3236+
if (auto Res = Queue->executeAllOpenCommandLists())
3237+
return Res;
32363238

3237-
ZE_CALL(zeHostSynchronize, (Queue->ZeComputeCommandQueue));
3238-
for (uint32_t i = 0; i < Queue->ZeCopyCommandQueues.size(); ++i) {
3239-
if (Queue->ZeCopyCommandQueues[i])
3240-
ZE_CALL(zeHostSynchronize, (Queue->ZeCopyCommandQueues[i]));
3239+
ZeQueues = Queue->ZeCopyCommandQueues;
3240+
ZeQueues.push_back(Queue->ZeComputeCommandQueue);
32413241
}
32423242

3243+
// Don't hold a lock to the queue's mutex while waiting.
3244+
// This allows continue working with the queue from other threads.
3245+
for (auto ZeQueue : ZeQueues) {
3246+
if (ZeQueue)
3247+
ZE_CALL(zeHostSynchronize, (ZeQueue));
3248+
}
3249+
3250+
// Lock automatically releases when this goes out of scope.
3251+
std::lock_guard<std::mutex> lock(Queue->PiQueueMutex);
32433252
// Prevent unneeded already finished events to show up in the wait list.
32443253
Queue->LastCommandEvent = nullptr;
32453254

0 commit comments

Comments
 (0)