Skip to content

Commit 45e8e15

Browse files
[SYCL][XPTI] Use xptiTraceEnabled version with filter (#10241)
Note: not all xptiTraceEnabled usages were replaced, in some cases it has no sense. --------- Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent 4a7a5d4 commit 45e8e15

File tree

8 files changed

+177
-139
lines changed

8 files changed

+177
-139
lines changed

sycl/source/detail/event_impl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
173173
uint64_t &IId) const {
174174
void *TraceEvent = nullptr;
175175
#ifdef XPTI_ENABLE_INSTRUMENTATION
176-
if (!xptiTraceEnabled())
176+
constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin;
177+
if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType))
177178
return TraceEvent;
178179
// Use a thread-safe counter to get a unique instance ID for the wait() on the
179180
// event
@@ -197,7 +198,7 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
197198

198199
// Record the current instance ID for use by Epilog
199200
IId = InstanceID++;
200-
xptiNotifySubscribers(StreamID, xpti::trace_wait_begin, nullptr, WaitEvent,
201+
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, WaitEvent,
201202
IId, static_cast<const void *>(Name.c_str()));
202203
TraceEvent = (void *)WaitEvent;
203204
#endif
@@ -208,12 +209,14 @@ void event_impl::instrumentationEpilog(void *TelemetryEvent,
208209
const std::string &Name,
209210
int32_t StreamID, uint64_t IId) const {
210211
#ifdef XPTI_ENABLE_INSTRUMENTATION
211-
if (!(xptiTraceEnabled() && TelemetryEvent))
212+
constexpr uint16_t NotificationTraceType = xpti::trace_wait_end;
213+
if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) &&
214+
TelemetryEvent))
212215
return;
213216
// Close the wait() scope
214217
xpti::trace_event_data_t *TraceEvent =
215218
(xpti::trace_event_data_t *)TelemetryEvent;
216-
xptiNotifySubscribers(StreamID, xpti::trace_wait_end, nullptr, TraceEvent,
219+
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, TraceEvent,
217220
IId, static_cast<const void *>(Name.c_str()));
218221
#endif
219222
}

