Skip to content

Commit

Permalink
[UR] Allow for extending enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Vesely committed Jun 19, 2023
1 parent a24d904 commit 590cb44
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 91 deletions.
13 changes: 8 additions & 5 deletions include/ur.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,11 @@ class ur_result_v(IntEnum):
ERROR_ADAPTER_SPECIFIC = 67 ## An adapter specific warning/error has been reported and can be
## retrieved via the urPlatformGetLastError entry point.
ERROR_INVALID_COMMAND_BUFFER_EXP = 0x1000 ## Invalid Command-Buffer
ERROR_INVALID_COMMAND_BUFFER_EXP = 0x1000 ## Invalid Command-Buffer
ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP = 0x1001## Sync point is not valid for the command-buffer
ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP = 0x1001## Sync point is not valid for the command-buffer
ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP = 0x1002 ## Sync point wait list is invalid
ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP = 0x1002 ## Sync point wait list is invalid
ERROR_UNKNOWN = 0x7ffffffe ## Unknown or internal error

class ur_result_t(c_int):
Expand Down Expand Up @@ -236,10 +239,10 @@ class ur_structure_type_v(IntEnum):
SAMPLER_NATIVE_PROPERTIES = 24 ## ::ur_sampler_native_properties_t
QUEUE_NATIVE_DESC = 25 ## ::ur_queue_native_desc_t
DEVICE_PARTITION_PROPERTIES = 26 ## ::ur_device_partition_properties_t
EXP_COMMAND_BUFFER_DESC = 27 ## ::ur_exp_command_buffer_desc_t
EXP_SAMPLER_MIP_PROPERTIES = 28 ## ::ur_exp_sampler_mip_properties_t
KERNEL_ARG_MEM_OBJ_PROPERTIES = 29 ## ::ur_kernel_arg_mem_obj_properties_t
PHYSICAL_MEM_PROPERTIES = 30 ## ::ur_physical_mem_properties_t
KERNEL_ARG_MEM_OBJ_PROPERTIES = 27 ## ::ur_kernel_arg_mem_obj_properties_t
PHYSICAL_MEM_PROPERTIES = 28 ## ::ur_physical_mem_properties_t
EXP_COMMAND_BUFFER_DESC = 0x1000 ## ::ur_exp_command_buffer_desc_t
EXP_SAMPLER_MIP_PROPERTIES = 0x2000 ## ::ur_exp_sampler_mip_properties_t

class ur_structure_type_t(c_int):
def __str__(self):
Expand Down Expand Up @@ -1719,7 +1722,7 @@ class ur_command_v(IntEnum):
DEVICE_GLOBAL_VARIABLE_READ = 24 ## Event created by ::urEnqueueDeviceGlobalVariableRead
READ_HOST_PIPE = 25 ## Event created by ::urEnqueueReadHostPipe
WRITE_HOST_PIPE = 26 ## Event created by ::urEnqueueWriteHostPipe
COMMAND_BUFFER_ENQUEUE_EXP = 27 ## Event created by ::urCommandBufferEnqueueExp
COMMAND_BUFFER_ENQUEUE_EXP = 0x1000 ## Event created by ::urCommandBufferEnqueueExp
INTEROP_SEMAPHORE_WAIT_EXP = 0x2000 ## Event created by ::urBindlessImagesWaitExternalSemaphoreExp
INTEROP_SEMAPHORE_SIGNAL_EXP = 0x2001 ## Event created by ::urBindlessImagesSignalExternalSemaphoreExp

