Skip to content

Commit e002ca8

Browse files
authored
Merge pull request #681 from aarongreig/aaron/layerConfig
Implement loader config object, allow programatic layer management.
2 parents 0ab0aa3 + 7e1c90b commit e002ca8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1367
-110
lines changed

examples/hello_world/hello_world.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int main(int argc, char *argv[]) {
1919
ur_result_t status;
2020

2121
// Initialize the platform
22-
status = urInit(0);
22+
status = urInit(0, nullptr);
2323
if (status != UR_RESULT_SUCCESS) {
2424
std::cout << "urInit failed with return code: " << status << std::endl;
2525
return 1;

include/ur.py

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ class ur_function_v(IntEnum):
187187
COMMAND_BUFFER_APPEND_MEMBUFFER_READ_EXP = 169 ## Enumerator for ::urCommandBufferAppendMembufferReadExp
188188
COMMAND_BUFFER_APPEND_MEMBUFFER_WRITE_RECT_EXP = 170## Enumerator for ::urCommandBufferAppendMembufferWriteRectExp
189189
COMMAND_BUFFER_APPEND_MEMBUFFER_READ_RECT_EXP = 171 ## Enumerator for ::urCommandBufferAppendMembufferReadRectExp
190+
LOADER_CONFIG_CREATE = 172 ## Enumerator for ::urLoaderConfigCreate
191+
LOADER_CONFIG_RELEASE = 173 ## Enumerator for ::urLoaderConfigRelease
192+
LOADER_CONFIG_RETAIN = 174 ## Enumerator for ::urLoaderConfigRetain
193+
LOADER_CONFIG_GET_INFO = 175 ## Enumerator for ::urLoaderConfigGetInfo
194+
LOADER_CONFIG_ENABLE_LAYER = 176 ## Enumerator for ::urLoaderConfigEnableLayer
190195

191196
class ur_function_t(c_int):
192197
def __str__(self):
@@ -278,6 +283,11 @@ def UR_MINOR_VERSION( _ver ):
278283
class ur_bool_t(c_ubyte):
279284
pass
280285

286+
###############################################################################
287+
## @brief Handle of a loader config object
288+
class ur_loader_config_handle_t(c_void_p):
289+
pass
290+
281291
###############################################################################
282292
## @brief Handle of a platform instance
283293
class ur_platform_handle_t(c_void_p):
@@ -420,6 +430,7 @@ class ur_result_v(IntEnum):
420430
ERROR_OBJECT_ALLOCATION_FAILURE = 66 ## Objection allocation failure
421431
ERROR_ADAPTER_SPECIFIC = 67 ## An adapter specific warning/error has been reported and can be
422432
## retrieved via the urPlatformGetLastError entry point.
433+
ERROR_LAYER_NOT_PRESENT = 68 ## A requested layer was not found by the loader.
423434
ERROR_INVALID_COMMAND_BUFFER_EXP = 0x1000 ## Invalid Command-Buffer
424435
ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP = 0x1001## Sync point is not valid for the command-buffer
425436
ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP = 0x1002 ## Sync point wait list is invalid
@@ -478,6 +489,18 @@ def __str__(self):
478489
return hex(self.value)
479490

480491

492+
###############################################################################
493+
## @brief Supported loader info
494+
class ur_loader_config_info_v(IntEnum):
495+
AVAILABLE_LAYERS = 0 ## [char[]] Null-terminated, semi-colon separated list of available
496+
## layers.
497+
REFERENCE_COUNT = 1 ## [uint32_t] Reference count of the loader config object.
498+
499+
class ur_loader_config_info_t(c_int):
500+
def __str__(self):
501+
return str(ur_loader_config_info_v(self.value))
502+
503+
481504
###############################################################################
482505
## @brief Supported platform info
483506
class ur_platform_info_v(IntEnum):
@@ -2200,6 +2223,53 @@ def __str__(self):
22002223
###############################################################################
22012224
__use_win_types = "Windows" == platform.uname()[0]
22022225

2226+
###############################################################################
2227+
## @brief Function-pointer for urLoaderConfigCreate
2228+
if __use_win_types:
2229+
_urLoaderConfigCreate_t = WINFUNCTYPE( ur_result_t, POINTER(ur_loader_config_handle_t) )
2230+
else:
2231+
_urLoaderConfigCreate_t = CFUNCTYPE( ur_result_t, POINTER(ur_loader_config_handle_t) )
2232+
2233+
###############################################################################
2234+
## @brief Function-pointer for urLoaderConfigRetain
2235+
if __use_win_types:
2236+
_urLoaderConfigRetain_t = WINFUNCTYPE( ur_result_t, ur_loader_config_handle_t )
2237+
else:
2238+
_urLoaderConfigRetain_t = CFUNCTYPE( ur_result_t, ur_loader_config_handle_t )
2239+
2240+
###############################################################################
2241+
## @brief Function-pointer for urLoaderConfigRelease
2242+
if __use_win_types:
2243+
_urLoaderConfigRelease_t = WINFUNCTYPE( ur_result_t, ur_loader_config_handle_t )
2244+
else:
2245+
_urLoaderConfigRelease_t = CFUNCTYPE( ur_result_t, ur_loader_config_handle_t )
2246+
2247+
###############################################################################
2248+
## @brief Function-pointer for urLoaderConfigGetInfo
2249+
if __use_win_types:
2250+
_urLoaderConfigGetInfo_t = WINFUNCTYPE( ur_result_t, ur_loader_config_handle_t, ur_loader_config_info_t, c_size_t, c_void_p, POINTER(c_size_t) )
2251+
else:
2252+
_urLoaderConfigGetInfo_t = CFUNCTYPE( ur_result_t, ur_loader_config_handle_t, ur_loader_config_info_t, c_size_t, c_void_p, POINTER(c_size_t) )
2253+
2254+
###############################################################################
2255+
## @brief Function-pointer for urLoaderConfigEnableLayer
2256+
if __use_win_types:
2257+
_urLoaderConfigEnableLayer_t = WINFUNCTYPE( ur_result_t, ur_loader_config_handle_t, c_char_p )
2258+
else:
2259+
_urLoaderConfigEnableLayer_t = CFUNCTYPE( ur_result_t, ur_loader_config_handle_t, c_char_p )
2260+
2261+
2262+
###############################################################################
2263+
## @brief Table of LoaderConfig functions pointers
2264+
class ur_loader_config_dditable_t(Structure):
2265+
_fields_ = [
2266+
("pfnCreate", c_void_p), ## _urLoaderConfigCreate_t
2267+
("pfnRetain", c_void_p), ## _urLoaderConfigRetain_t
2268+
("pfnRelease", c_void_p), ## _urLoaderConfigRelease_t
2269+
("pfnGetInfo", c_void_p), ## _urLoaderConfigGetInfo_t
2270+
("pfnEnableLayer", c_void_p) ## _urLoaderConfigEnableLayer_t
2271+
]
2272+
22032273
###############################################################################
22042274
## @brief Function-pointer for urPlatformGet
22052275
if __use_win_types:
@@ -3484,9 +3554,9 @@ class ur_usm_p2p_exp_dditable_t(Structure):
34843554
###############################################################################
34853555
## @brief Function-pointer for urInit
34863556
if __use_win_types:
3487-
_urInit_t = WINFUNCTYPE( ur_result_t, ur_device_init_flags_t )
3557+
_urInit_t = WINFUNCTYPE( ur_result_t, ur_device_init_flags_t, ur_loader_config_handle_t )
34883558
else:
3489-
_urInit_t = CFUNCTYPE( ur_result_t, ur_device_init_flags_t )
3559+
_urInit_t = CFUNCTYPE( ur_result_t, ur_device_init_flags_t, ur_loader_config_handle_t )
34903560

34913561
###############################################################################
34923562
## @brief Function-pointer for urTearDown
@@ -3649,6 +3719,7 @@ class ur_device_dditable_t(Structure):
36493719
###############################################################################
36503720
class ur_dditable_t(Structure):
36513721
_fields_ = [
3722+
("LoaderConfig", ur_loader_config_dditable_t),
36523723
("Platform", ur_platform_dditable_t),
36533724
("Context", ur_context_dditable_t),
36543725
("Event", ur_event_dditable_t),

include/ur_api.h

Lines changed: 190 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ typedef enum ur_function_t {
196196
UR_FUNCTION_COMMAND_BUFFER_APPEND_MEMBUFFER_READ_EXP = 169, ///< Enumerator for ::urCommandBufferAppendMembufferReadExp
197197
UR_FUNCTION_COMMAND_BUFFER_APPEND_MEMBUFFER_WRITE_RECT_EXP = 170, ///< Enumerator for ::urCommandBufferAppendMembufferWriteRectExp
198198
UR_FUNCTION_COMMAND_BUFFER_APPEND_MEMBUFFER_READ_RECT_EXP = 171, ///< Enumerator for ::urCommandBufferAppendMembufferReadRectExp
199+
UR_FUNCTION_LOADER_CONFIG_CREATE = 172, ///< Enumerator for ::urLoaderConfigCreate
200+
UR_FUNCTION_LOADER_CONFIG_RELEASE = 173, ///< Enumerator for ::urLoaderConfigRelease
201+
UR_FUNCTION_LOADER_CONFIG_RETAIN = 174, ///< Enumerator for ::urLoaderConfigRetain
202+
UR_FUNCTION_LOADER_CONFIG_GET_INFO = 175, ///< Enumerator for ::urLoaderConfigGetInfo
203+
UR_FUNCTION_LOADER_CONFIG_ENABLE_LAYER = 176, ///< Enumerator for ::urLoaderConfigEnableLayer
199204
/// @cond
200205
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
201206
/// @endcond
@@ -318,6 +323,10 @@ typedef enum ur_structure_type_t {
318323
/// @brief compiler-independent type
319324
typedef uint8_t ur_bool_t;
320325

326+
///////////////////////////////////////////////////////////////////////////////
327+
/// @brief Handle of a loader config object
328+
typedef struct ur_loader_config_handle_t_ *ur_loader_config_handle_t;
329+
321330
///////////////////////////////////////////////////////////////////////////////
322331
/// @brief Handle of a platform instance
323332
typedef struct ur_platform_handle_t_ *ur_platform_handle_t;
@@ -450,6 +459,7 @@ typedef enum ur_result_t {
450459
UR_RESULT_ERROR_OBJECT_ALLOCATION_FAILURE = 66, ///< Objection allocation failure
451460
UR_RESULT_ERROR_ADAPTER_SPECIFIC = 67, ///< An adapter specific warning/error has been reported and can be
452461
///< retrieved via the urPlatformGetLastError entry point.
462+
UR_RESULT_ERROR_LAYER_NOT_PRESENT = 68, ///< A requested layer was not found by the loader.
453463
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP = 0x1000, ///< Invalid Command-Buffer
454464
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP = 0x1001, ///< Sync point is not valid for the command-buffer
455465
UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP = 0x1002, ///< Sync point wait list is invalid
@@ -518,6 +528,137 @@ typedef enum ur_device_init_flag_t {
518528
/// @brief Bit Mask for validating ur_device_init_flags_t
519529
#define UR_DEVICE_INIT_FLAGS_MASK 0xffffffe0
520530

531+
///////////////////////////////////////////////////////////////////////////////
532+
/// @brief Create a loader config object.
533+
///
534+
/// @returns
535+
/// - ::UR_RESULT_SUCCESS
536+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
537+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
538+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
539+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
540+
/// + `NULL == phLoaderConfig`
541+
UR_APIEXPORT ur_result_t UR_APICALL
542+
urLoaderConfigCreate(
543+
ur_loader_config_handle_t *phLoaderConfig ///< [out] Pointer to handle of loader config object created.
544+
);
545+
546+
///////////////////////////////////////////////////////////////////////////////
547+
/// @brief Get a reference to the loader config object.
548+
///
549+
/// @details
550+
/// - Get a reference to the loader config handle. Increment its reference
551+
/// count
552+
/// - The application may call this function from simultaneous threads.
553+
/// - The implementation of this function should be lock-free.
554+
///
555+
/// @returns
556+
/// - ::UR_RESULT_SUCCESS
557+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
558+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
559+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
560+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
561+
/// + `NULL == hLoaderConfig`
562+
UR_APIEXPORT ur_result_t UR_APICALL
563+
urLoaderConfigRetain(
564+
ur_loader_config_handle_t hLoaderConfig ///< [in] loader config handle to retain
565+
);
566+
567+
///////////////////////////////////////////////////////////////////////////////
568+
/// @brief Release config handle.
569+
///
570+
/// @details
571+
/// - Decrement reference count and destroy the config handle if reference
572+
/// count becomes zero.
573+
/// - The application may call this function from simultaneous threads.
574+
/// - The implementation of this function should be lock-free.
575+
///
576+
/// @returns
577+
/// - ::UR_RESULT_SUCCESS
578+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
579+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
580+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
581+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
582+
/// + `NULL == hLoaderConfig`
583+
UR_APIEXPORT ur_result_t UR_APICALL
584+
urLoaderConfigRelease(
585+
ur_loader_config_handle_t hLoaderConfig ///< [in] config handle to release
586+
);
587+
588+
///////////////////////////////////////////////////////////////////////////////
589+
/// @brief Supported loader info
590+
typedef enum ur_loader_config_info_t {
591+
UR_LOADER_CONFIG_INFO_AVAILABLE_LAYERS = 0, ///< [char[]] Null-terminated, semi-colon separated list of available
592+
///< layers.
593+
UR_LOADER_CONFIG_INFO_REFERENCE_COUNT = 1, ///< [uint32_t] Reference count of the loader config object.
594+
/// @cond
595+
UR_LOADER_CONFIG_INFO_FORCE_UINT32 = 0x7fffffff
596+
/// @endcond
597+
598+
} ur_loader_config_info_t;
599+
600+
///////////////////////////////////////////////////////////////////////////////
601+
/// @brief Retrieves various information about the loader.
602+
///
603+
/// @details
604+
/// - The application may call this function from simultaneous threads.
605+
/// - The implementation of this function should be lock-free.
606+
///
607+
/// @returns
608+
/// - ::UR_RESULT_SUCCESS
609+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
610+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
611+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
612+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
613+
/// + `NULL == hLoaderConfig`
614+
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
615+
/// + `::UR_LOADER_CONFIG_INFO_REFERENCE_COUNT < propName`
616+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
617+
/// + If `propName` is not supported by the loader.
618+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
619+
/// + `propSize == 0 && pPropValue != NULL`
620+
/// + If `propSize` is less than the real number of bytes needed to return the info.
621+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
622+
/// + `propSize != 0 && pPropValue == NULL`
623+
/// + `pPropValue == NULL && pPropSizeRet == NULL`
624+
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
625+
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
626+
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
627+
UR_APIEXPORT ur_result_t UR_APICALL
628+
urLoaderConfigGetInfo(
629+
ur_loader_config_handle_t hLoaderConfig, ///< [in] handle of the loader config object
630+
ur_loader_config_info_t propName, ///< [in] type of the info to retrieve
631+
size_t propSize, ///< [in] the number of bytes pointed to by pPropValue.
632+
void *pPropValue, ///< [out][optional][typename(propName, propSize)] array of bytes holding
633+
///< the info.
634+
///< If propSize is not equal to or greater than the real number of bytes
635+
///< needed to return the info
636+
///< then the ::UR_RESULT_ERROR_INVALID_SIZE error is returned and
637+
///< pPropValue is not used.
638+
size_t *pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName.
639+
);
640+
641+
///////////////////////////////////////////////////////////////////////////////
642+
/// @brief Enable a layer for the specified loader config.
643+
///
644+
/// @returns
645+
/// - ::UR_RESULT_SUCCESS
646+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
647+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
648+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
649+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
650+
/// + `NULL == hLoaderConfig`
651+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
652+
/// + `NULL == pLayerName`
653+
/// - ::UR_RESULT_ERROR_LAYER_NOT_PRESENT
654+
/// + If layer specified with `pLayerName` can't be found by the loader.
655+
UR_APIEXPORT ur_result_t UR_APICALL
656+
urLoaderConfigEnableLayer(
657+
ur_loader_config_handle_t hLoaderConfig, ///< [in] Handle to config object the layer will be enabled for.
658+
const char *pLayerName ///< [in] Null terminated string containing the name of the layer to
659+
///< enable.
660+
);
661+
521662
///////////////////////////////////////////////////////////////////////////////
522663
/// @brief Initialize the 'oneAPI' adapter(s)
523664
///
@@ -545,8 +686,9 @@ typedef enum ur_device_init_flag_t {
545686
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
546687
UR_APIEXPORT ur_result_t UR_APICALL
547688
urInit(
548-
ur_device_init_flags_t device_flags ///< [in] device initialization flags.
549-
///< must be 0 (default) or a combination of ::ur_device_init_flag_t.
689+
ur_device_init_flags_t device_flags, ///< [in] device initialization flags.
690+
///< must be 0 (default) or a combination of ::ur_device_init_flag_t.
691+
ur_loader_config_handle_t hLoaderConfig ///< [in][optional] Handle of loader config handle.
550692
);
551693

552694
///////////////////////////////////////////////////////////////////////////////
@@ -7901,6 +8043,51 @@ urUsmP2PPeerAccessGetInfoExp(
79018043
#if !defined(__GNUC__)
79028044
#pragma region callbacks
79038045
#endif
8046+
///////////////////////////////////////////////////////////////////////////////
8047+
/// @brief Function parameters for urLoaderConfigCreate
8048+
/// @details Each entry is a pointer to the parameter passed to the function;
8049+
/// allowing the callback the ability to modify the parameter's value
8050+
typedef struct ur_loader_config_create_params_t {
8051+
ur_loader_config_handle_t **pphLoaderConfig;
8052+
} ur_loader_config_create_params_t;
8053+
8054+
///////////////////////////////////////////////////////////////////////////////
8055+
/// @brief Function parameters for urLoaderConfigRetain
8056+
/// @details Each entry is a pointer to the parameter passed to the function;
8057+
/// allowing the callback the ability to modify the parameter's value
8058+
typedef struct ur_loader_config_retain_params_t {
8059+
ur_loader_config_handle_t *phLoaderConfig;
8060+
} ur_loader_config_retain_params_t;
8061+
8062+
///////////////////////////////////////////////////////////////////////////////
8063+
/// @brief Function parameters for urLoaderConfigRelease
8064+
/// @details Each entry is a pointer to the parameter passed to the function;
8065+
/// allowing the callback the ability to modify the parameter's value
8066+
typedef struct ur_loader_config_release_params_t {
8067+
ur_loader_config_handle_t *phLoaderConfig;
8068+
} ur_loader_config_release_params_t;
8069+
8070+
///////////////////////////////////////////////////////////////////////////////
8071+
/// @brief Function parameters for urLoaderConfigGetInfo
8072+
/// @details Each entry is a pointer to the parameter passed to the function;
8073+
/// allowing the callback the ability to modify the parameter's value
8074+
typedef struct ur_loader_config_get_info_params_t {
8075+
ur_loader_config_handle_t *phLoaderConfig;
8076+
ur_loader_config_info_t *ppropName;
8077+
size_t *ppropSize;
8078+
void **ppPropValue;
8079+
size_t **ppPropSizeRet;
8080+
} ur_loader_config_get_info_params_t;
8081+
8082+
///////////////////////////////////////////////////////////////////////////////
8083+
/// @brief Function parameters for urLoaderConfigEnableLayer
8084+
/// @details Each entry is a pointer to the parameter passed to the function;
8085+
/// allowing the callback the ability to modify the parameter's value
8086+
typedef struct ur_loader_config_enable_layer_params_t {
8087+
ur_loader_config_handle_t *phLoaderConfig;
8088+
const char **ppLayerName;
8089+
} ur_loader_config_enable_layer_params_t;
8090+
79048091
///////////////////////////////////////////////////////////////////////////////
79058092
/// @brief Function parameters for urPlatformGet
79068093
/// @details Each entry is a pointer to the parameter passed to the function;
@@ -9656,6 +9843,7 @@ typedef struct ur_usm_p2p_peer_access_get_info_exp_params_t {
96569843
/// allowing the callback the ability to modify the parameter's value
96579844
typedef struct ur_init_params_t {
96589845
ur_device_init_flags_t *pdevice_flags;
9846+
ur_loader_config_handle_t *phLoaderConfig;
96599847
} ur_init_params_t;
96609848

96619849
///////////////////////////////////////////////////////////////////////////////

include/ur_ddi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,8 @@ typedef ur_result_t(UR_APICALL *ur_pfnGetUsmP2PExpProcAddrTable_t)(
18691869
///////////////////////////////////////////////////////////////////////////////
18701870
/// @brief Function-pointer for urInit
18711871
typedef ur_result_t(UR_APICALL *ur_pfnInit_t)(
1872-
ur_device_init_flags_t);
1872+
ur_device_init_flags_t,
1873+
ur_loader_config_handle_t);
18731874

18741875
///////////////////////////////////////////////////////////////////////////////
18751876
/// @brief Function-pointer for urTearDown

0 commit comments

Comments
 (0)