diff --git a/unified-runtime/source/adapters/level_zero/v2/command_buffer.cpp b/unified-runtime/source/adapters/level_zero/v2/command_buffer.cpp index e5713074a096a..cc2a88fb409e5 100644 --- a/unified-runtime/source/adapters/level_zero/v2/command_buffer.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/command_buffer.cpp @@ -84,6 +84,7 @@ ur_exp_command_buffer_handle_t_::getSyncPoint(ur_event_handle_t event) { throw UR_RESULT_ERROR_OUT_OF_RESOURCES; } syncPoints.push_back(event); + usedSyncPoints.push_back(false); return static_cast(syncPoints.size() - 1); } @@ -99,6 +100,7 @@ ur_event_handle_t *ur_exp_command_buffer_handle_t_::getWaitListFromSyncPoints( UR_LOG(ERR, "Invalid sync point"); throw UR_RESULT_ERROR_INVALID_VALUE; } + usedSyncPoints[pSyncPointWaitList[i]] = true; syncPointWaitList[i] = syncPoints[pSyncPointWaitList[i]]; } return syncPointWaitList.data(); @@ -132,9 +134,13 @@ ur_result_t ur_exp_command_buffer_handle_t_::finalizeCommandBuffer() { if (!isInOrder) { ZE2UR_CALL(zeCommandListAppendBarrier, (commandListLocked->getZeCommandList(), nullptr, 0, nullptr)); - for (auto &event : syncPoints) { - ZE2UR_CALL(zeCommandListAppendEventReset, - (commandListLocked->getZeCommandList(), event->getZeEvent())); + for (size_t i = 0; i < usedSyncPoints.size(); ++i) { + if (!usedSyncPoints[i]) { + continue; + } + ZE2UR_CALL( + zeCommandListAppendEventReset, + (commandListLocked->getZeCommandList(), syncPoints[i]->getZeEvent())); } ZE2UR_CALL(zeCommandListAppendBarrier, (commandListLocked->getZeCommandList(), nullptr, 0, nullptr)); diff --git a/unified-runtime/source/adapters/level_zero/v2/command_buffer.hpp b/unified-runtime/source/adapters/level_zero/v2/command_buffer.hpp index 697a214bbaca6..109ec09ce24fd 100644 --- a/unified-runtime/source/adapters/level_zero/v2/command_buffer.hpp +++ b/unified-runtime/source/adapters/level_zero/v2/command_buffer.hpp @@ -66,6 +66,9 @@ struct ur_exp_command_buffer_handle_t_ : public ur_object { // Stores all sync points that are created by the command buffer. std::vector syncPoints; + // Stores all sync points that should be reset after execution. + std::vector usedSyncPoints; + // Temporary storage for sync points that are passed to function that require // array of events. This is used to avoid allocating a new memory every time. std::vector syncPointWaitList;