Skip to content

Commit e8e1415

Browse files
committed
[Command-buffer][L0] Reset sync-point events
The L0 events used to implement UR sync-points in a command-buffer aren't reset after the first execution. Leaving them in a signalled state before subsequent submissions of the UR command-buffer. This patch resets the L0 events used as UR command-buffer sync-points to the non-signalled state, by appending event reset commands to the end of the user defined command-list. There is also a reset added for the UR command-buffer wait event that is signalled when the wait list dependencies of `urCommandBufferEnqueueExp` are met. Additionally this patch removes the host scope flag from being set on L0 events created by the UR command-buffer, as we never signal/reset them from host, only device.
1 parent ab45620 commit e8e1415

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

source/adapters/level_zero/command_buffer.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static ur_result_t enqueueCommandBufferMemCopyHelper(
293293
SyncPointWaitList, ZeEventList));
294294

295295
ur_event_handle_t LaunchEvent;
296-
UR_CALL(EventCreate(CommandBuffer->Context, nullptr, true, &LaunchEvent));
296+
UR_CALL(EventCreate(CommandBuffer->Context, nullptr, false, &LaunchEvent));
297297
LaunchEvent->CommandType = CommandType;
298298

299299
// Get sync point and register the event with it.
@@ -358,7 +358,7 @@ static ur_result_t enqueueCommandBufferMemCopyRectHelper(
358358
SyncPointWaitList, ZeEventList));
359359

360360
ur_event_handle_t LaunchEvent;
361-
UR_CALL(EventCreate(CommandBuffer->Context, nullptr, true, &LaunchEvent));
361+
UR_CALL(EventCreate(CommandBuffer->Context, nullptr, false, &LaunchEvent));
362362
LaunchEvent->CommandType = CommandType;
363363

364364
// Get sync point and register the event with it.
@@ -407,7 +407,7 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
407407
// Create signal & wait events to be used in the command-list for sync
408408
// on command-buffer enqueue.
409409
auto RetCommandBuffer = *CommandBuffer;
410-
UR_CALL(EventCreate(Context, nullptr, true, &RetCommandBuffer->SignalEvent));
410+
UR_CALL(EventCreate(Context, nullptr, false, &RetCommandBuffer->SignalEvent));
411411
UR_CALL(EventCreate(Context, nullptr, false, &RetCommandBuffer->WaitEvent));
412412

413413
// Add prefix commands
@@ -437,6 +437,21 @@ urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t CommandBuffer) {
437437

438438
UR_APIEXPORT ur_result_t UR_APICALL
439439
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));
448+
}
449+
450+
// Reset the wait-event for the UR command-buffer that is signalled when its
451+
// submission dependencies have been satisfied.
452+
ZE2UR_CALL(zeCommandListAppendEventReset,
453+
(CommandBuffer->ZeCommandList, CommandBuffer->WaitEvent->ZeEvent));
454+
440455
// We need to append signal that will indicate that command-buffer has
441456
// finished executing.
442457
ZE2UR_CALL(
@@ -497,7 +512,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
497512
UR_CALL(getEventsFromSyncPoints(CommandBuffer, NumSyncPointsInWaitList,
498513
SyncPointWaitList, ZeEventList));
499514
ur_event_handle_t LaunchEvent;
500-
UR_CALL(EventCreate(CommandBuffer->Context, nullptr, true, &LaunchEvent));
515+
UR_CALL(EventCreate(CommandBuffer->Context, nullptr, false, &LaunchEvent));
501516
LaunchEvent->CommandType = UR_COMMAND_KERNEL_LAUNCH;
502517

503518
// Get sync point and register the event with it.
@@ -727,7 +742,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp(
727742
(WaitCommandList->first, CommandBuffer->WaitEvent->ZeEvent));
728743
}
729744

730-
// Execution event for this enqueue of the PI command-buffer
745+
// Execution event for this enqueue of the UR command-buffer
731746
ur_event_handle_t RetEvent{};
732747
// Create a command-list to signal RetEvent on completion
733748
ur_command_list_ptr_t SignalCommandList{};

0 commit comments

Comments
 (0)