kokkos-utils 0.0.1
 
Loading...
Searching...
No Matches
Events.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_UTILS_CALLBACKS_EVENTS_HPP
2#define KOKKOS_UTILS_CALLBACKS_EVENTS_HPP
3
4#include <iomanip>
5
6#include "impl/Kokkos_Profiling.hpp"
7
9
11{
12
25{
26 std::string name {};
27 uint32_t dev_id = 0;
28 uint64_t event_id = 0;
29};
30
33{
34 uint64_t event_id = 0;
35};
36
39{
40 std::string name {};
41 uint32_t dev_id = 0;
42 uint64_t event_id = 0;
43};
44
47{
48 uint64_t event_id = 0;
49};
50
53{
54 std::string name {};
55 uint32_t dev_id = 0;
56 uint64_t event_id = 0;
57};
58
61{
62 uint64_t event_id = 0;
63};
64
67{
68 std::string name {};
69 uint32_t dev_id = 0;
70 uint64_t event_id = 0;
71};
72
75{
76 uint64_t event_id = 0;
77};
78
81{
82 Kokkos_Profiling_SpaceHandle kpsh {};
83 std::string name {};
84 const void* ptr = nullptr;
85 uint64_t size = 0;
86};
87
93
99
106
109
112{
113 std::string name {};
114 uint32_t section_id = 0;
115};
116
119{
120 uint32_t section_id = 0;
121};
122
125{
126 uint32_t section_id = 0;
127};
128
131{
132 uint32_t section_id = 0;
133};
134
137{
138 std::string name {};
139};
140
143
146{
147 std::string name {};
148};
149
150
152using EventTypeList = Kokkos::Impl::type_list<
163>;
164
168template <typename T>
170
172template <typename EventType>
173concept BeginEvent =
175 std::constructible_from<EventType, const char*, uint32_t, uint64_t> &&
176 requires (EventType event) {
177 { event.name } -> std::same_as<std::string&>;
178 { event.dev_id } -> std::same_as<uint32_t&>;
179 { event.event_id } -> std::same_as<uint64_t&>;
180 };
181
183template <typename EventType>
184concept EndEvent =
186 std::constructible_from<EventType, uint64_t> &&
187 requires (EventType event) {
188 { event.event_id } -> std::same_as<uint64_t&>;
189 };
190
192template <typename EventType>
193concept DataEvent =
195 std::constructible_from<EventType, AllocDescriptor> &&
196 requires (EventType event) {
197 { event.alloc } -> std::same_as<AllocDescriptor&>;
198 };
199
201template <typename EventType>
204 std::constructible_from<EventType, uint32_t> &&
205 requires (EventType event) {
206 { event.section_id } -> std::same_as<uint32_t&>;
207 };
208
210template <typename EventType>
211concept NamedEvent =
213 requires (EventType event) {
214 { event.name } -> std::same_as<std::string&>;
215 };
216
218template <typename T, typename EventTypeListType>
221
225template <Event EventType>
226constexpr auto get_name() {
227 return Kokkos::Impl::TypeInfo<EventType>::name().substr(26); // erase "Kokkos::utils::callbacks::"
228}
229
230template <Event EventType>
231std::ostream& operator<<(std::ostream &out, const EventType& /* event */) {
232 return out << get_name<EventType>() << ": "
233 << "{}";
234}
235
236template <BeginEvent EventType>
237std::ostream& operator<<(std::ostream &out, const EventType& event) {
238 return out << get_name<EventType>() << ": "
239 << "{name = " << std::quoted(event.name) << ", dev_id = " << event.dev_id << ", event_id = " << event.event_id << "}";
240}
241
242template <EndEvent EventType>
243std::ostream& operator<<(std::ostream &out, const EventType& event) {
244 return out << get_name<EventType>() << ": "
245 << "{event_id = " << event.event_id << "}";
246}
247
248template <DataEvent EventType>
249std::ostream& operator<<(std::ostream &out, const EventType& event) {
250 const auto& alloc = event.alloc;
251 return out << get_name<EventType>() << ": "
252 << "{name = " << std::quoted(alloc.name) << ", space = " << std::quoted(alloc.kpsh.name) << ", ptr = " << alloc.ptr << ", size = " << alloc.size << "}";
253}
254
255inline std::ostream& operator<<(std::ostream &out, const BeginDeepCopyEvent& event) {
256 const auto& dst = event.dst;
257 const auto& src = event.src;
258 return out << get_name<BeginDeepCopyEvent>() << ": "
259 << "{src = " << std::quoted(src.name) << " (" << src.kpsh.name << ", " << src.ptr << ") -> "
260 << "dst = " << std::quoted(dst.name) << " (" << dst.kpsh.name << ", " << dst.ptr << ") of size " << src.size << "}";
261}
262
263inline std::ostream& operator<<(std::ostream &out, const CreateProfileSectionEvent& event) {
264 return out << get_name<CreateProfileSectionEvent>() << ": "
265 << "{name = " << std::quoted(event.name) << ", section_id = " << event.section_id << "}";
266}
267
268template <ProfileSectionManipulationEvent EventType>
269std::ostream& operator<<(std::ostream &out, const EventType& event) {
270 return out << get_name<EventType>() << ": "
271 << "{section_id = " << event.section_id << "}";
272}
273
274inline std::ostream& operator<<(std::ostream &out, const PushRegionEvent& event) {
275 return out << get_name<PushRegionEvent>() << ": "
276 << "{name = " << std::quoted(event.name) << "}";
277}
278
279inline std::ostream& operator<<(std::ostream &out, const ProfileEvent& event) {
280 return out << get_name<ProfileEvent>() << ": "
281 << "{name = " << std::quoted(event.name) << "}";
282}
283
284
288template <Event EventType>
289auto get_callback_from_eventset(const Kokkos::Tools::Experimental::EventSet& event_set);
290
292#define GET_CALLBACK_FROM_EVENTSET(__eventtype__, __callback__) \
293 template <> \
294 inline auto get_callback_from_eventset<__eventtype__>(const Kokkos::Tools::Experimental::EventSet& event_set) { return event_set.__callback__; }
295
315
317template <Event EventType>
319
321#define GET_CALLBACK_SETTER(__eventtype__, __callback_setter__) \
322 template <> \
323 inline auto get_callback_setter<__eventtype__>() { return &Kokkos::Tools::Experimental::__callback_setter__; }
324
325GET_CALLBACK_SETTER(BeginParallelForEvent, set_begin_parallel_for_callback)
326GET_CALLBACK_SETTER(EndParallelForEvent, set_end_parallel_for_callback)
327GET_CALLBACK_SETTER(BeginParallelReduceEvent, set_begin_parallel_reduce_callback)
328GET_CALLBACK_SETTER(EndParallelReduceEvent, set_end_parallel_reduce_callback)
329GET_CALLBACK_SETTER(BeginParallelScanEvent, set_begin_parallel_scan_callback)
330GET_CALLBACK_SETTER(EndParallelScanEvent, set_end_parallel_scan_callback)
331GET_CALLBACK_SETTER(BeginFenceEvent, set_begin_fence_callback)
332GET_CALLBACK_SETTER(EndFenceEvent, set_end_fence_callback)
333GET_CALLBACK_SETTER(AllocateDataEvent, set_allocate_data_callback)
334GET_CALLBACK_SETTER(DeallocateDataEvent, set_deallocate_data_callback)
335GET_CALLBACK_SETTER(BeginDeepCopyEvent, set_begin_deep_copy_callback)
336GET_CALLBACK_SETTER(EndDeepCopyEvent, set_end_deep_copy_callback)
337GET_CALLBACK_SETTER(CreateProfileSectionEvent, set_create_profile_section_callback)
338GET_CALLBACK_SETTER(StartProfileSectionEvent, set_start_profile_section_callback)
339GET_CALLBACK_SETTER(StopProfileSectionEvent, set_stop_profile_section_callback)
340GET_CALLBACK_SETTER(DestroyProfileSectionEvent, set_destroy_profile_section_callback)
341GET_CALLBACK_SETTER(PushRegionEvent, set_push_region_callback)
342GET_CALLBACK_SETTER(PopRegionEvent, set_pop_region_callback)
343GET_CALLBACK_SETTER(ProfileEvent, set_profile_event_callback)
345
346} // namespace Kokkos::utils::callbacks
347
348#endif // KOKKOS_UTILS_CALLBACKS_EVENTS_HPP
#define GET_CALLBACK_SETTER(__eventtype__, __callback_setter__)
Helper macro related to the implementation of Kokkos::utils::callbacks::get_callback_setter.
Definition Events.hpp:321
#define GET_CALLBACK_FROM_EVENTSET(__eventtype__, __callback__)
Helper macro related to the implementation of Kokkos::utils::callbacks::get_callback_from_eventset.
Definition Events.hpp:292
Concept to constrain any begin event type.
Definition Events.hpp:173
Concept to constrain any data event type.
Definition Events.hpp:193
Concept to constrain any end event type.
Definition Events.hpp:184
Concept to constrain any event type that is one of the given event types.
Definition Events.hpp:219
Concept to constrain any event type that has a name field.
Definition Events.hpp:211
Concept to constrain any profile section manipulation event type.
Definition Events.hpp:202
std::ostream & operator<<(std::ostream &out, const EventType &)
Definition Events.hpp:231
constexpr auto get_name()
Definition Events.hpp:226
Kokkos::Impl::type_list< BeginParallelForEvent, EndParallelForEvent, BeginParallelReduceEvent, EndParallelReduceEvent, BeginParallelScanEvent, EndParallelScanEvent, BeginFenceEvent, EndFenceEvent, AllocateDataEvent, DeallocateDataEvent, BeginDeepCopyEvent, EndDeepCopyEvent, CreateProfileSectionEvent, DestroyProfileSectionEvent, StartProfileSectionEvent, StopProfileSectionEvent, PushRegionEvent, PopRegionEvent, ProfileEvent > EventTypeList
Type list holding all event types.
Definition Events.hpp:152
auto get_callback_from_eventset(const Kokkos::Tools::Experimental::EventSet &event_set)
auto get_callback_setter()
Get the setter function of a Kokkos profiling callback corresponding to EventType.
constexpr bool type_list_contains_v
Definition type_list.hpp:36
Helper struct to hold descriptors of a data allocation.
Definition Events.hpp:81
Kokkos_Profiling_SpaceHandle kpsh
Definition Events.hpp:82
Allocate-data event associated with Kokkos::Tools::Experimental::EventSet::allocate_data.
Definition Events.hpp:90
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
Definition Events.hpp:102
Begin-fence event associated with Kokkos::Tools::Experimental::EventSet::begin_fence.
Definition Events.hpp:67
Begin-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_red...
Definition Events.hpp:39
Begin-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_scan.
Definition Events.hpp:53
Create-profile-section event associated with Kokkos::Tools::Experimental::EventSet::create_profile_se...
Definition Events.hpp:112
Deallocate-data event associated with Kokkos::Tools::Experimental::EventSet::deallocate_data.
Definition Events.hpp:96
Destroy-profile-section event associated with Kokkos::Tools::Experimental::EventSet::destroy_profile_...
Definition Events.hpp:131
End-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::end_deep_copy.
Definition Events.hpp:108
End-fence event associated with Kokkos::Tools::Experimental::EventSet::end_fence.
Definition Events.hpp:75
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
Definition Events.hpp:33
End-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_reduce.
Definition Events.hpp:47
End-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_scan.
Definition Events.hpp:61
Pop-region event associated with Kokkos::Tools::Experimental::EventSet::pop_region.
Definition Events.hpp:142
Profile event associated with Kokkos::Tools::Experimental::EventSet::profile_event.
Definition Events.hpp:146
Push-region event associated with Kokkos::Tools::Experimental::EventSet::push_region.
Definition Events.hpp:137
Start-profile-section event associated with Kokkos::Tools::Experimental::EventSet::start_profile_sect...
Definition Events.hpp:119
Stop-profile-section event associated with Kokkos::Tools::Experimental::EventSet::stop_profile_sectio...
Definition Events.hpp:125