Skip to content

Commit e2a9320

Browse files
committed
[EXP][Command-Buffer] Add kernel command update
This change introduces a new API that allows the kernel commands of a command-buffer to be updated with a new configuration. For example, modified arguments or ND-Range. See [cl_khr_command_buffer_mutable_dispatch](https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#cl_khr_command_buffer_mutable_dispatch) as prior art. The differences between the proposed API and the above are: * No flag is required to be set on command-buffer creation to enable this functionality. * Only the append kernel entry-point returns a command handle. I imagine this will be changed in future to enable other commands to do update. * Only USM and buffer arguments can be updated, there is not equivalent update struct for `urKernelSetArgLocal`, `urKernelSetArgValue`, or `urKernelSetArgSampler` * There is no granularity of optional support for update, an implementer must either implement all the ways to update a kernel configuration, or none of them.
1 parent 534071e commit e2a9320

21 files changed

+1643
-563
lines changed

include/ur.py

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class ur_function_v(IntEnum):
196196
ADAPTER_RETAIN = 179 ## Enumerator for ::urAdapterRetain
197197
ADAPTER_GET_LAST_ERROR = 180 ## Enumerator for ::urAdapterGetLastError
198198
ADAPTER_GET_INFO = 181 ## Enumerator for ::urAdapterGetInfo
199+
COMMAND_BUFFER_UPDATE_KERNEL_LAUNCH_EXP = 182 ## Enumerator for ::urCommandBufferUpdateKernelLaunchExp
199200

200201
class ur_function_t(c_int):
201202
def __str__(self):
@@ -240,6 +241,10 @@ class ur_structure_type_v(IntEnum):
240241
KERNEL_ARG_VALUE_PROPERTIES = 32 ## ::ur_kernel_arg_value_properties_t
241242
KERNEL_ARG_LOCAL_PROPERTIES = 33 ## ::ur_kernel_arg_local_properties_t
242243
EXP_COMMAND_BUFFER_DESC = 0x1000 ## ::ur_exp_command_buffer_desc_t
244+
EXP_COMMAND_BUFFER_UPDATE_KERNEL_LAUNCH_DESC = 0x1001 ## ::ur_exp_command_buffer_update_kernel_launch_desc_t
245+
EXP_COMMAND_BUFFER_UPDATE_MEMOBJ_ARG_DESC = 0x1002 ## ::ur_exp_command_buffer_update_memobj_arg_desc_t
246+
EXP_COMMAND_BUFFER_UPDATE_POINTER_ARG_DESC = 0x1003 ## ::ur_exp_command_buffer_update_pointer_arg_desc_t
247+
EXP_COMMAND_BUFFER_UPDATE_EXEC_INFO_DESC = 0x1004 ## ::ur_exp_command_buffer_update_exec_info_desc_t
243248
EXP_SAMPLER_MIP_PROPERTIES = 0x2000 ## ::ur_exp_sampler_mip_properties_t
244249
EXP_INTEROP_MEM_DESC = 0x2001 ## ::ur_exp_interop_mem_desc_t
245250
EXP_INTEROP_SEMAPHORE_DESC = 0x2002 ## ::ur_exp_interop_semaphore_desc_t
@@ -443,6 +448,7 @@ class ur_result_v(IntEnum):
443448
ERROR_INVALID_COMMAND_BUFFER_EXP = 0x1000 ## Invalid Command-Buffer
444449
ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP = 0x1001## Sync point is not valid for the command-buffer
445450
ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP = 0x1002 ## Sync point wait list is invalid
451+
ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP = 0x1003## Handle to command-buffer command is invalid
446452
ERROR_UNKNOWN = 0x7ffffffe ## Unknown or internal error
447453

448454
class ur_result_t(c_int):
@@ -833,6 +839,10 @@ class ur_device_info_v(IntEnum):
833839
## version than older devices.
834840
VIRTUAL_MEMORY_SUPPORT = 114 ## [::ur_bool_t] return true if the device supports virtual memory.
835841
ESIMD_SUPPORT = 115 ## [::ur_bool_t] return true if the device supports ESIMD.
842+
COMMAND_BUFFER_SUPPORT_EXP = 0x1000 ## [::ur_bool_t] returns true if the device supports the use of
843+
## command-buffers.
844+
COMMAND_BUFFER_UPDATE_SUPPORT_EXP = 0x1001 ## [::ur_bool_t] returns true if the device supports updating the
845+
## commands in a command-buffer.
836846
BINDLESS_IMAGES_SUPPORT_EXP = 0x2000 ## [::ur_bool_t] returns true if the device supports the creation of
837847
## bindless images
838848
BINDLESS_IMAGES_SHARED_USM_SUPPORT_EXP = 0x2001 ## [::ur_bool_t] returns true if the device supports the creation of
@@ -2242,6 +2252,69 @@ class ur_exp_command_buffer_desc_t(Structure):
22422252
("pNext", c_void_p) ## [in][optional] pointer to extension-specific structure
22432253
]
22442254

