Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
hh::StateManager< Separator, AllTypes > Class Template Reference

AbstractState manager. More...

#include "state_manager.h"

Inheritance diagram for hh::StateManager< Separator, AllTypes >:
Inheritance graph
Collaboration diagram for hh::StateManager< Separator, AllTypes >:
Collaboration graph

Public Member Functions

 StateManager (std::shared_ptr< AbstractState< Separator, AllTypes... > > state, std::string const &name="State manager", bool const automaticStart=false)
 Main state manager constructor.
 
 StateManager (std::shared_ptr< core::CoreStateManager< Separator, AllTypes... > > core, std::shared_ptr< AbstractState< Separator, AllTypes... > > state)
 AbstractState Manager constructor with a user-custom core.
 
 ~StateManager () override=default
 Default destructor for the state manager.
 
std::shared_ptr< AbstractState< Separator, AllTypes... > > const & state () const
 AbstractState accessor.
 
bool automaticStart () const
 Automatic start flag accessor.
 
std::shared_ptr< core::CoreStateManager< Separator, AllTypes... > > const & coreStateManager () const
 Accessor to the core.
 
bool canTerminate () const override
 Default termination rule, it terminates if there is no predecessor connection and there is no input data.
 
std::shared_ptr< StateManager< Separator, AllTypes... > > copy () final
 Provide a copy of the state manager.
 
virtual std::shared_ptr< StateManager< Separator, AllTypes... > > copyStateManager (std::shared_ptr< AbstractState< Separator, AllTypes... > > state)
 Customizable copy method.
 
- Public Member Functions inherited from hh::behavior::TaskNode
 TaskNode (std::shared_ptr< hh::core::abstraction::TaskNodeAbstraction > core)
 Constructor using a core.
 
 ~TaskNode () override=default
 Default destructor.
 
std::shared_ptr< AbstractMemoryManager > const & memoryManager () const
 Memory manager accessor.
 
void connectMemoryManager (std::shared_ptr< AbstractMemoryManager > mm)
 Connect a memory manager to a task.
 
std::shared_ptr< ManagedMemorygetManagedMemory ()
 Get a managed memory for the memory manager attached to the task, can block if none are available at the time of the call.
 
virtual void initialize ()
 initialize step for the task
 
virtual void shutdown ()
 shutdown step for the task
 
virtual std::string extraPrintingInformation () const
 Print extra information for the task.
 
- Public Member Functions inherited from hh::behavior::Node
 Node (std::shared_ptr< hh::core::abstraction::NodeAbstraction > core)
 Constructor's node.
 
virtual ~Node ()=default
 Default destructor.
 
std::shared_ptr< hh::core::abstraction::NodeAbstraction > const & core () const
 Core accessor.
 
std::string name () const
 Node's name accessor.
 
- Public Member Functions inherited from hh::behavior::CanTerminate
 CanTerminate ()=default
 Default constructor.
 
virtual ~CanTerminate ()=default
 Default destructor.
 
virtual bool canTerminate () const =0
 Termination condition.
 
- Public Member Functions inherited from hh::behavior::Cleanable
 Cleanable ()=default
 Default constructor.
 
 ~Cleanable ()=default
 Default destructor.
 
virtual void clean ()
 Clean a node.
 
- Public Member Functions inherited from hh::behavior::Copyable< StateManager< Separator, AllTypes... > >
 Copyable (size_t const numberThreads)
 Copyable constructor, set the number of threads for a node.
 
virtual ~Copyable ()=default
 Default destructor.
 
size_t numberThreads () const
 Number of threads accessor.
 
std::vector< StateManager< Separator, AllTypes... > const * > group () const
 Get the group of nodes that hold the current nodes.
 
virtual std::shared_ptr< StateManager< Separator, AllTypes... > > copy ()
 Copy method called to either create a group of node or duplicate a node when an execution pipeline is created.
 

Private Attributes

std::shared_ptr< AbstractState< Separator, AllTypes... > > state_ = nullptr
 AbstractState managed.
 
std::shared_ptr< core::CoreStateManager< Separator, AllTypes... > > coreStateManager_ = nullptr
 AbstractState manager core.
 

Detailed Description

template<size_t Separator, class ... AllTypes>
class hh::StateManager< Separator, AllTypes >

AbstractState manager.

The state manager is a Hedgehog node that manages locally the state of the computation. To do so, it uses a state protected by a mutex. The state holds the data structures that are used to manage the flow of data and organize rendez-vous points or other synchronization mechanisms. The default order of execution is:

  1. The StateManager will acquire data,
  2. The StateManager will lock the AbstractState
  3. The StateManager will send the data to the AbstractState,
  4. The compatible Execute::execute is called within the data,
  5. During the call of Execute::execute, if the method StateMultiSenders::addResult is invoked the "result data" is stored in a ready list,
  6. When the Execute::execute has returned, the waiting list is emptied as output of the StateManager,
  7. The StateManager will unlock the AbstractState.

The state is protected because it can be shared between multiple state managers, either with multiple state managers in the same graph or if the state managers belongs to a graph that is duplicated with an execution pipeline. In this case, each of the state managers in every graph copy will share the same state. This can be used when dealing with computation across multiple GPUs, to synchronize data or share information between devices.

