9 #ifdef XPTI_ENABLE_INSTRUMENTATION
10 #include <xpti/xpti_data_types.h>
11 #include <xpti/xpti_trace_framework.h>
15 #include <layers/zel_tracing_api.h>
30 #ifdef XPTI_ENABLE_INSTRUMENTATION
31 static xpti_td *GCallEvent =
nullptr;
32 static xpti_td *GDebugEvent =
nullptr;
33 static uint8_t GCallStreamID = 0;
34 static uint8_t GDebugStreamID = 0;
38 #define _ZE_API(call, domain, cb, params_type) call,
44 #ifdef XPTI_ENABLE_INSTRUMENTATION
45 if (!xptiTraceEnabled())
55 xpti::payload_t ZePayload(
"Level Zero Plugin Layer");
57 xptiMakeEvent(
"Level Zero Plugin Layer", &ZePayload,
58 xpti::trace_algorithm_event, xpti_at::active, &Dummy);
60 xpti::payload_t ZeDebugPayload(
"Level Zero Plugin Debug Layer");
62 xptiMakeEvent(
"Level Zero Plugin Debug Layer", &ZeDebugPayload,
63 xpti::trace_algorithm_event, xpti_at::active, &Dummy);
65 ze_result_t Status = zeInit(0);
66 if (Status != ZE_RESULT_SUCCESS) {
72 zel_tracer_desc_t TracerDesc = {ZEL_STRUCTURE_TYPE_TRACER_EXP_DESC,
nullptr,
74 zel_tracer_handle_t Tracer =
nullptr;
76 Status = zelTracerCreate(&TracerDesc, &Tracer);
78 if (Status != ZE_RESULT_SUCCESS || Tracer ==
nullptr) {
79 std::cerr <<
"[WARNING] Failed to create Level Zero tracer: " << Status
84 zel_core_callbacks_t Prologue = {};
85 zel_core_callbacks_t Epilogue = {};
87 #define _ZE_API(call, domain, cb, params_type) \
88 Prologue.domain.cb = [](params_type *Params, ze_result_t, void *, void **) { \
89 if (xptiTraceEnabled()) { \
90 const char *FuncName = #call; \
91 if (xptiCheckTraceEnabled( \
93 (uint16_t)xpti::trace_point_type_t::function_begin)) { \
94 CallCorrelationID = xptiGetUniqueId(); \
95 xptiNotifySubscribers( \
96 GCallStreamID, (uint16_t)xpti::trace_point_type_t::function_begin, \
97 GCallEvent, nullptr, CallCorrelationID, FuncName); \
99 if (xptiCheckTraceEnabled( \
101 (uint16_t)xpti::trace_point_type_t::function_with_args_begin)) { \
102 DebugCorrelationID = xptiGetUniqueId(); \
103 uint32_t FuncID = static_cast<uint32_t>(ZEApiKind::call); \
104 xpti::function_with_args_t Payload{FuncID, FuncName, Params, nullptr, \
106 xptiNotifySubscribers( \
108 (uint16_t)xpti::trace_point_type_t::function_with_args_begin, \
109 GDebugEvent, nullptr, DebugCorrelationID, &Payload); \
113 Epilogue.domain.cb = [](params_type *Params, ze_result_t Result, void *, \
115 if (xptiTraceEnabled()) { \
116 const char *FuncName = #call; \
117 if (xptiCheckTraceEnabled( \
119 (uint16_t)xpti::trace_point_type_t::function_end)) { \
120 xptiNotifySubscribers( \
121 GCallStreamID, (uint16_t)xpti::trace_point_type_t::function_end, \
122 GCallEvent, nullptr, CallCorrelationID, FuncName); \
124 if (xptiCheckTraceEnabled( \
126 (uint16_t)xpti::trace_point_type_t::function_with_args_end)) { \
127 uint32_t FuncID = static_cast<uint32_t>(ZEApiKind::call); \
128 xpti::function_with_args_t Payload{FuncID, FuncName, Params, &Result, \
130 xptiNotifySubscribers( \
132 (uint16_t)xpti::trace_point_type_t::function_with_args_end, \
133 GDebugEvent, nullptr, DebugCorrelationID, &Payload); \
138 #include "ze_api.def"
142 Status = zelTracerSetPrologues(Tracer, &Prologue);
143 if (Status != ZE_RESULT_SUCCESS) {
144 std::cerr <<
"Failed to enable Level Zero tracing\n";
147 Status = zelTracerSetEpilogues(Tracer, &Epilogue);
148 if (Status != ZE_RESULT_SUCCESS) {
149 std::cerr <<
"Failed to enable Level Zero tracing\n";
153 Status = zelTracerSetEnabled(Tracer,
true);
154 if (Status != ZE_RESULT_SUCCESS) {
155 std::cerr <<
"Failed to enable Level Zero tracing\n";
162 #ifdef XPTI_ENABLE_INSTRUMENTATION
163 if (!xptiTraceEnabled())
__SYCL_EXTERN_STREAM_ATTRS ostream cerr
Linked to standard error (unbuffered)
constexpr auto ZE_DEBUG_STREAM_NAME
thread_local uint64_t CallCorrelationID
constexpr auto ZE_CALL_STREAM_NAME
thread_local uint64_t DebugCorrelationID