2255+
###############################################################################
2256+
## @brief Descriptor type for updating a kernel command memobj argument.
2257+
class ur_exp_command_buffer_update_memobj_arg_desc_t(Structure):
2258+
_fields_ = [
2259+
("stype", ur_structure_type_t), ## [in] type of this structure, must be
2260+
## ::UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_MEMOBJ_ARG_DESC
2261+
("pNext", c_void_p), ## [in][optional] pointer to extension-specific structure
2262+
("argIndex", c_ulong), ## [in] Argument index.
2263+
("pProperties", *), ## [in][optinal] Pointer to memory object properties.
2264+
("hArgValue", ur_mem_handle_t) ## [in][optional] Handle of memory object.
2265+
]
2266+
2267+
###############################################################################
2268+
## @brief Descriptor type for updating a kernel command pointer argument.
2269+
class ur_exp_command_buffer_update_pointer_arg_desc_t(Structure):
2270+
_fields_ = [
2271+
("stype", ur_structure_type_t), ## [in] type of this structure, must be
2272+
## ::UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_POINTER_ARG_DESC
2273+
("pNext", c_void_p), ## [in][optional] pointer to extension-specific structure
2274+
("argIndex", c_ulong), ## [in] Argument index.
2275+
("pProperties", *), ## [in][optinal] Pointer to USM pointer properties.
2276+
("pArgValue", *) ## [in][optional] USM pointer to memory location holding the argument
2277+
## value.
2278+
]
2279+
2280+
###############################################################################
2281+
## @brief Descriptor type for updating kernel command execution info.
2282+
class ur_exp_command_buffer_update_exec_info_desc_t(Structure):
2283+
_fields_ = [
2284+
("stype", ur_structure_type_t), ## [in] type of this structure, must be
2285+
## ::UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_EXEC_INFO_DESC
2286+
("pNext", c_void_p), ## [in][optional] pointer to extension-specific structure
2287+
("propName", ur_kernel_exec_info_t), ## [in] Name of execution attribute.
2288+
("propSize", c_size_t), ## [in] Size of execution attribute.
2289+
("pProperties", *), ## [in][optional] Pointer to execution info properties.
2290+
("pPropValue", *) ## [in] Pointer to memory location holding the property value.
2291+
]
2292+
2293+
###############################################################################
2294+
## @brief Descriptor type for updating a kernel launch command.
2295+
class ur_exp_command_buffer_update_kernel_launch_desc_t(Structure):
2296+
_fields_ = [
2297+
("stype", ur_structure_type_t), ## [in] type of this structure, must be
2298+
## ::UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_KERNEL_LAUNCH_DESC
2299+
("pNext", c_void_p), ## [in][optional] pointer to extension-specific structure
2300+
("numMemobjArgs", c_ulong), ## [in] Length of pArgMemobjList.
2301+
("numPointerArgs", c_ulong), ## [in] Length of pArgPointerList.
2302+
("numExecInfos", c_ulong), ## [in] Length of pExecInfoList.
2303+
("workDim", c_ulong), ## [in] Number of work dimensions in the kernel ND-range, from 1-3.
2304+
("pArgMemobjList", POINTER(ur_exp_command_buffer_update_memobj_arg_desc_t)),## [in] An array describing the new kernel mem obj arguments for the
2305+
## command.
2306+
("pArgPointerList", POINTER(ur_exp_command_buffer_update_pointer_arg_desc_t)), ## [in] An array describing the new kernel pointer arguments for the
2307+
## command.
2308+
("pArgExecInfoList", POINTER(ur_exp_command_buffer_update_exec_info_desc_t)), ## [in] An array describing the execution info objects for the command.
2309+
("pGlobalWorkOffset", POINTER(c_size_t)), ## [in] Array of workDim unsigned values that describe the offset used to
2310+
## calculate the global ID.
2311+
("pGlobalWorkSize", POINTER(c_size_t)), ## [in] Array of workDim unsigned values that describe the number of
2312+
## global work-items.
2313+
("pLocalWorkSize", POINTER(c_size_t)) ## [in] Array of workDim unsigned values that describe the number of
2314+
## work-items that make up a work-group. If nullptr, the runtime
2315+
## implementation will choose the work-group size.
2316+
]
2317+
22452318
###############################################################################
22462319
## @brief A value that identifies a command inside of a command-buffer, used for
22472320
## defining dependencies between commands in the same command-buffer.
@@ -2253,6 +2326,11 @@ class ur_exp_command_buffer_sync_point_t(c_ulong):
22532326
class ur_exp_command_buffer_handle_t(c_void_p):
22542327
pass
22552328

