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

AbstractState manager core. More...

#include "core_state_manager.h"

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

Public Member Functions

 CoreStateManager (StateManager< Separator, AllTypes... > *const stateManager, std::shared_ptr< AbstractState< Separator, AllTypes... > > const &state)
 Construct a state manager from the user state manager and its state.
 
 CoreStateManager (StateManager< Separator, AllTypes... > *const stateManager, std::shared_ptr< AbstractState< Separator, AllTypes... > > const &state, std::string const &name, bool const automaticStart)
 Construct a state manager from the user state manager, its state, a name and the automatic start flag.
 
template<class ConcreteMultiReceivers , class ConcreteMultiExecutes , class ConcreteMultiSenders >
 CoreStateManager (StateManager< Separator, AllTypes... > *const stateManager, std::shared_ptr< AbstractState< Separator, AllTypes... > > const &state, std::string const &name, bool const automaticStart, std::shared_ptr< implementor::ImplementorSlot > const &concreteSlot, std::shared_ptr< ConcreteMultiReceivers > concreteMultiReceivers, std::shared_ptr< ConcreteMultiExecutes > concreteMultiExecutes, std::shared_ptr< implementor::ImplementorNotifier > const &concreteNotifier, std::shared_ptr< ConcreteMultiSenders > concreteMultiSenders)
 Construct a state manager from the state manager and its concrete abstraction's implementations.
 
 ~CoreStateManager () override=default
 Default destructor.
 
bool automaticStart () const
 Accessor to the automatic start flag.
 
bool callCanTerminate (bool lock) override
 Call user-definable termination.
 
void visit (Printer *printer) override
 Visit the state manager.
 
std::vector< std::pair< std::string const, std::string const > > ids () const override
 Node ids [nodeId, nodeGroupId] accessor.
 
void preRun () override
 Initialize the state manager.
 
void run () override
 Main core state manager logic.
 
void postRun () override
 Post run logic, shutdown the state manager, notify successor nodes of state manager termination.
 
bool hasMemoryManagerAttached () const override
 Test if a memory manager is attached.
 
std::string extraPrintingInformation () const override
 Accessor to user-defined extra information for the state-manager.
 
std::shared_ptr< AbstractMemoryManagermemoryManager () const override
 Accessor to the memory manager.
 
- Public Member Functions inherited from hh::core::abstraction::TaskNodeAbstraction
 TaskNodeAbstraction (std::string const &name, behavior::Node *node)
 Create the abstraction with the node's name.
 
 ~TaskNodeAbstraction () override=default
 Default destructor.
 
bool isActive () const
 Accessor to task status.
 
bool isInitialized () const
 Accessor to initialized flag.
 
size_t numberReceivedElements () const
 Accessor to the number of received elements.
 
std::chrono::nanoseconds const & waitDuration () const
 Accessor to the duration the node was in a wait state.
 
std::chrono::nanoseconds const & memoryWaitDuration () const
 Accessor to the duration the node was in a memory wait state.
 
std::shared_ptr< NvtxProfiler > const & nvtxProfiler () const
 Accessor to the NVTX profiler attached to the node.
 
std::chrono::nanoseconds perElementExecutionDuration () const
 Accessor to the duration the average duration of processing an input data.
 
void isActive (bool isActive)
 Setter to the task status.
 
void incrementNumberReceivedElements ()
 Increment the number of elements received.
 
void incrementWaitDuration (std::chrono::nanoseconds const &wait)
 Increment the wait duration.
 
void incrementMemoryWaitDuration (std::chrono::nanoseconds const &wait)
 Increase the memory wait duration.
 
void incrementPerElementExecutionDuration (std::chrono::nanoseconds const &exec)
 Increase the execution time per elements.
 
virtual void preRun ()=0
 Pre run method, called only once.
 
virtual void run ()=0
 Run method, called when thread is attached.
 
virtual void postRun ()=0
 Post run method, called only once.
 
virtual std::string extraPrintingInformation () const =0
 Abstraction to add user-defined message for the printers.
 
