Skip to content

Commit 2673582

Browse files
committed
Use array for clUpdateMutableCommandsKHR.
Proposal to pass the update configs to `clUpdateMutableCommandsKHR` as an array, rather than pointer changed linked list. See #1041 for motivation.
1 parent 00c7969 commit 2673582

File tree

3 files changed

+80
-107
lines changed

3 files changed

+80
-107
lines changed

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-03-22
1010
*IP Status*::
1111
No known IP claims.
1212
*Contributors*::
@@ -43,39 +43,21 @@ 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`.
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` 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` 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 Types
7457

7558
* {cl_mutable_dispatch_fields_khr_TYPE}
7659
* {cl_mutable_command_info_khr_TYPE}
77-
* {cl_command_buffer_structure_type_khr_TYPE}
78-
* {cl_mutable_base_config_khr_TYPE}
60+
* {cl_command_buffer_update_type_khr_TYPE}
7961
* {cl_mutable_dispatch_asserts_khr_TYPE}
8062
* {cl_mutable_dispatch_config_khr_TYPE}
8163
* {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, 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
@@ -376,3 +359,6 @@ include::provisional_notice.asciidoc[]
376359
* Revision 0.9.1, 2023-11-07
377360
** Add type {cl_mutable_dispatch_asserts_khr_TYPE} and its possible values
378361
(provisional).
362+
* Revision 0.9.2, 2024-03-22
363+
** Change {clUpdateMutableCommandsKHR} API to pass configs as an array rather
364+
than linked list (provisional).

api/opencl_runtime_layer.asciidoc

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

1565015650
ifdef::cl_khr_command_buffer_mutable_dispatch[]
1565115651
[[mutable-commands]]
15652-
=== Mutable Commands:
15652+
=== Mutable Commands
1565315653

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

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

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

1571115715
// refError
1571215716

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

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

1576715767
* {CL_INVALID_MUTABLE_COMMAND_KHR} if _command_ is not a valid mutable
15768-
command object, or created from _command_buffer_.
15769-
* {CL_INVALID_VALUE} if _type_ is not
15770-
{CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR}.
15768+
command object returned from {clCommandNDRangeKernelKHR}, or created from
15769+
_command_buffer_.
1577115770
* {CL_INVALID_OPERATION} if the values of _local_work_size_ and/or
1577215771
_global_work_size_ result in a change to work-group uniformity.
1577315772
* {CL_INVALID_OPERATION} if the _work_dim_ is different from the
@@ -15795,24 +15794,25 @@ defined conditions:
1579515794
0, or _exec_info_list_ is not `NULL` and _num_exec_infos_ is 0.
1579615795
--
1579715796

15798-
[open,refpage='cl_mutable_base_config_khr',desc='DESC',type='structs']
15799-
--
15800-
The {cl_mutable_base_config_khr_TYPE} structure is TODO Add fuller
15801-
description here and is defined as:
15797+
[[mutable-commands-update-structs]]
15798+
==== Mutable Command Update Structs
1580215799

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

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

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

1582315823
include::{generated}/api/structs/cl_mutable_dispatch_config_khr.txt[]
1582415824

15825-
* _type_ is the type of this structure, and must be
15826-
{CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR}.
15827-
* _next_ is `NULL` or a pointer to an extending structure.
1582815825
* _command_ is a mutable-command object returned by
1582915826
{clCommandNDRangeKernelKHR} representing a kernel execution as part of a
1583015827
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>
@@ -354,8 +354,6 @@ server's OpenCL/api-docs repository.
354354
<member>const <type>void</type>* <name>param_value</name></member>
355355
</type>
356356
<type category="struct" name="cl_mutable_dispatch_config_khr">
357-
<member><type>cl_command_buffer_structure_type_khr</type> <name>type</name></member>
358-
<member>const <type>void</type>* <name>next</name></member>
359357
<member><type>cl_mutable_command_khr</type> <name>command</name></member>
360358
<member><type>cl_uint</type> <name>num_args</name></member>
361359
<member><type>cl_uint</type> <name>num_svm_args</name></member>
@@ -368,13 +366,6 @@ server's OpenCL/api-docs repository.
368366
<member>const <type>size_t</type>* <name>global_work_size</name></member>
369367
<member>const <type>size_t</type>* <name>local_work_size</name></member>
370368
</type>
371-
372-
<type category="struct" name="cl_mutable_base_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>
375-
<member><type>cl_uint</type> <name>num_mutable_dispatch</name></member>
376-
<member>const <type>cl_mutable_dispatch_config_khr</type>* <name>mutable_dispatch_list</name></member>
377-
</type>
378369
</types>
379370

380371
<!-- SECTION: OpenCL enumerant (token) definitions. -->
@@ -1354,10 +1345,9 @@ server's OpenCL/api-docs repository.
13541345
<enum bitpos="0" name="CL_MUTABLE_DISPATCH_ASSERT_NO_ADDITIONAL_WORK_GROUPS_KHR"/>
13551346
</enums>
13561347

1357-
<enums name="cl_command_buffer_structure_type_khr" vendor="Khronos">
1358-
<enum value="0" name="CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR"/>
1359-
<enum value="1" name="CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR"/>
1360-
<unused start="2" end="2" comment="Used by future command-buffer extensions"/>
1348+
<enums name="cl_command_buffer_update_type_khr" vendor="Khronos">
1349+
<enum value="0" name="CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR"/>
1350+
<unused start="1" end="1" comment="Used by future command-buffer extensions"/>
13611351
</enums>
13621352

13631353
<enums name="cl_device_fp_atomic_capabilities_ext" vendor="EXT" type="bitmask">
@@ -3259,9 +3249,11 @@ server's OpenCL/api-docs repository.
32593249
<param><type>size_t</type>* <name>param_value_size_ret</name></param>
32603250
</command>
32613251
<command>
3262-
<proto><type>cl_int</type> <name>clUpdateMutableCommandsKHR</name></proto>
3263-
<param><type>cl_command_buffer_khr</type> <name>command_buffer</name></param>
3264-
<param>const <type>cl_mutable_base_config_khr</type>* <name>mutable_config</name></param>
3252+
<proto><type>cl_int</type> <name>clUpdateMutableCommandsKHR</name></proto>
3253+
<param><type>cl_command_buffer_khr</type> <name>command_buffer</name></param>
3254+
<param><type>cl_uint</type> <name>num_configs</name></param>
3255+
<param>const <type>cl_command_buffer_update_type_khr</type>* <name>config_types</name></param>
3256+
<param>const <type>void</type>** <name>configs</name></param>
32653257
</command>
32663258
<command>
32673259
<proto><type>cl_int</type> <name>clGetMutableCommandInfoKHR</name></proto>
@@ -7308,18 +7300,17 @@ server's OpenCL/api-docs repository.
73087300
<enum name="CL_QUEUE_JOB_SLOT_ARM"/>
73097301
</require>
73107302
</extension>
7311-
<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">
7303+
<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">
73127304
<require>
73137305
<type name="CL/cl.h"/>
73147306
</require>
73157307
<require>
7316-
<type name="cl_command_buffer_structure_type_khr"/>
7308+
<type name="cl_command_buffer_update_type_khr"/>
73177309
<type name="cl_mutable_dispatch_fields_khr"/>
73187310
<type name="cl_mutable_command_info_khr"/>
73197311
<type name="cl_mutable_dispatch_arg_khr"/>
73207312
<type name="cl_mutable_dispatch_exec_info_khr"/>
73217313
<type name="cl_mutable_dispatch_config_khr"/>
7322-
<type name="cl_mutable_base_config_khr"/>
73237314
<type name="cl_mutable_dispatch_asserts_khr"/>
73247315
</require>
73257316
<require comment="cl_command_buffer_flags_khr - bitfield">
@@ -7353,8 +7344,7 @@ server's OpenCL/api-docs repository.
73537344
<enum name="CL_MUTABLE_DISPATCH_GLOBAL_WORK_SIZE_KHR"/>
73547345
<enum name="CL_MUTABLE_DISPATCH_LOCAL_WORK_SIZE_KHR"/>
73557346
</require>
7356-
<require comment="cl_command_buffer_structure_type_khr">
7357-
<enum name="CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR"/>
7347+
<require comment="cl_command_buffer_update_type_khr">
73587348
<enum name="CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR"/>
73597349
</require>
73607350
<require comment="cl_command_buffer_properties_khr">

0 commit comments

Comments
 (0)