Skip to content

[UR][L0] Event cleanup in urEnqueueKernelLaunch #19827

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

Draft
wants to merge 3 commits into
base: sycl
Choose a base branch
from
Draft
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
21 changes: 21 additions & 0 deletions unified-runtime/source/adapters/level_zero/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
//===----------------------------------------------------------------------===//

#include "kernel.hpp"
#include "common.hpp"
#include "logger/ur_logger.hpp"
#include "queue.hpp"
#include "ur_api.h"
#include "ur_interface_loader.hpp"

Expand Down Expand Up @@ -221,6 +223,25 @@ ur_result_t urEnqueueKernelLaunch(
UR_CALL(Queue->executeCommandList(CommandList, false /*IsBlocking*/,
true /*OKToBatchCommand*/));

// For internal events only, occasionally trigger cleanup to prevent event
// pool exhaustion, but avoid doing this for in-order queues which are
// commonly used in multi-threaded scenarios and may have stricter
// synchronization requirements
if (IsInternal && !Queue->isInOrderQueue()) {
// Use a probabilistic approach - only cleanup 1 in 128 internal events
// to minimize performance impact and reduce chances of race conditions
static thread_local uint32_t CleanupCounter = 0;
if ((++CleanupCounter & 127) == 0) {
if (Queue->UsingImmCmdLists) {
UR_CALL(CleanupEventsInImmCmdLists(Queue, true /*QueueLocked*/,
false /*QueueSynced*/,
nullptr /*CompletedEvent*/));
} else {
UR_CALL(resetCommandLists(Queue));
}
}
}

return UR_RESULT_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions unified-runtime/source/adapters/level_zero/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "common.hpp"
#include "common/ur_ref_count.hpp"
#include "memory.hpp"
#include "queue.hpp"

struct ur_kernel_handle_t_ : ur_object {
ur_kernel_handle_t_(bool OwnZeHandle, ur_program_handle_t Program)
Expand Down