kokkos-utils 0.0.4
 
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
15 using event_id_t = uint64_t;
16
17 static constexpr event_id_t invalid_event_id = Kokkos::Experimental::finite_max_v<event_id_t>;
18};
19
21bool operator==(const Kokkos_Profiling_SpaceHandle& fst, const Kokkos_Profiling_SpaceHandle& snd) {
22 return strcmp(fst.name, snd.name) == 0;
23};
24
44
52
62
70
80
88
91{
92 std::string name {};
93 uint32_t dev_id = 0;
95
96 bool operator==(const BeginFenceEvent&) const = default;
97};
98
106
109{
110 Kokkos_Profiling_SpaceHandle kpsh {};
111 std::string name {};
112 const void* ptr = nullptr;
113 uint64_t size = 0;
114
115 bool operator==(const AllocDescriptor&) const = default;
116};
117
120{
122
123 bool operator==(const AllocateDataEvent&) const = default;
124};
125
128{
130
131 bool operator==(const DeallocateDataEvent&) const = default;
132};
133
136{
139
140 bool operator==(const BeginDeepCopyEvent&) const = default;
141};
142
145{
146 bool operator==(const EndDeepCopyEvent&) const = default;
147};
148
151{
152 std::string name {};
153 uint32_t section_id = 0;
154
155 bool operator==(const CreateProfileSectionEvent&) const = default;
156};
157
160{
161 uint32_t section_id = 0;
162
163 bool operator==(const StartProfileSectionEvent&) const = default;
164};
165
168{
169 uint32_t section_id = 0;
170
171 bool operator==(const StopProfileSectionEvent&) const = default;
172};
173
176{
177 uint32_t section_id = 0;
178
179 bool operator==(const DestroyProfileSectionEvent&) const = default;
180};
181
184{
185 std::string name {};
186
187 bool operator==(const PushRegionEvent&) const = default;
188};
189
192{
193 bool operator==(const PopRegionEvent&) const = default;
194};
195
198{
199 std::string name {};
200
201 bool operator==(const ProfileEvent&) const = default;
202};
203
204
206using EventTypeList = Kokkos::Impl::type_list<
217>;
218
222template <typename T>
223concept Event = std::default_initializable<T>
224 && std::copyable<T>
225 && std::movable<T>
226 && std::equality_comparable<T>;
227
229template <typename EventType>
230concept BeginEvent =
232 std::constructible_from<EventType, const char*, uint32_t, EventTraits::event_id_t> &&
233 requires (EventType event) {
234 { event.name } -> std::same_as<std::string&>;
235 { event.dev_id } -> std::same_as<uint32_t&>;
236 { event.event_id } -> std::same_as<EventTraits::event_id_t&>;
237 };
238
240template <typename EventType>
241concept EndEvent =
243 std::constructible_from<EventType, EventTraits::event_id_t> &&
244 requires (EventType event) {
245 { event.event_id } -> std::same_as<EventTraits::event_id_t&>;
246 };
247
249template <typename EventType>
250concept DataEvent =
252 std::constructible_from<EventType, AllocDescriptor> &&
253 requires (EventType event) {
254 { event.alloc } -> std::same_as<AllocDescriptor&>;
255 };
256
258template <typename EventType>
261 std::constructible_from<EventType, uint32_t> &&
262 requires (EventType event) {
263 { event.section_id } -> std::same_as<uint32_t&>;
264 };
265
267template <typename EventType>
268concept NamedEvent =
270 requires (EventType event) {
271 { event.name } -> std::same_as<std::string&>;
272 };
273
275template <typename EventType>
276concept IndexedEvent = Event<EventType> && requires (EventType event) {
277 { event.event_id } -> std::same_as<EventTraits::event_id_t&>;
278};
279
281template <typename EventType>
282concept EnqueuedEvent = Event<EventType> && requires (EventType event) {
283 { event.dev_id } -> std::same_as<uint32_t&>;
284};
285
287template <typename T, typename... EventTypes>
288concept EventOneOf = impl::type_list_contains_v<T, EventTypes...>;
290
293template <Event EventType>
295
296#define PAIRED_EVENT_TYPE(__begin_eventtype__, __end_eventtype__) \
297 template <> \
298 struct PairedEventType<__begin_eventtype__> { using type = __end_eventtype__; };
299
309
310template <Event EventType>
311using paired_event_t = typename PairedEventType<EventType>::type;
313
316
321template <typename T>
322constexpr auto get_name() {
323 return Kokkos::Impl::TypeInfo<T>::name().substr(26);
324}
325
326template <BeginEvent EventType>
327std::ostream& operator<<(std::ostream &out, const EventType& event) {
328 return out << get_name<EventType>() << ": "
329 << "{name = " << std::quoted(event.name) << ", dev_id = " << event.dev_id << ", event_id = " << event.event_id << "}";
330}
331
332template <EndEvent EventType>
333std::ostream& operator<<(std::ostream &out, const EventType& event) {
334 return out << get_name<EventType>() << ": "
335 << "{event_id = " << event.event_id << "}";
336}
337
338template <DataEvent EventType>
339std::ostream& operator<<(std::ostream &out, const EventType& event) {
340 const auto& alloc = event.alloc;
341 return out << get_name<EventType>() << ": "
342 << "{name = " << std::quoted(alloc.name) << ", space = " << std::quoted(alloc.kpsh.name) << ", ptr = " << alloc.ptr << ", size = " << alloc.size << "}";
343}
344
345inline std::ostream& operator<<(std::ostream &out, const BeginDeepCopyEvent& event) {
346 const auto& dst = event.dst;
347 const auto& src = event.src;
348 return out << get_name<BeginDeepCopyEvent>() << ": "
349 << "{src = " << std::quoted(src.name) << " (" << src.kpsh.name << ", " << src.ptr << ") -> "
350 << "dst = " << std::quoted(dst.name) << " (" << dst.kpsh.name << ", " << dst.ptr << ") of size " << src.size << "}";
351}
352
353inline std::ostream& operator<<(std::ostream &out, const EndDeepCopyEvent& /* event */) {
354 return out << get_name<EndDeepCopyEvent>() << ": "
355 << "{}";
356}
357
358inline std::ostream& operator<<(std::ostream &out, const CreateProfileSectionEvent& event) {
359 return out << get_name<CreateProfileSectionEvent>() << ": "
360 << "{name = " << std::quoted(event.name) << ", section_id = " << event.section_id << "}";
361}
362
363template <ProfileSectionManipulationEvent EventType>
364std::ostream& operator<<(std::ostream &out, const EventType& event) {
365 return out << get_name<EventType>() << ": "
366 << "{section_id = " << event.section_id << "}";
367}
368
369inline std::ostream& operator<<(std::ostream &out, const PushRegionEvent& event) {
370 return out << get_name<PushRegionEvent>() << ": "
371 << "{name = " << std::quoted(event.name) << "}";
372}
373
374inline std::ostream& operator<<(std::ostream &out, const PopRegionEvent& /* event */) {
375 return out << get_name<PopRegionEvent>() << ": "
376 << "{}";
377}
378
379inline std::ostream& operator<<(std::ostream &out, const ProfileEvent& event) {
380 return out << get_name<ProfileEvent>() << ": "
381 << "{name = " << std::quoted(event.name) << "}";
382}
383
384inline std::ostream& operator<<(std::ostream& out, const AllocDescriptor& descr) {
385 return out << get_name<AllocDescriptor>() << ": "
386 << "{name = " << std::quoted(descr.name) << " (" << descr.kpsh.name << ", " << descr.ptr << ") of size " << descr.size << '}';
387}
388
389
393template <Event EventType>
394auto get_callback_from_eventset(const Kokkos::Tools::Experimental::EventSet& event_set);
395
397#define GET_CALLBACK_FROM_EVENTSET(__eventtype__, __callback__) \
398 template <> \
399 inline auto get_callback_from_eventset<__eventtype__>(const Kokkos::Tools::Experimental::EventSet& event_set) { return event_set.__callback__; }
400
420
422template <Event EventType>
424
426#define GET_CALLBACK_SETTER(__eventtype__, __callback_setter__) \
427 template <> \
428 inline auto get_callback_setter<__eventtype__>() { return &Kokkos::Tools::Experimental::__callback_setter__; }
429
430GET_CALLBACK_SETTER(BeginParallelForEvent, set_begin_parallel_for_callback)
431GET_CALLBACK_SETTER(EndParallelForEvent, set_end_parallel_for_callback)
432GET_CALLBACK_SETTER(BeginParallelReduceEvent, set_begin_parallel_reduce_callback)
433GET_CALLBACK_SETTER(EndParallelReduceEvent, set_end_parallel_reduce_callback)
434GET_CALLBACK_SETTER(BeginParallelScanEvent, set_begin_parallel_scan_callback)
435GET_CALLBACK_SETTER(EndParallelScanEvent, set_end_parallel_scan_callback)
436GET_CALLBACK_SETTER(BeginFenceEvent, set_begin_fence_callback)
437GET_CALLBACK_SETTER(EndFenceEvent, set_end_fence_callback)
438GET_CALLBACK_SETTER(AllocateDataEvent, set_allocate_data_callback)
439GET_CALLBACK_SETTER(DeallocateDataEvent, set_deallocate_data_callback)
440GET_CALLBACK_SETTER(BeginDeepCopyEvent, set_begin_deep_copy_callback)
441GET_CALLBACK_SETTER(EndDeepCopyEvent, set_end_deep_copy_callback)
442GET_CALLBACK_SETTER(CreateProfileSectionEvent, set_create_profile_section_callback)
443GET_CALLBACK_SETTER(StartProfileSectionEvent, set_start_profile_section_callback)
444GET_CALLBACK_SETTER(StopProfileSectionEvent, set_stop_profile_section_callback)
445GET_CALLBACK_SETTER(DestroyProfileSectionEvent, set_destroy_profile_section_callback)
446GET_CALLBACK_SETTER(PushRegionEvent, set_push_region_callback)
447GET_CALLBACK_SETTER(PopRegionEvent, set_pop_region_callback)
448GET_CALLBACK_SETTER(ProfileEvent, set_profile_event_callback)
450
451} // namespace Kokkos::utils::callbacks
452
453#endif // KOKKOS_UTILS_CALLBACKS_EVENTS_HPP
#define PAIRED_EVENT_TYPE(__begin_eventtype__, __end_eventtype__)
Definition Events.hpp:296
#define GET_CALLBACK_SETTER(__eventtype__, __callback_setter__)
Helper macro related to the implementation of Kokkos::utils::callbacks::get_callback_setter.
Definition Events.hpp:426
#define GET_CALLBACK_FROM_EVENTSET(__eventtype__, __callback__)
Helper macro related to the implementation of Kokkos::utils::callbacks::get_callback_from_eventset.
Definition Events.hpp:397
Concept to constrain any begin event type.
Definition Events.hpp:230
Concept to constrain any data event type.
Definition Events.hpp:250
Concept to constrain any end event type.
Definition Events.hpp:241
Concept to constrain any event type that has a member variable dev_id.
Definition Events.hpp:282
Concept to constrain any event type that is one of the given event types.
Definition Events.hpp:288
Concept to constrain any event type that has a member variable event_id.
Definition Events.hpp:276
Concept to constrain any event type that has a name field.
Definition Events.hpp:268
Concept to constrain any profile section manipulation event type.
Definition Events.hpp:259
bool operator==(const Kokkos_Profiling_SpaceHandle &fst, const Kokkos_Profiling_SpaceHandle &snd)
Equality comparison for Kokkos_Profiling_SpaceHandle.
Definition Events.hpp:21
std::ostream & operator<<(std::ostream &out, const EventType &event)
Definition Events.hpp:327
constexpr auto get_name()
Helper function to remove the Kokkos::utils::callbacks:: prefix.
Definition Events.hpp:322
typename PairedEventType< EventType >::type paired_event_t
Definition Events.hpp:311
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:206
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:109
Kokkos_Profiling_SpaceHandle kpsh
Definition Events.hpp:110
bool operator==(const AllocDescriptor &) const =default
Allocate-data event associated with Kokkos::Tools::Experimental::EventSet::allocate_data.
Definition Events.hpp:120
bool operator==(const AllocateDataEvent &) const =default
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
Definition Events.hpp:136
bool operator==(const BeginDeepCopyEvent &) const =default
Begin-fence event associated with Kokkos::Tools::Experimental::EventSet::begin_fence.
Definition Events.hpp:91
EventTraits::event_id_t event_id
Definition Events.hpp:94
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:55
bool operator==(const BeginParallelReduceEvent &) const =default
Begin-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_scan.
Definition Events.hpp:73
bool operator==(const BeginParallelScanEvent &) const =default
Create-profile-section event associated with Kokkos::Tools::Experimental::EventSet::create_profile_se...
Definition Events.hpp:151
bool operator==(const CreateProfileSectionEvent &) const =default
Deallocate-data event associated with Kokkos::Tools::Experimental::EventSet::deallocate_data.
Definition Events.hpp:128
bool operator==(const DeallocateDataEvent &) const =default
Destroy-profile-section event associated with Kokkos::Tools::Experimental::EventSet::destroy_profile_...
Definition Events.hpp:176
bool operator==(const DestroyProfileSectionEvent &) const =default
End-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::end_deep_copy.
Definition Events.hpp:145
bool operator==(const EndDeepCopyEvent &) const =default
End-fence event associated with Kokkos::Tools::Experimental::EventSet::end_fence.
Definition Events.hpp:101
EventTraits::event_id_t event_id
Definition Events.hpp:102
bool operator==(const EndFenceEvent &) const =default
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
Definition Events.hpp:47
bool operator==(const EndParallelForEvent &) const =default
End-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_reduce.
Definition Events.hpp:65
bool operator==(const EndParallelReduceEvent &) const =default
End-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_scan.
Definition Events.hpp:83
bool operator==(const EndParallelScanEvent &) const =default
static constexpr event_id_t invalid_event_id
Definition Events.hpp:17
Pop-region event associated with Kokkos::Tools::Experimental::EventSet::pop_region.
Definition Events.hpp:192
bool operator==(const PopRegionEvent &) const =default
Profile event associated with Kokkos::Tools::Experimental::EventSet::profile_event.
Definition Events.hpp:198
bool operator==(const ProfileEvent &) const =default
Push-region event associated with Kokkos::Tools::Experimental::EventSet::push_region.
Definition Events.hpp:184
bool operator==(const PushRegionEvent &) const =default
Start-profile-section event associated with Kokkos::Tools::Experimental::EventSet::start_profile_sect...
Definition Events.hpp:160
bool operator==(const StartProfileSectionEvent &) const =default
Stop-profile-section event associated with Kokkos::Tools::Experimental::EventSet::stop_profile_sectio...
Definition Events.hpp:168
bool operator==(const StopProfileSectionEvent &) const =default