-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <ben.ashbaugh@intel.com> Signed-off-by: Kevin Petit <kevin.petit@arm.com> Change-Id: Ie2c14148d75457030aa1a97cf601daba2c007397 * Update scripts/gen_c_feature_dictionary.py Co-authored-by: Ben Ashbaugh <ben.ashbaugh@intel.com> * define __opencl_c_<feature_name> outside of the list of features Signed-off-by: Kevin Petit <kevin.petit@arm.com> Change-Id: I8e0947c30775338dd70803d09c7059d340e86f5a --------- Signed-off-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>
- Loading branch information
Showing
4 changed files
with
111 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
__opencl_c_3d_image_writes | ||
__opencl_c_atomic_order_acq_rel | ||
__opencl_c_atomic_order_seq_cst | ||
__opencl_c_atomic_scope_device | ||
__opencl_c_atomic_scope_all_devices | ||
__opencl_c_device_enqueue | ||
__opencl_c_generic_address_space | ||
__opencl_c_fp64 | ||
__opencl_c_images | ||
__opencl_c_int64 | ||
__opencl_c_pipes | ||
__opencl_c_program_scope_global_variables | ||
__opencl_c_read_write_images | ||
__opencl_c_subgroups | ||
__opencl_c_work_group_collective_functions | ||
__opencl_c_integer_dot_product_input_4x8bit | ||
__opencl_c_integer_dot_product_input_4x8bit_packed | ||
__opencl_c_kernel_clock_scope_device | ||
__opencl_c_kernel_clock_scope_work_group | ||
__opencl_c_kernel_clock_scope_sub_group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/python3 | ||
|
||
# Copyright 2024 The Khronos Group Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from collections import OrderedDict | ||
|
||
import argparse | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument('-features', action='store', | ||
default='', | ||
help='File with OpenCL C features to generate, one per line') | ||
parser.add_argument('-o', action='store', default='', | ||
help='Output file in which to store the feature dictionary. stdout is used if no file is provided.') | ||
|
||
args = parser.parse_args() | ||
|
||
features = [] | ||
if len(args.features) > 0: | ||
print('Generating feature dictionaries from: ' + args.features) | ||
with open(args.features) as f: | ||
features = f.readlines() | ||
else: | ||
print('Reading feature dictionaries from stdin...') | ||
for line in sys.stdin: | ||
features.append(line) | ||
print('Generating...\n') | ||
|
||
numberOfFeatures = 0 | ||
|
||
if args.o: | ||
outfile = open(args.o, 'w') | ||
else: | ||
outfile = sys.stdout | ||
|
||
for name in features: | ||
name = name.strip() | ||
if len(name) == 0: | ||
continue | ||
|
||
# OpenCL C features start with __opencl_c | ||
if name.startswith('__opencl_c'): | ||
#print('found enum: ' + name) | ||
|
||
# Create a variant of the name that precedes underscores with | ||
# "zero width" spaces. This causes some long names to be | ||
# broken at more intuitive places. | ||
htmlName = name[:10] + name[10:].replace("_", "_<wbr>") | ||
otherName = name[:10] + name[10:].replace("_", "_​") | ||
|
||
# Remove the leading underscores. | ||
name = name[2:] | ||
|
||
# Example: | ||
# | ||
# // opencl_c_images | ||
# ifdef::backend-html5[] | ||
# :opencl_c_images: pass:q[`\__opencl_c_<wbr>images`] | ||
# endif::[] | ||
# ifndef::backend-html5[] | ||
# :opencl_c_images: pass:q[`\__opencl_c_​images`] | ||
# endif::[] | ||
outfile.write('// ' + name + '\n') | ||
outfile.write('ifdef::backend-html5[]\n') | ||
outfile.write(':' + name + ': pass:q[`\\' + htmlName + '`]\n') | ||
outfile.write('endif::[]\n') | ||
outfile.write('ifndef::backend-html5[]\n') | ||
outfile.write(':' + name + ': pass:q[`\\' + otherName + '`]\n') | ||
outfile.write('endif::[]\n') | ||
|
||
numberOfFeatures = numberOfFeatures + 1 | ||
|
||
# everything else is a function | ||
else: | ||
print('Unexpected feature name: ' + name + ', features should start with __opencl_c!') | ||
sys.exit(1) | ||
|
||
outfile.write('\n') | ||
|
||
if args.o: | ||
outfile.close() | ||
|
||
print('Found ' + str(numberOfFeatures) + ' features.') |