Skip to content

Commit b6109c8

Browse files
authored
Merge pull request #670 from veselypeta/petr/563/structure_type
[UR] Automatically generate ur_structure_type_t
2 parents da4335b + 2f73f77 commit b6109c8

File tree

7 files changed

+6133
-6020
lines changed

7 files changed

+6133
-6020
lines changed

include/ur.py

Lines changed: 219 additions & 219 deletions
Large diffs are not rendered by default.

include/ur_api.h

Lines changed: 226 additions & 226 deletions
Large diffs are not rendered by default.

scripts/core/common.yml

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -265,79 +265,6 @@ etors:
265265
value: "0x7ffffffe"
266266
desc: "Unknown or internal error"
267267
--- #--------------------------------------------------------------------------
268-
type: enum
269-
desc: "Defines structure types"
270-
name: $x_structure_type_t
271-
etors:
272-
- name: CONTEXT_PROPERTIES
273-
desc: $x_context_properties_t
274-
- name: IMAGE_DESC
275-
desc: $x_image_desc_t
276-
- name: BUFFER_PROPERTIES
277-
desc: $x_buffer_properties_t
278-
- name: BUFFER_REGION
279-
desc: $x_buffer_region_t
280-
- name: BUFFER_CHANNEL_PROPERTIES
281-
desc: $x_buffer_channel_properties_t
282-
- name: BUFFER_ALLOC_LOCATION_PROPERTIES
283-
desc: $x_buffer_alloc_location_properties_t
284-
- name: PROGRAM_PROPERTIES
285-
desc: $x_program_properties_t
286-
- name: USM_DESC
287-
desc: $x_usm_desc_t
288-
- name: USM_HOST_DESC
289-
desc: $x_usm_host_desc_t
290-
- name: USM_DEVICE_DESC
291-
desc: $x_usm_device_desc_t
292-
- name: USM_POOL_DESC
293-
desc: $x_usm_pool_desc_t
294-
- name: USM_POOL_LIMITS_DESC
295-
desc: $x_usm_pool_limits_desc_t
296-
- name: DEVICE_BINARY
297-
desc: $x_device_binary_t
298-
- name: SAMPLER_DESC
299-
desc: $x_sampler_desc_t
300-
- name: QUEUE_PROPERTIES
301-
desc: $x_queue_properties_t
302-
- name: QUEUE_INDEX_PROPERTIES
303-
desc: $x_queue_properties_t
304-
- name: CONTEXT_NATIVE_PROPERTIES
305-
desc: $x_context_native_properties_t
306-
- name: KERNEL_NATIVE_PROPERTIES
307-
desc: $x_kernel_native_properties_t
308-
- name: QUEUE_NATIVE_PROPERTIES
309-
desc: $x_queue_native_properties_t
310-
- name: MEM_NATIVE_PROPERTIES
311-
desc: $x_mem_native_properties_t
312-
- name: EVENT_NATIVE_PROPERTIES
313-
desc: $x_event_native_properties_t
314-
- name: PLATFORM_NATIVE_PROPERTIES
315-
desc: $x_platform_native_properties_t
316-
- name: DEVICE_NATIVE_PROPERTIES
317-
desc: $x_device_native_properties_t
318-
- name: PROGRAM_NATIVE_PROPERTIES
319-
desc: $x_program_native_properties_t
320-
- name: SAMPLER_NATIVE_PROPERTIES
321-
desc: $x_sampler_native_properties_t
322-
- name: QUEUE_NATIVE_DESC
323-
desc: $x_queue_native_desc_t
324-
- name: DEVICE_PARTITION_PROPERTIES
325-
desc: $x_device_partition_properties_t
326-
- name: KERNEL_ARG_MEM_OBJ_PROPERTIES
327-
desc: $x_kernel_arg_mem_obj_properties_t
328-
- name: PHYSICAL_MEM_PROPERTIES
329-
desc: $x_physical_mem_properties_t
330-
- name: KERNEL_ARG_POINTER_PROPERTIES
331-
desc: $x_kernel_arg_pointer_properties_t
332-
- name: KERNEL_ARG_SAMPLER_PROPERTIES
333-
desc: $x_kernel_arg_sampler_properties_t
334-
- name: KERNEL_EXEC_INFO_PROPERTIES
335-
desc: $x_kernel_exec_info_properties_t
336-
- name: KERNEL_ARG_VALUE_PROPERTIES
337-
desc: $x_kernel_arg_value_properties_t
338-
- name: KERNEL_ARG_LOCAL_PROPERTIES
339-
desc: $x_kernel_arg_local_properties_t
340-
--- #--------------------------------------------------------------------------
341268
type: struct
342269
desc: "Base for all properties types"
343270
name: $x_base_properties_t

