Skip to content

Commit 0f3d083

Browse files
committed
[UR] Add backend option entrypoint
1 parent e9f534a commit 0f3d083

13 files changed

Lines changed: 334 additions & 1 deletion

File tree

include/ur.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,7 @@ class ur_function_v(IntEnum):
15771577
USM_GET_MEM_ALLOC_INFO = 111 ## Enumerator for ::urUSMGetMemAllocInfo
15781578
USM_POOL_CREATE = 112 ## Enumerator for ::urUSMPoolCreate
15791579
USM_POOL_DESTROY = 113 ## Enumerator for ::urUSMPoolDestroy
1580+
PLATFORM_GET_BACKEND_OPTION = 114 ## Enumerator for ::urPlatformGetBackendOption
15801581

15811582
class ur_function_t(c_int):
15821583
def __str__(self):
@@ -1642,6 +1643,13 @@ def __str__(self):
16421643
else:
16431644
_urPlatformGetApiVersion_t = CFUNCTYPE( ur_result_t, ur_platform_handle_t, POINTER(ur_api_version_t) )
16441645

1646+
###############################################################################
1647+
## @brief Function-pointer for urPlatformGetBackendOption
1648+
if __use_win_types:
1649+
_urPlatformGetBackendOption_t = WINFUNCTYPE( ur_result_t, ur_platform_handle_t, c_char_p, POINTER(c_char_p) )
1650+
else:
1651+
_urPlatformGetBackendOption_t = CFUNCTYPE( ur_result_t, ur_platform_handle_t, c_char_p, POINTER(c_char_p) )
1652+
16451653

16461654
###############################################################################
16471655
## @brief Table of Platform functions pointers
@@ -1651,7 +1659,8 @@ class ur_platform_dditable_t(Structure):
16511659
("pfnGetInfo", c_void_p), ## _urPlatformGetInfo_t
16521660
("pfnGetNativeHandle", c_void_p), ## _urPlatformGetNativeHandle_t
16531661
("pfnCreateWithNativeHandle", c_void_p), ## _urPlatformCreateWithNativeHandle_t
1654-
("pfnGetApiVersion", c_void_p) ## _urPlatformGetApiVersion_t
1662+
("pfnGetApiVersion", c_void_p), ## _urPlatformGetApiVersion_t
1663+
("pfnGetBackendOption", c_void_p) ## _urPlatformGetBackendOption_t
16551664
]
16561665

16571666
###############################################################################
@@ -2641,6 +2650,7 @@ def __init__(self, version : ur_api_version_t):
26412650
self.urPlatformGetNativeHandle = _urPlatformGetNativeHandle_t(self.__dditable.Platform.pfnGetNativeHandle)
26422651
self.urPlatformCreateWithNativeHandle = _urPlatformCreateWithNativeHandle_t(self.__dditable.Platform.pfnCreateWithNativeHandle)
26432652
self.urPlatformGetApiVersion = _urPlatformGetApiVersion_t(self.__dditable.Platform.pfnGetApiVersion)
2653+
self.urPlatformGetBackendOption = _urPlatformGetBackendOption_t(self.__dditable.Platform.pfnGetBackendOption)
26442654

26452655
# call driver to get function pointers
26462656
Context = ur_context_dditable_t()

include/ur_api.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,36 @@ urPlatformCreateWithNativeHandle(
522522
ur_platform_handle_t *phPlatform ///< [out] pointer to the handle of the platform object created.
523523
);
524524

