Skip to content

Commit 1577f45

Browse files
Add Dynamic Tracing Support for Zer API's (#387)
* Add Dynamic Tracing Support for Zer API's Signed-off-by: Vishnu Khanth <[email protected]>
1 parent a93cb08 commit 1577f45

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

source/lib/ze_lib.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,21 @@ namespace ze_lib
177177
return ZE_RESULT_ERROR_UNINITIALIZED;
178178
}
179179
tracing_lib = getTracing();
180-
typedef ze_result_t (ZE_APICALL *zelLoaderTracingLayerInit_t)(std::atomic<ze_dditable_t *> &zeDdiTable);
181-
auto loaderTracingLayerInit = reinterpret_cast<zelLoaderTracingLayerInit_t>(
180+
typedef ze_result_t (ZE_APICALL *zelLoaderZeTracingLayerInit_t)(std::atomic<ze_dditable_t *> &zeDdiTable);
181+
auto loaderZeTracingLayerInit = reinterpret_cast<zelLoaderZeTracingLayerInit_t>(
182182
GET_FUNCTION_PTR(loader, "zelLoaderTracingLayerInit") );
183-
if (loaderTracingLayerInit == nullptr) {
183+
if (loaderZeTracingLayerInit == nullptr) {
184184
std::string message = "ze_lib Context Init() zelLoaderTracingLayerInit missing, disabling dynamic tracer support ";
185185
debug_trace_message(message, "");
186186
this->dynamicTracingSupported = false;
187187
}
188+
typedef ze_result_t (ZE_APICALL *zelLoaderZerTracingLayerInit_t)(std::atomic<zer_dditable_t *> &zerDdiTable);
189+
auto loaderZerTracingLayerInit = reinterpret_cast<zelLoaderZerTracingLayerInit_t>(
190+
GET_FUNCTION_PTR(loader, "zelLoaderZerTracingLayerInit") );
191+
if (loaderZerTracingLayerInit == nullptr) {
192+
std::string message = "ze_lib Context Init() zelLoaderZerTracingLayerInit missing, dynamic tracing support for Zer API's will be unavailable ";
193+
debug_trace_message(message, "");
194+
}
188195
typedef loader::context_t * (ZE_APICALL *zelLoaderGetContext_t)();
189196
auto loaderGetContext = reinterpret_cast<zelLoaderGetContext_t>(
190197
GET_FUNCTION_PTR(loader, "zelLoaderGetContext") );
@@ -280,11 +287,17 @@ namespace ze_lib
280287
if( ZE_RESULT_SUCCESS == result )
281288
{
282289
#ifdef L0_STATIC_LOADER_BUILD
283-
if (loaderTracingLayerInit) {
284-
result = loaderTracingLayerInit(this->pTracingZeDdiTable);
290+
if (loaderZeTracingLayerInit) {
291+
result = loaderZeTracingLayerInit(this->pTracingZeDdiTable);
292+
if (result == ZE_RESULT_SUCCESS && loaderZerTracingLayerInit) {
293+
result = loaderZerTracingLayerInit(this->pTracingZerDdiTable);
294+
}
285295
}
286296
#else
287297
result = zelLoaderTracingLayerInit(this->pTracingZeDdiTable);
298+
if (result == ZE_RESULT_SUCCESS) {
299+
result = zelLoaderZerTracingLayerInit(this->pTracingZerDdiTable);
300+
}
288301
#endif
289302
}
290303
// End DDI Table Inits
@@ -638,6 +651,9 @@ zelEnableTracingLayer()
638651
}
639652
if (ze_lib::context->tracingLayerEnableCounter.fetch_add(1) == 0) {
640653
ze_lib::context->zeDdiTable.exchange(ze_lib::context->pTracingZeDdiTable);
654+
if (ze_lib::context->pTracingZerDdiTable != nullptr) {
655+
ze_lib::context->zerDdiTable.exchange(ze_lib::context->pTracingZerDdiTable);
656+
}
641657
}
642658
#endif
643659
return ZE_RESULT_SUCCESS;
@@ -659,6 +675,9 @@ zelDisableTracingLayer()
659675
}
660676
if (ze_lib::context->tracingLayerEnableCounter.fetch_sub(1) <= 1) {
661677
ze_lib::context->zeDdiTable.exchange(&ze_lib::context->initialzeDdiTable);
678+
if (ze_lib::context->pTracingZerDdiTable != nullptr) {
679+
ze_lib::context->zerDdiTable.exchange(&ze_lib::context->initialzerDdiTable);
680+
}
662681
}
663682
#endif
664683
return ZE_RESULT_SUCCESS;

source/lib/ze_lib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ namespace ze_lib
169169
ze_result_t zelTracingDdiTableInit(ze_api_version_t version);
170170
zel_tracing_dditable_t zelTracingDdiTable = {};
171171
std::atomic<ze_dditable_t *> pTracingZeDdiTable = {nullptr};
172+
std::atomic<zer_dditable_t *> pTracingZerDdiTable = {nullptr};
172173
ze_dditable_t initialzeDdiTable;
173174
zet_dditable_t initialzetDdiTable;
174175
zes_dditable_t initialzesDdiTable;

source/loader/ze_loader_api.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,23 @@ zelLoaderGetContext() {
6060
}
6161

6262
///////////////////////////////////////////////////////////////////////////////
63-
/// @brief Internal function for Setting the ddi table for the Tracing Layer.
63+
/// @brief Internal function for Setting the ZE ddi table for the Tracing Layer.
6464
///
6565
ZE_DLLEXPORT ze_result_t ZE_APICALL
6666
zelLoaderTracingLayerInit(std::atomic<ze_dditable_t *> &zeDdiTable) {
6767
zeDdiTable.store(&loader::context->tracing_dditable.ze);
6868
return ZE_RESULT_SUCCESS;
6969
}
7070

71+
///////////////////////////////////////////////////////////////////////////////
72+
/// @brief Internal function for Setting the ZER ddi table for the Tracing Layer.
73+
///
74+
ZE_DLLEXPORT ze_result_t ZE_APICALL
75+
zelLoaderZerTracingLayerInit(std::atomic<zer_dditable_t *> &zerDdiTable) {
76+
zerDdiTable.store(&loader::context->tracing_dditable.zer);
77+
return ZE_RESULT_SUCCESS;
78+
}
79+
7180
ZE_DLLEXPORT ze_result_t ZE_APICALL
7281
zelLoaderGetVersionsInternal(
7382
size_t *num_elems, //Pointer to num versions to get.

source/loader/ze_loader_api.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2020-2021 Intel Corporation
3+
* Copyright (C) 2020-2025 Intel Corporation
44
*
55
* SPDX-License-Identifier: MIT
66
*
@@ -37,11 +37,17 @@ zelLoaderDriverCheck(ze_init_flags_t flags, ze_init_driver_type_desc_t* desc, ze
3737

3838

3939
///////////////////////////////////////////////////////////////////////////////
40-
/// @brief Internal function for Setting the ddi table for the Tracing Layer.
40+
/// @brief Internal function for Setting the ZE ddi table for the Tracing Layer.
4141
///
4242
ZE_DLLEXPORT ze_result_t ZE_APICALL
4343
zelLoaderTracingLayerInit(std::atomic<ze_dditable_t *> &zeDdiTable);
4444

45+
///////////////////////////////////////////////////////////////////////////////
46+
/// @brief Internal function for Setting the ZER ddi table for the Tracing Layer.
47+
///
48+
ZE_DLLEXPORT ze_result_t ZE_APICALL
49+
zelLoaderZerTracingLayerInit(std::atomic<zer_dditable_t *> &zerDdiTable);
50+
4551

4652
///////////////////////////////////////////////////////////////////////////////
4753
/// @brief Exported function for getting tracing lib handle

0 commit comments

Comments
 (0)