13 #include <unordered_set>
16 #include <sycl/version.hpp>
18 #ifdef XPTI_ENABLE_INSTRUMENTATION
21 #include "xpti/xpti_trace_framework.hpp"
25 inline namespace _V1 {
36 "sycl.experimental.mem_alloc";
38 #ifdef XPTI_ENABLE_INSTRUMENTATION
39 extern uint8_t GBufferStreamID;
40 extern uint8_t GImageStreamID;
41 extern uint8_t GMemAllocStreamID;
42 extern xpti::trace_event_data_t *GMemAllocEvent;
43 extern xpti::trace_event_data_t *GSYCLGraphEvent;
46 inline constexpr
auto XPTI_QUEUE_INSTANCE_ID_KEY =
"queue_id";
49 #define SYCL_VERSION_STR \
50 "sycl " STR(__LIBSYCL_MAJOR_VERSION) "." STR(__LIBSYCL_MINOR_VERSION)
54 constexpr uint32_t
GMajVer = __LIBSYCL_MAJOR_VERSION;
55 constexpr uint32_t
GMinVer = __LIBSYCL_MINOR_VERSION;
56 constexpr
const char *
GVerStr = SYCL_VERSION_STR;
61 "sycl.experimental.buffer";
69 #ifdef XPTI_ENABLE_INSTRUMENTATION
70 std::call_once(MInitialized, [
this] {
71 xptiFrameworkInitialize();
82 xpti::payload_t MAPayload(
"SYCL Memory Allocations Layer");
83 uint64_t MAInstanceNo = 0;
84 GMemAllocEvent = xptiMakeEvent(
"SYCL Memory Allocations", &MAPayload,
85 xpti::trace_algorithm_event,
86 xpti_at::active, &MAInstanceNo);
98 uint32_t MinVer,
const std::string &VerStr) {
99 #ifdef XPTI_ENABLE_INSTRUMENTATION
100 MActiveStreams.insert(StreamName);
101 xptiInitialize(StreamName.c_str(), MajVer, MinVer, VerStr.c_str());
106 #ifdef XPTI_ENABLE_INSTRUMENTATION
107 for (
const auto &StreamName : MActiveStreams) {
108 xptiFinalize(StreamName.c_str());
110 xptiFrameworkFinalize();
116 const void *,
const void *,
117 uint32_t, uint32_t,
size_t[3]);
127 const void *, uint32_t,
128 size_t[3], uint32_t, uint32_t,
134 size_t[3], uint32_t);
139 const void *, uint32_t,
143 const void *, uint32_t,
146 uint32_t,
const void *, uint32_t,
153 std::unordered_set<std::string> MActiveStreams;
154 std::once_flag MInitialized;
156 #ifdef XPTI_ENABLE_INSTRUMENTATION
157 static xpti::trace_event_data_t *
158 createTraceEvent(
const void *Obj,
const void *ObjName, uint64_t &IId,
160 uint16_t TraceEventType);
167 #if XPTI_ENABLE_INSTRUMENTATION
170 using TracePoint = xpti::framework::tracepoint_t;
180 XPTIScope(
void *CodePtr, uint16_t TraceType,
const char *StreamName,
181 uint64_t InstanceID,
const char *UserData)
182 : MUserData(UserData), MStreamID(0), MInstanceID(InstanceID),
183 MScopedNotify(false), MTraceType(0) {
185 auto TData = Tls.
query();
189 if (!TData.functionName() && !TData.fileName())
192 MTP =
new TracePoint(TData.fileName(), FuncName, TData.lineNumber(),
193 TData.columnNumber(), CodePtr);
194 if (TraceType == (uint16_t)xpti::trace_point_type_t::graph_create ||
195 TraceType == (uint16_t)xpti::trace_point_type_t::node_create ||
196 TraceType == (uint16_t)xpti::trace_point_type_t::edge_create ||
197 TraceType == (uint16_t)xpti::trace_point_type_t::queue_create)
198 MTP->parent_event(GSYCLGraphEvent);
200 if (xptiTraceEnabled() && MTP) {
201 MTP->stream(StreamName).trace_type((xpti::trace_point_type_t)TraceType);
202 MTraceEvent =
const_cast<xpti::trace_event_data_t *
>(MTP->trace_event());
203 MStreamID = MTP->stream_id();
206 MTP->override_instance_id(MInstanceID);
217 XPTIScope(
void *CodePtr, uint16_t TraceType,
const char *StreamName,
218 const char *UserData)
219 : MUserData(UserData), MStreamID(0), MInstanceID(0), MScopedNotify(false),
221 detail::tls_code_loc_t Tls;
222 auto TData = Tls.
query();
226 if (!TData.functionName() && !TData.fileName())
229 MTP =
new TracePoint(TData.fileName(), FuncName, TData.lineNumber(),
230 TData.columnNumber(), CodePtr);
231 if (TraceType == (uint16_t)xpti::trace_point_type_t::graph_create ||
232 TraceType == (uint16_t)xpti::trace_point_type_t::node_create ||
233 TraceType == (uint16_t)xpti::trace_point_type_t::edge_create ||
234 TraceType == (uint16_t)xpti::trace_point_type_t::queue_create)
235 MTP->parent_event(GSYCLGraphEvent);
237 if (xptiTraceEnabled() && MTP) {
238 MTP->stream(StreamName).trace_type((xpti::trace_point_type_t)TraceType);
239 MTraceEvent =
const_cast<xpti::trace_event_data_t *
>(MTP->trace_event());
240 MStreamID = MTP->stream_id();
241 MInstanceID = MTP->instance_id();
245 XPTIScope(
const XPTIScope &rhs) =
delete;
247 XPTIScope &
operator=(
const XPTIScope &rhs) =
delete;
249 xpti::trace_event_data_t *traceEvent() {
return MTraceEvent; }
251 uint8_t streamID() {
return MStreamID; }
253 uint64_t instanceID() {
return MTP ? MTP->instance_id() : 0; }
256 addMetadata(
const std::function<
void(xpti::trace_event_data_t *)> &Callback) {
257 if (xptiTraceEnabled() && MTP) {
258 auto TEvent =
const_cast<xpti::trace_event_data_t *
>(MTP->trace_event());
264 XPTIScope ¬ify() {
265 MTP->notify(
static_cast<const void *
>(MUserData));
271 XPTIScope &scopedNotify(uint16_t TraceType) {
274 MTraceType = TraceType & 0xfffe;
275 MScopedNotify =
true;
276 if (xptiCheckTraceEnabled(MStreamID, TraceType) && MTP) {
277 xptiNotifySubscribers(MStreamID, MTraceType,
nullptr, MTraceEvent,
278 MInstanceID,
static_cast<const void *
>(MUserData));
283 MTraceType = MTraceType | 1;
284 if (xptiCheckTraceEnabled(MStreamID, MTraceType) && MTP && MScopedNotify) {
285 if (MTraceType == (uint16_t)xpti::trace_point_type_t::signal ||
286 MTraceType == (uint16_t)xpti::trace_point_type_t::graph_create ||
287 MTraceType == (uint16_t)xpti::trace_point_type_t::node_create ||
288 MTraceType == (uint16_t)xpti::trace_point_type_t::edge_create ||
289 MTraceType == (uint16_t)xpti::trace_point_type_t::queue_create ||
290 MTraceType == (uint16_t)xpti::trace_point_type_t::queue_destroy ||
291 MTraceType == (uint16_t)xpti::trace_point_type_t::diagnostics)
295 xptiNotifySubscribers(MStreamID, MTraceType,
nullptr, MTraceEvent,
296 MInstanceID,
static_cast<const void *
>(MUserData));
305 TracePoint *MTP =
nullptr;
307 xpti::trace_event_data_t *MTraceEvent =
nullptr;
309 const char *MUserData =
nullptr;
314 uint64_t MInstanceID;
static void sampledImageHostAccessorNotification(const void *, const void *, const void *, uint32_t, const detail::code_location &)
static void bufferAccessorNotification(const void *, const void *, uint32_t, uint32_t, const detail::code_location &)
static void bufferAssociateNotification(const void *, const void *)
static void unsampledImageAccessorNotification(const void *, const void *, uint32_t, uint32_t, const void *, uint32_t, const detail::code_location &)
static void bufferConstructorNotification(const void *, const detail::code_location &, const void *, const void *, uint32_t, uint32_t, size_t[3])
static void unsampledImageHostAccessorNotification(const void *, const void *, uint32_t, const void *, uint32_t, const detail::code_location &)
static void sampledImageDestructorNotification(const void *)
static void unsampledImageDestructorNotification(const void *)
static void bufferDestructorNotification(const void *)
static void sampledImageAccessorNotification(const void *, const void *, uint32_t, const void *, uint32_t, const detail::code_location &)
void initializeFrameworkOnce()
static void bufferReleaseNotification(const void *, const void *)
static void unsampledImageConstructorNotification(const void *, const detail::code_location &, const void *, uint32_t, size_t[3], uint32_t)
void initializeStream(const std::string &StreamName, uint32_t MajVer, uint32_t MinVer, const std::string &VerStr)
Notifies XPTI subscribers about new stream.
static void sampledImageConstructorNotification(const void *, const detail::code_location &, const void *, uint32_t, size_t[3], uint32_t, uint32_t, uint32_t, uint32_t)
Data type that manages the code_location information in TLS.
const detail::code_location & query()
Query the information in the TLS slot.
constexpr const char * SYCL_IMAGE_STREAM_NAME
constexpr const char * SYCL_PIDEBUGCALL_STREAM_NAME
constexpr const char * SYCL_STREAM_NAME
constexpr auto SYCL_MEM_ALLOC_STREAM_NAME
constexpr const char * SYCL_BUFFER_STREAM_NAME
constexpr const char * SYCL_PICALL_STREAM_NAME
PropertyListT int access::address_space multi_ptr & operator=(multi_ptr &&)=default
constexpr const char * functionName() const noexcept