Skip to content

Commit

Permalink
Fix to add missing zeKernelGetExp API
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 12, 2024
1 parent 3cd7e37 commit 152067a
Show file tree
Hide file tree
Showing 23 changed files with 356 additions and 10 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.6
"""
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
30 changes: 29 additions & 1 deletion 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.6
*
*/
#ifndef _ZE_API_H
Expand Down Expand Up @@ -7659,6 +7659,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.6
*
*/
#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.6
"""
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.6
*
*/
#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.6
*
*/
#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.6
"""
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.6
*
*/
#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.6
*
*/
#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 @@ -5872,6 +5897,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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions source/layers/validation/common/ze_entry_points.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
Expand Down
Loading

0 comments on commit 152067a

Please sign in to comment.