Skip to content

[L0][CMDBUF] Optimize fence/event waits during update #2561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion source/adapters/level_zero/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,8 @@ ur_result_t urCommandBufferEnqueueExp(
EventWaitList, OutEvent, ZeCommandListHelper,
DoProfiling));
}
// Mark that synchronization will be required for later updates
CommandBuffer->NeedsUpdateSynchronization = true;

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -2117,6 +2119,13 @@ ur_result_t updateKernelCommand(
*/
ur_result_t
waitForOngoingExecution(ur_exp_command_buffer_handle_t CommandBuffer) {
// Calling function has taken a lock for the command buffer so we can safely
// check and modify this value here.
// If command buffer was recently synchronized we can return early.
if (!CommandBuffer->NeedsUpdateSynchronization) {
return UR_RESULT_SUCCESS;
}

if (CommandBuffer->UseImmediateAppendPath) {
if (ur_event_handle_t &CurrentSubmissionEvent =
CommandBuffer->CurrentSubmissionEvent) {
Expand All @@ -2128,7 +2137,8 @@ waitForOngoingExecution(ur_exp_command_buffer_handle_t CommandBuffer) {
} else if (ze_fence_handle_t &ZeFence = CommandBuffer->ZeActiveFence) {
ZE2UR_CALL(zeFenceHostSynchronize, (ZeFence, UINT64_MAX));
}

// Mark that command buffer was recently synchronized
CommandBuffer->NeedsUpdateSynchronization = false;
return UR_RESULT_SUCCESS;
}

Expand Down
4 changes: 4 additions & 0 deletions source/adapters/level_zero/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
// This list is needed to release all kernels retained by the
// command_buffer.
std::vector<ur_kernel_handle_t> KernelsList;
// Track whether synchronization is required when updating the command buffer
// Set this value to true when a command buffer is enqueued, and false after
// any fence or event synchronization to avoid repeated calls to synchronize.
bool NeedsUpdateSynchronization = false;
};

struct ur_exp_command_buffer_command_handle_t_ : public _ur_object {
Expand Down
Loading