Skip to content

Commit 4f48ed8

Browse files
authored
Merge pull request #436 from veselypeta/petr/427/add-backend-option
[UR] Add backend option entrypoint
2 parents 38085d9 + 70db45f commit 4f48ed8

File tree

15 files changed

+392
-1
lines changed

15 files changed

+392
-1
lines changed

include/ur.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,7 @@ class ur_function_v(IntEnum):
15911591
USM_GET_MEM_ALLOC_INFO = 111 ## Enumerator for ::urUSMGetMemAllocInfo
15921592
USM_POOL_CREATE = 112 ## Enumerator for ::urUSMPoolCreate
15931593
USM_POOL_DESTROY = 113 ## Enumerator for ::urUSMPoolDestroy
1594+
PLATFORM_GET_BACKEND_OPTION = 114 ## Enumerator for ::urPlatformGetBackendOption
15941595

15951596
class ur_function_t(c_int):
15961597
def __str__(self):
@@ -1656,6 +1657,13 @@ def __str__(self):
16561657
else:
16571658
_urPlatformGetApiVersion_t = CFUNCTYPE( ur_result_t, ur_platform_handle_t, POINTER(ur_api_version_t) )
16581659

1660+
###############################################################################
1661+
## @brief Function-pointer for urPlatformGetBackendOption
1662+
if __use_win_types:
1663+
_urPlatformGetBackendOption_t = WINFUNCTYPE( ur_result_t, ur_platform_handle_t, c_char_p, POINTER(c_char_p) )
1664+
else:
1665+
_urPlatformGetBackendOption_t = CFUNCTYPE( ur_result_t, ur_platform_handle_t, c_char_p, POINTER(c_char_p) )
1666+
16591667

16601668
###############################################################################
16611669
## @brief Table of Platform functions pointers
@@ -1665,7 +1673,8 @@ class ur_platform_dditable_t(Structure):
16651673
("pfnGetInfo", c_void_p), ## _urPlatformGetInfo_t
16661674
("pfnGetNativeHandle", c_void_p), ## _urPlatformGetNativeHandle_t
16671675
("pfnCreateWithNativeHandle", c_void_p), ## _urPlatformCreateWithNativeHandle_t
1668-
("pfnGetApiVersion", c_void_p) ## _urPlatformGetApiVersion_t
1676+
("pfnGetApiVersion", c_void_p), ## _urPlatformGetApiVersion_t
1677+
("pfnGetBackendOption", c_void_p) ## _urPlatformGetBackendOption_t
16691678
]
16701679

16711680
###############################################################################
@@ -2655,6 +2664,7 @@ def __init__(self, version : ur_api_version_t):
26552664
self.urPlatformGetNativeHandle = _urPlatformGetNativeHandle_t(self.__dditable.Platform.pfnGetNativeHandle)
26562665
self.urPlatformCreateWithNativeHandle = _urPlatformCreateWithNativeHandle_t(self.__dditable.Platform.pfnCreateWithNativeHandle)
26572666
self.urPlatformGetApiVersion = _urPlatformGetApiVersion_t(self.__dditable.Platform.pfnGetApiVersion)
2667+
self.urPlatformGetBackendOption = _urPlatformGetBackendOption_t(self.__dditable.Platform.pfnGetBackendOption)
26582668

26592669
# call driver to get function pointers
26602670
Context = ur_context_dditable_t()

include/ur_api.h

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

