Skip to content

Commit f739737

Browse files
committed
Finalize
1 parent 8e40a54 commit f739737

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

source/adapters/level_zero/command_buffer.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -667,46 +667,44 @@ urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t CommandBuffer) {
667667
return UR_RESULT_SUCCESS;
668668
}
669669

670+
void ur_exp_command_buffer_handle_t_::RegisterSyncPoint(
671+
ur_exp_command_buffer_sync_point_t SyncPoint, ur_event_handle_t Event) {
672+
SyncPoints[SyncPoint] = Event;
673+
NextSyncPoint++;
674+
ZeEventsList.push_back(Event->ZeEvent);
675+
}
676+
670677
UR_APIEXPORT ur_result_t UR_APICALL
671678
urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t CommandBuffer) {
672679
UR_ASSERT(CommandBuffer, UR_RESULT_ERROR_INVALID_NULL_POINTER);
673680
// It is not allowed to append to command list from multiple threads.
674681
std::scoped_lock<ur_shared_mutex> Guard(CommandBuffer->Mutex);
675682

676-
// Create a list of events for our signal event to wait on
677-
// This loop also resets the L0 events we use for command-buffer internal
678-
// sync-points to the non-signaled state.
679-
// This is required for multiple submissions.
680-
const size_t NumEvents = CommandBuffer->SyncPoints.size();
681-
for (size_t i = 0; i < NumEvents; i++) {
682-
auto ZeEvent = CommandBuffer->SyncPoints[i]->ZeEvent;
683-
CommandBuffer->ZeEventsList.push_back(ZeEvent);
684-
ZE2UR_CALL(zeCommandListAppendEventReset,
685-
(CommandBuffer->ZeCommandListResetEvents, ZeEvent));
686-
}
687-
ZE2UR_CALL(zeCommandListAppendSignalEvent,
688-
(CommandBuffer->ZeCommandListResetEvents,
689-
CommandBuffer->AllResetEvent->ZeEvent));
690-
691683
if (CommandBuffer->IsInOrderCmdList) {
692684
ZE2UR_CALL(zeCommandListAppendSignalEvent,
693685
(CommandBuffer->ZeComputeCommandList,
694686
CommandBuffer->SignalEvent->ZeEvent));
695687
} else {
696-
// Create a list of events for our signal event to wait on
697-
const size_t NumEvents = CommandBuffer->SyncPoints.size();
698-
std::vector<ze_event_handle_t> WaitEventList{NumEvents};
699-
for (size_t i = 0; i < NumEvents; i++) {
700-
WaitEventList[i] = CommandBuffer->SyncPoints[i]->ZeEvent;
688+
// Reset the L0 events we use for command-buffer sync-points to the
689+
// non-signaled state. This is required for multiple submissions.
690+
for (auto &Event : CommandBuffer->ZeEventsList) {
691+
ZE2UR_CALL(zeCommandListAppendEventReset,
692+
(CommandBuffer->ZeCommandListResetEvents, Event));
701693
}
702694

703695
// Wait for all the user added commands to complete, and signal the
704696
// command-buffer signal-event when they are done.
705-
ZE2UR_CALL(zeCommandListAppendBarrier, (CommandBuffer->ZeComputeCommandList,
706-
CommandBuffer->SignalEvent->ZeEvent,
707-
NumEvents, WaitEventList.data()));
697+
ZE2UR_CALL(zeCommandListAppendBarrier,
698+
(CommandBuffer->ZeComputeCommandList,
699+
CommandBuffer->SignalEvent->ZeEvent,
700+
CommandBuffer->ZeEventsList.size(),
701+
CommandBuffer->ZeEventsList.data()));
708702
}
709703

704+
ZE2UR_CALL(zeCommandListAppendSignalEvent,
705+
(CommandBuffer->ZeCommandListResetEvents,
706+
CommandBuffer->AllResetEvent->ZeEvent));
707+
710708
// Close the command lists and have them ready for dispatch.
711709
ZE2UR_CALL(zeCommandListClose, (CommandBuffer->ZeComputeCommandList));
712710
ZE2UR_CALL(zeCommandListClose, (CommandBuffer->ZeCommandListResetEvents));

source/adapters/level_zero/command_buffer.hpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
3030
ze_command_list_handle_t CommandList,
3131
ze_command_list_handle_t CommandListTranslated,
3232
ze_command_list_handle_t CommandListResetEvents,
33-
ze_command_list_handle_t CopyCommandList,
34-
ur_event_handle_t SignalEvent,
35-
ur_event_handle_t WaitEvent,
36-
ur_event_handle_t AllResetEvent,
33+
ze_command_list_handle_t CopyCommandList, ur_event_handle_t SignalEvent,
34+
ur_event_handle_t WaitEvent, ur_event_handle_t AllResetEvent,
3735
const ur_exp_command_buffer_desc_t *Desc, const bool IsInOrderCmdList);
3836

3937
~ur_exp_command_buffer_handle_t_();
4038

39+
// void RegisterSyncPoint(ur_exp_command_buffer_sync_point_t SyncPoint,
40+
// ur_event_handle_t Event) {
41+
// SyncPoints[SyncPoint] = Event;
42+
// NextSyncPoint++;
43+
// }
44+
4145
void RegisterSyncPoint(ur_exp_command_buffer_sync_point_t SyncPoint,
42-
ur_event_handle_t Event) {
43-
SyncPoints[SyncPoint] = Event;
44-
NextSyncPoint++;
45-
}
46+
ur_event_handle_t Event);
4647

4748
ur_exp_command_buffer_sync_point_t GetNextSyncPoint() const {
4849
return NextSyncPoint;
@@ -52,8 +53,10 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
5253
bool UseCopyEngine() const { return ZeCopyCommandList != nullptr; }
5354

5455
// FIXME Refactor Documentation
55-
ur_result_t getFence(ze_command_queue_handle_t & ZeCommandQueue, ze_fence_handle_t &ZeFence);
56-
ur_result_t getZeCommandQueue(ur_queue_handle_t Queue, bool UseCopyEngine, ze_command_queue_handle_t& ZeCommandQueue);
56+
ur_result_t getFence(ze_command_queue_handle_t &ZeCommandQueue,
57+
ze_fence_handle_t &ZeFence);
58+
ur_result_t getZeCommandQueue(ur_queue_handle_t Queue, bool UseCopyEngine,
59+
ze_command_queue_handle_t &ZeCommandQueue);
5760
ur_result_t chooseCommandList(bool PreferCopyEngine,
5861
ze_command_list_handle_t *ZeCommandList);
5962
ur_result_t chooseCommandList(bool PreferCopyEngine,
@@ -98,7 +101,7 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
98101
// Next sync_point value (may need to consider ways to reuse values if 32-bits
99102
// is not enough)
100103
ur_exp_command_buffer_sync_point_t NextSyncPoint;
101-
// List of Level Zero events associated to submitted commands.
104+
// List of Level Zero events associated with submitted commands.
102105
std::vector<ze_event_handle_t> ZeEventsList;
103106

104107
// Indicates if command-buffer commands can be updated after it is closed.

0 commit comments

Comments
 (0)