2329+
###############################################################################
2330+
## @brief Handle of a Command-Buffer command
2331+
class ur_exp_command_buffer_command_handle_t(c_void_p):
2332+
pass
2333+
22562334
###############################################################################
22572335
## @brief Supported peer info
22582336
class ur_exp_peer_info_v(IntEnum):
@@ -3431,9 +3509,9 @@ class ur_usm_exp_dditable_t(Structure):
34313509
###############################################################################
34323510
## @brief Function-pointer for urCommandBufferAppendKernelLaunchExp
34333511
if __use_win_types:
3434-
_urCommandBufferAppendKernelLaunchExp_t = WINFUNCTYPE( ur_result_t, ur_exp_command_buffer_handle_t, ur_kernel_handle_t, c_ulong, POINTER(c_size_t), POINTER(c_size_t), POINTER(c_size_t), c_ulong, POINTER(ur_exp_command_buffer_sync_point_t), POINTER(ur_exp_command_buffer_sync_point_t) )
3512+
_urCommandBufferAppendKernelLaunchExp_t = WINFUNCTYPE( ur_result_t, ur_exp_command_buffer_handle_t, ur_kernel_handle_t, c_ulong, POINTER(c_size_t), POINTER(c_size_t), POINTER(c_size_t), c_ulong, POINTER(ur_exp_command_buffer_sync_point_t), POINTER(ur_exp_command_buffer_sync_point_t), POINTER(ur_exp_command_buffer_command_handle_t) )
34353513
else:
3436-
_urCommandBufferAppendKernelLaunchExp_t = CFUNCTYPE( ur_result_t, ur_exp_command_buffer_handle_t, ur_kernel_handle_t, c_ulong, POINTER(c_size_t), POINTER(c_size_t), POINTER(c_size_t), c_ulong, POINTER(ur_exp_command_buffer_sync_point_t), POINTER(ur_exp_command_buffer_sync_point_t) )
3514+
_urCommandBufferAppendKernelLaunchExp_t = CFUNCTYPE( ur_result_t, ur_exp_command_buffer_handle_t, ur_kernel_handle_t, c_ulong, POINTER(c_size_t), POINTER(c_size_t), POINTER(c_size_t), c_ulong, POINTER(ur_exp_command_buffer_sync_point_t), POINTER(ur_exp_command_buffer_sync_point_t), POINTER(ur_exp_command_buffer_command_handle_t) )
34373515

34383516
###############################################################################
34393517
## @brief Function-pointer for urCommandBufferAppendMemcpyUSMExp
@@ -3491,6 +3569,13 @@ class ur_usm_exp_dditable_t(Structure):
34913569
else:
34923570
_urCommandBufferEnqueueExp_t = CFUNCTYPE( ur_result_t, ur_exp_command_buffer_handle_t, ur_queue_handle_t, c_ulong, POINTER(ur_event_handle_t), POINTER(ur_event_handle_t) )
34933571

3572+
###############################################################################
3573+
## @brief Function-pointer for urCommandBufferUpdateKernelLaunchExp
3574+
if __use_win_types:
3575+
_urCommandBufferUpdateKernelLaunchExp_t = WINFUNCTYPE( ur_result_t, ur_exp_command_buffer_command_handle_t, POINTER(ur_exp_command_buffer_update_kernel_launch_desc_t) )
3576+
else:
3577+
_urCommandBufferUpdateKernelLaunchExp_t = CFUNCTYPE( ur_result_t, ur_exp_command_buffer_command_handle_t, POINTER(ur_exp_command_buffer_update_kernel_launch_desc_t) )
3578+
34943579

34953580
###############################################################################
34963581
## @brief Table of CommandBufferExp functions pointers
@@ -3508,7 +3593,8 @@ class ur_command_buffer_exp_dditable_t(Structure):
35083593
("pfnAppendMembufferCopyRectExp", c_void_p), ## _urCommandBufferAppendMembufferCopyRectExp_t
35093594
("pfnAppendMembufferWriteRectExp", c_void_p), ## _urCommandBufferAppendMembufferWriteRectExp_t
35103595
("pfnAppendMembufferReadRectExp", c_void_p), ## _urCommandBufferAppendMembufferReadRectExp_t
3511-
("pfnEnqueueExp", c_void_p) ## _urCommandBufferEnqueueExp_t
3596+
("pfnEnqueueExp", c_void_p), ## _urCommandBufferEnqueueExp_t
3597+
("pfnUpdateKernelLaunchExp", c_void_p) ## _urCommandBufferUpdateKernelLaunchExp_t
35123598
]
35133599

35143600
###############################################################################
@@ -4054,6 +4140,7 @@ def __init__(self, version : ur_api_version_t):
40544140
self.urCommandBufferAppendMembufferWriteRectExp = _urCommandBufferAppendMembufferWriteRectExp_t(self.__dditable.CommandBufferExp.pfnAppendMembufferWriteRectExp)
40554141
self.urCommandBufferAppendMembufferReadRectExp = _urCommandBufferAppendMembufferReadRectExp_t(self.__dditable.CommandBufferExp.pfnAppendMembufferReadRectExp)
40564142
self.urCommandBufferEnqueueExp = _urCommandBufferEnqueueExp_t(self.__dditable.CommandBufferExp.pfnEnqueueExp)
4143+
self.urCommandBufferUpdateKernelLaunchExp = _urCommandBufferUpdateKernelLaunchExp_t(self.__dditable.CommandBufferExp.pfnUpdateKernelLaunchExp)
40574144

40584145
# call driver to get function pointers
40594146
UsmP2PExp = ur_usm_p2p_exp_dditable_t()

0 commit comments

Comments
 (0)