@@ -93,7 +93,7 @@ ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
93
93
const ur_exp_command_buffer_desc_t *Desc)
94
94
: Context(Context), Device(Device), ZeCommandList(CommandList),
95
95
ZeCommandListDesc(ZeDesc), QueueProperties(), SyncPoints(),
96
- NextSyncPoint(0 ), CommandListMap () {
96
+ NextSyncPoint(0 ), ZeFencesList () {
97
97
(void )Desc;
98
98
urContextRetain (Context);
99
99
urDeviceRetain (Device);
@@ -132,10 +132,8 @@ ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
132
132
}
133
133
134
134
// Release Fences allocated to command_buffer
135
- for (auto it = CommandListMap.begin (); it != CommandListMap.end (); ++it) {
136
- if (it->second .ZeFence != nullptr ) {
137
- ZE_CALL_NOCHECK (zeFenceDestroy, (it->second .ZeFence ));
138
- }
135
+ for (auto &ZeFence : ZeFencesList) {
136
+ ZE_CALL_NOCHECK (zeFenceDestroy, (ZeFence));
139
137
}
140
138
}
141
139
@@ -418,7 +416,6 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
418
416
ZE2UR_CALL (
419
417
zeCommandListAppendBarrier,
420
418
(ZeCommandList, nullptr , 1 , &RetCommandBuffer->WaitEvent ->ZeEvent ));
421
-
422
419
return UR_RESULT_SUCCESS;
423
420
}
424
421
@@ -687,12 +684,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp(
687
684
ur_exp_command_buffer_handle_t CommandBuffer, ur_queue_handle_t Queue,
688
685
uint32_t NumEventsInWaitList, const ur_event_handle_t *EventWaitList,
689
686
ur_event_handle_t *Event) {
690
- // There are issues with immediate command lists so return an error if the
691
- // queue is in that mode.
692
- if (Queue->UsingImmCmdLists ) {
693
- return UR_RESULT_ERROR_INVALID_QUEUE_PROPERTIES;
694
- }
695
-
696
687
std::scoped_lock<ur_shared_mutex> lock (Queue->Mutex );
697
688
// Use compute engine rather than copy engine
698
689
const auto UseCopyEngine = false ;
@@ -702,78 +693,68 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp(
702
693
703
694
ze_fence_handle_t ZeFence;
704
695
ZeStruct<ze_fence_desc_t > ZeFenceDesc;
705
- ur_command_list_ptr_t CommandListPtr;
706
696
707
697
ZE2UR_CALL (zeFenceCreate, (ZeCommandQueue, &ZeFenceDesc, &ZeFence));
708
- // TODO: Refactor so requiring a map iterator is not required here, currently
709
- // required for executeCommandList though.
710
- ZeStruct<ze_command_queue_desc_t > ZeQueueDesc;
711
- ZeQueueDesc.ordinal = QueueGroupOrdinal;
712
- CommandListPtr = CommandBuffer->CommandListMap .insert (
713
- std::pair<ze_command_list_handle_t , ur_command_list_info_t >(
714
- CommandBuffer->ZeCommandList ,
715
- {ZeFence, false , false , ZeCommandQueue, ZeQueueDesc}));
716
-
717
- // Previous execution will have closed the command list, we need to reopen
718
- // it otherwise calling `executeCommandList` will return early.
719
- CommandListPtr->second .IsClosed = false ;
720
- CommandListPtr->second .ZeFenceInUse = true ;
698
+ CommandBuffer->ZeFencesList .push_back (ZeFence);
721
699
722
700
// Create command-list to execute before `CommandListPtr` and will signal
723
701
// when `EventWaitList` dependencies are complete.
724
- ur_command_list_ptr_t WaitCommandList{} ;
702
+ bool MustSignalWaitEvent = true ;
725
703
if (NumEventsInWaitList) {
726
704
_ur_ze_event_list_t TmpWaitList;
727
705
UR_CALL (TmpWaitList.createAndRetainUrZeEventList (
728
706
NumEventsInWaitList, EventWaitList, Queue, UseCopyEngine));
729
707
730
- UR_CALL (Queue->Context ->getAvailableCommandList (Queue, WaitCommandList,
731
- false , false ))
732
-
733
708
// Update the WaitList of the Wait Event
734
709
// Events are appended to the WaitList if the WaitList is not empty
735
710
if (CommandBuffer->WaitEvent ->WaitList .isEmpty ())
736
711
CommandBuffer->WaitEvent ->WaitList = TmpWaitList;
737
712
else
738
713
CommandBuffer->WaitEvent ->WaitList .insert (TmpWaitList);
739
714
740
- ZE2UR_CALL (zeCommandListAppendBarrier,
741
- (WaitCommandList->first , CommandBuffer->WaitEvent ->ZeEvent ,
742
- CommandBuffer->WaitEvent ->WaitList .Length ,
743
- CommandBuffer->WaitEvent ->WaitList .ZeEventList ));
744
- } else {
745
- UR_CALL (Queue->Context ->getAvailableCommandList (Queue, WaitCommandList,
746
- false , false ));
715
+ if (!CommandBuffer->WaitEvent ->WaitList .isEmpty ()) {
716
+ ur_command_list_ptr_t WaitCommandList{};
717
+ UR_CALL (Queue->Context ->getAvailableCommandList (Queue, WaitCommandList,
718
+ false , false ))
719
+
720
+ ZE2UR_CALL (zeCommandListAppendBarrier,
721
+ (WaitCommandList->first , CommandBuffer->WaitEvent ->ZeEvent ,
722
+ CommandBuffer->WaitEvent ->WaitList .Length ,
723
+ CommandBuffer->WaitEvent ->WaitList .ZeEventList ));
724
+ Queue->executeCommandList (WaitCommandList, false , false );
725
+ MustSignalWaitEvent = false ;
726
+ }
727
+ }
747
728
748
- ZE2UR_CALL (zeCommandListAppendSignalEvent,
749
- (WaitCommandList-> first , CommandBuffer->WaitEvent ->ZeEvent ));
729
+ if (MustSignalWaitEvent) {
730
+ ZE2UR_CALL (zeEventHostSignal, ( CommandBuffer->WaitEvent ->ZeEvent ));
750
731
}
751
732
733
+ // Submit main command-list. This command-list is of a batch command-list
734
+ // type, regardless of the UR Queue type. We therefore need to submit the list
735
+ // directly using the Level-Zero API to avoid type mismatches if using UR
736
+ // functions.
737
+ ZE2UR_CALL (zeCommandQueueExecuteCommandLists,
738
+ (ZeCommandQueue, 1 , &CommandBuffer->ZeCommandList , ZeFence));
739
+
752
740
// Execution event for this enqueue of the UR command-buffer
753
741
ur_event_handle_t RetEvent{};
754
- // Create a command-list to signal RetEvent on completion
755
- ur_command_list_ptr_t SignalCommandList{};
756
742
if (Event) {
743
+ // Create a command-list to signal RetEvent on completion
744
+ ur_command_list_ptr_t SignalCommandList{};
757
745
UR_CALL (Queue->Context ->getAvailableCommandList (Queue, SignalCommandList,
758
746
false , false ));
759
747
760
748
UR_CALL (createEventAndAssociateQueue (Queue, &RetEvent,
761
749
UR_COMMAND_COMMAND_BUFFER_ENQUEUE_EXP,
762
- SignalCommandList, false ));
750
+ SignalCommandList, false , true ));
763
751
764
752
ZE2UR_CALL (zeCommandListAppendBarrier,
765
753
(SignalCommandList->first , RetEvent->ZeEvent , 1 ,
766
754
&(CommandBuffer->SignalEvent ->ZeEvent )));
755
+ Queue->executeCommandList (SignalCommandList, false , false );
767
756
}
768
757
769
- // Execution our command-lists asynchronously
770
- // TODO Look using a single `zeCommandQueueExecuteCommandLists()` call
771
- // passing all three command-lists, rather than individual calls which
772
- // introduces latency.
773
- UR_CALL (Queue->executeCommandList (WaitCommandList, false , false ));
774
- UR_CALL (Queue->executeCommandList (CommandListPtr, false , false ));
775
- UR_CALL (Queue->executeCommandList (SignalCommandList, false , false ));
776
-
777
758
if (Event) {
778
759
*Event = RetEvent;
779
760
}
0 commit comments