Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
hh::AbstractTask< TaskOutput, TaskInputs > Class Template Reference

Base node for computation. More...

#include "abstract_task.h"

Inheritance diagram for hh::AbstractTask< TaskOutput, TaskInputs >:
Inheritance graph
Collaboration diagram for hh::AbstractTask< TaskOutput, TaskInputs >:
Collaboration graph

Public Member Functions

 AbstractTask ()
 AbstractTask default constructor. More...
 
 AbstractTask (std::string_view const &name)
 Create a task with a custom name. More...
 
 AbstractTask (std::string_view const &name, size_t numberThreads)
 Create a task with a custom name and the task's cluster size. More...
 
 AbstractTask (std::string_view const &name, size_t numberThreads, bool automaticStart)
 Create a task with a custom name, the task's cluster size, and the automatic start. More...
 
 AbstractTask (std::string_view const name, size_t numberThreads, core::NodeType nodeType, bool automaticStart)
 Internal constructor needed to create nodes that derive from AbstractTask. More...
 
 AbstractTask (AbstractTask< TaskOutput, TaskInputs ... > *rhs)
 Copy constructor. More...
 
virtual ~AbstractTask ()=default
 Default destructor.
 
void addResult (std::shared_ptr< TaskOutput > output)
 Add an output data. More...
 
std::string_view name ()
 Task's name accessor. More...
 
size_t numberThreads ()
 Task's number of threads accessor. More...
 
bool automaticStart ()
 Task's automatic start accessor. More...
 
core::NodeType nodeType ()
 Task's node type accessor. More...
 
int deviceId ()
 Task's device ID accessor. More...
 
int graphId ()
 Task's graph ID accessor. More...
 
std::shared_ptr< core::CoreNodecore () final
 Task's core accessor. More...
 
std::shared_ptr< AbstractMemoryManager< TaskOutput > > const & memoryManager () const
 Task's memory manager accessor. More...
 
virtual std::shared_ptr< AbstractTask< TaskOutput, TaskInputs... > > copy ()
 Default copy overload, fail if cluster need to be copied. More...
 
virtual void initialize ()
 Initialize method called before AbstractTask::Execute loop.
 
virtual void shutdown ()
 Shutdown method called after AbstractTask::Execute loop, when AbstractTask::canTerminate evaluates to true.
 
void connectMemoryManager (std::shared_ptr< AbstractMemoryManager< TaskOutput >> mm)
 Connect a memory manager to the task. More...
 
std::shared_ptr< TaskOutput > getManagedMemory ()
 Memory manager accessor. More...
 
bool canTerminate () override
 Method called to test the task;s termination, by default, the test is: no input nodes connected and, no data waiting to be treated. More...
 
- Public Member Functions inherited from hh::behavior::Node
virtual std::string extraPrintingInformation () const
 Adds node information to print in the dot file. More...
 
- Public Member Functions inherited from hh::behavior::Execute< TaskInputs >
virtual void execute (std::shared_ptr< TaskInputs >)=0
 Virtual declaration of execute function for a data of type Input.
 

Private Attributes

std::shared_ptr< core::CoreTask< TaskOutput, TaskInputs... > > taskCore_ = nullptr
 Task Core.
 
std::shared_ptr< AbstractMemoryManager< TaskOutput > > mm_ = nullptr
 Task's memory manager.
 

Additional Inherited Members

- Public Types inherited from hh::behavior::MultiReceivers< TaskInputs... >
using inputs_t = std::tuple< Inputs... >
 Tuple with the list of input types.
 
- Public Types inherited from hh::behavior::Sender< TaskOutput >
using output_t = TaskOutput
 Output Type.
 

Detailed Description

template<class TaskOutput, class ... TaskInputs>
class hh::AbstractTask< TaskOutput, TaskInputs >

Base node for computation.

Hedgehog Graph's node made for holding a computation kernel into their execute overload method from Execute::execute.

An AbstractTask can be bound to multiple threads, forming a cluster of tasks. The base AbstractTask will be copied n times and each of them will be bound to a thread. The AbstractTask::copy method must be overloaded to use this functionality. Also, if the AbstractTask is part of Graph that will be duplicated with an AbstractExecutionPipeline, AbstractTask::copy method needs to be overloaded.

An AbstractMemoryManager could be linked to a task through a graph (from tutorial 4, example shows Cuda memory usage):

