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 {
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 
38 void XPTIRegistry::bufferConstructorNotification(
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
50  GlobalHandler::instance().getXPTIRegistry().initializeFrameworkOnce();
51  if (!xptiTraceEnabled())
52  return;
53 
54  uint64_t IId;
55  xpti::offload_buffer_data_t BufConstr{(uintptr_t)UserObj,
56  (uintptr_t)HostObj,
57  (const char *)Type,
58  ElemSize,
59  Dim,
60  {Range[0], Range[1], Range[2]}};
61 
62  xpti::trace_event_data_t *TraceEvent = createTraceEvent(
63  UserObj, "buffer", IId, CodeLoc, xpti::trace_offload_buffer_event);
64  xptiNotifySubscribers(GBufferStreamID, xpti::trace_offload_alloc_construct,
65  nullptr, TraceEvent, IId, &BufConstr);
66 #endif
67 }
68 
69 void XPTIRegistry::bufferAssociateNotification(const void *UserObj,
70  const void *MemObj) {
71  (void)UserObj;
72  (void)MemObj;
73 #ifdef XPTI_ENABLE_INSTRUMENTATION
74  if (!xptiTraceEnabled())
75  return;
76  uint64_t IId = xptiGetUniqueId();
77  xpti::offload_buffer_association_data_t BufAssoc{(uintptr_t)UserObj,
78  (uintptr_t)MemObj};
79 
80  // Add association between user level and PI level memory object
81  xptiNotifySubscribers(GBufferStreamID, xpti::trace_offload_alloc_associate,
82  nullptr, nullptr, IId, &BufAssoc);
83 #endif
84 }
85 
86 void XPTIRegistry::bufferReleaseNotification(const void *UserObj,
87  const void *MemObj) {
88  (void)UserObj;
89  (void)MemObj;
90 #ifdef XPTI_ENABLE_INSTRUMENTATION
91  if (!xptiTraceEnabled())
92  return;
93  uint64_t IId = xptiGetUniqueId();
94  xpti::offload_buffer_association_data_t BufRelease{(uintptr_t)UserObj,
95  (uintptr_t)MemObj};
96 
97  // Release PI level memory object
98  xptiNotifySubscribers(GBufferStreamID, xpti::trace_offload_alloc_release,
99  nullptr, nullptr, IId, &BufRelease);
100 #endif
101 }
102 
103 void XPTIRegistry::bufferDestructorNotification(const void *UserObj) {
104  (void)UserObj;
105 #ifdef XPTI_ENABLE_INSTRUMENTATION
106  if (!xptiTraceEnabled())
107  return;
108  uint64_t IId = xptiGetUniqueId();
109  xpti::offload_buffer_data_t BufDestr{(uintptr_t)UserObj};
110  // Destruction of user level memory object
111  xptiNotifySubscribers(GBufferStreamID, xpti::trace_offload_alloc_destruct,
112  nullptr, nullptr, IId, &BufDestr);
113 #endif
114 }
115 
116 void XPTIRegistry::bufferAccessorNotification(
117  const void *UserObj, const void *AccessorObj, uint32_t Target,
118  uint32_t Mode, const detail::code_location &CodeLoc) {
119  (void)UserObj;
120  (void)AccessorObj;
121  (void)CodeLoc;
122  (void)Target;
123  (void)Mode;
124 #ifdef XPTI_ENABLE_INSTRUMENTATION
125  if (!xptiTraceEnabled())
126  return;
127 
128  uint64_t IId;
129  xpti::offload_accessor_data_t AccessorConstr{
130  (uintptr_t)UserObj, (uintptr_t)AccessorObj, Target, Mode};
131 
132  xpti::trace_event_data_t *TraceEvent = createTraceEvent(
133  UserObj, "accessor", IId, CodeLoc, xpti::trace_offload_accessor_event);
134  xptiNotifySubscribers(GBufferStreamID, xpti::trace_offload_alloc_accessor,
135  nullptr, TraceEvent, IId, &AccessorConstr);
136 #endif
137 }
138 
139 } // namespace detail
140 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
141 } // namespace sycl
#define __SYCL_INLINE_VER_NAMESPACE(X)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14