Skip to content

Revert "[SYCL][UR][L0 v2] Fix issues with event lifetime" #19042

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
Jun 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,15 @@ ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
ur_context_handle_t context, ur_device_handle_t device,
v2::raii::command_list_unique_handle &&commandList,
const ur_exp_command_buffer_desc_t *desc)
: eventPool(context->getEventPoolCache(PoolCacheType::Regular)
.borrow(device->Id.value(),
isInOrder ? v2::EVENT_FLAGS_COUNTER : 0)),
context(context), device(device),
isUpdatable(desc ? desc->isUpdatable : false),
: isUpdatable(desc ? desc->isUpdatable : false),
isInOrder(desc ? desc->isInOrder : false),
commandListManager(
context, device,
std::forward<v2::raii::command_list_unique_handle>(commandList)) {
ur::level_zero::urContextRetain(context);
}
std::forward<v2::raii::command_list_unique_handle>(commandList)),
context(context), device(device),
eventPool(context->getEventPoolCache(PoolCacheType::Regular)
.borrow(device->Id.value(),
isInOrder ? v2::EVENT_FLAGS_COUNTER : 0)) {}

ur_exp_command_buffer_sync_point_t
ur_exp_command_buffer_handle_t_::getSyncPoint(ur_event_handle_t event) {
Expand Down Expand Up @@ -175,7 +173,6 @@ ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
for (auto &event : syncPoints) {
event->release();
}
ur::level_zero::urContextRelease(context);
}

ur_result_t ur_exp_command_buffer_handle_t_::applyUpdateCommands(
Expand Down
21 changes: 10 additions & 11 deletions unified-runtime/source/adapters/level_zero/v2/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ struct ur_exp_command_buffer_handle_t_ : public ur_object {
ur_result_t
registerExecutionEventUnlocked(ur_event_handle_t nextExecutionEvent);

// Indicates if command-buffer commands can be updated after it is closed.
const bool isUpdatable = false;
const bool isInOrder = true;

// Command-buffer profiling is enabled.
const bool isProfilingEnabled = false;

lockable<ur_command_list_manager> commandListManager;

ur_result_t finalizeCommandBuffer();

ur_result_t
Expand All @@ -54,8 +63,6 @@ struct ur_exp_command_buffer_handle_t_ : public ur_object {
createEventIfRequested(ur_exp_command_buffer_sync_point_t *retSyncPoint);

private:
v2::raii::cache_borrowed_event_pool eventPool;

// Stores all sync points that are created by the command buffer.
std::vector<ur_event_handle_t> syncPoints;

Expand All @@ -77,13 +84,5 @@ struct ur_exp_command_buffer_handle_t_ : public ur_object {

ur_event_handle_t currentExecution = nullptr;

public:
// Indicates if command-buffer commands can be updated after it is closed.
const bool isUpdatable = false;
const bool isInOrder = true;

// Command-buffer profiling is enabled.
const bool isProfilingEnabled = false;

lockable<ur_command_list_manager> commandListManager;
v2::raii::cache_borrowed_event_pool eventPool;
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ ur_command_list_manager::ur_command_list_manager(
ur_context_handle_t context, ur_device_handle_t device,
v2::raii::command_list_unique_handle &&commandList)
: hContext(context), hDevice(device),
zeCommandList(std::move(commandList)) {}
zeCommandList(std::move(commandList)) {
UR_CALL_THROWS(ur::level_zero::urContextRetain(context));
UR_CALL_THROWS(ur::level_zero::urDeviceRetain(device));
}

ur_command_list_manager::~ur_command_list_manager() {
ur::level_zero::urContextRelease(hContext);
ur::level_zero::urDeviceRelease(hDevice);
}

ur_result_t ur_command_list_manager::appendGenericFillUnlocked(
ur_mem_buffer_t *dst, size_t offset, size_t patternSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct ur_command_list_manager {
operator=(const ur_command_list_manager &src) = delete;
ur_command_list_manager &operator=(ur_command_list_manager &&src) = default;

~ur_command_list_manager() = default;
~ur_command_list_manager();

ze_command_list_handle_t getZeCommandList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,25 @@ ur_queue_immediate_in_order_t::ur_queue_immediate_in_order_t(
ze_command_queue_priority_t priority, std::optional<int32_t> index,
event_flags_t eventFlags, ur_queue_flags_t flags)
: hContext(hContext), hDevice(hDevice),
eventPool(hContext->getEventPoolCache(PoolCacheType::Immediate)
.borrow(hDevice->Id.value(), eventFlags)),
commandListManager(
hContext, hDevice,
hContext->getCommandListCache().getImmediateCommandList(
hDevice->ZeDevice,
{true, ordinal, true /* always enable copy offload */},
ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS, priority, index)),
flags(flags) {
ur::level_zero::urContextRetain(hContext);
}
flags(flags),
eventPool(hContext->getEventPoolCache(PoolCacheType::Immediate)
.borrow(hDevice->Id.value(), eventFlags)) {}

ur_queue_immediate_in_order_t::ur_queue_immediate_in_order_t(
ur_context_handle_t hContext, ur_device_handle_t hDevice,
raii::command_list_unique_handle commandListHandle,
event_flags_t eventFlags, ur_queue_flags_t flags)
: hContext(hContext), hDevice(hDevice),
eventPool(hContext->getEventPoolCache(PoolCacheType::Immediate)
.borrow(hDevice->Id.value(), eventFlags)),
commandListManager(hContext, hDevice, std::move(commandListHandle)),
flags(flags) {
ur::level_zero::urContextRetain(hContext);
}
flags(flags),
eventPool(hContext->getEventPoolCache(PoolCacheType::Immediate)
.borrow(hDevice->Id.value(), eventFlags)) {}

ur_result_t
ur_queue_immediate_in_order_t::queueGetInfo(ur_queue_info_t propName,
Expand Down Expand Up @@ -126,7 +122,6 @@ ur_result_t ur_queue_immediate_in_order_t::queueFlush() {
ur_queue_immediate_in_order_t::~ur_queue_immediate_in_order_t() {
try {
UR_CALL_THROWS(queueFinish());
ur::level_zero::urContextRelease(hContext);
} catch (...) {
// Ignore errors during destruction
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ struct ur_queue_immediate_in_order_t : ur_object, ur_queue_t_ {
private:
ur_context_handle_t hContext;
ur_device_handle_t hDevice;

v2::raii::cache_borrowed_event_pool eventPool;

lockable<ur_command_list_manager> commandListManager;
ur_queue_flags_t flags;
v2::raii::cache_borrowed_event_pool eventPool;

// Only create an event when requested by the user.
ur_event_handle_t createEventIfRequested(ur_event_handle_t *phEvent) {
Expand Down
Loading