Skip to content

Commit a0b84e0

Browse files
committed
[L0] Enable Disabling of Queue lock during L0 Sync calls
Signed-off-by: Neil R. Spruit <[email protected]>
1 parent a0f3c51 commit a0b84e0

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

source/adapters/level_zero/common.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ static const uint32_t UrL0Serialize = [] {
231231
return SerializeModeValue;
232232
}();
233233

234+
static const uint32_t UrL0QueueSyncNonBlocking = [] {
235+
const char *UrL0QueueSyncNonBlocking =
236+
std::getenv("UR_L0_QUEUE_SYNCHRONIZE_NON_BLOCKING");
237+
uint32_t L0QueueSyncLockingModeValue = 1;
238+
if (UrL0QueueSyncNonBlocking) {
239+
L0QueueSyncLockingModeValue = std::atoi(UrL0QueueSyncNonBlocking);
240+
}
241+
return L0QueueSyncLockingModeValue;
242+
}();
243+
234244
// This class encapsulates actions taken along with a call to Level Zero API.
235245
class ZeCall {
236246
private:

source/adapters/level_zero/queue.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,13 @@ ur_result_t ur_queue_handle_t_::synchronize() {
14001400
return UR_RESULT_SUCCESS;
14011401

14021402
// wait for all commands previously submitted to this immediate command list
1403-
ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX));
1403+
if (UrL0QueueSyncNonBlocking) {
1404+
Queue->Mutex.unlock();
1405+
ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX));
1406+
Queue->Mutex.lock();
1407+
} else {
1408+
ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX));
1409+
}
14041410

14051411
// Cleanup all events from the synced command list.
14061412
CleanupEventListFromResetCmdList(ImmCmdList->second.EventList, true);
@@ -1414,7 +1420,13 @@ ur_result_t ur_queue_handle_t_::synchronize() {
14141420
// zero handle can have device scope, so we can't synchronize the last
14151421
// event.
14161422
if (isInOrderQueue() && !LastCommandEvent->IsDiscarded) {
1417-
ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent));
1423+
if (UrL0QueueSyncNonBlocking) {
1424+
this->Mutex.unlock();
1425+
ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent));
1426+
this->Mutex.lock();
1427+
} else {
1428+
ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent));
1429+
}
14181430

14191431
// clean up all events known to have been completed as well,
14201432
// so they can be reused later
@@ -1441,8 +1453,15 @@ ur_result_t ur_queue_handle_t_::synchronize() {
14411453
UR_CALL(syncImmCmdList(this, ImmCmdList));
14421454
} else {
14431455
for (auto &ZeQueue : QueueGroup.second.ZeQueues)
1444-
if (ZeQueue)
1445-
ZE2UR_CALL(zeHostSynchronize, (ZeQueue));
1456+
if (ZeQueue) {
1457+
if (UrL0QueueSyncNonBlocking) {
1458+
this->Mutex.unlock();
1459+
ZE2UR_CALL(zeHostSynchronize, (ZeQueue));
1460+
this->Mutex.lock();
1461+
} else {
1462+
ZE2UR_CALL(zeHostSynchronize, (ZeQueue));
1463+
}
1464+
}
14461465
}
14471466
}
14481467
}

0 commit comments

Comments
 (0)