Skip to content

Commit

Permalink
Fix to add missing zeKernelGetExp API and header updates
Browse files Browse the repository at this point in the history
Signed-off-by: Neil R. Spruit <[email protected]>
  • Loading branch information
nrspruit committed Nov 13, 2024
1 parent 0a681d7 commit 5f9d031
Show file tree
Hide file tree
Showing 23 changed files with 390 additions and 34 deletions.
35 changes: 35 additions & 0 deletions include/layers/zel_tracing_register_cb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions include/ze.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SPDX-License-Identifier: MIT
@file ze.py
@version v1.11-r1.11.5
@version v1.11-r1.11.9
"""
import platform
Expand Down Expand Up @@ -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
]

###############################################################################
Expand Down Expand Up @@ -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()
Expand Down
59 changes: 46 additions & 13 deletions include/ze_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: MIT
*
* @file ze_api.h
* @version v1.11-r1.11.5
* @version v1.11-r1.11.9
*
*/
#ifndef _ZE_API_H
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion include/ze_ddi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: MIT
*
* @file ze_ddi.h
* @version v1.11-r1.11.5
* @version v1.11-r1.11.9
*
*/
#ifndef _ZE_DDI_H
Expand Down Expand Up @@ -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;

///////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion include/zes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SPDX-License-Identifier: MIT
@file zes.py
@version v1.11-r1.11.5
@version v1.11-r1.11.9
"""
import platform
Expand Down
2 changes: 1 addition & 1 deletion include/zes_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: MIT
*
* @file zes_api.h
* @version v1.11-r1.11.5
* @version v1.11-r1.11.9
*
*/
#ifndef _ZES_API_H
Expand Down
2 changes: 1 addition & 1 deletion include/zes_ddi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: MIT
*
* @file zes_ddi.h
* @version v1.11-r1.11.5
* @version v1.11-r1.11.9
*
*/
#ifndef _ZES_DDI_H
Expand Down
2 changes: 1 addition & 1 deletion include/zet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SPDX-License-Identifier: MIT
@file zet.py
@version v1.11-r1.11.5
@version v1.11-r1.11.9
"""
import platform
Expand Down
2 changes: 1 addition & 1 deletion include/zet_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: MIT
*
* @file zet_api.h
* @version v1.11-r1.11.5
* @version v1.11-r1.11.9
*
*/
#ifndef _ZET_API_H
Expand Down
2 changes: 1 addition & 1 deletion include/zet_ddi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: MIT
*
* @file zet_ddi.h
* @version v1.11-r1.11.5
* @version v1.11-r1.11.9
*
*/
#ifndef _ZET_DDI_H
Expand Down
27 changes: 27 additions & 0 deletions source/drivers/null/ze_nullddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -5876,6 +5901,8 @@ zeGetKernelExpProcAddrTable(

pDdiTable->pfnSetGlobalOffsetExp = driver::zeKernelSetGlobalOffsetExp;

pDdiTable->pfnGetBinaryExp = driver::zeKernelGetBinaryExp;

pDdiTable->pfnSchedulingHintExp = driver::zeKernelSchedulingHintExp;

return result;
Expand Down
1 change: 1 addition & 0 deletions source/layers/tracing/ze_tracing_cb_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions source/layers/tracing/ze_tracing_register_cb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
41 changes: 41 additions & 0 deletions source/layers/tracing/ze_trcddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ze_pfnKernelGetBinaryExpCb_t> 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
Expand Down Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 5f9d031

Please sign in to comment.