kokkos-utils 0.0.4
 
Loading...
Searching...
No Matches
Kokkos::utils::callbacks::Manager Class Reference

Class to manage Kokkos profiling callback calls. More...

#include <Manager.hpp>

Public Types

using listener_list_t = std::list<std::unique_ptr<impl::ListenerConceptBase>>
 
using listener_list_const_iter_t = typename listener_list_t::const_iterator
 
using listener_call_opr_list_tuple_t = impl::listener_call_opr_list_tuple_t
 

Public Member Functions

 Manager (const Manager &)=delete
 
Manageroperator= (const Manager &)=delete
 
 ~Manager ()
 
template<Event EventType>
void dispatch (const EventType &event) const
 Dispatch the event to all registered listeners that can handle it.
 
auto get_next_event_id () noexcept
 Get the next available event ID.
 
auto get_next_section_id () noexcept
 Get the next available section ID.
 

Static Public Member Functions

static void initialize ()
 
static void finalize ()
 
static bool is_initialized ()
 
static Managerget_instance ()
 
template<Listener Callable>
static listener_list_const_iter_t register_listener (std::shared_ptr< Callable > callable)
 Register a callable object, passed as a shared pointer, as a listener.
 
template<typename T>
requires Listener<std::remove_cvref_t<T>>
static listener_list_const_iter_t register_listener (T &&callable)
 
template<Listener Callable>
static void unregister_listener (const Callable *const callable)
 Unregister a callable object as a listener.
 
static void unregister_listener (const listener_list_const_iter_t &iter)
 

Protected Member Functions

 Manager ()
 Constructor. Retrieves and stores the Kokkos::Tools::Experimental::EventSet containing the Kokkos callback function pointers.
 

Private Member Functions

void reset_context_callbacks () const
 Uses Kokkos::Tools::Experimental::set_callbacks to restore the Kokkos callback function pointers to those retrieved on this class's initialization.
 
void set_dispatching_callbacks () const
 Uses the setters Kokkos::Tools::Experimental::set_<event_type_name>_callback to set the Kokkos callback function pointers to this class's dispatching functions for the event types for which there are registered callbacks.
 
template<Event EventType>
void set_dispatching_callback_impl () const
 
template<Event EventType>
void dispatch (EventType &event)
 Dispatch first the context callback, if any is set in Kokkos, and then sequentially the registered callbacks for the event type.
 
template<Event EventType>
void dispatch_context_callback (EventType &event)
 Dispatch the event to the context callback, if any is set in Kokkos.
 
template<Event EventType>
void increment_id_if_needed_for_event_type_impl (EventType &)
 
template<BeginEvent EventType>
void increment_id_if_needed_for_event_type_impl (EventType &event)
 
void increment_id_if_needed_for_event_type_impl (CreateProfileSectionEvent &event)
 
template<Event EventType>
void dispatch_registered_callbacks (const EventType &event) const
 

Static Private Member Functions

template<typename ListenerModelType, typename CallableType>
static listener_list_const_iter_t register_listener_impl (CallableType &&callable)
 
template<Event EventType>
static auto create_dispatching_callback_for_event_type_impl ()
 
template<BeginEvent EventType>
static auto create_dispatching_callback_for_event_type_impl ()
 
template<DataEvent EventType>
static auto create_dispatching_callback_for_event_type_impl ()
 
template<Event EventType>
requires std::same_as<EventType, BeginDeepCopyEvent>
static auto create_dispatching_callback_for_event_type_impl ()
 
template<Event EventType>
requires std::same_as<EventType, CreateProfileSectionEvent>
static auto create_dispatching_callback_for_event_type_impl ()
 
template<typename ContextCallbackType, BeginEvent EventType>
static void dispatch_context_callback_for_event_type_impl (ContextCallbackType *context_callback, EventType &event)
 
template<typename ContextCallbackType, EndEvent EventType>
static void dispatch_context_callback_for_event_type_impl (ContextCallbackType *context_callback, const EventType &event)
 
template<typename ContextCallbackType, DataEvent EventType>
static void dispatch_context_callback_for_event_type_impl (ContextCallbackType *context_callback, const EventType &event)
 