virtual bool hasMemoryManagerAttached () const =0
 Flag accessor to the presence of memory manager attached.
 
virtual std::shared_ptr< AbstractMemoryManagermemoryManager () const =0
 Accessor to the attached memory manager.
 
behavior::Nodenode () const override
 Node accessor.
 
- Public Member Functions inherited from hh::core::abstraction::NodeAbstraction
 NodeAbstraction (std::string name)
 Core node constructor using the core's name.
 
virtual ~NodeAbstraction ()=default
 DEfault destructor.
 
std::string const & name () const
 Accessor to the core's name.
 
virtual std::string id () const
 Core's id ('x' + address of abstraction) as string.
 
bool isRegistered () const
 Accessor to registration flag.
 
GraphNodeAbstractionbelongingGraph () const
 Belonging graph accessor.
 
virtual int deviceId () const
 Get the device identifier (got from belonging graph)
 
virtual size_t graphId () const
 Get the graph identifier (got from belonging graph)
 
std::chrono::nanoseconds const & executionDuration () const
 Execution duration.
 
std::chrono::time_point< std::chrono::system_clock > const & startExecutionTimeStamp () const
 Accessor to the starting execution timestamp.
 
void startExecutionTimeStamp (std::chrono::time_point< std::chrono::system_clock > const &startExecutionTimeStamp)
 Setter to the starting execution timestamp.
 
void incrementExecutionDuration (std::chrono::nanoseconds const &exec)
 Increment execution duration.
 
virtual void registerNode (GraphNodeAbstraction *belongingGraph)
 Register node to the given graph.
 
virtual std::vector< std::pair< std::string const, std::string const > > ids () const =0
 Node ids [nodeId, nodeGroupId] accessor.
 
virtual behavior::Nodenode () const =0
 Node accessor.
 
- Public Member Functions inherited from hh::core::abstraction::PrintableAbstraction
tool::PrintOptions const & printOptions () const
 Print options const accessor.
 
tool::PrintOptionsprintOptions ()
 Print options accessor.
 
virtual void visit (Printer *printer)=0
 Visitor method, used by the printer to visit all nodes in the graph.
 
- Public Member Functions inherited from hh::core::abstraction::ClonableAbstraction
 ClonableAbstraction ()
 Default constructor.
 
virtual ~ClonableAbstraction ()=default
 Default destructor.
 
void storeClone (std::shared_ptr< abstraction::NodeAbstraction > const &clone)
 Store a core clone.
 
virtual std::shared_ptr< abstraction::NodeAbstractionclone (std::map< NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &correspondenceMap)=0
 Clone virtual function.
 
virtual void duplicateEdge (std::map< NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &mapping)=0
 Duplicate the output edges of a node.
 
- Public Member Functions inherited from hh::core::abstraction::CleanableAbstraction
 CleanableAbstraction ()=default
 Constructor used by the CoreGraph to have the handles to clean inner cleanable nodes.
 
 CleanableAbstraction (behavior::Cleanable *const cleanableNode)
 Constructor used by cleanable nodes.
 
virtual ~CleanableAbstraction ()=default
 Default destructor.
 
virtual void gatherCleanable (std::unordered_set< hh::behavior::Cleanable * > &cleanableSet)
 Gather cleanable node from the graph, and the state manager.
 
- Public Member Functions inherited from hh::core::abstraction::CanTerminateAbstraction
 CanTerminateAbstraction (behavior::CanTerminate *const canTerminateNode)
 Constructor using behavior::CanTerminate node abstraction.
 
virtual ~CanTerminateAbstraction ()=default
 Default destructor.
 
bool callNodeCanTerminate () const
 Call user-definable termination.
 
virtual bool callCanTerminate (bool lock)=0
 Interface for calling user-definable termination.
 
- Public Member Functions inherited from hh::core::abstraction::CopyableAbstraction< StateManager< Separator, AllTypes... > >
 CopyableAbstraction (CopyableNode *const copyableNode)
 Constructor using a node abstraction.
 
virtual ~CopyableAbstraction ()=default
 Default destructor.
 

Protected Member Functions

