diff --git a/examples/hello_world/hello_world.cpp b/examples/hello_world/hello_world.cpp index 454aeea540..dcd504bf4e 100644 --- a/examples/hello_world/hello_world.cpp +++ b/examples/hello_world/hello_world.cpp @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) { ur_result_t status; // Initialize the platform - status = urInit(0); + status = urInit(0, nullptr); if (status != UR_RESULT_SUCCESS) { std::cout << "urInit failed with return code: " << status << std::endl; return 1; diff --git a/include/ur.py b/include/ur.py index 0b2ffc286a..3dca6d1867 100644 --- a/include/ur.py +++ b/include/ur.py @@ -55,6 +55,11 @@ def UR_MINOR_VERSION( _ver ): class ur_bool_t(c_ubyte): pass +############################################################################### +## @brief Handle of a loader config object +class ur_loader_config_handle_t(c_void_p): + pass + ############################################################################### ## @brief Handle of a platform instance class ur_platform_handle_t(c_void_p): @@ -300,6 +305,17 @@ def __str__(self): return hex(self.value) +############################################################################### +## @brief Supported loader info +class ur_loader_config_info_v(IntEnum): + AVAILABLE_LAYERS = 0 ## [char[]] Null-terminated, semi-colon separated list of available + ## layers. + +class ur_loader_config_info_t(c_int): + def __str__(self): + return str(ur_loader_config_info_v(self.value)) + + ############################################################################### ## @brief Supported platform info class ur_platform_info_v(IntEnum): @@ -2034,6 +2050,11 @@ class ur_function_v(IntEnum): COMMAND_BUFFER_APPEND_MEMBUFFER_READ_EXP = 169 ## Enumerator for ::urCommandBufferAppendMembufferReadExp COMMAND_BUFFER_APPEND_MEMBUFFER_WRITE_RECT_EXP = 170## Enumerator for ::urCommandBufferAppendMembufferWriteRectExp COMMAND_BUFFER_APPEND_MEMBUFFER_READ_RECT_EXP = 171 ## Enumerator for ::urCommandBufferAppendMembufferReadRectExp + LOADER_CONFIG_CREATE = 172 ## Enumerator for ::urLoaderConfigCreate + LOADER_CONFIG_RELEASE = 173 ## Enumerator for ::urLoaderConfigRelease + LOADER_CONFIG_RETAIN = 174 ## Enumerator for ::urLoaderConfigRetain + LOADER_CONFIG_GET_INFO = 175 ## Enumerator for ::urLoaderConfigGetInfo + LOADER_CONFIG_ENABLE_LAYER = 176 ## Enumerator for ::urLoaderConfigEnableLayer class ur_function_t(c_int): def __str__(self): @@ -2155,6 +2176,53 @@ def __str__(self): ############################################################################### __use_win_types = "Windows" == platform.uname()[0] +############################################################################### +## @brief Function-pointer for urLoaderConfigCreate +if __use_win_types: + _urLoaderConfigCreate_t = WINFUNCTYPE( ur_result_t, POINTER(ur_loader_config_handle_t) ) +else: + _urLoaderConfigCreate_t = CFUNCTYPE( ur_result_t, POINTER(ur_loader_config_handle_t) ) + +############################################################################### +## @brief Function-pointer for urLoaderConfigRetain +if __use_win_types: + _urLoaderConfigRetain_t = WINFUNCTYPE( ur_result_t, ur_loader_config_handle_t ) +else: + _urLoaderConfigRetain_t = CFUNCTYPE( ur_result_t, ur_loader_config_handle_t ) + +############################################################################### +## @brief Function-pointer for urLoaderConfigRelease +if __use_win_types: + _urLoaderConfigRelease_t = WINFUNCTYPE( ur_result_t, ur_loader_config_handle_t ) +else: + _urLoaderConfigRelease_t = CFUNCTYPE( ur_result_t, ur_loader_config_handle_t ) + +############################################################################### +## @brief Function-pointer for urLoaderConfigGetInfo +if __use_win_types: + _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) ) +else: + _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) ) + +############################################################################### +## @brief Function-pointer for urLoaderConfigEnableLayer +if __use_win_types: + _urLoaderConfigEnableLayer_t = WINFUNCTYPE( ur_result_t, ur_loader_config_handle_t, c_char_p ) +else: + _urLoaderConfigEnableLayer_t = CFUNCTYPE( ur_result_t, ur_loader_config_handle_t, c_char_p ) + + +############################################################################### +## @brief Table of LoaderConfig functions pointers +class ur_loader_config_dditable_t(Structure): + _fields_ = [ + ("pfnCreate", c_void_p), ## _urLoaderConfigCreate_t + ("pfnRetain", c_void_p), ## _urLoaderConfigRetain_t + ("pfnRelease", c_void_p), ## _urLoaderConfigRelease_t + ("pfnGetInfo", c_void_p), ## _urLoaderConfigGetInfo_t + ("pfnEnableLayer", c_void_p) ## _urLoaderConfigEnableLayer_t + ] + ############################################################################### ## @brief Function-pointer for urPlatformGet if __use_win_types: @@ -3439,9 +3507,9 @@ class ur_usm_p2p_exp_dditable_t(Structure): ############################################################################### ## @brief Function-pointer for urInit if __use_win_types: - _urInit_t = WINFUNCTYPE( ur_result_t, ur_device_init_flags_t ) + _urInit_t = WINFUNCTYPE( ur_result_t, ur_device_init_flags_t, ur_loader_config_handle_t ) else: - _urInit_t = CFUNCTYPE( ur_result_t, ur_device_init_flags_t ) + _urInit_t = CFUNCTYPE( ur_result_t, ur_device_init_flags_t, ur_loader_config_handle_t ) ############################################################################### ## @brief Function-pointer for urTearDown @@ -3604,6 +3672,7 @@ class ur_device_dditable_t(Structure): ############################################################################### class ur_dditable_t(Structure): _fields_ = [ + ("LoaderConfig", ur_loader_config_dditable_t), ("Platform", ur_platform_dditable_t), ("Context", ur_context_dditable_t), ("Event", ur_event_dditable_t), diff --git a/include/ur_api.h b/include/ur_api.h index 5c001e9c22..e727dd82c8 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -88,6 +88,10 @@ extern "C" { /// @brief compiler-independent type typedef uint8_t ur_bool_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Handle of a loader config object +typedef struct ur_loader_config_handle_t_ *ur_loader_config_handle_t; + /////////////////////////////////////////////////////////////////////////////// /// @brief Handle of a platform instance typedef struct ur_platform_handle_t_ *ur_platform_handle_t; @@ -333,6 +337,136 @@ typedef enum ur_device_init_flag_t { /// @brief Bit Mask for validating ur_device_init_flags_t #define UR_DEVICE_INIT_FLAGS_MASK 0xffffffe0 +/////////////////////////////////////////////////////////////////////////////// +/// @brief Create a loader config object. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == phLoaderConfig` +UR_APIEXPORT ur_result_t UR_APICALL +urLoaderConfigCreate( + ur_loader_config_handle_t *phLoaderConfig ///< [out] Pointer to handle of loader config object created. +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Get a reference to the loader config object. +/// +/// @details +/// - Get a reference to the loader config handle. Increment its reference +/// count +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function should be lock-free. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +UR_APIEXPORT ur_result_t UR_APICALL +urLoaderConfigRetain( + ur_loader_config_handle_t hLoaderConfig ///< [in] loader config handle to retain +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Release config handle. +/// +/// @details +/// - Decrement reference count and destroy the config handle if reference +/// count becomes zero. +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function should be lock-free. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +UR_APIEXPORT ur_result_t UR_APICALL +urLoaderConfigRelease( + ur_loader_config_handle_t hLoaderConfig ///< [in] config handle to release +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Supported loader info +typedef enum ur_loader_config_info_t { + UR_LOADER_CONFIG_INFO_AVAILABLE_LAYERS = 0, ///< [char[]] Null-terminated, semi-colon separated list of available + ///< layers. + /// @cond + UR_LOADER_CONFIG_INFO_FORCE_UINT32 = 0x7fffffff + /// @endcond + +} ur_loader_config_info_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves various information about the loader. +/// +/// @details +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function should be lock-free. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `::UR_LOADER_CONFIG_INFO_AVAILABLE_LAYERS < propName` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION +/// + If `propName` is not supported by the loader. +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// + `propSize == 0 && pPropValue != NULL` +/// + If `propSize` is less than the real number of bytes needed to return the info. +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `propSize != 0 && pPropValue == NULL` +/// + `pPropValue == NULL && pPropSizeRet == NULL` +/// - ::UR_RESULT_ERROR_INVALID_DEVICE +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +UR_APIEXPORT ur_result_t UR_APICALL +urLoaderConfigGetInfo( + ur_loader_config_handle_t hLoaderConfig, ///< [in] handle of the loader config object + ur_loader_config_info_t propName, ///< [in] type of the info to retrieve + size_t propSize, ///< [in] the number of bytes pointed to by pPropValue. + void *pPropValue, ///< [out][optional][typename(propName, propSize)] array of bytes holding + ///< the info. + ///< If propSize is not equal to or greater than the real number of bytes + ///< needed to return the info + ///< then the ::UR_RESULT_ERROR_INVALID_SIZE error is returned and + ///< pPropValue is not used. + size_t *pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName. +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enable a layer for the specified loader config. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == pLayerName` +/// - ::UR_RESULT_ERROR_INVALID_VALUE +/// + If layer specified with `pLayerName` can't be found by the loader. +UR_APIEXPORT ur_result_t UR_APICALL +urLoaderConfigEnableLayer( + ur_loader_config_handle_t hLoaderConfig, ///< [in] Handle to config object the layer will be enabled for. + const char *pLayerName ///< [in] Null terminated string containing the name of the layer to + ///< enable. +); + /////////////////////////////////////////////////////////////////////////////// /// @brief Initialize the 'oneAPI' adapter(s) /// @@ -360,8 +494,9 @@ typedef enum ur_device_init_flag_t { /// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY UR_APIEXPORT ur_result_t UR_APICALL urInit( - ur_device_init_flags_t device_flags ///< [in] device initialization flags. - ///< must be 0 (default) or a combination of ::ur_device_init_flag_t. + ur_device_init_flags_t device_flags, ///< [in] device initialization flags. + ///< must be 0 (default) or a combination of ::ur_device_init_flag_t. + ur_loader_config_handle_t hLoaderConfig ///< [in][optional] Handle of loader config handle. ); /////////////////////////////////////////////////////////////////////////////// @@ -5358,6 +5493,11 @@ typedef enum ur_function_t { UR_FUNCTION_COMMAND_BUFFER_APPEND_MEMBUFFER_READ_EXP = 169, ///< Enumerator for ::urCommandBufferAppendMembufferReadExp UR_FUNCTION_COMMAND_BUFFER_APPEND_MEMBUFFER_WRITE_RECT_EXP = 170, ///< Enumerator for ::urCommandBufferAppendMembufferWriteRectExp UR_FUNCTION_COMMAND_BUFFER_APPEND_MEMBUFFER_READ_RECT_EXP = 171, ///< Enumerator for ::urCommandBufferAppendMembufferReadRectExp + UR_FUNCTION_LOADER_CONFIG_CREATE = 172, ///< Enumerator for ::urLoaderConfigCreate + UR_FUNCTION_LOADER_CONFIG_RELEASE = 173, ///< Enumerator for ::urLoaderConfigRelease + UR_FUNCTION_LOADER_CONFIG_RETAIN = 174, ///< Enumerator for ::urLoaderConfigRetain + UR_FUNCTION_LOADER_CONFIG_GET_INFO = 175, ///< Enumerator for ::urLoaderConfigGetInfo + UR_FUNCTION_LOADER_CONFIG_ENABLE_LAYER = 176, ///< Enumerator for ::urLoaderConfigEnableLayer /// @cond UR_FUNCTION_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -7864,6 +8004,51 @@ urUsmP2PPeerAccessGetInfoExp( #if !defined(__GNUC__) #pragma region callbacks #endif +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urLoaderConfigCreate +/// @details Each entry is a pointer to the parameter passed to the function; +/// allowing the callback the ability to modify the parameter's value +typedef struct ur_loader_config_create_params_t { + ur_loader_config_handle_t **pphLoaderConfig; +} ur_loader_config_create_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urLoaderConfigRetain +/// @details Each entry is a pointer to the parameter passed to the function; +/// allowing the callback the ability to modify the parameter's value +typedef struct ur_loader_config_retain_params_t { + ur_loader_config_handle_t *phLoaderConfig; +} ur_loader_config_retain_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urLoaderConfigRelease +/// @details Each entry is a pointer to the parameter passed to the function; +/// allowing the callback the ability to modify the parameter's value +typedef struct ur_loader_config_release_params_t { + ur_loader_config_handle_t *phLoaderConfig; +} ur_loader_config_release_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urLoaderConfigGetInfo +/// @details Each entry is a pointer to the parameter passed to the function; +/// allowing the callback the ability to modify the parameter's value +typedef struct ur_loader_config_get_info_params_t { + ur_loader_config_handle_t *phLoaderConfig; + ur_loader_config_info_t *ppropName; + size_t *ppropSize; + void **ppPropValue; + size_t **ppPropSizeRet; +} ur_loader_config_get_info_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urLoaderConfigEnableLayer +/// @details Each entry is a pointer to the parameter passed to the function; +/// allowing the callback the ability to modify the parameter's value +typedef struct ur_loader_config_enable_layer_params_t { + ur_loader_config_handle_t *phLoaderConfig; + const char **ppLayerName; +} ur_loader_config_enable_layer_params_t; + /////////////////////////////////////////////////////////////////////////////// /// @brief Function parameters for urPlatformGet /// @details Each entry is a pointer to the parameter passed to the function; @@ -9619,6 +9804,7 @@ typedef struct ur_usm_p2p_peer_access_get_info_exp_params_t { /// allowing the callback the ability to modify the parameter's value typedef struct ur_init_params_t { ur_device_init_flags_t *pdevice_flags; + ur_loader_config_handle_t *phLoaderConfig; } ur_init_params_t; /////////////////////////////////////////////////////////////////////////////// diff --git a/include/ur_ddi.h b/include/ur_ddi.h index 3729208835..2a52806bf4 100644 --- a/include/ur_ddi.h +++ b/include/ur_ddi.h @@ -1869,7 +1869,8 @@ typedef ur_result_t(UR_APICALL *ur_pfnGetUsmP2PExpProcAddrTable_t)( /////////////////////////////////////////////////////////////////////////////// /// @brief Function-pointer for urInit typedef ur_result_t(UR_APICALL *ur_pfnInit_t)( - ur_device_init_flags_t); + ur_device_init_flags_t, + ur_loader_config_handle_t); /////////////////////////////////////////////////////////////////////////////// /// @brief Function-pointer for urTearDown diff --git a/scripts/core/common.yml b/scripts/core/common.yml index 9797c18ced..6104ef9cc7 100644 --- a/scripts/core/common.yml +++ b/scripts/core/common.yml @@ -60,6 +60,11 @@ name: $x_bool_t value: uint8_t --- #-------------------------------------------------------------------------- type: handle +desc: "Handle of a loader config object" +class: $xLoaderConfig +name: "$x_loader_config_handle_t" +--- #-------------------------------------------------------------------------- +type: handle desc: "Handle of a platform instance" class: $xPlatform name: "$x_platform_handle_t" diff --git a/scripts/core/registry.yml b/scripts/core/registry.yml index e29203afdc..05bd4408ac 100644 --- a/scripts/core/registry.yml +++ b/scripts/core/registry.yml @@ -502,3 +502,18 @@ etors: - name: COMMAND_BUFFER_APPEND_MEMBUFFER_READ_RECT_EXP desc: Enumerator for $xCommandBufferAppendMembufferReadRectExp value: '171' +- name: LOADER_CONFIG_CREATE + desc: Enumerator for $xLoaderConfigCreate + value: '172' +- name: LOADER_CONFIG_RELEASE + desc: Enumerator for $xLoaderConfigRelease + value: '173' +- name: LOADER_CONFIG_RETAIN + desc: Enumerator for $xLoaderConfigRetain + value: '174' +- name: LOADER_CONFIG_GET_INFO + desc: Enumerator for $xLoaderConfigGetInfo + value: '175' +- name: LOADER_CONFIG_ENABLE_LAYER + desc: Enumerator for $xLoaderConfigEnableLayer + value: '176' diff --git a/scripts/core/runtime.yml b/scripts/core/runtime.yml index c0bd7a12c7..7f5e188053 100644 --- a/scripts/core/runtime.yml +++ b/scripts/core/runtime.yml @@ -29,6 +29,111 @@ etors: desc: "initialize VPU device adapters." --- #-------------------------------------------------------------------------- type: function +desc: "Create a loader config object." +class: $xLoaderConfig +name: Create +decl: static +params: + - type: $x_loader_config_handle_t* + name: phLoaderConfig + desc: "[out] Pointer to handle of loader config object created." +--- #-------------------------------------------------------------------------- +type: function +desc: "Get a reference to the loader config object." +class: $xLoaderConfig +name: Retain +decl: static +details: + - "Get a reference to the loader config handle. Increment its reference count" + - "The application may call this function from simultaneous threads." + - "The implementation of this function should be lock-free." +params: + - type: $x_loader_config_handle_t + name: hLoaderConfig + desc: "[in] loader config handle to retain" +--- #-------------------------------------------------------------------------- +type: function +desc: "Release config handle." +class: $xLoaderConfig +name: Release +decl: static +details: + - "Decrement reference count and destroy the config handle if reference count becomes zero." + - "The application may call this function from simultaneous threads." + - "The implementation of this function should be lock-free." +params: + - type: $x_loader_config_handle_t + name: hLoaderConfig + desc: "[in] config handle to release" +--- #-------------------------------------------------------------------------- +type: enum +desc: "Supported loader info" +class: $xLoaderConfig +name: $x_loader_config_info_t +typed_etors: True +etors: + - name: AVAILABLE_LAYERS + desc: "[char[]] Null-terminated, semi-colon separated list of available layers." +--- #-------------------------------------------------------------------------- +type: function +desc: "Retrieves various information about the loader." +class: $xLoaderConfig +name: GetInfo +decl: static +details: + - "The application may call this function from simultaneous threads." + - "The implementation of this function should be lock-free." +params: + - type: $x_loader_config_handle_t + name: hLoaderConfig + desc: "[in] handle of the loader config object" + - type: $x_loader_config_info_t + name: propName + desc: "[in] type of the info to retrieve" + - type: "size_t" + name: propSize + desc: | + [in] the number of bytes pointed to by pPropValue. + - type: "void*" + name: pPropValue + desc: | + [out][optional][typename(propName, propSize)] array of bytes holding the info. + If propSize is not equal to or greater than the real number of bytes needed to return the info + then the $X_RESULT_ERROR_INVALID_SIZE error is returned and pPropValue is not used. + - type: "size_t*" + name: pPropSizeRet + desc: | + [out][optional] pointer to the actual size in bytes of the queried propName. +returns: + - $X_RESULT_ERROR_UNSUPPORTED_ENUMERATION: + - "If `propName` is not supported by the loader." + - $X_RESULT_ERROR_INVALID_SIZE: + - "`propSize == 0 && pPropValue != NULL`" + - "If `propSize` is less than the real number of bytes needed to return the info." + - $X_RESULT_ERROR_INVALID_NULL_POINTER: + - "`propSize != 0 && pPropValue == NULL`" + - "`pPropValue == NULL && pPropSizeRet == NULL`" + - $X_RESULT_ERROR_INVALID_DEVICE + - $X_RESULT_ERROR_OUT_OF_RESOURCES + - $X_RESULT_ERROR_OUT_OF_HOST_MEMORY +--- #-------------------------------------------------------------------------- +type: function +desc: "Enable a layer for the specified loader config." +class: $xLoaderConfig +name: EnableLayer +decl: static +params: + - type: $x_loader_config_handle_t + name: hLoaderConfig + desc: "[in] Handle to config object the layer will be enabled for." + - type: const char* + name: pLayerName + desc: "[in] Null terminated string containing the name of the layer to enable." +returns: + - $X_RESULT_ERROR_INVALID_VALUE: + - "If layer specified with `pLayerName` can't be found by the loader." +--- #-------------------------------------------------------------------------- +type: function desc: "Initialize the $OneApi adapter(s)" class: $x name: Init @@ -49,6 +154,9 @@ params: [in] device initialization flags. must be 0 (default) or a combination of $x_device_init_flag_t. init: "0" + - type: $x_loader_config_handle_t + name: hLoaderConfig + desc: "[in][optional] Handle of loader config handle." returns: - $X_RESULT_ERROR_OUT_OF_HOST_MEMORY --- #-------------------------------------------------------------------------- diff --git a/scripts/json2src.py b/scripts/json2src.py index 0a5c52e38a..10ad00a2fc 100755 --- a/scripts/json2src.py +++ b/scripts/json2src.py @@ -23,6 +23,33 @@ def add_argument(parser, name, help, default=False): group.add_argument("--skip-" + name, dest=name, help="Skip "+help, action="store_false") parser.set_defaults(**{name:default}) +""" + helpers to strip loader only api constructs from the json +""" +def strip_specs_class(specs, strip_class): + for spec in specs: + remove_obj = [] + for obj in spec["objects"]: + if "class" in obj and strip_class in obj["class"]: + remove_obj.append(obj) + for obj in remove_obj: + spec["objects"].remove(obj) + +def strip_meta_entry(meta, entry_name, pattern): + loader_entries = [] + for entry in meta[entry_name]: + if pattern in entry: + loader_entries.append(entry) + + for entry in loader_entries: + del meta[entry_name][entry] + +def strip_loader_meta(meta): + strip_meta_entry(meta, "class", "Loader") + strip_meta_entry(meta, "function", "Loader") + strip_meta_entry(meta, "enum", "loader") + strip_meta_entry(meta, "handle", "loader") + if __name__ == '__main__': parser = argparse.ArgumentParser() add_argument(parser, "lib", "generation of lib files.", True) @@ -48,6 +75,9 @@ def add_argument(parser, name, help, default=False): if args.sections == None or config['name'] in args.sections: if args.lib: generate_code.generate_lib(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta']) + # From here only generate code for functions adapters can implement. + strip_specs_class(specs, "Loader") + strip_loader_meta(input['meta']) if args.loader: generate_code.generate_loader(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta']) if args.layers: diff --git a/scripts/templates/api.py.mako b/scripts/templates/api.py.mako index 35a2fd6d27..0399bf1ba8 100644 --- a/scripts/templates/api.py.mako +++ b/scripts/templates/api.py.mako @@ -178,6 +178,9 @@ class ${N}_DDI: self.__dll.${x}Init(0, 0) %for tbl in tables: + %if 'Loader' in tbl['name']: +<% continue %> + %endif # call driver to get function pointers ${tbl['name']} = ${tbl['type']}() r = ${x}_result_v(self.__dll.${tbl['export']['name']}(version, byref(${tbl['name']}))) diff --git a/scripts/templates/ddi.h.mako b/scripts/templates/ddi.h.mako index 3a0e0c1af2..26d7f3f93d 100644 --- a/scripts/templates/ddi.h.mako +++ b/scripts/templates/ddi.h.mako @@ -31,6 +31,9 @@ extern "C" { #endif %for tbl in th.get_pfntables(specs, meta, n, tags): +%if 'Loader' in tbl['export']['name']: + <% continue %> +%endif %for obj in tbl['functions']: /////////////////////////////////////////////////////////////////////////////// /// @brief Function-pointer for ${th.make_func_name(n, tags, obj)} @@ -94,6 +97,9 @@ typedef ${x}_result_t (${X}_APICALL *${tbl['pfn']})( typedef struct ${n}_dditable_t { %for tbl in th.get_pfntables(specs, meta, n, tags): +%if 'loader' in tbl['type']: + <% continue %> +%endif ${th.append_ws(tbl['type'], 35)} ${tbl['name']}; %endfor } ${n}_dditable_t; diff --git a/scripts/templates/libapi.cpp.mako b/scripts/templates/libapi.cpp.mako index b054180fb6..c2fb67808e 100644 --- a/scripts/templates/libapi.cpp.mako +++ b/scripts/templates/libapi.cpp.mako @@ -56,10 +56,13 @@ ${th.make_func_name(n, tags, obj)}( %endfor ) try { +%if 'Loader' in obj['class']: + return ur_lib::${th.make_func_name(n, tags, obj)}(${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} ); +%else: %if re.match("Init", obj['name']): static ${x}_result_t result = ${X}_RESULT_SUCCESS; - std::call_once(${x}_lib::context->initOnce, [device_flags]() { - result = ${x}_lib::context->Init(device_flags); + std::call_once(${x}_lib::context->initOnce, [device_flags, hLoaderConfig]() { + result = ${x}_lib::context->Init(device_flags, hLoaderConfig); }); if( ${X}_RESULT_SUCCESS != result ) @@ -71,6 +74,7 @@ try { return ${X}_RESULT_ERROR_UNINITIALIZED; return ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} ); +%endif } catch(...) { return exceptionToResult(std::current_exception()); } %if 'condition' in obj: #endif // ${th.subt(n, tags, obj['condition'])} diff --git a/scripts/templates/libddi.cpp.mako b/scripts/templates/libddi.cpp.mako index de73cc2fc7..fc04c20ff8 100644 --- a/scripts/templates/libddi.cpp.mako +++ b/scripts/templates/libddi.cpp.mako @@ -33,6 +33,9 @@ namespace ${x}_lib ${x}_result_t result = ${X}_RESULT_SUCCESS; %for tbl in th.get_pfntables(specs, meta, n, tags): + %if 'Loader' in tbl['export']['name']: + <% continue %> + %endif if( ${X}_RESULT_SUCCESS == result ) { result = ${tbl['export']['name']}( ${X}_API_VERSION_CURRENT, &${n}DdiTable.${tbl['name']} ); diff --git a/scripts/templates/trcddi.cpp.mako b/scripts/templates/trcddi.cpp.mako index f8b506240a..6d97354260 100644 --- a/scripts/templates/trcddi.cpp.mako +++ b/scripts/templates/trcddi.cpp.mako @@ -102,9 +102,15 @@ namespace ur_tracing_layer } %endfor - ${x}_result_t context_t::init(ur_dditable_t *dditable) - { + ${x}_result_t context_t::init( + ur_dditable_t *dditable, + const std::set& enabledLayerNames) { ${x}_result_t result = ${X}_RESULT_SUCCESS; + + if (enabledLayerNames.find("UR_TRACING_LAYER") == enabledLayerNames.end() && + !traceEnvEnabled) { + return result; + } %for tbl in th.get_pfntables(specs, meta, n, tags): if( ${X}_RESULT_SUCCESS == result ) diff --git a/scripts/templates/valddi.cpp.mako b/scripts/templates/valddi.cpp.mako index bd8b11d5a2..9a3f7f4a90 100644 --- a/scripts/templates/valddi.cpp.mako +++ b/scripts/templates/valddi.cpp.mako @@ -139,10 +139,25 @@ namespace ur_validation_layer %endfor ${x}_result_t context_t::init( - ${x}_dditable_t *dditable - ) - { + ${x}_dditable_t *dditable, + const std::set& enabledLayerNames) { ${x}_result_t result = ${X}_RESULT_SUCCESS; + + if (enabledLayerNames.find("UR_FULL_VALIDATION_LAYER") != enabledLayerNames.end()) { + enableParameterValidation = true; + enableLeakChecking = true; + } else { + if (enabledLayerNames.find("UR_PARAMETER_VALIDATION_LAYER") != enabledLayerNames.end()) { + enableParameterValidation = true; + } + if (enabledLayerNames.find("UR_LEAK_CHECKING_LAYER") != enabledLayerNames.end()) { + enableLeakChecking = true; + } + } + + if(!enableParameterValidation && !enableLeakChecking) { + return result; + } %for tbl in th.get_pfntables(specs, meta, n, tags): if ( ${X}_RESULT_SUCCESS == result ) diff --git a/source/adapters/null/ur_nullddi.cpp b/source/adapters/null/ur_nullddi.cpp index 95b62afb0d..a61efe0fc9 100644 --- a/source/adapters/null/ur_nullddi.cpp +++ b/source/adapters/null/ur_nullddi.cpp @@ -15,15 +15,17 @@ namespace driver { /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urInit __urdlllocal ur_result_t UR_APICALL urInit( - ur_device_init_flags_t device_flags ///< [in] device initialization flags. + ur_device_init_flags_t device_flags, ///< [in] device initialization flags. ///< must be 0 (default) or a combination of ::ur_device_init_flag_t. + ur_loader_config_handle_t + hLoaderConfig ///< [in][optional] Handle of loader config handle. ) try { ur_result_t result = UR_RESULT_SUCCESS; // if the driver has created a custom function, then call it instead of using the generic path auto pfnInit = d_context.urDdiTable.Global.pfnInit; if (nullptr != pfnInit) { - result = pfnInit(device_flags); + result = pfnInit(device_flags, hLoaderConfig); } else { // generic implementation } diff --git a/source/common/ur_params.hpp b/source/common/ur_params.hpp index 15014813a1..1df85ec7e7 100644 --- a/source/common/ur_params.hpp +++ b/source/common/ur_params.hpp @@ -9220,6 +9220,26 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) { case UR_FUNCTION_COMMAND_BUFFER_APPEND_MEMBUFFER_READ_RECT_EXP: os << "UR_FUNCTION_COMMAND_BUFFER_APPEND_MEMBUFFER_READ_RECT_EXP"; break; + + case UR_FUNCTION_LOADER_CONFIG_CREATE: + os << "UR_FUNCTION_LOADER_CONFIG_CREATE"; + break; + + case UR_FUNCTION_LOADER_CONFIG_RELEASE: + os << "UR_FUNCTION_LOADER_CONFIG_RELEASE"; + break; + + case UR_FUNCTION_LOADER_CONFIG_RETAIN: + os << "UR_FUNCTION_LOADER_CONFIG_RETAIN"; + break; + + case UR_FUNCTION_LOADER_CONFIG_GET_INFO: + os << "UR_FUNCTION_LOADER_CONFIG_GET_INFO"; + break; + + case UR_FUNCTION_LOADER_CONFIG_ENABLE_LAYER: + os << "UR_FUNCTION_LOADER_CONFIG_ENABLE_LAYER"; + break; default: os << "unknown enumerator"; break; @@ -9531,6 +9551,11 @@ inline std::ostream &operator<<(std::ostream &os, ur_params::serializeFlag(os, *(params->pdevice_flags)); + os << ", "; + os << ".hLoaderConfig = "; + + ur_params::serializePtr(os, *(params->phLoaderConfig)); + return os; } diff --git a/source/loader/layers/tracing/ur_tracing_layer.cpp b/source/loader/layers/tracing/ur_tracing_layer.cpp index e12557b599..efe818693f 100644 --- a/source/loader/layers/tracing/ur_tracing_layer.cpp +++ b/source/loader/layers/tracing/ur_tracing_layer.cpp @@ -28,13 +28,14 @@ context_t::context_t() { xptiFrameworkInitialize(); call_stream_id = xptiRegisterStream(CALL_STREAM_NAME); + traceEnvEnabled = getenv_tobool("UR_ENABLE_TRACING"); std::ostringstream streamv; streamv << STREAM_VER_MAJOR << "." << STREAM_VER_MINOR; xptiInitialize(CALL_STREAM_NAME, STREAM_VER_MAJOR, STREAM_VER_MINOR, streamv.str().data()); } -bool context_t::isEnabled() { return xptiTraceEnabled(); } +bool context_t::isAvailable() const { return xptiTraceEnabled(); } void context_t::notify(uint16_t trace_type, uint32_t id, const char *name, void *args, ur_result_t *resultp, uint64_t instance) { diff --git a/source/loader/layers/tracing/ur_tracing_layer.hpp b/source/loader/layers/tracing/ur_tracing_layer.hpp index c2708ab976..c8f75dc408 100644 --- a/source/loader/layers/tracing/ur_tracing_layer.hpp +++ b/source/loader/layers/tracing/ur_tracing_layer.hpp @@ -28,8 +28,12 @@ class __urdlllocal context_t : public proxy_layer_context_t { context_t(); ~context_t(); - bool isEnabled() override; - ur_result_t init(ur_dditable_t *dditable) override; + bool isAvailable() const override; + std::vector getNames() const override { + return {"UR_TRACING_LAYER"}; + } + ur_result_t init(ur_dditable_t *dditable, + const std::set &enabledLayerNames) override; uint64_t notify_begin(uint32_t id, const char *name, void *args); void notify_end(uint32_t id, const char *name, void *args, ur_result_t *resultp, uint64_t instance); @@ -38,6 +42,9 @@ class __urdlllocal context_t : public proxy_layer_context_t { void notify(uint16_t trace_type, uint32_t id, const char *name, void *args, ur_result_t *resultp, uint64_t instance); uint8_t call_stream_id; + + // Whether the layer is enabled via env variable. + bool traceEnvEnabled = false; }; extern context_t context; diff --git a/source/loader/layers/tracing/ur_trcddi.cpp b/source/loader/layers/tracing/ur_trcddi.cpp index 9b6d6b34dc..9987590292 100644 --- a/source/loader/layers/tracing/ur_trcddi.cpp +++ b/source/loader/layers/tracing/ur_trcddi.cpp @@ -18,8 +18,10 @@ namespace ur_tracing_layer { /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urInit __urdlllocal ur_result_t UR_APICALL urInit( - ur_device_init_flags_t device_flags ///< [in] device initialization flags. + ur_device_init_flags_t device_flags, ///< [in] device initialization flags. ///< must be 0 (default) or a combination of ::ur_device_init_flag_t. + ur_loader_config_handle_t + hLoaderConfig ///< [in][optional] Handle of loader config handle. ) { auto pfnInit = context.urDdiTable.Global.pfnInit; @@ -27,11 +29,11 @@ __urdlllocal ur_result_t UR_APICALL urInit( return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } - ur_init_params_t params = {&device_flags}; + ur_init_params_t params = {&device_flags, &hLoaderConfig}; uint64_t instance = context.notify_begin(UR_FUNCTION_INIT, "urInit", ¶ms); - ur_result_t result = pfnInit(device_flags); + ur_result_t result = pfnInit(device_flags, hLoaderConfig); context.notify_end(UR_FUNCTION_INIT, "urInit", ¶ms, &result, instance); @@ -6772,9 +6774,15 @@ __urdlllocal ur_result_t UR_APICALL urGetDeviceProcAddrTable( return result; } -ur_result_t context_t::init(ur_dditable_t *dditable) { +ur_result_t context_t::init(ur_dditable_t *dditable, + const std::set &enabledLayerNames) { ur_result_t result = UR_RESULT_SUCCESS; + if (enabledLayerNames.find("UR_TRACING_LAYER") == enabledLayerNames.end() && + !traceEnvEnabled) { + return result; + } + if (UR_RESULT_SUCCESS == result) { result = ur_tracing_layer::urGetGlobalProcAddrTable( UR_API_VERSION_CURRENT, &dditable->Global); diff --git a/source/loader/layers/ur_proxy_layer.hpp b/source/loader/layers/ur_proxy_layer.hpp index 723011eacf..da45017a5f 100644 --- a/source/loader/layers/ur_proxy_layer.hpp +++ b/source/loader/layers/ur_proxy_layer.hpp @@ -15,13 +15,18 @@ #include "ur_ddi.h" #include "ur_util.hpp" +#include + /////////////////////////////////////////////////////////////////////////////// class __urdlllocal proxy_layer_context_t { public: ur_api_version_t version = UR_API_VERSION_0_6; - virtual bool isEnabled() = 0; - virtual ur_result_t init(ur_dditable_t *dditable) = 0; + virtual std::vector getNames() const = 0; + virtual bool isAvailable() const = 0; + virtual ur_result_t + init(ur_dditable_t *dditable, + const std::set &enabledLayerNames) = 0; }; -#endif /* UR_PROXY_LAYER_H */ \ No newline at end of file +#endif /* UR_PROXY_LAYER_H */ diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index 46ba1e9379..f369c2c7fd 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -17,8 +17,10 @@ namespace ur_validation_layer { /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urInit __urdlllocal ur_result_t UR_APICALL urInit( - ur_device_init_flags_t device_flags ///< [in] device initialization flags. + ur_device_init_flags_t device_flags, ///< [in] device initialization flags. ///< must be 0 (default) or a combination of ::ur_device_init_flag_t. + ur_loader_config_handle_t + hLoaderConfig ///< [in][optional] Handle of loader config handle. ) { auto pfnInit = context.urDdiTable.Global.pfnInit; @@ -32,7 +34,7 @@ __urdlllocal ur_result_t UR_APICALL urInit( } } - ur_result_t result = pfnInit(device_flags); + ur_result_t result = pfnInit(device_flags, hLoaderConfig); return result; } @@ -8167,9 +8169,29 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetDeviceProcAddrTable( return result; } -ur_result_t context_t::init(ur_dditable_t *dditable) { +ur_result_t context_t::init(ur_dditable_t *dditable, + const std::set &enabledLayerNames) { ur_result_t result = UR_RESULT_SUCCESS; + if (enabledLayerNames.find("UR_FULL_VALIDATION_LAYER") != + enabledLayerNames.end()) { + enableParameterValidation = true; + enableLeakChecking = true; + } else { + if (enabledLayerNames.find("UR_PARAMETER_VALIDATION_LAYER") != + enabledLayerNames.end()) { + enableParameterValidation = true; + } + if (enabledLayerNames.find("UR_LEAK_CHECKING_LAYER") != + enabledLayerNames.end()) { + enableLeakChecking = true; + } + } + + if (!enableParameterValidation && !enableLeakChecking) { + return result; + } + if (UR_RESULT_SUCCESS == result) { result = ur_validation_layer::urGetGlobalProcAddrTable( UR_API_VERSION_CURRENT, &dditable->Global); diff --git a/source/loader/layers/validation/ur_validation_layer.cpp b/source/loader/layers/validation/ur_validation_layer.cpp index 7da014054f..6f85447371 100644 --- a/source/loader/layers/validation/ur_validation_layer.cpp +++ b/source/loader/layers/validation/ur_validation_layer.cpp @@ -16,7 +16,6 @@ context_t context; /////////////////////////////////////////////////////////////////////////////// context_t::context_t() : logger(logger::create_logger("validation")) { - enableValidation = getenv_tobool("UR_ENABLE_VALIDATION_LAYER"); enableParameterValidation = getenv_tobool("UR_ENABLE_PARAMETER_VALIDATION"); enableLeakChecking = getenv_tobool("UR_ENABLE_LEAK_CHECKING"); } diff --git a/source/loader/layers/validation/ur_validation_layer.hpp b/source/loader/layers/validation/ur_validation_layer.hpp index 5aeacc30e9..6d45d46f19 100644 --- a/source/loader/layers/validation/ur_validation_layer.hpp +++ b/source/loader/layers/validation/ur_validation_layer.hpp @@ -20,10 +20,8 @@ namespace ur_validation_layer { /////////////////////////////////////////////////////////////////////////////// class __urdlllocal context_t : public proxy_layer_context_t { public: - bool enableValidation = false; - bool enableParameterValidation = false; - bool enableLeakChecking = false; - + bool enableParameterValidation; + bool enableLeakChecking; logger::Logger logger; ur_dditable_t urDdiTable = {}; @@ -31,8 +29,13 @@ class __urdlllocal context_t : public proxy_layer_context_t { context_t(); ~context_t(); - bool isEnabled() override { return enableValidation; }; - ur_result_t init(ur_dditable_t *dditable) override; + bool isAvailable() const override { return true; } + std::vector getNames() const override { + return {"UR_FULL_VALIDATION_LAYER", "UR_PARAMETER_VALIDATION_LAYER", + "UR_LEAK_CHECKING_LAYER"}; + } + ur_result_t init(ur_dditable_t *dditable, + const std::set &enabledLayerNames) override; }; extern context_t context; diff --git a/source/loader/ur_adapter_registry.hpp b/source/loader/ur_adapter_registry.hpp index 33cf4e130e..744d988336 100644 --- a/source/loader/ur_adapter_registry.hpp +++ b/source/loader/ur_adapter_registry.hpp @@ -106,8 +106,9 @@ class AdapterRegistry { // to load the adapter. std::vector> adaptersLoadPaths; - static constexpr std::array knownAdapterNames{ - MAKE_LIBRARY_NAME("ur_adapter_level_zero", "0")}; + static constexpr std::array knownAdapterNames{ + MAKE_LIBRARY_NAME("ur_adapter_level_zero", "0"), + MAKE_LIBRARY_NAME("ur_adapter_cuda", "0")}; std::optional> getEnvAdapterSearchPaths() { std::optional> pathStringsOpt; diff --git a/source/loader/ur_ldrddi.cpp b/source/loader/ur_ldrddi.cpp index b7176acac2..1ebe2dcb3d 100644 --- a/source/loader/ur_ldrddi.cpp +++ b/source/loader/ur_ldrddi.cpp @@ -35,8 +35,10 @@ ur_exp_command_buffer_factory_t ur_exp_command_buffer_factory; /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urInit __urdlllocal ur_result_t UR_APICALL urInit( - ur_device_init_flags_t device_flags ///< [in] device initialization flags. + ur_device_init_flags_t device_flags, ///< [in] device initialization flags. ///< must be 0 (default) or a combination of ::ur_device_init_flag_t. + ur_loader_config_handle_t + hLoaderConfig ///< [in][optional] Handle of loader config handle. ) { ur_result_t result = UR_RESULT_SUCCESS; @@ -44,7 +46,8 @@ __urdlllocal ur_result_t UR_APICALL urInit( if (platform.initStatus != UR_RESULT_SUCCESS) { continue; } - platform.initStatus = platform.dditable.ur.Global.pfnInit(device_flags); + platform.initStatus = + platform.dditable.ur.Global.pfnInit(device_flags, hLoaderConfig); } return result; diff --git a/source/loader/ur_lib.cpp b/source/loader/ur_lib.cpp index cfac087348..60bedbea36 100644 --- a/source/loader/ur_lib.cpp +++ b/source/loader/ur_lib.cpp @@ -12,25 +12,40 @@ #include "ur_lib.hpp" #include "logger/ur_logger.hpp" #include "ur_loader.hpp" -#include "ur_proxy_layer.hpp" -#include "validation/ur_validation_layer.hpp" -#if UR_ENABLE_TRACING -#include "tracing/ur_tracing_layer.hpp" -#endif +#include namespace ur_lib { /////////////////////////////////////////////////////////////////////////////// context_t *context; /////////////////////////////////////////////////////////////////////////////// -context_t::context_t() {} +context_t::context_t() { + for (auto l : layers) { + if (l->isAvailable()) { + for (auto &layerName : l->getNames()) { + availableLayers += layerName + ";"; + } + } + } + availableLayers.pop_back(); +} /////////////////////////////////////////////////////////////////////////////// context_t::~context_t() {} +void context_t::initLayers(const std::set &layerNames) { + for (auto &l : layers) { + if (l->isAvailable()) { + l->init(&context->urDdiTable, layerNames); + } + } +} + ////////////////////////////////////////////////////////////////////////// -__urdlllocal ur_result_t context_t::Init(ur_device_init_flags_t device_flags) { +__urdlllocal ur_result_t +context_t::Init(ur_device_init_flags_t device_flags, + ur_loader_config_handle_t hLoaderConfig) { ur_result_t result; const char *logger_name = "loader"; logger::init(logger_name); @@ -42,20 +57,64 @@ __urdlllocal ur_result_t context_t::Init(ur_device_init_flags_t device_flags) { result = urInit(); } - proxy_layer_context_t *layers[] = { - &ur_validation_layer::context, -#if UR_ENABLE_TRACING - &ur_tracing_layer::context -#endif - }; - - for (proxy_layer_context_t *l : layers) { - if (l->isEnabled()) { - l->init(&context->urDdiTable); - } + if (hLoaderConfig) { + initLayers(hLoaderConfig->getEnabledLayerNames()); + } else { + initLayers(); } return result; } +ur_result_t urLoaderConfigCreate(ur_loader_config_handle_t *phLoaderConfig) { + *phLoaderConfig = new ur_loader_config_handle_t_; + return UR_RESULT_SUCCESS; +} + +ur_result_t urLoaderConfigRetain(ur_loader_config_handle_t hLoaderConfig) { + hLoaderConfig->incrementReferenceCount(); + return UR_RESULT_SUCCESS; +} + +ur_result_t urLoaderConfigRelease(ur_loader_config_handle_t hLoaderConfig) { + if (hLoaderConfig->decrementReferenceCount() == 0) { + delete hLoaderConfig; + } + return UR_RESULT_SUCCESS; +} + +ur_result_t urLoaderConfigGetInfo(ur_loader_config_handle_t hLoaderConfig, + ur_loader_config_info_t propName, + size_t propSize, void *pPropValue, + size_t *pPropSizeRet) { + if (!pPropValue && !pPropSizeRet) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + + switch (propName) { + case UR_LOADER_CONFIG_INFO_AVAILABLE_LAYERS: { + if (pPropSizeRet) { + *pPropSizeRet = context->availableLayers.size() + 1; + } + if (pPropValue) { + char *outString = static_cast(pPropValue); + if (propSize != context->availableLayers.size() + 1) { + return UR_RESULT_ERROR_INVALID_SIZE; + } + std::memcpy(outString, context->availableLayers.data(), propSize); + outString[propSize + 1] = '\0'; + } + break; + } + default: + return UR_RESULT_ERROR_INVALID_ENUMERATION; + } + return UR_RESULT_SUCCESS; +} + +ur_result_t urLoaderConfigEnableLayer(ur_loader_config_handle_t hLoaderConfig, + const char *pLayerName) { + hLoaderConfig->enabled_layers.insert(pLayerName); + return UR_RESULT_SUCCESS; +} } // namespace ur_lib diff --git a/source/loader/ur_lib.hpp b/source/loader/ur_lib.hpp index bd12597475..da3a593b90 100644 --- a/source/loader/ur_lib.hpp +++ b/source/loader/ur_lib.hpp @@ -15,13 +15,32 @@ #include "ur_api.h" #include "ur_ddi.h" +#include "ur_proxy_layer.hpp" #include "ur_util.hpp" + +#include "validation/ur_validation_layer.hpp" +#if UR_ENABLE_TRACING +#include "tracing/ur_tracing_layer.hpp" +#endif + #include +#include #include +struct ur_loader_config_handle_t_ { + std::set enabled_layers; + size_t ref_count = 1; + + size_t incrementReferenceCount() { return ref_count++; } + size_t decrementReferenceCount() { return ref_count--; } + const std::set &getEnabledLayerNames() const { + return enabled_layers; + } +}; + namespace ur_lib { /////////////////////////////////////////////////////////////////////////////// -class context_t { +class __urdlllocal context_t { public: #ifdef DYNAMIC_LOAD_LOADER HMODULE loader = nullptr; @@ -32,14 +51,32 @@ class context_t { std::once_flag initOnce; - ur_result_t Init(ur_device_init_flags_t dflags); + ur_result_t Init(ur_device_init_flags_t dflags, + ur_loader_config_handle_t hLoaderConfig); ur_result_t urInit(); ur_dditable_t urDdiTable = {}; + + const std::vector layers = { + &ur_validation_layer::context, +#if UR_ENABLE_TRACING + &ur_tracing_layer::context +#endif + }; + std::string availableLayers; + + void initLayers(const std::set &layerNames = {}); }; extern context_t *context; - +ur_result_t urLoaderConfigCreate(ur_loader_config_handle_t *phLoaderConfig); +ur_result_t urLoaderConfigRetain(ur_loader_config_handle_t hLoaderConfig); +ur_result_t urLoaderConfigRelease(ur_loader_config_handle_t hLoaderConfig); +ur_result_t urLoaderConfigGetInfo(ur_loader_config_handle_t hLoaderConfig, + ur_loader_config_info_t propName, + size_t propSize, void *pPropValue, + size_t *pPropSizeRet); +ur_result_t urLoaderConfigEnableLayer(ur_loader_config_handle_t hLoaderConfig, + const char *pLayerName); } // namespace ur_lib - #endif /* UR_LOADER_LIB_H */ diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index 8e095d05ba..162bdfdf04 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -15,6 +15,148 @@ extern "C" { +/////////////////////////////////////////////////////////////////////////////// +/// @brief Create a loader config object. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == phLoaderConfig` +ur_result_t UR_APICALL urLoaderConfigCreate( + ur_loader_config_handle_t * + phLoaderConfig ///< [out] Pointer to handle of loader config object created. + ) try { + return ur_lib::urLoaderConfigCreate(phLoaderConfig); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Get a reference to the loader config object. +/// +/// @details +/// - Get a reference to the loader config handle. Increment its reference +/// count +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function should be lock-free. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +ur_result_t UR_APICALL urLoaderConfigRetain( + ur_loader_config_handle_t + hLoaderConfig ///< [in] loader config handle to retain + ) try { + return ur_lib::urLoaderConfigRetain(hLoaderConfig); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Release config handle. +/// +/// @details +/// - Decrement reference count and destroy the config handle if reference +/// count becomes zero. +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function should be lock-free. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +ur_result_t UR_APICALL urLoaderConfigRelease( + ur_loader_config_handle_t hLoaderConfig ///< [in] config handle to release + ) try { + return ur_lib::urLoaderConfigRelease(hLoaderConfig); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves various information about the loader. +/// +/// @details +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function should be lock-free. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `::UR_LOADER_CONFIG_INFO_AVAILABLE_LAYERS < propName` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION +/// + If `propName` is not supported by the loader. +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// + `propSize == 0 && pPropValue != NULL` +/// + If `propSize` is less than the real number of bytes needed to return the info. +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `propSize != 0 && pPropValue == NULL` +/// + `pPropValue == NULL && pPropSizeRet == NULL` +/// - ::UR_RESULT_ERROR_INVALID_DEVICE +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +ur_result_t UR_APICALL urLoaderConfigGetInfo( + ur_loader_config_handle_t + hLoaderConfig, ///< [in] handle of the loader config object + ur_loader_config_info_t propName, ///< [in] type of the info to retrieve + size_t propSize, ///< [in] the number of bytes pointed to by pPropValue. + void * + pPropValue, ///< [out][optional][typename(propName, propSize)] array of bytes holding + ///< the info. + ///< If propSize is not equal to or greater than the real number of bytes + ///< needed to return the info + ///< then the ::UR_RESULT_ERROR_INVALID_SIZE error is returned and + ///< pPropValue is not used. + size_t * + pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName. + ) try { + return ur_lib::urLoaderConfigGetInfo(hLoaderConfig, propName, propSize, + pPropValue, pPropSizeRet); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enable a layer for the specified loader config. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == pLayerName` +/// - ::UR_RESULT_ERROR_INVALID_VALUE +/// + If layer specified with `pLayerName` can't be found by the loader. +ur_result_t UR_APICALL urLoaderConfigEnableLayer( + ur_loader_config_handle_t + hLoaderConfig, ///< [in] Handle to config object the layer will be enabled for. + const char * + pLayerName ///< [in] Null terminated string containing the name of the layer to + ///< enable. + ) try { + return ur_lib::urLoaderConfigEnableLayer(hLoaderConfig, pLayerName); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Initialize the 'oneAPI' adapter(s) /// @@ -41,12 +183,14 @@ extern "C" { /// + `::UR_DEVICE_INIT_FLAGS_MASK & device_flags` /// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY ur_result_t UR_APICALL urInit( - ur_device_init_flags_t device_flags ///< [in] device initialization flags. + ur_device_init_flags_t device_flags, ///< [in] device initialization flags. ///< must be 0 (default) or a combination of ::ur_device_init_flag_t. + ur_loader_config_handle_t + hLoaderConfig ///< [in][optional] Handle of loader config handle. ) try { static ur_result_t result = UR_RESULT_SUCCESS; - std::call_once(ur_lib::context->initOnce, [device_flags]() { - result = ur_lib::context->Init(device_flags); + std::call_once(ur_lib::context->initOnce, [device_flags, hLoaderConfig]() { + result = ur_lib::context->Init(device_flags, hLoaderConfig); }); if (UR_RESULT_SUCCESS != result) { @@ -58,7 +202,7 @@ ur_result_t UR_APICALL urInit( return UR_RESULT_ERROR_UNINITIALIZED; } - return pfnInit(device_flags); + return pfnInit(device_flags, hLoaderConfig); } catch (...) { return exceptionToResult(std::current_exception()); } diff --git a/source/ur_api.cpp b/source/ur_api.cpp index 89c1271a54..6f980a8c60 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -12,6 +12,142 @@ */ #include "ur_api.h" +/////////////////////////////////////////////////////////////////////////////// +/// @brief Create a loader config object. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == phLoaderConfig` +ur_result_t UR_APICALL urLoaderConfigCreate( + ur_loader_config_handle_t * + phLoaderConfig ///< [out] Pointer to handle of loader config object created. +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Get a reference to the loader config object. +/// +/// @details +/// - Get a reference to the loader config handle. Increment its reference +/// count +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function should be lock-free. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +ur_result_t UR_APICALL urLoaderConfigRetain( + ur_loader_config_handle_t + hLoaderConfig ///< [in] loader config handle to retain +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Release config handle. +/// +/// @details +/// - Decrement reference count and destroy the config handle if reference +/// count becomes zero. +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function should be lock-free. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +ur_result_t UR_APICALL urLoaderConfigRelease( + ur_loader_config_handle_t hLoaderConfig ///< [in] config handle to release +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves various information about the loader. +/// +/// @details +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function should be lock-free. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `::UR_LOADER_CONFIG_INFO_AVAILABLE_LAYERS < propName` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION +/// + If `propName` is not supported by the loader. +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// + `propSize == 0 && pPropValue != NULL` +/// + If `propSize` is less than the real number of bytes needed to return the info. +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `propSize != 0 && pPropValue == NULL` +/// + `pPropValue == NULL && pPropSizeRet == NULL` +/// - ::UR_RESULT_ERROR_INVALID_DEVICE +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +ur_result_t UR_APICALL urLoaderConfigGetInfo( + ur_loader_config_handle_t + hLoaderConfig, ///< [in] handle of the loader config object + ur_loader_config_info_t propName, ///< [in] type of the info to retrieve + size_t propSize, ///< [in] the number of bytes pointed to by pPropValue. + void * + pPropValue, ///< [out][optional][typename(propName, propSize)] array of bytes holding + ///< the info. + ///< If propSize is not equal to or greater than the real number of bytes + ///< needed to return the info + ///< then the ::UR_RESULT_ERROR_INVALID_SIZE error is returned and + ///< pPropValue is not used. + size_t * + pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName. +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enable a layer for the specified loader config. +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hLoaderConfig` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == pLayerName` +/// - ::UR_RESULT_ERROR_INVALID_VALUE +/// + If layer specified with `pLayerName` can't be found by the loader. +ur_result_t UR_APICALL urLoaderConfigEnableLayer( + ur_loader_config_handle_t + hLoaderConfig, ///< [in] Handle to config object the layer will be enabled for. + const char * + pLayerName ///< [in] Null terminated string containing the name of the layer to + ///< enable. +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Initialize the 'oneAPI' adapter(s) /// @@ -38,8 +174,10 @@ /// + `::UR_DEVICE_INIT_FLAGS_MASK & device_flags` /// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY ur_result_t UR_APICALL urInit( - ur_device_init_flags_t device_flags ///< [in] device initialization flags. + ur_device_init_flags_t device_flags, ///< [in] device initialization flags. ///< must be 0 (default) or a combination of ::ur_device_init_flag_t. + ur_loader_config_handle_t + hLoaderConfig ///< [in][optional] Handle of loader config handle. ) { ur_result_t result = UR_RESULT_SUCCESS; return result; diff --git a/test/conformance/platform/fixtures.h b/test/conformance/platform/fixtures.h index 77f1f5465d..038d8f9ff4 100644 --- a/test/conformance/platform/fixtures.h +++ b/test/conformance/platform/fixtures.h @@ -14,7 +14,7 @@ struct urTest : ::testing::Test { void SetUp() override { ur_device_init_flags_t device_flags = 0; - ASSERT_SUCCESS(urInit(device_flags)); + ASSERT_SUCCESS(urInit(device_flags, nullptr)); } void TearDown() override { diff --git a/test/conformance/platform/urInit.cpp b/test/conformance/platform/urInit.cpp index eedf58af34..8bb43e3012 100644 --- a/test/conformance/platform/urInit.cpp +++ b/test/conformance/platform/urInit.cpp @@ -20,8 +20,12 @@ INSTANTIATE_TEST_SUITE_P( }); TEST_P(urInitTestWithParam, Success) { + ur_loader_config_handle_t config = nullptr; + urLoaderConfigCreate(&config); + urLoaderConfigEnableLayer(config, "UR_FULL_VALIDATION_LAYER"); + ur_device_init_flags_t device_flags = GetParam(); - ASSERT_SUCCESS(urInit(device_flags)); + ASSERT_SUCCESS(urInit(device_flags, config)); ur_tear_down_params_t tear_down_params{nullptr}; ASSERT_SUCCESS(urTearDown(&tear_down_params)); @@ -30,5 +34,6 @@ TEST_P(urInitTestWithParam, Success) { TEST(urInitTest, ErrorInvalidEnumerationDeviceFlags) { const ur_device_init_flags_t device_flags = UR_DEVICE_INIT_FLAG_FORCE_UINT32; - ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION, urInit(device_flags)); + ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION, + urInit(device_flags, nullptr)); } diff --git a/test/conformance/platform/urTearDown.cpp b/test/conformance/platform/urTearDown.cpp index e4dd0bbcb8..3639515f82 100644 --- a/test/conformance/platform/urTearDown.cpp +++ b/test/conformance/platform/urTearDown.cpp @@ -7,7 +7,7 @@ struct urTearDownTest : testing::Test { void SetUp() override { ur_device_init_flags_t device_flags = 0; - ASSERT_SUCCESS(urInit(device_flags)); + ASSERT_SUCCESS(urInit(device_flags, nullptr)); } }; diff --git a/test/conformance/source/environment.cpp b/test/conformance/source/environment.cpp index 1da7ad7c86..cc857e027e 100644 --- a/test/conformance/source/environment.cpp +++ b/test/conformance/source/environment.cpp @@ -43,8 +43,13 @@ std::ostream &operator<<(std::ostream &out, uur::PlatformEnvironment::PlatformEnvironment(int argc, char **argv) : platform_options{parsePlatformOptions(argc, argv)} { instance = this; + + ur_loader_config_handle_t config; + urLoaderConfigCreate(&config); + urLoaderConfigEnableLayer(config, "UR_FULL_VALIDATION_LAYER"); + ur_device_init_flags_t device_flags = 0; - switch (urInit(device_flags)) { + switch (urInit(device_flags, config)) { case UR_RESULT_SUCCESS: break; case UR_RESULT_ERROR_UNINITIALIZED: @@ -54,6 +59,7 @@ uur::PlatformEnvironment::PlatformEnvironment(int argc, char **argv) error = "urInit() failed"; return; } + urLoaderConfigRelease(config); uint32_t count = 0; if (urPlatformGet(0, nullptr, &count)) { diff --git a/test/layers/tracing/CMakeLists.txt b/test/layers/tracing/CMakeLists.txt index 3fe641824d..45bf5a038d 100644 --- a/test/layers/tracing/CMakeLists.txt +++ b/test/layers/tracing/CMakeLists.txt @@ -22,4 +22,5 @@ set_property(TEST ${TEST_NAME} PROPERTY ENVIRONMENT "XPTI_TRACE_ENABLE=1" "XPTI_FRAMEWORK_DISPATCHER=$" "XPTI_SUBSCRIBERS=$" - "UR_ADAPTERS_FORCE_LOAD=\"$\"") + "UR_ADAPTERS_FORCE_LOAD=\"$\"" + "UR_ENABLE_TRACING=true") diff --git a/test/layers/validation/fixtures.hpp b/test/layers/validation/fixtures.hpp index 0348068fa9..92ec7efd4d 100644 --- a/test/layers/validation/fixtures.hpp +++ b/test/layers/validation/fixtures.hpp @@ -12,8 +12,14 @@ struct urTest : ::testing::Test { void SetUp() override { + ur_loader_config_handle_t config; + ASSERT_EQ(urLoaderConfigCreate(&config), UR_RESULT_SUCCESS); + ASSERT_EQ(urLoaderConfigEnableLayer(config, "UR_FULL_VALIDATION_LAYER"), + UR_RESULT_SUCCESS); + ur_device_init_flags_t device_flags = 0; - ASSERT_EQ(urInit(device_flags), UR_RESULT_SUCCESS); + ASSERT_EQ(urInit(device_flags, config), UR_RESULT_SUCCESS); + ASSERT_EQ(urLoaderConfigRelease(config), UR_RESULT_SUCCESS); } void TearDown() override { diff --git a/test/layers/validation/parameters.cpp b/test/layers/validation/parameters.cpp index e7f73e87fc..ee679363dc 100644 --- a/test/layers/validation/parameters.cpp +++ b/test/layers/validation/parameters.cpp @@ -6,9 +6,15 @@ #include "fixtures.hpp" TEST(valTest, urInit) { + ur_loader_config_handle_t config; + urLoaderConfigCreate(&config); + urLoaderConfigEnableLayer(config, "UR_PARAMETER_VALIDATION_LAYER"); + const ur_device_init_flags_t device_flags = UR_DEVICE_INIT_FLAG_FORCE_UINT32; - ASSERT_EQ(UR_RESULT_ERROR_INVALID_ENUMERATION, urInit(device_flags)); + ASSERT_EQ(urInit(device_flags, config), + UR_RESULT_ERROR_INVALID_ENUMERATION); + ASSERT_EQ(urLoaderConfigRelease(config), UR_RESULT_SUCCESS); } TEST_F(valPlatformsTest, testUrPlatformGetApiVersion) { diff --git a/test/loader/platforms/platforms.cpp b/test/loader/platforms/platforms.cpp index 2b7c3c8146..c39b0af160 100644 --- a/test/loader/platforms/platforms.cpp +++ b/test/loader/platforms/platforms.cpp @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) { ur_result_t status; // Initialize the platform - status = urInit(0); + status = urInit(0, nullptr); if (status != UR_RESULT_SUCCESS) { error("urInit failed with return code: {}", status); return 1; diff --git a/test/tools/urtrace/null_hello.match b/test/tools/urtrace/null_hello.match index 59e4c95367..0c76ccac1a 100644 --- a/test/tools/urtrace/null_hello.match +++ b/test/tools/urtrace/null_hello.match @@ -1,4 +1,4 @@ -urInit(.device_flags = 0) -> UR_RESULT_SUCCESS; +urInit(.device_flags = 0, .hLoaderConfig = nullptr) -> UR_RESULT_SUCCESS; Platform initialized. urPlatformGet(.NumEntries = 1, .phPlatforms = {}, .pNumPlatforms = {{.*}} (1)) -> UR_RESULT_SUCCESS; urPlatformGet(.NumEntries = 1, .phPlatforms = {{{.*}}}, .pNumPlatforms = nullptr) -> UR_RESULT_SUCCESS; diff --git a/test/tools/urtrace/null_hello_begin.match b/test/tools/urtrace/null_hello_begin.match index c706e5616d..114eedfc23 100644 --- a/test/tools/urtrace/null_hello_begin.match +++ b/test/tools/urtrace/null_hello_begin.match @@ -1,5 +1,5 @@ -begin(1) - urInit(.device_flags = 0); -end(1) - urInit(.device_flags = 0) -> UR_RESULT_SUCCESS; +begin(1) - urInit(.device_flags = 0, .hLoaderConfig = nullptr); +end(1) - urInit(.device_flags = 0, .hLoaderConfig = nullptr) -> UR_RESULT_SUCCESS; Platform initialized. begin(2) - urPlatformGet(.NumEntries = 1, .phPlatforms = {}, .pNumPlatforms = {{.*}} (0)); end(2) - urPlatformGet(.NumEntries = 1, .phPlatforms = {}, .pNumPlatforms = {{.*}} (1)) -> UR_RESULT_SUCCESS; diff --git a/test/tools/urtrace/null_hello_json.match b/test/tools/urtrace/null_hello_json.match index 9b41e6e0d7..7e7c089f73 100644 --- a/test/tools/urtrace/null_hello_json.match +++ b/test/tools/urtrace/null_hello_json.match @@ -1,6 +1,6 @@ { "traceEvents": [ -{ "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urInit", "args": "(.device_flags = 0)" }, +{ "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urInit", "args": "(.device_flags = 0, .hLoaderConfig = nullptr)" }, Platform initialized. { "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urPlatformGet", "args": "(.NumEntries = 1, .phPlatforms = {}, .pNumPlatforms = {{.*}} (1))" }, { "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urPlatformGet", "args": "(.NumEntries = 1, .phPlatforms = {{{.*}}}, .pNumPlatforms = nullptr)" }, @@ -14,4 +14,4 @@ Found a Null Device gpu. { "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urTearDown", "args": "(.pParams = nullptr)" }, {"name": "", "cat": "", "ph": "", "pid": "", "tid": "", "ts": ""} ] -} \ No newline at end of file +} diff --git a/test/tools/urtrace/null_hello_profiling.match b/test/tools/urtrace/null_hello_profiling.match index 1162bb4a53..3ad7ae3614 100644 --- a/test/tools/urtrace/null_hello_profiling.match +++ b/test/tools/urtrace/null_hello_profiling.match @@ -1,4 +1,4 @@ -urInit(.device_flags = 0) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) +urInit(.device_flags = 0, .hLoaderConfig = nullptr) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) Platform initialized. urPlatformGet(.NumEntries = 1, .phPlatforms = {}, .pNumPlatforms = {{.*}} (1)) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) urPlatformGet(.NumEntries = 1, .phPlatforms = {{{.*}}}, .pNumPlatforms = nullptr) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) diff --git a/test/unit/utils/params.cpp b/test/unit/utils/params.cpp index 742804101d..ada116e2ad 100644 --- a/test/unit/utils/params.cpp +++ b/test/unit/utils/params.cpp @@ -20,8 +20,11 @@ template class ParamsTest : public testing::Test { struct UrInitParams { ur_init_params_t params; ur_device_init_flags_t flags; - UrInitParams(ur_device_init_flags_t _flags) : flags(_flags) { + ur_loader_config_handle_t config; + UrInitParams(ur_device_init_flags_t _flags) + : flags(_flags), config(nullptr) { params.pdevice_flags = &flags; + params.phLoaderConfig = &config; } ur_init_params_t *get_struct() { return ¶ms; } @@ -29,7 +32,9 @@ struct UrInitParams { struct UrInitParamsNoFlags : UrInitParams { UrInitParamsNoFlags() : UrInitParams(0) {} - const char *get_expected() { return ".device_flags = 0"; }; + const char *get_expected() { + return ".device_flags = 0, .hLoaderConfig = nullptr"; + }; }; struct UrInitParamsInvalidFlags : UrInitParams { @@ -39,7 +44,8 @@ struct UrInitParamsInvalidFlags : UrInitParams { const char *get_expected() { return ".device_flags = UR_DEVICE_INIT_FLAG_GPU \\| " "UR_DEVICE_INIT_FLAG_MCA \\| unknown bit flags " - "11000010000000000000000000000000"; + "11000010000000000000000000000000, " + ".hLoaderConfig = nullptr"; }; }; diff --git a/tools/urtrace/urtrace.py b/tools/urtrace/urtrace.py index 8ed43abc50..a239f6196d 100755 --- a/tools/urtrace/urtrace.py +++ b/tools/urtrace/urtrace.py @@ -96,6 +96,8 @@ def get_dynamic_library_name(name): env['XPTI_TRACE_ENABLE'] = "1" +env['UR_ENABLE_TRACING'] = "1" + xptifw_lib = get_dynamic_library_name("xptifw") xptifw = find_library(args.libpath, xptifw_lib, args.recursive) if xptifw is None: