kokkos-utils 0.0.7
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 <cstring>
5#include <iomanip>
6#include <memory>
7
8#include "Kokkos_Macros.hpp"
9#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
10import kokkos.core;
11#else
12#include "Kokkos_Core.hpp"
13#endif
14#include "Kokkos_TypeInfo.hpp"
15
17
19{
20
23 using event_id_t = uint64_t;
24
25 static constexpr event_id_t invalid_event_id = Kokkos::Experimental::finite_max_v<event_id_t>;
26};
27
29bool operator==(const Kokkos::Tools::SpaceHandle& fst, const Kokkos::Tools::SpaceHandle& snd) {
30 return strcmp(fst.name, snd.name) == 0;
31};
32
52
60
70
78
88
96
99{
100 std::string name {};
101 uint32_t dev_id = 0;
103
104 bool operator==(const BeginSingleEvent&) const = default;
105};
106
114
117{
118 std::string name {};
119 uint32_t dev_id = 0;
121
122 bool operator==(const BeginFenceEvent&) const = default;
123};
124
132
135{
136 Kokkos::Tools::SpaceHandle kpsh {};
137 std::string name {};
138 const void* ptr = nullptr;
139 uint64_t size = 0;
140
141 bool operator==(const AllocDescriptor&) const = default;
142};
143
146{
148
149 bool operator==(const AllocateDataEvent&) const = default;
150};
151
154{
156
157 bool operator==(const DeallocateDataEvent&) const = default;
158};
159
162{
165
166 bool operator==(const BeginDeepCopyEvent&) const = default;
167};
168
171{
172 bool operator==(const EndDeepCopyEvent&) const = default;
173};
174
177{
178 std::string name {};
179 uint32_t section_id = 0;
180
181 bool operator==(const CreateProfileSectionEvent&) const = default;
182};
183
186{
187 uint32_t section_id = 0;
188
189 bool operator==(const StartProfileSectionEvent&) const = default;
190};
191
194{
195 uint32_t section_id = 0;
196
197 bool operator==(const StopProfileSectionEvent&) const = default;
198};
199
202{
203 uint32_t section_id = 0;
204
205 bool operator==(const DestroyProfileSectionEvent&) const = default;
206};
207
210{
211 std::string name {};
212
213 bool operator==(const PushRegionEvent&) const = default;
214};
215
218{
219 bool operator==(const PopRegionEvent&) const = default;
220};
221
224{
225 std::string name {};
226
227 bool operator==(const ProfileEvent&) const = default;
228};
229
230
232using EventTypeList = Kokkos::Impl::type_list<
244>;
245
249template <typename T>
250concept Event = std::default_initializable<T>
251 && std::copyable<T>
252 && std::movable<T>
253 && std::equality_comparable<T>;
254
256template <typename EventType>
257concept BeginEvent =
259 std::constructible_from<EventType, const char*, uint32_t, EventTraits::event_id_t> &&
260 requires (EventType event) {
261 { event.name } -> std::same_as<std::string&>;
262 { event.dev_id } -> std::same_as<uint32_t&>;
263 { event.event_id } -> std::same_as<EventTraits::event_id_t&>;
264 };
265
267template <typename EventType>
268concept EndEvent =
270 std::constructible_from<EventType, EventTraits::event_id_t> &&
271 requires (EventType event) {
272 { event.event_id } -> std::same_as<EventTraits::event_id_t&>;
273 };
274
276template <typename EventType>
277concept DataEvent =
279 std::constructible_from<EventType, AllocDescriptor> &&
280 requires (EventType event) {
281 { event.alloc } -> std::same_as<AllocDescriptor&>;
282 };
283
285template <typename EventType>
288 std::constructible_from<EventType, uint32_t> &&
289 requires (EventType event) {
290 { event.section_id } -> std::same_as<uint32_t&>;
291 };
292
294template <typename EventType>
295concept NamedEvent =
297 requires (EventType event) {
298 { event.name } -> std::same_as<std::string&>;
299 };
300
302template <typename EventType>
303concept IndexedEvent = Event<EventType> && requires (EventType event) {
304 { event.event_id } -> std::same_as<EventTraits::event_id_t&>;
305};
306
308template <typename EventType>
309concept EnqueuedEvent = Event<EventType> && requires (EventType event) {
310 { event.dev_id } -> std::same_as<uint32_t&>;
311};
312
314template <typename T, typename... EventTypes>
315concept EventOneOf = impl::type_list_contains_v<T, EventTypes...>;
317
320template <Event EventType>
322
323#define PAIRED_EVENT_TYPE(__begin_eventtype__, __end_eventtype__) \
324 template <> \
325 struct PairedEventType<__begin_eventtype__> { using type = __end_eventtype__; };
326
337
338template <Event EventType>
339using paired_event_t = typename PairedEventType<EventType>::type;
341
344
349template <typename T>
350constexpr auto get_name() {
351 return Kokkos::Impl::TypeInfo<T>::name().substr(26);
352}
353
354template <BeginEvent EventType>
355std::ostream& operator<<(std::ostream &out, const EventType& event) {
356 return out << get_name<EventType>() << ": "
357 << "{name = " << std::quoted(event.name) << ", dev_id = " << event.dev_id << ", event_id = " << event.event_id << "}";
358}
359
360template <EndEvent EventType>
361std::ostream& operator<<(std::ostream &out, const EventType& event) {
362 return out << get_name<EventType>() << ": "
363 << "{event_id = " << event.event_id << "}";
364}
365
366template <DataEvent EventType>
367std::ostream& operator<<(std::ostream &out, const EventType& event) {
368 const auto& alloc = event.alloc;
369 return out << get_name<EventType>() << ": "
370 << "{name = " << std::quoted(alloc.name) << ", space = " << std::quoted(alloc.kpsh.name) << ", ptr = " << alloc.ptr << ", size = " << alloc.size << "}";
371}
372
373inline std::ostream& operator<<(std::ostream &out, const BeginDeepCopyEvent& event) {
374 const auto& dst = event.dst;
375 const auto& src = event.src;
376 return out << get_name<BeginDeepCopyEvent>() << ": "
377 << "{src = " << std::quoted(src.name) << " (" << src.kpsh.name << ", " << src.ptr << ") -> "
378 << "dst = " << std::quoted(dst.name) << " (" << dst.kpsh.name << ", " << dst.ptr << ") of size " << src.size << "}";
379}
380
381inline std::ostream& operator<<(std::ostream &out, const EndDeepCopyEvent& /* event */) {
382 return out << get_name<EndDeepCopyEvent>() << ": "
383 << "{}";
384}
385
386inline std::ostream& operator<<(std::ostream &out, const CreateProfileSectionEvent& event) {
387 return out << get_name<CreateProfileSectionEvent>() << ": "
388 << "{name = " << std::quoted(event.name) << ", section_id = " << event.section_id << "}";
389}
390
391template <ProfileSectionManipulationEvent EventType>
392std::ostream& operator<<(std::ostream &out, const EventType& event) {
393 return out << get_name<EventType>() << ": "
394 << "{section_id = " << event.section_id << "}";
395}
396
397inline std::ostream& operator<<(std::ostream &out, const PushRegionEvent& event) {
398 return out << get_name<PushRegionEvent>() << ": "
399 << "{name = " << std::quoted(event.name) << "}";
400}
401
402inline std::ostream& operator<<(std::ostream &out, const PopRegionEvent& /* event */) {
403 return out << get_name<PopRegionEvent>() << ": "
404 << "{}";
405}
406
407inline std::ostream& operator<<(std::ostream &out, const ProfileEvent& event) {
408 return out << get_name<ProfileEvent>() << ": "
409 << "{name = " << std::quoted(event.name) << "}";
410}
411
412inline std::ostream& operator<<(std::ostream& out, const AllocDescriptor& descr) {
413 return out << get_name<AllocDescriptor>() << ": "
414 << "{name = " << std::quoted(descr.name) << " (" << descr.kpsh.name << ", " << descr.ptr << ") of size " << descr.size << '}';
415}
416
417
421template <Event EventType>
422auto get_callback_from_eventset(const Kokkos::Tools::Experimental::EventSet& event_set);
423
425#define GET_CALLBACK_FROM_EVENTSET(__eventtype__, __callback__) \
426 template <> \
427 inline auto get_callback_from_eventset<__eventtype__>(const Kokkos::Tools::Experimental::EventSet& event_set) { return event_set.__callback__; }
428
450
452template <Event EventType>
454
456#define GET_CALLBACK_SETTER(__eventtype__, __callback_setter__) \
457 template <> \
458 inline auto get_callback_setter<__eventtype__>() { return &Kokkos::Tools::Experimental::__callback_setter__; }
459
460GET_CALLBACK_SETTER(BeginParallelForEvent, set_begin_parallel_for_callback)
461GET_CALLBACK_SETTER(EndParallelForEvent, set_end_parallel_for_callback)
462GET_CALLBACK_SETTER(BeginParallelReduceEvent, set_begin_parallel_reduce_callback)
463GET_CALLBACK_SETTER(EndParallelReduceEvent, set_end_parallel_reduce_callback)
464GET_CALLBACK_SETTER(BeginParallelScanEvent, set_begin_parallel_scan_callback)
465GET_CALLBACK_SETTER(EndParallelScanEvent, set_end_parallel_scan_callback)
466GET_CALLBACK_SETTER(BeginSingleEvent, set_begin_single_callback)
467GET_CALLBACK_SETTER(EndSingleEvent, set_end_single_callback)
468GET_CALLBACK_SETTER(BeginFenceEvent, set_begin_fence_callback)
469GET_CALLBACK_SETTER(EndFenceEvent, set_end_fence_callback)
470GET_CALLBACK_SETTER(AllocateDataEvent, set_allocate_data_callback)
471GET_CALLBACK_SETTER(DeallocateDataEvent, set_deallocate_data_callback)
472GET_CALLBACK_SETTER(BeginDeepCopyEvent, set_begin_deep_copy_callback)
473GET_CALLBACK_SETTER(EndDeepCopyEvent, set_end_deep_copy_callback)
474GET_CALLBACK_SETTER(CreateProfileSectionEvent, set_create_profile_section_callback)
475GET_CALLBACK_SETTER(StartProfileSectionEvent, set_start_profile_section_callback)
476GET_CALLBACK_SETTER(StopProfileSectionEvent, set_stop_profile_section_callback)
477GET_CALLBACK_SETTER(DestroyProfileSectionEvent, set_destroy_profile_section_callback)
478GET_CALLBACK_SETTER(PushRegionEvent, set_push_region_callback)
479GET_CALLBACK_SETTER(PopRegionEvent, set_pop_region_callback)
480GET_CALLBACK_SETTER(ProfileEvent, set_profile_event_callback)
482
483} // namespace Kokkos::utils::callbacks
484
485#endif // KOKKOS_UTILS_CALLBACKS_EVENTS_HPP
#define PAIRED_EVENT_TYPE(__begin_eventtype__, __end_eventtype__)
Definition Events.hpp:323
#define GET_CALLBACK_SETTER(__eventtype__, __callback_setter__)
Helper macro related to the implementation of Kokkos::utils::callbacks::get_callback_setter.
Definition Events.hpp:456
#define GET_CALLBACK_FROM_EVENTSET(__eventtype__, __callback__)
Helper macro related to the implementation of Kokkos::utils::callbacks::get_callback_from_eventset.
Definition Events.hpp:425
Concept to constrain any begin event type.
Definition Events.hpp:257
Concept to constrain any data event type.
Definition Events.hpp:277
Concept to constrain any end event type.
Definition Events.hpp:268
Concept to constrain any event type that has a member variable dev_id.
Definition Events.hpp:309
Concept to constrain any event type that is one of the given event types.
Definition Events.hpp:315
Concept to constrain any event type that has a member variable event_id.
Definition Events.hpp:303
Concept to constrain any event type that has a name field.
Definition Events.hpp:295
Concept to constrain any profile section manipulation event type.
Definition Events.hpp:286
std::ostream & operator<<(std::ostream &out, const EventType &event)
Definition Events.hpp:355
bool operator==(const Kokkos::Tools::SpaceHandle &fst, const Kokkos::Tools::SpaceHandle &snd)
Equality comparison for Kokkos::Tools::SpaceHandle.
Definition Events.hpp:29
constexpr auto get_name()
Helper function to remove the Kokkos::utils::callbacks:: prefix.
Definition Events.hpp:350
typename PairedEventType< EventType >::type paired_event_t
Definition Events.hpp:339
Kokkos::Impl::type_list< BeginParallelForEvent, EndParallelForEvent, BeginParallelReduceEvent, EndParallelReduceEvent, BeginParallelScanEvent, EndParallelScanEvent, BeginSingleEvent, EndSingleEvent, BeginFenceEvent, EndFenceEvent, AllocateDataEvent, DeallocateDataEvent, BeginDeepCopyEvent, EndDeepCopyEvent, CreateProfileSectionEvent, DestroyProfileSectionEvent, StartProfileSectionEvent, StopProfileSectionEvent, PushRegionEvent, PopRegionEvent, ProfileEvent > EventTypeList
Type list holding all event types.
Definition Events.hpp:232
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:135
Kokkos::Tools::SpaceHandle kpsh
Definition Events.hpp:136
bool operator==(const AllocDescriptor &) const =default
Allocate-data event associated with Kokkos::Tools::Experimental::EventSet::allocate_data.
Definition Events.hpp:146
bool operator==(const AllocateDataEvent &) const =default
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
Definition Events.hpp:162
bool operator==(const BeginDeepCopyEvent &) const =default
Begin-fence event associated with Kokkos::Tools::Experimental::EventSet::begin_fence.
Definition Events.hpp:117
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:63
bool operator==(const BeginParallelReduceEvent &) const =default
Begin-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_scan.
Definition Events.hpp:81
bool operator==(const BeginParallelScanEvent &) const =default
Begin-single event associated with Kokkos::Tools::Experimental::EventSet::begin_single.
Definition Events.hpp:99
bool operator==(const BeginSingleEvent &) const =default
Create-profile-section event associated with Kokkos::Tools::Experimental::EventSet::create_profile_se...
Definition Events.hpp:177
bool operator==(const CreateProfileSectionEvent &) const =default
Deallocate-data event associated with Kokkos::Tools::Experimental::EventSet::deallocate_data.
Definition Events.hpp:154
bool operator==(const DeallocateDataEvent &) const =default
Destroy-profile-section event associated with Kokkos::Tools::Experimental::EventSet::destroy_profile_...
Definition Events.hpp:202
bool operator==(const DestroyProfileSectionEvent &) const =default
End-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::end_deep_copy.
Definition Events.hpp:171
bool operator==(const EndDeepCopyEvent &) const =default
End-fence event associated with Kokkos::Tools::Experimental::EventSet::end_fence.
Definition Events.hpp:127
EventTraits::event_id_t event_id
Definition Events.hpp:128
bool operator==(const EndFenceEvent &) const =default
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
Definition Events.hpp:55
bool operator==(const EndParallelForEvent &) const =default
End-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_reduce.
Definition Events.hpp:73
bool operator==(const EndParallelReduceEvent &) const =default
End-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_scan.
Definition Events.hpp:91
bool operator==(const EndParallelScanEvent &) const =default
End-single event associated with Kokkos::Tools::Experimental::EventSet::end_single.
Definition Events.hpp:109
bool operator==(const EndSingleEvent &) const =default
EventTraits::event_id_t event_id
Definition Events.hpp:110
static constexpr event_id_t invalid_event_id
Definition Events.hpp:25
Pop-region event associated with Kokkos::Tools::Experimental::EventSet::pop_region.
Definition Events.hpp:218
bool operator==(const PopRegionEvent &) const =default
Profile event associated with Kokkos::Tools::Experimental::EventSet::profile_event.
Definition Events.hpp:224
bool operator==(const ProfileEvent &) const =default
Push-region event associated with Kokkos::Tools::Experimental::EventSet::push_region.
Definition Events.hpp:210
bool operator==(const PushRegionEvent &) const =default
Start-profile-section event associated with Kokkos::Tools::Experimental::EventSet::start_profile_sect...
Definition Events.hpp:186
bool operator==(const StartProfileSectionEvent &) const =default
Stop-profile-section event associated with Kokkos::Tools::Experimental::EventSet::stop_profile_sectio...
Definition Events.hpp:194
bool operator==(const StopProfileSectionEvent &) const =default