@@ -589,42 +589,27 @@ bool canBeInOrder(ur_context_handle_t Context,
589589
590590/* *
591591 * Append the initial barriers to the Compute and Copy command-lists.
592- * These barriers wait for all the events to be reset before starting execution
593- * of the command-buffer
594592 * @param CommandBuffer The CommandBuffer
595- * @param UseImmediateAppendPath true if the adapter is using the
596- * zeCommandListImmediateAppendCommandListsExp() API to launch the
597- * command-buffer.
598593 * @return UR_RESULT_SUCCESS or an error code on failure.
599594 */
600- ur_result_t appendExecutionWaits (ur_exp_command_buffer_handle_t CommandBuffer,
601- bool UseImmediateAppendPath) {
595+ ur_result_t appendExecutionWaits (ur_exp_command_buffer_handle_t CommandBuffer) {
602596
603- if (UseImmediateAppendPath && CommandBuffer->ZeCommandListResetEvents ) {
604- ZE2UR_CALL (zeCommandListAppendBarrier,
605- (CommandBuffer->ZeComputeCommandList , nullptr , 1 ,
606- &CommandBuffer->AllResetEvent ->ZeEvent ));
607-
608- if (CommandBuffer->ZeCopyCommandList ) {
609- ZE2UR_CALL (zeCommandListAppendBarrier,
610- (CommandBuffer->ZeCopyCommandList , nullptr , 1 ,
611- &CommandBuffer->AllResetEvent ->ZeEvent ));
612- }
597+ std::vector<ze_event_handle_t > PrecondEvents;
598+ if (CommandBuffer->ZeCommandListResetEvents ) {
599+ PrecondEvents.push_back (CommandBuffer->AllResetEvent ->ZeEvent );
600+ }
601+ if (!CommandBuffer->UseImmediateAppendPath ) {
602+ PrecondEvents.push_back (CommandBuffer->WaitEvent ->ZeEvent );
613603 }
614604
615- if (!UseImmediateAppendPath) {
616- std::vector<ze_event_handle_t > PrecondEvents = {
617- CommandBuffer->WaitEvent ->ZeEvent ,
618- CommandBuffer->AllResetEvent ->ZeEvent };
619- ZE2UR_CALL (zeCommandListAppendBarrier,
620- (CommandBuffer->ZeComputeCommandList , nullptr ,
621- PrecondEvents.size (), PrecondEvents.data ()));
605+ ZE2UR_CALL (zeCommandListAppendBarrier,
606+ (CommandBuffer->ZeComputeCommandList , nullptr ,
607+ PrecondEvents.size (), PrecondEvents.data ()));
622608
623- if (CommandBuffer->ZeCopyCommandList ) {
624- ZE2UR_CALL (zeCommandListAppendBarrier,
625- (CommandBuffer->ZeCopyCommandList , nullptr ,
626- PrecondEvents.size (), PrecondEvents.data ()));
627- }
609+ if (CommandBuffer->ZeCopyCommandList ) {
610+ ZE2UR_CALL (zeCommandListAppendBarrier,
611+ (CommandBuffer->ZeCopyCommandList , nullptr , PrecondEvents.size (),
612+ PrecondEvents.data ()));
628613 }
629614
630615 return UR_RESULT_SUCCESS;
@@ -651,6 +636,22 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
651636 ze_command_list_handle_t ZeComputeCommandList = nullptr ;
652637 ze_command_list_handle_t ZeCopyCommandList = nullptr ;
653638 ze_command_list_handle_t ZeCommandListResetEvents = nullptr ;
639+ ze_command_list_handle_t ZeComputeCommandListTranslated = nullptr ;
640+
641+ UR_CALL (createMainCommandList (Context, Device, IsInOrder, IsUpdatable, false ,
642+ ZeComputeCommandList));
643+
644+ // Create a list for copy commands. Note that to simplify the implementation,
645+ // the current implementation only uses the main copy engine and does not use
646+ // the link engine even if available.
647+ if (Device->hasMainCopyEngine ()) {
648+ UR_CALL (createMainCommandList (Context, Device, false , false , true ,
649+ ZeCopyCommandList));
650+ }
651+
652+ ZE2UR_CALL (zelLoaderTranslateHandle,
653+ (ZEL_HANDLE_COMMAND_LIST, ZeComputeCommandList,
654+ (void **)&ZeComputeCommandListTranslated));
654655
655656 // The CopyFinishedEvent and ComputeFinishedEvent are needed only when using
656657 // the ImmediateAppend Path.
@@ -697,22 +698,6 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
697698 false /* CounterBasedEventEnabled*/ , !EnableProfiling));
698699 }
699700
700- UR_CALL (createMainCommandList (Context, Device, IsInOrder, IsUpdatable, false ,
701- ZeComputeCommandList));
702-
703- // Create a list for copy commands. Note that to simplify the implementation,
704- // the current implementation only uses the main copy engine and does not use
705- // the link engine even if available.
706- if (Device->hasMainCopyEngine ()) {
707- UR_CALL (createMainCommandList (Context, Device, false , false , true ,
708- ZeCopyCommandList));
709- }
710-
711- ze_command_list_handle_t ZeComputeCommandListTranslated = nullptr ;
712- ZE2UR_CALL (zelLoaderTranslateHandle,
713- (ZEL_HANDLE_COMMAND_LIST, ZeComputeCommandList,
714- (void **)&ZeComputeCommandListTranslated));
715-
716701 try {
717702 *CommandBuffer = new ur_exp_command_buffer_handle_t_ (
718703 Context, Device, ZeComputeCommandList, ZeComputeCommandListTranslated,
@@ -725,9 +710,7 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
725710 return UR_RESULT_ERROR_UNKNOWN;
726711 }
727712
728- if (ZeCommandListResetEvents) {
729- UR_CALL (appendExecutionWaits (*CommandBuffer, ImmediateAppendPath));
730- }
713+ UR_CALL (appendExecutionWaits (*CommandBuffer));
731714
732715 return UR_RESULT_SUCCESS;
733716}
0 commit comments