Skip to content

Commit c78112c

Browse files
committed
[SYCL][UR][L0 v2] move command list selection
and event allocation logic to a separate entity
1 parent 1f76dfd commit c78112c

File tree

5 files changed

+320
-295
lines changed

5 files changed

+320
-295
lines changed

unified-runtime/source/adapters/level_zero/v2/command_buffer.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,29 @@ void checkImmediateAppendSupport(ur_context_handle_t context) {
6262

6363
} // namespace
6464

65+
struct buffer_command_list_provider : command_list_provider {
66+
buffer_command_list_provider(v2::raii::command_list_unique_handle commandList)
67+
: commandList(std::move(commandList)) {}
68+
69+
command_submission_descriptor_t
70+
getCmdSubmissionDescriptor(ur_event_handle_t *, ur_command_t,
71+
const ur_event_handle_t *, uint32_t,
72+
ur_event_handle_t) override {
73+
return command_submission_descriptor_t{commandList.get(), nullptr,
74+
wait_list_view(nullptr, 0)};
75+
}
76+
77+
private:
78+
v2::raii::command_list_unique_handle commandList;
79+
};
80+
6581
ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
6682
ur_context_handle_t context, ur_device_handle_t device,
6783
v2::raii::command_list_unique_handle &&commandList,
6884
const ur_exp_command_buffer_desc_t *desc)
69-
: commandListManager(
70-
context, device,
71-
std::forward<v2::raii::command_list_unique_handle>(commandList),
72-
v2::EVENT_FLAGS_COUNTER, nullptr),
85+
: commandListManager(context, device,
86+
std::make_unique<buffer_command_list_provider>(
87+
std::move(commandList))),
7388
isUpdatable(desc ? desc->isUpdatable : false), context(context),
7489
device(device) {}
7590

@@ -80,8 +95,9 @@ ur_result_t ur_exp_command_buffer_handle_t_::createCommandHandle(
8095
ur_exp_command_buffer_command_handle_t *command) {
8196

8297
auto platform = context->getPlatform();
83-
ze_command_list_handle_t zeCommandList =
84-
commandListLocked->getZeCommandList();
98+
auto [zeCommandList, _1, _2] = commandListLocked->getCmdSubmissionDescriptor(
99+
nullptr, UR_COMMAND_FORCE_UINT32, nullptr, 0);
100+
85101
std::unique_ptr<kernel_command_handle> newCommand;
86102
UR_CALL(createCommandHandleUnlocked(this, zeCommandList, hKernel, workDim,
87103
pGlobalWorkSize, numKernelAlternatives,
@@ -98,7 +114,9 @@ ur_result_t ur_exp_command_buffer_handle_t_::finalizeCommandBuffer() {
98114
auto commandListLocked = commandListManager.lock();
99115
UR_ASSERT(!isFinalized, UR_RESULT_ERROR_INVALID_OPERATION);
100116
// Close the command lists and have them ready for dispatch.
101-
ZE2UR_CALL(zeCommandListClose, (commandListLocked->getZeCommandList()));
117+
auto [zeCommandList, _1, _2] = commandListLocked->getCmdSubmissionDescriptor(
118+
nullptr, UR_COMMAND_FORCE_UINT32, nullptr, 0);
119+
ZE2UR_CALL(zeCommandListClose, (zeCommandList));
102120
isFinalized = true;
103121
return UR_RESULT_SUCCESS;
104122
}
@@ -149,8 +167,8 @@ ur_result_t ur_exp_command_buffer_handle_t_::applyUpdateCommands(
149167
device_ptr_storage_t zeHandles;
150168

151169
auto platform = context->getPlatform();
152-
ze_command_list_handle_t zeCommandList =
153-
commandListLocked->getZeCommandList();
170+
auto [zeCommandList, _1, _2] = commandListLocked->getCmdSubmissionDescriptor(
171+
nullptr, UR_COMMAND_FORCE_UINT32, nullptr, 0);
154172
UR_CALL(updateCommandBufferUnlocked(
155173
getZeKernelWrapped, getMemPtr, zeCommandList, platform, device,
156174
&zeHandles, numUpdateCommands, updateCommands));
@@ -562,9 +580,9 @@ urCommandBufferGetNativeHandleExp(ur_exp_command_buffer_handle_t hCommandBuffer,
562580
ur_native_handle_t *phNativeCommandBuffer) {
563581

564582
auto commandListLocked = hCommandBuffer->commandListManager.lock();
565-
ze_command_list_handle_t ZeCommandList =
566-
commandListLocked->getZeCommandList();
567-
*phNativeCommandBuffer = reinterpret_cast<ur_native_handle_t>(ZeCommandList);
583+
auto [zeCommandList, _1, _2] = commandListLocked->getCmdSubmissionDescriptor(
584+
nullptr, UR_COMMAND_FORCE_UINT32, nullptr, 0);
585+
*phNativeCommandBuffer = reinterpret_cast<ur_native_handle_t>(zeCommandList);
568586
return UR_RESULT_SUCCESS;
569587
}
570588

0 commit comments

Comments
 (0)