@@ -3388,13 +3388,13 @@ pi_result piQueueFinish(pi_queue Queue) {
3388
3388
3389
3389
if (UseImmediateCommandLists) {
3390
3390
// Lock automatically releases when this goes out of scope.
3391
- std::scoped_lock lock (Queue->Mutex );
3391
+ std::scoped_lock Lock (Queue->Mutex );
3392
3392
3393
3393
Queue->synchronize ();
3394
3394
return PI_SUCCESS;
3395
3395
}
3396
3396
3397
- std::unique_lock lock (Queue->Mutex );
3397
+ std::unique_lock Lock (Queue->Mutex );
3398
3398
std::vector<ze_command_queue_handle_t > ZeQueues;
3399
3399
3400
3400
// execute any command list that may still be open.
@@ -3407,6 +3407,9 @@ pi_result piQueueFinish(pi_queue Queue) {
3407
3407
Queue->ComputeQueueGroup .ZeQueues .end (),
3408
3408
std::back_inserter (ZeQueues));
3409
3409
3410
+ // Remember the last command's event.
3411
+ auto LastCommandEvent = Queue->LastCommandEvent ;
3412
+
3410
3413
// Don't hold a lock to the queue's mutex while waiting.
3411
3414
// This allows continue working with the queue from other threads.
3412
3415
// TODO: this currently exhibits some issues in the driver, so
@@ -3415,13 +3418,25 @@ pi_result piQueueFinish(pi_queue Queue) {
3415
3418
static bool HoldLock =
3416
3419
std::getenv (" SYCL_PI_LEVEL_ZERO_QUEUE_FINISH_HOLD_LOCK" ) != nullptr ;
3417
3420
if (!HoldLock) {
3418
- lock .unlock ();
3421
+ Lock .unlock ();
3419
3422
}
3420
3423
3421
3424
for (auto ZeQueue : ZeQueues) {
3422
3425
if (ZeQueue)
3423
3426
ZE_CALL (zeHostSynchronize, (ZeQueue));
3424
3427
}
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
+ }
3425
3440
return PI_SUCCESS;
3426
3441
}
3427
3442
0 commit comments