bool wait ()
 Wait statement when the node is alive and no input data are available.
 
- Protected Member Functions inherited from hh::core::abstraction::TaskNodeAbstraction
void setInitialized ()
 Set the task as initialized.
 
- Protected Member Functions inherited from hh::core::abstraction::CopyableAbstraction< StateManager< Separator, AllTypes... > >
std::shared_ptr< CopyableNode > callCopy ()
 Interface to call user-defined copy method.
 

Private Member Functions

void gatherCleanable (std::unordered_set< hh::behavior::Cleanable * > &cleanableSet) override
 Gather the state manager and the state into the cleanableSet.
 
template<class Outputs_t , size_t ... Indexes>
void emptyReadyLists (std::index_sequence< Indexes... >)
 Interface method to call emptyReadyLists for a type when decomposing types from a tuple.
 
template<class Output >
void emptyReadyLists ()
 Empty the ready list for a type.
 
std::shared_ptr< abstraction::NodeAbstractionclone (std::map< NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &correspondenceMap) override
 Clone method, to duplicate a state manager when it is part of another graph in an execution pipeline.
 
void duplicateEdge (std::map< NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &mapping) override
 Duplicate the state manager edge.
 

Private Attributes

StateManager< Separator, AllTypes... > *const stateManager_ = nullptr
 User defined state manager.
 
std::shared_ptr< AbstractState< Separator, AllTypes... > > const state_ = nullptr
 Managed state.
 
bool const automaticStart_ = false
 Flag for automatic start.
 

Detailed Description

template<size_t Separator, class ... AllTypes>
class hh::core::CoreStateManager< Separator, AllTypes >

AbstractState manager core.

Template Parameters
SeparatorSeparator position between input types and output types
AllTypesList of input and output types

Definition at line 72 of file core_state_manager.h.

Constructor & Destructor Documentation

◆ CoreStateManager() [1/3]

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

Construct a state manager from the user state manager and its state.

Parameters
stateManagerUser-defined state manager
stateAbstractState to manage

Definition at line 94 of file core_state_manager.h.

◆ CoreStateManager() [2/3]

template<size_t Separator, class ... AllTypes>
hh::core::CoreStateManager< Separator, AllTypes >::CoreStateManager ( StateManager< Separator, AllTypes... > *const  stateManager,
std::shared_ptr< AbstractState< Separator, AllTypes... > > const &  state,
std::string const &  name,
bool const  automaticStart 
)
inline

Construct a state manager from the user state manager, its state, a name and the automatic start flag.

Parameters
stateManagerUser-defined state manager
stateAbstractState to manage
nameAbstractState manager name
automaticStartFlag for automatic start

Definition at line 103 of file core_state_manager.h.

◆ CoreStateManager() [3/3]

template<size_t Separator, class ... AllTypes>
template<class ConcreteMultiReceivers , class ConcreteMultiExecutes , class ConcreteMultiSenders >
hh::core::CoreStateManager< Separator, AllTypes >::CoreStateManager ( StateManager< Separator, AllTypes... > *const  stateManager,
std::shared_ptr< AbstractState< Separator, AllTypes... > > const &  state,
std::string const &  name,
bool const  automaticStart,
std::shared_ptr< implementor::ImplementorSlot > const &  concreteSlot,
std::shared_ptr< ConcreteMultiReceivers >  concreteMultiReceivers,
std::shared_ptr< ConcreteMultiExecutes >  concreteMultiExecutes,
std::shared_ptr< implementor::ImplementorNotifier > const &  concreteNotifier,
std::shared_ptr< ConcreteMultiSenders >  concreteMultiSenders 
)
inline

Construct a state manager from the state manager and its concrete abstraction's implementations.

