Skip to content

[SYCL] Relax the mutex lock duration during piQueueFinish #5406

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

Merged
merged 1 commit into from
Jan 28, 2022
Merged
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
27 changes: 18 additions & 9 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3155,19 +3155,28 @@ pi_result piQueueFinish(pi_queue Queue) {
// Wait until command lists attached to the command queue are executed.
PI_ASSERT(Queue, PI_INVALID_QUEUE);

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

// execute any command list that may still be open.
if (auto Res = Queue->executeAllOpenCommandLists())
return Res;
// execute any command list that may still be open.
if (auto Res = Queue->executeAllOpenCommandLists())
return Res;

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

// Don't hold a lock to the queue's mutex while waiting.
// This allows continue working with the queue from other threads.
for (auto ZeQueue : ZeQueues) {
if (ZeQueue)
ZE_CALL(zeHostSynchronize, (ZeQueue));
}

// Lock automatically releases when this goes out of scope.
std::lock_guard<std::mutex> lock(Queue->PiQueueMutex);
// Prevent unneeded already finished events to show up in the wait list.
Queue->LastCommandEvent = nullptr;

Expand Down