Skip to content

Commit c613348

Browse files
author
Petr Vesely
committed
[UR] Implement extension mechanism
1 parent 000c083 commit c613348

File tree

15 files changed

+480
-1
lines changed

15 files changed

+480
-1
lines changed

include/ur.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,21 @@ def __str__(self):
323323
return str(ur_platform_backend_v(self.value))
324324

325325

326+
###############################################################################
327+
## @brief Extension name maximum length.
328+
UR_MAX_EXTENSION_NAME_LENGTH = 256
329+
330+
###############################################################################
331+
## @brief Extension properties.
332+
class ur_extension_properties_t(Structure):
333+
_fields_ = [
334+
("stype", ur_structure_type_t), ## [in] type of this structure, must be
335+
## ::UR_STRUCTURE_TYPE_EXTENSION_PROPERTIES
336+
("pNext", c_void_p), ## [in,out][optional] pointer to extension-specific structure
337+
("name", c_char * UR_MAX_EXTENSION_NAME_LENGTH), ## [in] null-terminated extension name.
338+
("version", c_ulong) ## [in] version of the extension using ::UR_MAKE_VERSION.
339+
]
340+
326341
###############################################################################
327342
## @brief Target identification strings for
328343
## ::ur_device_binary_t.pDeviceTargetSpec
@@ -1752,6 +1767,13 @@ def __str__(self):
17521767
else:
17531768
_urPlatformGetBackendOption_t = CFUNCTYPE( ur_result_t, ur_platform_handle_t, c_char_p, POINTER(c_char_p) )
17541769

1770+
###############################################################################
1771+
## @brief Function-pointer for urPlatformGetExtensionProperties
1772+
if __use_win_types:
1773+
_urPlatformGetExtensionProperties_t = WINFUNCTYPE( ur_result_t, ur_platform_handle_t, c_ulong, POINTER(ur_extension_properties_t), POINTER(c_ulong) )
1774+
else:
1775+
_urPlatformGetExtensionProperties_t = CFUNCTYPE( ur_result_t, ur_platform_handle_t, c_ulong, POINTER(ur_extension_properties_t), POINTER(c_ulong) )
1776+
17551777

17561778
###############################################################################
17571779
## @brief Table of Platform functions pointers
@@ -1762,7 +1784,8 @@ class ur_platform_dditable_t(Structure):
17621784
("pfnGetNativeHandle", c_void_p), ## _urPlatformGetNativeHandle_t
17631785
("pfnCreateWithNativeHandle", c_void_p), ## _urPlatformCreateWithNativeHandle_t
17641786
("pfnGetApiVersion", c_void_p), ## _urPlatformGetApiVersion_t
1765-
("pfnGetBackendOption", c_void_p) ## _urPlatformGetBackendOption_t
1787+
("pfnGetBackendOption", c_void_p), ## _urPlatformGetBackendOption_t
1788+
("pfnGetExtensionProperties", c_void_p) ## _urPlatformGetExtensionProperties_t
17661789
]
17671790

17681791
###############################################################################
@@ -2761,6 +2784,7 @@ def __init__(self, version : ur_api_version_t):
27612784
self.urPlatformCreateWithNativeHandle = _urPlatformCreateWithNativeHandle_t(self.__dditable.Platform.pfnCreateWithNativeHandle)
27622785
self.urPlatformGetApiVersion = _urPlatformGetApiVersion_t(self.__dditable.Platform.pfnGetApiVersion)
27632786
self.urPlatformGetBackendOption = _urPlatformGetBackendOption_t(self.__dditable.Platform.pfnGetBackendOption)
2787+
self.urPlatformGetExtensionProperties = _urPlatformGetExtensionProperties_t(self.__dditable.Platform.pfnGetExtensionProperties)
27642788

27652789
# call driver to get function pointers
27662790
Context = ur_context_dditable_t()

include/ur_api.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,41 @@ typedef enum ur_platform_backend_t {
606606

607607
} ur_platform_backend_t;
608608