Template Parameters
ConcreteMultiReceiversType of concrete implementation of ReceiverAbstraction for multiple types
ConcreteMultiExecutesType of concrete implementation of ExecuteAbstraction for multiple types
ConcreteMultiSendersType of concrete implementation of SenderAbstraction for multiple types
Parameters
stateManagerUser-defined state manager
stateAbstractState to manage
nameAbstractState manager name
automaticStartFlag for automatic start
concreteSlotConcrete implementation of SlotAbstraction
concreteMultiReceiversConcrete implementation of ReceiverAbstraction for multiple types
concreteMultiExecutesConcrete implementation of ExecuteAbstraction for multiple types
concreteNotifierConcrete implementation of NotifierAbstraction
concreteMultiSendersConcrete implementation of SenderAbstraction for multiple types

Definition at line 138 of file core_state_manager.h.

◆ ~CoreStateManager()

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

Default destructor.

Member Function Documentation

◆ automaticStart()

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

Accessor to the automatic start flag.

Returns

Definition at line 161 of file core_state_manager.h.

◆ callCanTerminate()

template<size_t Separator, class ... AllTypes>
bool hh::core::CoreStateManager< Separator, AllTypes >::callCanTerminate ( bool  lock)
inlineoverridevirtual

Call user-definable termination.

Parameters
lockFlag if the call to the user-definable termination need to be protected
Returns
True if the node can terminate, else false

Implements hh::core::abstraction::CanTerminateAbstraction.

Definition at line 166 of file core_state_manager.h.

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

◆ clone()

template<size_t Separator, class ... AllTypes>
std::shared_ptr< abstraction::NodeAbstraction > hh::core::CoreStateManager< Separator, AllTypes >::clone ( std::map< NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &  correspondenceMap)
inlineoverrideprivate

Clone method, to duplicate a state manager when it is part of another graph in an execution pipeline.

Parameters
correspondenceMapCorrespondence map of belonging graph's node
Returns
Clone of this state manager

Definition at line 348 of file core_state_manager.h.

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

◆ duplicateEdge()

template<size_t Separator, class ... AllTypes>
void hh::core::CoreStateManager< Separator, AllTypes >::duplicateEdge ( std::map< NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &  mapping)
inlineoverrideprivate

Duplicate the state manager edge.

Parameters
mappingCorrespondence map of belonging graph's node

Definition at line 357 of file core_state_manager.h.

◆ emptyReadyLists() [1/2]

template<size_t Separator, class ... AllTypes>
template<class Output >
void hh::core::CoreStateManager< Separator, AllTypes >::emptyReadyLists ( )
inlineprivate

Empty the ready list for a type.

Template Parameters
OutputReady list output type

Definition at line 335 of file core_state_manager.h.

◆ emptyReadyLists() [2/2]

template<size_t Separator, class ... AllTypes>
template<class Outputs_t , size_t ... Indexes>
void hh::core::CoreStateManager< Separator, AllTypes >::emptyReadyLists ( std::index_sequence< Indexes... >  )
inlineprivate

Interface method to call emptyReadyLists for a type when decomposing types from a tuple.

Template Parameters
Outputs_tTuple of types
IndexesIndexes of tuple

Definition at line 328 of file core_state_manager.h.

◆ extraPrintingInformation()

template<size_t Separator, class ... AllTypes>
std::string hh::core::CoreStateManager< Separator, AllTypes >::extraPrintingInformation ( ) const
inlineoverridevirtual

Accessor to user-defined extra information for the state-manager.

Returns
User-defined extra information for the state-manager

Implements hh::core::abstraction::TaskNodeAbstraction.

Definition at line 292 of file core_state_manager.h.

Here is the call graph for this function:

◆ gatherCleanable()

template<size_t Separator, class ... AllTypes>
void hh::core::CoreStateManager< Separator, AllTypes >::gatherCleanable ( std::unordered_set< hh::behavior::Cleanable * > &  cleanableSet)
inlineoverrideprivatevirtual

Gather the state manager and the state into the cleanableSet.

Parameters
cleanableSetSet of cleanable nodes

Reimplemented from hh::core::abstraction::CleanableAbstraction.

Definition at line 319 of file core_state_manager.h.

◆ hasMemoryManagerAttached()

template<size_t Separator, class ... AllTypes>
bool hh::core::CoreStateManager< Separator, AllTypes >::hasMemoryManagerAttached ( ) const
inlineoverridevirtual

Test if a memory manager is attached.

