@@ -113,39 +113,9 @@ class queue_impl {
113
113
has_property<ext::oneapi::property::queue::discard_events>()),
114
114
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
115
115
MHasDiscardEventsSupport(MDiscardEvents &&
116
- (MHostQueue ? true : MIsInorder)) {
117
- // We enable XPTI tracing events using the TLS mechanism; if the code
118
- // location data is available, then the tracing data will be rich.
119
- #if XPTI_ENABLE_INSTRUMENTATION
120
- // / This section of code is relying on scoped objects, so they cannot be
121
- // / encapsulated in a function
122
- constexpr uint16_t NotificationTraceType =
123
- static_cast <uint16_t >(xpti::trace_point_type_t ::queue_create);
124
- XPTIScope PrepareNotify ((void *)this , NotificationTraceType,
125
- SYCL_STREAM_NAME, " queue_create" );
126
- // Cache the trace event, stream id and instance IDs for the destructor
127
- if (xptiCheckTraceEnabled (PrepareNotify.streamID (),
128
- NotificationTraceType)) {
129
- MTraceEvent = (void *)PrepareNotify.traceEvent ();
130
- MStreamID = PrepareNotify.streamID ();
131
- MInstanceID = PrepareNotify.instanceID ();
132
- // Add the function to capture meta data for the XPTI trace event
133
- PrepareNotify.addMetadata ([&](auto TEvent) {
134
- xpti::addMetadata (TEvent, " sycl_context" ,
135
- reinterpret_cast <size_t >(MContext->getHandleRef ()));
136
- if (MDevice) {
137
- xpti::addMetadata (TEvent, " sycl_device_name" ,
138
- MDevice->getDeviceName ());
139
- xpti::addMetadata (
140
- TEvent, " sycl_device" ,
141
- reinterpret_cast <size_t >(
142
- MDevice->is_host () ? 0 : MDevice->getHandleRef ()));
143
- }
144
- xpti::addMetadata (TEvent, " is_inorder" , MIsInorder);
145
- });
146
- PrepareNotify.notify ();
147
- }
148
- #endif
116
+ (MHostQueue ? true : MIsInorder)),
117
+ MQueueID{
118
+ MNextAvailableQueueID.fetch_add (1 , std::memory_order_relaxed)} {
149
119
if (has_property<property::queue::enable_profiling>()) {
150
120
if (has_property<ext::oneapi::property::queue::discard_events>())
151
121
throw sycl::exception (make_error_code (errc::invalid),
@@ -196,28 +166,19 @@ class queue_impl {
196
166
// This section is the second part of the instrumentation that uses the
197
167
// tracepoint information and notifies
198
168
}
199
- }
200
-
201
- private:
202
- void queue_impl_interop (sycl::detail::pi::PiQueue PiQueue) {
203
- // The following commented section provides a guideline on how to use the
204
- // TLS enabled mechanism to create a tracepoint and notify using XPTI. This
205
- // is the prolog section and the epilog section will initiate the
206
- // notification.
169
+ // We enable XPTI tracing events using the TLS mechanism; if the code
170
+ // location data is available, then the tracing data will be rich.
207
171
#if XPTI_ENABLE_INSTRUMENTATION
208
- // / This section of code is relying on scoped objects, so they cannot be
209
- // / encapsulated in a function
210
172
constexpr uint16_t NotificationTraceType =
211
173
static_cast <uint16_t >(xpti::trace_point_type_t ::queue_create);
212
174
XPTIScope PrepareNotify ((void *)this , NotificationTraceType,
213
175
SYCL_STREAM_NAME, " queue_create" );
176
+ // Cache the trace event, stream id and instance IDs for the destructor
214
177
if (xptiCheckTraceEnabled (PrepareNotify.streamID (),
215
178
NotificationTraceType)) {
216
- // Cache the trace event, stream id and instance IDs for the destructor
217
179
MTraceEvent = (void *)PrepareNotify.traceEvent ();
218
180
MStreamID = PrepareNotify.streamID ();
219
181
MInstanceID = PrepareNotify.instanceID ();
220
-
221
182
// Add the function to capture meta data for the XPTI trace event
222
183
PrepareNotify.addMetadata ([&](auto TEvent) {
223
184
xpti::addMetadata (TEvent, " sycl_context" ,
@@ -231,10 +192,18 @@ class queue_impl {
231
192
MDevice->is_host () ? 0 : MDevice->getHandleRef ()));
232
193
}
233
194
xpti::addMetadata (TEvent, " is_inorder" , MIsInorder);
195
+ xpti::addMetadata (TEvent, " queue_id" , MQueueID);
196
+ if (!MHostQueue)
197
+ xpti::addMetadata (TEvent, " queue_handle" ,
198
+ reinterpret_cast <size_t >(getHandleRef ()));
234
199
});
235
200
PrepareNotify.notify ();
236
201
}
237
202
#endif
203
+ }
204
+
205
+ private:
206
+ void queue_impl_interop (sycl::detail::pi::PiQueue PiQueue) {
238
207
if (has_property<ext::oneapi::property::queue::discard_events>() &&
239
208
has_property<property::queue::enable_profiling>()) {
240
209
throw sycl::exception (make_error_code (errc::invalid),
@@ -255,6 +224,42 @@ class queue_impl {
255
224
make_error_code (errc::invalid),
256
225
" Device provided by native Queue not found in Context." );
257
226
}
227
+ // The following commented section provides a guideline on how to use the
228
+ // TLS enabled mechanism to create a tracepoint and notify using XPTI. This
229
+ // is the prolog section and the epilog section will initiate the
230
+ // notification.
231
+ #if XPTI_ENABLE_INSTRUMENTATION
232
+ constexpr uint16_t NotificationTraceType =
233
+ static_cast <uint16_t >(xpti::trace_point_type_t ::queue_create);
234
+ XPTIScope PrepareNotify ((void *)this , NotificationTraceType,
235
+ SYCL_STREAM_NAME, " queue_create" );
236
+ if (xptiCheckTraceEnabled (PrepareNotify.streamID (),
237
+ NotificationTraceType)) {
238
+ // Cache the trace event, stream id and instance IDs for the destructor
239
+ MTraceEvent = (void *)PrepareNotify.traceEvent ();
240
+ MStreamID = PrepareNotify.streamID ();
241
+ MInstanceID = PrepareNotify.instanceID ();
242
+
243
+ // Add the function to capture meta data for the XPTI trace event
244
+ PrepareNotify.addMetadata ([&](auto TEvent) {
245
+ xpti::addMetadata (TEvent, " sycl_context" ,
246
+ reinterpret_cast <size_t >(MContext->getHandleRef ()));
247
+ if (MDevice) {
248
+ xpti::addMetadata (TEvent, " sycl_device_name" ,
249
+ MDevice->getDeviceName ());
250
+ xpti::addMetadata (
251
+ TEvent, " sycl_device" ,
252
+ reinterpret_cast <size_t >(
253
+ MDevice->is_host () ? 0 : MDevice->getHandleRef ()));
254
+ }
255
+ xpti::addMetadata (TEvent, " is_inorder" , MIsInorder);
256
+ xpti::addMetadata (TEvent, " queue_id" , MQueueID);
257
+ if (!MHostQueue)
258
+ xpti::addMetadata (TEvent, " queue_handle" , getHandleRef ());
259
+ });
260
+ PrepareNotify.notify ();
261
+ }
262
+ #endif
258
263
}
259
264
260
265
public:
@@ -273,7 +278,9 @@ class queue_impl {
273
278
has_property<ext::oneapi::property::queue::discard_events>()),
274
279
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
275
280
MHasDiscardEventsSupport(MDiscardEvents &&
276
- (MHostQueue ? true : MIsInorder)) {
281
+ (MHostQueue ? true : MIsInorder)),
282
+ MQueueID{
283
+ MNextAvailableQueueID.fetch_add (1 , std::memory_order_relaxed)} {
277
284
queue_impl_interop (PiQueue);
278
285
}
279
286
@@ -310,6 +317,7 @@ class queue_impl {
310
317
(xpti::trace_event_data_t *)MTraceEvent,
311
318
MInstanceID,
312
319
static_cast <const void *>(" queue_destroy" ));
320
+ xptiReleaseEvent ((xpti::trace_event_data_t *)MTraceEvent);
313
321
}
314
322
#endif
315
323
throw_asynchronous ();
@@ -695,6 +703,8 @@ class queue_impl {
695
703
return MGraph.lock ();
696
704
}
697
705
706
+ unsigned long long getQueueID () { return MQueueID; }
707
+
698
708
protected:
699
709
// Hook to the scheduler to clean up any fusion command held on destruction.
700
710
void cleanup_fusion_cmd ();
@@ -890,6 +900,9 @@ class queue_impl {
890
900
// recording commands to it.
891
901
std::weak_ptr<ext::oneapi::experimental::detail::graph_impl> MGraph{};
892
902
903
+ unsigned long long MQueueID;
904
+ static std::atomic<unsigned long long > MNextAvailableQueueID;
905
+
893
906
friend class sycl ::ext::oneapi::experimental::detail::node_impl;
894
907
};
895
908
0 commit comments