template<typename ContextCallbackType>
static void dispatch_context_callback_for_event_type_impl (ContextCallbackType *context_callback, const BeginDeepCopyEvent &event)
 
template<typename ContextCallbackType>
static void dispatch_context_callback_for_event_type_impl (ContextCallbackType *context_callback, const EndDeepCopyEvent &)
 
template<typename ContextCallbackType>
static void dispatch_context_callback_for_event_type_impl (ContextCallbackType *context_callback, CreateProfileSectionEvent &event)
 
template<typename ContextCallbackType, ProfileSectionManipulationEvent EventType>
static void dispatch_context_callback_for_event_type_impl (ContextCallbackType *context_callback, const EventType &event)
 
template<typename ContextCallbackType>
static void dispatch_context_callback_for_event_type_impl (ContextCallbackType *context_callback, const PushRegionEvent &event)
 
template<typename ContextCallbackType>
static void dispatch_context_callback_for_event_type_impl (ContextCallbackType *context_callback, const PopRegionEvent &)
 
template<typename ContextCallbackType>
static void dispatch_context_callback_for_event_type_impl (ContextCallbackType *context_callback, const ProfileEvent &event)
 

Private Attributes

listener_call_opr_list_tuple_t registered_callbacks {}
 
listener_list_t listeners {}
 
Kokkos::Tools::Experimental::EventSet context_callbacks {}
 
std::atomic< EventTraits::event_id_tnext_event_id {0}
 
std::atomic< uint32_t > next_section_id {0}
 

Static Private Attributes

static Managersingleton = nullptr
 

Detailed Description

Class to manage Kokkos profiling callback calls.

This class allows the registration of callable objects as listeners for events representing Kokkos profiling callback calls.

On initialization, this class uses Kokkos::Tools::Experimental::get_callbacks to retrieve the callback function pointers already set within Kokkos. Note that this class refers to these callback functions as the "context callbacks".

On registering one or more callable objects as listeners for events, this class stores these callable objects by using a type-erasure pattern. Thus, on registering a callable object, this callable object is wrapped into a impl::ListenerModel that implements the abstract interface composed of impl::ListenerConceptBase and one or more impl::ListenerConceptCallOperator instances. The wrapped callable object is then stored in a list of unique pointers to the abstract base class.

In order to efficiently dispatch events to the corresponding call operators of the callable objects, this class stores for each event type a list of pointers to the listener models wrapping the callable objects that are registered as listeners for this event type. Note that this class refers to the call operators of these registered callable objects as the "registered callbacks".

This class uses the setters Kokkos::Tools::Experimental::set_<event_type_name>_callback to set the Kokkos callback function pointers to this class's dispatching functions for the event types for which there are registered callbacks. When a Kokkos callback call is made, these dispatching functions call the context callback first and then sequentially the registered callbacks for the event type.

On finalization, this class clears the list of registered callable objects and restores the Kokkos callback function pointers to the values they had prior to initializing this class.

Note
The profiling callback calls are implemented in Kokkos in terms of C function pointers. Class member functions cannot be converted to such C function pointers, unless they are static. This class is thus implemented as a singleton, and the dispatching functions are static member functions.

Definition at line 140 of file Manager.hpp.

Member Typedef Documentation

◆ listener_call_opr_list_tuple_t

◆ listener_list_const_iter_t

using Kokkos::utils::callbacks::Manager::listener_list_const_iter_t = typename listener_list_t::const_iterator

Definition at line 144 of file Manager.hpp.

◆ listener_list_t

Definition at line 143 of file Manager.hpp.

Constructor & Destructor Documentation

◆ Manager() [1/2]

Kokkos::utils::callbacks::Manager::Manager ( const Manager & )
delete

◆ ~Manager()

Kokkos::utils::callbacks::Manager::~Manager ( )
inline

Definition at line 151 of file Manager.hpp.

◆ Manager() [2/2]

Kokkos::utils::callbacks::Manager::Manager ( )
inlineprotected

