From a3e93e07316fe6c00b7835ea4da6ef9f97578e2f Mon Sep 17 00:00:00 2001 From: rdeodhar Date: Tue, 15 Nov 2022 23:32:50 +0530 Subject: [PATCH] [SYCL] [L0] With immediate commandlists recycle events after they have signalled (#7368) This change checks if an event has signalled completion before it is reset and reused. --- sycl/plugins/level_zero/pi_level_zero.cpp | 24 ++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 9ac8bcc6eabfd..252e437497b45 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -1022,11 +1022,25 @@ _pi_queue::resetCommandList(pi_command_list_ptr_t CommandList, } auto &EventList = CommandList->second.EventList; - // Remember all the events in this command list which needs to be - // released/cleaned up and clear event list associated with command list. - std::move(std::begin(EventList), std::end(EventList), - std::back_inserter(EventListToCleanup)); - EventList.clear(); + // Check if standard commandlist + if (CommandList->second.ZeFence != nullptr) { + // Remember all the events in this command list which needs to be + // released/cleaned up and clear event list associated with command list. + std::move(std::begin(EventList), std::end(EventList), + std::back_inserter(EventListToCleanup)); + EventList.clear(); + } else { + // For immediate commandlist reset only those events that have signalled. + for (auto it = EventList.begin(); it != EventList.end(); it++) { + std::scoped_lock EventLock((*it)->Mutex); + ze_result_t ZeResult = + ZE_CALL_NOCHECK(zeEventQueryStatus, ((*it)->ZeEvent)); + if (ZeResult == ZE_RESULT_SUCCESS) { + std::move(it, it, std::back_inserter(EventListToCleanup)); + EventList.erase(it, it); + } + } + } // Standard commandlists move in and out of the cache as they are recycled. // Immediate commandlists are always available.