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