Skip to content

Commit 7735328

Browse files
author
Fábio Mestre
committed
Update spec to have less errors
1 parent ee44a0b commit 7735328

25 files changed

+472
-216
lines changed

include/ur_api.h

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8275,9 +8275,11 @@ typedef struct ur_exp_command_buffer_update_kernel_launch_desc_t {
82758275
ur_structure_type_t stype; ///< [in] type of this structure, must be
82768276
///< ::UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_KERNEL_LAUNCH_DESC
82778277
const void *pNext; ///< [in][optional] pointer to extension-specific structure
8278-
ur_kernel_handle_t hNewKernel; ///< [in] The new kernel handle. If this value is equal to the current
8279-
///< kernel handle associated
8280-
///< with the command, then only the arguments to the kernel will be updated.
8278+
ur_kernel_handle_t hNewKernel; ///< [in][optional] The new kernel handle. If this parameter is nullptr,
8279+
///< the current kernel handle in `hCommand`
8280+
///< will be used. If a kernel handle is passed, it must be a valid kernel
8281+
///< alternative as defined in
8282+
///< ::urCommandBufferAppendKernelLaunchExp.
82818283
uint32_t numNewMemObjArgs; ///< [in] Length of pNewMemObjArgList.
82828284
uint32_t numNewPointerArgs; ///< [in] Length of pNewPointerArgList.
82838285
uint32_t numNewValueArgs; ///< [in] Length of pNewValueArgList.
@@ -8289,13 +8291,25 @@ typedef struct ur_exp_command_buffer_update_kernel_launch_desc_t {
82898291
const ur_exp_command_buffer_update_value_arg_desc_t *pNewValueArgList; ///< [in][optional][range(0, numNewValueArgs)] An array describing the new
82908292
///< kernel value arguments for the command.
82918293
size_t *pNewGlobalWorkOffset; ///< [in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned
8292-
///< values that describe the offset used to calculate the global ID.
8294+
///< values that describe the offset used
8295+
///< to calculate the global ID. If this parameter is nullptr, the current
8296+
///< global work offset will be used. This parameter is required if
8297+
///< `newWorkDim` is different from the current work dimensions
8298+
///< in the command.
82938299
size_t *pNewGlobalWorkSize; ///< [in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned
8294-
///< values that describe the number of global work-items.
8300+
///< values that describe the number of
8301+
///< global work-items. If this parameter is nullptr, the current global
8302+
///< work size in `hCommand` will be used.
8303+
///< This parameter is required if `newWorkDim` is different from the
8304+
///< current work dimensions in the command.
82958305
size_t *pNewLocalWorkSize; ///< [in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned
8296-
///< values that describe the number of work-items that make up a
8297-
///< work-group. If pNewLocalWorkSize is nullptr, then the local work size
8298-
///< is unchanged.
8306+
///< values that describe the number of
8307+
///< work-items that make up a work-group. If `pNewGlobalWorkSize` is set
8308+
///< and `pNewLocalWorkSize` is nullptr,
8309+
///< then the runtime implementation will choose the local work size. If
8310+
///< `pNewGlobalWorkSize` is nullptr and
8311+
///< `pNewLocalWorkSize` is nullptr, the current local work size in the
8312+
///< command will be used.
82998313

83008314
} ur_exp_command_buffer_update_kernel_launch_desc_t;
83018315

@@ -8438,8 +8452,8 @@ urCommandBufferAppendKernelLaunchExp(
84388452
///< implementation.
84398453
uint32_t numKernelAlternatives, ///< [in] The number of kernel alternatives provided in
84408454
///< phKernelAlternatives.
8441-
ur_kernel_handle_t *phKernelAlternatives, ///< [in][optional][range(0, numKernelAlternatives)] List of kernels
8442-
///< handles that might be used to update the kernel in this
8455+
ur_kernel_handle_t *phKernelAlternatives, ///< [in][optional][range(0, numKernelAlternatives)] List of kernel handles
8456+
///< that might be used to update the kernel in this
84438457
///< command after the command-buffer is finalized. The default kernel
84448458
///< `hKernel` is implicitly marked as an alternative. It's
84458459
///< invalid to specify it as part of this list.
@@ -8950,26 +8964,69 @@ urCommandBufferReleaseCommandExp(
89508964
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
89518965
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
89528966
/// + `NULL == hCommand`
8953-
/// + `NULL == pUpdateKernelLaunch->hNewKernel`
89548967
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
89558968
/// + `NULL == pUpdateKernelLaunch`
89568969
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
89578970
/// + If update functionality is not supported by the device.
89588971
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
89598972
/// + If ::ur_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to.
89608973
/// + If the command-buffer `hCommand` belongs to has not been finalized.
8961-
/// + `pUpdateKernelLaunch->pNewLocalWorkSize != NULL && pUpdateKernelLaunch->pNewGlobalWorkSize == NULL`
8962-
/// + If `pUpdateKernellaunch->hNewKernel` is equal to the currently active kernel in `hCommand`, and `pUpdateKernellaunch->newWorkDim` is different from the work-dim currently associated with `hCommand`.
89638974
/// - ::UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
89648975
/// - ::UR_RESULT_ERROR_INVALID_MEM_OBJECT
89658976
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX
89668977
/// - ::UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE
89678978
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
89688979
/// - ::UR_RESULT_ERROR_INVALID_WORK_DIMENSION
8969-
/// + `pUpdateKernelLaunch->newWorkDim < 0 || pUpdateKernelLaunch->newWorkDim > 3`
8980+
/// + `pUpdateKernelLaunch->newWorkDim < 1 || pUpdateKernelLaunch->newWorkDim > 3`
89708981
/// - ::UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
89718982
/// - ::UR_RESULT_ERROR_INVALID_VALUE
8972-
/// + If `pUpdateKernelLaunch->hNewKernel` was not passed to the `hKernel` or `phKernelAlternatives` parameters of ::urCommandBufferAppendKernelLaunchExp when this command was created.
8983+
/// + *
8984+
/// +
8985+
/// + I
8986+
/// + f
8987+
/// + `
8988+
/// + p
8989+
/// + U
8990+
/// + d
8991+
/// + a
8992+
/// + t
8993+
/// + e
8994+
/// + K
8995+
/// + r
8996+
/// + n
8997+
/// + l
8998+
/// + L
8999+
/// + u
9000+
/// + c
9001+
/// + h
9002+
/// + -
9003+
/// + >
9004+
/// + N
9005+
/// + w
9006+
/// + s
9007+
/// + o
9008+
/// + A
9009+
/// + i
9010+
/// + v
9011+
/// +
9012+
9013+
/// + m
9014+
/// + $
9015+
/// + x
9016+
/// + C
9017+
/// + B
9018+
/// + E
9019+
/// + .
9020+
/// + "
9021+
/// + W
9022+
/// + k
9023+
/// + D
9024+
/// + ,
9025+
/// + G
9026+
/// + b
9027+
/// + S
9028+
/// + z
9029+
/// + O
89739030
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
89749031
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
89759032
UR_APIEXPORT ur_result_t UR_APICALL

scripts/core/exp-command-buffer.yml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ members:
195195
- type: $x_kernel_handle_t
196196
name: hNewKernel
197197
desc: |
198-
[in] The new kernel handle. If this value is equal to the current kernel handle associated
199-
with the command, then only the arguments to the kernel will be updated.
198+
[in][optional] The new kernel handle. If this parameter is nullptr, the current kernel handle in `hCommand`
199+
will be used. If a kernel handle is passed, it must be a valid kernel alternative as defined in
200+
$xCommandBufferAppendKernelLaunchExp.
200201
- type: uint32_t
201202
name: numNewMemObjArgs
202203
desc: "[in] Length of pNewMemObjArgList."
@@ -220,13 +221,23 @@ members:
220221
desc: "[in][optional][range(0, numNewValueArgs)] An array describing the new kernel value arguments for the command."
221222
- type: "size_t*"
222223
name: pNewGlobalWorkOffset
223-
desc: "[in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned values that describe the offset used to calculate the global ID."
224+
desc: |
225+
[in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned values that describe the offset used
226+
to calculate the global ID. If this parameter is nullptr, the current global work offset will be used. This parameter is required if `newWorkDim` is different from the current work dimensions
227+
in the command.
224228
- type: "size_t*"
225229
name: pNewGlobalWorkSize
226-
desc: "[in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned values that describe the number of global work-items."
230+
desc: |
231+
[in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned values that describe the number of
232+
global work-items. If this parameter is nullptr, the current global work size in `hCommand` will be used.
233+
This parameter is required if `newWorkDim` is different from the current work dimensions in the command.
227234
- type: "size_t*"
228235
name: pNewLocalWorkSize
229-
desc: "[in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned values that describe the number of work-items that make up a work-group. If pNewLocalWorkSize is nullptr, then the local work size is unchanged."
236+
desc: |
237+
[in][optional][range(0, newWorkDim)] Array of newWorkDim unsigned values that describe the number of
238+
work-items that make up a work-group. If `pNewGlobalWorkSize` is set and `pNewLocalWorkSize` is nullptr,
239+
then the runtime implementation will choose the local work size. If `pNewGlobalWorkSize` is nullptr and
240+
`pNewLocalWorkSize` is nullptr, the current local work size in the command will be used.
230241
--- #--------------------------------------------------------------------------
231242
type: typedef
232243
desc: "A value that identifies a command inside of a command-buffer, used for defining dependencies between commands in the same command-buffer."
@@ -340,7 +351,7 @@ params:
340351
- type: $x_kernel_handle_t*
341352
name: "phKernelAlternatives"
342353
desc: |
343-
[in][optional][range(0, numKernelAlternatives)] List of kernels handles that might be used to update the kernel in this
354+
[in][optional][range(0, numKernelAlternatives)] List of kernel handles that might be used to update the kernel in this
344355
command after the command-buffer is finalized. The default kernel `hKernel` is implicitly marked as an alternative. It's
345356
invalid to specify it as part of this list.
346357
- type: uint32_t
@@ -954,18 +965,19 @@ returns:
954965
- $X_RESULT_ERROR_INVALID_OPERATION:
955966
- "If $x_exp_command_buffer_desc_t::isUpdatable was not set to true on creation of the command buffer `hCommand` belongs to."
956967
- "If the command-buffer `hCommand` belongs to has not been finalized."
957-
- "`pUpdateKernelLaunch->pNewLocalWorkSize != NULL && pUpdateKernelLaunch->pNewGlobalWorkSize == NULL`"
958-
- "If `pUpdateKernellaunch->hNewKernel` is equal to the currently active kernel in `hCommand`, and `pUpdateKernellaunch->newWorkDim` is different from the work-dim currently associated with `hCommand`."
959968
- $X_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP
960969
- $X_RESULT_ERROR_INVALID_MEM_OBJECT
961970
- $X_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX
962971
- $X_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE
963972
- $X_RESULT_ERROR_INVALID_ENUMERATION
964973
- $X_RESULT_ERROR_INVALID_WORK_DIMENSION:
965-
- "`pUpdateKernelLaunch->newWorkDim < 0 || pUpdateKernelLaunch->newWorkDim > 3`"
974+
- "`pUpdateKernelLaunch->newWorkDim < 1 || pUpdateKernelLaunch->newWorkDim > 3`"
966975
- $X_RESULT_ERROR_INVALID_WORK_GROUP_SIZE
967-
- $X_RESULT_ERROR_INVALID_VALUE:
968-
- "If `pUpdateKernelLaunch->hNewKernel` was not passed to the `hKernel` or `phKernelAlternatives` parameters of $xCommandBufferAppendKernelLaunchExp when this command was created."
976+
- $X_RESULT_ERROR_INVALID_VALUE: |
977+
* If `pUpdateKernelLaunch->hNewKernel` was not passed to the `hKernel` or `phKernelAlternatives`
978+
parameters of $xCommandBufferAppendKernelLaunchExp when this command was created.
979+
* "If `pUpdateKernelLaunch->newWorkDim` is different from the current workDim in `hCommand` and,
980+
pUpdateKernelLaunch->pNewGlobalWorkSize, or pUpdateKernelLaunch->pNewGlobalWorkOffset are nullptr.
969981
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
970982
- $X_RESULT_ERROR_OUT_OF_RESOURCES
971983
--- #--------------------------------------------------------------------------

source/adapters/cuda/command_buffer.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -877,22 +877,19 @@ validateCommandDesc(ur_exp_command_buffer_command_handle_t Command,
877877

878878
auto CommandBuffer = Command->CommandBuffer;
879879

880-
// Update requires command-buffer to be finalized
881-
if (!CommandBuffer->CudaGraphExec) {
882-
return UR_RESULT_ERROR_INVALID_OPERATION;
883-
}
884-
885-
// Update requires command-buffer to be created with update enabled
886-
if (!CommandBuffer->IsUpdatable) {
880+
// Update requires the command-buffer to be finalized and updatable.
881+
if (!CommandBuffer->CudaGraphExec || !CommandBuffer->IsUpdatable) {
887882
return UR_RESULT_ERROR_INVALID_OPERATION;
888883
}
889884

890885
if (UpdateCommandDesc->newWorkDim != Command->WorkDim &&
891-
Command->Kernel == UpdateCommandDesc->hNewKernel) {
892-
return UR_RESULT_ERROR_INVALID_OPERATION;
886+
(!UpdateCommandDesc->pNewGlobalWorkOffset ||
887+
!UpdateCommandDesc->pNewGlobalWorkSize)) {
888+
return UR_RESULT_ERROR_INVALID_VALUE;
893889
}
894890

895-
if (!Command->ValidKernelHandles.count(UpdateCommandDesc->hNewKernel)) {
891+
if (UpdateCommandDesc->hNewKernel &&
892+
!Command->ValidKernelHandles.count(UpdateCommandDesc->hNewKernel)) {
896893
return UR_RESULT_ERROR_INVALID_VALUE;
897894
}
898895
return UR_RESULT_SUCCESS;
@@ -987,7 +984,9 @@ updateCommand(ur_exp_command_buffer_command_handle_t Command,
987984
const ur_exp_command_buffer_update_kernel_launch_desc_t
988985
*UpdateCommandDesc) {
989986

990-
Command->Kernel = UpdateCommandDesc->hNewKernel;
987+
if (UpdateCommandDesc->hNewKernel) {
988+
Command->Kernel = UpdateCommandDesc->hNewKernel;
989+
}
991990

992991
if (UpdateCommandDesc->newWorkDim) {
993992
Command->WorkDim = UpdateCommandDesc->newWorkDim;
@@ -999,6 +998,9 @@ updateCommand(ur_exp_command_buffer_command_handle_t Command,
999998

1000999
if (UpdateCommandDesc->pNewGlobalWorkSize) {
10011000
Command->setGlobalSize(UpdateCommandDesc->pNewGlobalWorkSize);
1001+
if (!UpdateCommandDesc->pNewLocalWorkSize) {
1002+
Command->setNullLocalSize();
1003+
}
10021004
}
10031005

10041006
if (UpdateCommandDesc->pNewLocalWorkSize) {

source/adapters/cuda/command_buffer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ struct ur_exp_command_buffer_command_handle_t_ {
7575
}
7676
}
7777

78+
void setNullLocalSize() noexcept {
79+
std::memset(LocalWorkSize, 0, sizeof(size_t) * 3);
80+
}
81+
7882
bool isNullLocalSize() const noexcept {
7983
const size_t Zeros[3] = {0, 0, 0};
8084
return 0 == std::memcmp(LocalWorkSize, Zeros, sizeof(LocalWorkSize));

source/adapters/hip/command_buffer.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -862,22 +862,19 @@ validateCommandDesc(ur_exp_command_buffer_command_handle_t Command,
862862

863863
auto CommandBuffer = Command->CommandBuffer;
864864

865-
// Update requires command-buffer to be finalized
866-
if (!CommandBuffer->HIPGraphExec) {
867-
return UR_RESULT_ERROR_INVALID_OPERATION;
868-
}
869-
870-
// Update requires command-buffer to be created with update enabled
871-
if (!CommandBuffer->IsUpdatable) {
865+
// Update requires the command-buffer to be finalized and updatable.
866+
if (!CommandBuffer->HIPGraphExec || !CommandBuffer->IsUpdatable) {
872867
return UR_RESULT_ERROR_INVALID_OPERATION;
873868
}
874869

875870
if (UpdateCommandDesc->newWorkDim != Command->WorkDim &&
876-
Command->Kernel == UpdateCommandDesc->hNewKernel) {
877-
return UR_RESULT_ERROR_INVALID_OPERATION;
871+
(!UpdateCommandDesc->pNewGlobalWorkOffset ||
872+
!UpdateCommandDesc->pNewGlobalWorkSize)) {
873+
return UR_RESULT_ERROR_INVALID_VALUE;
878874
}
879875

880-
if (!Command->ValidKernelHandles.count(UpdateCommandDesc->hNewKernel)) {
876+
if (UpdateCommandDesc->hNewKernel &&
877+
!Command->ValidKernelHandles.count(UpdateCommandDesc->hNewKernel)) {
881878
return UR_RESULT_ERROR_INVALID_VALUE;
882879
}
883880

@@ -967,7 +964,9 @@ updateCommand(ur_exp_command_buffer_command_handle_t Command,
967964
const ur_exp_command_buffer_update_kernel_launch_desc_t
968965
*UpdateCommandDesc) {
969966

970-
Command->Kernel = UpdateCommandDesc->hNewKernel;
967+
if (UpdateCommandDesc->hNewKernel) {
968+
Command->Kernel = UpdateCommandDesc->hNewKernel;
969+
}
971970

972971
if (UpdateCommandDesc->hNewKernel) {
973972
Command->WorkDim = UpdateCommandDesc->newWorkDim;
@@ -979,6 +978,9 @@ updateCommand(ur_exp_command_buffer_command_handle_t Command,
979978

980979
if (UpdateCommandDesc->pNewGlobalWorkSize) {
981980
Command->setGlobalSize(UpdateCommandDesc->pNewGlobalWorkSize);
981+
if (!UpdateCommandDesc->pNewLocalWorkSize) {
982+
Command->setNullLocalSize();
983+
}
982984
}
983985

984986
if (UpdateCommandDesc->pNewLocalWorkSize) {

source/adapters/hip/command_buffer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ struct ur_exp_command_buffer_command_handle_t_ {
7474
}
7575
}
7676

77+
void setNullLocalSize() noexcept {
78+
std::memset(LocalWorkSize, 0, sizeof(size_t) * 3);
79+
}
80+
7781
bool isNullLocalSize() const noexcept {
7882
const size_t Zeros[3] = {0, 0, 0};
7983
return 0 == std::memcmp(LocalWorkSize, Zeros, sizeof(LocalWorkSize));

source/adapters/level_zero/command_buffer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,10 +1325,10 @@ ur_result_t validateCommandDesc(
13251325
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
13261326
}
13271327

1328-
// Error if work dim changes
1329-
if (CommandDesc->hNewKernel == Command->Kernel &&
1330-
CommandDesc->newWorkDim != Command->WorkDim) {
1331-
return UR_RESULT_ERROR_INVALID_OPERATION;
1328+
if (CommandDesc->newWorkDim != Command->WorkDim &&
1329+
(!CommandDesc->pNewGlobalWorkOffset ||
1330+
!CommandDesc->pNewGlobalWorkSize)) {
1331+
return UR_RESULT_ERROR_INVALID_VALUE;
13321332
}
13331333

13341334
// Check if new global offset is provided.

0 commit comments

Comments
 (0)