diff --git a/examples/hello_world/hello_world.cpp b/examples/hello_world/hello_world.cpp index dcd504bf4e..4d903da65a 100644 --- a/examples/hello_world/hello_world.cpp +++ b/examples/hello_world/hello_world.cpp @@ -26,10 +26,27 @@ int main(int argc, char *argv[]) { } std::cout << "Platform initialized.\n"; + uint32_t adapterCount = 0; + std::vector adapters; uint32_t platformCount = 0; std::vector platforms; - status = urPlatformGet(1, nullptr, &platformCount); + status = urAdapterGet(0, nullptr, &adapterCount); + if (status != UR_RESULT_SUCCESS) { + std::cout << "urAdapterGet failed with return code: " << status + << std::endl; + return 1; + } + adapters.resize(adapterCount); + status = urAdapterGet(adapterCount, adapters.data(), nullptr); + if (status != UR_RESULT_SUCCESS) { + std::cout << "urAdapterGet failed with return code: " << status + << std::endl; + return 1; + } + + status = urPlatformGet(adapters.data(), adapterCount, 1, nullptr, + &platformCount); if (status != UR_RESULT_SUCCESS) { std::cout << "urPlatformGet failed with return code: " << status << std::endl; @@ -37,7 +54,8 @@ int main(int argc, char *argv[]) { } platforms.resize(platformCount); - status = urPlatformGet(platformCount, platforms.data(), nullptr); + status = urPlatformGet(adapters.data(), adapterCount, platformCount, + platforms.data(), nullptr); if (status != UR_RESULT_SUCCESS) { std::cout << "urPlatformGet failed with return code: " << status << std::endl; @@ -98,6 +116,9 @@ int main(int argc, char *argv[]) { } out: + for (auto adapter : adapters) { + urAdapterRelease(adapter); + } urTearDown(nullptr); return status == UR_RESULT_SUCCESS ? 0 : 1; } diff --git a/include/ur.py b/include/ur.py index 50d2969fc8..770e1d68a2 100644 --- a/include/ur.py +++ b/include/ur.py @@ -165,7 +165,6 @@ class ur_function_v(IntEnum): BINDLESS_IMAGES_DESTROY_EXTERNAL_SEMAPHORE_EXP = 147## Enumerator for ::urBindlessImagesDestroyExternalSemaphoreExp BINDLESS_IMAGES_WAIT_EXTERNAL_SEMAPHORE_EXP = 148 ## Enumerator for ::urBindlessImagesWaitExternalSemaphoreExp BINDLESS_IMAGES_SIGNAL_EXTERNAL_SEMAPHORE_EXP = 149 ## Enumerator for ::urBindlessImagesSignalExternalSemaphoreExp - PLATFORM_GET_LAST_ERROR = 150 ## Enumerator for ::urPlatformGetLastError ENQUEUE_USM_FILL_2D = 151 ## Enumerator for ::urEnqueueUSMFill2D ENQUEUE_USM_MEMCPY_2D = 152 ## Enumerator for ::urEnqueueUSMMemcpy2D VIRTUAL_MEM_GRANULARITY_GET_INFO = 153 ## Enumerator for ::urVirtualMemGranularityGetInfo @@ -192,6 +191,11 @@ class ur_function_v(IntEnum): LOADER_CONFIG_RETAIN = 174 ## Enumerator for ::urLoaderConfigRetain LOADER_CONFIG_GET_INFO = 175 ## Enumerator for ::urLoaderConfigGetInfo LOADER_CONFIG_ENABLE_LAYER = 176 ## Enumerator for ::urLoaderConfigEnableLayer + ADAPTER_RELEASE = 177 ## Enumerator for ::urAdapterRelease + ADAPTER_GET = 178 ## Enumerator for ::urAdapterGet + ADAPTER_RETAIN = 179 ## Enumerator for ::urAdapterRetain + ADAPTER_GET_LAST_ERROR = 180 ## Enumerator for ::urAdapterGetLastError + ADAPTER_GET_INFO = 181 ## Enumerator for ::urAdapterGetInfo class ur_function_t(c_int): def __str__(self): @@ -288,6 +292,11 @@ class ur_bool_t(c_ubyte): class ur_loader_config_handle_t(c_void_p): pass +############################################################################### +## @brief Handle of an adapter instance +class ur_adapter_handle_t(c_void_p): + pass + ############################################################################### ## @brief Handle of a platform instance class ur_platform_handle_t(c_void_p): @@ -501,6 +510,36 @@ def __str__(self): return str(ur_loader_config_info_v(self.value)) +############################################################################### +## @brief Supported adapter info +class ur_adapter_info_v(IntEnum): + BACKEND = 0 ## [::ur_adapter_backend_t] Identifies the native backend supported by + ## the adapter. + REFERENCE_COUNT = 1 ## [uint32_t] Reference count of the adapter. + ## The reference count returned should be considered immediately stale. + ## It is unsuitable for general use in applications. This feature is + ## provided for identifying memory leaks. + +class ur_adapter_info_t(c_int): + def __str__(self): + return str(ur_adapter_info_v(self.value)) + + +############################################################################### +## @brief Identifies backend of the adapter +class ur_adapter_backend_v(IntEnum): + UNKNOWN = 0 ## The backend is not a recognized one + LEVEL_ZERO = 1 ## The backend is Level Zero + OPENCL = 2 ## The backend is OpenCL + CUDA = 3 ## The backend is CUDA + HIP = 4 ## The backend is HIP + NATIVE_CPU = 5 ## The backend is Native CPU + +class ur_adapter_backend_t(c_int): + def __str__(self): + return str(ur_adapter_backend_v(self.value)) + + ############################################################################### ## @brief Supported platform info class ur_platform_info_v(IntEnum): @@ -2273,9 +2312,9 @@ class ur_loader_config_dditable_t(Structure): ############################################################################### ## @brief Function-pointer for urPlatformGet if __use_win_types: - _urPlatformGet_t = WINFUNCTYPE( ur_result_t, c_ulong, POINTER(ur_platform_handle_t), POINTER(c_ulong) ) + _urPlatformGet_t = WINFUNCTYPE( ur_result_t, POINTER(ur_adapter_handle_t), c_ulong, c_ulong, POINTER(ur_platform_handle_t), POINTER(c_ulong) ) else: - _urPlatformGet_t = CFUNCTYPE( ur_result_t, c_ulong, POINTER(ur_platform_handle_t), POINTER(c_ulong) ) + _urPlatformGet_t = CFUNCTYPE( ur_result_t, POINTER(ur_adapter_handle_t), c_ulong, c_ulong, POINTER(ur_platform_handle_t), POINTER(c_ulong) ) ############################################################################### ## @brief Function-pointer for urPlatformGetInfo @@ -2298,13 +2337,6 @@ class ur_loader_config_dditable_t(Structure): else: _urPlatformCreateWithNativeHandle_t = CFUNCTYPE( ur_result_t, ur_native_handle_t, POINTER(ur_platform_native_properties_t), POINTER(ur_platform_handle_t) ) -############################################################################### -## @brief Function-pointer for urPlatformGetLastError -if __use_win_types: - _urPlatformGetLastError_t = WINFUNCTYPE( ur_result_t, ur_platform_handle_t, POINTER(c_char_p), POINTER(c_long) ) -else: - _urPlatformGetLastError_t = CFUNCTYPE( ur_result_t, ur_platform_handle_t, POINTER(c_char_p), POINTER(c_long) ) - ############################################################################### ## @brief Function-pointer for urPlatformGetApiVersion if __use_win_types: @@ -2328,7 +2360,6 @@ class ur_platform_dditable_t(Structure): ("pfnGetInfo", c_void_p), ## _urPlatformGetInfo_t ("pfnGetNativeHandle", c_void_p), ## _urPlatformGetNativeHandle_t ("pfnCreateWithNativeHandle", c_void_p), ## _urPlatformCreateWithNativeHandle_t - ("pfnGetLastError", c_void_p), ## _urPlatformGetLastError_t ("pfnGetApiVersion", c_void_p), ## _urPlatformGetApiVersion_t ("pfnGetBackendOption", c_void_p) ## _urPlatformGetBackendOption_t ] @@ -3565,13 +3596,53 @@ class ur_usm_p2p_exp_dditable_t(Structure): else: _urTearDown_t = CFUNCTYPE( ur_result_t, c_void_p ) +############################################################################### +## @brief Function-pointer for urAdapterGet +if __use_win_types: + _urAdapterGet_t = WINFUNCTYPE( ur_result_t, c_ulong, POINTER(ur_adapter_handle_t), POINTER(c_ulong) ) +else: + _urAdapterGet_t = CFUNCTYPE( ur_result_t, c_ulong, POINTER(ur_adapter_handle_t), POINTER(c_ulong) ) + +############################################################################### +## @brief Function-pointer for urAdapterRelease +if __use_win_types: + _urAdapterRelease_t = WINFUNCTYPE( ur_result_t, ur_adapter_handle_t ) +else: + _urAdapterRelease_t = CFUNCTYPE( ur_result_t, ur_adapter_handle_t ) + +############################################################################### +## @brief Function-pointer for urAdapterRetain +if __use_win_types: + _urAdapterRetain_t = WINFUNCTYPE( ur_result_t, ur_adapter_handle_t ) +else: + _urAdapterRetain_t = CFUNCTYPE( ur_result_t, ur_adapter_handle_t ) + +############################################################################### +## @brief Function-pointer for urAdapterGetLastError +if __use_win_types: + _urAdapterGetLastError_t = WINFUNCTYPE( ur_result_t, ur_adapter_handle_t, POINTER(c_char_p), POINTER(c_long) ) +else: + _urAdapterGetLastError_t = CFUNCTYPE( ur_result_t, ur_adapter_handle_t, POINTER(c_char_p), POINTER(c_long) ) + +############################################################################### +## @brief Function-pointer for urAdapterGetInfo +if __use_win_types: + _urAdapterGetInfo_t = WINFUNCTYPE( ur_result_t, ur_adapter_handle_t, ur_adapter_info_t, c_size_t, c_void_p, POINTER(c_size_t) ) +else: + _urAdapterGetInfo_t = CFUNCTYPE( ur_result_t, ur_adapter_handle_t, ur_adapter_info_t, c_size_t, c_void_p, POINTER(c_size_t) ) + ############################################################################### ## @brief Table of Global functions pointers class ur_global_dditable_t(Structure): _fields_ = [ ("pfnInit", c_void_p), ## _urInit_t - ("pfnTearDown", c_void_p) ## _urTearDown_t + ("pfnTearDown", c_void_p), ## _urTearDown_t + ("pfnAdapterGet", c_void_p), ## _urAdapterGet_t + ("pfnAdapterRelease", c_void_p), ## _urAdapterRelease_t + ("pfnAdapterRetain", c_void_p), ## _urAdapterRetain_t + ("pfnAdapterGetLastError", c_void_p), ## _urAdapterGetLastError_t + ("pfnAdapterGetInfo", c_void_p) ## _urAdapterGetInfo_t ] ############################################################################### @@ -3768,7 +3839,6 @@ def __init__(self, version : ur_api_version_t): self.urPlatformGetInfo = _urPlatformGetInfo_t(self.__dditable.Platform.pfnGetInfo) self.urPlatformGetNativeHandle = _urPlatformGetNativeHandle_t(self.__dditable.Platform.pfnGetNativeHandle) self.urPlatformCreateWithNativeHandle = _urPlatformCreateWithNativeHandle_t(self.__dditable.Platform.pfnCreateWithNativeHandle) - self.urPlatformGetLastError = _urPlatformGetLastError_t(self.__dditable.Platform.pfnGetLastError) self.urPlatformGetApiVersion = _urPlatformGetApiVersion_t(self.__dditable.Platform.pfnGetApiVersion) self.urPlatformGetBackendOption = _urPlatformGetBackendOption_t(self.__dditable.Platform.pfnGetBackendOption) @@ -4048,6 +4118,11 @@ def __init__(self, version : ur_api_version_t): # attach function interface to function address self.urInit = _urInit_t(self.__dditable.Global.pfnInit) self.urTearDown = _urTearDown_t(self.__dditable.Global.pfnTearDown) + self.urAdapterGet = _urAdapterGet_t(self.__dditable.Global.pfnAdapterGet) + self.urAdapterRelease = _urAdapterRelease_t(self.__dditable.Global.pfnAdapterRelease) + self.urAdapterRetain = _urAdapterRetain_t(self.__dditable.Global.pfnAdapterRetain) + self.urAdapterGetLastError = _urAdapterGetLastError_t(self.__dditable.Global.pfnAdapterGetLastError) + self.urAdapterGetInfo = _urAdapterGetInfo_t(self.__dditable.Global.pfnAdapterGetInfo) # call driver to get function pointers VirtualMem = ur_virtual_mem_dditable_t() diff --git a/include/ur_api.h b/include/ur_api.h index e80d850442..9460f43bd1 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -174,7 +174,6 @@ typedef enum ur_function_t { UR_FUNCTION_BINDLESS_IMAGES_DESTROY_EXTERNAL_SEMAPHORE_EXP = 147, ///< Enumerator for ::urBindlessImagesDestroyExternalSemaphoreExp UR_FUNCTION_BINDLESS_IMAGES_WAIT_EXTERNAL_SEMAPHORE_EXP = 148, ///< Enumerator for ::urBindlessImagesWaitExternalSemaphoreExp UR_FUNCTION_BINDLESS_IMAGES_SIGNAL_EXTERNAL_SEMAPHORE_EXP = 149, ///< Enumerator for ::urBindlessImagesSignalExternalSemaphoreExp - UR_FUNCTION_PLATFORM_GET_LAST_ERROR = 150, ///< Enumerator for ::urPlatformGetLastError UR_FUNCTION_ENQUEUE_USM_FILL_2D = 151, ///< Enumerator for ::urEnqueueUSMFill2D UR_FUNCTION_ENQUEUE_USM_MEMCPY_2D = 152, ///< Enumerator for ::urEnqueueUSMMemcpy2D UR_FUNCTION_VIRTUAL_MEM_GRANULARITY_GET_INFO = 153, ///< Enumerator for ::urVirtualMemGranularityGetInfo @@ -201,6 +200,11 @@ typedef enum ur_function_t { 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 + UR_FUNCTION_ADAPTER_RELEASE = 177, ///< Enumerator for ::urAdapterRelease + UR_FUNCTION_ADAPTER_GET = 178, ///< Enumerator for ::urAdapterGet + UR_FUNCTION_ADAPTER_RETAIN = 179, ///< Enumerator for ::urAdapterRetain + UR_FUNCTION_ADAPTER_GET_LAST_ERROR = 180, ///< Enumerator for ::urAdapterGetLastError + UR_FUNCTION_ADAPTER_GET_INFO = 181, ///< Enumerator for ::urAdapterGetInfo /// @cond UR_FUNCTION_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -327,6 +331,10 @@ 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 an adapter instance +typedef struct ur_adapter_handle_t_ *ur_adapter_handle_t; + /////////////////////////////////////////////////////////////////////////////// /// @brief Handle of a platform instance typedef struct ur_platform_handle_t_ *ur_platform_handle_t; @@ -707,6 +715,197 @@ urTearDown( void *pParams ///< [in] pointer to tear down parameters ); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves all available adapters +/// +/// @details +/// - Adapter implementations must return exactly one adapter handle from +/// this entry point. +/// - The loader may return more than one adapter handle when there are +/// multiple available. +/// - Each returned adapter has its reference count incremented and should +/// be released with a subsequent call to ::urAdapterRelease. +/// - Adapters may perform adapter-specific state initialization when the +/// first reference to them is taken. +/// - An application may call this entry point multiple times to acquire +/// multiple references to the adapter handle(s). +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_SIZE +UR_APIEXPORT ur_result_t UR_APICALL +urAdapterGet( + uint32_t NumEntries, ///< [in] the number of adapters to be added to phAdapters. + ///< If phAdapters is not NULL, then NumEntries should be greater than + ///< zero, otherwise ::UR_RESULT_ERROR_INVALID_SIZE, + ///< will be returned. + ur_adapter_handle_t *phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters. + ///< If NumEntries is less than the number of adapters available, then + ///< ::urAdapterGet shall only retrieve that number of platforms. + uint32_t *pNumAdapters ///< [out][optional] returns the total number of adapters available. +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Releases the adapter handle reference indicating end of its usage +/// +/// @details +/// - When the reference count of the adapter reaches zero, the adapter may +/// perform adapter-specififc resource teardown +/// +/// @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 == hAdapter` +UR_APIEXPORT ur_result_t UR_APICALL +urAdapterRelease( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to release +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Get a reference to the adapter handle. +/// +/// @details +/// - Get a reference to the adapter handle. Increment its reference count +/// +/// @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 == hAdapter` +UR_APIEXPORT ur_result_t UR_APICALL +urAdapterRetain( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to retain +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Get the last adapter specific error. +/// +/// @details +/// To be used after another entry-point has returned +/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC in order to retrieve a message describing +/// the circumstances of the underlying driver error and the error code +/// returned by the failed driver entry-point. +/// +/// * Implementations *must* store the message and error code in thread-local +/// storage prior to returning ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. +/// +/// * The message and error code storage is will only be valid if a previously +/// called entry-point returned ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. +/// +/// * The memory pointed to by the C string returned in `ppMessage` is owned by +/// the adapter and *must* be null terminated. +/// +/// * The application *may* call this function from simultaneous threads. +/// +/// * The implementation of this function *should* be lock-free. +/// +/// Example usage: +/// +/// ```cpp +/// if (::urQueueCreate(hContext, hDevice, nullptr, &hQueue) == +/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC) { +/// const char* pMessage; +/// int32_t error; +/// ::urAdapterGetLastError(hAdapter, &pMessage, &error); +/// } +/// ``` +/// +/// @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 == hAdapter` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMessage` +/// + `NULL == pError` +UR_APIEXPORT ur_result_t UR_APICALL +urAdapterGetLastError( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter instance + const char **ppMessage, ///< [out] pointer to a C string where the adapter specific error message + ///< will be stored. + int32_t *pError ///< [out] pointer to an integer where the adapter specific error code will + ///< be stored. +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Supported adapter info +typedef enum ur_adapter_info_t { + UR_ADAPTER_INFO_BACKEND = 0, ///< [::ur_adapter_backend_t] Identifies the native backend supported by + ///< the adapter. + UR_ADAPTER_INFO_REFERENCE_COUNT = 1, ///< [uint32_t] Reference count of the adapter. + ///< The reference count returned should be considered immediately stale. + ///< It is unsuitable for general use in applications. This feature is + ///< provided for identifying memory leaks. + /// @cond + UR_ADAPTER_INFO_FORCE_UINT32 = 0x7fffffff + /// @endcond + +} ur_adapter_info_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves information about the adapter +/// +/// @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 == hAdapter` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `::UR_ADAPTER_INFO_REFERENCE_COUNT < propName` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION +/// + If `propName` is not supported by the adapter. +/// - ::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_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +UR_APIEXPORT ur_result_t UR_APICALL +urAdapterGetInfo( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter + ur_adapter_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 Size is not equal to or greater to 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 number of bytes being queried by pPropValue. +); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Identifies backend of the adapter +typedef enum ur_adapter_backend_t { + UR_ADAPTER_BACKEND_UNKNOWN = 0, ///< The backend is not a recognized one + UR_ADAPTER_BACKEND_LEVEL_ZERO = 1, ///< The backend is Level Zero + UR_ADAPTER_BACKEND_OPENCL = 2, ///< The backend is OpenCL + UR_ADAPTER_BACKEND_CUDA = 3, ///< The backend is CUDA + UR_ADAPTER_BACKEND_HIP = 4, ///< The backend is HIP + UR_ADAPTER_BACKEND_NATIVE_CPU = 5, ///< The backend is Native CPU + /// @cond + UR_ADAPTER_BACKEND_FORCE_UINT32 = 0x7fffffff + /// @endcond + +} ur_adapter_backend_t; + #if !defined(__GNUC__) #pragma endregion #endif @@ -715,7 +914,7 @@ urTearDown( #pragma region platform #endif /////////////////////////////////////////////////////////////////////////////// -/// @brief Retrieves all available platforms +/// @brief Retrieves all available platforms for the given adapters /// /// @details /// - Multiple calls to this function will return identical platforms @@ -732,9 +931,13 @@ urTearDown( /// - ::UR_RESULT_ERROR_UNINITIALIZED /// - ::UR_RESULT_ERROR_DEVICE_LOST /// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == phAdapters` /// - ::UR_RESULT_ERROR_INVALID_SIZE UR_APIEXPORT ur_result_t UR_APICALL urPlatformGet( + ur_adapter_handle_t *phAdapters, ///< [in][range(0, NumAdapters)] array of adapters to query for platforms. + uint32_t NumAdapters, ///< [in] number of adapters pointed to by phAdapters uint32_t NumEntries, ///< [in] the number of platforms to be added to phPlatforms. ///< If phPlatforms is not NULL, then NumEntries should be greater than ///< zero, otherwise ::UR_RESULT_ERROR_INVALID_SIZE, @@ -942,58 +1145,6 @@ urPlatformGetBackendOption( ///< the frontend option. ); -/////////////////////////////////////////////////////////////////////////////// -/// @brief Get the last adapter specific error. -/// -/// @details -/// To be used after another entry-point has returned -/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC in order to retrieve a message describing -/// the circumstances of the underlying driver error and the error code -/// returned by the failed driver entry-point. -/// -/// * Implementations *must* store the message and error code in thread-local -/// storage prior to returning ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. -/// -/// * The message and error code storage is will only be valid if a previously -/// called entry-point returned ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. -/// -/// * The memory pointed to by the C string returned in `ppMessage` is owned by -/// the adapter and *must* be null terminated. -/// -/// * The application *may* call this function from simultaneous threads. -/// -/// * The implementation of this function *should* be lock-free. -/// -/// Example usage: -/// -/// ```cpp -/// if (::urQueueCreate(hContext, hDevice, nullptr, &hQueue) == -/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC) { -/// const char* pMessage; -/// int32_t error; -/// ::urPlatformGetLastError(hPlatform, &pMessage, &error); -/// } -/// ``` -/// -/// @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 == hPlatform` -/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER -/// + `NULL == ppMessage` -/// + `NULL == pError` -UR_APIEXPORT ur_result_t UR_APICALL -urPlatformGetLastError( - ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance - const char **ppMessage, ///< [out] pointer to a C string where the adapter specific error message - ///< will be stored. - int32_t *pError ///< [out] pointer to an integer where the adapter specific error code will - ///< be stored. -); - /////////////////////////////////////////////////////////////////////////////// /// @brief Identifies native backend adapters typedef enum ur_platform_backend_t { @@ -8093,6 +8244,8 @@ typedef struct ur_loader_config_enable_layer_params_t { /// @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_platform_get_params_t { + ur_adapter_handle_t **pphAdapters; + uint32_t *pNumAdapters; uint32_t *pNumEntries; ur_platform_handle_t **pphPlatforms; uint32_t **ppNumPlatforms; @@ -8129,16 +8282,6 @@ typedef struct ur_platform_create_with_native_handle_params_t { ur_platform_handle_t **pphPlatform; } ur_platform_create_with_native_handle_params_t; -/////////////////////////////////////////////////////////////////////////////// -/// @brief Function parameters for urPlatformGetLastError -/// @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_platform_get_last_error_params_t { - ur_platform_handle_t *phPlatform; - const char ***pppMessage; - int32_t **ppError; -} ur_platform_get_last_error_params_t; - /////////////////////////////////////////////////////////////////////////////// /// @brief Function parameters for urPlatformGetApiVersion /// @details Each entry is a pointer to the parameter passed to the function; @@ -9854,6 +9997,54 @@ typedef struct ur_tear_down_params_t { void **ppParams; } ur_tear_down_params_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urAdapterGet +/// @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_adapter_get_params_t { + uint32_t *pNumEntries; + ur_adapter_handle_t **pphAdapters; + uint32_t **ppNumAdapters; +} ur_adapter_get_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urAdapterRelease +/// @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_adapter_release_params_t { + ur_adapter_handle_t *phAdapter; +} ur_adapter_release_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urAdapterRetain +/// @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_adapter_retain_params_t { + ur_adapter_handle_t *phAdapter; +} ur_adapter_retain_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urAdapterGetLastError +/// @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_adapter_get_last_error_params_t { + ur_adapter_handle_t *phAdapter; + const char ***pppMessage; + int32_t **ppError; +} ur_adapter_get_last_error_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urAdapterGetInfo +/// @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_adapter_get_info_params_t { + ur_adapter_handle_t *phAdapter; + ur_adapter_info_t *ppropName; + size_t *ppropSize; + void **ppPropValue; + size_t **ppPropSizeRet; +} ur_adapter_get_info_params_t; + /////////////////////////////////////////////////////////////////////////////// /// @brief Function parameters for urVirtualMemGranularityGetInfo /// @details Each entry is a pointer to the parameter passed to the function; diff --git a/include/ur_ddi.h b/include/ur_ddi.h index cdf161412d..958f5ca29b 100644 --- a/include/ur_ddi.h +++ b/include/ur_ddi.h @@ -24,6 +24,8 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////// /// @brief Function-pointer for urPlatformGet typedef ur_result_t(UR_APICALL *ur_pfnPlatformGet_t)( + ur_adapter_handle_t *, + uint32_t, uint32_t, ur_platform_handle_t *, uint32_t *); @@ -50,13 +52,6 @@ typedef ur_result_t(UR_APICALL *ur_pfnPlatformCreateWithNativeHandle_t)( const ur_platform_native_properties_t *, ur_platform_handle_t *); -/////////////////////////////////////////////////////////////////////////////// -/// @brief Function-pointer for urPlatformGetLastError -typedef ur_result_t(UR_APICALL *ur_pfnPlatformGetLastError_t)( - ur_platform_handle_t, - const char **, - int32_t *); - /////////////////////////////////////////////////////////////////////////////// /// @brief Function-pointer for urPlatformGetApiVersion typedef ur_result_t(UR_APICALL *ur_pfnPlatformGetApiVersion_t)( @@ -77,7 +72,6 @@ typedef struct ur_platform_dditable_t { ur_pfnPlatformGetInfo_t pfnGetInfo; ur_pfnPlatformGetNativeHandle_t pfnGetNativeHandle; ur_pfnPlatformCreateWithNativeHandle_t pfnCreateWithNativeHandle; - ur_pfnPlatformGetLastError_t pfnGetLastError; ur_pfnPlatformGetApiVersion_t pfnGetApiVersion; ur_pfnPlatformGetBackendOption_t pfnGetBackendOption; } ur_platform_dditable_t; @@ -1877,11 +1871,49 @@ typedef ur_result_t(UR_APICALL *ur_pfnInit_t)( typedef ur_result_t(UR_APICALL *ur_pfnTearDown_t)( void *); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urAdapterGet +typedef ur_result_t(UR_APICALL *ur_pfnAdapterGet_t)( + uint32_t, + ur_adapter_handle_t *, + uint32_t *); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urAdapterRelease +typedef ur_result_t(UR_APICALL *ur_pfnAdapterRelease_t)( + ur_adapter_handle_t); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urAdapterRetain +typedef ur_result_t(UR_APICALL *ur_pfnAdapterRetain_t)( + ur_adapter_handle_t); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urAdapterGetLastError +typedef ur_result_t(UR_APICALL *ur_pfnAdapterGetLastError_t)( + ur_adapter_handle_t, + const char **, + int32_t *); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urAdapterGetInfo +typedef ur_result_t(UR_APICALL *ur_pfnAdapterGetInfo_t)( + ur_adapter_handle_t, + ur_adapter_info_t, + size_t, + void *, + size_t *); + /////////////////////////////////////////////////////////////////////////////// /// @brief Table of Global functions pointers typedef struct ur_global_dditable_t { ur_pfnInit_t pfnInit; ur_pfnTearDown_t pfnTearDown; + ur_pfnAdapterGet_t pfnAdapterGet; + ur_pfnAdapterRelease_t pfnAdapterRelease; + ur_pfnAdapterRetain_t pfnAdapterRetain; + ur_pfnAdapterGetLastError_t pfnAdapterGetLastError; + ur_pfnAdapterGetInfo_t pfnAdapterGetInfo; } ur_global_dditable_t; /////////////////////////////////////////////////////////////////////////////// diff --git a/scripts/core/PROG.rst b/scripts/core/PROG.rst index 9c97823be1..e7bf24986b 100644 --- a/scripts/core/PROG.rst +++ b/scripts/core/PROG.rst @@ -51,12 +51,18 @@ Initialization and Discovery .. parsed-literal:: + // Discover all available adapters + uint32_t adapterCount = 0; + ${x}AdapterGet(0, nullptr, &adapterCount); + std::vector<${x}_adapter_handle_t> adapters(adapterCount); + ${x}AdapterGet(adapterCount, adapters.data(), nullptr); + // Discover all the platform instances uint32_t platformCount = 0; - ${x}PlatformGet(0, nullptr, &platformCount); + ${x}PlatformGet(adapters.data(), adapterCount, 0, nullptr, &platformCount); std::vector<${x}_platform_handle_t> platforms(platformCount); - ${x}PlatformGet(platform.size(), platforms.data(), &platformCount); + ${x}PlatformGet(adapters.data(), adapterCount, platform.size(), platforms.data(), &platformCount); // Get number of total GPU devices in the platform uint32_t deviceCount = 0; diff --git a/scripts/core/common.yml b/scripts/core/common.yml index ed29a1be99..7a522ada35 100644 --- a/scripts/core/common.yml +++ b/scripts/core/common.yml @@ -65,6 +65,11 @@ class: $xLoaderConfig name: "$x_loader_config_handle_t" --- #-------------------------------------------------------------------------- type: handle +desc: "Handle of an adapter instance" +class: $xAdapter +name: "$x_adapter_handle_t" +--- #-------------------------------------------------------------------------- +type: handle desc: "Handle of a platform instance" class: $xPlatform name: "$x_platform_handle_t" diff --git a/scripts/core/platform.yml b/scripts/core/platform.yml index 7188044848..c0c235c354 100644 --- a/scripts/core/platform.yml +++ b/scripts/core/platform.yml @@ -13,7 +13,7 @@ desc: "Intel $OneApi Unified Runtime APIs for Platform" ordinal: "1" --- #-------------------------------------------------------------------------- type: function -desc: "Retrieves all available platforms" +desc: "Retrieves all available platforms for the given adapters" class: $xPlatform name: Get decl: static @@ -24,6 +24,12 @@ details: - "Multiple calls to this function will return identical platforms handles, in the same order." - "The application may call this function from simultaneous threads, the implementation must be thread-safe" params: + - type: "$x_adapter_handle_t*" + name: "phAdapters" + desc: "[in][range(0, NumAdapters)] array of adapters to query for platforms." + - type: "uint32_t" + name: "NumAdapters" + desc: "[in] number of adapters pointed to by phAdapters" - type: "uint32_t" name: NumEntries desc: | @@ -221,56 +227,6 @@ returns: - $X_RESULT_ERROR_INVALID_VALUE: - "If `pFrontendOption` is not a valid frontend option." --- #-------------------------------------------------------------------------- -type: function -desc: "Get the last adapter specific error." -details: | - To be used after another entry-point has returned - $X_RESULT_ERROR_ADAPTER_SPECIFIC in order to retrieve a message describing - the circumstances of the underlying driver error and the error code - returned by the failed driver entry-point. - - * Implementations *must* store the message and error code in thread-local - storage prior to returning $X_RESULT_ERROR_ADAPTER_SPECIFIC. - - * The message and error code storage is will only be valid if a previously - called entry-point returned $X_RESULT_ERROR_ADAPTER_SPECIFIC. - - * The memory pointed to by the C string returned in `ppMessage` is owned by - the adapter and *must* be null terminated. - - * The application *may* call this function from simultaneous threads. - - * The implementation of this function *should* be lock-free. - - Example usage: - - ```cpp - if ($xQueueCreate(hContext, hDevice, nullptr, &hQueue) == - $X_RESULT_ERROR_ADAPTER_SPECIFIC) { - const char* pMessage; - int32_t error; - $xPlatformGetLastError(hPlatform, &pMessage, &error); - } - ``` -class: $xPlatform -name: GetLastError -decl: static -ordinal: "0" -params: - - type: $x_platform_handle_t - name: hPlatform - desc: "[in] handle of the platform instance" - - type: const char** - name: ppMessage - desc: > - [out] pointer to a C string where the adapter specific error message - will be stored. - - type: int32_t* - name: pError - desc: > - [out] pointer to an integer where the adapter specific error code - will be stored. ---- #-------------------------------------------------------------------------- type: enum desc: "Identifies native backend adapters" class: $xPlatform diff --git a/scripts/core/registry.yml b/scripts/core/registry.yml index f0d198b668..30596ec14e 100644 --- a/scripts/core/registry.yml +++ b/scripts/core/registry.yml @@ -436,9 +436,6 @@ etors: - name: BINDLESS_IMAGES_SIGNAL_EXTERNAL_SEMAPHORE_EXP desc: Enumerator for $xBindlessImagesSignalExternalSemaphoreExp value: '149' -- name: PLATFORM_GET_LAST_ERROR - desc: Enumerator for $xPlatformGetLastError - value: '150' - name: ENQUEUE_USM_FILL_2D desc: Enumerator for $xEnqueueUSMFill2D value: '151' @@ -517,6 +514,21 @@ etors: - name: LOADER_CONFIG_ENABLE_LAYER desc: Enumerator for $xLoaderConfigEnableLayer value: '176' +- name: ADAPTER_RELEASE + desc: Enumerator for $xAdapterRelease + value: '177' +- name: ADAPTER_GET + desc: Enumerator for $xAdapterGet + value: '178' +- name: ADAPTER_RETAIN + desc: Enumerator for $xAdapterRetain + value: '179' +- name: ADAPTER_GET_LAST_ERROR + desc: Enumerator for $xAdapterGetLastError + value: '180' +- name: ADAPTER_GET_INFO + desc: Enumerator for $xAdapterGetInfo + value: '181' --- type: enum desc: Defines structure types diff --git a/scripts/core/runtime.yml b/scripts/core/runtime.yml index b5bbd9987c..06010a643c 100644 --- a/scripts/core/runtime.yml +++ b/scripts/core/runtime.yml @@ -174,3 +174,191 @@ params: desc: "[in] pointer to tear down parameters" returns: - $X_RESULT_ERROR_OUT_OF_HOST_MEMORY +--- #-------------------------------------------------------------------------- +type: function +desc: "Retrieves all available adapters" +class: $x +name: AdapterGet +decl: static +ordinal: "2" +details: + - "Adapter implementations must return exactly one adapter handle from this entry point." + - "The loader may return more than one adapter handle when there are multiple available." + - "Each returned adapter has its reference count incremented and should be released with a subsequent call to $xAdapterRelease." + - "Adapters may perform adapter-specific state initialization when the first reference to them is taken." + - "An application may call this entry point multiple times to acquire multiple references to the adapter handle(s)." +params: + - type: "uint32_t" + name: NumEntries + desc: | + [in] the number of adapters to be added to phAdapters. + If phAdapters is not NULL, then NumEntries should be greater than zero, otherwise $X_RESULT_ERROR_INVALID_SIZE, + will be returned. + - type: "$x_adapter_handle_t*" + name: phAdapters + desc: | + [out][optional][range(0, NumEntries)] array of handle of adapters. + If NumEntries is less than the number of adapters available, then $xAdapterGet shall only retrieve that number of platforms. + - type: "uint32_t*" + name: "pNumAdapters" + desc: | + [out][optional] returns the total number of adapters available. +returns: + - $X_RESULT_ERROR_INVALID_SIZE +--- #-------------------------------------------------------------------------- +type: function +desc: "Releases the adapter handle reference indicating end of its usage" +class: $x +name: AdapterRelease +decl: static +ordinal: "3" +details: + - "When the reference count of the adapter reaches zero, the adapter may perform adapter-specififc resource teardown" +params: + - type: "$x_adapter_handle_t" + name: hAdapter + desc: | + [in] Adapter handle to release +--- #-------------------------------------------------------------------------- +type: function +desc: "Get a reference to the adapter handle." +class: $x +name: AdapterRetain +decl: static +ordinal: "4" +details: + - "Get a reference to the adapter handle. Increment its reference count" +params: + - type: "$x_adapter_handle_t" + name: hAdapter + desc: | + [in] Adapter handle to retain +--- #-------------------------------------------------------------------------- +type: function +desc: "Get the last adapter specific error." +details: | + To be used after another entry-point has returned + $X_RESULT_ERROR_ADAPTER_SPECIFIC in order to retrieve a message describing + the circumstances of the underlying driver error and the error code + returned by the failed driver entry-point. + + * Implementations *must* store the message and error code in thread-local + storage prior to returning $X_RESULT_ERROR_ADAPTER_SPECIFIC. + + * The message and error code storage is will only be valid if a previously + called entry-point returned $X_RESULT_ERROR_ADAPTER_SPECIFIC. + + * The memory pointed to by the C string returned in `ppMessage` is owned by + the adapter and *must* be null terminated. + + * The application *may* call this function from simultaneous threads. + + * The implementation of this function *should* be lock-free. + + Example usage: + + ```cpp + if ($xQueueCreate(hContext, hDevice, nullptr, &hQueue) == + $X_RESULT_ERROR_ADAPTER_SPECIFIC) { + const char* pMessage; + int32_t error; + $xAdapterGetLastError(hAdapter, &pMessage, &error); + } + ``` +class: $x +name: AdapterGetLastError +decl: static +ordinal: "5" +params: + - type: $x_adapter_handle_t + name: hAdapter + desc: "[in] handle of the adapter instance" + - type: const char** + name: ppMessage + desc: > + [out] pointer to a C string where the adapter specific error message + will be stored. + - type: int32_t* + name: pError + desc: > + [out] pointer to an integer where the adapter specific error code + will be stored. +--- #-------------------------------------------------------------------------- +type: enum +desc: "Supported adapter info" +class: $xAdapter +name: $x_adapter_info_t +typed_etors: True +etors: + - name: BACKEND + desc: "[$x_adapter_backend_t] Identifies the native backend supported by the adapter." + - name: REFERENCE_COUNT + desc: | + [uint32_t] Reference count of the adapter. + The reference count returned should be considered immediately stale. + It is unsuitable for general use in applications. This feature is provided for identifying memory leaks. +--- #-------------------------------------------------------------------------- +type: function +desc: "Retrieves information about the adapter" +class: $x +name: AdapterGetInfo +decl: static +ordinal: "6" +details: + - "The application may call this function from simultaneous threads." + - "The implementation of this function should be lock-free." +params: + - type: $x_adapter_handle_t + name: hAdapter + desc: "[in] handle of the adapter" + - type: $x_adapter_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 Size is not equal to or greater to 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 number of bytes being queried by pPropValue. +returns: + - $X_RESULT_ERROR_UNSUPPORTED_ENUMERATION: + - "If `propName` is not supported by the adapter." + - $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_OUT_OF_RESOURCES + - $X_RESULT_ERROR_OUT_OF_HOST_MEMORY +--- #-------------------------------------------------------------------------- +type: enum +desc: "Identifies backend of the adapter" +class: $x +name: $x_adapter_backend_t +etors: + - name: UNKNOWN + value: "0" + desc: "The backend is not a recognized one" + - name: LEVEL_ZERO + value: "1" + desc: "The backend is Level Zero" + - name: OPENCL + value: "2" + desc: "The backend is OpenCL" + - name: CUDA + value: "3" + desc: "The backend is CUDA" + - name: HIP + value: "4" + desc: "The backend is HIP" + - name: NATIVE_CPU + value: "5" + desc: "The backend is Native CPU" diff --git a/scripts/templates/ldrddi.cpp.mako b/scripts/templates/ldrddi.cpp.mako index 76ba506b64..bb15dc97c7 100644 --- a/scripts/templates/ldrddi.cpp.mako +++ b/scripts/templates/ldrddi.cpp.mako @@ -66,36 +66,65 @@ namespace ur_loader platform.dditable.${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} ); } + %elif re.match(r"\w+AdapterGet$", th.make_func_name(n, tags, obj)): + + size_t adapterIndex = 0; + if( nullptr != ${obj['params'][1]['name']} && ${obj['params'][0]['name']} !=0) + { + for( auto& platform : context->platforms ) + { + platform.dditable.${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}( 1, &${obj['params'][1]['name']}[adapterIndex], nullptr ); + try + { + ${obj['params'][1]['name']}[adapterIndex] = reinterpret_cast<${n}_adapter_handle_t>(${n}_adapter_factory.getInstance( + ${obj['params'][1]['name']}[adapterIndex], &platform.dditable + )); + } + catch( std::bad_alloc &) + { + result = ${X}_RESULT_ERROR_OUT_OF_HOST_MEMORY; + break; + } + adapterIndex++; + } + } + + if( ${obj['params'][2]['name']} != nullptr ) + { + *${obj['params'][2]['name']} = static_cast(context->platforms.size()); + } + %elif re.match(r"\w+PlatformGet$", th.make_func_name(n, tags, obj)): uint32_t total_platform_handle_count = 0; - for( auto& platform : context->platforms ) + for( uint32_t adapter_index = 0; adapter_index < ${obj['params'][1]['name']}; adapter_index++) { - if(platform.initStatus != ${X}_RESULT_SUCCESS) - continue; + // extract adapter's function pointer table + auto dditable = + reinterpret_cast<${n}_platform_object_t *>( ${obj['params'][0]['name']}[adapter_index])->dditable; - if( ( 0 < ${obj['params'][0]['name']} ) && ( ${obj['params'][0]['name']} == total_platform_handle_count)) + if( ( 0 < ${obj['params'][2]['name']} ) && ( ${obj['params'][2]['name']} == total_platform_handle_count)) break; uint32_t library_platform_handle_count = 0; - result = platform.dditable.${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}( 0, nullptr, &library_platform_handle_count ); + result = dditable->${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}( &${obj['params'][0]['name']}[adapter_index], 1, 0, nullptr, &library_platform_handle_count ); if( ${X}_RESULT_SUCCESS != result ) break; - if( nullptr != ${obj['params'][1]['name']} && ${obj['params'][0]['name']} !=0) + if( nullptr != ${obj['params'][3]['name']} && ${obj['params'][2]['name']} !=0) { - if( total_platform_handle_count + library_platform_handle_count > ${obj['params'][0]['name']}) { - library_platform_handle_count = ${obj['params'][0]['name']} - total_platform_handle_count; + if( total_platform_handle_count + library_platform_handle_count > ${obj['params'][2]['name']}) { + library_platform_handle_count = ${obj['params'][2]['name']} - total_platform_handle_count; } - result = platform.dditable.${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}( library_platform_handle_count, &${obj['params'][1]['name']}[ total_platform_handle_count ], nullptr ); + result = dditable->${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}( &${obj['params'][0]['name']}[adapter_index], 1, library_platform_handle_count, &${obj['params'][3]['name']}[ total_platform_handle_count ], nullptr ); if( ${X}_RESULT_SUCCESS != result ) break; try { for( uint32_t i = 0; i < library_platform_handle_count; ++i ) { uint32_t platform_index = total_platform_handle_count + i; - ${obj['params'][1]['name']}[ platform_index ] = reinterpret_cast<${n}_platform_handle_t>( - ${n}_platform_factory.getInstance( ${obj['params'][1]['name']}[ platform_index ], &platform.dditable ) ); + ${obj['params'][3]['name']}[ platform_index ] = reinterpret_cast<${n}_platform_handle_t>( + ${n}_platform_factory.getInstance( ${obj['params'][3]['name']}[ platform_index ], dditable ) ); } } catch( std::bad_alloc& ) @@ -107,8 +136,8 @@ namespace ur_loader total_platform_handle_count += library_platform_handle_count; } - if( ${X}_RESULT_SUCCESS == result && ${obj['params'][2]['name']} != nullptr ) - *${obj['params'][2]['name']} = total_platform_handle_count; + if( ${X}_RESULT_SUCCESS == result && ${obj['params'][4]['name']} != nullptr ) + *${obj['params'][4]['name']} = total_platform_handle_count; %else: <%param_replacements={}%> diff --git a/source/adapters/null/ur_null.cpp b/source/adapters/null/ur_null.cpp index 5653ca57db..18c8d89ef5 100644 --- a/source/adapters/null/ur_null.cpp +++ b/source/adapters/null/ur_null.cpp @@ -18,7 +18,28 @@ context_t d_context; ////////////////////////////////////////////////////////////////////////// context_t::context_t() { ////////////////////////////////////////////////////////////////////////// - urDdiTable.Platform.pfnGet = [](uint32_t NumEntries, + urDdiTable.Global.pfnAdapterGet = [](uint32_t NumAdapters, + ur_adapter_handle_t *phAdapters, + uint32_t *pNumAdapters) { + if (phAdapters != nullptr && NumAdapters != 1) { + return UR_RESULT_ERROR_INVALID_SIZE; + } + if (pNumAdapters != nullptr) { + *pNumAdapters = 1; + } + if (nullptr != phAdapters) { + *reinterpret_cast(phAdapters) = d_context.get(); + } + + return UR_RESULT_SUCCESS; + }; + ////////////////////////////////////////////////////////////////////////// + urDdiTable.Global.pfnAdapterRelease = [](ur_adapter_handle_t) { + return UR_RESULT_SUCCESS; + }; + ////////////////////////////////////////////////////////////////////////// + urDdiTable.Platform.pfnGet = [](ur_adapter_handle_t *phAdapters, + uint32_t NumAdapters, uint32_t NumEntries, ur_platform_handle_t *phPlatforms, uint32_t *pNumPlatforms) { if (phPlatforms != nullptr && NumEntries != 1) { diff --git a/source/adapters/null/ur_nullddi.cpp b/source/adapters/null/ur_nullddi.cpp index b26735876b..f9b8fb4d11 100644 --- a/source/adapters/null/ur_nullddi.cpp +++ b/source/adapters/null/ur_nullddi.cpp @@ -55,9 +55,144 @@ __urdlllocal ur_result_t UR_APICALL urTearDown( return exceptionToResult(std::current_exception()); } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGet +__urdlllocal ur_result_t UR_APICALL urAdapterGet( + uint32_t + NumEntries, ///< [in] the number of adapters to be added to phAdapters. + ///< If phAdapters is not NULL, then NumEntries should be greater than + ///< zero, otherwise ::UR_RESULT_ERROR_INVALID_SIZE, + ///< will be returned. + ur_adapter_handle_t * + phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters. + ///< If NumEntries is less than the number of adapters available, then + ///< ::urAdapterGet shall only retrieve that number of platforms. + uint32_t * + pNumAdapters ///< [out][optional] returns the total number of adapters available. + ) 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 pfnAdapterGet = d_context.urDdiTable.Global.pfnAdapterGet; + if (nullptr != pfnAdapterGet) { + result = pfnAdapterGet(NumEntries, phAdapters, pNumAdapters); + } else { + // generic implementation + for (size_t i = 0; (nullptr != phAdapters) && (i < NumEntries); ++i) { + phAdapters[i] = + reinterpret_cast(d_context.get()); + } + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterRelease +__urdlllocal ur_result_t UR_APICALL urAdapterRelease( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to release + ) 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 pfnAdapterRelease = d_context.urDdiTable.Global.pfnAdapterRelease; + if (nullptr != pfnAdapterRelease) { + result = pfnAdapterRelease(hAdapter); + } else { + // generic implementation + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterRetain +__urdlllocal ur_result_t UR_APICALL urAdapterRetain( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to retain + ) 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 pfnAdapterRetain = d_context.urDdiTable.Global.pfnAdapterRetain; + if (nullptr != pfnAdapterRetain) { + result = pfnAdapterRetain(hAdapter); + } else { + // generic implementation + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGetLastError +__urdlllocal ur_result_t UR_APICALL urAdapterGetLastError( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter instance + const char ** + ppMessage, ///< [out] pointer to a C string where the adapter specific error message + ///< will be stored. + int32_t * + pError ///< [out] pointer to an integer where the adapter specific error code will + ///< be stored. + ) 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 pfnAdapterGetLastError = + d_context.urDdiTable.Global.pfnAdapterGetLastError; + if (nullptr != pfnAdapterGetLastError) { + result = pfnAdapterGetLastError(hAdapter, ppMessage, pError); + } else { + // generic implementation + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGetInfo +__urdlllocal ur_result_t UR_APICALL urAdapterGetInfo( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter + ur_adapter_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 Size is not equal to or greater to 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 number of bytes being queried by pPropValue. + ) 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 pfnAdapterGetInfo = d_context.urDdiTable.Global.pfnAdapterGetInfo; + if (nullptr != pfnAdapterGetInfo) { + result = pfnAdapterGetInfo(hAdapter, propName, propSize, pPropValue, + pPropSizeRet); + } else { + // generic implementation + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urPlatformGet __urdlllocal ur_result_t UR_APICALL urPlatformGet( + ur_adapter_handle_t * + phAdapters, ///< [in][range(0, NumAdapters)] array of adapters to query for platforms. + uint32_t NumAdapters, ///< [in] number of adapters pointed to by phAdapters uint32_t NumEntries, ///< [in] the number of platforms to be added to phPlatforms. ///< If phPlatforms is not NULL, then NumEntries should be greater than @@ -75,7 +210,8 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGet( // if the driver has created a custom function, then call it instead of using the generic path auto pfnGet = d_context.urDdiTable.Platform.pfnGet; if (nullptr != pfnGet) { - result = pfnGet(NumEntries, phPlatforms, pNumPlatforms); + result = pfnGet(phAdapters, NumAdapters, NumEntries, phPlatforms, + pNumPlatforms); } else { // generic implementation for (size_t i = 0; (nullptr != phPlatforms) && (i < NumEntries); ++i) { @@ -220,32 +356,6 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGetBackendOption( return exceptionToResult(std::current_exception()); } -/////////////////////////////////////////////////////////////////////////////// -/// @brief Intercept function for urPlatformGetLastError -__urdlllocal ur_result_t UR_APICALL urPlatformGetLastError( - ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance - const char ** - ppMessage, ///< [out] pointer to a C string where the adapter specific error message - ///< will be stored. - int32_t * - pError ///< [out] pointer to an integer where the adapter specific error code will - ///< be stored. - ) 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 pfnGetLastError = d_context.urDdiTable.Platform.pfnGetLastError; - if (nullptr != pfnGetLastError) { - result = pfnGetLastError(hPlatform, ppMessage, pError); - } else { - // generic implementation - } - - return result; -} catch (...) { - return exceptionToResult(std::current_exception()); -} - /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urDeviceGet __urdlllocal ur_result_t UR_APICALL urDeviceGet( @@ -4946,6 +5056,16 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetGlobalProcAddrTable( pDdiTable->pfnTearDown = driver::urTearDown; + pDdiTable->pfnAdapterGet = driver::urAdapterGet; + + pDdiTable->pfnAdapterRelease = driver::urAdapterRelease; + + pDdiTable->pfnAdapterRetain = driver::urAdapterRetain; + + pDdiTable->pfnAdapterGetLastError = driver::urAdapterGetLastError; + + pDdiTable->pfnAdapterGetInfo = driver::urAdapterGetInfo; + return result; } catch (...) { return exceptionToResult(std::current_exception()); @@ -5429,8 +5549,6 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetPlatformProcAddrTable( pDdiTable->pfnCreateWithNativeHandle = driver::urPlatformCreateWithNativeHandle; - pDdiTable->pfnGetLastError = driver::urPlatformGetLastError; - pDdiTable->pfnGetApiVersion = driver::urPlatformGetApiVersion; pDdiTable->pfnGetBackendOption = driver::urPlatformGetBackendOption; diff --git a/source/common/ur_params.hpp b/source/common/ur_params.hpp index d84bc617fa..8278d36e04 100644 --- a/source/common/ur_params.hpp +++ b/source/common/ur_params.hpp @@ -30,6 +30,10 @@ template <> inline void serializeFlag(std::ostream &os, uint32_t flag); +template <> +inline void serializeTagged(std::ostream &os, const void *ptr, + ur_adapter_info_t value, size_t size); + template <> inline void serializeTagged(std::ostream &os, const void *ptr, ur_platform_info_t value, size_t size); @@ -203,6 +207,9 @@ inline std::ostream &operator<<(std::ostream &os, const struct ur_rect_region_t params); inline std::ostream &operator<<(std::ostream &os, enum ur_device_init_flag_t value); +inline std::ostream &operator<<(std::ostream &os, enum ur_adapter_info_t value); +inline std::ostream &operator<<(std::ostream &os, + enum ur_adapter_backend_t value); inline std::ostream &operator<<(std::ostream &os, enum ur_platform_info_t value); inline std::ostream &operator<<(std::ostream &os, enum ur_api_version_t value); @@ -982,10 +989,6 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) { os << "UR_FUNCTION_BINDLESS_IMAGES_SIGNAL_EXTERNAL_SEMAPHORE_EXP"; break; - case UR_FUNCTION_PLATFORM_GET_LAST_ERROR: - os << "UR_FUNCTION_PLATFORM_GET_LAST_ERROR"; - break; - case UR_FUNCTION_ENQUEUE_USM_FILL_2D: os << "UR_FUNCTION_ENQUEUE_USM_FILL_2D"; break; @@ -1089,6 +1092,26 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) { case UR_FUNCTION_LOADER_CONFIG_ENABLE_LAYER: os << "UR_FUNCTION_LOADER_CONFIG_ENABLE_LAYER"; break; + + case UR_FUNCTION_ADAPTER_RELEASE: + os << "UR_FUNCTION_ADAPTER_RELEASE"; + break; + + case UR_FUNCTION_ADAPTER_GET: + os << "UR_FUNCTION_ADAPTER_GET"; + break; + + case UR_FUNCTION_ADAPTER_RETAIN: + os << "UR_FUNCTION_ADAPTER_RETAIN"; + break; + + case UR_FUNCTION_ADAPTER_GET_LAST_ERROR: + os << "UR_FUNCTION_ADAPTER_GET_LAST_ERROR"; + break; + + case UR_FUNCTION_ADAPTER_GET_INFO: + os << "UR_FUNCTION_ADAPTER_GET_INFO"; + break; default: os << "unknown enumerator"; break; @@ -1983,6 +2006,100 @@ inline void serializeFlag(std::ostream &os, } } } // namespace ur_params +inline std::ostream &operator<<(std::ostream &os, + enum ur_adapter_info_t value) { + switch (value) { + + case UR_ADAPTER_INFO_BACKEND: + os << "UR_ADAPTER_INFO_BACKEND"; + break; + + case UR_ADAPTER_INFO_REFERENCE_COUNT: + os << "UR_ADAPTER_INFO_REFERENCE_COUNT"; + break; + default: + os << "unknown enumerator"; + break; + } + return os; +} +namespace ur_params { +template <> +inline void serializeTagged(std::ostream &os, const void *ptr, + ur_adapter_info_t value, size_t size) { + if (ptr == NULL) { + serializePtr(os, ptr); + return; + } + + switch (value) { + + case UR_ADAPTER_INFO_BACKEND: { + const ur_adapter_backend_t *tptr = (const ur_adapter_backend_t *)ptr; + if (sizeof(ur_adapter_backend_t) > size) { + os << "invalid size (is: " << size + << ", expected: >=" << sizeof(ur_adapter_backend_t) << ")"; + return; + } + os << (void *)(tptr) << " ("; + + os << *tptr; + + os << ")"; + } break; + + case UR_ADAPTER_INFO_REFERENCE_COUNT: { + const uint32_t *tptr = (const uint32_t *)ptr; + if (sizeof(uint32_t) > size) { + os << "invalid size (is: " << size + << ", expected: >=" << sizeof(uint32_t) << ")"; + return; + } + os << (void *)(tptr) << " ("; + + os << *tptr; + + os << ")"; + } break; + default: + os << "unknown enumerator"; + break; + } +} +} // namespace ur_params +inline std::ostream &operator<<(std::ostream &os, + enum ur_adapter_backend_t value) { + switch (value) { + + case UR_ADAPTER_BACKEND_UNKNOWN: + os << "UR_ADAPTER_BACKEND_UNKNOWN"; + break; + + case UR_ADAPTER_BACKEND_LEVEL_ZERO: + os << "UR_ADAPTER_BACKEND_LEVEL_ZERO"; + break; + + case UR_ADAPTER_BACKEND_OPENCL: + os << "UR_ADAPTER_BACKEND_OPENCL"; + break; + + case UR_ADAPTER_BACKEND_CUDA: + os << "UR_ADAPTER_BACKEND_CUDA"; + break; + + case UR_ADAPTER_BACKEND_HIP: + os << "UR_ADAPTER_BACKEND_HIP"; + break; + + case UR_ADAPTER_BACKEND_NATIVE_CPU: + os << "UR_ADAPTER_BACKEND_NATIVE_CPU"; + break; + default: + os << "unknown enumerator"; + break; + } + return os; +} inline std::ostream &operator<<(std::ostream &os, enum ur_platform_info_t value) { switch (value) { @@ -9751,6 +9868,105 @@ inline std::ostream &operator<<(std::ostream &os, return os; } +inline std::ostream &operator<<(std::ostream &os, + const struct ur_adapter_get_params_t *params) { + + os << ".NumEntries = "; + + os << *(params->pNumEntries); + + os << ", "; + os << ".phAdapters = {"; + for (size_t i = 0; + *(params->pphAdapters) != NULL && i < *params->pNumEntries; ++i) { + if (i != 0) { + os << ", "; + } + + ur_params::serializePtr(os, (*(params->pphAdapters))[i]); + } + os << "}"; + + os << ", "; + os << ".pNumAdapters = "; + + ur_params::serializePtr(os, *(params->ppNumAdapters)); + + return os; +} + +inline std::ostream & +operator<<(std::ostream &os, const struct ur_adapter_release_params_t *params) { + + os << ".hAdapter = "; + + ur_params::serializePtr(os, *(params->phAdapter)); + + return os; +} + +inline std::ostream & +operator<<(std::ostream &os, const struct ur_adapter_retain_params_t *params) { + + os << ".hAdapter = "; + + ur_params::serializePtr(os, *(params->phAdapter)); + + return os; +} + +inline std::ostream & +operator<<(std::ostream &os, + const struct ur_adapter_get_last_error_params_t *params) { + + os << ".hAdapter = "; + + ur_params::serializePtr(os, *(params->phAdapter)); + + os << ", "; + os << ".ppMessage = "; + + ur_params::serializePtr(os, *(params->pppMessage)); + + os << ", "; + os << ".pError = "; + + ur_params::serializePtr(os, *(params->ppError)); + + return os; +} + +inline std::ostream & +operator<<(std::ostream &os, + const struct ur_adapter_get_info_params_t *params) { + + os << ".hAdapter = "; + + ur_params::serializePtr(os, *(params->phAdapter)); + + os << ", "; + os << ".propName = "; + + os << *(params->ppropName); + + os << ", "; + os << ".propSize = "; + + os << *(params->ppropSize); + + os << ", "; + os << ".pPropValue = "; + ur_params::serializeTagged(os, *(params->ppPropValue), *(params->ppropName), + *(params->ppropSize)); + + os << ", "; + os << ".pPropSizeRet = "; + + ur_params::serializePtr(os, *(params->ppPropSizeRet)); + + return os; +} + inline std::ostream &operator<<( std::ostream &os, const struct ur_bindless_images_unsampled_image_handle_destroy_exp_params_t @@ -13360,6 +13576,23 @@ operator<<(std::ostream &os, inline std::ostream &operator<<(std::ostream &os, const struct ur_platform_get_params_t *params) { + os << ".phAdapters = {"; + for (size_t i = 0; + *(params->pphAdapters) != NULL && i < *params->pNumAdapters; ++i) { + if (i != 0) { + os << ", "; + } + + ur_params::serializePtr(os, (*(params->pphAdapters))[i]); + } + os << "}"; + + os << ", "; + os << ".NumAdapters = "; + + os << *(params->pNumAdapters); + + os << ", "; os << ".NumEntries = "; os << *(params->pNumEntries); @@ -13452,27 +13685,6 @@ inline std::ostream &operator<<( return os; } -inline std::ostream & -operator<<(std::ostream &os, - const struct ur_platform_get_last_error_params_t *params) { - - os << ".hPlatform = "; - - ur_params::serializePtr(os, *(params->phPlatform)); - - os << ", "; - os << ".ppMessage = "; - - ur_params::serializePtr(os, *(params->pppMessage)); - - os << ", "; - os << ".pError = "; - - ur_params::serializePtr(os, *(params->ppError)); - - return os; -} - inline std::ostream & operator<<(std::ostream &os, const struct ur_platform_get_api_version_params_t *params) { @@ -14933,6 +15145,21 @@ inline int serializeFunctionParams(std::ostream &os, uint32_t function, case UR_FUNCTION_TEAR_DOWN: { os << (const struct ur_tear_down_params_t *)params; } break; + case UR_FUNCTION_ADAPTER_GET: { + os << (const struct ur_adapter_get_params_t *)params; + } break; + case UR_FUNCTION_ADAPTER_RELEASE: { + os << (const struct ur_adapter_release_params_t *)params; + } break; + case UR_FUNCTION_ADAPTER_RETAIN: { + os << (const struct ur_adapter_retain_params_t *)params; + } break; + case UR_FUNCTION_ADAPTER_GET_LAST_ERROR: { + os << (const struct ur_adapter_get_last_error_params_t *)params; + } break; + case UR_FUNCTION_ADAPTER_GET_INFO: { + os << (const struct ur_adapter_get_info_params_t *)params; + } break; case UR_FUNCTION_BINDLESS_IMAGES_UNSAMPLED_IMAGE_HANDLE_DESTROY_EXP: { os << (const struct ur_bindless_images_unsampled_image_handle_destroy_exp_params_t *) @@ -15280,9 +15507,6 @@ inline int serializeFunctionParams(std::ostream &os, uint32_t function, os << (const struct ur_platform_create_with_native_handle_params_t *) params; } break; - case UR_FUNCTION_PLATFORM_GET_LAST_ERROR: { - os << (const struct ur_platform_get_last_error_params_t *)params; - } break; case UR_FUNCTION_PLATFORM_GET_API_VERSION: { os << (const struct ur_platform_get_api_version_params_t *)params; } break; diff --git a/source/loader/layers/tracing/ur_trcddi.cpp b/source/loader/layers/tracing/ur_trcddi.cpp index bc0c0e8ea0..f30fac3807 100644 --- a/source/loader/layers/tracing/ur_trcddi.cpp +++ b/source/loader/layers/tracing/ur_trcddi.cpp @@ -63,9 +63,157 @@ __urdlllocal ur_result_t UR_APICALL urTearDown( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGet +__urdlllocal ur_result_t UR_APICALL urAdapterGet( + uint32_t + NumEntries, ///< [in] the number of adapters to be added to phAdapters. + ///< If phAdapters is not NULL, then NumEntries should be greater than + ///< zero, otherwise ::UR_RESULT_ERROR_INVALID_SIZE, + ///< will be returned. + ur_adapter_handle_t * + phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters. + ///< If NumEntries is less than the number of adapters available, then + ///< ::urAdapterGet shall only retrieve that number of platforms. + uint32_t * + pNumAdapters ///< [out][optional] returns the total number of adapters available. +) { + auto pfnAdapterGet = context.urDdiTable.Global.pfnAdapterGet; + + if (nullptr == pfnAdapterGet) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ur_adapter_get_params_t params = {&NumEntries, &phAdapters, &pNumAdapters}; + uint64_t instance = + context.notify_begin(UR_FUNCTION_ADAPTER_GET, "urAdapterGet", ¶ms); + + ur_result_t result = pfnAdapterGet(NumEntries, phAdapters, pNumAdapters); + + context.notify_end(UR_FUNCTION_ADAPTER_GET, "urAdapterGet", ¶ms, + &result, instance); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterRelease +__urdlllocal ur_result_t UR_APICALL urAdapterRelease( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to release +) { + auto pfnAdapterRelease = context.urDdiTable.Global.pfnAdapterRelease; + + if (nullptr == pfnAdapterRelease) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ur_adapter_release_params_t params = {&hAdapter}; + uint64_t instance = context.notify_begin(UR_FUNCTION_ADAPTER_RELEASE, + "urAdapterRelease", ¶ms); + + ur_result_t result = pfnAdapterRelease(hAdapter); + + context.notify_end(UR_FUNCTION_ADAPTER_RELEASE, "urAdapterRelease", ¶ms, + &result, instance); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterRetain +__urdlllocal ur_result_t UR_APICALL urAdapterRetain( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to retain +) { + auto pfnAdapterRetain = context.urDdiTable.Global.pfnAdapterRetain; + + if (nullptr == pfnAdapterRetain) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ur_adapter_retain_params_t params = {&hAdapter}; + uint64_t instance = context.notify_begin(UR_FUNCTION_ADAPTER_RETAIN, + "urAdapterRetain", ¶ms); + + ur_result_t result = pfnAdapterRetain(hAdapter); + + context.notify_end(UR_FUNCTION_ADAPTER_RETAIN, "urAdapterRetain", ¶ms, + &result, instance); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGetLastError +__urdlllocal ur_result_t UR_APICALL urAdapterGetLastError( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter instance + const char ** + ppMessage, ///< [out] pointer to a C string where the adapter specific error message + ///< will be stored. + int32_t * + pError ///< [out] pointer to an integer where the adapter specific error code will + ///< be stored. +) { + auto pfnAdapterGetLastError = + context.urDdiTable.Global.pfnAdapterGetLastError; + + if (nullptr == pfnAdapterGetLastError) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ur_adapter_get_last_error_params_t params = {&hAdapter, &ppMessage, + &pError}; + uint64_t instance = context.notify_begin(UR_FUNCTION_ADAPTER_GET_LAST_ERROR, + "urAdapterGetLastError", ¶ms); + + ur_result_t result = pfnAdapterGetLastError(hAdapter, ppMessage, pError); + + context.notify_end(UR_FUNCTION_ADAPTER_GET_LAST_ERROR, + "urAdapterGetLastError", ¶ms, &result, instance); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGetInfo +__urdlllocal ur_result_t UR_APICALL urAdapterGetInfo( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter + ur_adapter_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 Size is not equal to or greater to 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 number of bytes being queried by pPropValue. +) { + auto pfnAdapterGetInfo = context.urDdiTable.Global.pfnAdapterGetInfo; + + if (nullptr == pfnAdapterGetInfo) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ur_adapter_get_info_params_t params = {&hAdapter, &propName, &propSize, + &pPropValue, &pPropSizeRet}; + uint64_t instance = context.notify_begin(UR_FUNCTION_ADAPTER_GET_INFO, + "urAdapterGetInfo", ¶ms); + + ur_result_t result = pfnAdapterGetInfo(hAdapter, propName, propSize, + pPropValue, pPropSizeRet); + + context.notify_end(UR_FUNCTION_ADAPTER_GET_INFO, "urAdapterGetInfo", + ¶ms, &result, instance); + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urPlatformGet __urdlllocal ur_result_t UR_APICALL urPlatformGet( + ur_adapter_handle_t * + phAdapters, ///< [in][range(0, NumAdapters)] array of adapters to query for platforms. + uint32_t NumAdapters, ///< [in] number of adapters pointed to by phAdapters uint32_t NumEntries, ///< [in] the number of platforms to be added to phPlatforms. ///< If phPlatforms is not NULL, then NumEntries should be greater than @@ -84,12 +232,13 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGet( return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } - ur_platform_get_params_t params = {&NumEntries, &phPlatforms, - &pNumPlatforms}; + ur_platform_get_params_t params = {&phAdapters, &NumAdapters, &NumEntries, + &phPlatforms, &pNumPlatforms}; uint64_t instance = context.notify_begin(UR_FUNCTION_PLATFORM_GET, "urPlatformGet", ¶ms); - ur_result_t result = pfnGet(NumEntries, phPlatforms, pNumPlatforms); + ur_result_t result = + pfnGet(phAdapters, NumAdapters, NumEntries, phPlatforms, pNumPlatforms); context.notify_end(UR_FUNCTION_PLATFORM_GET, "urPlatformGet", ¶ms, &result, instance); @@ -249,36 +398,6 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGetBackendOption( return result; } -/////////////////////////////////////////////////////////////////////////////// -/// @brief Intercept function for urPlatformGetLastError -__urdlllocal ur_result_t UR_APICALL urPlatformGetLastError( - ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance - const char ** - ppMessage, ///< [out] pointer to a C string where the adapter specific error message - ///< will be stored. - int32_t * - pError ///< [out] pointer to an integer where the adapter specific error code will - ///< be stored. -) { - auto pfnGetLastError = context.urDdiTable.Platform.pfnGetLastError; - - if (nullptr == pfnGetLastError) { - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; - } - - ur_platform_get_last_error_params_t params = {&hPlatform, &ppMessage, - &pError}; - uint64_t instance = context.notify_begin( - UR_FUNCTION_PLATFORM_GET_LAST_ERROR, "urPlatformGetLastError", ¶ms); - - ur_result_t result = pfnGetLastError(hPlatform, ppMessage, pError); - - context.notify_end(UR_FUNCTION_PLATFORM_GET_LAST_ERROR, - "urPlatformGetLastError", ¶ms, &result, instance); - - return result; -} - /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urDeviceGet __urdlllocal ur_result_t UR_APICALL urDeviceGet( @@ -5715,6 +5834,21 @@ __urdlllocal ur_result_t UR_APICALL urGetGlobalProcAddrTable( dditable.pfnTearDown = pDdiTable->pfnTearDown; pDdiTable->pfnTearDown = ur_tracing_layer::urTearDown; + dditable.pfnAdapterGet = pDdiTable->pfnAdapterGet; + pDdiTable->pfnAdapterGet = ur_tracing_layer::urAdapterGet; + + dditable.pfnAdapterRelease = pDdiTable->pfnAdapterRelease; + pDdiTable->pfnAdapterRelease = ur_tracing_layer::urAdapterRelease; + + dditable.pfnAdapterRetain = pDdiTable->pfnAdapterRetain; + pDdiTable->pfnAdapterRetain = ur_tracing_layer::urAdapterRetain; + + dditable.pfnAdapterGetLastError = pDdiTable->pfnAdapterGetLastError; + pDdiTable->pfnAdapterGetLastError = ur_tracing_layer::urAdapterGetLastError; + + dditable.pfnAdapterGetInfo = pDdiTable->pfnAdapterGetInfo; + pDdiTable->pfnAdapterGetInfo = ur_tracing_layer::urAdapterGetInfo; + return result; } /////////////////////////////////////////////////////////////////////////////// @@ -6342,9 +6476,6 @@ __urdlllocal ur_result_t UR_APICALL urGetPlatformProcAddrTable( pDdiTable->pfnCreateWithNativeHandle = ur_tracing_layer::urPlatformCreateWithNativeHandle; - dditable.pfnGetLastError = pDdiTable->pfnGetLastError; - pDdiTable->pfnGetLastError = ur_tracing_layer::urPlatformGetLastError; - dditable.pfnGetApiVersion = pDdiTable->pfnGetApiVersion; pDdiTable->pfnGetApiVersion = ur_tracing_layer::urPlatformGetApiVersion; diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index 34440491f1..ce88ab6cb1 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -66,9 +66,179 @@ __urdlllocal ur_result_t UR_APICALL urTearDown( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGet +__urdlllocal ur_result_t UR_APICALL urAdapterGet( + uint32_t + NumEntries, ///< [in] the number of adapters to be added to phAdapters. + ///< If phAdapters is not NULL, then NumEntries should be greater than + ///< zero, otherwise ::UR_RESULT_ERROR_INVALID_SIZE, + ///< will be returned. + ur_adapter_handle_t * + phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters. + ///< If NumEntries is less than the number of adapters available, then + ///< ::urAdapterGet shall only retrieve that number of platforms. + uint32_t * + pNumAdapters ///< [out][optional] returns the total number of adapters available. +) { + auto pfnAdapterGet = context.urDdiTable.Global.pfnAdapterGet; + + if (nullptr == pfnAdapterGet) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + if (context.enableParameterValidation) { + } + + ur_result_t result = pfnAdapterGet(NumEntries, phAdapters, pNumAdapters); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterRelease +__urdlllocal ur_result_t UR_APICALL urAdapterRelease( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to release +) { + auto pfnAdapterRelease = context.urDdiTable.Global.pfnAdapterRelease; + + if (nullptr == pfnAdapterRelease) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + if (context.enableParameterValidation) { + if (NULL == hAdapter) { + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + } + + ur_result_t result = pfnAdapterRelease(hAdapter); + + if (context.enableLeakChecking && result == UR_RESULT_SUCCESS) { + refCountContext.decrementRefCount(hAdapter); + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterRetain +__urdlllocal ur_result_t UR_APICALL urAdapterRetain( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to retain +) { + auto pfnAdapterRetain = context.urDdiTable.Global.pfnAdapterRetain; + + if (nullptr == pfnAdapterRetain) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + if (context.enableParameterValidation) { + if (NULL == hAdapter) { + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + } + + ur_result_t result = pfnAdapterRetain(hAdapter); + + if (context.enableLeakChecking && result == UR_RESULT_SUCCESS) { + refCountContext.incrementRefCount(hAdapter); + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGetLastError +__urdlllocal ur_result_t UR_APICALL urAdapterGetLastError( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter instance + const char ** + ppMessage, ///< [out] pointer to a C string where the adapter specific error message + ///< will be stored. + int32_t * + pError ///< [out] pointer to an integer where the adapter specific error code will + ///< be stored. +) { + auto pfnAdapterGetLastError = + context.urDdiTable.Global.pfnAdapterGetLastError; + + if (nullptr == pfnAdapterGetLastError) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + if (context.enableParameterValidation) { + if (NULL == hAdapter) { + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + if (NULL == ppMessage) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (NULL == pError) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + } + + ur_result_t result = pfnAdapterGetLastError(hAdapter, ppMessage, pError); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGetInfo +__urdlllocal ur_result_t UR_APICALL urAdapterGetInfo( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter + ur_adapter_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 Size is not equal to or greater to 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 number of bytes being queried by pPropValue. +) { + auto pfnAdapterGetInfo = context.urDdiTable.Global.pfnAdapterGetInfo; + + if (nullptr == pfnAdapterGetInfo) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + if (context.enableParameterValidation) { + if (NULL == hAdapter) { + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + if (propSize != 0 && pPropValue == NULL) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (pPropValue == NULL && pPropSizeRet == NULL) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (UR_ADAPTER_INFO_REFERENCE_COUNT < propName) { + return UR_RESULT_ERROR_INVALID_ENUMERATION; + } + + if (propSize == 0 && pPropValue != NULL) { + return UR_RESULT_ERROR_INVALID_SIZE; + } + } + + ur_result_t result = pfnAdapterGetInfo(hAdapter, propName, propSize, + pPropValue, pPropSizeRet); + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urPlatformGet __urdlllocal ur_result_t UR_APICALL urPlatformGet( + ur_adapter_handle_t * + phAdapters, ///< [in][range(0, NumAdapters)] array of adapters to query for platforms. + uint32_t NumAdapters, ///< [in] number of adapters pointed to by phAdapters uint32_t NumEntries, ///< [in] the number of platforms to be added to phPlatforms. ///< If phPlatforms is not NULL, then NumEntries should be greater than @@ -88,9 +258,13 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGet( } if (context.enableParameterValidation) { + if (NULL == phAdapters) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } } - ur_result_t result = pfnGet(NumEntries, phPlatforms, pNumPlatforms); + ur_result_t result = + pfnGet(phAdapters, NumAdapters, NumEntries, phPlatforms, pNumPlatforms); return result; } @@ -264,42 +438,6 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGetBackendOption( return result; } -/////////////////////////////////////////////////////////////////////////////// -/// @brief Intercept function for urPlatformGetLastError -__urdlllocal ur_result_t UR_APICALL urPlatformGetLastError( - ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance - const char ** - ppMessage, ///< [out] pointer to a C string where the adapter specific error message - ///< will be stored. - int32_t * - pError ///< [out] pointer to an integer where the adapter specific error code will - ///< be stored. -) { - auto pfnGetLastError = context.urDdiTable.Platform.pfnGetLastError; - - if (nullptr == pfnGetLastError) { - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; - } - - if (context.enableParameterValidation) { - if (NULL == hPlatform) { - return UR_RESULT_ERROR_INVALID_NULL_HANDLE; - } - - if (NULL == ppMessage) { - return UR_RESULT_ERROR_INVALID_NULL_POINTER; - } - - if (NULL == pError) { - return UR_RESULT_ERROR_INVALID_NULL_POINTER; - } - } - - ur_result_t result = pfnGetLastError(hPlatform, ppMessage, pError); - - return result; -} - /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urDeviceGet __urdlllocal ur_result_t UR_APICALL urDeviceGet( @@ -7051,6 +7189,22 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetGlobalProcAddrTable( dditable.pfnTearDown = pDdiTable->pfnTearDown; pDdiTable->pfnTearDown = ur_validation_layer::urTearDown; + dditable.pfnAdapterGet = pDdiTable->pfnAdapterGet; + pDdiTable->pfnAdapterGet = ur_validation_layer::urAdapterGet; + + dditable.pfnAdapterRelease = pDdiTable->pfnAdapterRelease; + pDdiTable->pfnAdapterRelease = ur_validation_layer::urAdapterRelease; + + dditable.pfnAdapterRetain = pDdiTable->pfnAdapterRetain; + pDdiTable->pfnAdapterRetain = ur_validation_layer::urAdapterRetain; + + dditable.pfnAdapterGetLastError = pDdiTable->pfnAdapterGetLastError; + pDdiTable->pfnAdapterGetLastError = + ur_validation_layer::urAdapterGetLastError; + + dditable.pfnAdapterGetInfo = pDdiTable->pfnAdapterGetInfo; + pDdiTable->pfnAdapterGetInfo = ur_validation_layer::urAdapterGetInfo; + return result; } @@ -7694,9 +7848,6 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetPlatformProcAddrTable( pDdiTable->pfnCreateWithNativeHandle = ur_validation_layer::urPlatformCreateWithNativeHandle; - dditable.pfnGetLastError = pDdiTable->pfnGetLastError; - pDdiTable->pfnGetLastError = ur_validation_layer::urPlatformGetLastError; - dditable.pfnGetApiVersion = pDdiTable->pfnGetApiVersion; pDdiTable->pfnGetApiVersion = ur_validation_layer::urPlatformGetApiVersion; diff --git a/source/loader/ur_ldrddi.cpp b/source/loader/ur_ldrddi.cpp index ebdd60c739..e192088bbc 100644 --- a/source/loader/ur_ldrddi.cpp +++ b/source/loader/ur_ldrddi.cpp @@ -14,6 +14,7 @@ namespace ur_loader { /////////////////////////////////////////////////////////////////////////////// +ur_adapter_factory_t ur_adapter_factory; ur_platform_factory_t ur_platform_factory; ur_device_factory_t ur_device_factory; ur_context_factory_t ur_context_factory; @@ -67,9 +68,163 @@ __urdlllocal ur_result_t UR_APICALL urTearDown( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGet +__urdlllocal ur_result_t UR_APICALL urAdapterGet( + uint32_t + NumEntries, ///< [in] the number of adapters to be added to phAdapters. + ///< If phAdapters is not NULL, then NumEntries should be greater than + ///< zero, otherwise ::UR_RESULT_ERROR_INVALID_SIZE, + ///< will be returned. + ur_adapter_handle_t * + phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters. + ///< If NumEntries is less than the number of adapters available, then + ///< ::urAdapterGet shall only retrieve that number of platforms. + uint32_t * + pNumAdapters ///< [out][optional] returns the total number of adapters available. +) { + ur_result_t result = UR_RESULT_SUCCESS; + + size_t adapterIndex = 0; + if (nullptr != phAdapters && NumEntries != 0) { + for (auto &platform : context->platforms) { + platform.dditable.ur.Global.pfnAdapterGet( + 1, &phAdapters[adapterIndex], nullptr); + try { + phAdapters[adapterIndex] = + reinterpret_cast( + ur_adapter_factory.getInstance(phAdapters[adapterIndex], + &platform.dditable)); + } catch (std::bad_alloc &) { + result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; + break; + } + adapterIndex++; + } + } + + if (pNumAdapters != nullptr) { + *pNumAdapters = static_cast(context->platforms.size()); + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterRelease +__urdlllocal ur_result_t UR_APICALL urAdapterRelease( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to release +) { + ur_result_t result = UR_RESULT_SUCCESS; + + // extract platform's function pointer table + auto dditable = reinterpret_cast(hAdapter)->dditable; + auto pfnAdapterRelease = dditable->ur.Global.pfnAdapterRelease; + if (nullptr == pfnAdapterRelease) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + // convert loader handle to platform handle + hAdapter = reinterpret_cast(hAdapter)->handle; + + // forward to device-platform + result = pfnAdapterRelease(hAdapter); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterRetain +__urdlllocal ur_result_t UR_APICALL urAdapterRetain( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to retain +) { + ur_result_t result = UR_RESULT_SUCCESS; + + // extract platform's function pointer table + auto dditable = reinterpret_cast(hAdapter)->dditable; + auto pfnAdapterRetain = dditable->ur.Global.pfnAdapterRetain; + if (nullptr == pfnAdapterRetain) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + // convert loader handle to platform handle + hAdapter = reinterpret_cast(hAdapter)->handle; + + // forward to device-platform + result = pfnAdapterRetain(hAdapter); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGetLastError +__urdlllocal ur_result_t UR_APICALL urAdapterGetLastError( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter instance + const char ** + ppMessage, ///< [out] pointer to a C string where the adapter specific error message + ///< will be stored. + int32_t * + pError ///< [out] pointer to an integer where the adapter specific error code will + ///< be stored. +) { + ur_result_t result = UR_RESULT_SUCCESS; + + // extract platform's function pointer table + auto dditable = reinterpret_cast(hAdapter)->dditable; + auto pfnAdapterGetLastError = dditable->ur.Global.pfnAdapterGetLastError; + if (nullptr == pfnAdapterGetLastError) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + // convert loader handle to platform handle + hAdapter = reinterpret_cast(hAdapter)->handle; + + // forward to device-platform + result = pfnAdapterGetLastError(hAdapter, ppMessage, pError); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urAdapterGetInfo +__urdlllocal ur_result_t UR_APICALL urAdapterGetInfo( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter + ur_adapter_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 Size is not equal to or greater to 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 number of bytes being queried by pPropValue. +) { + ur_result_t result = UR_RESULT_SUCCESS; + + // extract platform's function pointer table + auto dditable = reinterpret_cast(hAdapter)->dditable; + auto pfnAdapterGetInfo = dditable->ur.Global.pfnAdapterGetInfo; + if (nullptr == pfnAdapterGetInfo) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + // convert loader handle to platform handle + hAdapter = reinterpret_cast(hAdapter)->handle; + + // forward to device-platform + result = pfnAdapterGetInfo(hAdapter, propName, propSize, pPropValue, + pPropSizeRet); + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urPlatformGet __urdlllocal ur_result_t UR_APICALL urPlatformGet( + ur_adapter_handle_t * + phAdapters, ///< [in][range(0, NumAdapters)] array of adapters to query for platforms. + uint32_t NumAdapters, ///< [in] number of adapters pointed to by phAdapters uint32_t NumEntries, ///< [in] the number of platforms to be added to phPlatforms. ///< If phPlatforms is not NULL, then NumEntries should be greater than @@ -86,10 +241,12 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGet( uint32_t total_platform_handle_count = 0; - for (auto &platform : context->platforms) { - if (platform.initStatus != UR_RESULT_SUCCESS) { - continue; - } + for (uint32_t adapter_index = 0; adapter_index < NumAdapters; + adapter_index++) { + // extract adapter's function pointer table + auto dditable = + reinterpret_cast(phAdapters[adapter_index]) + ->dditable; if ((0 < NumEntries) && (NumEntries == total_platform_handle_count)) { break; @@ -97,8 +254,9 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGet( uint32_t library_platform_handle_count = 0; - result = platform.dditable.ur.Platform.pfnGet( - 0, nullptr, &library_platform_handle_count); + result = dditable->ur.Platform.pfnGet(&phAdapters[adapter_index], 1, 0, + nullptr, + &library_platform_handle_count); if (UR_RESULT_SUCCESS != result) { break; } @@ -109,8 +267,8 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGet( library_platform_handle_count = NumEntries - total_platform_handle_count; } - result = platform.dditable.ur.Platform.pfnGet( - library_platform_handle_count, + result = dditable->ur.Platform.pfnGet( + &phAdapters[adapter_index], 1, library_platform_handle_count, &phPlatforms[total_platform_handle_count], nullptr); if (UR_RESULT_SUCCESS != result) { break; @@ -122,8 +280,7 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGet( phPlatforms[platform_index] = reinterpret_cast( ur_platform_factory.getInstance( - phPlatforms[platform_index], - &platform.dditable)); + phPlatforms[platform_index], dditable)); } } catch (std::bad_alloc &) { result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; @@ -311,36 +468,6 @@ __urdlllocal ur_result_t UR_APICALL urPlatformGetBackendOption( return result; } -/////////////////////////////////////////////////////////////////////////////// -/// @brief Intercept function for urPlatformGetLastError -__urdlllocal ur_result_t UR_APICALL urPlatformGetLastError( - ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance - const char ** - ppMessage, ///< [out] pointer to a C string where the adapter specific error message - ///< will be stored. - int32_t * - pError ///< [out] pointer to an integer where the adapter specific error code will - ///< be stored. -) { - ur_result_t result = UR_RESULT_SUCCESS; - - // extract platform's function pointer table - auto dditable = - reinterpret_cast(hPlatform)->dditable; - auto pfnGetLastError = dditable->ur.Platform.pfnGetLastError; - if (nullptr == pfnGetLastError) { - return UR_RESULT_ERROR_UNINITIALIZED; - } - - // convert loader handle to platform handle - hPlatform = reinterpret_cast(hPlatform)->handle; - - // forward to device-platform - result = pfnGetLastError(hPlatform, ppMessage, pError); - - return result; -} - /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urDeviceGet __urdlllocal ur_result_t UR_APICALL urDeviceGet( @@ -6869,6 +6996,12 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetGlobalProcAddrTable( // return pointers to loader's DDIs pDdiTable->pfnInit = ur_loader::urInit; pDdiTable->pfnTearDown = ur_loader::urTearDown; + pDdiTable->pfnAdapterGet = ur_loader::urAdapterGet; + pDdiTable->pfnAdapterRelease = ur_loader::urAdapterRelease; + pDdiTable->pfnAdapterRetain = ur_loader::urAdapterRetain; + pDdiTable->pfnAdapterGetLastError = + ur_loader::urAdapterGetLastError; + pDdiTable->pfnAdapterGetInfo = ur_loader::urAdapterGetInfo; } else { // return pointers directly to platform's DDIs *pDdiTable = @@ -7485,7 +7618,6 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetPlatformProcAddrTable( ur_loader::urPlatformGetNativeHandle; pDdiTable->pfnCreateWithNativeHandle = ur_loader::urPlatformCreateWithNativeHandle; - pDdiTable->pfnGetLastError = ur_loader::urPlatformGetLastError; pDdiTable->pfnGetApiVersion = ur_loader::urPlatformGetApiVersion; pDdiTable->pfnGetBackendOption = ur_loader::urPlatformGetBackendOption; diff --git a/source/loader/ur_ldrddi.hpp b/source/loader/ur_ldrddi.hpp index 9ebaeed9d9..4edbabbd8b 100644 --- a/source/loader/ur_ldrddi.hpp +++ b/source/loader/ur_ldrddi.hpp @@ -17,6 +17,10 @@ namespace ur_loader { /////////////////////////////////////////////////////////////////////////////// +using ur_adapter_object_t = object_t; +using ur_adapter_factory_t = + singleton_factory_t; + using ur_platform_object_t = object_t; using ur_platform_factory_t = singleton_factory_t; diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index e5e5b847c3..a31751b254 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -232,7 +232,219 @@ ur_result_t UR_APICALL urTearDown( } /////////////////////////////////////////////////////////////////////////////// -/// @brief Retrieves all available platforms +/// @brief Retrieves all available adapters +/// +/// @details +/// - Adapter implementations must return exactly one adapter handle from +/// this entry point. +/// - The loader may return more than one adapter handle when there are +/// multiple available. +/// - Each returned adapter has its reference count incremented and should +/// be released with a subsequent call to ::urAdapterRelease. +/// - Adapters may perform adapter-specific state initialization when the +/// first reference to them is taken. +/// - An application may call this entry point multiple times to acquire +/// multiple references to the adapter handle(s). +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_SIZE +ur_result_t UR_APICALL urAdapterGet( + uint32_t + NumEntries, ///< [in] the number of adapters to be added to phAdapters. + ///< If phAdapters is not NULL, then NumEntries should be greater than + ///< zero, otherwise ::UR_RESULT_ERROR_INVALID_SIZE, + ///< will be returned. + ur_adapter_handle_t * + phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters. + ///< If NumEntries is less than the number of adapters available, then + ///< ::urAdapterGet shall only retrieve that number of platforms. + uint32_t * + pNumAdapters ///< [out][optional] returns the total number of adapters available. + ) try { + auto pfnAdapterGet = ur_lib::context->urDdiTable.Global.pfnAdapterGet; + if (nullptr == pfnAdapterGet) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + return pfnAdapterGet(NumEntries, phAdapters, pNumAdapters); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Releases the adapter handle reference indicating end of its usage +/// +/// @details +/// - When the reference count of the adapter reaches zero, the adapter may +/// perform adapter-specififc resource teardown +/// +/// @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 == hAdapter` +ur_result_t UR_APICALL urAdapterRelease( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to release + ) try { + auto pfnAdapterRelease = + ur_lib::context->urDdiTable.Global.pfnAdapterRelease; + if (nullptr == pfnAdapterRelease) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + return pfnAdapterRelease(hAdapter); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Get a reference to the adapter handle. +/// +/// @details +/// - Get a reference to the adapter handle. Increment its reference count +/// +/// @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 == hAdapter` +ur_result_t UR_APICALL urAdapterRetain( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to retain + ) try { + auto pfnAdapterRetain = ur_lib::context->urDdiTable.Global.pfnAdapterRetain; + if (nullptr == pfnAdapterRetain) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + return pfnAdapterRetain(hAdapter); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Get the last adapter specific error. +/// +/// @details +/// To be used after another entry-point has returned +/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC in order to retrieve a message describing +/// the circumstances of the underlying driver error and the error code +/// returned by the failed driver entry-point. +/// +/// * Implementations *must* store the message and error code in thread-local +/// storage prior to returning ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. +/// +/// * The message and error code storage is will only be valid if a previously +/// called entry-point returned ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. +/// +/// * The memory pointed to by the C string returned in `ppMessage` is owned by +/// the adapter and *must* be null terminated. +/// +/// * The application *may* call this function from simultaneous threads. +/// +/// * The implementation of this function *should* be lock-free. +/// +/// Example usage: +/// +/// ```cpp +/// if (::urQueueCreate(hContext, hDevice, nullptr, &hQueue) == +/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC) { +/// const char* pMessage; +/// int32_t error; +/// ::urAdapterGetLastError(hAdapter, &pMessage, &error); +/// } +/// ``` +/// +/// @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 == hAdapter` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMessage` +/// + `NULL == pError` +ur_result_t UR_APICALL urAdapterGetLastError( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter instance + const char ** + ppMessage, ///< [out] pointer to a C string where the adapter specific error message + ///< will be stored. + int32_t * + pError ///< [out] pointer to an integer where the adapter specific error code will + ///< be stored. + ) try { + auto pfnAdapterGetLastError = + ur_lib::context->urDdiTable.Global.pfnAdapterGetLastError; + if (nullptr == pfnAdapterGetLastError) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + return pfnAdapterGetLastError(hAdapter, ppMessage, pError); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves information about the adapter +/// +/// @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 == hAdapter` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `::UR_ADAPTER_INFO_REFERENCE_COUNT < propName` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION +/// + If `propName` is not supported by the adapter. +/// - ::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_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +ur_result_t UR_APICALL urAdapterGetInfo( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter + ur_adapter_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 Size is not equal to or greater to 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 number of bytes being queried by pPropValue. + ) try { + auto pfnAdapterGetInfo = + ur_lib::context->urDdiTable.Global.pfnAdapterGetInfo; + if (nullptr == pfnAdapterGetInfo) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + return pfnAdapterGetInfo(hAdapter, propName, propSize, pPropValue, + pPropSizeRet); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves all available platforms for the given adapters /// /// @details /// - Multiple calls to this function will return identical platforms @@ -249,8 +461,13 @@ ur_result_t UR_APICALL urTearDown( /// - ::UR_RESULT_ERROR_UNINITIALIZED /// - ::UR_RESULT_ERROR_DEVICE_LOST /// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == phAdapters` /// - ::UR_RESULT_ERROR_INVALID_SIZE ur_result_t UR_APICALL urPlatformGet( + ur_adapter_handle_t * + phAdapters, ///< [in][range(0, NumAdapters)] array of adapters to query for platforms. + uint32_t NumAdapters, ///< [in] number of adapters pointed to by phAdapters uint32_t NumEntries, ///< [in] the number of platforms to be added to phPlatforms. ///< If phPlatforms is not NULL, then NumEntries should be greater than @@ -268,7 +485,8 @@ ur_result_t UR_APICALL urPlatformGet( return UR_RESULT_ERROR_UNINITIALIZED; } - return pfnGet(NumEntries, phPlatforms, pNumPlatforms); + return pfnGet(phAdapters, NumAdapters, NumEntries, phPlatforms, + pNumPlatforms); } catch (...) { return exceptionToResult(std::current_exception()); } @@ -474,68 +692,6 @@ ur_result_t UR_APICALL urPlatformGetBackendOption( return exceptionToResult(std::current_exception()); } -/////////////////////////////////////////////////////////////////////////////// -/// @brief Get the last adapter specific error. -/// -/// @details -/// To be used after another entry-point has returned -/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC in order to retrieve a message describing -/// the circumstances of the underlying driver error and the error code -/// returned by the failed driver entry-point. -/// -/// * Implementations *must* store the message and error code in thread-local -/// storage prior to returning ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. -/// -/// * The message and error code storage is will only be valid if a previously -/// called entry-point returned ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. -/// -/// * The memory pointed to by the C string returned in `ppMessage` is owned by -/// the adapter and *must* be null terminated. -/// -/// * The application *may* call this function from simultaneous threads. -/// -/// * The implementation of this function *should* be lock-free. -/// -/// Example usage: -/// -/// ```cpp -/// if (::urQueueCreate(hContext, hDevice, nullptr, &hQueue) == -/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC) { -/// const char* pMessage; -/// int32_t error; -/// ::urPlatformGetLastError(hPlatform, &pMessage, &error); -/// } -/// ``` -/// -/// @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 == hPlatform` -/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER -/// + `NULL == ppMessage` -/// + `NULL == pError` -ur_result_t UR_APICALL urPlatformGetLastError( - ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance - const char ** - ppMessage, ///< [out] pointer to a C string where the adapter specific error message - ///< will be stored. - int32_t * - pError ///< [out] pointer to an integer where the adapter specific error code will - ///< be stored. - ) try { - auto pfnGetLastError = ur_lib::context->urDdiTable.Platform.pfnGetLastError; - if (nullptr == pfnGetLastError) { - return UR_RESULT_ERROR_UNINITIALIZED; - } - - return pfnGetLastError(hPlatform, ppMessage, pError); -} catch (...) { - return exceptionToResult(std::current_exception()); -} - /////////////////////////////////////////////////////////////////////////////// /// @brief Retrieves devices within a platform /// diff --git a/source/ur_api.cpp b/source/ur_api.cpp index 4ce155ddbb..b63c0975f8 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -202,7 +202,185 @@ ur_result_t UR_APICALL urTearDown( } /////////////////////////////////////////////////////////////////////////////// -/// @brief Retrieves all available platforms +/// @brief Retrieves all available adapters +/// +/// @details +/// - Adapter implementations must return exactly one adapter handle from +/// this entry point. +/// - The loader may return more than one adapter handle when there are +/// multiple available. +/// - Each returned adapter has its reference count incremented and should +/// be released with a subsequent call to ::urAdapterRelease. +/// - Adapters may perform adapter-specific state initialization when the +/// first reference to them is taken. +/// - An application may call this entry point multiple times to acquire +/// multiple references to the adapter handle(s). +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_SIZE +ur_result_t UR_APICALL urAdapterGet( + uint32_t + NumEntries, ///< [in] the number of adapters to be added to phAdapters. + ///< If phAdapters is not NULL, then NumEntries should be greater than + ///< zero, otherwise ::UR_RESULT_ERROR_INVALID_SIZE, + ///< will be returned. + ur_adapter_handle_t * + phAdapters, ///< [out][optional][range(0, NumEntries)] array of handle of adapters. + ///< If NumEntries is less than the number of adapters available, then + ///< ::urAdapterGet shall only retrieve that number of platforms. + uint32_t * + pNumAdapters ///< [out][optional] returns the total number of adapters available. +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Releases the adapter handle reference indicating end of its usage +/// +/// @details +/// - When the reference count of the adapter reaches zero, the adapter may +/// perform adapter-specififc resource teardown +/// +/// @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 == hAdapter` +ur_result_t UR_APICALL urAdapterRelease( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to release +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Get a reference to the adapter handle. +/// +/// @details +/// - Get a reference to the adapter handle. Increment its reference count +/// +/// @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 == hAdapter` +ur_result_t UR_APICALL urAdapterRetain( + ur_adapter_handle_t hAdapter ///< [in] Adapter handle to retain +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Get the last adapter specific error. +/// +/// @details +/// To be used after another entry-point has returned +/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC in order to retrieve a message describing +/// the circumstances of the underlying driver error and the error code +/// returned by the failed driver entry-point. +/// +/// * Implementations *must* store the message and error code in thread-local +/// storage prior to returning ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. +/// +/// * The message and error code storage is will only be valid if a previously +/// called entry-point returned ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. +/// +/// * The memory pointed to by the C string returned in `ppMessage` is owned by +/// the adapter and *must* be null terminated. +/// +/// * The application *may* call this function from simultaneous threads. +/// +/// * The implementation of this function *should* be lock-free. +/// +/// Example usage: +/// +/// ```cpp +/// if (::urQueueCreate(hContext, hDevice, nullptr, &hQueue) == +/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC) { +/// const char* pMessage; +/// int32_t error; +/// ::urAdapterGetLastError(hAdapter, &pMessage, &error); +/// } +/// ``` +/// +/// @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 == hAdapter` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMessage` +/// + `NULL == pError` +ur_result_t UR_APICALL urAdapterGetLastError( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter instance + const char ** + ppMessage, ///< [out] pointer to a C string where the adapter specific error message + ///< will be stored. + int32_t * + pError ///< [out] pointer to an integer where the adapter specific error code will + ///< be stored. +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves information about the adapter +/// +/// @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 == hAdapter` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `::UR_ADAPTER_INFO_REFERENCE_COUNT < propName` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION +/// + If `propName` is not supported by the adapter. +/// - ::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_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +ur_result_t UR_APICALL urAdapterGetInfo( + ur_adapter_handle_t hAdapter, ///< [in] handle of the adapter + ur_adapter_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 Size is not equal to or greater to 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 number of bytes being queried by pPropValue. +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves all available platforms for the given adapters /// /// @details /// - Multiple calls to this function will return identical platforms @@ -219,8 +397,13 @@ ur_result_t UR_APICALL urTearDown( /// - ::UR_RESULT_ERROR_UNINITIALIZED /// - ::UR_RESULT_ERROR_DEVICE_LOST /// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == phAdapters` /// - ::UR_RESULT_ERROR_INVALID_SIZE ur_result_t UR_APICALL urPlatformGet( + ur_adapter_handle_t * + phAdapters, ///< [in][range(0, NumAdapters)] array of adapters to query for platforms. + uint32_t NumAdapters, ///< [in] number of adapters pointed to by phAdapters uint32_t NumEntries, ///< [in] the number of platforms to be added to phPlatforms. ///< If phPlatforms is not NULL, then NumEntries should be greater than @@ -404,62 +587,6 @@ ur_result_t UR_APICALL urPlatformGetBackendOption( return result; } -/////////////////////////////////////////////////////////////////////////////// -/// @brief Get the last adapter specific error. -/// -/// @details -/// To be used after another entry-point has returned -/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC in order to retrieve a message describing -/// the circumstances of the underlying driver error and the error code -/// returned by the failed driver entry-point. -/// -/// * Implementations *must* store the message and error code in thread-local -/// storage prior to returning ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. -/// -/// * The message and error code storage is will only be valid if a previously -/// called entry-point returned ::UR_RESULT_ERROR_ADAPTER_SPECIFIC. -/// -/// * The memory pointed to by the C string returned in `ppMessage` is owned by -/// the adapter and *must* be null terminated. -/// -/// * The application *may* call this function from simultaneous threads. -/// -/// * The implementation of this function *should* be lock-free. -/// -/// Example usage: -/// -/// ```cpp -/// if (::urQueueCreate(hContext, hDevice, nullptr, &hQueue) == -/// ::UR_RESULT_ERROR_ADAPTER_SPECIFIC) { -/// const char* pMessage; -/// int32_t error; -/// ::urPlatformGetLastError(hPlatform, &pMessage, &error); -/// } -/// ``` -/// -/// @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 == hPlatform` -/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER -/// + `NULL == ppMessage` -/// + `NULL == pError` -ur_result_t UR_APICALL urPlatformGetLastError( - ur_platform_handle_t hPlatform, ///< [in] handle of the platform instance - const char ** - ppMessage, ///< [out] pointer to a C string where the adapter specific error message - ///< will be stored. - int32_t * - pError ///< [out] pointer to an integer where the adapter specific error code will - ///< be stored. -) { - ur_result_t result = UR_RESULT_SUCCESS; - return result; -} - /////////////////////////////////////////////////////////////////////////////// /// @brief Retrieves devices within a platform /// diff --git a/test/conformance/platform/CMakeLists.txt b/test/conformance/platform/CMakeLists.txt index 3a9483e2a8..eec1e9bee3 100644 --- a/test/conformance/platform/CMakeLists.txt +++ b/test/conformance/platform/CMakeLists.txt @@ -9,5 +9,4 @@ add_conformance_test(platform urPlatformGetApiVersion.cpp urPlatformGetBackendOption.cpp urPlatformGetInfo.cpp - urPlatformGetLastError.cpp urPlatformGetNativeHandle.cpp) diff --git a/test/conformance/platform/fixtures.h b/test/conformance/platform/fixtures.h index 1558d8d1b3..c8170a4ea2 100644 --- a/test/conformance/platform/fixtures.h +++ b/test/conformance/platform/fixtures.h @@ -20,12 +20,22 @@ struct urTest : ::testing::Test { urLoaderConfigEnableLayer(config, "UR_LAYER_FULL_VALIDATION")); ASSERT_SUCCESS(urInit(device_flags, config)); ASSERT_SUCCESS(urLoaderConfigRelease(config)); + + uint32_t adapter_count; + ASSERT_SUCCESS(urAdapterGet(0, nullptr, &adapter_count)); + adapters.resize(adapter_count); + ASSERT_SUCCESS(urAdapterGet(adapter_count, adapters.data(), nullptr)); } void TearDown() override { + for (auto adapter : adapters) { + ASSERT_SUCCESS(urAdapterRelease(adapter)); + } ur_tear_down_params_t tear_down_params{}; ASSERT_SUCCESS(urTearDown(&tear_down_params)); } + + std::vector adapters; }; struct urPlatformsTest : urTest { @@ -33,10 +43,14 @@ struct urPlatformsTest : urTest { void SetUp() override { UUR_RETURN_ON_FATAL_FAILURE(urTest::SetUp()); uint32_t count; - ASSERT_SUCCESS(urPlatformGet(0, nullptr, &count)); + ASSERT_SUCCESS(urPlatformGet(adapters.data(), + static_cast(adapters.size()), 0, + nullptr, &count)); ASSERT_NE(count, 0); platforms.resize(count); - ASSERT_SUCCESS(urPlatformGet(count, platforms.data(), nullptr)); + ASSERT_SUCCESS(urPlatformGet(adapters.data(), + static_cast(adapters.size()), + count, platforms.data(), nullptr)); } std::vector platforms; diff --git a/test/conformance/platform/urPlatformGet.cpp b/test/conformance/platform/urPlatformGet.cpp index d7c369e0bd..2f3b28279d 100644 --- a/test/conformance/platform/urPlatformGet.cpp +++ b/test/conformance/platform/urPlatformGet.cpp @@ -9,10 +9,14 @@ using urPlatformGetTest = uur::platform::urTest; TEST_F(urPlatformGetTest, Success) { uint32_t count; - ASSERT_SUCCESS(urPlatformGet(0, nullptr, &count)); + ASSERT_SUCCESS(urPlatformGet(adapters.data(), + static_cast(adapters.size()), 0, + nullptr, &count)); ASSERT_NE(count, 0); std::vector platforms(count); - ASSERT_SUCCESS(urPlatformGet(count, platforms.data(), nullptr)); + ASSERT_SUCCESS(urPlatformGet(adapters.data(), + static_cast(adapters.size()), count, + platforms.data(), nullptr)); for (auto platform : platforms) { ASSERT_NE(nullptr, platform); } @@ -20,8 +24,12 @@ TEST_F(urPlatformGetTest, Success) { TEST_F(urPlatformGetTest, InvalidNumEntries) { uint32_t count; - ASSERT_SUCCESS(urPlatformGet(0, nullptr, &count)); + ASSERT_SUCCESS(urPlatformGet(adapters.data(), + static_cast(adapters.size()), 0, + nullptr, &count)); std::vector platforms(count); ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE, - urPlatformGet(0, platforms.data(), nullptr)); + urPlatformGet(adapters.data(), + static_cast(adapters.size()), 0, + platforms.data(), nullptr)); } diff --git a/test/conformance/runtime/CMakeLists.txt b/test/conformance/runtime/CMakeLists.txt index 1eff8db3b7..8c46abd82b 100644 --- a/test/conformance/runtime/CMakeLists.txt +++ b/test/conformance/runtime/CMakeLists.txt @@ -4,5 +4,10 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception add_conformance_test(runtime + urAdapterGet.cpp + urAdapterGetInfo.cpp + urAdapterGetLastError.cpp + urAdapterRetain.cpp + urAdapterRelease.cpp urInit.cpp urTearDown.cpp) diff --git a/test/conformance/runtime/fixtures.h b/test/conformance/runtime/fixtures.h new file mode 100644 index 0000000000..852d6d038c --- /dev/null +++ b/test/conformance/runtime/fixtures.h @@ -0,0 +1,50 @@ +// Copyright (C) 2022-2023 Intel Corporation +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +// See LICENSE.TXT +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +namespace uur { +namespace runtime { + +struct urTest : ::testing::Test { + + void SetUp() override { + ur_device_init_flags_t device_flags = 0; + ur_loader_config_handle_t config; + ASSERT_SUCCESS(urLoaderConfigCreate(&config)); + ASSERT_SUCCESS( + urLoaderConfigEnableLayer(config, "UR_LAYER_FULL_VALIDATION")); + ASSERT_SUCCESS(urInit(device_flags, config)); + ASSERT_SUCCESS(urLoaderConfigRelease(config)); + } + + void TearDown() override { + ur_tear_down_params_t tear_down_params{}; + ASSERT_SUCCESS(urTearDown(&tear_down_params)); + } +}; + +struct urAdapterTest : urTest { + + void SetUp() override { + UUR_RETURN_ON_FATAL_FAILURE(urTest::SetUp()); + + uint32_t adapter_count; + ASSERT_SUCCESS(urAdapterGet(0, nullptr, &adapter_count)); + adapters.resize(adapter_count); + ASSERT_SUCCESS(urAdapterGet(adapter_count, adapters.data(), nullptr)); + } + + void TearDown() override { + for (auto adapter : adapters) { + ASSERT_SUCCESS(urAdapterRelease(adapter)); + } + UUR_RETURN_ON_FATAL_FAILURE(urTest::TearDown()); + } + + std::vector adapters; +}; + +} // namespace runtime +} // namespace uur diff --git a/test/conformance/runtime/urAdapterGet.cpp b/test/conformance/runtime/urAdapterGet.cpp new file mode 100644 index 0000000000..2c3b62a620 --- /dev/null +++ b/test/conformance/runtime/urAdapterGet.cpp @@ -0,0 +1,22 @@ +// Copyright (C) 2022-2023 Intel Corporation +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +// See LICENSE.TXT +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include "fixtures.h" + +using urAdapterGetTest = uur::runtime::urTest; + +TEST_F(urAdapterGetTest, Success) { + uint32_t adapter_count; + ASSERT_SUCCESS(urAdapterGet(0, nullptr, &adapter_count)); + std::vector adapters(adapter_count); + ASSERT_SUCCESS(urAdapterGet(adapter_count, adapters.data(), nullptr)); +} + +TEST_F(urAdapterGetTest, InvalidNumEntries) { + uint32_t adapter_count; + ASSERT_SUCCESS(urAdapterGet(0, nullptr, &adapter_count)); + std::vector adapters(adapter_count); + ASSERT_SUCCESS(urAdapterGet(0, adapters.data(), nullptr)); +} diff --git a/test/conformance/runtime/urAdapterGetInfo.cpp b/test/conformance/runtime/urAdapterGetInfo.cpp new file mode 100644 index 0000000000..6eea5182d8 --- /dev/null +++ b/test/conformance/runtime/urAdapterGetInfo.cpp @@ -0,0 +1,89 @@ +// Copyright (C) 2022-2023 Intel Corporation +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +// See LICENSE.TXT +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include "fixtures.h" + +#include + +struct urAdapterGetInfoTest : uur::runtime::urAdapterTest, + ::testing::WithParamInterface { + + void SetUp() { + UUR_RETURN_ON_FATAL_FAILURE(uur::runtime::urAdapterTest::SetUp()); + adapter = adapters[0]; + } + + ur_adapter_handle_t adapter; +}; + +std::unordered_map adapter_info_size_map = { + {UR_ADAPTER_INFO_BACKEND, sizeof(ur_adapter_backend_t)}, + {UR_ADAPTER_INFO_REFERENCE_COUNT, sizeof(uint32_t)}, +}; + +INSTANTIATE_TEST_SUITE_P( + urAdapterGetInfo, urAdapterGetInfoTest, + ::testing::Values(UR_ADAPTER_INFO_BACKEND, UR_ADAPTER_INFO_REFERENCE_COUNT), + [](const ::testing::TestParamInfo &info) { + std::stringstream ss; + ss << info.param; + return ss.str(); + }); + +TEST_P(urAdapterGetInfoTest, Success) { + size_t size = 0; + ur_adapter_info_t info_type = GetParam(); + ASSERT_SUCCESS(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size)); + ASSERT_NE(size, 0); + + if (const auto expected_size = adapter_info_size_map.find(info_type); + expected_size != adapter_info_size_map.end()) { + ASSERT_EQ(expected_size->second, size); + } + + std::vector info_data(size); + ASSERT_SUCCESS( + urAdapterGetInfo(adapter, info_type, size, info_data.data(), nullptr)); +} + +TEST_P(urAdapterGetInfoTest, InvalidNullHandleAdapter) { + size_t size = 0; + ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, + urAdapterGetInfo(nullptr, GetParam(), 0, nullptr, &size)); +} + +TEST_F(urAdapterGetInfoTest, InvalidEnumerationAdapterInfoType) { + size_t size = 0; + ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION, + urAdapterGetInfo(adapter, UR_ADAPTER_INFO_FORCE_UINT32, 0, + nullptr, &size)); +} + +TEST_F(urAdapterGetInfoTest, InvalidSizeZero) { + ur_adapter_backend_t backend; + ASSERT_EQ_RESULT(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, 0, + &backend, nullptr), + UR_RESULT_ERROR_INVALID_SIZE); +} + +TEST_F(urAdapterGetInfoTest, InvalidSizeSmall) { + ur_adapter_backend_t backend; + ASSERT_EQ_RESULT(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, + sizeof(backend) - 1, &backend, nullptr), + UR_RESULT_ERROR_INVALID_SIZE); +} + +TEST_F(urAdapterGetInfoTest, InvalidNullPointerPropValue) { + ur_adapter_backend_t backend; + ASSERT_EQ_RESULT(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, + sizeof(backend), nullptr, nullptr), + UR_RESULT_ERROR_INVALID_NULL_POINTER); +} + +TEST_F(urAdapterGetInfoTest, InvalidNullPointerPropSizeRet) { + ASSERT_EQ_RESULT( + urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, 0, nullptr, nullptr), + UR_RESULT_ERROR_INVALID_NULL_POINTER); +} diff --git a/test/conformance/platform/urPlatformGetLastError.cpp b/test/conformance/runtime/urAdapterGetLastError.cpp similarity index 57% rename from test/conformance/platform/urPlatformGetLastError.cpp rename to test/conformance/runtime/urAdapterGetLastError.cpp index e4fbc38b21..a82b0664f0 100644 --- a/test/conformance/platform/urPlatformGetLastError.cpp +++ b/test/conformance/runtime/urAdapterGetLastError.cpp @@ -5,31 +5,31 @@ #include "fixtures.h" -struct urPlatformGetLastErrorTest : uur::platform::urPlatformTest { +struct urAdapterGetLastErrorTest : uur::runtime::urAdapterTest { int32_t error; const char *message = nullptr; }; -TEST_F(urPlatformGetLastErrorTest, Success) { +TEST_F(urAdapterGetLastErrorTest, Success) { // We can't reliably generate a UR_RESULT_ERROR_ADAPTER_SPECIFIC error to // test the full functionality of this entry point, so instead do a minimal // smoke test and check that the call returns successfully, even if no // actual error was set. ASSERT_EQ_RESULT(UR_RESULT_SUCCESS, - urPlatformGetLastError(platform, &message, &error)); + urAdapterGetLastError(adapters[0], &message, &error)); } -TEST_F(urPlatformGetLastErrorTest, InvalidHandle) { +TEST_F(urAdapterGetLastErrorTest, InvalidHandle) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, - urPlatformGetLastError(nullptr, &message, &error)); + urAdapterGetLastError(nullptr, &message, &error)); } -TEST_F(urPlatformGetLastErrorTest, InvalidMessagePtr) { +TEST_F(urAdapterGetLastErrorTest, InvalidMessagePtr) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER, - urPlatformGetLastError(platform, nullptr, &error)); + urAdapterGetLastError(adapters[0], nullptr, &error)); } -TEST_F(urPlatformGetLastErrorTest, InvalidErrorPtr) { +TEST_F(urAdapterGetLastErrorTest, InvalidErrorPtr) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER, - urPlatformGetLastError(platform, &message, nullptr)); + urAdapterGetLastError(adapters[0], &message, nullptr)); } diff --git a/test/conformance/runtime/urAdapterRelease.cpp b/test/conformance/runtime/urAdapterRelease.cpp new file mode 100644 index 0000000000..e7c5bd11ce --- /dev/null +++ b/test/conformance/runtime/urAdapterRelease.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2022-2023 Intel Corporation +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +// See LICENSE.TXT +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include "fixtures.h" + +struct urAdapterReleaseTest : uur::runtime::urAdapterTest { + void SetUp() { + UUR_RETURN_ON_FATAL_FAILURE(uur::runtime::urAdapterTest::SetUp()); + adapter = adapters[0]; + } + + ur_adapter_handle_t adapter; +}; + +TEST_F(urAdapterReleaseTest, Success) { + ASSERT_SUCCESS(urAdapterRetain(adapter)); + EXPECT_SUCCESS(urAdapterRelease(adapter)); +} + +TEST_F(urAdapterReleaseTest, InvalidNullHandleAdapter) { + ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, + urAdapterRelease(nullptr)); +} diff --git a/test/conformance/runtime/urAdapterRetain.cpp b/test/conformance/runtime/urAdapterRetain.cpp new file mode 100644 index 0000000000..2a5efd0344 --- /dev/null +++ b/test/conformance/runtime/urAdapterRetain.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2022-2023 Intel Corporation +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +// See LICENSE.TXT +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include "fixtures.h" + +struct urAdapterRetainTest : uur::runtime::urAdapterTest { + void SetUp() { + UUR_RETURN_ON_FATAL_FAILURE(uur::runtime::urAdapterTest::SetUp()); + adapter = adapters[0]; + } + + ur_adapter_handle_t adapter; +}; + +TEST_F(urAdapterRetainTest, Success) { + ASSERT_SUCCESS(urAdapterRetain(adapter)); + EXPECT_SUCCESS(urAdapterRelease(adapter)); +} + +TEST_F(urAdapterRetainTest, InvalidNullHandleAdapter) { + ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, + urAdapterRetain(nullptr)); +} diff --git a/test/conformance/source/environment.cpp b/test/conformance/source/environment.cpp index 43862b0451..287310f679 100644 --- a/test/conformance/source/environment.cpp +++ b/test/conformance/source/environment.cpp @@ -75,8 +75,13 @@ uur::PlatformEnvironment::PlatformEnvironment(int argc, char **argv) return; } + uint32_t adapter_count = 0; + urAdapterGet(0, nullptr, &adapter_count); + adapters.resize(adapter_count); + urAdapterGet(adapter_count, adapters.data(), nullptr); + uint32_t count = 0; - if (urPlatformGet(0, nullptr, &count)) { + if (urPlatformGet(adapters.data(), adapter_count, 0, nullptr, &count)) { error = "urPlatformGet() failed to get number of platforms."; return; } @@ -87,7 +92,8 @@ uur::PlatformEnvironment::PlatformEnvironment(int argc, char **argv) } std::vector platforms(count); - if (urPlatformGet(count, platforms.data(), nullptr)) { + if (urPlatformGet(adapters.data(), adapter_count, count, platforms.data(), + nullptr)) { error = "urPlatformGet failed to get platforms."; return; } @@ -150,6 +156,9 @@ void uur::PlatformEnvironment::TearDown() { if (error == ERROR_NO_ADAPTER) { return; } + for (auto adapter : adapters) { + urAdapterRelease(adapter); + } ur_tear_down_params_t tear_down_params{}; if (urTearDown(&tear_down_params)) { FAIL() << "urTearDown() failed"; diff --git a/test/conformance/testing/include/uur/environment.h b/test/conformance/testing/include/uur/environment.h index f42c5a6436..5cc6756364 100644 --- a/test/conformance/testing/include/uur/environment.h +++ b/test/conformance/testing/include/uur/environment.h @@ -28,6 +28,7 @@ struct PlatformEnvironment : ::testing::Environment { PlatformOptions parsePlatformOptions(int argc, char **argv); PlatformOptions platform_options; + std::vector adapters{}; ur_platform_handle_t platform = nullptr; std::string error; static PlatformEnvironment *instance; diff --git a/test/layers/tracing/hello_world.out.match b/test/layers/tracing/hello_world.out.match index 3df85ca49a..7658650d04 100644 --- a/test/layers/tracing/hello_world.out.match +++ b/test/layers/tracing/hello_world.out.match @@ -1,21 +1,27 @@ function_with_args_begin(1) - urInit(.device_flags = 0); function_with_args_end(1) - urInit(...) -> ur_result_t(0); Platform initialized. -function_with_args_begin(2) - urPlatformGet(unimplemented); -function_with_args_end(2) - urPlatformGet(...) -> ur_result_t(0); -function_with_args_begin(3) - urPlatformGet(unimplemented); -function_with_args_end(3) - urPlatformGet(...) -> ur_result_t(0); -function_with_args_begin(4) - urPlatformGetApiVersion(unimplemented); -function_with_args_end(4) - urPlatformGetApiVersion(...) -> ur_result_t(0); +function_with_args_begin(2) - urAdapterGet(unimplemented); +function_with_args_end(2) - urAdapterGet(...) -> ur_result_t(0); +function_with_args_begin(3) - urAdapterGet(unimplemented); +function_with_args_end(3) - urAdapterGet(...) -> ur_result_t(0); +function_with_args_begin(4) - urPlatformGet(unimplemented); +function_with_args_end(4) - urPlatformGet(...) -> ur_result_t(0); +function_with_args_begin(5) - urPlatformGet(unimplemented); +function_with_args_end(5) - urPlatformGet(...) -> ur_result_t(0); +function_with_args_begin(6) - urPlatformGetApiVersion(unimplemented); +function_with_args_end(6) - urPlatformGetApiVersion(...) -> ur_result_t(0); API version: {{0\.[0-9]+}} -function_with_args_begin(5) - urDeviceGet(unimplemented); -function_with_args_end(5) - urDeviceGet(...) -> ur_result_t(0); -function_with_args_begin(6) - urDeviceGet(unimplemented); -function_with_args_end(6) - urDeviceGet(...) -> ur_result_t(0); -function_with_args_begin(7) - urDeviceGetInfo(unimplemented); -function_with_args_end(7) - urDeviceGetInfo(...) -> ur_result_t(0); -function_with_args_begin(8) - urDeviceGetInfo(unimplemented); -function_with_args_end(8) - urDeviceGetInfo(...) -> ur_result_t(0); +function_with_args_begin(7) - urDeviceGet(unimplemented); +function_with_args_end(7) - urDeviceGet(...) -> ur_result_t(0); +function_with_args_begin(8) - urDeviceGet(unimplemented); +function_with_args_end(8) - urDeviceGet(...) -> ur_result_t(0); +function_with_args_begin(9) - urDeviceGetInfo(unimplemented); +function_with_args_end(9) - urDeviceGetInfo(...) -> ur_result_t(0); +function_with_args_begin(10) - urDeviceGetInfo(unimplemented); +function_with_args_end(10) - urDeviceGetInfo(...) -> ur_result_t(0); Found a Null Device gpu. -function_with_args_begin(9) - urTearDown(unimplemented); -function_with_args_end(9) - urTearDown(...) -> ur_result_t(0); +function_with_args_begin(11) - urAdapterRelease(unimplemented); +function_with_args_end(11) - urAdapterRelease(...) -> ur_result_t(0); +function_with_args_begin(12) - urTearDown(unimplemented); +function_with_args_end(12) - urTearDown(...) -> ur_result_t(0); diff --git a/test/layers/validation/fixtures.hpp b/test/layers/validation/fixtures.hpp index 6af67c6f00..99bc3e5acd 100644 --- a/test/layers/validation/fixtures.hpp +++ b/test/layers/validation/fixtures.hpp @@ -36,14 +36,27 @@ struct valPlatformsTest : urTest { void SetUp() override { urTest::SetUp(); + + uint32_t adapter_count; + ASSERT_EQ(urAdapterGet(0, nullptr, &adapter_count), UR_RESULT_SUCCESS); + adapters.resize(adapter_count); + ASSERT_EQ(urAdapterGet(adapter_count, adapters.data(), nullptr), + UR_RESULT_SUCCESS); + uint32_t count; - ASSERT_EQ(urPlatformGet(0, nullptr, &count), UR_RESULT_SUCCESS); + ASSERT_EQ( + urPlatformGet(adapters.data(), adapter_count, 0, nullptr, &count), + UR_RESULT_SUCCESS); ASSERT_NE(count, 0); platforms.resize(count); - ASSERT_EQ(urPlatformGet(count, platforms.data(), nullptr), + ASSERT_EQ(urPlatformGet(adapters.data(), adapter_count, count, + platforms.data(), nullptr), UR_RESULT_SUCCESS); } + void TearDown() override { urTest::TearDown(); } + + std::vector adapters; std::vector platforms; }; diff --git a/test/loader/platforms/platforms.cpp b/test/loader/platforms/platforms.cpp index c39b0af160..2a665fe8d6 100644 --- a/test/loader/platforms/platforms.cpp +++ b/test/loader/platforms/platforms.cpp @@ -31,10 +31,26 @@ int main(int argc, char *argv[]) { } info("urInit succeeded."); + uint32_t adapterCount = 0; + std::vector adapters; + status = urAdapterGet(0, nullptr, &adapterCount); + if (status != UR_RESULT_SUCCESS) { + error("urAdapterGet failed with return code: {}", status); + return 1; + } + + adapters.resize(adapterCount); + status = urAdapterGet(adapterCount, adapters.data(), nullptr); + if (status != UR_RESULT_SUCCESS) { + error("urAdapterGet failed with return code: {}", status); + return 1; + } + uint32_t platformCount = 0; std::vector platforms; - status = urPlatformGet(1, nullptr, &platformCount); + status = urPlatformGet(adapters.data(), adapterCount, 1, nullptr, + &platformCount); if (status != UR_RESULT_SUCCESS) { error("urPlatformGet failed with return code: {}", status); goto out; @@ -42,7 +58,8 @@ int main(int argc, char *argv[]) { info("urPlatformGet found {} platforms", platformCount); platforms.resize(platformCount); - status = urPlatformGet(platformCount, platforms.data(), nullptr); + status = urPlatformGet(adapters.data(), adapterCount, platformCount, + platforms.data(), nullptr); if (status != UR_RESULT_SUCCESS) { error("urPlatformGet failed with return code: {}", status); goto out; diff --git a/test/tools/urtrace/null_hello.match b/test/tools/urtrace/null_hello.match index 0c76ccac1a..b58a4d8d96 100644 --- a/test/tools/urtrace/null_hello.match +++ b/test/tools/urtrace/null_hello.match @@ -1,7 +1,9 @@ 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; +urAdapterGet(.NumEntries = 0, .phAdapters = {}, .pNumAdapters = {{.*}} (1)) -> UR_RESULT_SUCCESS; +urAdapterGet(.NumEntries = 1, .phAdapters = {{{.*}}}, .pNumAdapters = nullptr) -> UR_RESULT_SUCCESS; +urPlatformGet(.phAdapters = {{{.*}}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {}, .pNumPlatforms = {{.*}} (1)) -> UR_RESULT_SUCCESS; +urPlatformGet(.phAdapters = {{{.*}}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {{{.*}}}, .pNumPlatforms = nullptr) -> UR_RESULT_SUCCESS; urPlatformGetApiVersion(.hPlatform = {{.*}}, .pVersion = {{.*}} ({{.*}})) -> UR_RESULT_SUCCESS; API version: {{.*}} urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 0, .phDevices = {}, .pNumDevices = {{.*}} (1)) -> UR_RESULT_SUCCESS; @@ -9,4 +11,5 @@ urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_TYPE, .propSize = {{.*}}, .pPropValue = {{.*}}, .pPropSizeRet = nullptr) -> UR_RESULT_SUCCESS; urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_NAME, .propSize = {{.*}}, .pPropValue = {{.*}}, .pPropSizeRet = nullptr) -> UR_RESULT_SUCCESS; Found a Null Device gpu. +urAdapterRelease(.hAdapter = {{.*}}) -> UR_RESULT_SUCCESS; urTearDown(.pParams = nullptr) -> UR_RESULT_SUCCESS; diff --git a/test/tools/urtrace/null_hello_begin.match b/test/tools/urtrace/null_hello_begin.match index 114eedfc23..571b01bb89 100644 --- a/test/tools/urtrace/null_hello_begin.match +++ b/test/tools/urtrace/null_hello_begin.match @@ -1,21 +1,27 @@ 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; -begin(3) - urPlatformGet(.NumEntries = 1, .phPlatforms = {nullptr}, .pNumPlatforms = nullptr); -end(3) - urPlatformGet(.NumEntries = 1, .phPlatforms = {{{.*}}}, .pNumPlatforms = nullptr) -> UR_RESULT_SUCCESS; -begin(4) - urPlatformGetApiVersion(.hPlatform = {{.*}}, .pVersion = {{.*}} (0.0)); -end(4) - urPlatformGetApiVersion(.hPlatform = {{.*}}, .pVersion = {{.*}} (0.6)) -> UR_RESULT_SUCCESS; +begin(2) - urAdapterGet(.NumEntries = 0, .phAdapters = {}, .pNumAdapters = {{.*}} (0)); +end(2) - urAdapterGet(.NumEntries = 0, .phAdapters = {}, .pNumAdapters = {{.*}} (1)) -> UR_RESULT_SUCCESS; +begin(3) - urAdapterGet(.NumEntries = 1, .phAdapters = {{{.*}}}, .pNumAdapters = nullptr); +end(3) - urAdapterGet(.NumEntries = 1, .phAdapters = {{{.*}}}, .pNumAdapters = nullptr) -> UR_RESULT_SUCCESS; +begin(4) - urPlatformGet(.phAdapters = {{{.*}}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {}, .pNumPlatforms = {{.*}} (0)); +end(4) - urPlatformGet(.phAdapters = {{{.*}}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {}, .pNumPlatforms = {{.*}} (1)) -> UR_RESULT_SUCCESS; +begin(5) - urPlatformGet(.phAdapters = {{{.*}}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {nullptr}, .pNumPlatforms = nullptr); +end(5) - urPlatformGet(.phAdapters = {{{.*}}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {{{.*}}}, .pNumPlatforms = nullptr) -> UR_RESULT_SUCCESS; +begin(6) - urPlatformGetApiVersion(.hPlatform = {{.*}}, .pVersion = {{.*}} (0.0)); +end(6) - urPlatformGetApiVersion(.hPlatform = {{.*}}, .pVersion = {{.*}} (0.6)) -> UR_RESULT_SUCCESS; API version: {{.*}} -begin(5) - urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 0, .phDevices = {}, .pNumDevices = {{.*}} (0)); -end(5) - urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 0, .phDevices = {}, .pNumDevices = {{.*}} (1)) -> UR_RESULT_SUCCESS; -begin(6) - urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 1, .phDevices = {nullptr}, .pNumDevices = nullptr); -end(6) - urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 1, .phDevices = {{{.*}}}, .pNumDevices = nullptr) -> UR_RESULT_SUCCESS; -begin(7) - urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_TYPE, .propSize = 4, .pPropValue = {{.*}}, .pPropSizeRet = nullptr); -end(7) - urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_TYPE, .propSize = 4, .pPropValue = {{.*}}, .pPropSizeRet = nullptr) -> UR_RESULT_SUCCESS; -begin(8) - urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_NAME, .propSize = 1023, .pPropValue = {{.*}}, .pPropSizeRet = nullptr); -end(8) - urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_NAME, .propSize = 1023, .pPropValue = {{.*}}, .pPropSizeRet = nullptr) -> UR_RESULT_SUCCESS; +begin(7) - urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 0, .phDevices = {}, .pNumDevices = {{.*}} (0)); +end(7) - urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 0, .phDevices = {}, .pNumDevices = {{.*}} (1)) -> UR_RESULT_SUCCESS; +begin(8) - urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 1, .phDevices = {nullptr}, .pNumDevices = nullptr); +end(8) - urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 1, .phDevices = {{{.*}}}, .pNumDevices = nullptr) -> UR_RESULT_SUCCESS; +begin(9) - urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_TYPE, .propSize = 4, .pPropValue = {{.*}}, .pPropSizeRet = nullptr); +end(9) - urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_TYPE, .propSize = 4, .pPropValue = {{.*}}, .pPropSizeRet = nullptr) -> UR_RESULT_SUCCESS; +begin(10) - urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_NAME, .propSize = 1023, .pPropValue = {{.*}}, .pPropSizeRet = nullptr); +end(10) - urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_NAME, .propSize = 1023, .pPropValue = {{.*}}, .pPropSizeRet = nullptr) -> UR_RESULT_SUCCESS; Found a Null Device gpu. -begin(9) - urTearDown(.pParams = nullptr); -end(9) - urTearDown(.pParams = nullptr) -> UR_RESULT_SUCCESS; +begin(11) - urAdapterRelease(.hAdapter = {{.*}}); +end(11) - urAdapterRelease(.hAdapter = {{.*}}) -> UR_RESULT_SUCCESS; +begin(12) - urTearDown(.pParams = nullptr); +end(12) - urTearDown(.pParams = nullptr) -> UR_RESULT_SUCCESS; diff --git a/test/tools/urtrace/null_hello_json.match b/test/tools/urtrace/null_hello_json.match index 7e7c089f73..9ba4d93f62 100644 --- a/test/tools/urtrace/null_hello_json.match +++ b/test/tools/urtrace/null_hello_json.match @@ -2,8 +2,10 @@ "traceEvents": [ { "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)" }, +{ "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urAdapterGet", "args": "(.NumEntries = 0, .phAdapters = {}, .pNumAdapters = {{.*}} (1))" }, +{ "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urAdapterGet", "args": "(.NumEntries = 1, .phAdapters = {{{.*}}}, .pNumAdapters = nullptr)" }, +{ "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urPlatformGet", "args": "(.phAdapters = {{{.*}}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {}, .pNumPlatforms = {{.*}} (1))" }, +{ "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urPlatformGet", "args": "(.phAdapters = {{{.*}}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {{{.*}}}, .pNumPlatforms = nullptr)" }, { "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urPlatformGetApiVersion", "args": "(.hPlatform = {{.*}}, .pVersion = {{.*}} (0.6))" }, API version: 0.6 { "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urDeviceGet", "args": "(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 0, .phDevices = {}, .pNumDevices = {{.*}} (1))" }, @@ -11,6 +13,7 @@ API version: 0.6 { "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urDeviceGetInfo", "args": "(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_TYPE, .propSize = 4, .pPropValue = {{.*}} (UR_DEVICE_TYPE_GPU), .pPropSizeRet = nullptr)" }, { "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urDeviceGetInfo", "args": "(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_NAME, .propSize = 1023, .pPropValue = {{.*}} (Null Device), .pPropSizeRet = nullptr)" }, Found a Null Device gpu. +{ "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urAdapterRelease", "args": "(.hAdapter = {{.*}})" }, { "cat": "UR", "ph": "X", "pid": {{.*}}, "tid": {{.*}}, "ts": {{.*}}, "dur": {{.*}}, "name": "urTearDown", "args": "(.pParams = nullptr)" }, {"name": "", "cat": "", "ph": "", "pid": "", "tid": "", "ts": ""} ] diff --git a/test/tools/urtrace/null_hello_no_args.match b/test/tools/urtrace/null_hello_no_args.match index b4edbe85f7..e0afcd2868 100644 --- a/test/tools/urtrace/null_hello_no_args.match +++ b/test/tools/urtrace/null_hello_no_args.match @@ -1,5 +1,7 @@ urInit(...) -> UR_RESULT_SUCCESS; Platform initialized. +urAdapterGet(...) -> UR_RESULT_SUCCESS; +urAdapterGet(...) -> UR_RESULT_SUCCESS; urPlatformGet(...) -> UR_RESULT_SUCCESS; urPlatformGet(...) -> UR_RESULT_SUCCESS; urPlatformGetApiVersion(...) -> UR_RESULT_SUCCESS; @@ -9,4 +11,5 @@ urDeviceGet(...) -> UR_RESULT_SUCCESS; urDeviceGetInfo(...) -> UR_RESULT_SUCCESS; urDeviceGetInfo(...) -> UR_RESULT_SUCCESS; Found a Null Device gpu. +urAdapterRelease(...) -> UR_RESULT_SUCCESS; urTearDown(...) -> UR_RESULT_SUCCESS; diff --git a/test/tools/urtrace/null_hello_profiling.match b/test/tools/urtrace/null_hello_profiling.match index 3ad7ae3614..635c3c8784 100644 --- a/test/tools/urtrace/null_hello_profiling.match +++ b/test/tools/urtrace/null_hello_profiling.match @@ -1,7 +1,9 @@ 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) +urAdapterGet(.NumEntries = 0, .phAdapters = {}, .pNumAdapters = {{.*}} (1)) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) +urAdapterGet(.NumEntries = 1, .phAdapters = {{{.*}}}, .pNumAdapters = nullptr) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) +urPlatformGet(.phAdapters = {{{.*}}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {}, .pNumPlatforms = {{.*}} (1)) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) +urPlatformGet(.phAdapters = {{{.*}}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {{{.*}}}, .pNumPlatforms = nullptr) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) urPlatformGetApiVersion(.hPlatform = {{.*}}, .pVersion = {{.*}} ({{.*}})) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) API version: {{.*}} urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = 0, .phDevices = {}, .pNumDevices = {{.*}} (1)) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) @@ -9,4 +11,5 @@ urDeviceGet(.hPlatform = {{.*}}, .DeviceType = UR_DEVICE_TYPE_GPU, .NumEntries = urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_TYPE, .propSize = {{.*}}, .pPropValue = {{.*}}, .pPropSizeRet = nullptr) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) urDeviceGetInfo(.hDevice = {{.*}}, .propName = UR_DEVICE_INFO_NAME, .propSize = {{.*}}, .pPropValue = {{.*}}, .pPropSizeRet = nullptr) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) Found a Null Device gpu. +urAdapterRelease(.hAdapter = {{.*}}) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) urTearDown(.pParams = nullptr) -> UR_RESULT_SUCCESS; ({{[0-9]+}}ns) diff --git a/test/unit/utils/params.cpp b/test/unit/utils/params.cpp index da87800121..964d117e49 100644 --- a/test/unit/utils/params.cpp +++ b/test/unit/utils/params.cpp @@ -51,13 +51,19 @@ struct UrInitParamsInvalidFlags : UrInitParams { struct UrPlatformGet { ur_platform_get_params_t params; + uint32_t num_adapters; + ur_adapter_handle_t *phAdapters; uint32_t num_entries; uint32_t *pNumPlatforms; ur_platform_handle_t *pPlatforms; UrPlatformGet() { + num_adapters = 0; + phAdapters = nullptr; num_entries = 0; pPlatforms = nullptr; pNumPlatforms = nullptr; + params.pNumAdapters = &num_adapters; + params.pphAdapters = &phAdapters; params.pNumEntries = &num_entries; params.pphPlatforms = &pPlatforms; params.ppNumPlatforms = &pNumPlatforms; @@ -69,7 +75,8 @@ struct UrPlatformGet { struct UrPlatformGetEmptyArray : UrPlatformGet { UrPlatformGetEmptyArray() : UrPlatformGet() {} const char *get_expected() { - return ".NumEntries = 0, .phPlatforms = \\{\\}, .pNumPlatforms = " + return ".phAdapters = \\{\\}, .NumAdapters = 0, .NumEntries = 0, " + ".phPlatforms = \\{\\}, .pNumPlatforms = " "nullptr"; }; }; @@ -85,7 +92,8 @@ struct UrPlatformGetTwoPlatforms : UrPlatformGet { pNumPlatforms = &num_platforms; } const char *get_expected() { - return ".NumEntries = 2, .phPlatforms = \\{.+, .+\\}, " + return ".phAdapters = \\{\\}, .NumAdapters = 0, .NumEntries = 2, " + ".phPlatforms = \\{.+, .+\\}, " ".pNumPlatforms = .+ \\(2\\)"; }; };