525+
///////////////////////////////////////////////////////////////////////////////
526+
/// @brief Get the platform specific compiler backend option from a generic
527+
/// frontend option.
528+
///
529+
/// @details
530+
/// - The string returned via the ppPlatformOption is a NULL terminated C
531+
/// style string.
532+
/// - The string returned via the ppPlatformOption is thread local.
533+
/// - The memory in the string returned via the ppPlatformOption 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 == ppPlatformOption`
547+
/// - ::UR_RESULT_ERROR_INVALID_VALUE
548+
/// + If `pFrontendOption` is not a valid frontend option.
549+
UR_APIEXPORT ur_result_t UR_APICALL
550+
urPlatformGetBackendOption(
551+
ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance.
552+
const char *pFrontendOption, ///< [in] string containing the frontend option.
553+
const char **ppPlatformOption ///< [out] returns the correct platform specific compiler option based on
554+
///< the frontend option.
555+
);
556+
525557
///////////////////////////////////////////////////////////////////////////////
526558
/// @brief Retrieve string representation of the underlying adapter specific
527559
/// result reported by the the last API that returned
@@ -4309,6 +4341,7 @@ typedef enum ur_function_t {
43094341
UR_FUNCTION_USM_GET_MEM_ALLOC_INFO = 111, ///< Enumerator for ::urUSMGetMemAllocInfo
43104342
UR_FUNCTION_USM_POOL_CREATE = 112, ///< Enumerator for ::urUSMPoolCreate
43114343
UR_FUNCTION_USM_POOL_DESTROY = 113, ///< Enumerator for ::urUSMPoolDestroy
4344+
UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION = 114, ///< Enumerator for ::urPlatformGetBackendOption
43124345
/// @cond
43134346
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
43144347
/// @endcond
@@ -5540,6 +5573,28 @@ typedef void(UR_APICALL *ur_pfnPlatformGetApiVersionCb_t)(
55405573
void *pTracerUserData,
55415574
void **ppTracerInstanceUserData);
55425575

5576+
///////////////////////////////////////////////////////////////////////////////
5577+
/// @brief Callback function parameters for urPlatformGetBackendOption
5578+
/// @details Each entry is a pointer to the parameter passed to the function;
5579+
/// allowing the callback the ability to modify the parameter's value
5580+
typedef struct ur_platform_get_backend_option_params_t {
5581+
ur_platform_handle_t *phPlatform;
5582+
const char **ppFrontendOption;
5583+
const char ***pppPlatformOption;
5584+
} ur_platform_get_backend_option_params_t;
5585+
5586+
///////////////////////////////////////////////////////////////////////////////
5587+
/// @brief Callback function-pointer for urPlatformGetBackendOption
5588+
/// @param[in] params Parameters passed to this instance
5589+
/// @param[in] result Return value
5590+
/// @param[in] pTracerUserData Per-Tracer user data
5591+
/// @param[in,out] ppTracerInstanceUserData Per-Tracer, Per-Instance user data
5592+
typedef void(UR_APICALL *ur_pfnPlatformGetBackendOptionCb_t)(
5593+
ur_platform_get_backend_option_params_t *params,
5594+
ur_result_t result,
5595+
void *pTracerUserData,
5596+
void **ppTracerInstanceUserData);
5597+
55435598
///////////////////////////////////////////////////////////////////////////////
55445599
/// @brief Table of Platform callback functions pointers
55455600
typedef struct ur_platform_callbacks_t {
@@ -5548,6 +5603,7 @@ typedef struct ur_platform_callbacks_t {
55485603
ur_pfnPlatformGetNativeHandleCb_t pfnGetNativeHandleCb;
55495604
ur_pfnPlatformCreateWithNativeHandleCb_t pfnCreateWithNativeHandleCb;
55505605
ur_pfnPlatformGetApiVersionCb_t pfnGetApiVersionCb;
5606+
ur_pfnPlatformGetBackendOptionCb_t pfnGetBackendOptionCb;
55515607
} ur_platform_callbacks_t;
55525608

55535609
///////////////////////////////////////////////////////////////////////////////

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,31 @@ params:
168168
[out] pointer to the handle of the platform object created.
169169
--- #--------------------------------------------------------------------------
170170
type: function
171+
desc: "Get the platform 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 ppPlatformOption is a NULL terminated C style string."
177+
- "The string returned via the ppPlatformOption is thread local."
178+
- "The memory in the string returned via the ppPlatformOption 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: ppPlatformOption
190+
desc: "[out] returns the correct platform specific compiler option based on the frontend option."
191+
returns:
192+
- $X_RESULT_ERROR_INVALID_VALUE:
193+
- "If `pFrontendOption` is not a valid frontend option."
194+
--- #--------------------------------------------------------------------------
195+
type: function
171196
desc: "Retrieve string representation of the underlying adapter specific result
172197
reported by the the last API that returned UR_RESULT_ADAPTER_SPECIFIC.
173198
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
@@ -4295,6 +4295,10 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) {
42954295
case UR_FUNCTION_USM_POOL_DESTROY:
42964296
os << "UR_FUNCTION_USM_POOL_DESTROY";
42974297
break;
4298+
4299+
case UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION:
4300+
os << "UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION";
4301+
break;
42984302
default:
42994303
os << "unknown enumerator";
43004304
break;
@@ -6755,6 +6759,27 @@ operator<<(std::ostream &os,
67556759
return os;
67566760
}
67576761

6762+
inline std::ostream &
6763+
operator<<(std::ostream &os,
6764+
const struct ur_platform_get_backend_option_params_t *params) {
6765+
6766+
os << ".hPlatform = ";
6767+
6768+
ur_params::serializePtr(os, *(params->phPlatform));
6769+
6770+
os << ", ";
6771+
os << ".pFrontendOption = ";
6772+
6773+
ur_params::serializePtr(os, *(params->ppFrontendOption));
6774+
6775+
os << ", ";
6776+
os << ".ppPlatformOption = ";
6777+
6778+
ur_params::serializePtr(os, *(params->pppPlatformOption));
6779+
6780+
return os;
6781+
}
6782+
67586783
inline std::ostream &
67596784
operator<<(std::ostream &os,
67606785
const struct ur_program_create_with_il_params_t *params) {
@@ -7958,6 +7983,9 @@ inline int serializeFunctionParams(std::ostream &os, uint32_t function,
79587983
case UR_FUNCTION_PLATFORM_GET_API_VERSION: {
79597984
os << (const struct ur_platform_get_api_version_params_t *)params;
79607985
} break;
7986+
case UR_FUNCTION_PLATFORM_GET_BACKEND_OPTION: {
7987+
os << (const struct ur_platform_get_backend_option_params_t *)params;
7988+
} break;
79617989
case UR_FUNCTION_PROGRAM_CREATE_WITH_IL: {
79627990
os << (const struct ur_program_create_with_il_params_t *)params;
79637991
} 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+
ppPlatformOption ///< [out] returns the correct platform specific compiler option based on
181+
///< the 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, ppPlatformOption);
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+
ppPlatformOption ///< [out] returns the correct platform specific compiler option based on
219+
///< the 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, &ppPlatformOption};
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, ppPlatformOption);
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+
ppPlatformOption ///< [out] returns the correct platform specific compiler option based on
222+
///< the 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 == ppPlatformOption) {
240+
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
241+
}
242+
}
243+
244+
ur_result_t result =
245+
pfnGetBackendOption(hPlatform, pFrontendOption, ppPlatformOption);
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)