Skip to content

Commit df68355

Browse files
committed
[EXP][Command-buffer] OpenCL kernel command update
Implement the API for updating the kernel commands in a command-buffer defined by #1089 for the OpenCL adapter. However, the following changes to the UR kernel update API have been made based on implementation experience: 1. Forbid updating the work-dim of the kernel, see KhronosGroup/OpenCL-Docs#1057 2. Remove struct fields to update exec info, after [DPC++ implementation prototype](intel/llvm#12840) shows this isn't needed. 3. Forbid changing the local work size from user to impl defined and vice-versa. See discussion in [L0 implementation PR](#1353 (comment)). This adapter implementation depends on support for the [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) extension. Tested on Intel GPU/CPUs OpenCL implementations with the [command-buffer emulation layer](https://github.com/bashbaug/SimpleOpenCLSamples/tree/main/layers/10_cmdbufemu). ```bash $ OPENCL_LAYERS=<path/to/SimpleOpenCLSamples/build/layers/10_cmdbufemu/libCmdBufEmu.so> ./bin/test-exp_command_buffer --platform="Intel(R) OpenCL Graphics" ``` DPC++ PR intel/llvm#12724
1 parent a504ead commit df68355

30 files changed

+712
-417
lines changed

include/ur_api.h

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ typedef enum ur_structure_type_t {
271271
UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_MEMOBJ_ARG_DESC = 0x1002, ///< ::ur_exp_command_buffer_update_memobj_arg_desc_t
272272
UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_POINTER_ARG_DESC = 0x1003, ///< ::ur_exp_command_buffer_update_pointer_arg_desc_t
273273
UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_VALUE_ARG_DESC = 0x1004, ///< ::ur_exp_command_buffer_update_value_arg_desc_t
274-
UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_EXEC_INFO_DESC = 0x1005, ///< ::ur_exp_command_buffer_update_exec_info_desc_t
275274
UR_STRUCTURE_TYPE_EXP_SAMPLER_MIP_PROPERTIES = 0x2000, ///< ::ur_exp_sampler_mip_properties_t
276275
UR_STRUCTURE_TYPE_EXP_INTEROP_MEM_DESC = 0x2001, ///< ::ur_exp_interop_mem_desc_t
277276
UR_STRUCTURE_TYPE_EXP_INTEROP_SEMAPHORE_DESC = 0x2002, ///< ::ur_exp_interop_semaphore_desc_t
@@ -7934,19 +7933,6 @@ typedef struct ur_exp_command_buffer_update_value_arg_desc_t {
79347933

79357934
} ur_exp_command_buffer_update_value_arg_desc_t;
79367935

7937-
///////////////////////////////////////////////////////////////////////////////
7938-
/// @brief Descriptor type for updating kernel command execution info.
7939-
typedef struct ur_exp_command_buffer_update_exec_info_desc_t {
7940-
ur_structure_type_t stype; ///< [in] type of this structure, must be
7941-
///< ::UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_EXEC_INFO_DESC
7942-
const void *pNext; ///< [in][optional] pointer to extension-specific structure
7943-
ur_kernel_exec_info_t propName; ///< [in] Name of execution attribute.
7944-
size_t propSize; ///< [in] Size of execution attribute.
7945-
const ur_kernel_exec_info_properties_t *pProperties; ///< [in][optional] Pointer to execution info properties.
7946-
const void *pNewExecInfo; ///< [in] Pointer to memory location holding the execution info value.
7947-
7948-
} ur_exp_command_buffer_update_exec_info_desc_t;
7949-
79507936
///////////////////////////////////////////////////////////////////////////////
79517937
/// @brief Descriptor type for updating a kernel launch command.
79527938
typedef struct ur_exp_command_buffer_update_kernel_launch_desc_t {
@@ -7956,24 +7942,23 @@ typedef struct ur_exp_command_buffer_update_kernel_launch_desc_t {
79567942
uint32_t numNewMemObjArgs; ///< [in] Length of pNewMemObjArgList.
79577943
uint32_t numNewPointerArgs; ///< [in] Length of pNewPointerArgList.
79587944
uint32_t numNewValueArgs; ///< [in] Length of pNewValueArgList.
7959-
uint32_t numNewExecInfos; ///< [in] Length of pNewExecInfoList.
79607945
uint32_t newWorkDim; ///< [in] Number of work dimensions in the kernel ND-range, from 1-3.
79617946
const ur_exp_command_buffer_update_memobj_arg_desc_t *pNewMemObjArgList; ///< [in][optional][range(0, numNewMemObjArgs)] An array describing the new
79627947
///< kernel mem obj arguments for the command.
79637948
const ur_exp_command_buffer_update_pointer_arg_desc_t *pNewPointerArgList; ///< [in][optional][range(0, numNewPointerArgs)] An array describing the
79647949
///< new kernel pointer arguments for the command.
79657950
const ur_exp_command_buffer_update_value_arg_desc_t *pNewValueArgList; ///< [in][optional][range(0, numNewValueArgs)] An array describing the new
79667951
///< kernel value arguments for the command.
7967-
const ur_exp_command_buffer_update_exec_info_desc_t *pNewExecInfoList; ///< [in][optional][range(0, numNewExecInfos)] An array describing the
7968-
///< execution info objects for the command.
79697952
size_t *pNewGlobalWorkOffset; ///< [in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned
79707953
///< values that describe the offset used to calculate the global ID.
79717954
size_t *pNewGlobalWorkSize; ///< [in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned
79727955
///< values that describe the number of global work-items.
79737956
size_t *pNewLocalWorkSize; ///< [in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned
79747957
///< values that describe the number of work-items that make up a
7975-
///< work-group. If nullptr, the runtime implementation will choose the
7976-
///< work-group size.
7958+
///< work-group. If newWorkDim is non-zero and pNewLocalWorkSize is
7959+
///< nullptr, then runtime implementation will choose the work-group size.
7960+
///< If newWorkDim is zero and pNewLocalWorkSize is nullptr, then the local
7961+
///< work size is unchanged.
79777962

79787963
} ur_exp_command_buffer_update_kernel_launch_desc_t;
79797964

@@ -8008,6 +7993,8 @@ typedef struct ur_exp_command_buffer_command_handle_t_ *ur_exp_command_buffer_co
80087993
/// + `NULL == phCommandBuffer`
80097994
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
80107995
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
7996+
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
7997+
/// + If `pCommandBufferDesc->isUpdatable` is true and `hDevice` does not support UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_SUPPORT_EXP.
80117998
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
80127999
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
80138000
UR_APIEXPORT ur_result_t UR_APICALL
@@ -8088,7 +8075,6 @@ urCommandBufferFinalizeExp(
80888075
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
80898076
/// + `NULL == pGlobalWorkOffset`
80908077
/// + `NULL == pGlobalWorkSize`
8091-
/// + `NULL == pLocalWorkSize`
80928078
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP
80938079
/// - ::UR_RESULT_ERROR_INVALID_KERNEL
80948080
/// - ::UR_RESULT_ERROR_INVALID_WORK_DIMENSION
@@ -8107,7 +8093,7 @@ urCommandBufferAppendKernelLaunchExp(
81078093
uint32_t workDim, ///< [in] Dimension of the kernel execution.
81088094
const size_t *pGlobalWorkOffset, ///< [in] Offset to use when executing kernel.
81098095
const size_t *pGlobalWorkSize, ///< [in] Global work size to use when executing kernel.
8110-
const size_t *pLocalWorkSize, ///< [in] Local work size to use when executing kernel.
8096+
const size_t *pLocalWorkSize, ///< [in][optional] Local work size to use when executing kernel.
81118097
uint32_t numSyncPointsInWaitList, ///< [in] The number of sync points in the provided dependency list.
81128098
const ur_exp_command_buffer_sync_point_t *pSyncPointWaitList, ///< [in][optional] A list of sync points that this command depends on.
81138099
ur_exp_command_buffer_sync_point_t *pSyncPoint, ///< [out][optional] Sync point associated with this command.
@@ -8609,6 +8595,10 @@ urCommandBufferReleaseCommandExp(
86098595
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
86108596
/// + If ::ur_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to.
86118597
/// + If the command-buffer `hCommand` belongs to has not been finalized.
8598+
/// + If `pUpdateKernellaunch->newWorkDim` is non-zero and different from the work-dim used on creation of `hCommand`.
8599+
/// + If `pUpdateKernellaunch->newWorkDim` is non-zero and `pUpdateKernelLaunch->pNewLocalWorkSize` is set to a non-NULL value and `pUpdateKernelLaunch->pNewGlobalWorkSize` is NULL.
8600+
/// + If `pUpdateKernellaunch->newWorkDim` is non-zero and `pUpdateKernelLaunch->pNewLocalWorkSize` is set to a non-NULL value when `hCommand` was created with a NULL local work size.
8601+
/// + If `pUpdateKernellaunch->newWorkDim` is non-zero and `pUpdateKernelLaunch->pNewLocalWorkSize` is set to a NULL value when `hCommand` was created with a non-NULL local work size.
86128602
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
86138603
/// - ::UR_RESULT_ERROR_INVALID_MEM_OBJECT
86148604
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX

include/ur_print.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -978,14 +978,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintExpCommandBufferUpdatePointerArgDesc(
978978
/// - `buff_size < out_size`
979979
UR_APIEXPORT ur_result_t UR_APICALL urPrintExpCommandBufferUpdateValueArgDesc(const struct ur_exp_command_buffer_update_value_arg_desc_t params, char *buffer, const size_t buff_size, size_t *out_size);
980980

981-
///////////////////////////////////////////////////////////////////////////////
982-
/// @brief Print ur_exp_command_buffer_update_exec_info_desc_t struct
983-
/// @returns
984-
/// - ::UR_RESULT_SUCCESS
985-
/// - ::UR_RESULT_ERROR_INVALID_SIZE
986-
/// - `buff_size < out_size`
987-
UR_APIEXPORT ur_result_t UR_APICALL urPrintExpCommandBufferUpdateExecInfoDesc(const struct ur_exp_command_buffer_update_exec_info_desc_t params, char *buffer, const size_t buff_size, size_t *out_size);
988-
989981
///////////////////////////////////////////////////////////////////////////////
990982
/// @brief Print ur_exp_command_buffer_update_kernel_launch_desc_t struct
991983
/// @returns

include/ur_print.hpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
332332
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_exp_command_buffer_update_memobj_arg_desc_t params);
333333
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_exp_command_buffer_update_pointer_arg_desc_t params);
334334
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_exp_command_buffer_update_value_arg_desc_t params);
335-
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_exp_command_buffer_update_exec_info_desc_t params);
336335
inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_exp_command_buffer_update_kernel_launch_desc_t params);
337336
inline std::ostream &operator<<(std::ostream &os, enum ur_exp_peer_info_t value);
338337

@@ -1047,9 +1046,6 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_structure_type_t value
10471046
case UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_VALUE_ARG_DESC:
10481047
os << "UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_VALUE_ARG_DESC";
10491048
break;
1050-
case UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_EXEC_INFO_DESC:
1051-
os << "UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_EXEC_INFO_DESC";
1052-
break;
10531049
case UR_STRUCTURE_TYPE_EXP_SAMPLER_MIP_PROPERTIES:
10541050
os << "UR_STRUCTURE_TYPE_EXP_SAMPLER_MIP_PROPERTIES";
10551051
break;
@@ -1285,11 +1281,6 @@ inline ur_result_t printStruct(std::ostream &os, const void *ptr) {
12851281
printPtr(os, pstruct);
12861282
} break;
12871283

1288-
case UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_EXEC_INFO_DESC: {
1289-
const ur_exp_command_buffer_update_exec_info_desc_t *pstruct = (const ur_exp_command_buffer_update_exec_info_desc_t *)ptr;
1290-
printPtr(os, pstruct);
1291-
} break;
1292-
12931284
case UR_STRUCTURE_TYPE_EXP_SAMPLER_MIP_PROPERTIES: {
12941285
const ur_exp_sampler_mip_properties_t *pstruct = (const ur_exp_sampler_mip_properties_t *)ptr;
12951286
printPtr(os, pstruct);
@@ -9516,46 +9507,6 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_exp_command_bu
95169507
return os;
95179508
}
95189509
///////////////////////////////////////////////////////////////////////////////
9519-
/// @brief Print operator for the ur_exp_command_buffer_update_exec_info_desc_t type
9520-
/// @returns
9521-
/// std::ostream &
9522-
inline std::ostream &operator<<(std::ostream &os, const struct ur_exp_command_buffer_update_exec_info_desc_t params) {
9523-
os << "(struct ur_exp_command_buffer_update_exec_info_desc_t){";
9524-
9525-
os << ".stype = ";
9526-
9527-
os << (params.stype);
9528-
9529-
os << ", ";
9530-
os << ".pNext = ";
9531-
9532-
ur::details::printStruct(os,
9533-
(params.pNext));
9534-
9535-
os << ", ";
9536-
os << ".propName = ";
9537-
9538-
os << (params.propName);
9539-
9540-
os << ", ";
9541-
os << ".propSize = ";
9542-
9543-
os << (params.propSize);
9544-
9545-
os << ", ";
9546-
os << ".pProperties = ";
9547-
9548-
os << (params.pProperties);
9549-
9550-
os << ", ";
9551-
os << ".pNewExecInfo = ";
9552-
9553-
os << (params.pNewExecInfo);
9554-
9555-
os << "}";
9556-
return os;
9557-
}
9558-
///////////////////////////////////////////////////////////////////////////////
95599510
/// @brief Print operator for the ur_exp_command_buffer_update_kernel_launch_desc_t type
95609511
/// @returns
95619512
/// std::ostream &
@@ -9587,11 +9538,6 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_exp_command_bu
95879538

95889539
os << (params.numNewValueArgs);
95899540

9590-
os << ", ";
9591-
os << ".numNewExecInfos = ";
9592-
9593-
os << (params.numNewExecInfos);
9594-
95959541
os << ", ";
95969542
os << ".newWorkDim = ";
95979543

@@ -9630,17 +9576,6 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_exp_command_bu
96309576
}
96319577
os << "}";
96329578

