Skip to content

Commit 6b00a9b

Browse files
kpetbashbaug
andauthored
Generate extension interfaces for all EXT extensions (KhronosGroup#1460)
* Generate extension interfaces for all EXT extensions - Add script to automatically generate the list of new commands, types, enums, and error codes. - Use generated output for all EXT extensions. - This fixes missing new enums for cl_ext_image_raw10_raw12. Signed-off-by: Kevin Petit <kevin.petit@arm.com> Change-Id: I5a7edd837d39a3a0c6f86876ec7faa97a01d736e * Update scripts/gen_extension_interfaces.py Co-authored-by: Ben Ashbaugh <ben.ashbaugh@intel.com> * Update scripts/gen_extension_interfaces.py Co-authored-by: Ben Ashbaugh <ben.ashbaugh@intel.com> --------- Signed-off-by: Kevin Petit <kevin.petit@arm.com> Co-authored-by: Ben Ashbaugh <ben.ashbaugh@intel.com>
1 parent 1053c99 commit 6b00a9b

10 files changed

Lines changed: 99 additions & 62 deletions

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ CFEATURES = c/features.txt
517517
CFUNCTIONS = c/functions.txt
518518
GENSCRIPT = $(SCRIPTS)/gencl.py
519519
DICTSCRIPT = $(SCRIPTS)/gen_dictionaries.py
520+
EXTIFACESSCRIPT= $(SCRIPTS)/gen_extension_interfaces.py
520521
VERSIONSCRIPT = $(SCRIPTS)/gen_version_notes.py
521522
CFEATSCRIPT = $(SCRIPTS)/gen_dictionary_from_file.py
522523
CFUNCSCRIPT = $(SCRIPTS)/gen_dictionary_from_file.py
@@ -542,11 +543,13 @@ $(APIDEPEND): $(APIXML) $(DICTSCRIPT) $(GENSCRIPT) $(VERSIONSCRIPT)
542543

543544
extinc: $(METADEPEND)
544545

545-
$(METADEPEND): $(APIXML) $(GENSCRIPT)
546+
$(METADEPEND): $(APIXML) $(GENSCRIPT) $(CFEATSCRIPT) $(EXTIFACESSCRIPT)
546547
$(QUIET)$(MKDIR) $(METAPATH)
548+
$(QUIET)$(MKDIR) $(METAPATH)/interfaces
547549
$(QUIET)$(PYTHON) $(GENSCRIPT) $(GENSCRIPTOPTS) -o $(METAPATH) extinc
548550
$(QUIET)$(PYTHON) $(CFEATSCRIPT) -i $(CFEATURES) -o $(METAPATH)/c-feature-dictionary.asciidoc
549551
$(QUIET)$(PYTHON) $(CFUNCSCRIPT) -i $(CFUNCTIONS) -o $(METAPATH)/c-function-dictionary.asciidoc
552+
$(QUIET)$(PYTHON) $(EXTIFACESSCRIPT) -registry $(APIXML) -o $(METAPATH)/interfaces
550553

551554
# This generates a single file containing asciidoc attributes for each
552555
# extension in the spec being built.

api/cl_ext_buffer_device_address.asciidoc

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,7 @@ This extension is targeted to complement the OpenCL SVM extension by providing
4444
an additional lower-end step in the spectrum of type of pointers/buffers OpenCL
4545
can allocate.
4646

47-
=== New Command
48-
49-
* {clSetKernelArgDevicePointerEXT}
50-
51-
=== New Types
52-
53-
* {cl_mem_device_address_ext_TYPE}
54-
55-
=== New Enums
56-
57-
* {cl_mem_properties_TYPE}
58-
** {CL_MEM_DEVICE_PRIVATE_ADDRESS_EXT}
59-
* {cl_mem_info_TYPE}
60-
** {CL_MEM_DEVICE_ADDRESS_EXT}
61-
* {cl_kernel_exec_info_TYPE}
62-
** {CL_KERNEL_EXEC_INFO_DEVICE_PTRS_EXT}
47+
include::{generated}/meta/interfaces/cl_ext_buffer_device_address.txt[]
6348

6449
=== Version History
6550

api/cl_ext_cxx_for_opencl.asciidoc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ with stable versions published in releases of the repository.
2727
This extension also enables applications to query the version of the language
2828
supported by the device compiler.
2929

30-
=== New Enums
31-
32-
* {cl_device_info_TYPE}
33-
** {CL_DEVICE_CXX_FOR_OPENCL_NUMERIC_VERSION_EXT}
30+
include::{generated}/meta/interfaces/cl_ext_cxx_for_opencl.txt[]
3431

3532
=== New build option
3633

api/cl_ext_image_from_buffer.asciidoc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ include::{generated}/meta/{refprefix}cl_ext_image_from_buffer.txt[]
2020
This extension enables all types of images to be created from an existing buffer
2121
object.
2222

23-
=== New Enums
24-
25-
* {cl_image_requirements_info_ext_TYPE}
26-
** {CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT}
23+
include::{generated}/meta/interfaces/cl_ext_image_from_buffer.txt[]
2724

2825
=== Conformance tests
2926

api/cl_ext_image_raw10_raw12.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ include::{generated}/meta/{refprefix}cl_ext_image_raw10_raw12.txt[]
1515
The latest published specification for this extension is available on
1616
the https://registry.khronos.org/OpenCL/extensions/ext/cl_ext_image_raw10_raw12.html[OpenCL registry].
1717

18+
include::{generated}/meta/interfaces/cl_ext_image_raw10_raw12.txt[]
19+
1820
=== Version History
1921

2022
* Revision 1.0.0, 2023-05-03

api/cl_ext_image_requirements_info.asciidoc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,7 @@ include::{generated}/meta/{refprefix}cl_ext_image_requirements_info.txt[]
2222
This extension enables applications to query requirements for an image without
2323
having to create the image.
2424

25-
=== New Commands
26-
27-
* {clGetImageRequirementsInfoEXT}
28-
29-
=== New Types
30-
31-
* {cl_image_requirements_info_ext_TYPE}
32-
33-
=== New Enums
34-
35-
* {cl_image_requirements_info_ext_TYPE}
36-
** {CL_IMAGE_REQUIREMENTS_ROW_PITCH_ALIGNMENT_EXT}
37-
** {CL_IMAGE_REQUIREMENTS_BASE_ADDRESS_ALIGNMENT_EXT}
38-
** {CL_IMAGE_REQUIREMENTS_SIZE_EXT}
39-
** {CL_IMAGE_REQUIREMENTS_MAX_WIDTH_EXT}
40-
** {CL_IMAGE_REQUIREMENTS_MAX_HEIGHT_EXT}
41-
** {CL_IMAGE_REQUIREMENTS_MAX_DEPTH_EXT}
42-
** {CL_IMAGE_REQUIREMENTS_MAX_ARRAY_SIZE_EXT}
25+
include::{generated}/meta/interfaces/cl_ext_image_requirements_info.txt[]
4326

4427
=== Conformance tests
4528

api/cl_ext_image_unorm_int_2_101010.asciidoc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@ image format.
2020
OpenCL C compilers supporting this extension will define the
2121
{opencl_c_ext_image_unorm_int_2_101010} feature macro.
2222

23+
include::{generated}/meta/interfaces/cl_ext_image_unorm_int_2_101010.txt[]
24+
2325
=== New feature macro
2426

2527
* {opencl_c_ext_image_unorm_int_2_101010}
2628

27-
=== New Enums
28-
29-
* {cl_channel_type_TYPE}
30-
** {CL_UNORM_INT_2_101010_EXT}
31-
3229
=== New OpenCL C channel data type
3330

3431
* `CLK_UNORM_INT_2_101010_EXT`

api/cl_ext_image_unsigned_10x6_12x4_14x2.asciidoc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,12 @@ formats:
2727
OpenCL C compilers supporting this extension will define the
2828
{opencl_c_ext_image_unsigned_10x6_12x4_14x2} feature macro.
2929

30+
include::{generated}/meta/interfaces/cl_ext_image_unsigned_10x6_12x4_14x2.txt[]
31+
3032
=== New feature macro
3133

3234
* {opencl_c_ext_image_unsigned_10x6_12x4_14x2}
3335

34-
=== New Enums
35-
36-
* {cl_channel_type_TYPE}
37-
** {CL_UNSIGNED_INT10X6_EXT}
38-
** {CL_UNSIGNED_INT12X4_EXT}
39-
** {CL_UNSIGNED_INT14X2_EXT}
40-
** {CL_UNORM_INT10X6_EXT}
41-
** {CL_UNORM_INT12X4_EXT}
42-
** {CL_UNORM_INT14X2_EXT}
43-
4436
=== New OpenCL C channel data type
4537

4638
* `CLK_UNSIGNED_INT10X6_EXT`

api/cl_ext_immutable_memory_objects.asciidoc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ objects that cannot be modified by the implementation after creation. This,
2323
for example, enables implementation to support image formats for which no write
2424
operations can be supported.
2525

26-
=== New Enums
27-
28-
* {cl_mem_flags_TYPE}
29-
** {CL_MEM_IMMUTABLE_EXT}
26+
include::{generated}/meta/interfaces/cl_ext_immutable_memory_objects.txt[]
3027

3128
=== Issues
3229

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2025 The Khronos Group Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
import argparse
7+
import os
8+
import urllib
9+
import xml.etree.ElementTree as etree
10+
import urllib.request
11+
12+
def parse_xml(path):
13+
file = urllib.request.urlopen(path) if path.startswith("http") else open(path, 'r')
14+
with file:
15+
tree = etree.parse(file)
16+
return tree
17+
18+
def GetHeader():
19+
return """// Copyright 2025 The Khronos Group.
20+
// SPDX-License-Identifier: CC-BY-4.0
21+
22+
"""
23+
24+
if __name__ == "__main__":
25+
parser = argparse.ArgumentParser()
26+
27+
parser.add_argument('-registry', action='store',
28+
default='cl.xml',
29+
help='Use specified registry file instead of cl.xml')
30+
parser.add_argument('-o', action='store', dest='directory',
31+
default='.',
32+
help='Create target and related files in specified directory')
33+
34+
args = parser.parse_args()
35+
36+
specpath = args.registry
37+
38+
print('Generating extension interfaces from: ' + specpath)
39+
40+
spec = parse_xml(specpath)
41+
42+
for extension in spec.findall('extensions/extension'):
43+
extname = extension.get('name')
44+
#print(extname)
45+
iface_file = open(os.path.join(args.directory, extname + '.txt'), 'w')
46+
47+
iface_file.write(GetHeader())
48+
49+
# New commands
50+
commands = extension.findall('require/command')
51+
if commands:
52+
iface_file.write('=== New Commands\n\n')
53+
for cmd in commands:
54+
iface_file.write(' * {{{}}}\n'.format(cmd.get('name')))
55+
iface_file.write('\n')
56+
57+
# New types
58+
types = extension.findall('require/type')
59+
if types:
60+
iface_file.write('=== New Types\n\n')
61+
for ty in types:
62+
iface_file.write(' * {{{}_TYPE}}\n'.format(ty.get('name')))
63+
64+
# New enums
65+
first_enum = True
66+
requires = extension.findall('require')
67+
for req in requires:
68+
enums = req.findall('enum')
69+
first_for_require = True
70+
for e in enums:
71+
if first_enum:
72+
iface_file.write('=== New enums\n\n')
73+
first_enum = False
74+
if first_for_require:
75+
comment = req.get('comment')
76+
if comment == 'Error codes':
77+
iface_file.write(' * New Error Codes\n')
78+
else:
79+
iface_file.write(' * {{{}_TYPE}}\n'.format(comment))
80+
first_for_require = False
81+
iface_file.write(' ** {{{}}}\n'.format(e.get('name')))
82+
iface_file.write('\n')
83+
84+
iface_file.close()

0 commit comments

Comments
 (0)