DPC++ Runtime
Runtime libraries for oneAPI DPC++
xpti_registry.hpp
Go to the documentation of this file.
1 //==---------- xpti_registry.hpp ----- 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 
9 #pragma once
10 
11 #include <mutex>
12 #include <string>
13 #include <unordered_set>
14 
16 
17 #ifdef XPTI_ENABLE_INSTRUMENTATION
18 // Include the headers necessary for emitting
19 // traces using the trace framework
20 #include "xpti/xpti_trace_framework.h"
21 #endif
22 
24 namespace sycl {
25 namespace detail {
26 // We define a sycl stream name and this will be used by the instrumentation
27 // framework
28 inline constexpr const char *SYCL_STREAM_NAME = "sycl";
29 // Stream name being used for traces generated from the SYCL plugin layer
30 inline constexpr const char *SYCL_PICALL_STREAM_NAME = "sycl.pi";
31 // Stream name being used for traces generated from PI calls. This stream
32 // contains information about function arguments.
33 inline constexpr const char *SYCL_PIDEBUGCALL_STREAM_NAME = "sycl.pi.debug";
34 inline constexpr auto SYCL_MEM_ALLOC_STREAM_NAME =
35  "sycl.experimental.mem_alloc";
36 
37 #ifdef XPTI_ENABLE_INSTRUMENTATION
38 extern uint8_t GBufferStreamID;
39 extern uint8_t GMemAllocStreamID;
40 extern xpti::trace_event_data_t *GMemAllocEvent;
41 #endif
42 
43 // Stream name being used to notify about buffer objects.
44 inline constexpr const char *SYCL_BUFFER_STREAM_NAME =
45  "sycl.experimental.buffer";
46 
47 class XPTIRegistry {
48 public:
50 #ifdef XPTI_ENABLE_INSTRUMENTATION
51  std::call_once(MInitialized, [this] {
52  xptiFrameworkInitialize();
53  // SYCL buffer events
54  GBufferStreamID = xptiRegisterStream(SYCL_BUFFER_STREAM_NAME);
55  this->initializeStream(SYCL_BUFFER_STREAM_NAME, 0, 1, "0.1");
56 
57  // Memory allocation events
58  GMemAllocStreamID = xptiRegisterStream(SYCL_MEM_ALLOC_STREAM_NAME);
59  this->initializeStream(SYCL_MEM_ALLOC_STREAM_NAME, 0, 1, "0.1");
60  xpti::payload_t MAPayload("SYCL Memory Allocations Layer");
61  uint64_t MAInstanceNo = 0;
62  GMemAllocEvent = xptiMakeEvent("SYCL Memory Allocations", &MAPayload,
63  xpti::trace_algorithm_event,
64  xpti_at::active, &MAInstanceNo);
65  });
66 #endif
67  }
68 
75  void initializeStream(const std::string &StreamName, uint32_t MajVer,
76  uint32_t MinVer, const std::string &VerStr) {
77 #ifdef XPTI_ENABLE_INSTRUMENTATION
78  MActiveStreams.insert(StreamName);
79  xptiInitialize(StreamName.c_str(), MajVer, MinVer, VerStr.c_str());
80 #endif // XPTI_ENABLE_INSTRUMENTATION
81  }
82 
84 #ifdef XPTI_ENABLE_INSTRUMENTATION
85  for (const auto &StreamName : MActiveStreams) {
86  xptiFinalize(StreamName.c_str());
87  }
88  xptiFrameworkFinalize();
89 #endif // XPTI_ENABLE_INSTRUMENTATION
90  }
91 
92  static void bufferConstructorNotification(const void *,
93  const detail::code_location &,
94  const void *, const void *,
95  uint32_t, uint32_t, size_t[3]);
96  static void bufferAssociateNotification(const void *, const void *);
97  static void bufferReleaseNotification(const void *, const void *);
98  static void bufferDestructorNotification(const void *);
99  static void bufferAccessorNotification(const void *, const void *, uint32_t,
100  uint32_t,
101  const detail::code_location &);
102 
103 private:
104  std::unordered_set<std::string> MActiveStreams;
105  std::once_flag MInitialized;
106 
107 #ifdef XPTI_ENABLE_INSTRUMENTATION
108  static xpti::trace_event_data_t *
109  createTraceEvent(const void *Obj, const void *ObjName, uint64_t &IId,
110  const detail::code_location &CodeLoc,
111  uint16_t TraceEventType);
112 #endif // XPTI_ENABLE_INSTRUMENTATION
113 };
114 } // namespace detail
115 } // namespace sycl
116 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::SYCL_PIDEBUGCALL_STREAM_NAME
constexpr const char * SYCL_PIDEBUGCALL_STREAM_NAME
Definition: xpti_registry.hpp:33
cl::sycl::detail::SYCL_MEM_ALLOC_STREAM_NAME
constexpr auto SYCL_MEM_ALLOC_STREAM_NAME
Definition: xpti_registry.hpp:34
cl::sycl::detail::SYCL_PICALL_STREAM_NAME
constexpr const char * SYCL_PICALL_STREAM_NAME
Definition: xpti_registry.hpp:30
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::code_location
Definition: common.hpp:54
cl::sycl::detail::SYCL_STREAM_NAME
constexpr const char * SYCL_STREAM_NAME
Definition: xpti_registry.hpp:28
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::XPTIRegistry
Definition: xpti_registry.hpp:47
cl::sycl::detail::XPTIRegistry::~XPTIRegistry
~XPTIRegistry()
Definition: xpti_registry.hpp:83
cl::sycl::detail::SYCL_BUFFER_STREAM_NAME
constexpr const char * SYCL_BUFFER_STREAM_NAME
Definition: xpti_registry.hpp:44
cl::sycl::detail::XPTIRegistry::initializeFrameworkOnce
void initializeFrameworkOnce()
Definition: xpti_registry.hpp:49
common.hpp
cl::sycl::detail::XPTIRegistry::initializeStream
void initializeStream(const std::string &StreamName, uint32_t MajVer, uint32_t MinVer, const std::string &VerStr)
Notifies XPTI subscribers about new stream.
Definition: xpti_registry.hpp:75
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12