Constructor. Retrieves and stores the Kokkos::Tools::Experimental::EventSet containing the Kokkos callback function pointers.

Definition at line 158 of file Manager.hpp.

Member Function Documentation

◆ create_dispatching_callback_for_event_type_impl() [1/5]

template<Event EventType>
static auto Kokkos::utils::callbacks::Manager::create_dispatching_callback_for_event_type_impl ( )
inlinestaticprivate
Note
We don't forward in the templated lambda because the signature must be the one of the Kokkos callback function pointers which pass by value.

Definition at line 321 of file Manager.hpp.

◆ create_dispatching_callback_for_event_type_impl() [2/5]

template<BeginEvent EventType>
static auto Kokkos::utils::callbacks::Manager::create_dispatching_callback_for_event_type_impl ( )
inlinestaticprivate

Definition at line 330 of file Manager.hpp.

◆ create_dispatching_callback_for_event_type_impl() [3/5]

template<DataEvent EventType>
static auto Kokkos::utils::callbacks::Manager::create_dispatching_callback_for_event_type_impl ( )
inlinestaticprivate

Definition at line 341 of file Manager.hpp.

◆ create_dispatching_callback_for_event_type_impl() [4/5]

template<Event EventType>
requires std::same_as<EventType, BeginDeepCopyEvent>
static auto Kokkos::utils::callbacks::Manager::create_dispatching_callback_for_event_type_impl ( )
inlinestaticprivate

Definition at line 351 of file Manager.hpp.

◆ create_dispatching_callback_for_event_type_impl() [5/5]

template<Event EventType>
requires std::same_as<EventType, CreateProfileSectionEvent>
static auto Kokkos::utils::callbacks::Manager::create_dispatching_callback_for_event_type_impl ( )
inlinestaticprivate

Definition at line 365 of file Manager.hpp.

◆ dispatch() [1/2]

template<Event EventType>
void Kokkos::utils::callbacks::Manager::dispatch ( const EventType & event) const
inline

Dispatch the event to all registered listeners that can handle it.

Definition at line 242 of file Manager.hpp.

◆ dispatch() [2/2]

template<Event EventType>
void Kokkos::utils::callbacks::Manager::dispatch ( EventType & event)
inlineprivate

Dispatch first the context callback, if any is set in Kokkos, and then sequentially the registered callbacks for the event type.

Definition at line 380 of file Manager.hpp.

◆ dispatch_context_callback()

template<Event EventType>
void Kokkos::utils::callbacks::Manager::dispatch_context_callback ( EventType & event)
inlineprivate

Dispatch the event to the context callback, if any is set in Kokkos.

Definition at line 389 of file Manager.hpp.

◆ dispatch_context_callback_for_event_type_impl() [1/10]

template<typename ContextCallbackType>
static void Kokkos::utils::callbacks::Manager::dispatch_context_callback_for_event_type_impl ( ContextCallbackType * context_callback,
const BeginDeepCopyEvent & event )
inlinestaticprivate

Definition at line 416 of file Manager.hpp.

◆ dispatch_context_callback_for_event_type_impl() [2/10]

template<typename ContextCallbackType>
static void Kokkos::utils::callbacks::Manager::dispatch_context_callback_for_event_type_impl ( ContextCallbackType * context_callback,
const EndDeepCopyEvent &  )
inlinestaticprivate

Definition at line 422 of file Manager.hpp.

◆ dispatch_context_callback_for_event_type_impl() [3/10]

template<typename ContextCallbackType, EndEvent EventType>
static void Kokkos::utils::callbacks::Manager::dispatch_context_callback_for_event_type_impl ( ContextCallbackType * context_callback,
const EventType & event )
inlinestaticprivate

Definition at line 406 of file Manager.hpp.

◆ dispatch_context_callback_for_event_type_impl() [4/10]

template<typename ContextCallbackType, DataEvent EventType>
static void Kokkos::utils::callbacks::Manager::dispatch_context_callback_for_event_type_impl ( ContextCallbackType * context_callback,
const EventType & event )
inlinestaticprivate

Definition at line 411 of file Manager.hpp.

