Skip to content

Commit 013f743

Browse files
smaslov-intelYang,Yin
authored andcommitted
[SYCL][L0] Optimize the LastCommandEvent of the synchronized queue (intel#6159)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 17f7864 commit 013f743

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,13 +3388,13 @@ pi_result piQueueFinish(pi_queue Queue) {
33883388

33893389
if (UseImmediateCommandLists) {
33903390
// Lock automatically releases when this goes out of scope.
3391-
std::scoped_lock lock(Queue->Mutex);
3391+
std::scoped_lock Lock(Queue->Mutex);
33923392

33933393
Queue->synchronize();
33943394
return PI_SUCCESS;
33953395
}
33963396

3397-
std::unique_lock lock(Queue->Mutex);
3397+
std::unique_lock Lock(Queue->Mutex);
33983398
std::vector<ze_command_queue_handle_t> ZeQueues;
33993399

34003400
// execute any command list that may still be open.
@@ -3407,6 +3407,9 @@ pi_result piQueueFinish(pi_queue Queue) {
34073407
Queue->ComputeQueueGroup.ZeQueues.end(),
34083408
std::back_inserter(ZeQueues));
34093409

3410+
// Remember the last command's event.
3411+
auto LastCommandEvent = Queue->LastCommandEvent;
3412+
34103413
// Don't hold a lock to the queue's mutex while waiting.
34113414
// This allows continue working with the queue from other threads.
34123415
// TODO: this currently exhibits some issues in the driver, so
@@ -3415,13 +3418,25 @@ pi_result piQueueFinish(pi_queue Queue) {
34153418
static bool HoldLock =
34163419
std::getenv("SYCL_PI_LEVEL_ZERO_QUEUE_FINISH_HOLD_LOCK") != nullptr;
34173420
if (!HoldLock) {
3418-
lock.unlock();
3421+
Lock.unlock();
34193422
}
34203423

34213424
for (auto ZeQueue : ZeQueues) {
34223425
if (ZeQueue)
34233426
ZE_CALL(zeHostSynchronize, (ZeQueue));
34243427
}
3428+
3429+
// Prevent unneeded already finished events to show up in the wait list.
3430+
// We can only do so if nothing else was submitted to the queue
3431+
// while we were synchronizing it.
3432+
if (!HoldLock) {
3433+
std::scoped_lock Lock(Queue->Mutex);
3434+
if (LastCommandEvent == Queue->LastCommandEvent) {
3435+
Queue->LastCommandEvent = nullptr;
3436+
}
3437+
} else {
3438+
Queue->LastCommandEvent = nullptr;
3439+
}
34253440
return PI_SUCCESS;
34263441
}
34273442

0 commit comments

Comments
 (0)