scripts/core/registry.yml

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
type: header
33
desc: "Intel $OneApi Unified Runtime function registry"
4-
ordinal: "9"
4+
ordinal: "-1"
55
---
66
name: $x_function_t
77
type: enum
@@ -502,3 +502,110 @@ etors:
502502
- name: COMMAND_BUFFER_APPEND_MEMBUFFER_READ_RECT_EXP
503503
desc: Enumerator for $xCommandBufferAppendMembufferReadRectExp
504504
value: '171'
505+
---
506+
type: enum
507+
desc: Defines structure types
508+
name: $x_structure_type_t
509+
etors:
510+
- name: CONTEXT_PROPERTIES
511+
desc: $x_context_properties_t
512+
value: '0'
513+
- name: IMAGE_DESC
514+
desc: $x_image_desc_t
515+
value: '1'
516+
- name: BUFFER_PROPERTIES
517+
desc: $x_buffer_properties_t
518+
value: '2'
519+
- name: BUFFER_REGION
520+
desc: $x_buffer_region_t
521+
value: '3'
522+
- name: BUFFER_CHANNEL_PROPERTIES
523+
desc: $x_buffer_channel_properties_t
524+
value: '4'
525+
- name: BUFFER_ALLOC_LOCATION_PROPERTIES
526+
desc: $x_buffer_alloc_location_properties_t
527+
value: '5'
528+
- name: PROGRAM_PROPERTIES
529+
desc: $x_program_properties_t
530+
value: '6'
531+
- name: USM_DESC
532+
desc: $x_usm_desc_t
533+
value: '7'
534+
- name: USM_HOST_DESC
535+
desc: $x_usm_host_desc_t
536+
value: '8'
537+
- name: USM_DEVICE_DESC
538+
desc: $x_usm_device_desc_t
539+
value: '9'
540+
- name: USM_POOL_DESC
541+
desc: $x_usm_pool_desc_t
542+
value: '10'
543+
- name: USM_POOL_LIMITS_DESC
544+
desc: $x_usm_pool_limits_desc_t
545+
value: '11'
546+
- name: DEVICE_BINARY
547+
desc: $x_device_binary_t
548+
value: '12'
549+
- name: SAMPLER_DESC
550+
desc: $x_sampler_desc_t
551+
value: '13'
552+
- name: QUEUE_PROPERTIES
553+
desc: $x_queue_properties_t
554+
value: '14'
555+
- name: QUEUE_INDEX_PROPERTIES
556+
desc: $x_queue_index_properties_t
557+
value: '15'
558+
- name: CONTEXT_NATIVE_PROPERTIES
559+
desc: $x_context_native_properties_t
560+
value: '16'
561+
- name: KERNEL_NATIVE_PROPERTIES
562+
desc: $x_kernel_native_properties_t
563+
value: '17'
564+
- name: QUEUE_NATIVE_PROPERTIES
565+
desc: $x_queue_native_properties_t
566+
value: '18'
567+
- name: MEM_NATIVE_PROPERTIES
568+
desc: $x_mem_native_properties_t
569+
value: '19'
570+
- name: EVENT_NATIVE_PROPERTIES
571+
desc: $x_event_native_properties_t
572+
value: '20'
573+
- name: PLATFORM_NATIVE_PROPERTIES
574+
desc: $x_platform_native_properties_t
575+
value: '21'
576+
- name: DEVICE_NATIVE_PROPERTIES
577+
desc: $x_device_native_properties_t
578+
value: '22'
579+
- name: PROGRAM_NATIVE_PROPERTIES
580+
desc: $x_program_native_properties_t
581+
value: '23'
582+
- name: SAMPLER_NATIVE_PROPERTIES
583+
desc: $x_sampler_native_properties_t
584+
value: '24'
585+
- name: QUEUE_NATIVE_DESC
586+
desc: $x_queue_native_desc_t
587+
value: '25'
588+
- name: DEVICE_PARTITION_PROPERTIES
589+
desc: $x_device_partition_properties_t
590+
value: '26'
591+
- name: KERNEL_ARG_MEM_OBJ_PROPERTIES
592+
desc: $x_kernel_arg_mem_obj_properties_t
593+
value: '27'
594+
- name: PHYSICAL_MEM_PROPERTIES
595+
desc: $x_physical_mem_properties_t
596+
value: '28'
597+
- name: KERNEL_ARG_POINTER_PROPERTIES
598+
desc: $x_kernel_arg_pointer_properties_t
599+
value: '29'
600+
- name: KERNEL_ARG_SAMPLER_PROPERTIES
601+
desc: $x_kernel_arg_sampler_properties_t
602+
value: '30'
603+
- name: KERNEL_EXEC_INFO_PROPERTIES
604+
desc: $x_kernel_exec_info_properties_t
605+
value: '31'
606+
- name: KERNEL_ARG_VALUE_PROPERTIES
607+
desc: $x_kernel_arg_value_properties_t
608+
value: '32'
609+
- name: KERNEL_ARG_LOCAL_PROPERTIES
610+
desc: $x_kernel_arg_local_properties_t
611+
value: '33'