auto productTask = std::make_shared<CudaProductTask<MatrixType>>(p, numberThreadProduct);
auto cudaMemoryManagerA = std::make_shared<CudaMemoryManager<MatrixType, 'a'>>(nBlocks + 4, blockSize);
productTask->connectMemoryManager(cudaMemoryManagerProduct);

Linking an AbstractMemoryManager requires that the AbstractTask's TaskOutput match the template type of the AbstractMemoryManager

The default order of execution is:

  1. The cluster is created, for each task:
  2. The thread is spawned,
  3. The AbstractTask::initialize is called,
  4. The memory manager, if it exists, is bound to the task (the device Id is shared, and is initialized),
  5. Execute is called, while AbstractTask::canTerminate is True:
    • If the task is set to start automatically Execute::execute is called with nullptr,
    • If not, the task will wait for a data to come and Execute::execute is called with the received data,
  6. AbstractTask::shutdown is called, and is signal to the linked nodes.

Only Execute::execute method need to be overloaded for every AbstractTask input types.

Virtual functions
Execute::execute (one for each of TaskInputs)
AbstractTask::initialize
AbstractTask::shutdown
AbstractTask::copy (mandatory if usage of clusters or AbstractExecutionPipeline)
Node::canTerminate (mandatory if cycle in the graph)
Node::extraPrintingInformation
Attention
In case of cycle in the graph AbstractTask::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
TaskOutputOutput task data type.
TaskInputsInputs task data type.

Definition at line 76 of file abstract_task.h.

Constructor & Destructor Documentation

◆ AbstractTask() [1/6]

template<class TaskOutput, class ... TaskInputs>
hh::AbstractTask< TaskOutput, TaskInputs >::AbstractTask ( )
inline

AbstractTask default constructor.

Create a task with the name "Task", one task in the cluster (no copy overload needed), and no automatic start.

Definition at line 92 of file abstract_task.h.

◆ AbstractTask() [2/6]

template<class TaskOutput, class ... TaskInputs>
hh::AbstractTask< TaskOutput, TaskInputs >::AbstractTask ( std::string_view const &  name)
inlineexplicit

Create a task with a custom name.

Create a task with one task in the cluster (no copy overload needed), and no automatic start.

Parameters
nameTask name

Definition at line 103 of file abstract_task.h.

◆ AbstractTask() [3/6]

template<class TaskOutput, class ... TaskInputs>
hh::AbstractTask< TaskOutput, TaskInputs >::AbstractTask ( std::string_view const &  name,
size_t  numberThreads 
)
inlineexplicit

Create a task with a custom name and the task's cluster size.

Parameters
nameTask name
numberThreadsTask's cluster size

Definition at line 111 of file abstract_task.h.

◆ AbstractTask() [4/6]

template<class TaskOutput, class ... TaskInputs>
hh::AbstractTask< TaskOutput, TaskInputs >::AbstractTask ( std::string_view const &  name,
size_t  numberThreads,
bool  automaticStart 
)
inlineexplicit

Create a task with a custom name, the task's cluster size, and the automatic start.

Parameters
nameTask name
numberThreadsTask's cluster size
automaticStartTask's automatic start

Definition at line 124 of file abstract_task.h.

◆ AbstractTask() [5/6]

template<class TaskOutput, class ... TaskInputs>
hh::AbstractTask< TaskOutput, TaskInputs >::AbstractTask ( std::string_view const  name,
size_t  numberThreads,
core::NodeType  nodeType,
bool  automaticStart 
)
inline

Internal constructor needed to create nodes that derive from AbstractTask.

Attention
Do not use
Parameters
nameTask name
numberThreadsTask's cluster size
nodeTypeTask node type
automaticStartTask's automatic start

Definition at line 136 of file abstract_task.h.

◆ AbstractTask() [6/6]

template<class TaskOutput, class ... TaskInputs>
hh::AbstractTask< TaskOutput, TaskInputs >::AbstractTask ( AbstractTask< TaskOutput, TaskInputs ... > *  rhs)
inlineexplicit

Copy constructor.

Parameters
rhsTask to copy

Definition at line 143 of file abstract_task.h.

Member Function Documentation

◆ addResult()

template<class TaskOutput, class ... TaskInputs>
void hh::AbstractTask< TaskOutput, TaskInputs >::addResult ( std::shared_ptr< TaskOutput >  output)
inline

