Skip to content

Commit 7c3419c

Browse files
aarongreigkbenzie
authored andcommitted
Merge pull request oneapi-src#1492 from nrspruit/l0_queue_sync_unblocking
[L0] Enable Disabling of Queue lock during L0 Sync calls
1 parent 1d73739 commit 7c3419c

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
@@ -1403,7 +1403,13 @@ ur_result_t ur_queue_handle_t_::synchronize() {
14031403
return UR_RESULT_SUCCESS;
14041404

14051405
// wait for all commands previously submitted to this immediate command list
1406-
ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX));
1406+
if (UrL0QueueSyncNonBlocking) {
1407+
Queue->Mutex.unlock();
1408+
ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX));
1409+
Queue->Mutex.lock();
1410+
} else {
1411+
ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX));
1412+
}
14071413

14081414
// Cleanup all events from the synced command list.
14091415
CleanupEventListFromResetCmdList(ImmCmdList->second.EventList, true);
@@ -1417,7 +1423,13 @@ ur_result_t ur_queue_handle_t_::synchronize() {
14171423
// zero handle can have device scope, so we can't synchronize the last
14181424
// event.
14191425
if (isInOrderQueue() && !LastCommandEvent->IsDiscarded) {
1420-
ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent));
1426+
if (UrL0QueueSyncNonBlocking) {
1427+
this->Mutex.unlock();
1428+
ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent));
1429+
this->Mutex.lock();
1430+
} else {
1431+
ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent));
1432+
}
14211433

14221434
// clean up all events known to have been completed as well,
14231435
// so they can be reused later
@@ -1444,8 +1456,15 @@ ur_result_t ur_queue_handle_t_::synchronize() {
14441456
UR_CALL(syncImmCmdList(this, ImmCmdList));
14451457
} else {
14461458
for (auto &ZeQueue : QueueGroup.second.ZeQueues)
1447-
if (ZeQueue)
1448-
ZE2UR_CALL(zeHostSynchronize, (ZeQueue));
1459+
if (ZeQueue) {
1460+
if (UrL0QueueSyncNonBlocking) {
1461+
this->Mutex.unlock();
1462+
ZE2UR_CALL(zeHostSynchronize, (ZeQueue));
1463+
this->Mutex.lock();
1464+
} else {
1465+
ZE2UR_CALL(zeHostSynchronize, (ZeQueue));
1466+
}
1467+
}
14491468
}
14501469
}
14511470
}

0 commit comments

Comments
 (0)