◆ dispatch_context_callback_for_event_type_impl() [5/10]

template<typename ContextCallbackType, ProfileSectionManipulationEvent EventType>
static void Kokkos::utils::callbacks::Manager::dispatch_context_callback_for_event_type_impl ( ContextCallbackType * context_callback,
const EventType & event )
inlinestaticprivate

Definition at line 432 of file Manager.hpp.

◆ dispatch_context_callback_for_event_type_impl() [6/10]

template<typename ContextCallbackType>
static void Kokkos::utils::callbacks::Manager::dispatch_context_callback_for_event_type_impl ( ContextCallbackType * context_callback,
const PopRegionEvent &  )
inlinestaticprivate

Definition at line 442 of file Manager.hpp.

◆ dispatch_context_callback_for_event_type_impl() [7/10]

template<typename ContextCallbackType>
static void Kokkos::utils::callbacks::Manager::dispatch_context_callback_for_event_type_impl ( ContextCallbackType * context_callback,
const ProfileEvent & event )
inlinestaticprivate

Definition at line 447 of file Manager.hpp.

◆ dispatch_context_callback_for_event_type_impl() [8/10]

template<typename ContextCallbackType>
static void Kokkos::utils::callbacks::Manager::dispatch_context_callback_for_event_type_impl ( ContextCallbackType * context_callback,
const PushRegionEvent & event )
inlinestaticprivate

Definition at line 437 of file Manager.hpp.

◆ dispatch_context_callback_for_event_type_impl() [9/10]

template<typename ContextCallbackType>
static void Kokkos::utils::callbacks::Manager::dispatch_context_callback_for_event_type_impl ( ContextCallbackType * context_callback,
CreateProfileSectionEvent & event )
inlinestaticprivate

Definition at line 427 of file Manager.hpp.

◆ dispatch_context_callback_for_event_type_impl() [10/10]

template<typename ContextCallbackType, BeginEvent EventType>
static void Kokkos::utils::callbacks::Manager::dispatch_context_callback_for_event_type_impl ( ContextCallbackType * context_callback,
EventType & event )
inlinestaticprivate

Definition at line 401 of file Manager.hpp.

◆ dispatch_registered_callbacks()

template<Event EventType>
void Kokkos::utils::callbacks::Manager::dispatch_registered_callbacks ( const EventType & event) const
inlineprivate

Definition at line 464 of file Manager.hpp.

◆ finalize()

static void Kokkos::utils::callbacks::Manager::finalize ( )
inlinestatic

Definition at line 162 of file Manager.hpp.

◆ get_instance()

static Manager & Kokkos::utils::callbacks::Manager::get_instance ( )
inlinestatic

Definition at line 166 of file Manager.hpp.

◆ get_next_event_id()

auto Kokkos::utils::callbacks::Manager::get_next_event_id ( )
inlinenoexcept

Get the next available event ID.

Definition at line 251 of file Manager.hpp.

◆ get_next_section_id()

auto Kokkos::utils::callbacks::Manager::get_next_section_id ( )
inlinenoexcept

Get the next available section ID.

Definition at line 256 of file Manager.hpp.

◆ increment_id_if_needed_for_event_type_impl() [1/3]

void Kokkos::utils::callbacks::Manager::increment_id_if_needed_for_event_type_impl ( CreateProfileSectionEvent & event)
inlineprivate

Definition at line 459 of file Manager.hpp.

◆ increment_id_if_needed_for_event_type_impl() [2/3]

template<Event EventType>
void Kokkos::utils::callbacks::Manager::increment_id_if_needed_for_event_type_impl ( EventType & )
inlineprivate

Definition at line 452 of file Manager.hpp.

◆ increment_id_if_needed_for_event_type_impl() [3/3]

template<BeginEvent EventType>
void Kokkos::utils::callbacks::Manager::increment_id_if_needed_for_event_type_impl ( EventType & event)
inlineprivate

Definition at line 455 of file Manager.hpp.

◆ initialize()

static void Kokkos::utils::callbacks::Manager::initialize ( )
inlinestatic