Add an output data.

Parameters
outputData to send to the output nodes

Definition at line 157 of file abstract_task.h.

◆ automaticStart()

template<class TaskOutput, class ... TaskInputs>
bool hh::AbstractTask< TaskOutput, TaskInputs >::automaticStart ( )
inline

Task's automatic start accessor.

Returns
Task automatic start property

Definition at line 169 of file abstract_task.h.

Here is the caller graph for this function:

◆ canTerminate()

template<class TaskOutput, class ... TaskInputs>
bool hh::AbstractTask< TaskOutput, TaskInputs >::canTerminate ( )
inlineoverridevirtual

Method called to test the task;s termination, by default, the test is: no input nodes connected and, no data waiting to be treated.

Returns
True if the task can be terminated, else False

Reimplemented from hh::behavior::Node.

Definition at line 236 of file abstract_task.h.

◆ connectMemoryManager()

template<class TaskOutput, class ... TaskInputs>
void hh::AbstractTask< TaskOutput, TaskInputs >::connectMemoryManager ( std::shared_ptr< AbstractMemoryManager< TaskOutput >>  mm)
inline

Connect a memory manager to the task.

Parameters
mmMemory manager to connect

Definition at line 203 of file abstract_task.h.

◆ copy()

template<class TaskOutput, class ... TaskInputs>
virtual std::shared_ptr<AbstractTask<TaskOutput, TaskInputs...> > hh::AbstractTask< TaskOutput, TaskInputs >::copy ( )
inlinevirtual

Default copy overload, fail if cluster need to be copied.

Returns
A copy of the current AbstractTask

Reimplemented in hh::StateManager< StateOutput, StateInputs >.

Definition at line 193 of file abstract_task.h.

Here is the caller graph for this function:

◆ core()

template<class TaskOutput, class ... TaskInputs>
std::shared_ptr<core::CoreNode> hh::AbstractTask< TaskOutput, TaskInputs >::core ( )
inlinefinalvirtual

Task's core accessor.

Returns
Task's core

Implements hh::behavior::Node.

Definition at line 185 of file abstract_task.h.

Here is the caller graph for this function:

◆ deviceId()

template<class TaskOutput, class ... TaskInputs>
int hh::AbstractTask< TaskOutput, TaskInputs >::deviceId ( )
inline

Task's device ID accessor.

Returns
Task's device ID

Definition at line 177 of file abstract_task.h.

◆ getManagedMemory()

template<class TaskOutput, class ... TaskInputs>
std::shared_ptr<TaskOutput> hh::AbstractTask< TaskOutput, TaskInputs >::getManagedMemory ( )
inline

Memory manager accessor.

Returns
Connected memory manager

Definition at line 212 of file abstract_task.h.

◆ graphId()

template<class TaskOutput, class ... TaskInputs>
int hh::AbstractTask< TaskOutput, TaskInputs >::graphId ( )
inline

Task's graph ID accessor.

Returns
Task's graph ID

Definition at line 181 of file abstract_task.h.

◆ memoryManager()

template<class TaskOutput, class ... TaskInputs>
std::shared_ptr<AbstractMemoryManager<TaskOutput> > const& hh::AbstractTask< TaskOutput, TaskInputs >::memoryManager ( ) const
inline

Task's memory manager accessor.

Returns
Task's memory manager

Definition at line 189 of file abstract_task.h.

Here is the caller graph for this function:

◆ name()

template<class TaskOutput, class ... TaskInputs>
std::string_view hh::AbstractTask< TaskOutput, TaskInputs >::name ( )
inline

Task's name accessor.

Returns
Task name

Definition at line 161 of file abstract_task.h.

Here is the caller graph for this function:

◆ nodeType()

template<class TaskOutput, class ... TaskInputs>
core::NodeType hh::AbstractTask< TaskOutput, TaskInputs >::nodeType ( )
inline

Task's node type accessor.

Returns
Task's node type property

Definition at line 173 of file abstract_task.h.

Here is the caller graph for this function:

◆ numberThreads()

template<class TaskOutput, class ... TaskInputs>
size_t hh::AbstractTask< TaskOutput, TaskInputs >::numberThreads ( )
inline

Task's number of threads accessor.

Returns
Task number of threads

Definition at line 165 of file abstract_task.h.

Here is the caller graph for this function:

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