Returns
True if there is a memory manager attached, else false

Implements hh::core::abstraction::TaskNodeAbstraction.

Definition at line 288 of file core_state_manager.h.

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

◆ ids()

template<size_t Separator, class ... AllTypes>
std::vector< std::pair< std::string const, std::string const > > hh::core::CoreStateManager< Separator, AllTypes >::ids ( ) const
inlineoverridevirtual

Node ids [nodeId, nodeGroupId] accessor.

Returns
Node ids [nodeId, nodeGroupId]

Implements hh::core::abstraction::NodeAbstraction.

Definition at line 185 of file core_state_manager.h.

Here is the call graph for this function:

◆ memoryManager()

template<size_t Separator, class ... AllTypes>
std::shared_ptr< AbstractMemoryManager > hh::core::CoreStateManager< Separator, AllTypes >::memoryManager ( ) const
inlineoverridevirtual

Accessor to the memory manager.

Returns
The attached memory manager

Implements hh::core::abstraction::TaskNodeAbstraction.

Definition at line 298 of file core_state_manager.h.

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

◆ postRun()

template<size_t Separator, class ... AllTypes>
void hh::core::CoreStateManager< Separator, AllTypes >::postRun ( )
inlineoverridevirtual

Post run logic, shutdown the state manager, notify successor nodes of state manager termination.

Implements hh::core::abstraction::TaskNodeAbstraction.

Definition at line 278 of file core_state_manager.h.

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

◆ preRun()

template<size_t Separator, class ... AllTypes>
void hh::core::CoreStateManager< Separator, AllTypes >::preRun ( )
inlineoverridevirtual

Initialize the state manager.

Call user define initialize, initialize memory manager if present

Implements hh::core::abstraction::TaskNodeAbstraction.

Definition at line 191 of file core_state_manager.h.

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

◆ run()

template<size_t Separator, class ... AllTypes>
void hh::core::CoreStateManager< Separator, AllTypes >::run ( )
inlineoverridevirtual

Main core state manager logic.

  • if automatic start
    • lock the state
    • link the state-manager to the state
    • call user-defined state's execute method with nullptr
    • empty ready list
    • unlink the state-manager to the state
    • unlock the state
  • while the state-manager runs
    • wait for data or termination
    • if can terminate, break
    • lock the state
    • get a piece of data from the queue
    • link the state-manager to the state
    • call user-defined state's execute method with data
    • empty ready list
    • unlink the state-manager to the state (ensures correct state manager is used, such as with memory manager)
    • unlock the state
  • shutdown the state manager
  • notify successors state manager terminated

Implements hh::core::abstraction::TaskNodeAbstraction.

Definition at line 224 of file core_state_manager.h.

Here is the call graph for this function:

◆ visit()

template<size_t Separator, class ... AllTypes>
void hh::core::CoreStateManager< Separator, AllTypes >::visit ( Printer printer)
inlineoverridevirtual

Visit the state manager.

Parameters
printerPrinter gathering node information

Implements hh::core::abstraction::PrintableAbstraction.

Definition at line 176 of file core_state_manager.h.

Here is the call graph for this function:

◆ wait()

template<size_t Separator, class ... AllTypes>
bool hh::core::CoreStateManager< Separator, AllTypes >::wait ( )
inlineprotected

Wait statement when the node is alive and no input data are available.

Returns
True if the node can terminate, else false

Definition at line 305 of file core_state_manager.h.

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

Member Data Documentation

◆ automaticStart_

template<size_t Separator, class ... AllTypes>
bool const hh::core::CoreStateManager< Separator, AllTypes >::automaticStart_ = false
private

Flag for automatic start.

Definition at line 88 of file core_state_manager.h.

◆ state_

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

Managed state.

Definition at line 85 of file core_state_manager.h.

◆ stateManager_

template<size_t Separator, class ... AllTypes>
StateManager<Separator, AllTypes...>* const hh::core::CoreStateManager< Separator, AllTypes >::stateManager_ = nullptr
private

User defined state manager.

Definition at line 82 of file core_state_manager.h.