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

Task core. More...

#include "core_task.h"

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

Public Member Functions

 CoreTask (AbstractTask< Separator, AllTypes... > *const task)
 Create a CoreTask from a user-defined AbstractTask with one thread.
 
 CoreTask (AbstractTask< Separator, AllTypes... > *const task, std::string const &name, size_t const numberThreads, bool const automaticStart)
 Create a CoreTask from a user-defined AbstractTask, its name, the number of threads and the automatic start flag.
 
template<class ConcreteMultiReceivers , class ConcreteMultiExecutes , class ConcreteMultiSenders >
 CoreTask (AbstractTask< Separator, AllTypes... > *const task, std::string const &name, size_t const numberThreads, bool const automaticStart, std::shared_ptr< implementor::ImplementorSlot > concreteSlot, std::shared_ptr< ConcreteMultiReceivers > concreteMultiReceivers, std::shared_ptr< ConcreteMultiExecutes > concreteMultiExecutes, std::shared_ptr< implementor::ImplementorNotifier > concreteNotifier, std::shared_ptr< ConcreteMultiSenders > concreteMultiSenders)
 Construct a task from the user-defined task and its concrete abstraction's implementations.
 
 ~CoreTask () override=default
 Default destructor.
 
std::shared_ptr< AbstractMemoryManagermemoryManager () const override
 Accessor to the memory manager.
 
bool callCanTerminate (bool lock) override
 Call user-definable termination.
 
void preRun () override
 Initialize the task.
 
void run () override
 Main core task logic.
 
void postRun () override
 When a task terminates, set the task to non active, call user-defined shutdown, and disconnect the task to successor nodes.
 
bool wait ()
 Wait statement when the node is alive and no input data are available.
 
void createGroup (std::map< NodeAbstraction *, std::vector< NodeAbstraction * > > &map) override
 Create a group for this task, and connect each copies to the predecessor and successor nodes.
 
bool hasMemoryManagerAttached () const override
 Test if a memory manager is attached.
 
std::string extraPrintingInformation () const override
 Accessor to user-defined extra information for the task.
 
void copyInnerStructure (CoreTask< Separator, AllTypes... > *copyableCore) override
 Copy task's inner structure.
 
std::vector< std::pair< std::string const, std::string const > > ids () const override
 Node ids [nodeId, nodeGroupId] accessor.
 
void visit (Printer *printer) override
 Visit the task.
 
std::shared_ptr< abstraction::NodeAbstractionclone (std::map< NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &correspondenceMap) override
 Clone method, to duplicate a task when it is part of another graph in an execution pipeline.
 
void duplicateEdge (std::map< NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &mapping) override
 Duplicate the task edge.
 
- 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::GroupableAbstraction< AbstractTask< Separator, AllTypes... >, CoreTask< Separator, AllTypes... > >
 GroupableAbstraction (CopyableNode *const copyableNode, size_t const &numberThreads)
 Constructor using the node abstraction to call the user-defined copy and the number of threads.
 
 ~GroupableAbstraction () override=default
 Default destructor.
 
int threadId () const
 Accessor to thread id.
 
std::shared_ptr< CopyableNode > callCopyAndRegisterInGroup ()
 Call the used-defined copy and register the copy in the group.
 
virtual void copyInnerStructure (CoreTask< Separator, AllTypes... > *copyableCore)=0
 Copy the inner structure of the core.
 
- Public Member Functions inherited from hh::core::abstraction::CopyableAbstraction< CopyableNode >
 CopyableAbstraction (CopyableNode *const copyableNode)
 Constructor using a node abstraction.
 
virtual ~CopyableAbstraction ()=default
 Default destructor.
 
- Public Member Functions inherited from hh::core::abstraction::AnyGroupableAbstraction
 AnyGroupableAbstraction (size_t const numberThreads)
 Constructor using the number of threads.
 
virtual ~AnyGroupableAbstraction ()=default
 Default destructor.
 
size_t numberThreads () const
 Accessor to the number of threads.
 
bool isInGroup () const
 Test if a group is needed.
 
std::string nodeId () const
 Accessor to the node id (redirection to NodeAbstraction::nodeId)
 
std::shared_ptr< std::set< AnyGroupableAbstraction * > > const & group () const
 Group of cores accessor.
 
std::shared_ptr< std::set< NodeAbstraction * > > groupAsNodes () const
 Create a set of the NodeAbstraction constituting the group.
 
AnyGroupableAbstractiongroupRepresentative () const
 Group representative accessor.
 
std::string groupRepresentativeId () const
 Group id representative accessor.
 
