Skip to content

Commit

Permalink
Merge pull request #1492 from nrspruit/l0_queue_sync_unblocking
Browse files Browse the repository at this point in the history
[L0] Enable Disabling of Queue lock during L0 Sync calls
  • Loading branch information
aarongreig committed Apr 15, 2024
2 parents 1333d4a + a0b84e0 commit 4177e93
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
10 changes: 10 additions & 0 deletions source/adapters/level_zero/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ static const uint32_t UrL0Serialize = [] {
return SerializeModeValue;
}();

static const uint32_t UrL0QueueSyncNonBlocking = [] {
const char *UrL0QueueSyncNonBlocking =
std::getenv("UR_L0_QUEUE_SYNCHRONIZE_NON_BLOCKING");
uint32_t L0QueueSyncLockingModeValue = 1;
if (UrL0QueueSyncNonBlocking) {
L0QueueSyncLockingModeValue = std::atoi(UrL0QueueSyncNonBlocking);
}
return L0QueueSyncLockingModeValue;
}();

// This class encapsulates actions taken along with a call to Level Zero API.
class ZeCall {
private:
Expand Down
27 changes: 23 additions & 4 deletions source/adapters/level_zero/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,13 @@ ur_result_t ur_queue_handle_t_::synchronize() {
return UR_RESULT_SUCCESS;

// wait for all commands previously submitted to this immediate command list
ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX));
if (UrL0QueueSyncNonBlocking) {
Queue->Mutex.unlock();
ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX));
Queue->Mutex.lock();
} else {
ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX));
}

// Cleanup all events from the synced command list.
CleanupEventListFromResetCmdList(ImmCmdList->second.EventList, true);
Expand All @@ -1417,7 +1423,13 @@ ur_result_t ur_queue_handle_t_::synchronize() {
// zero handle can have device scope, so we can't synchronize the last
// event.
if (isInOrderQueue() && !LastCommandEvent->IsDiscarded) {
ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent));
if (UrL0QueueSyncNonBlocking) {
this->Mutex.unlock();
ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent));
this->Mutex.lock();
} else {
ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent));
}

// clean up all events known to have been completed as well,
// so they can be reused later
Expand All @@ -1444,8 +1456,15 @@ ur_result_t ur_queue_handle_t_::synchronize() {
UR_CALL(syncImmCmdList(this, ImmCmdList));
} else {
for (auto &ZeQueue : QueueGroup.second.ZeQueues)
if (ZeQueue)
ZE2UR_CALL(zeHostSynchronize, (ZeQueue));
if (ZeQueue) {
if (UrL0QueueSyncNonBlocking) {
this->Mutex.unlock();
ZE2UR_CALL(zeHostSynchronize, (ZeQueue));
this->Mutex.lock();
} else {
ZE2UR_CALL(zeHostSynchronize, (ZeQueue));
}
}
}
}
}
Expand Down

0 comments on commit 4177e93

Please sign in to comment.