scripts/generate_ids.py

Lines changed: 95 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from fileinput import FileInput
1010
import util
1111
import yaml
12+
import re
13+
import copy
1214

1315
ENUM_NAME = '$x_function_t'
1416

@@ -18,29 +20,100 @@ class quoted(str):
1820
def quoted_presenter(dumper, data):
1921
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='"')
2022

21-
def generate_registry(path, specs):
23+
def get_registry_header():
24+
return {'type': 'header', 'desc': quoted('Intel $OneApi Unified Runtime function registry'), 'ordinal': quoted(-1)}
25+
26+
def write_registry(data, path):
27+
with open(path, 'w') as fout:
28+
yaml.add_representer(quoted, quoted_presenter)
29+
yaml.dump_all(data, fout,
30+
default_flow_style=False,
31+
sort_keys=False,
32+
explicit_start=True)
33+
34+
def find_type_in_specs(specs, type):
35+
return [obj for s in specs for obj in s['objects'] if obj['name'] == type][0]
36+
37+
def get_max_enum(enum):
38+
return int(max(enum['etors'], key=lambda x : int(x['value']))['value'])
39+
40+
def copy_and_strip_prefix_from_enums(enum, prefix):
41+
cpy = copy.deepcopy(enum)
42+
for etor in cpy['etors']:
43+
etor['name'] = etor['name'][len(prefix):]
44+
return cpy
45+
46+
47+
def generate_function_type(specs, meta, update_fn) -> dict:
48+
existing_function_type = find_type_in_specs(specs, '$x_function_t')
49+
existing_etors = {etor['name'] : etor['value'] for etor in existing_function_type['etors']}
50+
max_etor = get_max_enum(existing_function_type)
51+
functions = [obj['class'][len('$x'):] + obj['name'] for s in specs for obj in s['objects'] if obj['type'] == 'function']
52+
registry = list()
53+
for fname in functions:
54+
etor_name = "$X_FUNCTION_" + util.to_snake_case(fname).upper()
55+
id = existing_etors.get(etor_name)
56+
if id is None:
57+
max_etor += 1
58+
id = max_etor
59+
registry.append({
60+
'name': etor_name,
61+
'desc': f'Enumerator for $x{fname}',
62+
'value': str(id)}
63+
)
64+
registry = sorted(registry, key=lambda x : int(x['value']))
65+
existing_function_type['etors'] = registry
66+
update_fn(existing_function_type, meta)
67+
68+
## create a copy to write back to registry.yml
69+
return copy_and_strip_prefix_from_enums(existing_function_type, '$X_FUNCTION_')
70+
71+
72+
def generate_structure_type(specs, meta, refresh_fn) -> dict:
73+
structure_type = find_type_in_specs(specs, '$x_structure_type_t')
74+
extended_structs = [obj for s in specs for obj in s['objects'] if re.match(r"struct|union", obj['type']) and 'base' in obj]
75+
max_enum = get_max_enum(structure_type)
76+
77+
structure_type_etors = list()
78+
for struct in extended_structs:
79+
# skip experimental enumerations
80+
if struct['name'].startswith('$x_exp_'):
81+
continue
82+
83+
etor = [mem for mem in struct['members'] if mem['name'] == 'stype'][0]['init']
84+
85+
# try and match the etor
86+
matched_etor = [e for e in structure_type['etors'] if e['name'] == etor]
87+
88+
out_etor = {
89+
'name': etor,
90+
'desc': struct['name']
91+
}
92+
93+
# if no match exists we assign it a new value
94+
if len(matched_etor) == 0:
95+
max_enum += 1
96+
out_etor['value'] = str(max_enum)
97+
else:
98+
out_etor['value'] = matched_etor[0]['value']
99+
100+
structure_type_etors.append(out_etor)
101+
102+
structure_type_etors = sorted(structure_type_etors, key = lambda x : int(x['value']))
103+
structure_type['etors'] = structure_type_etors
104+
refresh_fn(structure_type, meta)
105+
106+
## create a copy to write back to registry.yml
107+
return copy_and_strip_prefix_from_enums(structure_type, '$X_STRUCTURE_TYPE_')
108+
109+
def generate_registry(path, specs, meta, update_fn):
22110
try:
23-
existing_registry = list(util.yamlRead(path))[1]['etors']
24-
existing_etors = {etor["name"]: etor["value"] for etor in existing_registry}
25-
max_etor = int(max(existing_registry, key = lambda x : int(x["value"]))["value"])
26-
functions = [obj['class'][len('$x'):] + obj['name'] for s in specs for obj in s['objects'] if obj['type'] == 'function']
27-
registry = list()
28-
for fname in functions:
29-
etor_name = util.to_snake_case(fname).upper()
30-
id = existing_etors.get(etor_name)
31-
if id is None:
32-
max_etor += 1
33-
id = max_etor
34-
registry.append({'name': util.to_snake_case(fname).upper(), 'desc': 'Enumerator for $x'+fname, 'value': str(id)})
35-
registry = sorted(registry, key=lambda x: int(x['value']))
36-
wrapper = { 'name': ENUM_NAME, 'type': 'enum', 'desc': 'Defines unique stable identifiers for all functions' , 'etors': registry}
37-
header = {'type': 'header', 'desc': quoted('Intel $OneApi Unified Runtime function registry'), 'ordinal': quoted(9)}
38-
with open(path, 'w') as fout:
39-
yaml.add_representer(quoted, quoted_presenter)
40-
yaml.dump_all([header, wrapper], fout,
41-
default_flow_style=False,
42-
sort_keys=False,
43-
explicit_start=True)
111+
write_registry([
112+
get_registry_header(),
113+
generate_function_type(specs, meta, update_fn),
114+
generate_structure_type(specs, meta, update_fn)
115+
], path)
116+
44117
except BaseException as e:
45118
print("Failed to generate registry.yml... %s", e)
46119
raise e