Expand Down
13 changes: 8 additions & 5 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,11 @@ typedef enum ur_result_t {
UR_RESULT_ERROR_ADAPTER_SPECIFIC = 67, ///< An adapter specific warning/error has been reported and can be
///< retrieved via the urPlatformGetLastError entry point.
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP = 0x1000, ///< Invalid Command-Buffer
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP = 0x1000, ///< Invalid Command-Buffer
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP = 0x1001, ///< Sync point is not valid for the command-buffer
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP = 0x1001, ///< Sync point is not valid for the command-buffer
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP = 0x1002, ///< Sync point wait list is invalid
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP = 0x1002, ///< Sync point wait list is invalid
UR_RESULT_ERROR_UNKNOWN = 0x7ffffffe, ///< Unknown or internal error
/// @cond
UR_RESULT_FORCE_UINT32 = 0x7fffffff
Expand Down Expand Up @@ -259,10 +262,10 @@ typedef enum ur_structure_type_t {
UR_STRUCTURE_TYPE_SAMPLER_NATIVE_PROPERTIES = 24, ///< ::ur_sampler_native_properties_t
UR_STRUCTURE_TYPE_QUEUE_NATIVE_DESC = 25, ///< ::ur_queue_native_desc_t
UR_STRUCTURE_TYPE_DEVICE_PARTITION_PROPERTIES = 26, ///< ::ur_device_partition_properties_t
UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC = 27, ///< ::ur_exp_command_buffer_desc_t
UR_STRUCTURE_TYPE_EXP_SAMPLER_MIP_PROPERTIES = 28, ///< ::ur_exp_sampler_mip_properties_t
UR_STRUCTURE_TYPE_KERNEL_ARG_MEM_OBJ_PROPERTIES = 29, ///< ::ur_kernel_arg_mem_obj_properties_t
UR_STRUCTURE_TYPE_PHYSICAL_MEM_PROPERTIES = 30, ///< ::ur_physical_mem_properties_t
UR_STRUCTURE_TYPE_KERNEL_ARG_MEM_OBJ_PROPERTIES = 27, ///< ::ur_kernel_arg_mem_obj_properties_t
UR_STRUCTURE_TYPE_PHYSICAL_MEM_PROPERTIES = 28, ///< ::ur_physical_mem_properties_t
UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC = 0x1000, ///< ::ur_exp_command_buffer_desc_t
UR_STRUCTURE_TYPE_EXP_SAMPLER_MIP_PROPERTIES = 0x2000, ///< ::ur_exp_sampler_mip_properties_t
/// @cond
UR_STRUCTURE_TYPE_FORCE_UINT32 = 0x7fffffff
/// @endcond
Expand Down Expand Up @@ -4684,7 +4687,7 @@ typedef enum ur_command_t {
UR_COMMAND_DEVICE_GLOBAL_VARIABLE_READ = 24, ///< Event created by ::urEnqueueDeviceGlobalVariableRead
UR_COMMAND_READ_HOST_PIPE = 25, ///< Event created by ::urEnqueueReadHostPipe
UR_COMMAND_WRITE_HOST_PIPE = 26, ///< Event created by ::urEnqueueWriteHostPipe
UR_COMMAND_COMMAND_BUFFER_ENQUEUE_EXP = 27, ///< Event created by ::urCommandBufferEnqueueExp
UR_COMMAND_COMMAND_BUFFER_ENQUEUE_EXP = 0x1000, ///< Event created by ::urCommandBufferEnqueueExp
UR_COMMAND_INTEROP_SEMAPHORE_WAIT_EXP = 0x2000, ///< Event created by ::urBindlessImagesWaitExternalSemaphoreExp
UR_COMMAND_INTEROP_SEMAPHORE_SIGNAL_EXP = 0x2001, ///< Event created by ::urBindlessImagesSignalExternalSemaphoreExp
/// @cond
Expand Down
4 changes: 0 additions & 4 deletions scripts/core/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ etors:
desc: $x_queue_native_desc_t
- name: DEVICE_PARTITION_PROPERTIES
desc: $x_device_partition_properties_t
- name: EXP_COMMAND_BUFFER_DESC
desc: $x_exp_command_buffer_desc_t
- name: EXP_SAMPLER_MIP_PROPERTIES
desc: $x_exp_sampler_mip_properties_t
- name: KERNEL_ARG_MEM_OBJ_PROPERTIES
desc: $x_kernel_arg_mem_obj_properties_t
- name: PHYSICAL_MEM_PROPERTIES
Expand Down
48 changes: 0 additions & 48 deletions scripts/core/device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,54 +383,6 @@ etors:
desc: "[uint32_t] The maximum number of registers available per block."
- name: IP_VERSION
desc: "[uint32_t] The device IP version. The meaning of the device IP version is implementation-defined, but newer devices should have a higher version than older devices."
- name: BINDLESS_IMAGES_SUPPORT_EXP
value: "0x2000"
desc: "[$x_bool_t] returns true if the device supports the creation of bindless images"
- name: BINDLESS_IMAGES_1D_USM_SUPPORT_EXP
value: "0x2001"
desc: "[$x_bool_t] returns true if the device supports the creation of 1D bindless images backed by USM"
- name: BINDLESS_IMAGES_2D_USM_SUPPORT_EXP
value: "0x2002"
desc: "[$x_bool_t] returns true if the device supports the creation of 2D bindless images backed by USM"
- name: BINDLESS_IMAGES_3D_USM_SUPPORT_EXP
value: "0x2003"
desc: "[$x_bool_t] returns true if the device supports the creation of 3D bindless images backed by USM"
- name: IMAGE_PITCH_ALIGN_EXP
value: "0x2004"
desc: "[uint32_t] returns the required alignment of the pitch between two rows of an image in bytes"
- name: MAX_IMAGE_LINEAR_WIDTH_EXP
value: "0x2005"
desc: "[size_t] returns the maximum linear width allowed for images allocated using USM"
- name: MAX_IMAGE_LINEAR_HEIGHT_EXP
value: "0x2006"
desc: "[size_t] returns the maximum linear height allowed for images allocated using USM"
- name: MAX_IMAGE_LINEAR_PITCH_EXP
value: "0x2007"
desc: "[size_t] returns the maximum linear pitch allowed for images allocated using USM"
- name: MIPMAP_SUPPORT_EXP
value: "0x2008"
desc: "[$x_bool_t] returns true if the device supports allocating mipmap resources"
- name: MIPMAP_ANISOTROPY_SUPPORT_EXP
value: "0x2009"
desc: "[$x_bool_t] returns true if the device supports sampling mipmap images with anisotropic filtering"
- name: MIPMAP_MAX_ANISOTROPY_EXP
value: "0x200A"
desc: "[uint32_t] returns the maximum anisotropic ratio supported by the device"
- name: MIPMAP_LEVEL_REFERENCE_SUPPORT_EXP
value: "0x200B"
desc: "[$x_bool_t] returns true if the device supports using images created from individual mipmap levels"
- name: INTEROP_MEMORY_IMPORT_SUPPORT_EXP
value: "0x200C"
desc: "[$x_bool_t] returns true if the device supports importing external memory resources"
- name: INTEROP_MEMORY_EXPORT_SUPPORT_EXP
value: "0x200D"
desc: "[$x_bool_t] returns true if the device supports exporting internal memory resources"
- name: INTEROP_SEMAPHORE_IMPORT_SUPPORT_EXP
value: "0x200E"
desc: "[$x_bool_t] returns true if the device supports importing external semaphore resources"
- name: INTEROP_SEMAPHORE_EXPORT_SUPPORT_EXP
value: "0x200F"
desc: "[$x_bool_t] returns true if the device supports exporting internal event resources"
--- #--------------------------------------------------------------------------
type: function
desc: "Retrieves various information about device"
Expand Down
8 changes: 0 additions & 8 deletions scripts/core/event.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ etors:
desc: Event created by $xEnqueueReadHostPipe
- name: WRITE_HOST_PIPE
desc: Event created by $xEnqueueWriteHostPipe
- name: COMMAND_BUFFER_ENQUEUE_EXP
desc: Event created by $xCommandBufferEnqueueExp
- name: INTEROP_SEMAPHORE_WAIT_EXP
value: "0x2000"
desc: Event created by $xBindlessImagesWaitExternalSemaphoreExp
- name: INTEROP_SEMAPHORE_SIGNAL_EXP
value: "0x2001"
desc: Event created by $xBindlessImagesSignalExternalSemaphoreExp
--- #--------------------------------------------------------------------------
type: enum
desc: "Event Status"
Expand Down
75 changes: 75 additions & 0 deletions scripts/core/exp-bindless-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,81 @@ class: $xBindlessImages
name: "$x_exp_interop_semaphore_handle_t"
--- #--------------------------------------------------------------------------
type: enum
extend: true
desc: "Extension enums to $x_device_info_t to support bindless images."
name: $x_device_info_t
etors:
- name: BINDLESS_IMAGES_SUPPORT_EXP
value: "0x2000"
desc: "[$x_bool_t] returns true if the device supports the creation of bindless images"
- name: BINDLESS_IMAGES_1D_USM_SUPPORT_EXP
value: "0x2001"
desc: "[$x_bool_t] returns true if the device supports the creation of 1D bindless images backed by USM"
- name: BINDLESS_IMAGES_2D_USM_SUPPORT_EXP
value: "0x2002"
desc: "[$x_bool_t] returns true if the device supports the creation of 2D bindless images backed by USM"
- name: BINDLESS_IMAGES_3D_USM_SUPPORT_EXP
value: "0x2003"
desc: "[$x_bool_t] returns true if the device supports the creation of 3D bindless images backed by USM"
- name: IMAGE_PITCH_ALIGN_EXP
value: "0x2004"
desc: "[uint32_t] returns the required alignment of the pitch between two rows of an image in bytes"
- name: MAX_IMAGE_LINEAR_WIDTH_EXP
value: "0x2005"
desc: "[size_t] returns the maximum linear width allowed for images allocated using USM"
- name: MAX_IMAGE_LINEAR_HEIGHT_EXP
value: "0x2006"
desc: "[size_t] returns the maximum linear height allowed for images allocated using USM"
- name: MAX_IMAGE_LINEAR_PITCH_EXP
value: "0x2007"
desc: "[size_t] returns the maximum linear pitch allowed for images allocated using USM"
- name: MIPMAP_SUPPORT_EXP
value: "0x2008"
desc: "[$x_bool_t] returns true if the device supports allocating mipmap resources"
- name: MIPMAP_ANISOTROPY_SUPPORT_EXP
value: "0x2009"
desc: "[$x_bool_t] returns true if the device supports sampling mipmap images with anisotropic filtering"
- name: MIPMAP_MAX_ANISOTROPY_EXP
value: "0x200A"
desc: "[uint32_t] returns the maximum anisotropic ratio supported by the device"
- name: MIPMAP_LEVEL_REFERENCE_SUPPORT_EXP
value: "0x200B"
desc: "[$x_bool_t] returns true if the device supports using images created from individual mipmap levels"
- name: INTEROP_MEMORY_IMPORT_SUPPORT_EXP
value: "0x200C"
desc: "[$x_bool_t] returns true if the device supports importing external memory resources"
- name: INTEROP_MEMORY_EXPORT_SUPPORT_EXP
value: "0x200D"
desc: "[$x_bool_t] returns true if the device supports exporting internal memory resources"
- name: INTEROP_SEMAPHORE_IMPORT_SUPPORT_EXP
value: "0x200E"
desc: "[$x_bool_t] returns true if the device supports importing external semaphore resources"
- name: INTEROP_SEMAPHORE_EXPORT_SUPPORT_EXP
value: "0x200F"
desc: "[$x_bool_t] returns true if the device supports exporting internal event resources"
--- #--------------------------------------------------------------------------
type: enum
extend: true
desc: "Structure Type experimental enumerations."
name: $x_structure_type_t
etors:
- name: EXP_SAMPLER_MIP_PROPERTIES
desc: $x_exp_sampler_mip_properties_t
value: "0x2000"
--- #--------------------------------------------------------------------------
type: enum
extend: true
desc: "Command Type experimental enumerations."
name: $x_command_t
etors:
- name: INTEROP_SEMAPHORE_WAIT_EXP
value: "0x2000"
desc: Event created by $xBindlessImagesWaitExternalSemaphoreExp
- name: INTEROP_SEMAPHORE_SIGNAL_EXP
value: "0x2001"
desc: Event created by $xBindlessImagesSignalExternalSemaphoreExp
--- #--------------------------------------------------------------------------
type: enum
desc: "Dictates the type of memory copy."
class: $xBindlessImages
name: $x_exp_image_copy_flags_t
Expand Down
33 changes: 33 additions & 0 deletions scripts/core/exp-command-buffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@ type: header
desc: "Intel $OneApi Unified Runtime Experimental APIs for Command-Buffers"
ordinal: "99"
--- #--------------------------------------------------------------------------
type: enum
extend: true
desc: "Experimental Command Buffer result type enums."
name: $x_result_t
etors:
- name: ERROR_INVALID_COMMAND_BUFFER_EXP
value: "0x1000"
desc: "Invalid Command-Buffer"
- name: ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP
value: "0x1001"
desc: "Sync point is not valid for the command-buffer"
- name: ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP
value: "0x1002"
desc: "Sync point wait list is invalid"
--- #--------------------------------------------------------------------------
type: enum
extend: true
desc: "Extend enumeration of Command Buffer Structure Type."
name: $x_structure_type_t
etors:
- name: EXP_COMMAND_BUFFER_DESC
desc: $x_exp_command_buffer_desc_t
value: "0x1000"
--- #--------------------------------------------------------------------------
type: enum
extend: true
desc: "Extend command type enumeration for Command-Buffer experimental feature."
name: $x_command_t
etors:
- name: COMMAND_BUFFER_ENQUEUE_EXP
desc: Event created by $xCommandBufferEnqueueExp
value: "0x1000"
--- #--------------------------------------------------------------------------
type: macro
desc: "The extension string which defines support for command-buffers which is returned when querying device extensions."
name: $X_COMMAND_BUFFER_EXTENSION_STRING_EXP
Expand Down
33 changes: 32 additions & 1 deletion scripts/parse_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ def _generate_meta(d, ordinal, meta):
for idx, etor in enumerate(d['etors']):
meta[type][name]['etors'].append(etor['name'])
value = _get_etor_value(etor.get('value'), value)
if not etor.get('value'):
etor['value'] = str(value)
if type_traits.is_flags(name):
bit_mask |= value
if value > max_value:
Expand All @@ -568,7 +570,7 @@ def _generate_meta(d, ordinal, meta):
if bit_mask != 0:
meta[type][name]['bit_mask'] = hex(ctypes.c_uint32(~bit_mask).value)
else:
meta[type][name]['max'] = d['etors'][idx]['name']
meta[type][name]['max'] = d['etors'][max_index]['name']

elif 'macro' == type:
meta[type][name]['values'] = []
Expand Down Expand Up @@ -797,6 +799,31 @@ def _generate_ref(specs, tags, ref):

return ref

def refresh_enum_meta(obj, header, meta):
## remove the existing meta records
if obj.get('class'):
meta['class'][obj['class']]['enum'].remove(obj['name'])

del meta['enum'][obj['name']]
## re-generate meta
meta = _generate_meta(obj, header['ordinal'], meta)


def handle_enum_extensions(d, specs, header, meta):
matching_enum = [obj for s in specs for obj in s['objects'] if obj['type'] == 'enum' and d['name'] == obj['name']][0]
matching_enum['etors'].extend(d['etors'])

## Refresh metadata
refresh_enum_meta(matching_enum, header, meta)

## Sort the etors
value = -1
def sort_etors(x):
nonlocal value
value = _get_etor_value(x.get('value'), value)
return value
matching_enum['etors'] = sorted(matching_enum['etors'], key=sort_etors)


"""
Entry-point:
Expand Down Expand Up @@ -832,6 +859,10 @@ def parse(section, version, tags, meta, ref):
if not d:
continue

if d['type'] == "enum" and d.get("extend") == True:
handle_enum_extensions(d, specs, header, meta)
continue

# extract header from objects
if re.match(r"header", d['type']):
header = d
Expand Down
Loading

0 comments on commit 590cb44

Please sign in to comment.