DPC++ Runtime
Runtime libraries for oneAPI DPC++
xpti_registry.cpp
Go to the documentation of this file.
1 //==---------- xpti_registry.cpp ----- XPTI Stream Registry ----------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include <detail/xpti_registry.hpp>
11 
12 #ifdef XPTI_ENABLE_INSTRUMENTATION
13 #include "xpti/xpti_trace_framework.hpp"
14 #include <sstream>
15 #endif
16 namespace sycl {
17 inline namespace _V1 {
18 namespace detail {
19 #ifdef XPTI_ENABLE_INSTRUMENTATION
20 xpti::trace_event_data_t *XPTIRegistry::createTraceEvent(
21  const void *Obj, const void *FuncPtr, uint64_t &IId,
22  const detail::code_location &CodeLoc, uint16_t TraceEventType) {
23  xpti::utils::StringHelper NG;
24  auto Name = NG.nameWithAddress<void *>(CodeLoc.functionName(),
25  const_cast<void *>(FuncPtr));
26  xpti::payload_t Payload(Name.c_str(),
27  (CodeLoc.fileName() ? CodeLoc.fileName() : ""),
28  CodeLoc.lineNumber(), CodeLoc.columnNumber(), Obj);
29 
30  // Calls could be at different user-code locations; We create a new event
31  // based on the code location info and if this has been seen before, a
32  // previously created event will be returned.
33  return xptiMakeEvent(Name.c_str(), &Payload, TraceEventType, xpti_at::active,
34  &IId);
35 }
36 #endif // XPTI_ENABLE_INSTRUMENTATION
37 
39  const void *UserObj, const detail::code_location &CodeLoc,
40  const void *HostObj, const void *Type, uint32_t Dim, uint32_t ElemSize,
41  size_t Range[3]) {
42  (void)UserObj;
43  (void)CodeLoc;
44  (void)HostObj;
45  (void)Type;
46  (void)Dim;
47  (void)ElemSize;
48  (void)Range;
49 #ifdef XPTI_ENABLE_INSTRUMENTATION
51  constexpr uint16_t NotificationTraceType =
52  xpti::trace_offload_alloc_memory_object_construct;
53  if (!xptiCheckTraceEnabled(GBufferStreamID, NotificationTraceType))
54  return;
55 
56  uint64_t IId;
57  xpti::offload_buffer_data_t BufConstr{(uintptr_t)UserObj,
58  (uintptr_t)HostObj,
59  (const char *)Type,
60  ElemSize,
61  Dim,
62  {Range[0], Range[1], Range[2]}};
63 
64  xpti::trace_event_data_t *TraceEvent = createTraceEvent(
65  UserObj, "buffer", IId, CodeLoc, xpti::trace_offload_memory_object_event);
66  xptiNotifySubscribers(GBufferStreamID, NotificationTraceType, nullptr,
67  TraceEvent, IId, &BufConstr);
68 #endif
69 }
70 
72  const void *MemObj) {
73  (void)UserObj;
74  (void)MemObj;
75 #ifdef XPTI_ENABLE_INSTRUMENTATION
76  constexpr uint16_t NotificationTraceType =
77  xpti::trace_offload_alloc_memory_object_associate;
78  if (!xptiCheckTraceEnabled(GBufferStreamID, NotificationTraceType))
79  return;
80  uint64_t IId = xptiGetUniqueId();
81  xpti::offload_association_data_t BufAssoc{(uintptr_t)UserObj,
82  (uintptr_t)MemObj};
83 
84  // Add association between user level and PI level memory object
85  xptiNotifySubscribers(GBufferStreamID, NotificationTraceType, nullptr,
86  nullptr, IId, &BufAssoc);
87 #endif
88 }
89 
90 void XPTIRegistry::bufferReleaseNotification(const void *UserObj,
91  const void *MemObj) {
92  (void)UserObj;
93  (void)MemObj;
94 #ifdef XPTI_ENABLE_INSTRUMENTATION
95  constexpr uint16_t NotificationTraceType =
96  xpti::trace_offload_alloc_memory_object_release;
97  if (!xptiCheckTraceEnabled(GBufferStreamID, NotificationTraceType))
98  return;
99  uint64_t IId = xptiGetUniqueId();
100  xpti::offload_association_data_t BufRelease{(uintptr_t)UserObj,
101  (uintptr_t)MemObj};
102 
103  // Release PI level memory object
104  xptiNotifySubscribers(GBufferStreamID, NotificationTraceType, nullptr,
105  nullptr, IId, &BufRelease);
106 #endif
107 }
108 
110  (void)UserObj;
111 #ifdef XPTI_ENABLE_INSTRUMENTATION
112  constexpr uint16_t NotificationTraceType =
113  xpti::trace_offload_alloc_memory_object_destruct;
114  if (!xptiCheckTraceEnabled(GBufferStreamID, NotificationTraceType))
115  return;
116  uint64_t IId = xptiGetUniqueId();
117  xpti::offload_buffer_data_t BufDestr{(uintptr_t)UserObj};
118  // Destruction of user level memory object
119  xptiNotifySubscribers(GBufferStreamID, NotificationTraceType, nullptr,
120  nullptr, IId, &BufDestr);
121 #endif
122 }
123 
125  const void *UserObj, const void *AccessorObj, uint32_t Target,
126  uint32_t Mode, const detail::code_location &CodeLoc) {
127  (void)UserObj;
128  (void)AccessorObj;
129  (void)CodeLoc;
130  (void)Target;
131  (void)Mode;
132 #ifdef XPTI_ENABLE_INSTRUMENTATION
133  constexpr uint16_t NotificationTraceType = xpti::trace_offload_alloc_accessor;
134  if (!xptiCheckTraceEnabled(GBufferStreamID, NotificationTraceType))
135  return;
136 
137  uint64_t IId;
138  xpti::offload_accessor_data_t AccessorConstr{
139  (uintptr_t)UserObj, (uintptr_t)AccessorObj, Target, Mode};
140 
141  xpti::trace_event_data_t *TraceEvent = createTraceEvent(
142  UserObj, "accessor", IId, CodeLoc, xpti::trace_offload_accessor_event);
143  xptiNotifySubscribers(GBufferStreamID, NotificationTraceType, nullptr,
144  TraceEvent, IId, &AccessorConstr);
145 #endif
146 }
147 
149  const void *UserObj, const detail::code_location &CodeLoc,
150  const void *HostObj, uint32_t Dim, size_t Range[3], uint32_t ImageFormat,
151  uint32_t SamplerAddressingMode, uint32_t SamplerCoordinateNormalizationMode,
152  uint32_t SamplerFilteringMode) {
153  (void)UserObj;
154  (void)CodeLoc;
155  (void)HostObj;
156  (void)Dim;
157  (void)Range;
158  (void)ImageFormat;
159  (void)SamplerAddressingMode;
160  (void)SamplerCoordinateNormalizationMode;
161  (void)SamplerFilteringMode;
162 #ifdef XPTI_ENABLE_INSTRUMENTATION
164  constexpr uint16_t NotificationTraceType =
165  xpti::trace_offload_alloc_memory_object_construct;
166  if (!xptiCheckTraceEnabled(GImageStreamID, NotificationTraceType))
167  return;
168 
169  uint64_t IId;
170  xpti::offload_image_data_t ImgConstr{(uintptr_t)UserObj,
171  (uintptr_t)HostObj,
172  Dim,
173  {Range[0], Range[1], Range[2]},
174  ImageFormat,
175  SamplerAddressingMode,
176  SamplerCoordinateNormalizationMode,
177  SamplerFilteringMode};
178 
179  xpti::trace_event_data_t *TraceEvent =
180  createTraceEvent(UserObj, "sampled_image", IId, CodeLoc,
181  xpti::trace_offload_memory_object_event);
182  xptiNotifySubscribers(GImageStreamID, NotificationTraceType, nullptr,
183  TraceEvent, IId, &ImgConstr);
184 #endif
185 }
186 
188  (void)UserObj;
189 #ifdef XPTI_ENABLE_INSTRUMENTATION
190  constexpr uint16_t NotificationTraceType =
191  xpti::trace_offload_alloc_memory_object_destruct;
192  if (!xptiCheckTraceEnabled(GImageStreamID, NotificationTraceType))
193  return;
194  uint64_t IId = xptiGetUniqueId();
195  xpti::offload_image_data_t ImgDestr{(uintptr_t)UserObj};
196  // Destruction of user level memory object
197  xptiNotifySubscribers(GImageStreamID, NotificationTraceType, nullptr, nullptr,
198  IId, &ImgDestr);
199 #endif
200 }
201 
203  const void *UserObj, const detail::code_location &CodeLoc,
204  const void *HostObj, uint32_t Dim, size_t Range[3], uint32_t ImageFormat) {
205  (void)UserObj;
206  (void)CodeLoc;
207  (void)HostObj;
208  (void)Dim;
209  (void)Range;
210  (void)ImageFormat;
211 #ifdef XPTI_ENABLE_INSTRUMENTATION
213  constexpr uint16_t NotificationTraceType =
214  xpti::trace_offload_alloc_memory_object_construct;
215  if (!xptiCheckTraceEnabled(GImageStreamID, NotificationTraceType))
216  return;
217 
218  uint64_t IId;
219  xpti::offload_image_data_t ImgConstr{(uintptr_t)UserObj,
220  (uintptr_t)HostObj,
221  Dim,
222  {Range[0], Range[1], Range[2]},
223  ImageFormat,
224  // No sampler information
225  std::nullopt,
226  std::nullopt,
227  std::nullopt};
228 
229  xpti::trace_event_data_t *TraceEvent =
230  createTraceEvent(UserObj, "unsampled_image", IId, CodeLoc,
231  xpti::trace_offload_memory_object_event);
232  xptiNotifySubscribers(GImageStreamID, NotificationTraceType, nullptr,
233  TraceEvent, IId, &ImgConstr);
234 #endif
235 }
236 
238  (void)UserObj;
239 #ifdef XPTI_ENABLE_INSTRUMENTATION
240  constexpr uint16_t NotificationTraceType =
241  xpti::trace_offload_alloc_memory_object_destruct;
242  if (!xptiCheckTraceEnabled(GImageStreamID, NotificationTraceType))
243  return;
244  uint64_t IId = xptiGetUniqueId();
245  xpti::offload_image_data_t ImgDestr{(uintptr_t)UserObj};
246  // Destruction of user level memory object
247  xptiNotifySubscribers(GImageStreamID, NotificationTraceType, nullptr, nullptr,
248  IId, &ImgDestr);
249 #endif
250 }
251 
253  const void *UserObj, const void *AccessorObj, uint32_t Target,
254  uint32_t Mode, const void *Type, uint32_t ElemSize,
255  const detail::code_location &CodeLoc) {
256  (void)UserObj;
257  (void)AccessorObj;
258  (void)CodeLoc;
259  (void)Target;
260  (void)Mode;
261  (void)Type;
262  (void)ElemSize;
263 #ifdef XPTI_ENABLE_INSTRUMENTATION
264  constexpr uint16_t NotificationTraceType = xpti::trace_offload_alloc_accessor;
265  if (!xptiCheckTraceEnabled(GImageStreamID, NotificationTraceType))
266  return;
267 
268  uint64_t IId;
269  xpti::offload_image_accessor_data_t AccessorConstr{(uintptr_t)UserObj,
270  (uintptr_t)AccessorObj,
271  Target,
272  Mode,
273  (const char *)Type,
274  ElemSize};
275 
276  xpti::trace_event_data_t *TraceEvent =
277  createTraceEvent(UserObj, "unsampled_image_accessor", IId, CodeLoc,
278  xpti::trace_offload_accessor_event);
279  xptiNotifySubscribers(GImageStreamID, NotificationTraceType, nullptr,
280  TraceEvent, IId, &AccessorConstr);
281 #endif
282 }
283 
285  const void *UserObj, const void *AccessorObj, uint32_t Mode,
286  const void *Type, uint32_t ElemSize, const detail::code_location &CodeLoc) {
287  (void)UserObj;
288  (void)AccessorObj;
289  (void)CodeLoc;
290  (void)Mode;
291  (void)Type;
292  (void)ElemSize;
293 #ifdef XPTI_ENABLE_INSTRUMENTATION
294  constexpr uint16_t NotificationTraceType = xpti::trace_offload_alloc_accessor;
295  if (!xptiCheckTraceEnabled(GImageStreamID, NotificationTraceType))
296  return;
297 
298  uint64_t IId;
299  xpti::offload_image_accessor_data_t AccessorConstr{
300  (uintptr_t)UserObj, (uintptr_t)AccessorObj,
301  std::nullopt, Mode,
302  (const char *)Type, ElemSize};
303 
304  xpti::trace_event_data_t *TraceEvent =
305  createTraceEvent(UserObj, "host_unsampled_image_accessor", IId, CodeLoc,
306  xpti::trace_offload_accessor_event);
307  xptiNotifySubscribers(GImageStreamID, NotificationTraceType, nullptr,
308  TraceEvent, IId, &AccessorConstr);
309 #endif
310 }
311 
313  const void *UserObj, const void *AccessorObj, uint32_t Target,
314  const void *Type, uint32_t ElemSize, const detail::code_location &CodeLoc) {
315  (void)UserObj;
316  (void)AccessorObj;
317  (void)CodeLoc;
318  (void)Target;
319  (void)Type;
320  (void)ElemSize;
321 #ifdef XPTI_ENABLE_INSTRUMENTATION
322  constexpr uint16_t NotificationTraceType = xpti::trace_offload_alloc_accessor;
323  if (!xptiCheckTraceEnabled(GImageStreamID, NotificationTraceType))
324  return;
325 
326  uint64_t IId;
327  xpti::offload_image_accessor_data_t AccessorConstr{
328  (uintptr_t)UserObj, (uintptr_t)AccessorObj, Target,
329  std::nullopt, (const char *)Type, ElemSize};
330 
331  xpti::trace_event_data_t *TraceEvent =
332  createTraceEvent(UserObj, "sampled_image_accessor", IId, CodeLoc,
333  xpti::trace_offload_accessor_event);
334  xptiNotifySubscribers(GImageStreamID, NotificationTraceType, nullptr,
335  TraceEvent, IId, &AccessorConstr);
336 #endif
337 }
338 
340  const void *UserObj, const void *AccessorObj, const void *Type,
341  uint32_t ElemSize, const detail::code_location &CodeLoc) {
342  (void)UserObj;
343  (void)AccessorObj;
344  (void)CodeLoc;
345  (void)Type;
346  (void)ElemSize;
347 #ifdef XPTI_ENABLE_INSTRUMENTATION
348  constexpr uint16_t NotificationTraceType = xpti::trace_offload_alloc_accessor;
349  if (!xptiCheckTraceEnabled(GImageStreamID, NotificationTraceType))
350  return;
351 
352  uint64_t IId;
353  xpti::offload_image_accessor_data_t AccessorConstr{
354  (uintptr_t)UserObj, (uintptr_t)AccessorObj, std::nullopt,
355  std::nullopt, (const char *)Type, ElemSize};
356 
357  xpti::trace_event_data_t *TraceEvent =
358  createTraceEvent(UserObj, "host_sampled_image_accessor", IId, CodeLoc,
359  xpti::trace_offload_accessor_event);
360  xptiNotifySubscribers(GImageStreamID, NotificationTraceType, nullptr,
361  TraceEvent, IId, &AccessorConstr);
362 #endif
363 }
364 
365 } // namespace detail
366 } // namespace _V1
367 } // namespace sycl
sycl::_V1::detail::XPTIRegistry::bufferDestructorNotification
static void bufferDestructorNotification(const void *)
Definition: xpti_registry.cpp:109
xpti_registry.hpp
sycl::_V1::detail::GlobalHandler::getXPTIRegistry
XPTIRegistry & getXPTIRegistry()
Definition: global_handler.cpp:217
sycl::_V1::detail::GlobalHandler::instance
static GlobalHandler & instance()
Definition: global_handler.cpp:125
detail
---— Error handling, matching OpenCL plugin semantics.
Definition: common.hpp:44
sycl
Definition: access.hpp:18
sycl::_V1::detail::XPTIRegistry::unsampledImageAccessorNotification
static void unsampledImageAccessorNotification(const void *, const void *, uint32_t, uint32_t, const void *, uint32_t, const detail::code_location &)
Definition: xpti_registry.cpp:252
sycl::_V1::detail::XPTIRegistry::bufferAccessorNotification
static void bufferAccessorNotification(const void *, const void *, uint32_t, uint32_t, const detail::code_location &)
Definition: xpti_registry.cpp:124
sycl::_V1::detail::XPTIRegistry::sampledImageAccessorNotification
static void sampledImageAccessorNotification(const void *, const void *, uint32_t, const void *, uint32_t, const detail::code_location &)
Definition: xpti_registry.cpp:312
sycl::_V1::detail::XPTIRegistry::unsampledImageDestructorNotification
static void unsampledImageDestructorNotification(const void *)
Definition: xpti_registry.cpp:237
sycl::_V1::detail::XPTIRegistry::unsampledImageConstructorNotification
static void unsampledImageConstructorNotification(const void *, const detail::code_location &, const void *, uint32_t, size_t[3], uint32_t)
Definition: xpti_registry.cpp:202
sycl::_V1::detail::XPTIRegistry::unsampledImageHostAccessorNotification
static void unsampledImageHostAccessorNotification(const void *, const void *, uint32_t, const void *, uint32_t, const detail::code_location &)
Definition: xpti_registry.cpp:284
sycl::_V1::detail::XPTIRegistry::initializeFrameworkOnce
void initializeFrameworkOnce()
Definition: xpti_registry.hpp:65
sycl::_V1::detail::XPTIRegistry::bufferAssociateNotification
static void bufferAssociateNotification(const void *, const void *)
Definition: xpti_registry.cpp:71
global_handler.hpp
sycl::_V1::detail::XPTIRegistry::sampledImageHostAccessorNotification
static void sampledImageHostAccessorNotification(const void *, const void *, const void *, uint32_t, const detail::code_location &)
Definition: xpti_registry.cpp:339
sycl::_V1::detail::XPTIRegistry::sampledImageDestructorNotification
static void sampledImageDestructorNotification(const void *)
Definition: xpti_registry.cpp:187
sycl::_V1::detail::code_location
Definition: common.hpp:66
sycl::_V1::detail::XPTIRegistry::bufferReleaseNotification
static void bufferReleaseNotification(const void *, const void *)
Definition: xpti_registry.cpp:90
sycl::_V1::detail::XPTIRegistry::bufferConstructorNotification
static void bufferConstructorNotification(const void *, const detail::code_location &, const void *, const void *, uint32_t, uint32_t, size_t[3])
Definition: xpti_registry.cpp:38
sycl::_V1::detail::XPTIRegistry::sampledImageConstructorNotification
static void sampledImageConstructorNotification(const void *, const detail::code_location &, const void *, uint32_t, size_t[3], uint32_t, uint32_t, uint32_t, uint32_t)
Definition: xpti_registry.cpp:148