sycl/source/detail/memory_manager.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ uint64_t emitMemAllocBeginTrace(uintptr_t ObjHandle, size_t AllocSize,
4141
(void)GuardZone;
4242
uint64_t CorrelationID = 0;
4343
#ifdef XPTI_ENABLE_INSTRUMENTATION
44-
if (xptiTraceEnabled()) {
44+
constexpr uint16_t NotificationTraceType =
45+
static_cast<uint16_t>(xpti::trace_point_type_t::mem_alloc_begin);
46+
if (xptiCheckTraceEnabled(GMemAllocStreamID, NotificationTraceType)) {
4547
xpti::mem_alloc_data_t MemAlloc{ObjHandle, 0 /* alloc ptr */, AllocSize,
4648
GuardZone};
4749

4850
CorrelationID = xptiGetUniqueId();
49-
xptiNotifySubscribers(
50-
GMemAllocStreamID,
51-
static_cast<uint16_t>(xpti::trace_point_type_t::mem_alloc_begin),
52-
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
51+
xptiNotifySubscribers(GMemAllocStreamID, NotificationTraceType,
52+
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
5353
}
5454
#endif
5555
return CorrelationID;
@@ -64,13 +64,13 @@ void emitMemAllocEndTrace(uintptr_t ObjHandle, uintptr_t AllocPtr,
6464
(void)GuardZone;
6565
(void)CorrelationID;
6666
#ifdef XPTI_ENABLE_INSTRUMENTATION
67-
if (xptiTraceEnabled()) {
67+
constexpr uint16_t NotificationTraceType =
68+
static_cast<uint16_t>(xpti::trace_point_type_t::mem_alloc_end);
69+
if (xptiCheckTraceEnabled(GMemAllocStreamID, NotificationTraceType)) {
6870
xpti::mem_alloc_data_t MemAlloc{ObjHandle, AllocPtr, AllocSize, GuardZone};
6971

70-
xptiNotifySubscribers(
71-
GMemAllocStreamID,
72-
static_cast<uint16_t>(xpti::trace_point_type_t::mem_alloc_end),
73-
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
72+
xptiNotifySubscribers(GMemAllocStreamID, NotificationTraceType,
73+
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
7474
}
7575
#endif
7676
}
@@ -80,15 +80,15 @@ uint64_t emitMemReleaseBeginTrace(uintptr_t ObjHandle, uintptr_t AllocPtr) {
8080
(void)AllocPtr;
8181
uint64_t CorrelationID = 0;
8282
#ifdef XPTI_ENABLE_INSTRUMENTATION
83-
if (xptiTraceEnabled()) {
83+
constexpr uint16_t NotificationTraceType =
84+
static_cast<uint16_t>(xpti::trace_point_type_t::mem_release_begin);
85+
if (xptiCheckTraceEnabled(GMemAllocStreamID, NotificationTraceType)) {
8486
xpti::mem_alloc_data_t MemAlloc{ObjHandle, AllocPtr, 0 /* alloc size */,
8587
0 /* guard zone */};
8688

8789
CorrelationID = xptiGetUniqueId();
88-
xptiNotifySubscribers(
89-
GMemAllocStreamID,
90-
static_cast<uint16_t>(xpti::trace_point_type_t::mem_release_begin),
91-
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
90+
xptiNotifySubscribers(GMemAllocStreamID, NotificationTraceType,
91+
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
9292
}
9393
#endif
9494
return CorrelationID;
@@ -100,14 +100,14 @@ void emitMemReleaseEndTrace(uintptr_t ObjHandle, uintptr_t AllocPtr,
100100
(void)AllocPtr;
101101
(void)CorrelationID;
102102
#ifdef XPTI_ENABLE_INSTRUMENTATION
103-
if (xptiTraceEnabled()) {
103+
constexpr uint16_t NotificationTraceType =
104+
static_cast<uint16_t>(xpti::trace_point_type_t::mem_release_end);
105+
if (xptiCheckTraceEnabled(GMemAllocStreamID, NotificationTraceType)) {
104106
xpti::mem_alloc_data_t MemAlloc{ObjHandle, AllocPtr, 0 /* alloc size */,
105107
0 /* guard zone */};
106108

107-
xptiNotifySubscribers(
108-
GMemAllocStreamID,
109-
static_cast<uint16_t>(xpti::trace_point_type_t::mem_release_end),
110-
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
109+
xptiNotifySubscribers(GMemAllocStreamID, NotificationTraceType,
110+
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
111111
}
112112
#endif
113113
}

sycl/source/detail/pi.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ xpti_td *GPICallEvent = nullptr;
5252
xpti_td *GPIArgCallEvent = nullptr;
5353
xpti_td *GPIArgCallActiveEvent = nullptr;
5454

55+
uint8_t PiCallStreamID = 0;
56+
uint8_t PiDebugCallStreamID = 0;
57+
5558
#endif // XPTI_ENABLE_INSTRUMENTATION
5659

5760
template <sycl::backend BE> void *getPluginOpaqueData(void *OpaqueDataParam) {
@@ -108,28 +111,30 @@ uint64_t emitFunctionBeginTrace(const char *FName) {
108111
/// xptiNotifySubscribers(stream_id, pi_func_begin, parent, event, instance,
109112
/// (void *)argument_data);
110113
/// \endcode
111-
if (xptiTraceEnabled()) {
112-
uint8_t StreamID = xptiRegisterStream(SYCL_PICALL_STREAM_NAME);
114+
constexpr uint16_t NotificationTraceType =
115+
(uint16_t)xpti::trace_point_type_t::function_begin;
116+
if (xptiCheckTraceEnabled(PiCallStreamID, NotificationTraceType)) {
113117
CorrelationID = xptiGetUniqueId();
114-
xptiNotifySubscribers(
115-
StreamID, (uint16_t)xpti::trace_point_type_t::function_begin,
116-
GPICallEvent, nullptr, CorrelationID, static_cast<const void *>(FName));
118+
xptiNotifySubscribers(PiCallStreamID, NotificationTraceType, GPICallEvent,
119+
nullptr, CorrelationID,
120+
static_cast<const void *>(FName));
117121
}
118122
#endif // XPTI_ENABLE_INSTRUMENTATION
119123
return CorrelationID;
120124
}
121125

122126
void emitFunctionEndTrace(uint64_t CorrelationID, const char *FName) {
123127
#ifdef XPTI_ENABLE_INSTRUMENTATION
124-
if (xptiTraceEnabled()) {
128+
constexpr uint16_t NotificationTraceType =
129+
(uint16_t)xpti::trace_point_type_t::function_end;
130+
if (xptiCheckTraceEnabled(PiCallStreamID, NotificationTraceType)) {
125131
// CorrelationID is the unique ID that ties together a function_begin and
126132
// function_end pair of trace calls. The splitting of a scoped_notify into
127133
// two function calls incurs an additional overhead as the StreamID must
128134
// be looked up twice.
129-
uint8_t StreamID = xptiRegisterStream(SYCL_PICALL_STREAM_NAME);
130-
xptiNotifySubscribers(
131-
StreamID, (uint16_t)xpti::trace_point_type_t::function_end,
132-
GPICallEvent, nullptr, CorrelationID, static_cast<const void *>(FName));
135+
xptiNotifySubscribers(PiCallStreamID, NotificationTraceType, GPICallEvent,
136+
nullptr, CorrelationID,
137+
static_cast<const void *>(FName));
133138
}
134139
#endif // XPTI_ENABLE_INSTRUMENTATION
135140
}
@@ -139,9 +144,9 @@ uint64_t emitFunctionWithArgsBeginTrace(uint32_t FuncID, const char *FuncName,
139144
pi_plugin Plugin) {
140145
uint64_t CorrelationID = 0;
141146
#ifdef XPTI_ENABLE_INSTRUMENTATION
142-
if (xptiTraceEnabled()) {
143-
uint8_t StreamID = xptiRegisterStream(SYCL_PIDEBUGCALL_STREAM_NAME);
144-
147+
constexpr uint16_t NotificationTraceType =
148+
(uint16_t)xpti::trace_point_type_t::function_with_args_begin;
149+
if (xptiCheckTraceEnabled(PiDebugCallStreamID, NotificationTraceType)) {
145150
xpti::function_with_args_t Payload{FuncID, FuncName, ArgsData, nullptr,
146151
&Plugin};
147152
{
@@ -158,9 +163,9 @@ uint64_t emitFunctionWithArgsBeginTrace(uint32_t FuncID, const char *FuncName,
158163
}
159164

160165
CorrelationID = xptiGetUniqueId();
161-
xptiNotifySubscribers(
162-
StreamID, (uint16_t)xpti::trace_point_type_t::function_with_args_begin,
163-
GPIArgCallEvent, GPIArgCallActiveEvent, CorrelationID, &Payload);
166+
xptiNotifySubscribers(PiDebugCallStreamID, NotificationTraceType,
167+
GPIArgCallEvent, GPIArgCallActiveEvent, CorrelationID,
168+
&Payload);
164169
}
165170
#endif
166171
return CorrelationID;
@@ -170,15 +175,15 @@ void emitFunctionWithArgsEndTrace(uint64_t CorrelationID, uint32_t FuncID,
170175
const char *FuncName, unsigned char *ArgsData,
171176
pi_result Result, pi_plugin Plugin) {
172177
#ifdef XPTI_ENABLE_INSTRUMENTATION
173-
if (xptiTraceEnabled()) {
174-
uint8_t StreamID = xptiRegisterStream(SYCL_PIDEBUGCALL_STREAM_NAME);
175-
178+
constexpr uint16_t NotificationTraceType =
179+
(uint16_t)xpti::trace_point_type_t::function_with_args_end;
180+
if (xptiCheckTraceEnabled(PiDebugCallStreamID, NotificationTraceType)) {
176181
xpti::function_with_args_t Payload{FuncID, FuncName, ArgsData, &Result,
177182
&Plugin};
178183

179-
xptiNotifySubscribers(
180-
StreamID, (uint16_t)xpti::trace_point_type_t::function_with_args_end,
181-
GPIArgCallEvent, GPIArgCallActiveEvent, CorrelationID, &Payload);
184+
xptiNotifySubscribers(PiDebugCallStreamID, NotificationTraceType,
185+
GPIArgCallEvent, GPIArgCallActiveEvent, CorrelationID,
186+
&Payload);
182187
GPIArgCallActiveEvent = nullptr;
183188
}
184189
#endif
@@ -524,6 +529,9 @@ static void initializePlugins(std::vector<PluginPtr> &Plugins) {
524529
GPIArgCallEvent = xptiMakeEvent("PI Layer with arguments", &PIArgPayload,
525530
xpti::trace_algorithm_event, xpti_at::active,
526531
&PiArgInstanceNo);
532+
533+
PiCallStreamID = xptiRegisterStream(SYCL_PICALL_STREAM_NAME);
534+
PiDebugCallStreamID = xptiRegisterStream(SYCL_PIDEBUGCALL_STREAM_NAME);
527535
#endif
528536
}
529537

sycl/source/detail/queue_impl.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
382382
(void)StreamID;
383383
(void)IId;
384384
#ifdef XPTI_ENABLE_INSTRUMENTATION
385-
xpti::trace_event_data_t *WaitEvent = nullptr;
386-
if (!xptiTraceEnabled())
385+
constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin;
386+
if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType))
387387
return TraceEvent;
388388

389389
xpti::payload_t Payload;
@@ -407,8 +407,9 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
407407
// event based on the code location info and if this has been seen before, a
408408
// previously created event will be returned.
409409
uint64_t QWaitInstanceNo = 0;
410-
WaitEvent = xptiMakeEvent(Name.c_str(), &Payload, xpti::trace_graph_event,
411-
xpti_at::active, &QWaitInstanceNo);
410+
xpti::trace_event_data_t *WaitEvent =
411+
xptiMakeEvent(Name.c_str(), &Payload, xpti::trace_graph_event,
412+
xpti_at::active, &QWaitInstanceNo);
412413
IId = QWaitInstanceNo;
413414
if (WaitEvent) {
414415
device D = get_device();
@@ -448,12 +449,14 @@ void queue_impl::instrumentationEpilog(void *TelemetryEvent, std::string &Name,
448449
(void)StreamID;
449450
(void)IId;
450451
#ifdef XPTI_ENABLE_INSTRUMENTATION
451-
if (!(xptiTraceEnabled() && TelemetryEvent))
452+
constexpr uint16_t NotificationTraceType = xpti::trace_wait_end;
453+
if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) &&
454+
TelemetryEvent))
452455
return;
453456
// Close the wait() scope
454457
xpti::trace_event_data_t *TraceEvent =
455458
(xpti::trace_event_data_t *)TelemetryEvent;
456-
xptiNotifySubscribers(StreamID, xpti::trace_wait_end, nullptr, TraceEvent,
459+
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, TraceEvent,
457460
IId, static_cast<const void *>(Name.c_str()));
458461
#endif
459462
}

sycl/source/detail/queue_impl.hpp

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,32 @@ class queue_impl {
117117
#if XPTI_ENABLE_INSTRUMENTATION
118118
/// This section of code is relying on scoped objects, so they cannot be
119119
/// encapsulated in a function
120-
XPTIScope PrepareNotify((void *)this,
121-
(uint16_t)xpti::trace_point_type_t::queue_create,
120+
constexpr uint16_t NotificationTraceType =
121+
static_cast<uint16_t>(xpti::trace_point_type_t::queue_create);
122+
XPTIScope PrepareNotify((void *)this, NotificationTraceType,
122123
SYCL_STREAM_NAME, "queue_create");
123124
// Cache the trace event, stream id and instance IDs for the destructor
124-
if (xptiTraceEnabled()) {
125+
if (xptiCheckTraceEnabled(PrepareNotify.streamID(),
126+
NotificationTraceType)) {
125127
MTraceEvent = (void *)PrepareNotify.traceEvent();
126128
MStreamID = PrepareNotify.streamID();
127129
MInstanceID = PrepareNotify.instanceID();
130+
// Add the function to capture meta data for the XPTI trace event
131+
PrepareNotify.addMetadata([&](auto TEvent) {
132+
xpti::addMetadata(TEvent, "sycl_context",
133+
reinterpret_cast<size_t>(MContext->getHandleRef()));
134+
if (MDevice) {
135+
xpti::addMetadata(TEvent, "sycl_device_name",
136+
MDevice->getDeviceName());
137+
xpti::addMetadata(
138+
TEvent, "sycl_device",
139+
reinterpret_cast<size_t>(
140+
MDevice->is_host() ? 0 : MDevice->getHandleRef()));
141+
}
142+
xpti::addMetadata(TEvent, "is_inorder", MIsInorder);
143+
});
144+
PrepareNotify.notify();
128145
}
129-
// Add the function to capture meta data for the XPTI trace event
130-
PrepareNotify.addMetadata([&](auto TEvent) {
131-
xpti::addMetadata(TEvent, "sycl_context",
132-
reinterpret_cast<size_t>(MContext->getHandleRef()));
133-
if (MDevice) {
134-
xpti::addMetadata(TEvent, "sycl_device_name", MDevice->getDeviceName());
135-
xpti::addMetadata(
136-
TEvent, "sycl_device",
137-
reinterpret_cast<size_t>(
138-
MDevice->is_host() ? 0 : MDevice->getHandleRef()));
139-
}
140-
xpti::addMetadata(TEvent, "is_inorder", MIsInorder);
141-
});
142-
PrepareNotify.notify();
143146
#endif
144147
if (has_property<property::queue::enable_profiling>()) {
145148
if (has_property<ext::oneapi::property::queue::discard_events>())
@@ -201,29 +204,33 @@ class queue_impl {
201204
#if XPTI_ENABLE_INSTRUMENTATION
202205
/// This section of code is relying on scoped objects, so they cannot be
203206
/// encapsulated in a function
204-
XPTIScope PrepareNotify((void *)this,
205-
(uint16_t)xpti::trace_point_type_t::queue_create,
207+
constexpr uint16_t NotificationTraceType =
208+
static_cast<uint16_t>(xpti::trace_point_type_t::queue_create);
209+
XPTIScope PrepareNotify((void *)this, NotificationTraceType,
206210
SYCL_STREAM_NAME, "queue_create");
207-
if (xptiTraceEnabled()) {
211+
if (xptiCheckTraceEnabled(PrepareNotify.streamID(),
212+
NotificationTraceType)) {
208213
// Cache the trace event, stream id and instance IDs for the destructor
209214
MTraceEvent = (void *)PrepareNotify.traceEvent();
210215
MStreamID = PrepareNotify.streamID();
211216
MInstanceID = PrepareNotify.instanceID();
217+
218+
// Add the function to capture meta data for the XPTI trace event
219+
PrepareNotify.addMetadata([&](auto TEvent) {
220+
xpti::addMetadata(TEvent, "sycl_context",
221+
reinterpret_cast<size_t>(MContext->getHandleRef()));
222+
if (MDevice) {
223+
xpti::addMetadata(TEvent, "sycl_device_name",
224+
MDevice->getDeviceName());
225+
xpti::addMetadata(
226+
TEvent, "sycl_device",
227+
reinterpret_cast<size_t>(
228+
MDevice->is_host() ? 0 : MDevice->getHandleRef()));
229+
}
230+
xpti::addMetadata(TEvent, "is_inorder", MIsInorder);
231+
});
232+
PrepareNotify.notify();
212233
}
213-
// Add the function to capture meta data for the XPTI trace event
214-
PrepareNotify.addMetadata([&](auto TEvent) {
215-
xpti::addMetadata(TEvent, "sycl_context",
216-
reinterpret_cast<size_t>(MContext->getHandleRef()));
217-
if (MDevice) {
218-
xpti::addMetadata(TEvent, "sycl_device_name", MDevice->getDeviceName());
219-
xpti::addMetadata(
220-
TEvent, "sycl_device",
221-
reinterpret_cast<size_t>(
222-
MDevice->is_host() ? 0 : MDevice->getHandleRef()));
223-
}
224-
xpti::addMetadata(TEvent, "is_inorder", MIsInorder);
225-
});
226-
PrepareNotify.notify();
227234
#endif
228235
if (has_property<ext::oneapi::property::queue::discard_events>() &&
229236
has_property<property::queue::enable_profiling>()) {
@@ -292,12 +299,14 @@ class queue_impl {
292299
// lifetime of the queue object as member variables when ABI breakage is
293300
// allowed. This example shows MTraceEvent as a member variable.
294301
#if XPTI_ENABLE_INSTRUMENTATION
295-
if (xptiTraceEnabled()) {
302+
constexpr uint16_t NotificationTraceType =
303+
static_cast<uint16_t>(xpti::trace_point_type_t::queue_destroy);
304+
if (xptiCheckTraceEnabled(MStreamID, NotificationTraceType)) {
296305
// Used cached information in member variables
297-
xptiNotifySubscribers(
298-
MStreamID, (uint16_t)xpti::trace_point_type_t::queue_destroy, nullptr,
299-
(xpti::trace_event_data_t *)MTraceEvent, MInstanceID,
300-
static_cast<const void *>("queue_destroy"));
306+
xptiNotifySubscribers(MStreamID, NotificationTraceType, nullptr,
307+
(xpti::trace_event_data_t *)MTraceEvent,
308+
MInstanceID,
309+
static_cast<const void *>("queue_destroy"));
301310
}
302311
#endif
303312
throw_asynchronous();

0 commit comments

Comments
 (0)