@@ -583,42 +583,27 @@ bool canBeInOrder(ur_context_handle_t Context,
583583
584584/* *
585585 * Append the initial barriers to the Compute and Copy command-lists.
586- * These barriers wait for all the events to be reset before starting execution
587- * of the command-buffer
588586 * @param CommandBuffer The CommandBuffer
589- * @param UseImmediateAppendPath true if the adapter is using the
590- * zeCommandListImmediateAppendCommandListsExp() API to launch the
591- * command-buffer.
592587 * @return UR_RESULT_SUCCESS or an error code on failure.
593588 */
594- ur_result_t appendExecutionWaits (ur_exp_command_buffer_handle_t CommandBuffer,
595- bool UseImmediateAppendPath) {
589+ ur_result_t appendExecutionWaits (ur_exp_command_buffer_handle_t CommandBuffer) {
596590
597- if (UseImmediateAppendPath && CommandBuffer->ZeCommandListResetEvents ) {
598- ZE2UR_CALL (zeCommandListAppendBarrier,
599- (CommandBuffer->ZeComputeCommandList , nullptr , 1 ,
600- &CommandBuffer->AllResetEvent ->ZeEvent ));
601-
602- if (CommandBuffer->ZeCopyCommandList ) {
603- ZE2UR_CALL (zeCommandListAppendBarrier,
604- (CommandBuffer->ZeCopyCommandList , nullptr , 1 ,
605- &CommandBuffer->AllResetEvent ->ZeEvent ));
606- }
591+ std::vector<ze_event_handle_t > PrecondEvents;
592+ if (CommandBuffer->ZeCommandListResetEvents ) {
593+ PrecondEvents.push_back (CommandBuffer->AllResetEvent ->ZeEvent );
594+ }
595+ if (!CommandBuffer->UseImmediateAppendPath ) {
596+ PrecondEvents.push_back (CommandBuffer->WaitEvent ->ZeEvent );
607597 }
608598
609- if (!UseImmediateAppendPath) {
610- std::vector<ze_event_handle_t > PrecondEvents = {
611- CommandBuffer->WaitEvent ->ZeEvent ,
612- CommandBuffer->AllResetEvent ->ZeEvent };
613- ZE2UR_CALL (zeCommandListAppendBarrier,
614- (CommandBuffer->ZeComputeCommandList , nullptr ,
615- PrecondEvents.size (), PrecondEvents.data ()));
599+ ZE2UR_CALL (zeCommandListAppendBarrier,
600+ (CommandBuffer->ZeComputeCommandList , nullptr ,
601+ PrecondEvents.size (), PrecondEvents.data ()));
616602
617- if (CommandBuffer->ZeCopyCommandList ) {
618- ZE2UR_CALL (zeCommandListAppendBarrier,
619- (CommandBuffer->ZeCopyCommandList , nullptr ,
620- PrecondEvents.size (), PrecondEvents.data ()));
621- }
603+ if (CommandBuffer->ZeCopyCommandList ) {
604+ ZE2UR_CALL (zeCommandListAppendBarrier,
605+ (CommandBuffer->ZeCopyCommandList , nullptr , PrecondEvents.size (),
606+ PrecondEvents.data ()));
622607 }
623608
624609 return UR_RESULT_SUCCESS;
@@ -645,6 +630,22 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
645630 ze_command_list_handle_t ZeComputeCommandList = nullptr ;
646631 ze_command_list_handle_t ZeCopyCommandList = nullptr ;
647632 ze_command_list_handle_t ZeCommandListResetEvents = nullptr ;
633+ ze_command_list_handle_t ZeComputeCommandListTranslated = nullptr ;
634+
635+ UR_CALL (createMainCommandList (Context, Device, IsInOrder, IsUpdatable, false ,
636+ ZeComputeCommandList));
637+
638+ // Create a list for copy commands. Note that to simplify the implementation,
639+ // the current implementation only uses the main copy engine and does not use
640+ // the link engine even if available.
641+ if (Device->hasMainCopyEngine ()) {
642+ UR_CALL (createMainCommandList (Context, Device, false , false , true ,
643+ ZeCopyCommandList));
644+ }
645+
646+ ZE2UR_CALL (zelLoaderTranslateHandle,
647+ (ZEL_HANDLE_COMMAND_LIST, ZeComputeCommandList,
648+ (void **)&ZeComputeCommandListTranslated));
648649
649650 // The CopyFinishedEvent and ComputeFinishedEvent are needed only when using
650651 // the ImmediateAppend Path.
@@ -691,22 +692,6 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
691692 !EnableProfiling));
692693 }
693694
694- UR_CALL (createMainCommandList (Context, Device, IsInOrder, IsUpdatable, false ,
695- ZeComputeCommandList));
696-
697- // Create a list for copy commands. Note that to simplify the implementation,
698- // the current implementation only uses the main copy engine and does not use
699- // the link engine even if available.
700- if (Device->hasMainCopyEngine ()) {
701- UR_CALL (createMainCommandList (Context, Device, false , false , true ,
702- ZeCopyCommandList));
703- }
704-
705- ze_command_list_handle_t ZeComputeCommandListTranslated = nullptr ;
706- ZE2UR_CALL (zelLoaderTranslateHandle,
707- (ZEL_HANDLE_COMMAND_LIST, ZeComputeCommandList,
708- (void **)&ZeComputeCommandListTranslated));
709-
710695 try {
711696 *CommandBuffer = new ur_exp_command_buffer_handle_t_ (
712697 Context, Device, ZeComputeCommandList, ZeComputeCommandListTranslated,
@@ -719,9 +704,7 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
719704 return UR_RESULT_ERROR_UNKNOWN;
720705 }
721706
722- if (ZeCommandListResetEvents) {
723- UR_CALL (appendExecutionWaits (*CommandBuffer, ImmediateAppendPath));
724- }
707+ UR_CALL (appendExecutionWaits (*CommandBuffer));
725708
726709 return UR_RESULT_SUCCESS;
727710}
0 commit comments