Definition at line 161 of file Manager.hpp.

◆ is_initialized()

static bool Kokkos::utils::callbacks::Manager::is_initialized ( )
inlinestatic

Definition at line 164 of file Manager.hpp.

◆ operator=()

Manager & Kokkos::utils::callbacks::Manager::operator= ( const Manager & )
delete

◆ register_listener() [1/2]

template<Listener Callable>
static listener_list_const_iter_t Kokkos::utils::callbacks::Manager::register_listener ( std::shared_ptr< Callable > callable)
inlinestatic

Register a callable object, passed as a shared pointer, as a listener.

Todo
Add the possibility to select only a subset of the event types.

Definition at line 174 of file Manager.hpp.

◆ register_listener() [2/2]

template<typename T>
requires Listener<std::remove_cvref_t<T>>
static listener_list_const_iter_t Kokkos::utils::callbacks::Manager::register_listener ( T && callable)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This overload registers a new callable object that is copy or move constructed from the passed callable. This overload can be useful for instance to register a lambda as a listener.

Definition at line 188 of file Manager.hpp.

◆ register_listener_impl()

template<typename ListenerModelType, typename CallableType>
static listener_list_const_iter_t Kokkos::utils::callbacks::Manager::register_listener_impl ( CallableType && callable)
inlinestaticprivate

Wrap the callable object into a impl::ListenerModel and store it in the list of listeners.

For each event type that the callable object can be invoked with, store the raw pointer to the listener model in the list of listeners for this event type.

Definition at line 270 of file Manager.hpp.

◆ reset_context_callbacks()

void Kokkos::utils::callbacks::Manager::reset_context_callbacks ( ) const
inlineprivate

Uses Kokkos::Tools::Experimental::set_callbacks to restore the Kokkos callback function pointers to those retrieved on this class's initialization.

Definition at line 265 of file Manager.hpp.

◆ set_dispatching_callback_impl()

template<Event EventType>
void Kokkos::utils::callbacks::Manager::set_dispatching_callback_impl ( ) const
inlineprivate

Definition at line 309 of file Manager.hpp.

◆ set_dispatching_callbacks()

void Kokkos::utils::callbacks::Manager::set_dispatching_callbacks ( ) const
inlineprivate

Uses the setters Kokkos::Tools::Experimental::set_<event_type_name>_callback to set the Kokkos callback function pointers to this class's dispatching functions for the event types for which there are registered callbacks.

Definition at line 301 of file Manager.hpp.

◆ unregister_listener() [1/2]

template<Listener Callable>
static void Kokkos::utils::callbacks::Manager::unregister_listener ( const Callable *const callable)
inlinestatic

Unregister a callable object as a listener.

Definition at line 197 of file Manager.hpp.

◆ unregister_listener() [2/2]

static void Kokkos::utils::callbacks::Manager::unregister_listener ( const listener_list_const_iter_t & iter)
inlinestatic

Definition at line 227 of file Manager.hpp.

Member Data Documentation

◆ context_callbacks

Kokkos::Tools::Experimental::EventSet Kokkos::utils::callbacks::Manager::context_callbacks {}
private

Definition at line 478 of file Manager.hpp.

◆ listeners

listener_list_t Kokkos::utils::callbacks::Manager::listeners {}
private

Definition at line 474 of file Manager.hpp.

◆ next_event_id

std::atomic<EventTraits::event_id_t> Kokkos::utils::callbacks::Manager::next_event_id {0}
private

Definition at line 480 of file Manager.hpp.

◆ next_section_id

std::atomic<uint32_t> Kokkos::utils::callbacks::Manager::next_section_id {0}
private

Definition at line 481 of file Manager.hpp.

◆ registered_callbacks

listener_call_opr_list_tuple_t Kokkos::utils::callbacks::Manager::registered_callbacks {}
private

Definition at line 472 of file Manager.hpp.

◆ singleton

Manager* Kokkos::utils::callbacks::Manager::singleton = nullptr
inlinestaticprivate

Definition at line 476 of file Manager.hpp.


The documentation for this class was generated from the following file: