Skip to content

Commit c6cceb1

Browse files
author
Ewan Crawford
authored
Use array for clUpdateMutableCommandsKHR. (KhronosGroup#1045)
Proposal to pass the update configs to `clUpdateMutableCommandsKHR` as an array, rather than pointer changed linked list. See KhronosGroup#1041 for motivation.
1 parent fed48e7 commit c6cceb1

3 files changed

Lines changed: 80 additions & 107 deletions

File tree

api/cl_khr_command_buffer_mutable_dispatch.asciidoc

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include::{generated}/meta/{refprefix}cl_khr_command_buffer_mutable_dispatch.txt[
66
=== Other Extension Metadata
77

88
*Last Modified Date*::
9-
2022-08-31
9+
2024-06-19
1010
*IP Status*::
1111
No known IP claims.
1212
*Contributors*::
@@ -43,32 +43,15 @@ in a new command-buffer.
4343

4444
=== Interactions With Other Extensions
4545

46-
The {cl_command_buffer_structure_type_khr_TYPE} type has been added to this
47-
extension for the purpose of allowing expansion of mutable functionality in
48-
future extensions layered on top of
49-
{cl_khr_command_buffer_mutable_dispatch_EXT}.
50-
Any parameter that is a structure containing a `void* next` member *must*
51-
have a value of `next` that is either `NULL`, or is a pointer to a valid
52-
structure defined by {cl_khr_command_buffer_mutable_dispatch_EXT} or an
53-
extension layered on top.
54-
To be a valid structure in the pointer chain the first member of the
55-
structure *must* be a {cl_command_buffer_structure_type_khr_TYPE} identifier
56-
for the structure being iterated through, and the second member a `void*
57-
next` pointer to the next structure in the chain.
58-
59-
[NOTE]
60-
====
61-
This approach is based on structure pointer chains in Vulkan, for more
62-
details see the "`Valid Usage for Structure Pointer Chains`" section of the
63-
Vulkan specification.
64-
====
65-
66-
This is designed so that another extension layered on
67-
{cl_khr_command_buffer_mutable_dispatch_EXT} could allow modification of
68-
commands recorded to a command-buffer other than kernel execution commands.
69-
As all command recording entry-points return a {cl_mutable_command_khr_TYPE}
70-
handle, and aspects like which {cl_mem_TYPE} object a command uses could
71-
also be updated between enqueues of the command-buffer.
46+
The {clUpdateMutableCommandsKHR} entry-point has been designed for the purpose
47+
of allowing expansion of mutable functionality in future extensions layered on
48+
top of `cl_khr_command_buffer_mutable_dispatch`.
49+
50+
A new extension can define its own structure type to specify the update
51+
configuration it requires, with a matching
52+
{cl_command_buffer_update_type_khr_TYPE} value. This new structure type can
53+
then be passed to {clUpdateMutableCommandsKHR} where it is reinterpreted from a
54+
void pointer using {cl_command_buffer_update_type_khr_TYPE}.
7255

7356
=== New Commands
7457

@@ -79,8 +62,7 @@ also be updated between enqueues of the command-buffer.
7962

8063
* {cl_mutable_dispatch_fields_khr_TYPE}
8164
* {cl_mutable_command_info_khr_TYPE}
82-
* {cl_command_buffer_structure_type_khr_TYPE}
83-
* {cl_mutable_base_config_khr_TYPE}
65+
* {cl_command_buffer_update_type_khr_TYPE}
8466
* {cl_mutable_dispatch_asserts_khr_TYPE}
8567
* {cl_mutable_dispatch_config_khr_TYPE}
8668
* {cl_mutable_dispatch_exec_info_khr_TYPE}
@@ -115,8 +97,7 @@ also be updated between enqueues of the command-buffer.
11597
** {CL_COMMAND_BUFFER_MUTABLE_KHR}
11698
* {cl_command_buffer_properties_khr_TYPE}
11799
** {CL_COMMAND_BUFFER_MUTABLE_DISPATCH_ASSERTS_KHR}
118-
* {cl_command_buffer_structure_type_khr_TYPE}
119-
** {CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR}
100+
* {cl_command_buffer_update_type_khr_TYPE}
120101
** {CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR}
121102
* New Error Codes
122103
** {CL_INVALID_MUTABLE_COMMAND_KHR}
@@ -274,8 +255,6 @@ kernel void vector_addition(global int* tile1, global int* tile2,
274255
cl_mutable_dispatch_arg_khr arg_2{2, sizeof(cl_mem), &output_buffer};
275256
cl_mutable_dispatch_arg_khr args[] = {arg_0, arg_1, arg_2};
276257
cl_mutable_dispatch_config_khr dispatch_config{
277-
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR,
278-
nullptr,
279258
command_handle,
280259
3 /* num_args */,
281260
0 /* num_svm_arg */,
@@ -287,12 +266,16 @@ kernel void vector_addition(global int* tile1, global int* tile2,
287266
nullptr /* global_work_offset */,
288267
nullptr /* global_work_size */,
289268
nullptr /* local_work_size */};
290-
cl_mutable_base_config_khr mutable_config{
291-
CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR, nullptr, 1,
292-
&dispatch_config};
293269
294270
// Update the command buffer with the mutable configuration
295-
error = clUpdateMutableCommandsKHR(command_buffer, &mutable_config);
271+
cl_uint num_configs = 1;
272+
cl_command_buffer_update_type_khr config_types[1] = {
273+
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR
274+
};
275+
const void* configs[1] = {&dispatch_config};
276+
error = clUpdateMutableCommandsKHR(command_buffer, num_configs,
277+
config_types, configs);
278+
296279
CL_CHECK(error);
297280
}
298281
@@ -374,3 +357,6 @@ may be a introduced as a stand alone extension.
374357
* Revision 0.9.1, 2023-11-07
375358
** Add type {cl_mutable_dispatch_asserts_khr_TYPE} and its possible values
376359
(provisional).
360+
* Revision 0.9.2, 2024-06-19
361+
** Change {clUpdateMutableCommandsKHR} API to pass configs as an array rather
362+
than linked list (provisional).

api/opencl_runtime_layer.asciidoc

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15647,7 +15647,7 @@ endif::cl_khr_command_buffer_multi_device[]
1564715647

1564815648
ifdef::cl_khr_command_buffer_mutable_dispatch[]
1564915649
[[mutable-commands]]
15650-
=== Mutable Commands:
15650+
=== Mutable Commands
1565115651

1565215652
A generic {cl_mutable_command_khr_TYPE} handle is called a _mutable-command_
1565315653
object as it can be returned from any command recording entry-point in the
@@ -15658,11 +15658,10 @@ modified through the fields of {cl_mutable_dispatch_config_khr_TYPE}.
1565815658

1565915659
Mutable-command handles are updated between enqueues using entry-point
1566015660
{clUpdateMutableCommandsKHR}.
15661-
To enable performant usage, all aspects of mutation are encapsulated inside
15662-
a single {cl_mutable_base_config_khr_TYPE} parameter.
15663-
This means that the runtime has access to all the information about how the
15664-
command-buffer will change, allowing the command-buffer to be rebuilt as
15665-
efficiently as possible.
15661+
To enable performant usage, all aspects of mutation can be passed in a single
15662+
call using an array. This means that the runtime has access to all the
15663+
information about how the command-buffer will change, allowing the
15664+
command-buffer to be rebuilt as efficiently as possible.
1566615665
Any modifications to the arguments or execution info of a mutable-dispatch
1566715666
handle using {cl_mutable_dispatch_arg_khr_TYPE} or
1566815667
{cl_mutable_dispatch_exec_info_khr_TYPE} have no affect on the original
@@ -15703,8 +15702,13 @@ include::{generated}/api/protos/clUpdateMutableCommandsKHR.txt[]
1570315702
include::{generated}/api/version-notes/clUpdateMutableCommandsKHR.asciidoc[]
1570415703

1570515704
* _command_buffer_ refers to a valid command-buffer object.
15706-
* _mutable_config_ is a pointer to a {cl_mutable_base_config_khr_TYPE}
15707-
structure defining updates to make to mutable-commands.
15705+
* _num_configs_ Number of elements in the _config_types_ and _config_ arrays.
15706+
* _config_types_ An array of length _num_configs_ with each element identifying
15707+
the type of each config in _configs_ at the same array index.
15708+
* _configs_ An array of length _num_configs_ containing structs which define how a
15709+
mutable-command handle in _command_buffer_ is to be updated, each of which is
15710+
interpreted using _config_types_ at the same index with the mapping defined
15711+
in the <<update-config-mapping, Mutable Command Update Structs>> section.
1570815712

1570915713
// refError
1571015714

@@ -15718,16 +15722,13 @@ one of the errors below is returned:
1571815722
* {CL_INVALID_OPERATION} if _command_buffer_ has not been finalized.
1571915723
* {CL_INVALID_OPERATION} if _command_buffer_ was not created with the
1572015724
{CL_COMMAND_BUFFER_MUTABLE_KHR} flag.
15721-
* {CL_INVALID_VALUE} if the _type_ member of _mutable_config_ is not
15722-
{CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR}.
15723-
* {CL_INVALID_VALUE} if the _mutable_dispatch_list_ member of
15724-
_mutable_config_ is `NULL` and _num_mutable_dispatch_ > 0, or
15725-
_mutable_dispatch_list_ is not `NULL` and _num_mutable_dispatch_ is 0.
15726-
* {CL_INVALID_VALUE} if the _next_ member of _mutable_config_ is not
15727-
`NULL` and any iteration of the structure pointer chain does not contain
15728-
valid _type_ and _next_ members.
15729-
* {CL_INVALID_VALUE} if _mutable_config_ is `NULL`, or if both _next_ and
15730-
_mutable_dispatch_list_ members of _mutable_config_ are `NULL`.
15725+
* {CL_INVALID_VALUE} if _config_types_ is `NULL` and _num_configs_ > 0, or
15726+
_config_types_ is not `NULL` and _num_configs_ is 0.
15727+
* {CL_INVALID_VALUE} if _configs_ is `NULL` and _num_configs_ > 0, or
15728+
_configs_ is not `NULL` and _num_configs_ is 0.
15729+
* {CL_INVALID_VALUE} if any element of _config_types_ is not a valid
15730+
{cl_command_buffer_update_type_khr_TYPE} enum.
15731+
* {CL_INVALID_VALUE} if any element of _configs_ is NULL.
1573115732
* {CL_OUT_OF_RESOURCES} if there is a failure to allocate resources
1573215733
required by the OpenCL implementation on the device.
1573315734
* {CL_OUT_OF_HOST_MEMORY} if there is a failure to allocate resources
@@ -15753,19 +15754,17 @@ parameters are updated so that the new number of work-groups exceeds the
1575315754
number when the ND-range command was recorded, the behavior is undefined.
1575415755
====
1575515756

15756-
If the _mutable_dispatch_list_ member of _mutable_config_ is non-`NULL`,
15757-
then errors defined by {clEnqueueNDRangeKernel}, {clSetKernelExecInfo},
15758-
{clSetKernelArg}, and {clSetKernelArgSVMPointer} are returned by
15759-
{clUpdateMutableCommandsKHR} if any of the array elements are set to an
15760-
invalid value.
15761-
Additionally, the following errors are returned if any
15762-
{cl_mutable_dispatch_config_khr_TYPE} element of the array violates the
15763-
defined conditions:
15757+
If _configs_ is non-`NULL`, then for any {cl_mutable_dispatch_config_khr_TYPE}
15758+
element of the array the errors defined by {clEnqueueNDRangeKernel},
15759+
{clSetKernelExecInfo}, {clSetKernelArg}, and {clSetKernelArgSVMPointer} are
15760+
returned by {clUpdateMutableCommandsKHR} if any of the struct elements are set
15761+
to an invalid value. Additionally, the following errors are returned if any
15762+
{cl_mutable_dispatch_config_khr_TYPE} element of the array violates the defined
15763+
conditions:
1576415764

1576515765
* {CL_INVALID_MUTABLE_COMMAND_KHR} if _command_ is not a valid mutable
15766-
command object, or created from _command_buffer_.
15767-
* {CL_INVALID_VALUE} if _type_ is not
15768-
{CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR}.
15766+
command object returned from {clCommandNDRangeKernelKHR}, or created from
15767+
_command_buffer_.
1576915768
* {CL_INVALID_OPERATION} if the values of _local_work_size_ and/or
1577015769
_global_work_size_ result in a change to work-group uniformity.
1577115770
* {CL_INVALID_OPERATION} if the _work_dim_ is different from the
@@ -15793,24 +15792,25 @@ defined conditions:
1579315792
0, or _exec_info_list_ is not `NULL` and _num_exec_infos_ is 0.
1579415793
--
1579515794

15796-
[open,refpage='cl_mutable_base_config_khr',desc='DESC',type='structs']
15797-
--
15798-
The {cl_mutable_base_config_khr_TYPE} structure encapsulates all aspects of
15799-
mutation and is defined as:
15795+
[[mutable-commands-update-structs]]
15796+
==== Mutable Command Update Structs
1580015797

15801-
include::{generated}/api/structs/cl_mutable_base_config_khr.txt[]
15798+
The following table defines the mapping of
15799+
{cl_command_buffer_update_type_khr_TYPE} values to the structs they define
15800+
reinterpreting a void pointer as when passed to {clUpdateMutableCommandsKHR}.
1580215801

15803-
* _type_ is the type of this structure, and must be
15804-
{CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR_anchor}
15805-
* _next_ is `NULL` or a pointer to an extending structure.
15806-
* _num_mutable_dispatch_ is the number of mutable-dispatch objects to
15807-
configure in this enqueue of the command-buffer.
15808-
* _mutable_dispatch_list_ is an array containing _num_mutable_dispatch_
15809-
elements describing the configurations of mutable kernel execution
15810-
commands in the command-buffer.
15811-
For a description of struct members making up each array element see
15812-
{cl_mutable_dispatch_config_khr_TYPE}.
15813-
--
15802+
[[update-config-mapping]]
15803+
[cols=",,",options="header",]
15804+
|====
15805+
| Enum Value | Struct Type | Entry Point
15806+
15807+
| {CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR_anchor}
15808+
| {cl_mutable_dispatch_config_khr_TYPE}
15809+
| {clCommandNDRangeKernelKHR}
15810+
15811+
|====
15812+
15813+
==== Kernel Command Update Structs
1581415814

1581515815
[open,refpage='cl_mutable_dispatch_config_khr',desc='Set kernel configuration of a mutable clCommandNDRangeKernelKHR command',type='structs']
1581615816
--
@@ -15820,9 +15820,6 @@ The {cl_mutable_dispatch_arg_khr_TYPE} structure is passed to
1582015820

1582115821
include::{generated}/api/structs/cl_mutable_dispatch_config_khr.txt[]
1582215822

15823-
* _type_ is the type of this structure, and must be
15824-
{CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR_anchor}.
15825-
* _next_ is `NULL` or a pointer to an extending structure.
1582615823
* _command_ is a mutable-command object returned by
1582715824
{clCommandNDRangeKernelKHR} representing a kernel execution as part of a
1582815825
command-buffer.

xml/cl.xml

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ server's OpenCL/api-docs repository.
249249
<type category="define">typedef struct _cl_mutable_command_khr* <name>cl_mutable_command_khr</name>;</type>
250250
<type category="define">typedef <type>cl_bitfield</type> <name>cl_mutable_dispatch_fields_khr</name>;</type>
251251
<type category="define">typedef <type>cl_uint</type> <name>cl_mutable_command_info_khr</name>;</type>
252-
<type category="define">typedef <type>cl_uint</type> <name>cl_command_buffer_structure_type_khr</name>;</type>
252+
<type category="define">typedef <type>cl_uint</type> <name>cl_command_buffer_update_type_khr</name>;</type>
253253
<type category="define">typedef <type>cl_bitfield</type> <name>cl_device_fp_atomic_capabilities_ext</name>;</type>
254254
<type category="define">typedef <type>cl_uint</type> <name>cl_image_requirements_info_ext</name>;</type>
255255
<type category="define">typedef <type>cl_bitfield</type> <name>cl_platform_command_buffer_capabilities_khr</name>;</type>
@@ -370,8 +370,6 @@ server's OpenCL/api-docs repository.
370370
<member>const <type>void</type>* <name>param_value</name></member>
371371
</type>
372372
<type category="struct" name="cl_mutable_dispatch_config_khr">
373-
<member><type>cl_command_buffer_structure_type_khr</type> <name>type</name></member>
374-
<member>const <type>void</type>* <name>next</name></member>
375373
<member><type>cl_mutable_command_khr</type> <name>command</name></member>
376374
<member><type>cl_uint</type> <name>num_args</name></member>
377375
<member><type>cl_uint</type> <name>num_svm_args</name></member>
@@ -384,13 +382,6 @@ server's OpenCL/api-docs repository.
384382
<member>const <type>size_t</type>* <name>global_work_size</name></member>
385383
<member>const <type>size_t</type>* <name>local_work_size</name></member>
386384
</type>
387-
388-
<type category="struct" name="cl_mutable_base_config_khr">
389-
<member><type>cl_command_buffer_structure_type_khr</type> <name>type</name></member>
390-
<member>const <type>void</type>* <name>next</name></member>
391-
<member><type>cl_uint</type> <name>num_mutable_dispatch</name></member>
392-
<member>const <type>cl_mutable_dispatch_config_khr</type>* <name>mutable_dispatch_list</name></member>
393-
</type>
394385
</types>
395386

396387
<!-- SECTION: OpenCL enumerant (token) definitions. -->
@@ -1370,10 +1361,9 @@ server's OpenCL/api-docs repository.
13701361
<enum bitpos="0" name="CL_MUTABLE_DISPATCH_ASSERT_NO_ADDITIONAL_WORK_GROUPS_KHR"/>
13711362
</enums>
13721363

1373-
<enums name="cl_command_buffer_structure_type_khr" vendor="Khronos">
1374-
<enum value="0" name="CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR"/>
1375-
<enum value="1" name="CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR"/>
1376-
<unused start="2" end="2" comment="Used by future command-buffer extensions"/>
1364+
<enums name="cl_command_buffer_update_type_khr" vendor="Khronos">
1365+
<enum value="0" name="CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR"/>
1366+
<unused start="1" end="1" comment="Used by future command-buffer extensions"/>
13771367
</enums>
13781368

13791369
<enums name="cl_device_fp_atomic_capabilities_ext" vendor="EXT" type="bitmask">
@@ -3280,9 +3270,11 @@ server's OpenCL/api-docs repository.
32803270
<param><type>size_t</type>* <name>param_value_size_ret</name></param>
32813271
</command>
32823272
<command>
3283-
<proto><type>cl_int</type> <name>clUpdateMutableCommandsKHR</name></proto>
3284-
<param><type>cl_command_buffer_khr</type> <name>command_buffer</name></param>
3285-
<param>const <type>cl_mutable_base_config_khr</type>* <name>mutable_config</name></param>
3273+
<proto><type>cl_int</type> <name>clUpdateMutableCommandsKHR</name></proto>
3274+
<param><type>cl_command_buffer_khr</type> <name>command_buffer</name></param>
3275+
<param><type>cl_uint</type> <name>num_configs</name></param>
3276+
<param>const <type>cl_command_buffer_update_type_khr</type>* <name>config_types</name></param>
3277+
<param>const <type>void</type>** <name>configs</name></param>
32863278
</command>
32873279
<command>
32883280
<proto><type>cl_int</type> <name>clGetMutableCommandInfoKHR</name></proto>
@@ -7324,18 +7316,17 @@ server's OpenCL/api-docs repository.
73247316
<enum name="CL_QUEUE_JOB_SLOT_ARM"/>
73257317
</require>
73267318
</extension>
7327-
<extension name="cl_khr_command_buffer_mutable_dispatch" revision="0.9.1" supported="opencl" depends="cl_khr_command_buffer" ratified="opencl" provisional="true" comment="requires cl_khr_command_buffer 0.9.0 or later">
7319+
<extension name="cl_khr_command_buffer_mutable_dispatch" revision="0.9.2" supported="opencl" depends="cl_khr_command_buffer" ratified="opencl" provisional="true" comment="requires cl_khr_command_buffer 0.9.0 or later">
73287320
<require>
73297321
<type name="CL/cl.h"/>
73307322
</require>
73317323
<require>
7332-
<type name="cl_command_buffer_structure_type_khr"/>
7324+
<type name="cl_command_buffer_update_type_khr"/>
73337325
<type name="cl_mutable_dispatch_fields_khr"/>
73347326
<type name="cl_mutable_command_info_khr"/>
73357327
<type name="cl_mutable_dispatch_arg_khr"/>
73367328
<type name="cl_mutable_dispatch_exec_info_khr"/>
73377329
<type name="cl_mutable_dispatch_config_khr"/>
7338-
<type name="cl_mutable_base_config_khr"/>
73397330
<type name="cl_mutable_dispatch_asserts_khr"/>
73407331
</require>
73417332
<require comment="cl_command_buffer_flags_khr - bitfield">
@@ -7369,8 +7360,7 @@ server's OpenCL/api-docs repository.
73697360
<enum name="CL_MUTABLE_DISPATCH_GLOBAL_WORK_SIZE_KHR"/>
73707361
<enum name="CL_MUTABLE_DISPATCH_LOCAL_WORK_SIZE_KHR"/>
73717362
</require>
7372-
<require comment="cl_command_buffer_structure_type_khr">
7373-
<enum name="CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR"/>
7363+
<require comment="cl_command_buffer_update_type_khr">
73747364
<enum name="CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR"/>
73757365
</require>
73767366
<require comment="cl_command_buffer_properties_khr">

0 commit comments

Comments
 (0)