Skip to content

Commit d673f03

Browse files
[SYCL][L0] Add control to hold mutex lock while queue is synchronizing (#6075)
Signed-off-by: Sergey V Maslov <sergey.v.maslov@intel.com>
1 parent 80e9148 commit d673f03

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

100755100644
Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,24 +3375,30 @@ pi_result piQueueFinish(pi_queue Queue) {
33753375
return PI_SUCCESS;
33763376
}
33773377

3378+
std::unique_lock lock(Queue->Mutex);
33783379
std::vector<ze_command_queue_handle_t> ZeQueues;
3379-
{
3380-
// Lock automatically releases when this goes out of scope.
3381-
std::scoped_lock lock(Queue->Mutex);
33823380

3383-
// execute any command list that may still be open.
3384-
if (auto Res = Queue->executeAllOpenCommandLists())
3385-
return Res;
3381+
// execute any command list that may still be open.
3382+
if (auto Res = Queue->executeAllOpenCommandLists())
3383+
return Res;
33863384

3387-
// Make a copy of queues to sync and release the lock.
3388-
ZeQueues = Queue->CopyQueueGroup.ZeQueues;
3389-
std::copy(Queue->ComputeQueueGroup.ZeQueues.begin(),
3390-
Queue->ComputeQueueGroup.ZeQueues.end(),
3391-
std::back_inserter(ZeQueues));
3392-
}
3385+
// Make a copy of queues to sync and release the lock.
3386+
ZeQueues = Queue->CopyQueueGroup.ZeQueues;
3387+
std::copy(Queue->ComputeQueueGroup.ZeQueues.begin(),
3388+
Queue->ComputeQueueGroup.ZeQueues.end(),
3389+
std::back_inserter(ZeQueues));
33933390

33943391
// Don't hold a lock to the queue's mutex while waiting.
33953392
// This allows continue working with the queue from other threads.
3393+
// TODO: this currently exhibits some issues in the driver, so
3394+
// we control this with an env var. Remove this control when
3395+
// we settle one way or the other.
3396+
static bool HoldLock =
3397+
std::getenv("SYCL_PI_LEVEL_ZERO_QUEUE_FINISH_HOLD_LOCK") != nullptr;
3398+
if (!HoldLock) {
3399+
lock.unlock();
3400+
}
3401+
33963402
for (auto ZeQueue : ZeQueues) {
33973403
if (ZeQueue)
33983404
ZE_CALL(zeHostSynchronize, (ZeQueue));

0 commit comments

Comments
 (0)