void groupRepresentative (AnyGroupableAbstraction *groupRepresentative)
 Group representative setter.
 
void group (std::shared_ptr< std::set< AnyGroupableAbstraction * > > const &group)
 Group setter.
 
size_t numberActiveThreadInGroup () const
 Accessor to the number of nodes alive in the group.
 
std::pair< std::chrono::nanoseconds, std::chrono::nanoseconds > minmaxWaitDurationGroup () const
 Accessor to the min / max wait duration of the nodes in the group.
 
std::pair< std::chrono::nanoseconds, std::chrono::nanoseconds > meanSDWaitDurationGroup () const
 Accessor to the mean / standard deviation wait duration of the nodes in the group.
 
std::pair< std::chrono::nanoseconds, std::chrono::nanoseconds > minmaxExecutionDurationGroup () const
 Accessor to the min / max execution duration of the nodes in the group.
 
std::pair< std::chrono::nanoseconds, std::chrono::nanoseconds > meanSDExecutionDurationGroup () const
 Accessor to the mean / standard deviation execution duration of the nodes in the group.
 
std::pair< std::chrono::nanoseconds, std::chrono::nanoseconds > minmaxExecTimePerElementGroup () const
 Accessor to the min / max execution per elements duration of the nodes in the group.
 
std::pair< std::chrono::nanoseconds, std::chrono::nanoseconds > meanSDExecTimePerElementGroup () const
 Accessor to the mean / standard deviation execution per elements duration of the nodes in the group.
 
std::pair< std::chrono::nanoseconds, std::chrono::nanoseconds > minmaxMemoryWaitTimeGroup () const
 Accessor to the min / max wait time duration of the nodes in the group.
 
std::pair< std::chrono::nanoseconds, std::chrono::nanoseconds > meanSDMemoryWaitTimePerElementGroup () const
 Accessor to the mean / standard deviation wait time duration of the nodes in the group.
 
std::pair< size_t, size_tminmaxNumberElementsReceivedGroup () const
 Accessor to the min / max number of elements received in the group.
 
std::pair< double, double > meanSDNumberElementsReceivedGroup () const
 Accessor to the mean / standard deviation number of elements received in the group.
 
virtual void createGroup (std::map< NodeAbstraction *, std::vector< NodeAbstraction * > > &)=0
 Create a group to insert in the map.
 

Private Attributes

AbstractTask< Separator, AllTypes... > *const task_ = nullptr
 User defined task.
 
bool const automaticStart_ = false
 Flag for automatic start.
 

Additional Inherited Members

- 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< CopyableNode >
std::shared_ptr< CopyableNode > callCopy ()
 Interface to call user-defined copy method.
 

Detailed Description

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

Task core.

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

Definition at line 64 of file core_task.h.

Constructor & Destructor Documentation

◆ CoreTask() [1/3]

template<size_t Separator, class ... AllTypes>
hh::core::CoreTask< Separator, AllTypes >::CoreTask ( AbstractTask< Separator, AllTypes... > *const  task)
inlineexplicit

Create a CoreTask from a user-defined AbstractTask with one thread.

Parameters
taskUser-defined AbstractTask

Definition at line 83 of file core_task.h.

◆ CoreTask() [2/3]

template<size_t Separator, class ... AllTypes>
hh::core::CoreTask< Separator, AllTypes >::CoreTask ( AbstractTask< Separator, AllTypes... > *const  task,
std::string const &  name,
size_t const  numberThreads,
bool const  automaticStart 
)
inline

Create a CoreTask from a user-defined AbstractTask, its name, the number of threads and the automatic start flag.

Parameters
taskUser-defined AbstractTask
nameTask's name
numberThreadsNumber of threads
automaticStartFlag for automatic start

Definition at line 100 of file core_task.h.

Here is the call graph for this function:

◆ CoreTask() [3/3]

template<size_t Separator, class ... AllTypes>
template<class ConcreteMultiReceivers , class ConcreteMultiExecutes , class ConcreteMultiSenders >
hh::core::CoreTask< Separator, AllTypes >::CoreTask ( AbstractTask< Separator, AllTypes... > *const  task,
std::string const &  name,
size_t const  numberThreads,
bool const  automaticStart,
std::shared_ptr< implementor::ImplementorSlot concreteSlot,
std::shared_ptr< ConcreteMultiReceivers >  concreteMultiReceivers,
std::shared_ptr< ConcreteMultiExecutes >  concreteMultiExecutes,
std::shared_ptr< implementor::ImplementorNotifier concreteNotifier,
std::shared_ptr< ConcreteMultiSenders >  concreteMultiSenders 
)
inline

