@@ -1314,10 +1314,13 @@ ur_result_t urQueueReleaseInternal(ur_queue_handle_t Queue) {
1314
1314
for (auto &QueueGroup : QueueMap)
1315
1315
for (auto &ZeQueue : QueueGroup.second .ZeQueues )
1316
1316
if (ZeQueue) {
1317
- auto ZeResult = ZE_CALL_NOCHECK (zeCommandQueueDestroy, (ZeQueue));
1318
- // Gracefully handle the case that L0 was already unloaded.
1319
- if (ZeResult && ZeResult != ZE_RESULT_ERROR_UNINITIALIZED)
1320
- return ze2urResult (ZeResult);
1317
+ {
1318
+ std::scoped_lock<ur_shared_mutex> Lock (UrQueue->zeQueueInUseMutex );
1319
+ auto ZeResult = ZE_CALL_NOCHECK (zeCommandQueueDestroy, (ZeQueue));
1320
+ // Gracefully handle the case that L0 was already unloaded.
1321
+ if (ZeResult && ZeResult != ZE_RESULT_ERROR_UNINITIALIZED)
1322
+ return ze2urResult (ZeResult);
1323
+ }
1321
1324
}
1322
1325
}
1323
1326
@@ -1392,7 +1395,6 @@ ur_result_t CleanupEventListFromResetCmdList(
1392
1395
// runtime. Need to investigate whether relase can be done earlier, at sync
1393
1396
// points such as this, to reduce total number of active Events.
1394
1397
ur_result_t ur_queue_handle_t_::synchronize () {
1395
- // std::shared_lock<ur_shared_mutex> QueueLock(this->Mutex);
1396
1398
this ->Mutex .lock ();
1397
1399
if (!Healthy) {
1398
1400
this ->Mutex .unlock ();
@@ -1406,7 +1408,10 @@ ur_result_t ur_queue_handle_t_::synchronize() {
1406
1408
1407
1409
// wait for all commands previously submitted to this immediate command list
1408
1410
Queue->Mutex .unlock ();
1409
- ZE2UR_CALL (zeCommandListHostSynchronize, (ImmCmdList->first , UINT64_MAX));\
1411
+ {
1412
+ std::scoped_lock<ur_shared_mutex> Lock (Queue->zeQueueInUseMutex );
1413
+ ZE2UR_CALL (zeCommandListHostSynchronize, (ImmCmdList->first , UINT64_MAX));
1414
+ }
1410
1415
Queue->Mutex .lock ();
1411
1416
1412
1417
// Cleanup all events from the synced command list.
@@ -1421,7 +1426,12 @@ ur_result_t ur_queue_handle_t_::synchronize() {
1421
1426
// zero handle can have device scope, so we can't synchronize the last
1422
1427
// event.
1423
1428
if (isInOrderQueue () && !LastCommandEvent->IsDiscarded ) {
1424
- ZE2UR_CALL (zeHostSynchronize, (LastCommandEvent->ZeEvent ));
1429
+ this ->Mutex .unlock ();
1430
+ {
1431
+ std::scoped_lock<ur_shared_mutex> Lock (this ->zeQueueInUseMutex );
1432
+ ZE2UR_CALL (zeHostSynchronize, (LastCommandEvent->ZeEvent ));
1433
+ }
1434
+ this ->Mutex .lock ();
1425
1435
1426
1436
// clean up all events known to have been completed as well,
1427
1437
// so they can be reused later
@@ -1450,7 +1460,10 @@ ur_result_t ur_queue_handle_t_::synchronize() {
1450
1460
for (auto &ZeQueue : QueueGroup.second .ZeQueues )
1451
1461
if (ZeQueue) {
1452
1462
this ->Mutex .unlock ();
1453
- ZE2UR_CALL (zeHostSynchronize, (ZeQueue));
1463
+ {
1464
+ std::scoped_lock<ur_shared_mutex> Lock (this ->zeQueueInUseMutex );
1465
+ ZE2UR_CALL (zeHostSynchronize, (ZeQueue));
1466
+ }
1454
1467
this ->Mutex .lock ();
1455
1468
}
1456
1469
}
0 commit comments