525+
///////////////////////////////////////////////////////////////////////////////
526+
/// @brief Get the adapter specific compiler backend option from a generic
527+
/// frontend option.
528+
///
529+
/// @details
530+
/// - The string returned via the ppAdapterOption is a NULL terminated C
531+
/// style string.
532+
/// - The string returned via the ppAdapterOption is thread local.
533+
/// - The memory in the string returned via the ppAdapterOption is owned by
534+
/// the adapter.
535+
/// - The application may call this function from simultaneous threads.
536+
/// - The implementation of this function should be lock-free.
537+
///
538+
/// @returns
539+
/// - ::UR_RESULT_SUCCESS
540+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
541+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
542+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
543+
/// + `NULL == hPlatform`
544+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
545+
/// + `NULL == pFrontendOption`
546+
/// + `NULL == ppAdapterOption`
547+
UR_APIEXPORT ur_result_t UR_APICALL
548+
urPlatformGetBackendOption(
549+
ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance.
550+
const char *pFrontendOption, ///< [in] string containing the frontend option.
551+
const char **ppAdapterOption ///< [out] returns the correct adapter specific option based on the
552+
///< frontend option.
553+
);
554+
525555
///////////////////////////////////////////////////////////////////////////////
526556
/// @brief Retrieve string representation of the underlying adapter specific
527557
/// result reported by the the last API that returned
@@ -4295,6 +4325,7 @@ typedef enum ur_function_t {
42954325
UR_FUNCTION_USM_GET_MEM_ALLOC_INFO = 111, ///< Enumerator for ::urUSMGetMemAllocInfo
42964326
UR_FUNCTION_USM_POOL_CREATE = 112, ///< Enumerator for ::urUSMPoolCreate
42974327
UR_FUNCTION_USM_POOL_DESTROY = 113, ///< Enumerator for ::urUSMPoolDestroy
4328+
UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION = 114, ///< Enumerator for ::urPlatformGetBackendOption
42984329
/// @cond
42994330
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
43004331
/// @endcond
@@ -5526,6 +5557,28 @@ typedef void(UR_APICALL *ur_pfnPlatformGetApiVersionCb_t)(
55265557
void *pTracerUserData,
55275558
void **ppTracerInstanceUserData);
55285559

5560+
///////////////////////////////////////////////////////////////////////////////
5561+
/// @brief Callback function parameters for urPlatformGetBackendOption
5562+
/// @details Each entry is a pointer to the parameter passed to the function;
5563+
/// allowing the callback the ability to modify the parameter's value
5564+
typedef struct ur_platform_get_backend_option_params_t {
5565+
ur_platform_handle_t *phPlatform;
5566+
const char **ppFrontendOption;
5567+
const char ***pppAdapterOption;
5568+
} ur_platform_get_backend_option_params_t;
5569+
5570+
///////////////////////////////////////////////////////////////////////////////
5571+
/// @brief Callback function-pointer for urPlatformGetBackendOption
5572+
/// @param[in] params Parameters passed to this instance
5573+
/// @param[in] result Return value
5574+
/// @param[in] pTracerUserData Per-Tracer user data
5575+
/// @param[in,out] ppTracerInstanceUserData Per-Tracer, Per-Instance user data
5576+
typedef void(UR_APICALL *ur_pfnPlatformGetBackendOptionCb_t)(
5577+
ur_platform_get_backend_option_params_t *params,
5578+
ur_result_t result,
5579+
void *pTracerUserData,
5580+
void **ppTracerInstanceUserData);
5581+
55295582
///////////////////////////////////////////////////////////////////////////////
55305583
/// @brief Table of Platform callback functions pointers
55315584
typedef struct ur_platform_callbacks_t {
@@ -5534,6 +5587,7 @@ typedef struct ur_platform_callbacks_t {
55345587
ur_pfnPlatformGetNativeHandleCb_t pfnGetNativeHandleCb;
55355588
ur_pfnPlatformCreateWithNativeHandleCb_t pfnCreateWithNativeHandleCb;
55365589
ur_pfnPlatformGetApiVersionCb_t pfnGetApiVersionCb;
5590+
ur_pfnPlatformGetBackendOptionCb_t pfnGetBackendOptionCb;
55375591
} ur_platform_callbacks_t;
55385592

55395593
///////////////////////////////////////////////////////////////////////////////

include/ur_ddi.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ typedef ur_result_t(UR_APICALL *ur_pfnPlatformGetApiVersion_t)(
5353
ur_platform_handle_t,
5454
ur_api_version_t *);
5555

56+
///////////////////////////////////////////////////////////////////////////////
57+
/// @brief Function-pointer for urPlatformGetBackendOption
58+
typedef ur_result_t(UR_APICALL *ur_pfnPlatformGetBackendOption_t)(
59+
ur_platform_handle_t,
60+
const char *,
61+
const char **);
62+
5663
///////////////////////////////////////////////////////////////////////////////
5764
/// @brief Table of Platform functions pointers
5865
typedef struct ur_platform_dditable_t {
@@ -61,6 +68,7 @@ typedef struct ur_platform_dditable_t {
6168
ur_pfnPlatformGetNativeHandle_t pfnGetNativeHandle;
6269
ur_pfnPlatformCreateWithNativeHandle_t pfnCreateWithNativeHandle;
6370
ur_pfnPlatformGetApiVersion_t pfnGetApiVersion;
71+
ur_pfnPlatformGetBackendOption_t pfnGetBackendOption;
6472
} ur_platform_dditable_t;
6573

6674
///////////////////////////////////////////////////////////////////////////////

scripts/core/platform.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,28 @@ params:
168168
[out] pointer to the handle of the platform object created.
169169
--- #--------------------------------------------------------------------------
170170
type: function
171+
desc: "Get the adapter specific compiler backend option from a generic frontend option."
172+
class: $xPlatform
173+
name: GetBackendOption
174+
decl: static
175+
details:
176+
- "The string returned via the ppAdapterOption is a NULL terminated C style string."
177+
- "The string returned via the ppAdapterOption is thread local."
178+
- "The memory in the string returned via the ppAdapterOption is owned by the adapter."
179+
- "The application may call this function from simultaneous threads."
180+
- "The implementation of this function should be lock-free."
181+
params:
182+
- type: $x_platform_handle_t
183+
name: hPlatform
184+
desc: "[in] handle of the platform instance."
185+
- type: const char*
186+
name: pFrontendOption
187+
desc: "[in] string containing the frontend option."
188+
- type: const char**
189+
name: ppAdapterOption
190+
desc: "[out] returns the correct adapter specific option based on the frontend option."
191+
--- #--------------------------------------------------------------------------
192+
type: function
171193
desc: "Retrieve string representation of the underlying adapter specific result
172194
reported by the the last API that returned UR_RESULT_ADAPTER_SPECIFIC.
173195
Allows for an adapter independent way to return an adapter

scripts/core/registry.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,6 @@ etors:
346346
- name: USM_POOL_DESTROY
347347
desc: Enumerator for $xUSMPoolDestroy
348348
value: '113'
349+
- name: PLATFORM_GET_BACKEND_OPTION
350+
desc: Enumerator for $xPlatformGetBackendOption
351+
value: '114'

scripts/generate_ids.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def generate_registry(path, specs):
5252
print("Updating registry %s"%path)
5353

5454
ids = new_registry
55+
ids = sorted(ids, key=lambda x: int(x['value']))
5556
wrapper = { 'name': ENUM_NAME, 'type': 'enum', 'desc': 'Defines unique stable identifiers for all functions' , 'etors': ids}
5657
header = {'type': 'header', 'desc': quoted('Intel$OneApi Unified Rutime function registry'), 'ordinal': quoted(9)}
5758

source/common/ur_params.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4270,6 +4270,10 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) {
42704270
case UR_FUNCTION_USM_POOL_DESTROY:
42714271
os << "UR_FUNCTION_USM_POOL_DESTROY";
42724272
break;
4273+
4274+
case UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION:
4275+
os << "UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION";
4276+
break;
42734277
default:
42744278
os << "unknown enumerator";
42754279
break;
@@ -6730,6 +6734,27 @@ operator<<(std::ostream &os,
67306734
return os;
67316735
}
67326736

6737+
inline std::ostream &
6738+
operator<<(std::ostream &os,
6739+
const struct ur_platform_get_backend_option_params_t *params) {
6740+
6741+
os << ".hPlatform = ";
6742+
6743+
ur_params::serializePtr(os, *(params->phPlatform));
6744+
6745+
os << ", ";
6746+
os << ".pFrontendOption = ";
6747+
6748+
ur_params::serializePtr(os, *(params->ppFrontendOption));
6749+
6750+
os << ", ";
6751+
os << ".ppAdapterOption = ";
6752+
6753+
ur_params::serializePtr(os, *(params->pppAdapterOption));
6754+
6755+
return os;
6756+
}
6757+
67336758
inline std::ostream &
67346759
operator<<(std::ostream &os,
67356760
const struct ur_program_create_with_il_params_t *params) {
@@ -7933,6 +7958,9 @@ inline int serializeFunctionParams(std::ostream &os, uint32_t function,
79337958
case UR_FUNCTION_PLATFORM_GET_API_VERSION: {
79347959
os << (const struct ur_platform_get_api_version_params_t *)params;
79357960
} break;
7961+
case UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION: {
7962+
os << (const struct ur_platform_get_backend_option_params_t *)params;
7963+
} break;
79367964
case UR_FUNCTION_PROGRAM_CREATE_WITH_IL: {
79377965
os << (const struct ur_program_create_with_il_params_t *)params;
79387966
} break;

source/drivers/null/ur_nullddi.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,31 @@ __urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
170170
return result;
171171
}
172172

173+
///////////////////////////////////////////////////////////////////////////////
174+
/// @brief Intercept function for urPlatformGetBackendOption
175+
__urdlllocal ur_result_t UR_APICALL urPlatformGetBackendOption(
176+
ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance.
177+
const char
178+
*pFrontendOption, ///< [in] string containing the frontend option.
179+
const char **
180+
ppAdapterOption ///< [out] returns the correct adapter specific option based on the
181+
///< frontend option.
182+
) {
183+
ur_result_t result = UR_RESULT_SUCCESS;
184+
185+
// if the driver has created a custom function, then call it instead of using the generic path
186+
auto pfnGetBackendOption =
187+
d_context.urDdiTable.Platform.pfnGetBackendOption;
188+
if (nullptr != pfnGetBackendOption) {
189+
result =
190+
pfnGetBackendOption(hPlatform, pFrontendOption, ppAdapterOption);
191+
} else {
192+
// generic implementation
193+
}
194+
195+
return result;
196+
}
197+
173198
///////////////////////////////////////////////////////////////////////////////
174199
/// @brief Intercept function for urGetLastResult
175200
__urdlllocal ur_result_t UR_APICALL urGetLastResult(
@@ -3342,6 +3367,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetPlatformProcAddrTable(
33423367

33433368
pDdiTable->pfnGetApiVersion = driver::urPlatformGetApiVersion;
33443369

3370+
pDdiTable->pfnGetBackendOption = driver::urPlatformGetBackendOption;
3371+
33453372
return result;
33463373
}
33473374

source/loader/layers/tracing/ur_trcddi.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,38 @@ __urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
208208
return result;
209209
}
210210

211+
///////////////////////////////////////////////////////////////////////////////
212+
/// @brief Intercept function for urPlatformGetBackendOption
213+
__urdlllocal ur_result_t UR_APICALL urPlatformGetBackendOption(
214+
ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance.
215+
const char
216+
*pFrontendOption, ///< [in] string containing the frontend option.
217+
const char **
218+
ppAdapterOption ///< [out] returns the correct adapter specific option based on the
219+
///< frontend option.
220+
) {
221+
auto pfnGetBackendOption = context.urDdiTable.Platform.pfnGetBackendOption;
222+
223+
if (nullptr == pfnGetBackendOption) {
224+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
225+
}
226+
227+
ur_platform_get_backend_option_params_t params = {
228+
&hPlatform, &pFrontendOption, &ppAdapterOption};
229+
uint64_t instance =
230+
context.notify_begin(UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION,
231+
"urPlatformGetBackendOption", &params);
232+
233+
ur_result_t result =
234+
pfnGetBackendOption(hPlatform, pFrontendOption, ppAdapterOption);
235+
236+
context.notify_end(UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION,
237+
"urPlatformGetBackendOption", &params, &result,
238+
instance);
239+
240+
return result;
241+
}
242+
211243
///////////////////////////////////////////////////////////////////////////////
212244
/// @brief Intercept function for urGetLastResult
213245
__urdlllocal ur_result_t UR_APICALL urGetLastResult(
@@ -4112,6 +4144,10 @@ __urdlllocal ur_result_t UR_APICALL urGetPlatformProcAddrTable(
41124144
dditable.pfnGetApiVersion = pDdiTable->pfnGetApiVersion;
41134145
pDdiTable->pfnGetApiVersion = ur_tracing_layer::urPlatformGetApiVersion;
41144146

4147+
dditable.pfnGetBackendOption = pDdiTable->pfnGetBackendOption;
4148+
pDdiTable->pfnGetBackendOption =
4149+
ur_tracing_layer::urPlatformGetBackendOption;
4150+
41154151
return result;
41164152
}
41174153
///////////////////////////////////////////////////////////////////////////////

source/loader/layers/validation/ur_valddi.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,42 @@ __urdlllocal ur_result_t UR_APICALL urPlatformCreateWithNativeHandle(
211211
return result;
212212
}
213213

214+
///////////////////////////////////////////////////////////////////////////////
215+
/// @brief Intercept function for urPlatformGetBackendOption
216+
__urdlllocal ur_result_t UR_APICALL urPlatformGetBackendOption(
217+
ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance.
218+
const char
219+
*pFrontendOption, ///< [in] string containing the frontend option.
220+
const char **
221+
ppAdapterOption ///< [out] returns the correct adapter specific option based on the
222+
///< frontend option.
223+
) {
224+
auto pfnGetBackendOption = context.urDdiTable.Platform.pfnGetBackendOption;
225+
226+
if (nullptr == pfnGetBackendOption) {
227+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
228+
}
229+
230+
if (context.enableParameterValidation) {
231+
if (NULL == hPlatform) {
232+
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
233+
}
234+
235+
if (NULL == pFrontendOption) {
236+
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
237+
}
238+
239+
if (NULL == ppAdapterOption) {
240+
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
241+
}
242+
}
243+
244+
ur_result_t result =
245+
pfnGetBackendOption(hPlatform, pFrontendOption, ppAdapterOption);
246+
247+
return result;
248+
}
249+
214250
///////////////////////////////////////////////////////////////////////////////
215251
/// @brief Intercept function for urGetLastResult
216252
__urdlllocal ur_result_t UR_APICALL urGetLastResult(
@@ -4983,6 +5019,10 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetPlatformProcAddrTable(
49835019
dditable.pfnGetApiVersion = pDdiTable->pfnGetApiVersion;
49845020
pDdiTable->pfnGetApiVersion = ur_validation_layer::urPlatformGetApiVersion;
49855021

5022+
dditable.pfnGetBackendOption = pDdiTable->pfnGetBackendOption;
5023+
pDdiTable->pfnGetBackendOption =
5024+
ur_validation_layer::urPlatformGetBackendOption;
5025+
49865026
return result;
49875027
}
49885028

0 commit comments

Comments
 (0)