Skip to content

Commit a6bb8fb

Browse files
pbalcerXewar313lslusarczyk
authored
[v2] add initial Command Buffers support (#2629)
* [v2] add initial Command Buffers support --------- Co-authored-by: Mikołaj Komar <[email protected]> Co-authored-by: Łukasz Ślusarczyk <[email protected]>
1 parent 6026786 commit a6bb8fb

26 files changed

+614
-296
lines changed

include/ur_api.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11101,7 +11101,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferReleaseCommandExp(
1110111101
/// is not nullptr.
1110211102
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
1110311103
/// + If ::ur_exp_command_buffer_desc_t::isUpdatable was not set to true
11104-
/// on creation of the command buffer `hCommand` belongs to.
11104+
/// on creation of the command-buffer `hCommand` belongs to.
1110511105
/// + If the command-buffer `hCommand` belongs to has not been
1110611106
/// finalized.
1110711107
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
@@ -11154,7 +11154,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp(
1115411154
/// supported by the device associated with `hCommand`.
1115511155
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
1115611156
/// + If ::ur_exp_command_buffer_desc_t::isUpdatable was not set to true
11157-
/// on creation of the command buffer `hCommand` belongs to.
11157+
/// on creation of the command-buffer `hCommand` belongs to.
1115811158
/// + If the command-buffer `hCommand` belongs to has not been
1115911159
/// finalized.
1116011160
/// + If no `phEvent` parameter was set on creation of the command
@@ -11185,7 +11185,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateSignalEventExp(
1118511185
/// supported by the device associated with `hCommand`.
1118611186
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
1118711187
/// + If ::ur_exp_command_buffer_desc_t::isUpdatable was not set to true
11188-
/// on creation of the command buffer `hCommand` belongs to.
11188+
/// on creation of the command-buffer `hCommand` belongs to.
1118911189
/// + If the command-buffer `hCommand` belongs to has not been
1119011190
/// finalized.
1119111191
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP

scripts/core/exp-command-buffer.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ returns:
12111211
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_GLOBAL_WORK_OFFSET is not supported by the device but `pUpdateKernelLaunch->pNewGlobalWorkOffset` is not nullptr."
12121212
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_KERNEL_HANDLE is not supported by the device but `pUpdateKernelLaunch->hNewKernel` is not nullptr."
12131213
- $X_RESULT_ERROR_INVALID_OPERATION:
1214-
- "If $x_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to."
1214+
- "If $x_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command-buffer `hCommand` belongs to."
12151215
- "If the command-buffer `hCommand` belongs to has not been finalized."
12161216
- $X_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP:
12171217
- "If `hCommand` is not a kernel execution command."
@@ -1244,7 +1244,7 @@ returns:
12441244
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
12451245
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_EVENTS is not supported by the device associated with `hCommand`."
12461246
- $X_RESULT_ERROR_INVALID_OPERATION:
1247-
- "If $x_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to."
1247+
- "If $x_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command-buffer `hCommand` belongs to."
12481248
- "If the command-buffer `hCommand` belongs to has not been finalized."
12491249
- "If no `phEvent` parameter was set on creation of the command associated with `hCommand`."
12501250
- $X_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
@@ -1270,7 +1270,7 @@ returns:
12701270
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
12711271
- "If $X_DEVICE_COMMAND_BUFFER_UPDATE_CAPABILITY_FLAG_EVENTS is not supported by the device associated with `hCommand`."
12721272
- $X_RESULT_ERROR_INVALID_OPERATION:
1273-
- "If $x_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to."
1273+
- "If $x_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command-buffer `hCommand` belongs to."
12741274
- "If the command-buffer `hCommand` belongs to has not been finalized."
12751275
- $X_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
12761276
- $X_RESULT_ERROR_INVALID_EVENT_WAIT_LIST:

scripts/templates/queue_api.cpp.mako

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ from templates import helper as th
2020
*
2121
*/
2222

23+
// Do not edit. This file is auto generated from a template: scripts/templates/queue_api.cpp.mako
24+
2325
#include "queue_api.hpp"
2426
#include "ur_util.hpp"
2527

scripts/templates/queue_api.hpp.mako

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ from templates import helper as th
2020
*
2121
*/
2222

23+
// Do not edit. This file is auto generated from a template: scripts/templates/queue_api.hpp.mako
24+
2325
#pragma once
2426

2527
#include <ur_api.h>
28+
#include <ze_api.h>
2629

2730
struct ur_queue_handle_t_ {
2831
virtual ~ur_queue_handle_t_();
@@ -32,4 +35,8 @@ struct ur_queue_handle_t_ {
3235
%for obj in th.get_queue_related_functions(specs, n, tags):
3336
virtual ${x}_result_t ${th.transform_queue_related_function_name(n, tags, obj, format=["type"])} = 0;
3437
%endfor
38+
39+
virtual ur_result_t
40+
enqueueCommandBuffer(ze_command_list_handle_t, ur_event_handle_t *,
41+
uint32_t, const ur_event_handle_t *) = 0;
3542
};

source/adapters/cuda/command_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ updateKernelArguments(kernel_command_handle *Command,
13131313
}
13141314

13151315
/**
1316-
* Updates the command buffer command with new values from the update
1316+
* Updates the command-buffer command with new values from the update
13171317
* description.
13181318
* @param[in] Command The command to be updated.
13191319
* @param[in] UpdateCommandDesc The update command description.

source/adapters/cuda/command_buffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ struct ur_exp_command_buffer_handle_t_ {
362362

363363
// UR context associated with this command-buffer
364364
ur_context_handle_t Context;
365-
// Device associated with this command buffer
365+
// Device associated with this command-buffer
366366
ur_device_handle_t Device;
367367
// Whether commands in the command-buffer can be updated
368368
bool IsUpdatable;

source/adapters/hip/command_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ updateKernelArguments(ur_exp_command_buffer_command_handle_t Command,
10241024
}
10251025

10261026
/**
1027-
* Updates the command buffer command with new values from the update
1027+
* Updates the command-buffer command with new values from the update
10281028
* description.
10291029
* @param[in] Command The command to be updated.
10301030
* @param[in] UpdateCommandDesc The update command description.

source/adapters/hip/command_buffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct ur_exp_command_buffer_handle_t_ {
168168

169169
// UR context associated with this command-buffer
170170
ur_context_handle_t Context;
171-
// Device associated with this command buffer
171+
// Device associated with this command-buffer
172172
ur_device_handle_t Device;
173173
// Whether commands in the command-buffer can be updated
174174
bool IsUpdatable;

source/adapters/level_zero/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ if(UR_BUILD_ADAPTER_L0_V2)
143143
${CMAKE_CURRENT_SOURCE_DIR}/virtual_mem.cpp
144144
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
145145
# v2-only sources
146+
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_buffer.hpp
146147
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_cache.hpp
148+
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_manager.hpp
147149
${CMAKE_CURRENT_SOURCE_DIR}/v2/context.hpp
148150
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_pool_cache.hpp
149151
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_pool.hpp
@@ -157,7 +159,9 @@ if(UR_BUILD_ADAPTER_L0_V2)
157159
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.hpp
158160
${CMAKE_CURRENT_SOURCE_DIR}/v2/usm.hpp
159161
${CMAKE_CURRENT_SOURCE_DIR}/v2/api.cpp
162+
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_buffer.cpp
160163
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_cache.cpp
164+
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_manager.cpp
161165
${CMAKE_CURRENT_SOURCE_DIR}/v2/context.cpp
162166
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_pool_cache.cpp
163167
${CMAKE_CURRENT_SOURCE_DIR}/v2/event_pool.cpp

source/adapters/level_zero/command_buffer.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ ur_result_t getEventsFromSyncPoints(
173173
/**
174174
* If needed, creates a sync point for a given command and returns the L0
175175
* events associated with the sync point.
176-
* This operations is skipped if the command buffer is in order.
176+
* This operations is skipped if the command-buffer is in order.
177177
* @param[in] CommandType The type of the command.
178178
* @param[in] CommandBuffer The CommandBuffer where the command is appended.
179179
* @param[in] NumSyncPointsInWaitList Number of sync points that are
@@ -252,7 +252,7 @@ ur_result_t enqueueCommandBufferMemCopyHelper(
252252
}
253253

254254
// Helper function for common code when enqueuing rectangular memory operations
255-
// to a command buffer.
255+
// to a command-buffer.
256256
ur_result_t enqueueCommandBufferMemCopyRectHelper(
257257
ur_command_t CommandType, ur_exp_command_buffer_handle_t CommandBuffer,
258258
void *Dst, const void *Src, ur_rect_offset_t SrcOrigin,
@@ -584,10 +584,10 @@ ur_result_t createMainCommandList(ur_context_handle_t Context,
584584
}
585585

586586
/**
587-
* Checks whether the command buffer can be constructed using in order
587+
* Checks whether the command-buffer can be constructed using in order
588588
* command-lists.
589-
* @param[in] Context The Context associated with the command buffer.
590-
* @param[in] CommandBufferDesc The description of the command buffer.
589+
* @param[in] Context The Context associated with the command-buffer.
590+
* @param[in] CommandBufferDesc The description of the command-buffer.
591591
* @return Returns true if in order command-lists can be enabled.
592592
*/
593593
bool canBeInOrder(ur_context_handle_t Context,
@@ -810,7 +810,7 @@ finalizeImmediateAppendPath(ur_exp_command_buffer_handle_t CommandBuffer) {
810810
CommandBuffer->AllResetEvent->ZeEvent));
811811

812812
// All the events are reset by default. So signal the all reset event for
813-
// the first run of the command buffer
813+
// the first run of the command-buffer
814814
ZE2UR_CALL(zeEventHostSignal, (CommandBuffer->AllResetEvent->ZeEvent));
815815
}
816816

@@ -887,7 +887,7 @@ urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t CommandBuffer) {
887887

888888
/**
889889
* Sets the kernel arguments for a kernel command that will be appended to the
890-
* command buffer.
890+
* command-buffer.
891891
* @param[in] Device The Device associated with the command-buffer where the
892892
* kernel command will be appended.
893893
* @param[in,out] Arguments stored in the ur_kernel_handle_t object to be set
@@ -918,7 +918,7 @@ ur_result_t setKernelPendingArguments(
918918
}
919919

920920
/**
921-
* Creates a new command handle to use in future updates to the command buffer.
921+
* Creates a new command handle to use in future updates to the command-buffer.
922922
* @param[in] CommandBuffer The CommandBuffer associated with the new command.
923923
* @param[in] Kernel The Kernel associated with the new command.
924924
* @param[in] WorkDim Dimensions of the kernel associated with the new command.
@@ -1315,7 +1315,7 @@ ur_result_t urCommandBufferAppendUSMPrefetchExp(
13151315
std::ignore = Flags;
13161316

13171317
if (CommandBuffer->IsInOrderCmdList) {
1318-
// Add the prefetch command to the command buffer.
1318+
// Add the prefetch command to the command-buffer.
13191319
// Note that L0 does not handle migration flags.
13201320
ZE2UR_CALL(zeCommandListAppendMemoryPrefetch,
13211321
(CommandBuffer->ZeComputeCommandList, Mem, Size));
@@ -1332,7 +1332,7 @@ ur_result_t urCommandBufferAppendUSMPrefetchExp(
13321332
ZeEventList.data()));
13331333
}
13341334

1335-
// Add the prefetch command to the command buffer.
1335+
// Add the prefetch command to the command-buffer.
13361336
// Note that L0 does not handle migration flags.
13371337
ZE2UR_CALL(zeCommandListAppendMemoryPrefetch,
13381338
(CommandBuffer->ZeComputeCommandList, Mem, Size));
@@ -1463,7 +1463,7 @@ ur_result_t urCommandBufferAppendUSMFillExp(
14631463

14641464
/**
14651465
* Gets an L0 command queue that supports the chosen engine.
1466-
* @param[in] Queue The UR queue used to submit the command buffer.
1466+
* @param[in] Queue The UR queue used to submit the command-buffer.
14671467
* @param[in] UseCopyEngine Which engine to use. true for the copy engine and
14681468
* false for the compute engine.
14691469
* @param[out] ZeCommandQueue The L0 command queue.
@@ -1478,9 +1478,9 @@ ur_result_t getZeCommandQueue(ur_queue_handle_t Queue, bool UseCopyEngine,
14781478
}
14791479

14801480
/**
1481-
* Waits for the all the dependencies of the command buffer
1482-
* @param[in] CommandBuffer The command buffer.
1483-
* @param[in] Queue The UR queue used to submit the command buffer.
1481+
* Waits for the all the dependencies of the command-buffer
1482+
* @param[in] CommandBuffer The command-buffer.
1483+
* @param[in] Queue The UR queue used to submit the command-buffer.
14841484
* @param[in] NumEventsInWaitList The number of events to wait for.
14851485
* @param[in] EventWaitList List of events to wait for.
14861486
* @return UR_RESULT_SUCCESS or an error code on failure
@@ -1546,10 +1546,10 @@ ur_result_t appendProfilingQueries(ur_exp_command_buffer_handle_t CommandBuffer,
15461546
ur_event_handle_t SignalEvent,
15471547
ur_event_handle_t WaitEvent,
15481548
ur_event_handle_t ProfilingEvent) {
1549-
// Multiple submissions of a command buffer implies that we need to save
1550-
// the event timestamps before resubmiting the command buffer. We
1549+
// Multiple submissions of a command-buffer implies that we need to save
1550+
// the event timestamps before resubmiting the command-buffer. We
15511551
// therefore copy these timestamps in a dedicated USM memory section
1552-
// before completing the command buffer execution, and then attach this
1552+
// before completing the command-buffer execution, and then attach this
15531553
// memory to the event returned to users to allow the profiling
15541554
// engine to recover these timestamps.
15551555
command_buffer_profiling_t *Profiling = new command_buffer_profiling_t();
@@ -2129,9 +2129,9 @@ ur_result_t updateKernelCommand(
21292129
*/
21302130
ur_result_t
21312131
waitForOngoingExecution(ur_exp_command_buffer_handle_t CommandBuffer) {
2132-
// Calling function has taken a lock for the command buffer so we can safely
2132+
// Calling function has taken a lock for the command-buffer so we can safely
21332133
// check and modify this value here.
2134-
// If command buffer was recently synchronized we can return early.
2134+
// If command-buffer was recently synchronized we can return early.
21352135
if (!CommandBuffer->NeedsUpdateSynchronization) {
21362136
return UR_RESULT_SUCCESS;
21372137
}
@@ -2147,7 +2147,7 @@ waitForOngoingExecution(ur_exp_command_buffer_handle_t CommandBuffer) {
21472147
} else if (ze_fence_handle_t &ZeFence = CommandBuffer->ZeActiveFence) {
21482148
ZE2UR_CALL(zeFenceHostSynchronize, (ZeFence, UINT64_MAX));
21492149
}
2150-
// Mark that command buffer was recently synchronized
2150+
// Mark that command-buffer was recently synchronized
21512151
CommandBuffer->NeedsUpdateSynchronization = false;
21522152
return UR_RESULT_SUCCESS;
21532153
}
@@ -2162,7 +2162,7 @@ ur_result_t urCommandBufferUpdateKernelLaunchExp(
21622162

21632163
UR_ASSERT(KernelCommandHandle->Kernel, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
21642164

2165-
// Lock command, kernel and command buffer for update.
2165+
// Lock command, kernel and command-buffer for update.
21662166
std::scoped_lock<ur_shared_mutex, ur_shared_mutex, ur_shared_mutex> Guard(
21672167
Command->Mutex, Command->CommandBuffer->Mutex,
21682168
KernelCommandHandle->Kernel->Mutex);

source/adapters/level_zero/command_buffer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
7373

7474
// UR context associated with this command-buffer
7575
ur_context_handle_t Context;
76-
// Device associated with this command buffer
76+
// Device associated with this command-buffer
7777
ur_device_handle_t Device;
7878
// Level Zero command list handle that has the compute engine commands for
7979
// this command-buffer.
@@ -129,7 +129,7 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
129129

130130
// Indicates if command-buffer commands can be updated after it is closed.
131131
bool IsUpdatable = false;
132-
// Indicates if command buffer was finalized.
132+
// Indicates if command-buffer was finalized.
133133
bool IsFinalized = false;
134134
// Command-buffer profiling is enabled.
135135
bool IsProfilingEnabled = false;
@@ -141,8 +141,8 @@ struct ur_exp_command_buffer_handle_t_ : public _ur_object {
141141
// This list is needed to release all kernels retained by the
142142
// command_buffer.
143143
std::vector<ur_kernel_handle_t> KernelsList;
144-
// Track whether synchronization is required when updating the command buffer
145-
// Set this value to true when a command buffer is enqueued, and false after
144+
// Track whether synchronization is required when updating the command-buffer
145+
// Set this value to true when a command-buffer is enqueued, and false after
146146
// any fence or event synchronization to avoid repeated calls to synchronize.
147147
bool NeedsUpdateSynchronization = false;
148148
};

source/adapters/level_zero/helpers/kernel_helpers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ur_result_t calculateKernelWorkDimensions(
3333

3434
/**
3535
* Sets the global offset for a kernel command that will be appended to the
36-
* command buffer.
36+
* command-buffer.
3737
* @param[in] Context Context associated with the queue.
3838
* @param[in] Kernel The handle to the kernel that will be appended.
3939
* @param[in] WorkDim The number of work dimensions.

0 commit comments

Comments
 (0)