scripts/parse_specs.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -763,14 +763,20 @@ def _append(lst, key, val):
763763
obj['returns'] = rets
764764
return obj
765765

766+
767+
def _inline_extended_structs(specs, meta):
768+
for s in specs:
769+
for i, obj in enumerate(s['objects']):
770+
obj = _inline_base(obj, meta)
771+
s['objects'][i] = obj
772+
766773
"""
767774
generates extra content
768775
"""
769776
def _generate_extra(specs, meta):
770777
for s in specs:
771778
for i, obj in enumerate(s['objects']):
772779
obj = _generate_hash(obj)
773-
obj = _inline_base(obj, meta)
774780
obj = _generate_returns(obj, meta)
775781
s['objects'][i] = obj
776782

@@ -809,7 +815,8 @@ def _refresh_enum_meta(obj, meta):
809815
if obj.get('class'):
810816
meta['class'][obj['class']]['enum'].remove(obj['name'])
811817

812-
del meta['enum'][obj['name']]
818+
if meta['enum'].get(obj['name']):
819+
del meta['enum'][obj['name']]
813820
## re-generate meta
814821
meta = _generate_meta(obj, None, meta)
815822

@@ -856,13 +863,10 @@ def parse(section, version, tags, meta, ref):
856863
specs = []
857864

858865
files = util.findFiles(path, "*.yml")
859-
# make sure registry is last, because it's autogenerated based on the rest of the spec
860-
files = sorted(files, key=lambda f: 1 if f.endswith('registry.yml') else 0)
866+
registry = [f for f in files if f.endswith('registry.yml')][0]
861867

862868
enum_extensions = []
863869
for f in files:
864-
if f.endswith('registry.yml'):
865-
generate_ids.generate_registry(f, specs)
866870

867871
print("Parsing %s..."%f)
868872
docs = util.yamlRead(f)
@@ -914,6 +918,8 @@ def parse(section, version, tags, meta, ref):
914918
})
915919

916920
specs = sorted(specs, key=lambda s: s['header']['ordinal'])
921+
_inline_extended_structs(specs, meta)
922+
generate_ids.generate_registry(registry, specs, meta, _refresh_enum_meta)
917923
_extend_enums(enum_extensions, specs, meta)
918924
_generate_extra(specs, meta)
919925

0 commit comments

Comments
 (0)