Skip to content

Commit de6f1be

Browse files
authored
[SYCL][L0] Optimize mutex acquisition. (#10595)
CleanupEventListFromResetCmdList sets the event as completed under mutex. Then releases the mutex and calls CleanupCompletedEvent. In this method the same mutex is taken again. This causes that we take the same mutex twice for every event in CleanupEventListFromResetCmdList. This change adds paramter to CleanupCompletedEvent and moves the code from CleanupEventListFromResetCmdList to CleanupCompletedEvent, which avoids taking the same mutex twice. Signed-off-by: mmrozek <[email protected]> Signed-off-by: mmrozek <[email protected]>
1 parent 0717c40 commit de6f1be

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

sycl/plugins/unified_runtime/ur/adapters/level_zero/event.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -817,13 +817,16 @@ template <> ze_result_t zeHostSynchronize(ze_command_queue_handle_t Handle) {
817817
// the event, updates the last command event in the queue and cleans up all dep
818818
// events of the event.
819819
// If the caller locks queue mutex then it must pass 'true' to QueueLocked.
820-
ur_result_t CleanupCompletedEvent(ur_event_handle_t Event, bool QueueLocked) {
820+
ur_result_t CleanupCompletedEvent(ur_event_handle_t Event, bool QueueLocked,
821+
bool SetEventCompleted) {
821822
ur_kernel_handle_t AssociatedKernel = nullptr;
822823
// List of dependent events.
823824
std::list<ur_event_handle_t> EventsToBeReleased;
824825
ur_queue_handle_t AssociatedQueue = nullptr;
825826
{
826827
std::scoped_lock<ur_shared_mutex> EventLock(Event->Mutex);
828+
if (SetEventCompleted)
829+
Event->Completed = true;
827830
// Exit early of event was already cleanedup.
828831
if (Event->CleanedUp)
829832
return UR_RESULT_SUCCESS;

sycl/plugins/unified_runtime/ur/adapters/level_zero/event.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ template <> ze_result_t zeHostSynchronize(ze_command_queue_handle_t Handle);
237237
// events of the event.
238238
// If the caller locks queue mutex then it must pass 'true' to QueueLocked.
239239
ur_result_t CleanupCompletedEvent(ur_event_handle_t Event,
240-
bool QueueLocked = false);
240+
bool QueueLocked = false,
241+
bool SetEventCompleted = false);
241242

242243
// Get value of device scope events env var setting or default setting
243244
static const EventsScope DeviceEventsSetting = [] {

sycl/plugins/unified_runtime/ur/adapters/level_zero/queue.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -1352,11 +1352,7 @@ ur_result_t CleanupEventListFromResetCmdList(
13521352
for (auto &Event : EventListToCleanup) {
13531353
// We don't need to synchronize the events since the fence associated with
13541354
// the command list was synchronized.
1355-
{
1356-
std::scoped_lock<ur_shared_mutex> EventLock(Event->Mutex);
1357-
Event->Completed = true;
1358-
}
1359-
UR_CALL(CleanupCompletedEvent(Event, QueueLocked));
1355+
UR_CALL(CleanupCompletedEvent(Event, QueueLocked, true));
13601356
// This event was removed from the command list, so decrement ref count
13611357
// (it was incremented when they were added to the command list).
13621358
UR_CALL(urEventReleaseInternal(Event));

0 commit comments

Comments
 (0)