From b0265bb82c7b3de3de69c26f82579bf79e4186b3 Mon Sep 17 00:00:00 2001 From: "Neil R. Spruit" Date: Tue, 12 Nov 2024 07:34:49 -0800 Subject: [PATCH] Fix to add missing zeKernelGetExp API and header updates Signed-off-by: Neil R. Spruit --- include/layers/zel_tracing_register_cb.h | 35 +++++++++ include/ze.py | 13 +++- include/ze_api.h | 59 +++++++++++---- include/ze_ddi.h | 11 ++- include/zes.py | 2 +- include/zes_api.h | 2 +- include/zes_ddi.h | 2 +- include/zet.py | 2 +- include/zet_api.h | 2 +- include/zet_ddi.h | 2 +- source/drivers/null/ze_nullddi.cpp | 27 +++++++ source/layers/tracing/ze_tracing_cb_structs.h | 1 + .../layers/tracing/ze_tracing_register_cb.cpp | 16 +++++ source/layers/tracing/ze_trcddi.cpp | 41 +++++++++++ .../ze_parameter_validation.cpp | 20 ++++++ .../ze_parameter_validation.h | 1 + .../validation/common/ze_entry_points.h | 2 + .../ze_handle_lifetime.cpp | 13 ++++ .../ze_handle_lifetime.h | 1 + source/layers/validation/ze_valddi.cpp | 48 +++++++++++++ source/lib/ze_libapi.cpp | 72 +++++++++++++++---- source/lib/ze_tracing_register_cb_libapi.cpp | 25 +++++++ source/loader/ze_ldrddi.cpp | 27 +++++++ 23 files changed, 390 insertions(+), 34 deletions(-) diff --git a/include/layers/zel_tracing_register_cb.h b/include/layers/zel_tracing_register_cb.h index d70dd3b1..5341c090 100644 --- a/include/layers/zel_tracing_register_cb.h +++ b/include/layers/zel_tracing_register_cb.h @@ -1410,6 +1410,33 @@ typedef void (ZE_APICALL *ze_pfnKernelSetGlobalOffsetExpCb_t)( void** ppTracerInstanceUserData ); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Callback function parameters for zeKernelGetBinaryExp +/// @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 _ze_kernel_get_binary_exp_params_t +{ + ze_kernel_handle_t* phKernel; + size_t** ppSize; + uint8_t** ppKernelBinary; +} ze_kernel_get_binary_exp_params_t; + + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Callback function-pointer for zeKernelGetBinaryExp +/// @param[in] params Parameters passed to this instance +/// @param[in] result Return value +/// @param[in] pTracerUserData Per-Tracer user data +/// @param[in,out] ppTracerInstanceUserData Per-Tracer, Per-Instance user data + +typedef void (ZE_APICALL *ze_pfnKernelGetBinaryExpCb_t)( + ze_kernel_get_binary_exp_params_t* params, + ze_result_t result, + void* pTracerUserData, + void** ppTracerInstanceUserData + ); + /////////////////////////////////////////////////////////////////////////////// /// @brief Callback function parameters for zeKernelSchedulingHintExp /// @details Each entry is a pointer to the parameter passed to the function; @@ -3023,6 +3050,14 @@ zelTracerKernelSetGlobalOffsetExpRegisterCallback( ); +ZE_APIEXPORT ze_result_t ZE_APICALL +zelTracerKernelGetBinaryExpRegisterCallback( + zel_tracer_handle_t hTracer, + zel_tracer_reg_t callback_type, + ze_pfnKernelGetBinaryExpCb_t pfnGetBinaryExpCb + ); + + ZE_APIEXPORT ze_result_t ZE_APICALL zelTracerDeviceReserveCacheExtRegisterCallback( zel_tracer_handle_t hTracer, diff --git a/include/ze.py b/include/ze.py index 6ebee1de..d17cf647 100644 --- a/include/ze.py +++ b/include/ze.py @@ -4,7 +4,7 @@ SPDX-License-Identifier: MIT @file ze.py - @version v1.11-r1.11.5 + @version v1.11-r1.11.8 """ import platform @@ -5520,13 +5520,21 @@ class _ze_kernel_dditable_t(Structure): else: _zeKernelSchedulingHintExp_t = CFUNCTYPE( ze_result_t, ze_kernel_handle_t, POINTER(ze_scheduling_hint_exp_desc_t) ) +############################################################################### +## @brief Function-pointer for zeKernelGetBinaryExp +if __use_win_types: + _zeKernelGetBinaryExp_t = WINFUNCTYPE( ze_result_t, ze_kernel_handle_t, POINTER(c_size_t), POINTER(c_ubyte) ) +else: + _zeKernelGetBinaryExp_t = CFUNCTYPE( ze_result_t, ze_kernel_handle_t, POINTER(c_size_t), POINTER(c_ubyte) ) + ############################################################################### ## @brief Table of KernelExp functions pointers class _ze_kernel_exp_dditable_t(Structure): _fields_ = [ ("pfnSetGlobalOffsetExp", c_void_p), ## _zeKernelSetGlobalOffsetExp_t - ("pfnSchedulingHintExp", c_void_p) ## _zeKernelSchedulingHintExp_t + ("pfnSchedulingHintExp", c_void_p), ## _zeKernelSchedulingHintExp_t + ("pfnGetBinaryExp", c_void_p) ## _zeKernelGetBinaryExp_t ] ############################################################################### @@ -6129,6 +6137,7 @@ def __init__(self, version : ze_api_version_t): # attach function interface to function address self.zeKernelSetGlobalOffsetExp = _zeKernelSetGlobalOffsetExp_t(self.__dditable.KernelExp.pfnSetGlobalOffsetExp) self.zeKernelSchedulingHintExp = _zeKernelSchedulingHintExp_t(self.__dditable.KernelExp.pfnSchedulingHintExp) + self.zeKernelGetBinaryExp = _zeKernelGetBinaryExp_t(self.__dditable.KernelExp.pfnGetBinaryExp) # call driver to get function pointers _Sampler = _ze_sampler_dditable_t() diff --git a/include/ze_api.h b/include/ze_api.h index d6fa7f1f..dc57f4d4 100644 --- a/include/ze_api.h +++ b/include/ze_api.h @@ -5,7 +5,7 @@ * SPDX-License-Identifier: MIT * * @file ze_api.h - * @version v1.11-r1.11.5 + * @version v1.11-r1.11.8 * */ #ifndef _ZE_API_H @@ -968,8 +968,9 @@ typedef enum _ze_init_flag_t /// @brief Initialize the 'oneAPI' driver(s) /// /// @details -/// - The application must call this function before calling any other -/// function. +/// - @deprecated since 1.10. Please use zeInitDrivers() +/// - The application must call this function or zeInitDrivers before +/// calling any other function. /// - If this function is not called then all other functions will return /// ::ZE_RESULT_ERROR_UNINITIALIZED. /// - Only one instance of each driver will be initialized per process. @@ -999,6 +1000,10 @@ zeInit( /// @brief Retrieves driver instances /// /// @details +/// - @deprecated since 1.10. Please use zeInitDrivers() +/// - Usage of zeInitDrivers and zeDriverGet is mutually exclusive and +/// should not be used together. Usage of them together will result in +/// undefined behavior. /// - A driver represents a collection of physical devices. /// - Multiple calls to this function will return identical driver handles, /// in the same order. @@ -1075,20 +1080,20 @@ typedef struct _ze_init_driver_type_desc_t /// /// @details /// - The application must call this function or zeInit before calling any -/// other function. -/// - The application can call InitDrivers or zeInit to init the drivers on -/// the system. -/// - Calls to zeInit or InitDrivers will not alter the drivers retrieved -/// thru either api. -/// - Drivers init thru zeInit or InitDrivers will not be reInitialized once -/// init in an application. The Loader will determine if the already init -/// driver needs to be delivered to the user thru the init type flags. +/// other function. (zeInit is [Deprecated] and is replaced by +/// zeInitDrivers) +/// - Calls to zeInit[Deprecated] or InitDrivers will not alter the drivers +/// retrieved thru either api. +/// - Drivers init thru zeInit[Deprecated] or InitDrivers will not be +/// reInitialized once init in an application. The Loader will determine +/// if the already init driver needs to be delivered to the user thru the +/// init type flags. /// - Already init Drivers will not be uninitialized if the call to /// InitDrivers does not include that driver's type. Those init drivers /// which don't match the init flags will not have their driver handles /// returned to the user in that InitDrivers call. -/// - If this function or zeInit is not called, then all other functions -/// will return ::ZE_RESULT_ERROR_UNINITIALIZED. +/// - If this function or zeInit[Deprecated] is not called, then all other +/// functions will return ::ZE_RESULT_ERROR_UNINITIALIZED. /// - Only one instance of each driver will be initialized per process. /// - A driver represents a collection of physical devices. /// - Multiple calls to this function will return identical driver handles, @@ -7659,6 +7664,34 @@ typedef struct _ze_relaxed_allocation_limits_exp_desc_t #define ZE_GET_KERNEL_BINARY_EXP_NAME "ZE_extension_kernel_binary_exp" #endif // ZE_GET_KERNEL_BINARY_EXP_NAME +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves kernel binary program data (ISA GEN format). +/// +/// @details +/// - A valid kernel handle must be created with ::zeKernelCreate. +/// - Returns Intel Graphics Assembly (GEN ISA) format binary program data +/// for kernel handle. +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function must be thread-safe. +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_UNINITIALIZED +/// - ::ZE_RESULT_ERROR_DEVICE_LOST +/// - ::ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY +/// - ::ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY +/// - ::ZE_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `nullptr == hKernel` +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// + `nullptr == pSize` +/// + `nullptr == pKernelBinary` +ZE_APIEXPORT ze_result_t ZE_APICALL +zeKernelGetBinaryExp( + ze_kernel_handle_t hKernel, ///< [in] Kernel handle. + size_t* pSize, ///< [in,out] pointer to variable with size of GEN ISA binary. + uint8_t* pKernelBinary ///< [in,out] pointer to storage area for GEN ISA binary function. + ); + #if !defined(__GNUC__) #pragma endregion #endif diff --git a/include/ze_ddi.h b/include/ze_ddi.h index 5e0a6f36..e06ef343 100644 --- a/include/ze_ddi.h +++ b/include/ze_ddi.h @@ -5,7 +5,7 @@ * SPDX-License-Identifier: MIT * * @file ze_ddi.h - * @version v1.11-r1.11.5 + * @version v1.11-r1.11.8 * */ #ifndef _ZE_DDI_H @@ -2196,12 +2196,21 @@ typedef ze_result_t (ZE_APICALL *ze_pfnKernelSchedulingHintExp_t)( ze_scheduling_hint_exp_desc_t* ); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for zeKernelGetBinaryExp +typedef ze_result_t (ZE_APICALL *ze_pfnKernelGetBinaryExp_t)( + ze_kernel_handle_t, + size_t*, + uint8_t* + ); + /////////////////////////////////////////////////////////////////////////////// /// @brief Table of KernelExp functions pointers typedef struct _ze_kernel_exp_dditable_t { ze_pfnKernelSetGlobalOffsetExp_t pfnSetGlobalOffsetExp; ze_pfnKernelSchedulingHintExp_t pfnSchedulingHintExp; + ze_pfnKernelGetBinaryExp_t pfnGetBinaryExp; } ze_kernel_exp_dditable_t; /////////////////////////////////////////////////////////////////////////////// diff --git a/include/zes.py b/include/zes.py index 478de47c..dc4af648 100644 --- a/include/zes.py +++ b/include/zes.py @@ -4,7 +4,7 @@ SPDX-License-Identifier: MIT @file zes.py - @version v1.11-r1.11.5 + @version v1.11-r1.11.8 """ import platform diff --git a/include/zes_api.h b/include/zes_api.h index 31be495b..874643ce 100644 --- a/include/zes_api.h +++ b/include/zes_api.h @@ -5,7 +5,7 @@ * SPDX-License-Identifier: MIT * * @file zes_api.h - * @version v1.11-r1.11.5 + * @version v1.11-r1.11.8 * */ #ifndef _ZES_API_H diff --git a/include/zes_ddi.h b/include/zes_ddi.h index 30b0d266..27ef4403 100644 --- a/include/zes_ddi.h +++ b/include/zes_ddi.h @@ -5,7 +5,7 @@ * SPDX-License-Identifier: MIT * * @file zes_ddi.h - * @version v1.11-r1.11.5 + * @version v1.11-r1.11.8 * */ #ifndef _ZES_DDI_H diff --git a/include/zet.py b/include/zet.py index f7f98ab2..993e7383 100644 --- a/include/zet.py +++ b/include/zet.py @@ -4,7 +4,7 @@ SPDX-License-Identifier: MIT @file zet.py - @version v1.11-r1.11.5 + @version v1.11-r1.11.8 """ import platform diff --git a/include/zet_api.h b/include/zet_api.h index 7660f3fa..15c74eb5 100644 --- a/include/zet_api.h +++ b/include/zet_api.h @@ -5,7 +5,7 @@ * SPDX-License-Identifier: MIT * * @file zet_api.h - * @version v1.11-r1.11.5 + * @version v1.11-r1.11.8 * */ #ifndef _ZET_API_H diff --git a/include/zet_ddi.h b/include/zet_ddi.h index 79047372..8d6d7c0d 100644 --- a/include/zet_ddi.h +++ b/include/zet_ddi.h @@ -5,7 +5,7 @@ * SPDX-License-Identifier: MIT * * @file zet_ddi.h - * @version v1.11-r1.11.5 + * @version v1.11-r1.11.8 * */ #ifndef _ZET_DDI_H diff --git a/source/drivers/null/ze_nullddi.cpp b/source/drivers/null/ze_nullddi.cpp index e4fd220e..4eb10ddb 100644 --- a/source/drivers/null/ze_nullddi.cpp +++ b/source/drivers/null/ze_nullddi.cpp @@ -3969,6 +3969,31 @@ namespace driver return result; } + /////////////////////////////////////////////////////////////////////////////// + /// @brief Intercept function for zeKernelGetBinaryExp + __zedlllocal ze_result_t ZE_APICALL + zeKernelGetBinaryExp( + ze_kernel_handle_t hKernel, ///< [in] Kernel handle. + size_t* pSize, ///< [in,out] pointer to variable with size of GEN ISA binary. + uint8_t* pKernelBinary ///< [in,out] pointer to storage area for GEN ISA binary function. + ) + { + ze_result_t result = ZE_RESULT_SUCCESS; + + // if the driver has created a custom function, then call it instead of using the generic path + auto pfnGetBinaryExp = context.zeDdiTable.KernelExp.pfnGetBinaryExp; + if( nullptr != pfnGetBinaryExp ) + { + result = pfnGetBinaryExp( hKernel, pSize, pKernelBinary ); + } + else + { + // generic implementation + } + + return result; + } + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for zeDeviceReserveCacheExt __zedlllocal ze_result_t ZE_APICALL @@ -5876,6 +5901,8 @@ zeGetKernelExpProcAddrTable( pDdiTable->pfnSetGlobalOffsetExp = driver::zeKernelSetGlobalOffsetExp; + pDdiTable->pfnGetBinaryExp = driver::zeKernelGetBinaryExp; + pDdiTable->pfnSchedulingHintExp = driver::zeKernelSchedulingHintExp; return result; diff --git a/source/layers/tracing/ze_tracing_cb_structs.h b/source/layers/tracing/ze_tracing_cb_structs.h index 26ab1632..601e66cf 100644 --- a/source/layers/tracing/ze_tracing_cb_structs.h +++ b/source/layers/tracing/ze_tracing_cb_structs.h @@ -235,6 +235,7 @@ typedef struct _zel_kernel_callbacks_t ze_pfnKernelGetPropertiesCb_t pfnGetPropertiesCb; ze_pfnKernelGetNameCb_t pfnGetNameCb; ze_pfnKernelSetGlobalOffsetExpCb_t pfnSetGlobalOffsetExpCb; + ze_pfnKernelGetBinaryExpCb_t pfnGetBinaryExpCb; ze_pfnKernelSchedulingHintExpCb_t pfnSchedulingHintExpCb; } zel_kernel_callbacks_t; diff --git a/source/layers/tracing/ze_tracing_register_cb.cpp b/source/layers/tracing/ze_tracing_register_cb.cpp index 7eb97a2f..3ccdc516 100644 --- a/source/layers/tracing/ze_tracing_register_cb.cpp +++ b/source/layers/tracing/ze_tracing_register_cb.cpp @@ -2355,6 +2355,22 @@ zelTracerKernelSetGlobalOffsetExpRegisterCallback( } +ZE_DLLEXPORT ze_result_t ZE_APICALL +zelTracerKernelGetBinaryExpRegisterCallback( + zel_tracer_handle_t hTracer, + zel_tracer_reg_t callback_type, + ze_pfnKernelGetBinaryExpCb_t pfnGetBinaryExpCb + ) { + + ze_result_t result; + auto& cbs = tracing_layer::APITracer::fromHandle(hTracer)->getProEpilogues(callback_type, result); + if (result == ZE_RESULT_SUCCESS) + cbs.Kernel.pfnGetBinaryExpCb = pfnGetBinaryExpCb; + + return result; +} + + ZE_DLLEXPORT ze_result_t ZE_APICALL zelTracerDeviceReserveCacheExtRegisterCallback( zel_tracer_handle_t hTracer, diff --git a/source/layers/tracing/ze_trcddi.cpp b/source/layers/tracing/ze_trcddi.cpp index d4d16f3f..5342ffea 100644 --- a/source/layers/tracing/ze_trcddi.cpp +++ b/source/layers/tracing/ze_trcddi.cpp @@ -5827,6 +5827,44 @@ namespace tracing_layer *tracerParams.poffsetZ); } + /////////////////////////////////////////////////////////////////////////////// + /// @brief Intercept function for zeKernelGetBinaryExp + __zedlllocal ze_result_t ZE_APICALL + zeKernelGetBinaryExp( + ze_kernel_handle_t hKernel, ///< [in] Kernel handle. + size_t* pSize, ///< [in,out] pointer to variable with size of GEN ISA binary. + uint8_t* pKernelBinary ///< [in,out] pointer to storage area for GEN ISA binary function. + ) + { + auto pfnGetBinaryExp = context.zeDdiTable.KernelExp.pfnGetBinaryExp; + + if( nullptr == pfnGetBinaryExp) + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + + ZE_HANDLE_TRACER_RECURSION(context.zeDdiTable.KernelExp.pfnGetBinaryExp, hKernel, pSize, pKernelBinary); + + // capture parameters + ze_kernel_get_binary_exp_params_t tracerParams = { + &hKernel, + &pSize, + &pKernelBinary + }; + + tracing_layer::APITracerCallbackDataImp apiCallbackData; + + ZE_GEN_PER_API_CALLBACK_STATE(apiCallbackData, ze_pfnKernelGetBinaryExpCb_t, Kernel, pfnGetBinaryExpCb); + + + return tracing_layer::APITracerWrapperImp(context.zeDdiTable.KernelExp.pfnGetBinaryExp, + &tracerParams, + apiCallbackData.apiOrdinal, + apiCallbackData.prologCallbacks, + apiCallbackData.epilogCallbacks, + *tracerParams.phKernel, + *tracerParams.ppSize, + *tracerParams.ppKernelBinary); + } + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for zeDeviceReserveCacheExt __zedlllocal ze_result_t ZE_APICALL @@ -8470,6 +8508,9 @@ zeGetKernelExpProcAddrTable( dditable.pfnSetGlobalOffsetExp = pDdiTable->pfnSetGlobalOffsetExp; pDdiTable->pfnSetGlobalOffsetExp = tracing_layer::zeKernelSetGlobalOffsetExp; + dditable.pfnGetBinaryExp = pDdiTable->pfnGetBinaryExp; + pDdiTable->pfnGetBinaryExp = tracing_layer::zeKernelGetBinaryExp; + dditable.pfnSchedulingHintExp = pDdiTable->pfnSchedulingHintExp; pDdiTable->pfnSchedulingHintExp = tracing_layer::zeKernelSchedulingHintExp; diff --git a/source/layers/validation/checkers/parameter_validation/ze_parameter_validation.cpp b/source/layers/validation/checkers/parameter_validation/ze_parameter_validation.cpp index a848bccf..89fdccc1 100644 --- a/source/layers/validation/checkers/parameter_validation/ze_parameter_validation.cpp +++ b/source/layers/validation/checkers/parameter_validation/ze_parameter_validation.cpp @@ -3044,6 +3044,26 @@ namespace validation_layer } + ze_result_t + ZEParameterValidation::zeKernelGetBinaryExpPrologue( + ze_kernel_handle_t hKernel, ///< [in] Kernel handle. + size_t* pSize, ///< [in,out] pointer to variable with size of GEN ISA binary. + uint8_t* pKernelBinary ///< [in,out] pointer to storage area for GEN ISA binary function. + ) + { + if( nullptr == hKernel ) + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + + if( nullptr == pSize ) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + if( nullptr == pKernelBinary ) + return ZE_RESULT_ERROR_INVALID_NULL_POINTER; + + return ZE_RESULT_SUCCESS; + } + + ze_result_t ZEParameterValidation::zeDeviceReserveCacheExtPrologue( ze_device_handle_t hDevice, ///< [in] handle of the device object diff --git a/source/layers/validation/checkers/parameter_validation/ze_parameter_validation.h b/source/layers/validation/checkers/parameter_validation/ze_parameter_validation.h index f84ed21f..d193a1be 100644 --- a/source/layers/validation/checkers/parameter_validation/ze_parameter_validation.h +++ b/source/layers/validation/checkers/parameter_validation/ze_parameter_validation.h @@ -166,6 +166,7 @@ namespace validation_layer ze_result_t zeVirtualMemSetAccessAttributePrologue( ze_context_handle_t hContext, const void* ptr, size_t size, ze_memory_access_attribute_t access ) override; ze_result_t zeVirtualMemGetAccessAttributePrologue( ze_context_handle_t hContext, const void* ptr, size_t size, ze_memory_access_attribute_t* access, size_t* outSize ) override; ze_result_t zeKernelSetGlobalOffsetExpPrologue( ze_kernel_handle_t hKernel, uint32_t offsetX, uint32_t offsetY, uint32_t offsetZ ) override; + ze_result_t zeKernelGetBinaryExpPrologue( ze_kernel_handle_t hKernel, size_t* pSize, uint8_t* pKernelBinary ) override; ze_result_t zeDeviceReserveCacheExtPrologue( ze_device_handle_t hDevice, size_t cacheLevel, size_t cacheReservationSize ) override; ze_result_t zeDeviceSetCacheAdviceExtPrologue( ze_device_handle_t hDevice, void* ptr, size_t regionSize, ze_cache_ext_region_t cacheRegion ) override; ze_result_t zeEventQueryTimestampsExpPrologue( ze_event_handle_t hEvent, ze_device_handle_t hDevice, uint32_t* pCount, ze_kernel_timestamp_result_t* pTimestamps ) override; diff --git a/source/layers/validation/common/ze_entry_points.h b/source/layers/validation/common/ze_entry_points.h index 539aaf0e..dfd8c900 100644 --- a/source/layers/validation/common/ze_entry_points.h +++ b/source/layers/validation/common/ze_entry_points.h @@ -309,6 +309,8 @@ class ZEValidationEntryPoints { virtual ze_result_t zeVirtualMemGetAccessAttributeEpilogue( ze_context_handle_t hContext, const void* ptr, size_t size, ze_memory_access_attribute_t* access, size_t* outSize ) {return ZE_RESULT_SUCCESS;} virtual ze_result_t zeKernelSetGlobalOffsetExpPrologue( ze_kernel_handle_t hKernel, uint32_t offsetX, uint32_t offsetY, uint32_t offsetZ ) {return ZE_RESULT_SUCCESS;} virtual ze_result_t zeKernelSetGlobalOffsetExpEpilogue( ze_kernel_handle_t hKernel, uint32_t offsetX, uint32_t offsetY, uint32_t offsetZ ) {return ZE_RESULT_SUCCESS;} + virtual ze_result_t zeKernelGetBinaryExpPrologue( ze_kernel_handle_t hKernel, size_t* pSize, uint8_t* pKernelBinary ) {return ZE_RESULT_SUCCESS;} + virtual ze_result_t zeKernelGetBinaryExpEpilogue( ze_kernel_handle_t hKernel, size_t* pSize, uint8_t* pKernelBinary ) {return ZE_RESULT_SUCCESS;} virtual ze_result_t zeDeviceReserveCacheExtPrologue( ze_device_handle_t hDevice, size_t cacheLevel, size_t cacheReservationSize ) {return ZE_RESULT_SUCCESS;} virtual ze_result_t zeDeviceReserveCacheExtEpilogue( ze_device_handle_t hDevice, size_t cacheLevel, size_t cacheReservationSize ) {return ZE_RESULT_SUCCESS;} virtual ze_result_t zeDeviceSetCacheAdviceExtPrologue( ze_device_handle_t hDevice, void* ptr, size_t regionSize, ze_cache_ext_region_t cacheRegion ) {return ZE_RESULT_SUCCESS;} diff --git a/source/layers/validation/handle_lifetime_tracking/ze_handle_lifetime.cpp b/source/layers/validation/handle_lifetime_tracking/ze_handle_lifetime.cpp index a36d224a..7edec245 100644 --- a/source/layers/validation/handle_lifetime_tracking/ze_handle_lifetime.cpp +++ b/source/layers/validation/handle_lifetime_tracking/ze_handle_lifetime.cpp @@ -2497,6 +2497,19 @@ namespace validation_layer return ZE_RESULT_SUCCESS; } ze_result_t + ZEHandleLifetimeValidation::zeKernelGetBinaryExpPrologue( + ze_kernel_handle_t hKernel, ///< [in] Kernel handle. + size_t* pSize, ///< [in,out] pointer to variable with size of GEN ISA binary. + uint8_t* pKernelBinary ///< [in,out] pointer to storage area for GEN ISA binary function. + ) + { + + if ( !context.handleLifetime->isHandleValid( hKernel )){ + return ZE_RESULT_ERROR_INVALID_NULL_HANDLE; + } + return ZE_RESULT_SUCCESS; + } + ze_result_t ZEHandleLifetimeValidation::zeDeviceReserveCacheExtPrologue( ze_device_handle_t hDevice, ///< [in] handle of the device object size_t cacheLevel, ///< [in] cache level where application want to reserve. If zero, then the diff --git a/source/layers/validation/handle_lifetime_tracking/ze_handle_lifetime.h b/source/layers/validation/handle_lifetime_tracking/ze_handle_lifetime.h index a19d057e..d0d7635f 100644 --- a/source/layers/validation/handle_lifetime_tracking/ze_handle_lifetime.h +++ b/source/layers/validation/handle_lifetime_tracking/ze_handle_lifetime.h @@ -162,6 +162,7 @@ namespace validation_layer ze_result_t zeVirtualMemSetAccessAttributePrologue( ze_context_handle_t hContext, const void* ptr, size_t size, ze_memory_access_attribute_t access ) override; ze_result_t zeVirtualMemGetAccessAttributePrologue( ze_context_handle_t hContext, const void* ptr, size_t size, ze_memory_access_attribute_t* access, size_t* outSize ) override; ze_result_t zeKernelSetGlobalOffsetExpPrologue( ze_kernel_handle_t hKernel, uint32_t offsetX, uint32_t offsetY, uint32_t offsetZ ) override; + ze_result_t zeKernelGetBinaryExpPrologue( ze_kernel_handle_t hKernel, size_t* pSize, uint8_t* pKernelBinary ) override; ze_result_t zeDeviceReserveCacheExtPrologue( ze_device_handle_t hDevice, size_t cacheLevel, size_t cacheReservationSize ) override; ze_result_t zeDeviceSetCacheAdviceExtPrologue( ze_device_handle_t hDevice, void* ptr, size_t regionSize, ze_cache_ext_region_t cacheRegion ) override; ze_result_t zeEventQueryTimestampsExpPrologue( ze_event_handle_t hEvent, ze_device_handle_t hDevice, uint32_t* pCount, ze_kernel_timestamp_result_t* pTimestamps ) override; diff --git a/source/layers/validation/ze_valddi.cpp b/source/layers/validation/ze_valddi.cpp index 42251228..c639f521 100644 --- a/source/layers/validation/ze_valddi.cpp +++ b/source/layers/validation/ze_valddi.cpp @@ -6381,6 +6381,51 @@ namespace validation_layer return result; } + /////////////////////////////////////////////////////////////////////////////// + /// @brief Intercept function for zeKernelGetBinaryExp + __zedlllocal ze_result_t ZE_APICALL + zeKernelGetBinaryExp( + ze_kernel_handle_t hKernel, ///< [in] Kernel handle. + size_t* pSize, ///< [in,out] pointer to variable with size of GEN ISA binary. + uint8_t* pKernelBinary ///< [in,out] pointer to storage area for GEN ISA binary function. + ) + { + auto pfnGetBinaryExp = context.zeDdiTable.KernelExp.pfnGetBinaryExp; + + if( nullptr == pfnGetBinaryExp ) + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + + auto numValHandlers = context.validationHandlers.size(); + for (size_t i = 0; i < numValHandlers; i++) { + auto result = context.validationHandlers[i]->zeValidation->zeKernelGetBinaryExpPrologue( hKernel, pSize, pKernelBinary ); + if(result!=ZE_RESULT_SUCCESS) return result; + } + + + if( context.enableThreadingValidation ){ + //Unimplemented + } + + + if(context.enableHandleLifetime ){ + auto result = context.handleLifetime->zeHandleLifetime.zeKernelGetBinaryExpPrologue( hKernel, pSize, pKernelBinary ); + if(result!=ZE_RESULT_SUCCESS) return result; + } + + auto result = pfnGetBinaryExp( hKernel, pSize, pKernelBinary ); + + for (size_t i = 0; i < numValHandlers; i++) { + auto result = context.validationHandlers[i]->zeValidation->zeKernelGetBinaryExpEpilogue( hKernel, pSize, pKernelBinary ); + if(result!=ZE_RESULT_SUCCESS) return result; + } + + + if( result == ZE_RESULT_SUCCESS && context.enableHandleLifetime ){ + + } + return result; + } + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for zeDeviceReserveCacheExt __zedlllocal ze_result_t ZE_APICALL @@ -9246,6 +9291,9 @@ zeGetKernelExpProcAddrTable( dditable.pfnSetGlobalOffsetExp = pDdiTable->pfnSetGlobalOffsetExp; pDdiTable->pfnSetGlobalOffsetExp = validation_layer::zeKernelSetGlobalOffsetExp; + dditable.pfnGetBinaryExp = pDdiTable->pfnGetBinaryExp; + pDdiTable->pfnGetBinaryExp = validation_layer::zeKernelGetBinaryExp; + dditable.pfnSchedulingHintExp = pDdiTable->pfnSchedulingHintExp; pDdiTable->pfnSchedulingHintExp = validation_layer::zeKernelSchedulingHintExp; diff --git a/source/lib/ze_libapi.cpp b/source/lib/ze_libapi.cpp index c93e19c8..3f7ed2bc 100644 --- a/source/lib/ze_libapi.cpp +++ b/source/lib/ze_libapi.cpp @@ -17,8 +17,9 @@ extern "C" { /// @brief Initialize the 'oneAPI' driver(s) /// /// @details -/// - The application must call this function before calling any other -/// function. +/// - @deprecated since 1.10. Please use zeInitDrivers() +/// - The application must call this function or zeInitDrivers before +/// calling any other function. /// - If this function is not called then all other functions will return /// ::ZE_RESULT_ERROR_UNINITIALIZED. /// - Only one instance of each driver will be initialized per process. @@ -78,6 +79,10 @@ zeInit( /// @brief Retrieves driver instances /// /// @details +/// - @deprecated since 1.10. Please use zeInitDrivers() +/// - Usage of zeInitDrivers and zeDriverGet is mutually exclusive and +/// should not be used together. Usage of them together will result in +/// undefined behavior. /// - A driver represents a collection of physical devices. /// - Multiple calls to this function will return identical driver handles, /// in the same order. @@ -136,20 +141,20 @@ zeDriverGet( /// /// @details /// - The application must call this function or zeInit before calling any -/// other function. -/// - The application can call InitDrivers or zeInit to init the drivers on -/// the system. -/// - Calls to zeInit or InitDrivers will not alter the drivers retrieved -/// thru either api. -/// - Drivers init thru zeInit or InitDrivers will not be reInitialized once -/// init in an application. The Loader will determine if the already init -/// driver needs to be delivered to the user thru the init type flags. +/// other function. (zeInit is [Deprecated] and is replaced by +/// zeInitDrivers) +/// - Calls to zeInit[Deprecated] or InitDrivers will not alter the drivers +/// retrieved thru either api. +/// - Drivers init thru zeInit[Deprecated] or InitDrivers will not be +/// reInitialized once init in an application. The Loader will determine +/// if the already init driver needs to be delivered to the user thru the +/// init type flags. /// - Already init Drivers will not be uninitialized if the call to /// InitDrivers does not include that driver's type. Those init drivers /// which don't match the init flags will not have their driver handles /// returned to the user in that InitDrivers call. -/// - If this function or zeInit is not called, then all other functions -/// will return ::ZE_RESULT_ERROR_UNINITIALIZED. +/// - If this function or zeInit[Deprecated] is not called, then all other +/// functions will return ::ZE_RESULT_ERROR_UNINITIALIZED. /// - Only one instance of each driver will be initialized per process. /// - A driver represents a collection of physical devices. /// - Multiple calls to this function will return identical driver handles, @@ -7046,6 +7051,49 @@ zeKernelSetGlobalOffsetExp( return pfnSetGlobalOffsetExp( hKernel, offsetX, offsetY, offsetZ ); } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Retrieves kernel binary program data (ISA GEN format). +/// +/// @details +/// - A valid kernel handle must be created with ::zeKernelCreate. +/// - Returns Intel Graphics Assembly (GEN ISA) format binary program data +/// for kernel handle. +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function must be thread-safe. +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_UNINITIALIZED +/// - ::ZE_RESULT_ERROR_DEVICE_LOST +/// - ::ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY +/// - ::ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY +/// - ::ZE_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `nullptr == hKernel` +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// + `nullptr == pSize` +/// + `nullptr == pKernelBinary` +ze_result_t ZE_APICALL +zeKernelGetBinaryExp( + ze_kernel_handle_t hKernel, ///< [in] Kernel handle. + size_t* pSize, ///< [in,out] pointer to variable with size of GEN ISA binary. + uint8_t* pKernelBinary ///< [in,out] pointer to storage area for GEN ISA binary function. + ) +{ + if(ze_lib::context->inTeardown) { + return ZE_RESULT_ERROR_UNINITIALIZED; + } + + auto pfnGetBinaryExp = ze_lib::context->zeDdiTable.load()->KernelExp.pfnGetBinaryExp; + if( nullptr == pfnGetBinaryExp ) { + if(!ze_lib::context->isInitialized) + return ZE_RESULT_ERROR_UNINITIALIZED; + else + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + return pfnGetBinaryExp( hKernel, pSize, pKernelBinary ); +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Reserve Cache on Device /// diff --git a/source/lib/ze_tracing_register_cb_libapi.cpp b/source/lib/ze_tracing_register_cb_libapi.cpp index 7f2ea268..1f85cfdb 100644 --- a/source/lib/ze_tracing_register_cb_libapi.cpp +++ b/source/lib/ze_tracing_register_cb_libapi.cpp @@ -3668,6 +3668,31 @@ zelTracerKernelSetGlobalOffsetExpRegisterCallback( } +ZE_APIEXPORT ze_result_t ZE_APICALL +zelTracerKernelGetBinaryExpRegisterCallback( + zel_tracer_handle_t hTracer, + zel_tracer_reg_t callback_type, + ze_pfnKernelGetBinaryExpCb_t pfnGetBinaryExpCb + ) { + + if(!ze_lib::context->tracing_lib) + return ZE_RESULT_ERROR_UNINITIALIZED; + typedef ze_result_t (ZE_APICALL *ze_pfnSetCallback_t)( + zel_tracer_handle_t hTracer, + zel_tracer_reg_t callback_type, + ze_pfnKernelGetBinaryExpCb_t pfnGetBinaryExpCb + ); + + auto func = reinterpret_cast( + GET_FUNCTION_PTR(ze_lib::context->tracing_lib, "zelTracerKernelGetBinaryExpRegisterCallback") ); + + if(func) + return func(hTracer, callback_type, pfnGetBinaryExpCb); + + return ZE_RESULT_ERROR_UNINITIALIZED; +} + + ZE_APIEXPORT ze_result_t ZE_APICALL zelTracerDeviceReserveCacheExtRegisterCallback( zel_tracer_handle_t hTracer, diff --git a/source/loader/ze_ldrddi.cpp b/source/loader/ze_ldrddi.cpp index b0d1dcd8..d99f5100 100644 --- a/source/loader/ze_ldrddi.cpp +++ b/source/loader/ze_ldrddi.cpp @@ -4859,6 +4859,32 @@ namespace loader return result; } + /////////////////////////////////////////////////////////////////////////////// + /// @brief Intercept function for zeKernelGetBinaryExp + __zedlllocal ze_result_t ZE_APICALL + zeKernelGetBinaryExp( + ze_kernel_handle_t hKernel, ///< [in] Kernel handle. + size_t* pSize, ///< [in,out] pointer to variable with size of GEN ISA binary. + uint8_t* pKernelBinary ///< [in,out] pointer to storage area for GEN ISA binary function. + ) + { + ze_result_t result = ZE_RESULT_SUCCESS; + + // extract driver's function pointer table + auto dditable = reinterpret_cast( hKernel )->dditable; + auto pfnGetBinaryExp = dditable->ze.KernelExp.pfnGetBinaryExp; + if( nullptr == pfnGetBinaryExp ) + return ZE_RESULT_ERROR_UNINITIALIZED; + + // convert loader handle to driver handle + hKernel = reinterpret_cast( hKernel )->handle; + + // forward to device-driver + result = pfnGetBinaryExp( hKernel, pSize, pKernelBinary ); + + return result; + } + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for zeDeviceReserveCacheExt __zedlllocal ze_result_t ZE_APICALL @@ -8075,6 +8101,7 @@ zeGetKernelExpProcAddrTable( { // return pointers to loader's DDIs pDdiTable->pfnSetGlobalOffsetExp = loader::zeKernelSetGlobalOffsetExp; + pDdiTable->pfnGetBinaryExp = loader::zeKernelGetBinaryExp; pDdiTable->pfnSchedulingHintExp = loader::zeKernelSchedulingHintExp; } else