Skip to content

Commit 47dd749

Browse files
kpetbashbaug
andauthored
Generate OpenCL C feature dictionary (#1212)
* Generate OpenCL C feature dictionary Features are stored in a text file for now. Ultimately, we probably want to use the XML registry for this. Generation script taken from #1174 with a few modifications. Contributes to #1166. Signed-off-by: Ben Ashbaugh <[email protected]> Signed-off-by: Kevin Petit <[email protected]> Change-Id: Ie2c14148d75457030aa1a97cf601daba2c007397 * Update scripts/gen_c_feature_dictionary.py Co-authored-by: Ben Ashbaugh <[email protected]> * define __opencl_c_<feature_name> outside of the list of features Signed-off-by: Kevin Petit <[email protected]> Change-Id: I8e0947c30775338dd70803d09c7059d340e86f5a --------- Signed-off-by: Ben Ashbaugh <[email protected]> Signed-off-by: Kevin Petit <[email protected]> Co-authored-by: Ben Ashbaugh <[email protected]>
1 parent aca3750 commit 47dd749

File tree

4 files changed

+111
-159
lines changed

4 files changed

+111
-159
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,11 @@ $(MANHTMLDIR)/intro.html: $(REFPATH)/intro.txt $(MANCOPYRIGHT)
512512

513513
REGISTRY = $(ROOTDIR)/xml
514514
APIXML = $(REGISTRY)/cl.xml
515+
CFEATURES = c/features.txt
515516
GENSCRIPT = $(SCRIPTS)/gencl.py
516517
DICTSCRIPT = $(SCRIPTS)/gen_dictionaries.py
517518
VERSIONSCRIPT = $(SCRIPTS)/gen_version_notes.py
519+
CFEATSCRIPT = $(SCRIPTS)/gen_c_feature_dictionary.py
518520
GENSCRIPTOPTS = $(VERSIONOPTIONS) $(EXTOPTIONS) $(GENSCRIPTEXTRA) -registry $(APIXML)
519521
GENSCRIPTEXTRA =
520522

@@ -540,6 +542,7 @@ extinc: $(METADEPEND)
540542
$(METADEPEND): $(APIXML) $(GENSCRIPT)
541543
$(QUIET)$(MKDIR) $(METAPATH)
542544
$(QUIET)$(PYTHON) $(GENSCRIPT) $(GENSCRIPTOPTS) -o $(METAPATH) extinc
545+
$(QUIET)$(PYTHON) $(CFEATSCRIPT) -features $(CFEATURES) -o $(METAPATH)/c-feature-dictionary.asciidoc
543546

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

c/feature-dictionary.asciidoc

+1-159
Original file line numberDiff line numberDiff line change
@@ -10,162 +10,4 @@ ifndef::backend-html5[]
1010
:opencl_c_feature_name: pass:q[`\__opencl_c_&#8203;&lt;feature_&#8203;name&gt;`]
1111
endif::[]
1212

13-
// opencl_c_3d_image_writes
14-
ifdef::backend-html5[]
15-
:opencl_c_3d_image_writes: pass:q[`\__opencl_c_<wbr>3d_<wbr>image_<wbr>writes`]
16-
endif::[]
17-
ifndef::backend-html5[]
18-
:opencl_c_3d_image_writes: pass:q[`\__opencl_c_&#8203;3d_&#8203;image_&#8203;writes`]
19-
endif::[]
20-
21-
// opencl_c_atomic_order_acq_rel
22-
ifdef::backend-html5[]
23-
:opencl_c_atomic_order_acq_rel: pass:q[`\__opencl_c_<wbr>atomic_<wbr>order_<wbr>acq_<wbr>rel`]
24-
endif::[]
25-
ifndef::backend-html5[]
26-
:opencl_c_atomic_order_acq_rel: pass:q[`\__opencl_c_&#8203;atomic_&#8203;order_&#8203;&#8203;`]
27-
endif::[]
28-
29-
// opencl_c_atomic_order_seq_cst
30-
ifdef::backend-html5[]
31-
:opencl_c_atomic_order_seq_cst: pass:q[`\__opencl_c_<wbr>atomic_<wbr>order_<wbr>seq_<wbr>cst`]
32-
endif::[]
33-
ifndef::backend-html5[]
34-
:opencl_c_atomic_order_seq_cst: pass:q[`\__opencl_c_&#8203;atomic_&#8203;order_&#8203;seq_&#8203;cst`]
35-
endif::[]
36-
37-
// opencl_c_atomic_scope_device
38-
ifdef::backend-html5[]
39-
:opencl_c_atomic_scope_device: pass:q[`\__opencl_c_<wbr>atomic_<wbr>scope_<wbr>device`]
40-
endif::[]
41-
ifndef::backend-html5[]
42-
:opencl_c_atomic_scope_device: pass:q[`\__opencl_c_&#8203;atomic_&#8203;scope_&#8203;device`]
43-
endif::[]
44-
45-
// opencl_c_atomic_scope_all_devices
46-
ifdef::backend-html5[]
47-
:opencl_c_atomic_scope_all_devices: pass:q[`\__opencl_c_<wbr>atomic_<wbr>scope_<wbr>all_<wbr>devices`]
48-
endif::[]
49-
ifndef::backend-html5[]
50-
:opencl_c_atomic_scope_all_devices: pass:q[`\__opencl_c_&#8203;atomic_&#8203;scope_&#8203;all_&#8203;devices`]
51-
endif::[]
52-
53-
// opencl_c_device_enqueue
54-
ifdef::backend-html5[]
55-
:opencl_c_device_enqueue: pass:q[`\__opencl_c_<wbr>device_<wbr>enqueue`]
56-
endif::[]
57-
ifndef::backend-html5[]
58-
:opencl_c_device_enqueue: pass:q[`\__opencl_c_&#8203;device_&#8203;enqueue`]
59-
endif::[]
60-
61-
// opencl_c_generic_address_space
62-
ifdef::backend-html5[]
63-
:opencl_c_generic_address_space: pass:q[`\__opencl_c_<wbr>generic_<wbr>address_<wbr>space`]
64-
endif::[]
65-
ifndef::backend-html5[]
66-
:opencl_c_generic_address_space: pass:q[`\__opencl_c_&#8203;generic_&#8203;address_&#8203;space`]
67-
endif::[]
68-
69-
// opencl_c_fp64
70-
ifdef::backend-html5[]
71-
:opencl_c_fp64: pass:q[`\__opencl_c_<wbr>fp64`]
72-
endif::[]
73-
ifndef::backend-html5[]
74-
:opencl_c_fp64: pass:q[`\__opencl_c_&#8203;fp64`]
75-
endif::[]
76-
77-
// opencl_c_images
78-
ifdef::backend-html5[]
79-
:opencl_c_images: pass:q[`\__opencl_c_<wbr>images`]
80-
endif::[]
81-
ifndef::backend-html5[]
82-
:opencl_c_images: pass:q[`\__opencl_c_&#8203;images`]
83-
endif::[]
84-
85-
// opencl_c_int64
86-
ifdef::backend-html5[]
87-
:opencl_c_int64: pass:q[`\__opencl_c_<wbr>int64`]
88-
endif::[]
89-
ifndef::backend-html5[]
90-
:opencl_c_int64: pass:q[`\__opencl_c_&#8203;int64`]
91-
endif::[]
92-
93-
// opencl_c_pipes
94-
ifdef::backend-html5[]
95-
:opencl_c_pipes: pass:q[`\__opencl_c_<wbr>pipes`]
96-
endif::[]
97-
ifndef::backend-html5[]
98-
:opencl_c_pipes: pass:q[`\__opencl_c_&#8203;pipes`]
99-
endif::[]
100-
101-
// opencl_c_program_scope_global_variables
102-
ifdef::backend-html5[]
103-
:opencl_c_program_scope_global_variables: pass:q[`\__opencl_c_<wbr>program_<wbr>scope_<wbr>global_<wbr>variables`]
104-
endif::[]
105-
ifndef::backend-html5[]
106-
:opencl_c_program_scope_global_variables: pass:q[`\__opencl_c_&#8203;program_&#8203;scope_&#8203;global_&#8203;variables`]
107-
endif::[]
108-
109-
// opencl_c_read_write_images
110-
ifdef::backend-html5[]
111-
:opencl_c_read_write_images: pass:q[`\__opencl_c_<wbr>read_<wbr>write_<wbr>images`]
112-
endif::[]
113-
ifndef::backend-html5[]
114-
:opencl_c_read_write_images: pass:q[`\__opencl_c_&#8203;read_&#8203;write_&#8203;images`]
115-
endif::[]
116-
117-
// opencl_c_subgroups
118-
ifdef::backend-html5[]
119-
:opencl_c_subgroups: pass:q[`\__opencl_c_<wbr>subgroups`]
120-
endif::[]
121-
ifndef::backend-html5[]
122-
:opencl_c_subgroups: pass:q[`\__opencl_c_&#8203;subgroups`]
123-
endif::[]
124-
125-
// opencl_c_work_group_collective_functions
126-
ifdef::backend-html5[]
127-
:opencl_c_work_group_collective_functions: pass:q[`\__opencl_c_<wbr>work_<wbr>group_<wbr>collective_<wbr>functions`]
128-
endif::[]
129-
ifndef::backend-html5[]
130-
:opencl_c_work_group_collective_functions: pass:q[`\__opencl_c_&#8203;work_&#8203;group_&#8203;collective_&#8203;functions`]
131-
endif::[]
132-
133-
// opencl_c_integer_dot_product_input_4x8bit
134-
ifdef::backend-html5[]
135-
:opencl_c_integer_dot_product_input_4x8bit: pass:q[`\__opencl_c_<wbr>integer_<wbr>dot_<wbr>product_<wbr>input_<wbr>4x8bit`]
136-
endif::[]
137-
ifndef::backend-html5[]
138-
:opencl_c_integer_dot_product_input_4x8bit: pass:q[`\__opencl_c_&#8203;integer_&#8203;dot_&#8203;product_&#8203;input_&#8203;4x8bit`]
139-
endif::[]
140-
141-
// opencl_c_integer_dot_product_input_4x8bit_packed
142-
ifdef::backend-html5[]
143-
:opencl_c_integer_dot_product_input_4x8bit_packed: pass:q[`\__opencl_c_<wbr>integer_<wbr>dot_<wbr>product_<wbr>input_<wbr>4x8bit_<wbr>packed`]
144-
endif::[]
145-
ifndef::backend-html5[]
146-
:opencl_c_integer_dot_product_input_4x8bit_packed: pass:q[`\__opencl_c_&#8203;integer_&#8203;dot_&#8203;product_&#8203;input_&#8203;4x8bit_&#8203;packed`]
147-
endif::[]
148-
149-
// opencl_c_kernel_clock_scope_device
150-
ifdef::backend-html5[]
151-
:opencl_c_kernel_clock_scope_device: pass:q[`\__opencl_c_<wbr>kernel_<wbr>clock_<wbr>scope_<wbr>device`]
152-
endif::[]
153-
ifndef::backend-html5[]
154-
:opencl_c_kernel_clock_scope_device: pass:q[`\__opencl_c_&#8203;kernel_&#8203;clock_&#8203;scope_&#8203;device`]
155-
endif::[]
156-
157-
// opencl_c_kernel_clock_scope_work_group
158-
ifdef::backend-html5[]
159-
:opencl_c_kernel_clock_scope_work_group: pass:q[`\__opencl_c_<wbr>kernel_<wbr>clock_<wbr>scope_<wbr>work_<wbr>group`]
160-
endif::[]
161-
ifndef::backend-html5[]
162-
:opencl_c_kernel_clock_scope_work_group: pass:q[`\__opencl_c_&#8203;kernel_&#8203;clock_&#8203;scope_&#8203;work_&#8203;group`]
163-
endif::[]
164-
165-
// opencl_c_kernel_clock_scope_sub_group
166-
ifdef::backend-html5[]
167-
:opencl_c_kernel_clock_scope_sub_group: pass:q[`\__opencl_c_<wbr>kernel_<wbr>clock_<wbr>scope_<wbr>sub_<wbr>group`]
168-
endif::[]
169-
ifndef::backend-html5[]
170-
:opencl_c_kernel_clock_scope_sub_group: pass:q[`\__opencl_c_&#8203;kernel_&#8203;clock_&#8203;scope_&#8203;sub_&#8203;group`]
171-
endif::[]
13+
include::{generated}/meta/c-feature-dictionary.asciidoc[]

c/features.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
__opencl_c_3d_image_writes
2+
__opencl_c_atomic_order_acq_rel
3+
__opencl_c_atomic_order_seq_cst
4+
__opencl_c_atomic_scope_device
5+
__opencl_c_atomic_scope_all_devices
6+
__opencl_c_device_enqueue
7+
__opencl_c_generic_address_space
8+
__opencl_c_fp64
9+
__opencl_c_images
10+
__opencl_c_int64
11+
__opencl_c_pipes
12+
__opencl_c_program_scope_global_variables
13+
__opencl_c_read_write_images
14+
__opencl_c_subgroups
15+
__opencl_c_work_group_collective_functions
16+
__opencl_c_integer_dot_product_input_4x8bit
17+
__opencl_c_integer_dot_product_input_4x8bit_packed
18+
__opencl_c_kernel_clock_scope_device
19+
__opencl_c_kernel_clock_scope_work_group
20+
__opencl_c_kernel_clock_scope_sub_group

scripts/gen_c_feature_dictionary.py

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/python3
2+
3+
# Copyright 2024 The Khronos Group Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
from collections import OrderedDict
7+
8+
import argparse
9+
import sys
10+
11+
if __name__ == "__main__":
12+
parser = argparse.ArgumentParser()
13+
14+
parser.add_argument('-features', action='store',
15+
default='',
16+
help='File with OpenCL C features to generate, one per line')
17+
parser.add_argument('-o', action='store', default='',
18+
help='Output file in which to store the feature dictionary. stdout is used if no file is provided.')
19+
20+
args = parser.parse_args()
21+
22+
features = []
23+
if len(args.features) > 0:
24+
print('Generating feature dictionaries from: ' + args.features)
25+
with open(args.features) as f:
26+
features = f.readlines()
27+
else:
28+
print('Reading feature dictionaries from stdin...')
29+
for line in sys.stdin:
30+
features.append(line)
31+
print('Generating...\n')
32+
33+
numberOfFeatures = 0
34+
35+
if args.o:
36+
outfile = open(args.o, 'w')
37+
else:
38+
outfile = sys.stdout
39+
40+
for name in features:
41+
name = name.strip()
42+
if len(name) == 0:
43+
continue
44+
45+
# OpenCL C features start with __opencl_c
46+
if name.startswith('__opencl_c'):
47+
#print('found enum: ' + name)
48+
49+
# Create a variant of the name that precedes underscores with
50+
# "zero width" spaces. This causes some long names to be
51+
# broken at more intuitive places.
52+
htmlName = name[:10] + name[10:].replace("_", "_<wbr>")
53+
otherName = name[:10] + name[10:].replace("_", "_&#8203;")
54+
55+
# Remove the leading underscores.
56+
name = name[2:]
57+
58+
# Example:
59+
#
60+
# // opencl_c_images
61+
# ifdef::backend-html5[]
62+
# :opencl_c_images: pass:q[`\__opencl_c_<wbr>images`]
63+
# endif::[]
64+
# ifndef::backend-html5[]
65+
# :opencl_c_images: pass:q[`\__opencl_c_&#8203;images`]
66+
# endif::[]
67+
outfile.write('// ' + name + '\n')
68+
outfile.write('ifdef::backend-html5[]\n')
69+
outfile.write(':' + name + ': pass:q[`\\' + htmlName + '`]\n')
70+
outfile.write('endif::[]\n')
71+
outfile.write('ifndef::backend-html5[]\n')
72+
outfile.write(':' + name + ': pass:q[`\\' + otherName + '`]\n')
73+
outfile.write('endif::[]\n')
74+
75+
numberOfFeatures = numberOfFeatures + 1
76+
77+
# everything else is a function
78+
else:
79+
print('Unexpected feature name: ' + name + ', features should start with __opencl_c!')
80+
sys.exit(1)
81+
82+
outfile.write('\n')
83+
84+
if args.o:
85+
outfile.close()
86+
87+
print('Found ' + str(numberOfFeatures) + ' features.')

0 commit comments

Comments
 (0)