609+
///////////////////////////////////////////////////////////////////////////////
610+
#ifndef UR_MAX_EXTENSION_NAME_LENGTH
611+
/// @brief Extension name maximum length.
612+
#define UR_MAX_EXTENSION_NAME_LENGTH 256
613+
#endif // UR_MAX_EXTENSION_NAME_LENGTH
614+
615+
///////////////////////////////////////////////////////////////////////////////
616+
/// @brief Extension properties.
617+
typedef struct ur_extension_properties_t {
618+
ur_structure_type_t stype; ///< [in] type of this structure, must be
619+
///< ::UR_STRUCTURE_TYPE_EXTENSION_PROPERTIES
620+
void *pNext; ///< [in,out][optional] pointer to extension-specific structure
621+
char name[UR_MAX_EXTENSION_NAME_LENGTH]; ///< [in] null-terminated extension name.
622+
uint32_t version; ///< [in] version of the extension using ::UR_MAKE_VERSION.
623+
624+
} ur_extension_properties_t;
625+
626+
///////////////////////////////////////////////////////////////////////////////
627+
/// @brief Retrieve the set of supported extensions.
628+
///
629+
/// @returns
630+
/// - ::UR_RESULT_SUCCESS
631+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
632+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
633+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
634+
/// + `NULL == hPlatform`
635+
UR_APIEXPORT ur_result_t UR_APICALL
636+
urPlatformGetExtensionProperties(
637+
ur_platform_handle_t hPlatform, ///< [in] handle to the platform.
638+
uint32_t count, ///< [in] number of extension properties to fetch.
639+
ur_extension_properties_t *pExtensionProperties, ///< [out][optional] array of supported extension.
640+
uint32_t *pCountRet ///< [out][optional] will be updated with the total count of supported
641+
///< extensions.
642+
);
643+
609644
#if !defined(__GNUC__)
610645
#pragma endregion
611646
#endif
@@ -5671,6 +5706,17 @@ typedef struct ur_platform_get_backend_option_params_t {
56715706
const char ***pppPlatformOption;
56725707
} ur_platform_get_backend_option_params_t;
56735708

5709+
///////////////////////////////////////////////////////////////////////////////
5710+
/// @brief Function parameters for urPlatformGetExtensionProperties
5711+
/// @details Each entry is a pointer to the parameter passed to the function;
5712+
/// allowing the callback the ability to modify the parameter's value
5713+
typedef struct ur_platform_get_extension_properties_params_t {
5714+
ur_platform_handle_t *phPlatform;
5715+
uint32_t *pcount;
5716+
ur_extension_properties_t **ppExtensionProperties;
5717+
uint32_t **ppCountRet;
5718+
} ur_platform_get_extension_properties_params_t;
5719+
56745720
///////////////////////////////////////////////////////////////////////////////
56755721
/// @brief Function parameters for urContextCreate
56765722
/// @details Each entry is a pointer to the parameter passed to the function;

include/ur_ddi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ typedef ur_result_t(UR_APICALL *ur_pfnPlatformGetBackendOption_t)(
6060
const char *,
6161
const char **);
6262

