@@ -1753,6 +1753,8 @@ ur_result_t urCommandBufferEnqueueExp(
17531753 EventWaitList, OutEvent, ZeCommandListHelper,
17541754 DoProfiling));
17551755 }
1756+ // Mark that synchronization will be required for later updates
1757+ CommandBuffer->NeedsUpdateSynchronization = true ;
17561758
17571759 return UR_RESULT_SUCCESS;
17581760}
@@ -2117,6 +2119,13 @@ ur_result_t updateKernelCommand(
21172119 */
21182120ur_result_t
21192121waitForOngoingExecution (ur_exp_command_buffer_handle_t CommandBuffer) {
2122+ // Calling function has taken a lock for the command buffer so we can safely
2123+ // check and modify this value here.
2124+ // If command buffer was recently synchronized we can return early.
2125+ if (!CommandBuffer->NeedsUpdateSynchronization ) {
2126+ return UR_RESULT_SUCCESS;
2127+ }
2128+
21202129 if (CommandBuffer->UseImmediateAppendPath ) {
21212130 if (ur_event_handle_t &CurrentSubmissionEvent =
21222131 CommandBuffer->CurrentSubmissionEvent ) {
@@ -2128,7 +2137,8 @@ waitForOngoingExecution(ur_exp_command_buffer_handle_t CommandBuffer) {
21282137 } else if (ze_fence_handle_t &ZeFence = CommandBuffer->ZeActiveFence ) {
21292138 ZE2UR_CALL (zeFenceHostSynchronize, (ZeFence, UINT64_MAX));
21302139 }
2131-
2140+ // Mark that command buffer was recently synchronized
2141+ CommandBuffer->NeedsUpdateSynchronization = false ;
21322142 return UR_RESULT_SUCCESS;
21332143}
21342144
0 commit comments