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
14bool operator==(const Kokkos_Profiling_SpaceHandle& fst, const Kokkos_Profiling_SpaceHandle& snd) {
15 return strcmp(fst.name, snd.name) == 0;
16};
17
30{
31 std::string name {};
32 uint32_t dev_id = 0;
33 uint64_t event_id = 0;
34
35 bool operator==(const BeginParallelForEvent&) const = default;
36};
37
40{
41 uint64_t event_id = 0;
42
43 bool operator==(const EndParallelForEvent&) const = default;
44};
45
48{
49 std::string name {};
50 uint32_t dev_id = 0;
51 uint64_t event_id = 0;
52
53 bool operator==(const BeginParallelReduceEvent&) const = default;
54};
55
58{
59 uint64_t event_id = 0;
60
61 bool operator==(const EndParallelReduceEvent&) const = default;
62};
63
66{
67 std::string name {};
68 uint32_t dev_id = 0;
69 uint64_t event_id = 0;
70
71 bool operator==(const BeginParallelScanEvent&) const = default;
72};
73
76{
77 uint64_t event_id = 0;
78
79 bool operator==(const EndParallelScanEvent&) const = default;
80};
81
84{
85 std::string name {};
86 uint32_t dev_id = 0;
87 uint64_t event_id = 0;
88
89 bool operator==(const BeginFenceEvent&) const = default;
90};
91
94{
95 uint64_t event_id = 0;
96
97 bool operator==(const EndFenceEvent&) const = default;
98};
99
102{
103 Kokkos_Profiling_SpaceHandle kpsh {};
104 std::string name {};
105 const void* ptr = nullptr;
106 uint64_t size = 0;
107
108 bool operator==(const AllocDescriptor&) const = default;
109};
110
113{
115
116 bool operator==(const AllocateDataEvent&) const = default;
117};
118
121{
123
124 bool operator==(const DeallocateDataEvent&) const = default;
125};
126
129{
132
133 bool operator==(const BeginDeepCopyEvent&) const = default;
134};
135
138{
139 bool operator==(const EndDeepCopyEvent&) const = default;
140};
141
144{
145 std::string name {};
146 uint32_t section_id = 0;
147
148 bool operator==(const CreateProfileSectionEvent&) const = default;
149};
150
153{
154 uint32_t section_id = 0;
155
156 bool operator==(const StartProfileSectionEvent&) const = default;
157};
158
161{
162 uint32_t section_id = 0;
163
164 bool operator==(const StopProfileSectionEvent&) const = default;
165};
166
169{
170 uint32_t section_id = 0;
171
172 bool operator==(const DestroyProfileSectionEvent&) const = default;
173};
174
177{
178 std::string name {};
179
180 bool operator==(const PushRegionEvent&) const = default;
181};
182
185{
186 bool operator==(const PopRegionEvent&) const = default;
187};
188
191{
192 std::string name {};
193
194 bool operator==(const ProfileEvent&) const = default;
195};
196
197
199using EventTypeList = Kokkos::Impl::type_list<
210>;
211
215template <typename T>
217
219template <typename EventType>
220concept BeginEvent =
222 std::constructible_from<EventType, const char*, uint32_t, uint64_t> &&
223 requires (EventType event) {
224 { event.name } -> std::same_as<std::string&>;
225 { event.dev_id } -> std::same_as<uint32_t&>;
226 { event.event_id } -> std::same_as<uint64_t&>;
227 };
228
230template <typename EventType>
231concept EndEvent =
233 std::constructible_from<EventType, uint64_t> &&
234 requires (EventType event) {
235 { event.event_id } -> std::same_as<uint64_t&>;
236 };
237
239template <typename EventType>
240concept DataEvent =
242 std::constructible_from<EventType, AllocDescriptor> &&
243 requires (EventType event) {
244 { event.alloc } -> std::same_as<AllocDescriptor&>;
245 };
246
248template <typename EventType>
251 std::constructible_from<EventType, uint32_t> &&
252 requires (EventType event) {
253 { event.section_id } -> std::same_as<uint32_t&>;
254 };
255
257template <typename EventType>
258concept NamedEvent =
260 requires (EventType event) {
261 { event.name } -> std::same_as<std::string&>;
262 };
263
265template <typename EventType>
266concept IndexedEvent = Event<EventType> && requires (EventType event) {
267 { event.event_id } -> std::same_as<uint64_t&>;
268};
269
271template <typename EventType>
272concept EnqueuedEvent = Event<EventType> && requires (EventType event) {
273 { event.dev_id } -> std::same_as<uint32_t&>;
274};
275
277template <typename T, typename... EventTypes>
278concept EventOneOf = impl::type_list_contains_v<T, EventTypes...>;
280
283template <Event EventType>
285
286#define PAIRED_EVENT_TYPE(__begin_eventtype__, __end_eventtype__) \
287 template <> \
288 struct PairedEventType<__begin_eventtype__> { using type = __end_eventtype__; };
289
299
300template <Event EventType>
301using paired_event_t = typename PairedEventType<EventType>::type;
303
307template <Event EventType>
308constexpr auto get_name() {
309 return Kokkos::Impl::TypeInfo<EventType>::name().substr(26); // erase "Kokkos::utils::callbacks::"
310}
311
312template <Event EventType>
313std::ostream& operator<<(std::ostream &out, const EventType& /* event */) {
314 return out << get_name<EventType>() << ": "
315 << "{}";
316}
317
318template <BeginEvent EventType>
319std::ostream& operator<<(std::ostream &out, const EventType& event) {
320 return out << get_name<EventType>() << ": "
321 << "{name = " << std::quoted(event.name) << ", dev_id = " << event.dev_id << ", event_id = " << event.event_id << "}";
322}
323
324template <EndEvent EventType>
325std::ostream& operator<<(std::ostream &out, const EventType& event) {
326 return out << get_name<EventType>() << ": "
327 << "{event_id = " << event.event_id << "}";
328}
329
330template <DataEvent EventType>
331std::ostream& operator<<(std::ostream &out, const EventType& event) {
332 const auto& alloc = event.alloc;
333 return out << get_name<EventType>() << ": "
334 << "{name = " << std::quoted(alloc.name) << ", space = " << std::quoted(alloc.kpsh.name) << ", ptr = " << alloc.ptr << ", size = " << alloc.size << "}";
335}
336
337inline std::ostream& operator<<(std::ostream &out, const BeginDeepCopyEvent& event) {
338 const auto& dst = event.dst;
339 const auto& src = event.src;
340 return out << get_name<BeginDeepCopyEvent>() << ": "
341 << "{src = " << std::quoted(src.name) << " (" << src.kpsh.name << ", " << src.ptr << ") -> "
342 << "dst = " << std::quoted(dst.name) << " (" << dst.kpsh.name << ", " << dst.ptr << ") of size " << src.size << "}";
343}
344
345inline std::ostream& operator<<(std::ostream &out, const CreateProfileSectionEvent& event) {
346 return out << get_name<CreateProfileSectionEvent>() << ": "
347 << "{name = " << std::quoted(event.name) << ", section_id = " << event.section_id << "}";
348}
349
350template <ProfileSectionManipulationEvent EventType>
351std::ostream& operator<<(std::ostream &out, const EventType& event) {
352 return out << get_name<EventType>() << ": "
353 << "{section_id = " << event.section_id << "}";
354}
355
356inline std::ostream& operator<<(std::ostream &out, const PushRegionEvent& event) {
357 return out << get_name<PushRegionEvent>() << ": "
358 << "{name = " << std::quoted(event.name) << "}";
359}
360
361inline std::ostream& operator<<(std::ostream &out, const ProfileEvent& event) {
362 return out << get_name<ProfileEvent>() << ": "
363 << "{name = " << std::quoted(event.name) << "}";
364}
365
366
370template <Event EventType>
371auto get_callback_from_eventset(const Kokkos::Tools::Experimental::EventSet& event_set);
372
374#define GET_CALLBACK_FROM_EVENTSET(__eventtype__, __callback__) \
375 template <> \
376 inline auto get_callback_from_eventset<__eventtype__>(const Kokkos::Tools::Experimental::EventSet& event_set) { return event_set.__callback__; }
377
397
399template <Event EventType>
401
403#define GET_CALLBACK_SETTER(__eventtype__, __callback_setter__) \
404 template <> \
405 inline auto get_callback_setter<__eventtype__>() { return &Kokkos::Tools::Experimental::__callback_setter__; }
406
407GET_CALLBACK_SETTER(BeginParallelForEvent, set_begin_parallel_for_callback)
408GET_CALLBACK_SETTER(EndParallelForEvent, set_end_parallel_for_callback)
409GET_CALLBACK_SETTER(BeginParallelReduceEvent, set_begin_parallel_reduce_callback)
410GET_CALLBACK_SETTER(EndParallelReduceEvent, set_end_parallel_reduce_callback)
411GET_CALLBACK_SETTER(BeginParallelScanEvent, set_begin_parallel_scan_callback)
412GET_CALLBACK_SETTER(EndParallelScanEvent, set_end_parallel_scan_callback)
413GET_CALLBACK_SETTER(BeginFenceEvent, set_begin_fence_callback)
414GET_CALLBACK_SETTER(EndFenceEvent, set_end_fence_callback)
415GET_CALLBACK_SETTER(AllocateDataEvent, set_allocate_data_callback)
416GET_CALLBACK_SETTER(DeallocateDataEvent, set_deallocate_data_callback)
417GET_CALLBACK_SETTER(BeginDeepCopyEvent, set_begin_deep_copy_callback)
418GET_CALLBACK_SETTER(EndDeepCopyEvent, set_end_deep_copy_callback)
419GET_CALLBACK_SETTER(CreateProfileSectionEvent, set_create_profile_section_callback)
420GET_CALLBACK_SETTER(StartProfileSectionEvent, set_start_profile_section_callback)
421GET_CALLBACK_SETTER(StopProfileSectionEvent, set_stop_profile_section_callback)
422GET_CALLBACK_SETTER(DestroyProfileSectionEvent, set_destroy_profile_section_callback)
423GET_CALLBACK_SETTER(PushRegionEvent, set_push_region_callback)
424GET_CALLBACK_SETTER(PopRegionEvent, set_pop_region_callback)
425GET_CALLBACK_SETTER(ProfileEvent, set_profile_event_callback)
427
428} // namespace Kokkos::utils::callbacks
429
430#endif // KOKKOS_UTILS_CALLBACKS_EVENTS_HPP
#define PAIRED_EVENT_TYPE(__begin_eventtype__, __end_eventtype__)
Definition Events.hpp:286
#define GET_CALLBACK_SETTER(__eventtype__, __callback_setter__)
Helper macro related to the implementation of Kokkos::utils::callbacks::get_callback_setter.
Definition Events.hpp:403
#define GET_CALLBACK_FROM_EVENTSET(__eventtype__, __callback__)
Helper macro related to the implementation of Kokkos::utils::callbacks::get_callback_from_eventset.
Definition Events.hpp:374
Concept to constrain any begin event type.
Definition Events.hpp:220
Concept to constrain any data event type.
Definition Events.hpp:240
Concept to constrain any end event type.
Definition Events.hpp:231
Concept to constrain any event type that has a member variable dev_id.
Definition Events.hpp:272
Concept to constrain any event type that is one of the given event types.
Definition Events.hpp:278
Concept to constrain any event type that has a member variable event_id.
Definition Events.hpp:266
Concept to constrain any event type that has a name field.
Definition Events.hpp:258
Concept to constrain any profile section manipulation event type.
Definition Events.hpp:249
bool operator==(const Kokkos_Profiling_SpaceHandle &fst, const Kokkos_Profiling_SpaceHandle &snd)
Equality comparison for Kokkos_Profiling_SpaceHandle.
Definition Events.hpp:14
std::ostream & operator<<(std::ostream &out, const EventType &)
Definition Events.hpp:313
constexpr auto get_name()
Definition Events.hpp:308
typename PairedEventType< EventType >::type paired_event_t
Definition Events.hpp:301
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:199
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:73
Helper struct to hold descriptors of a data allocation.
Definition Events.hpp:102
Kokkos_Profiling_SpaceHandle kpsh
Definition Events.hpp:103
bool operator==(const AllocDescriptor &) const =default
Allocate-data event associated with Kokkos::Tools::Experimental::EventSet::allocate_data.
Definition Events.hpp:113
bool operator==(const AllocateDataEvent &) const =default
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
Definition Events.hpp:129
bool operator==(const BeginDeepCopyEvent &) const =default
Begin-fence event associated with Kokkos::Tools::Experimental::EventSet::begin_fence.
Definition Events.hpp:84
bool operator==(const BeginFenceEvent &) const =default
bool operator==(const BeginParallelForEvent &) const =default
Begin-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_red...
Definition Events.hpp:48
bool operator==(const BeginParallelReduceEvent &) const =default
Begin-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_scan.
Definition Events.hpp:66
bool operator==(const BeginParallelScanEvent &) const =default
Create-profile-section event associated with Kokkos::Tools::Experimental::EventSet::create_profile_se...
Definition Events.hpp:144
bool operator==(const CreateProfileSectionEvent &) const =default
Deallocate-data event associated with Kokkos::Tools::Experimental::EventSet::deallocate_data.
Definition Events.hpp:121
bool operator==(const DeallocateDataEvent &) const =default
Destroy-profile-section event associated with Kokkos::Tools::Experimental::EventSet::destroy_profile_...
Definition Events.hpp:169
bool operator==(const DestroyProfileSectionEvent &) const =default
End-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::end_deep_copy.
Definition Events.hpp:138
bool operator==(const EndDeepCopyEvent &) const =default
End-fence event associated with Kokkos::Tools::Experimental::EventSet::end_fence.
Definition Events.hpp:94
bool operator==(const EndFenceEvent &) const =default
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
Definition Events.hpp:40
bool operator==(const EndParallelForEvent &) const =default
End-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_reduce.
Definition Events.hpp:58
bool operator==(const EndParallelReduceEvent &) const =default
End-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_scan.
Definition Events.hpp:76
bool operator==(const EndParallelScanEvent &) const =default
Pop-region event associated with Kokkos::Tools::Experimental::EventSet::pop_region.
Definition Events.hpp:185
bool operator==(const PopRegionEvent &) const =default
Profile event associated with Kokkos::Tools::Experimental::EventSet::profile_event.
Definition Events.hpp:191
bool operator==(const ProfileEvent &) const =default
Push-region event associated with Kokkos::Tools::Experimental::EventSet::push_region.
Definition Events.hpp:177
bool operator==(const PushRegionEvent &) const =default
Start-profile-section event associated with Kokkos::Tools::Experimental::EventSet::start_profile_sect...
Definition Events.hpp:153
bool operator==(const StartProfileSectionEvent &) const =default
Stop-profile-section event associated with Kokkos::Tools::Experimental::EventSet::stop_profile_sectio...
Definition Events.hpp:161
bool operator==(const StopProfileSectionEvent &) const =default