63+
///////////////////////////////////////////////////////////////////////////////
64+
/// @brief Function-pointer for urPlatformGetExtensionProperties
65+
typedef ur_result_t(UR_APICALL *ur_pfnPlatformGetExtensionProperties_t)(
66+
ur_platform_handle_t,
67+
uint32_t,
68+
ur_extension_properties_t *,
69+
uint32_t *);
70+
6371
///////////////////////////////////////////////////////////////////////////////
6472
/// @brief Table of Platform functions pointers
6573
typedef struct ur_platform_dditable_t {
@@ -69,6 +77,7 @@ typedef struct ur_platform_dditable_t {
6977
ur_pfnPlatformCreateWithNativeHandle_t pfnCreateWithNativeHandle;
7078
ur_pfnPlatformGetApiVersion_t pfnGetApiVersion;
7179
ur_pfnPlatformGetBackendOption_t pfnGetBackendOption;
80+
ur_pfnPlatformGetExtensionProperties_t pfnGetExtensionProperties;
7281
} ur_platform_dditable_t;
7382

7483
///////////////////////////////////////////////////////////////////////////////

scripts/core/EXT.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<%
2+
OneApi=tags['$OneApi']
3+
x=tags['$x']
4+
X=x.upper()
5+
%>
6+
==============
7+
Extensions
8+
==============
9+
10+
Objective
11+
=========
12+
13+
Extensions allow for additional functionality to be added to the Unified Runtime specification
14+
without affecting the core specification. Extensions may in future be promoted to the core specification
15+
in a later version of Unified Runtime, when agreed upon by the Working Group. All extensions are
16+
optional and are not required to be implemented by any particular adapter, but are expected to
17+
be widely available and possibly be required in a future version of the specification. Adapters
18+
must report which extensions are supported through the ${x}PlatformGetExtensionProperties query.
19+
Each extensions may also impose additional restrictions on when it can be used - i.e. a platform
20+
or device query.
21+
22+
There are two types of extensions defined by this specification:
23+
24+
1. **Standard** - extension will be included into the current and all future version of the specification.
25+
2. **Experimental** - extensions require additional experimentation and development, before becoming a standard extension.
26+
Applications should not rely on experimental extensions in production.
27+
28+
Requirements
29+
============
30+
31+
- Extensions must use globally unique names for macros, enums, structures and functions
32+
- Extensions must have globally unique extension names reported from ${x}PlatformGetExtensionProperties
33+
- All extensions must be defined in this specification
34+
- Extensions must not break backwards compatibility of the core APIs
35+
- Standard extension versions must be backwards compatible with prior versions
36+
37+
38+
Naming Convention
39+
-----------------
40+
41+
The following naming conventions must be followed for **standard** extensions:
42+
## --validate=off
43+
- The extension name must begin with `${x}_ext`
44+
- All extension functions must be postfixed with `Ext`
45+
- All macros must use all caps `${X}_<NAME>_EXT` convention
46+
- All structures, enumerations and other types must follow `${x}_<name>_ext_t` snake case convention
47+
- All enumerator values must use all caps `${X}_ENUM_EXT_ETOR_NAME` convention
48+
- All handle types must end with `ext_handle_t`
49+
- All descriptor structures must end with `ext_desc_t`
50+
- All property structures must end with `ext_properties_t`
51+
- All flag enumerations must end with `ext_flags_t`
52+
## --validate=on
53+
54+
The following naming conventions must be followed for **experimental** extensions:
55+
56+
## --validate=off
57+
- The extension name must begin with `${x}_exp`
58+
- Experimental extensions may be added and removed from the driver at any time.
59+
- Experimental extensions are not guaranteed to be forward- or backward-compatible between versions.
60+
- Experimental extensions are not guaranteed to be supported in production driver releases; and may appear and disappear from release to release.
61+
- All extension functions must be postfixed with `Exp`
62+
- All macros must use all caps `${X}_<NAME>_EXP` convention
63+
- All structures, enumerations and other types must follow `${x}_<name>_exp_t` snake case convention
64+
- All enumerator values must use all caps `${X}_ENUM_EXP_ETOR_NAME` convention
65+
- All handle types must end with `exp_handle_t`
66+
- All descriptor structures must end with `exp_desc_t`
67+
- All property structures must end with `exp_properties_t`
68+
- All flag enumerations must end with `exp_flags_t`
69+
## --validate=on
70+
71+
Extending Enumerations
72+
----------------------
73+
74+
Any existing enumeration may be extended by adding new enumerators. Enumerators must use the extensions naming
75+
convention and values should be assigned to avoid future compatibility issues.
76+
77+
78+
Extending Structures
79+
--------------------
80+
81+
Any structure derived from `${x}_base_desc_t`` or `${x}_base_properties_t`` can be extended using structure chains. No other
82+
method of extending structures is allowed.
83+
84+
A structure chain can contain more than one extension structure, in any order. Therefore, extensions should not
85+
be dependent on their order relative to other extensions and the implementation must be order agnostic. In addition,
86+
the implementation will ignore extended structures that it does not support.
87+
88+
The extension must document the specific structures and functions that may be extended using the structure chain.
89+
90+
91+
// TODO - list all extensions

scripts/core/platform.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,40 @@ etors:
242242
- name: HIP
243243
value: "4"
244244
desc: "The backend is HIP"
245+
--- #--------------------------------------------------------------------------
246+
type: macro
247+
desc: "Extension name maximum length."
248+
name: $X_MAX_EXTENSION_NAME_LENGTH
249+
value: "256"
250+
--- #--------------------------------------------------------------------------
251+
type: struct
252+
desc: "Extension properties."
253+
name: $x_extension_properties_t
254+
base: $x_base_properties_t
255+
class: $xPlatform
256+
members:
257+
- type: char
258+
name: name[$X_MAX_EXTENSION_NAME_LENGTH]
259+
desc: "[in] null-terminated extension name."
260+
- type: uint32_t
261+
name: version
262+
desc: "[in] version of the extension using $X_MAKE_VERSION."
263+
--- #--------------------------------------------------------------------------
264+
type: function
265+
desc: "Retrieve the set of supported extensions."
266+
class: $xPlatform
267+
name: GetExtensionProperties
268+
decl: static
269+
params:
270+
- type: $x_platform_handle_t
271+
name: hPlatform
272+
desc: "[in] handle to the platform."
273+
- type: uint32_t
274+
name: count
275+
desc: "[in] number of extension properties to fetch."
276+
- type: $x_extension_properties_t*
277+
name: pExtensionProperties
278+
desc: "[out][optional] array of supported extension."
279+
- type: uint32_t*
280+
name: pCountRet
281+
desc: "[out][optional] will be updated with the total count of supported extensions."

scripts/templates/index.rst.mako

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313

1414
core/INTRO.rst
1515
core/PROG.rst
16+
core/EXT.rst
1617
api.rst

source/adapters/null/ur_nullddi.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,32 @@ __urdlllocal ur_result_t UR_APICALL urGetLastResult(
218218
return result;
219219
}
220220

221+
///////////////////////////////////////////////////////////////////////////////
222+
/// @brief Intercept function for urPlatformGetExtensionProperties
223+
__urdlllocal ur_result_t UR_APICALL urPlatformGetExtensionProperties(
224+
ur_platform_handle_t hPlatform, ///< [in] handle to the platform.
225+
uint32_t count, ///< [in] number of extension properties to fetch.
226+
ur_extension_properties_t *
227+
pExtensionProperties, ///< [out][optional] array of supported extension.
228+
uint32_t *
229+
pCountRet ///< [out][optional] will be updated with the total count of supported
230+
///< extensions.
231+
) {
232+
ur_result_t result = UR_RESULT_SUCCESS;
233+
234+
// if the driver has created a custom function, then call it instead of using the generic path
235+
auto pfnGetExtensionProperties =
236+
d_context.urDdiTable.Platform.pfnGetExtensionProperties;
237+
if (nullptr != pfnGetExtensionProperties) {
238+
result = pfnGetExtensionProperties(hPlatform, count,
239+
pExtensionProperties, pCountRet);
240+
} else {
241+
// generic implementation
242+
}
243+
244+
return result;
245+
}
246+
221247
///////////////////////////////////////////////////////////////////////////////
222248
/// @brief Intercept function for urDeviceGet
223249
__urdlllocal ur_result_t UR_APICALL urDeviceGet(
@@ -3440,6 +3466,9 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetPlatformProcAddrTable(
34403466

34413467
pDdiTable->pfnGetBackendOption = driver::urPlatformGetBackendOption;
34423468

3469+
pDdiTable->pfnGetExtensionProperties =
3470+
driver::urPlatformGetExtensionProperties;
3471+
34433472
return result;
34443473
}
34453474

0 commit comments

Comments
 (0)