Skip to content

Commit 6523932

Browse files
EwanCreble
andcommitted
[Command-buffer][L0] Condense signalling
Rather than having a command-list wide barrier and separate signal command, have a single barrier command which signals the UR command-buffer signal event and waits on the events that correspond to sync-points. Co-authored-by: Pablo Reble <[email protected]>
1 parent e8e1415 commit 6523932

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

source/adapters/level_zero/command_buffer.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
3939
There is also a WaitEvent used by the `ur_exp_command_buffer_handle_t` class
4040
in the prefix to wait on any dependencies passed in the enqueue wait-list.
41+
This WaitEvent is reset at the end of the suffix, along with reset commands
42+
to reset the L0 events used to implement the UR sync-points.
4143
4244
┌──────────┬────────────────────────────────────────────────┬─────────┐
4345
│ Prefix │ Commands added to UR command-buffer by UR user │ Suffix │
@@ -47,10 +49,10 @@
4749
Prefix │Reset signal event │ Barrier waiting on wait event│
4850
└───────────────────┴──────────────────────────────┘
4951
50-
┌─────────────────────────────────────────┐
51-
Suffix │Signal the UR command-buffer signal event│
52-
└─────────────────────────────────────────┘
53-
52+
┌─────────────────────────────────────────────┐──────────────
53+
Suffix │Barrier waiting on sync-point event, │ Reset events
54+
│signalling the UR command-buffer signal event│ │
55+
└─────────────────────────────────────────────┘──────────────┘
5456
5557
For a call to `urCommandBufferEnqueueExp` with an event_list `EL`,
5658
command-buffer `CB`, and return event `RE` our implementation has to create
@@ -437,26 +439,31 @@ urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t CommandBuffer) {
437439

438440
UR_APIEXPORT ur_result_t UR_APICALL
439441
urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t CommandBuffer) {
440-
// Reset the L0 events we use for command-buffer internal sync-points to the
441-
// non-signalled state
442-
ZE2UR_CALL(zeCommandListAppendBarrier,
443-
(CommandBuffer->ZeCommandList, nullptr, 0, nullptr));
444-
for (auto SyncPoint : CommandBuffer->SyncPoints) {
445-
ur_event_handle_t Event = SyncPoint.second;
446-
ZE2UR_CALL(zeCommandListAppendEventReset,
447-
(CommandBuffer->ZeCommandList, Event->ZeEvent));
442+
// Create a list of events for our signal event to wait on
443+
const size_t NumEvents = CommandBuffer->SyncPoints.size();
444+
std::vector<ze_event_handle_t> WaitEventList{NumEvents};
445+
for (size_t i = 0; i < NumEvents; i++) {
446+
WaitEventList[i] = CommandBuffer->SyncPoints[i]->ZeEvent;
448447
}
449448

449+
// Wait for all the user added commands to complete, and signal the
450+
// command-buffer signal-event when they are done.
451+
ZE2UR_CALL(zeCommandListAppendBarrier,
452+
(CommandBuffer->ZeCommandList, CommandBuffer->SignalEvent->ZeEvent,
453+
NumEvents, WaitEventList.data()));
454+
450455
// Reset the wait-event for the UR command-buffer that is signalled when its
451456
// submission dependencies have been satisfied.
452457
ZE2UR_CALL(zeCommandListAppendEventReset,
453458
(CommandBuffer->ZeCommandList, CommandBuffer->WaitEvent->ZeEvent));
454459

455-
// We need to append signal that will indicate that command-buffer has
456-
// finished executing.
457-
ZE2UR_CALL(
458-
zeCommandListAppendSignalEvent,
459-
(CommandBuffer->ZeCommandList, CommandBuffer->SignalEvent->ZeEvent));
460+
// Reset the L0 events we use for command-buffer internal sync-points to the
461+
// non-signalled state
462+
for (auto Event : WaitEventList) {
463+
ZE2UR_CALL(zeCommandListAppendEventReset,
464+
(CommandBuffer->ZeCommandList, Event));
465+
}
466+
460467
// Close the command list and have it ready for dispatch.
461468
ZE2UR_CALL(zeCommandListClose, (CommandBuffer->ZeCommandList));
462469
return UR_RESULT_SUCCESS;

0 commit comments

Comments
 (0)