Skip to content

Commit a2efd6b

Browse files
Kerilkbashbaug
andauthored
Extension of cl_khr_icd to 2.0.0 with loader managed dispatch. (KhronosGroup#1005)
* Extension of cl_khr_icd to 2.0.0 with loader managed dispatch. * update last modified dates --------- Co-authored-by: Ben Ashbaugh <ben.ashbaugh@intel.com>
1 parent 60969ff commit a2efd6b

4 files changed

Lines changed: 121 additions & 3 deletions

File tree

api/cl_khr_icd.asciidoc

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include::{generated}/meta/{refprefix}cl_khr_icd.txt[]
99
=== Other Extension Metadata
1010

1111
*Last Modified Date*::
12-
2020-04-21
12+
2025-04-01
1313
*IP Status*::
1414
No known IP claims.
1515

@@ -48,6 +48,8 @@ An object is said to be ICD compatible if it is of the following structure:
4848
struct _cl_<object>
4949
{
5050
struct _cl_icd_dispatch *dispatch;
51+
// Since version 2.0.0
52+
void *dispatch_data;
5153
// ... remainder of internal data
5254
};
5355
----
@@ -67,6 +69,13 @@ can be appended.
6769
Functions which do not have an argument from which the vendor implementation
6870
may be inferred have been deprecated and may be ignored.
6971

72+
New in version 2.0.0, object that are ICD 2 compatible should also contain
73+
a `dispatch_data` field of type `void *` that the loader is free to modify
74+
for a platform through the {clIcdSetPlatformDispatchDataKHR} new API entry
75+
point. In order to distinguish ICD 1 and ICD 2 objects, the pointers to
76+
`clGetPlatformIDs` and `clUnloadCompiler` in the dispatch structure must be
77+
set to `CL_ICD2_TAG_KHR`. The vendor driver is responsible for propagating
78+
the `dispatch_data` value when returning objects to users.
7079

7180
=== ICD Data
7281

@@ -230,10 +239,31 @@ value {CL_PLATFORM_ICD_SUFFIX_KHR}.
230239
If any of these steps fail, the ICD Loader will ignore the Vendor ICD and
231240
continue on to the next.
232241

242+
New in version 2.0.0, the ICD Loader will also query the following functions
243+
from the library: {clIcdGetFunctionAddressForPlatformKHR} and
244+
{clIcdSetPlatformDispatchDataKHR}. If these two functions are present and the
245+
pointers to `clGetPlatformIDs` and `clUnloadCompiler` in the dispatch
246+
structure of a platform is set to `CL_ICD2_TAG_KHR` the platform will be
247+
deemed ICD 2 compatible and dispatch will be managed by the ICD Loader. If the
248+
`CL_ICD2_TAG_KHR` tag is present but one of the two functions above is
249+
missing or it the tag is present in only one of the pointers, the ICD Loader
250+
will ignore the Vendor ICD and continue on to the next.
251+
252+
During initialization, after calling {clIcdGetPlatformIDsKHR} to query the
253+
available platforms, the ICD Loader will, for each ICD 2 compatible platform,
254+
query dispatchable entry points using {clIcdGetFunctionAddressForPlatformKHR}
255+
and then set the platform dispatch data using
256+
{clIcdSetPlatformDispatchDataKHR}.
257+
233258
=== New Commands
234259

235260
* {clIcdGetPlatformIDsKHR}
236261

262+
New in version 2.0.0:
263+
264+
* {clIcdGetFunctionAddressForPlatformKHR}
265+
* {clIcdSetPlatformDispatchDataKHR}
266+
237267
=== New Enums
238268

239269
Accepted as _param_name_ to the function {clGetPlatformInfo}:
@@ -244,6 +274,11 @@ Returned by {clGetPlatformIDs} when no platforms are found:
244274

245275
* {CL_PLATFORM_NOT_FOUND_KHR}
246276

277+
New in version 2.0.0, used as a value in the pointers to `clGetPlatformIDs`
278+
and `clUnloadCompiler` in the dispatch structure:
279+
280+
* `CL_ICD2_TAG_KHR`
281+
247282
=== Issues
248283

249284
. Some OpenCL functions do not take an object argument from which their
@@ -286,9 +321,31 @@ obtaining the ICD dispatch table.
286321
On detecting a `NULL` object it will return one of the an invalid object
287322
error values (e.g. {CL_INVALID_DEVICE} corresponding to the object in
288323
question.
324+
--
325+
326+
. How will the ICD loader avoid calling entry points outside of the dispatch
327+
table of old implementations, potentially causing segfaults?
328+
+
329+
--
330+
*RESOLVED*: From versions 2.0.0 and above, the loader will be responsible for
331+
managing dispatch data information per platform. The content of the dispatch
332+
table is obtained through a dedicated entry point, and missing entry points are
333+
replaced by stubs that return {CL_INVALID_OPERATION}.
334+
--
335+
336+
. How will the ICD loader set the loader managed dispatch information in new
337+
objects? Some of these objects may be created by extension functions that
338+
the loader is unaware of.
339+
+
340+
--
341+
*RESOLVED*: During initialization, the loader will set the platform dispatch
342+
information through a new entry point. The implementation will be responsible
343+
for propagating this information to new objects.
289344
--
290345

291346
=== Version History
292347

293348
* Revision 1.0.0, 2020-04-21
294349
** First assigned version.
350+
* Revision 2.0.0, 2025-04-01
351+
** Loader managed dispatch.

api/opencl_platform_layer.asciidoc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,43 @@ Otherwise, it returns one of the following errors:
8484
* {CL_INVALID_VALUE} if _num_entries_ is equal to zero and _platforms_ is
8585
not `NULL` or if both _num_platforms_ and _platforms_ are `NULL`.
8686
--
87+
88+
[open,refpage='clIcdGetFunctionAddressForPlatformKHR',desc='Query API entry points for a platform',type='protos']
89+
--
90+
The entry point of a given platform that is ICD 2 compatible can be obtained
91+
using the following function:
92+
93+
include::{generated}/api/protos/clIcdGetFunctionAddressForPlatformKHR.txt[]
94+
include::{generated}/api/version-notes/clIcdGetFunctionAddressForPlatformKHR.asciidoc[]
95+
96+
* _platform_ refers to the platform ID returned by {clIcdGetPlatformIDsKHR}
97+
* _func_name_ name of an API entry point
98+
99+
{clIcdGetFunctionAddressForPlatformKHR} returns the address of the API entry
100+
point named by _func_name_. The pointer returned should be cast to a function
101+
pointer type matching the API entry point as defined in the specification
102+
header file.
103+
104+
A return value of `NULL` indicates that the specified function does not exist
105+
for _platform_, or _platform_ is not a valid platform for the implementation.
106+
--
107+
108+
[open,refpage='clIcdSetPlatformDispatchDataKHR',desc='Set the dispatch data for a platform',type='protos']
109+
--
110+
The `dispatch_data` field of a platform can be set using the following function:
111+
112+
include::{generated}/api/protos/clIcdSetPlatformDispatchDataKHR.txt[]
113+
include::{generated}/api/version-notes/clIcdSetPlatformDispatchDataKHR.asciidoc[]
114+
115+
* _platform_ refers to the platform ID returned by {clIcdGetPlatformIDsKHR}
116+
* _dispatch_data_ is the value to set the `dispatch_data` field of the
117+
structure to
118+
119+
{clIcdSetPlatformDispatchDataKHR} returns {CL_SUCCESS} if the function is
120+
executed successfully.
121+
It returns {CL_INVALID_PLATFORM} if _platform_ is not a valid platform.
122+
--
123+
87124
endif::cl_khr_icd[]
88125

89126
[open,refpage='clGetPlatformInfo',desc='Query information about an OpenCL platform',type='protos']

scripts/gen_dictionaries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def GetFooter():
249249
addLink = True
250250
name = type.get('name')
251251
elif category == 'define':
252-
if type.text and type.text.startswith("#define"):
252+
if type.text and (type.text.startswith("#define") or type.text.strip().startswith("#if")):
253253
continue
254254
name = type.find('name').text
255255
else:

xml/cl.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,15 @@ server's OpenCL/api-docs repository.
383383
<member>const <type>size_t</type>* <name>global_work_size</name></member>
384384
<member>const <type>size_t</type>* <name>local_work_size</name></member>
385385
</type>
386+
387+
<type category="define" requires="stdint" name="CL_ICD2_TAG_KHR" comment="ICD 2 tag, in cl_ext.h">
388+
#if INTPTR_MAX == INT32_MAX
389+
#define CL_ICD2_TAG_KHR ((intptr_t)0x434C3331)
390+
#else
391+
#define CL_ICD2_TAG_KHR ((intptr_t)0x4F50454E434C3331)
392+
#endif
393+
</type>
394+
386395
</types>
387396

388397
<!-- SECTION: OpenCL enumerant (token) definitions. -->
@@ -2573,6 +2582,16 @@ server's OpenCL/api-docs repository.
25732582
<param><type>cl_platform_id</type>* <name>platforms</name></param>
25742583
<param><type>cl_uint</type>* <name>num_platforms</name></param>
25752584
</command>
2585+
<command>
2586+
<proto><type>void</type>* <name>clIcdGetFunctionAddressForPlatformKHR</name></proto>
2587+
<param><type>cl_platform_id</type> <name>platform</name></param>
2588+
<param>const <type>char</type>* <name>func_name</name></param>
2589+
</command>
2590+
<command>
2591+
<proto><type>cl_int</type> <name>clIcdSetPlatformDispatchDataKHR</name></proto>
2592+
<param><type>cl_platform_id</type> <name>platform</name></param>
2593+
<param><type>void</type>* <name>dispatch_data</name></param>
2594+
</command>
25762595
<command suffix="CL_API_SUFFIX__VERSION_1_2">
25772596
<proto><type>cl_program</type> <name>clCreateProgramWithILKHR</name></proto>
25782597
<param><type>cl_context</type> <name>context</name></param>
@@ -5631,7 +5650,7 @@ server's OpenCL/api-docs repository.
56315650
<command name="clLogMessagesToStderrAPPLE"/>
56325651
</require>
56335652
</extension>
5634-
<extension name="cl_khr_icd" revision="1.0.0" supported="opencl" ratified="opencl">
5653+
<extension name="cl_khr_icd" revision="2.0.0" supported="opencl" ratified="opencl">
56355654
<require>
56365655
<type name="CL/cl.h"/>
56375656
</require>
@@ -5641,8 +5660,13 @@ server's OpenCL/api-docs repository.
56415660
<require comment="Error codes">
56425661
<enum name="CL_PLATFORM_NOT_FOUND_KHR"/>
56435662
</require>
5663+
<require comment="ICD 2 tag value">
5664+
<type name="CL_ICD2_TAG_KHR"/>
5665+
</require>
56445666
<require>
56455667
<command name="clIcdGetPlatformIDsKHR"/>
5668+
<command name="clIcdGetFunctionAddressForPlatformKHR"/>
5669+
<command name="clIcdSetPlatformDispatchDataKHR"/>
56465670
</require>
56475671
</extension>
56485672
<extension name="cl_loader_layers" revision="1.0.0" supported="opencl">

0 commit comments

Comments
 (0)