Construct a task from the user-defined task 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
taskUser-defined task
nameTask's name
numberThreadsNumber of threads for the task
automaticStartFlag for automatic start
concreteSlotConcrete implementation of SlotAbstraction
concreteMultiReceiversConcrete implementation of ReceiverAbstraction for multiple types
concreteMultiExecutesConcrete implementation of ExecuteAbstraction for multiple type
concreteNotifierConcrete implementation of NotifierAbstraction
concreteMultiSendersConcrete implementation of SenderAbstraction for multiple types
Exceptions
std::runtime_errorif the number of threads is 0

Definition at line 129 of file core_task.h.

Here is the call graph for this function:

◆ ~CoreTask()

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

Default destructor.

Member Function Documentation

◆ callCanTerminate()

template<size_t Separator, class ... AllTypes>
bool hh::core::CoreTask< 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 160 of file core_task.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::CoreTask< Separator, AllTypes >::clone ( std::map< NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &  correspondenceMap)
inlineoverride

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

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

Definition at line 350 of file core_task.h.

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

◆ copyInnerStructure()

template<size_t Separator, class ... AllTypes>
void hh::core::CoreTask< Separator, AllTypes >::copyInnerStructure ( CoreTask< Separator, AllTypes... > *  copyableCore)
inlineoverridevirtual

Copy task's inner structure.

Parameters
copyableCoreTask to copy from

Implements hh::core::abstraction::GroupableAbstraction< AbstractTask< Separator, AllTypes... >, CoreTask< Separator, AllTypes... > >.

Definition at line 328 of file core_task.h.

◆ createGroup()

template<size_t Separator, class ... AllTypes>
void hh::core::CoreTask< Separator, AllTypes >::createGroup ( std::map< NodeAbstraction *, std::vector< NodeAbstraction * > > &  map)
inlineoverride

Create a group for this task, and connect each copies to the predecessor and successor nodes.

Parameters
mapMap of nodes and groups
Exceptions
std::runtime_errorit the task is ill-formed or the copy is not of the right type

Definition at line 259 of file core_task.h.

Here is the call graph for this function:

◆ duplicateEdge()

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

Duplicate the task edge.

Parameters
mappingCorrespondence map of belonging graph's node

Definition at line 359 of file core_task.h.

◆ extraPrintingInformation()

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

Accessor to user-defined extra information for the task.

Returns
User-defined extra information for the task

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

Definition at line 322 of file core_task.h.

Here is the call graph for this function:

◆ hasMemoryManagerAttached()

template<size_t Separator, class ... AllTypes>
bool hh::core::CoreTask< 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 318 of file core_task.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::CoreTask< Separator, AllTypes >::ids ( ) const
inlineoverridevirtual

Node ids [nodeId, nodeGroupId] accessor.

Returns
Node ids [nodeId, nodeGroupId]

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

Definition at line 335 of file core_task.h.

Here is the call graph for this function:

◆ memoryManager()

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

Accessor to the memory manager.

Returns
The attached memory manager

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

Definition at line 153 of file core_task.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::CoreTask< Separator, AllTypes >::postRun ( )
inlineoverridevirtual

When a task terminates, set the task to non active, call user-defined shutdown, and disconnect the task to successor nodes.

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

Definition at line 235 of file core_task.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::CoreTask< Separator, AllTypes >::preRun ( )
inlineoverridevirtual

Initialize the task.

Call user define initialize, initialise memory manager if present

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

Definition at line 170 of file core_task.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::CoreTask< Separator, AllTypes >::run ( )
inlineoverridevirtual

Main core task logic.

  • if automatic start
    • call user-defined task's execute method with nullptr
  • while the task runs
    • wait for data or termination
    • if can terminate, break
    • get a piece of data from the queue
    • call user-defined state's execute method with data
  • shutdown the task
  • notify successors task terminated

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

Definition at line 193 of file core_task.h.

Here is the call graph for this function:

◆ visit()

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

Visit the task.

Parameters
printerPrinter gathering task information

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

Definition at line 340 of file core_task.h.

Here is the call graph for this function:

◆ wait()

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

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 245 of file core_task.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::CoreTask< Separator, AllTypes >::automaticStart_ = false
private

Flag for automatic start.

Definition at line 78 of file core_task.h.

◆ task_

template<size_t Separator, class ... AllTypes>
AbstractTask<Separator, AllTypes...>* const hh::core::CoreTask< Separator, AllTypes >::task_ = nullptr
private

User defined task.

Definition at line 75 of file core_task.h.