The state manager can be derived to change its termination rule for example. The method copyStateManager can be derived to customise the copy mechanism of the state manager.

Attention
A state manager can not be part of a group of threads (multi-threaded).
In case of a cycle in the graph CanTerminate::canTerminate needs to be overloaded or the graph will // deadlock. By default, AbstractTask::canTerminate will be true if there is no "input node" connected AND no data // available in the task input queue (CF tutorial 3).
Template Parameters
SeparatorSeparator position between input types and output types
AllTypesList of input and output types

Definition at line 60 of file state_manager.h.

Constructor & Destructor Documentation

◆ StateManager() [1/2]

template<size_t Separator, class ... AllTypes>
hh::StateManager< Separator, AllTypes >::StateManager ( std::shared_ptr< AbstractState< Separator, AllTypes... > >  state,
std::string const &  name = "State manager",
bool const  automaticStart = false 
)
inlineexplicit

Main state manager constructor.

Parameters
stateAbstractState managed by the state manager
nameName of the state manager (default: "AbstractState manager")
automaticStartFlag to start the execution of the state manager without data (sending automatically nullptr to each of the input types)
Exceptions
std::runtime_errorthe state is not valid (== nullptr or does not derive from CoreStateManager)

Definition at line 78 of file state_manager.h.

Here is the call graph for this function:

◆ StateManager() [2/2]

template<size_t Separator, class ... AllTypes>
hh::StateManager< Separator, AllTypes >::StateManager ( std::shared_ptr< core::CoreStateManager< Separator, AllTypes... > >  core,
std::shared_ptr< AbstractState< Separator, AllTypes... > >  state 
)
inlineexplicit

AbstractState Manager constructor with a user-custom core.

A custom core can be used to customize how the state manager behaves internally. For example, by default any input is stored in a std::queue, it can be changed to a std::priority_queue instead through the core.

Parameters
coreCustom core used to change the behavior of the state manager
stateAbstractState managed by the state manager
Exceptions
std::runtime_errorthe state is not valid (== nullptr or does not derive from CoreStateManager)

Definition at line 107 of file state_manager.h.

Here is the call graph for this function:

◆ ~StateManager()

template<size_t Separator, class ... AllTypes>
hh::StateManager< Separator, AllTypes >::~StateManager ( )
overridedefault

Default destructor for the state manager.

Member Function Documentation

◆ automaticStart()

template<size_t Separator, class ... AllTypes>
bool hh::StateManager< Separator, AllTypes >::automaticStart ( ) const
inline

Automatic start flag accessor.

Returns
True if the state manager is set to automatically start, else false

Definition at line 136 of file state_manager.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canTerminate()

template<size_t Separator, class ... AllTypes>
bool hh::StateManager< Separator, AllTypes >::canTerminate ( ) const
inlineoverridevirtual

Default termination rule, it terminates if there is no predecessor connection and there is no input data.

Returns
True if the state manager can terminate, else false

Implements hh::behavior::CanTerminate.

Definition at line 146 of file state_manager.h.

◆ copy()

template<size_t Separator, class ... AllTypes>
std::shared_ptr< StateManager< Separator, AllTypes... > > hh::StateManager< Separator, AllTypes >::copy ( )
inlinefinalvirtual

Provide a copy of the state manager.

Returns
A copy of the state manager
Exceptions
std::runtime_errora state manager copy is not valid (== nullptr or do not share the same state)

Reimplemented from hh::behavior::Copyable< StateManager< Separator, AllTypes... > >.

Definition at line 153 of file state_manager.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyStateManager()

template<size_t Separator, class ... AllTypes>
virtual std::shared_ptr< StateManager< Separator, AllTypes... > > hh::StateManager< Separator, AllTypes >::copyStateManager ( std::shared_ptr< AbstractState< Separator, AllTypes... > >  state)
inlinevirtual

Customizable copy method.

Parameters
stateAbstractState to insert in the state manager copy
Returns
New state manager with the same state

Definition at line 174 of file state_manager.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ coreStateManager()

template<size_t Separator, class ... AllTypes>
std::shared_ptr< core::CoreStateManager< Separator, AllTypes... > > const & hh::StateManager< Separator, AllTypes >::coreStateManager ( ) const
inline

Accessor to the core.

Returns
Core tot he state manager

Definition at line 140 of file state_manager.h.

Here is the caller graph for this function:

◆ state()

template<size_t Separator, class ... AllTypes>
std::shared_ptr< AbstractState< Separator, AllTypes... > > const & hh::StateManager< Separator, AllTypes >::state ( ) const
inline

AbstractState accessor.

Returns
AbstractState managed by the state manager

Definition at line 132 of file state_manager.h.

Here is the caller graph for this function:

Member Data Documentation

◆ coreStateManager_

template<size_t Separator, class ... AllTypes>
std::shared_ptr<core::CoreStateManager<Separator, AllTypes...> > hh::StateManager< Separator, AllTypes >::coreStateManager_ = nullptr
private

AbstractState manager core.

Definition at line 69 of file state_manager.h.

◆ state_

template<size_t Separator, class ... AllTypes>
std::shared_ptr<AbstractState<Separator, AllTypes...> > hh::StateManager< Separator, AllTypes >::state_ = nullptr
private

AbstractState managed.

Definition at line 68 of file state_manager.h.