1#ifndef KOKKOS_UTILS_CALLBACKS_EVENTS_HPP
2#define KOKKOS_UTILS_CALLBACKS_EVENTS_HPP
8#include "Kokkos_Macros.hpp"
9#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
12#include "Kokkos_Core.hpp"
14#include "Kokkos_TypeInfo.hpp"
29bool operator==(
const Kokkos::Tools::SpaceHandle& fst,
const Kokkos::Tools::SpaceHandle& snd) {
30 return strcmp(fst.name, snd.name) == 0;
136 Kokkos::Tools::SpaceHandle
kpsh {};
138 const void*
ptr =
nullptr;
250concept Event = std::default_initializable<T>
253 && std::equality_comparable<T>;
256template <
typename EventType>
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&>;
267template <
typename EventType>
270 std::constructible_from<EventType, EventTraits::event_id_t> &&
271 requires (EventType event) {
272 {
event.event_id } -> std::same_as<EventTraits::event_id_t&>;
276template <
typename EventType>
279 std::constructible_from<EventType, AllocDescriptor> &&
280 requires (EventType event) {
281 {
event.alloc } -> std::same_as<AllocDescriptor&>;
285template <
typename EventType>
288 std::constructible_from<EventType, uint32_t> &&
289 requires (EventType event) {
290 {
event.section_id } -> std::same_as<uint32_t&>;
294template <
typename EventType>
297 requires (EventType event) {
298 {
event.name } -> std::same_as<std::string&>;
302template <
typename EventType>
304 {
event.event_id } -> std::same_as<EventTraits::event_id_t&>;
308template <
typename EventType>
310 {
event.dev_id } -> std::same_as<uint32_t&>;
314template <
typename T,
typename... EventTypes>
320template <Event EventType>
323#define PAIRED_EVENT_TYPE(__begin_eventtype__, __end_eventtype__) \
325 struct PairedEventType<__begin_eventtype__> { using type = __end_eventtype__; };
338template <
Event EventType>
351 return Kokkos::Impl::TypeInfo<T>::name().substr(26);
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 <<
"}";
360template <EndEvent EventType>
361std::ostream&
operator<<(std::ostream &out,
const EventType& event) {
362 return out << get_name<EventType>() <<
": "
363 <<
"{event_id = " <<
event.event_id <<
"}";
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 <<
"}";
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 <<
"}";
382 return out << get_name<EndDeepCopyEvent>() <<
": "
387 return out << get_name<CreateProfileSectionEvent>() <<
": "
388 <<
"{name = " << std::quoted(event.
name) <<
", section_id = " <<
event.section_id <<
"}";
391template <ProfileSectionManipulationEvent EventType>
392std::ostream&
operator<<(std::ostream &out,
const EventType& event) {
393 return out << get_name<EventType>() <<
": "
394 <<
"{section_id = " <<
event.section_id <<
"}";
398 return out << get_name<PushRegionEvent>() <<
": "
399 <<
"{name = " << std::quoted(event.
name) <<
"}";
403 return out << get_name<PopRegionEvent>() <<
": "
408 return out << get_name<ProfileEvent>() <<
": "
409 <<
"{name = " << std::quoted(event.
name) <<
"}";
413 return out << get_name<AllocDescriptor>() <<
": "
414 <<
"{name = " << std::quoted(descr.
name) <<
" (" << descr.
kpsh.name <<
", " << descr.
ptr <<
") of size " << descr.
size <<
'}';
421template <Event EventType>
425#define GET_CALLBACK_FROM_EVENTSET(__eventtype__, __callback__) \
427 inline auto get_callback_from_eventset<__eventtype__>(const Kokkos::Tools::Experimental::EventSet& event_set) { return event_set.__callback__; }
452template <
Event EventType>
456#define GET_CALLBACK_SETTER(__eventtype__, __callback_setter__) \
458 inline auto get_callback_setter<__eventtype__>() { return &Kokkos::Tools::Experimental::__callback_setter__; }
#define PAIRED_EVENT_TYPE(__begin_eventtype__, __end_eventtype__)
#define GET_CALLBACK_SETTER(__eventtype__, __callback_setter__)
Helper macro related to the implementation of Kokkos::utils::callbacks::get_callback_setter.
#define GET_CALLBACK_FROM_EVENTSET(__eventtype__, __callback__)
Helper macro related to the implementation of Kokkos::utils::callbacks::get_callback_from_eventset.
Concept to constrain any begin event type.
Concept to constrain any data event type.
Concept to constrain any end event type.
Concept to constrain any event type that has a member variable dev_id.
Concept to constrain any event type that is one of the given event types.
Concept to constrain any event type that has a member variable event_id.
Concept to constrain any event type that has a name field.
Concept to constrain any profile section manipulation event type.
std::ostream & operator<<(std::ostream &out, const EventType &event)
bool operator==(const Kokkos::Tools::SpaceHandle &fst, const Kokkos::Tools::SpaceHandle &snd)
Equality comparison for Kokkos::Tools::SpaceHandle.
constexpr auto get_name()
Helper function to remove the Kokkos::utils::callbacks:: prefix.
typename PairedEventType< EventType >::type paired_event_t
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.
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
Helper struct to hold descriptors of a data allocation.
Kokkos::Tools::SpaceHandle kpsh
bool operator==(const AllocDescriptor &) const =default
Allocate-data event associated with Kokkos::Tools::Experimental::EventSet::allocate_data.
bool operator==(const AllocateDataEvent &) const =default
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
bool operator==(const BeginDeepCopyEvent &) const =default
Begin-fence event associated with Kokkos::Tools::Experimental::EventSet::begin_fence.
EventTraits::event_id_t event_id
bool operator==(const BeginFenceEvent &) const =default
bool operator==(const BeginParallelForEvent &) const =default
EventTraits::event_id_t event_id
Begin-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_red...
EventTraits::event_id_t event_id
bool operator==(const BeginParallelReduceEvent &) const =default
Begin-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_scan.
bool operator==(const BeginParallelScanEvent &) const =default
EventTraits::event_id_t event_id
Begin-single event associated with Kokkos::Tools::Experimental::EventSet::begin_single.
bool operator==(const BeginSingleEvent &) const =default
EventTraits::event_id_t event_id
Create-profile-section event associated with Kokkos::Tools::Experimental::EventSet::create_profile_se...
bool operator==(const CreateProfileSectionEvent &) const =default
Deallocate-data event associated with Kokkos::Tools::Experimental::EventSet::deallocate_data.
bool operator==(const DeallocateDataEvent &) const =default
Destroy-profile-section event associated with Kokkos::Tools::Experimental::EventSet::destroy_profile_...
bool operator==(const DestroyProfileSectionEvent &) const =default
End-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::end_deep_copy.
bool operator==(const EndDeepCopyEvent &) const =default
End-fence event associated with Kokkos::Tools::Experimental::EventSet::end_fence.
EventTraits::event_id_t event_id
bool operator==(const EndFenceEvent &) const =default
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
EventTraits::event_id_t event_id
bool operator==(const EndParallelForEvent &) const =default
End-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_reduce.
bool operator==(const EndParallelReduceEvent &) const =default
EventTraits::event_id_t event_id
End-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_scan.
EventTraits::event_id_t event_id
bool operator==(const EndParallelScanEvent &) const =default
End-single event associated with Kokkos::Tools::Experimental::EventSet::end_single.
bool operator==(const EndSingleEvent &) const =default
EventTraits::event_id_t event_id
static constexpr event_id_t invalid_event_id
Pop-region event associated with Kokkos::Tools::Experimental::EventSet::pop_region.
bool operator==(const PopRegionEvent &) const =default
Profile event associated with Kokkos::Tools::Experimental::EventSet::profile_event.
bool operator==(const ProfileEvent &) const =default
Push-region event associated with Kokkos::Tools::Experimental::EventSet::push_region.
bool operator==(const PushRegionEvent &) const =default
Start-profile-section event associated with Kokkos::Tools::Experimental::EventSet::start_profile_sect...
bool operator==(const StartProfileSectionEvent &) const =default
Stop-profile-section event associated with Kokkos::Tools::Experimental::EventSet::stop_profile_sectio...
bool operator==(const StopProfileSectionEvent &) const =default