9633-
os << ", ";
9634-
os << ".pNewExecInfoList = {";
9635-
for (size_t i = 0; (params.pNewExecInfoList) != NULL && i < params.numNewExecInfos; ++i) {
9636-
if (i != 0) {
9637-
os << ", ";
9638-
}
9639-
9640-
os << ((params.pNewExecInfoList))[i];
9641-
}
9642-
os << "}";
9643-
96449579
os << ", ";
96459580
os << ".pNewGlobalWorkOffset = {";
96469581
for (size_t i = 0; (params.pNewGlobalWorkOffset) != NULL && i < params.newWorkDim; ++i) {

scripts/core/EXP-COMMAND-BUFFER.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ Enums
256256
* ${X}_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_MEMOBJ_ARG_DESC
257257
* ${X}_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_POINTER_ARG_DESC
258258
* ${X}_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_VALUE_ARG_DESC
259-
* ${X}_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_EXEC_INFO_DESC
260259
* ${x}_command_t
261260
* ${X}_COMMAND_COMMAND_BUFFER_ENQUEUE_EXP
262261
* ${x}_function_t
@@ -290,7 +289,6 @@ Types
290289
* ${x}_exp_command_buffer_update_memobj_arg_desc_t
291290
* ${x}_exp_command_buffer_update_pointer_arg_desc_t
292291
* ${x}_exp_command_buffer_update_value_arg_desc_t
293-
* ${x}_exp_command_buffer_update_exec_info_desc_t
294292
* ${x}_exp_command_buffer_sync_point_t
295293
* ${x}_exp_command_buffer_handle_t
296294
* ${x}_exp_command_buffer_command_handle_t

0 commit comments

Comments
 (0)