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

Abstract Task specialized for CUDA computation. More...

#include "abstract_cuda_task.h"

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

Public Member Functions

 AbstractCUDATask (size_t numberThreads=1)
 Default constructor for an AbstractCUDATask. More...
 
 AbstractCUDATask (std::string_view const &name, size_t numberThreads=1)
 Constructor for an AbstractCUDATask with name as mandatory parameter and the number of threads as optional parameter. More...
 
 AbstractCUDATask (std::string_view const &name, size_t numberThreads, bool automaticStart, bool enablePeerAccess)
 Constructor for an AbstractCUDATask with name, number of threads, automaticStart and enablePeerAccess as mandatory parameter. More...
 
void initialize () final
 Initialize an AbstractCUDATask to bound it to a CUDA device, and do the peer access if enabled. At the end will call AbstractCUDATask::initializeCuda.
 
void shutdown () final
 Shutdown an AbstractCUDATask to destroy the task's CUDA stream created during AbstractCUDATask::initialize. First calls AbstractCUDATask::shutdownCuda.
 
virtual void initializeCuda ()
 Virtual initialization step, where user defined data structure can be initialized.
 
virtual void shutdownCuda ()
 Virtual shutdown step, where user defined data structure can be destroyed.
 
bool enablePeerAccess () const
 Accessor for peer access choice. More...
 
cudaStream_t stream () const
 Getter for CUDA task's stream. More...
 
bool hasPeerAccess (int peerDeviceId)
 Accessor for peer access enabled for a specific device id. More...
 
- Public Member Functions inherited from hh::AbstractTask< TaskOutput, TaskInputs... >
 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...
 
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

bool enablePeerAccess_ = false
 Enable CUDA Peer Access through all CUDA devices available.
 
std::unordered_set< intpeerDeviceIds_ = {}
 Sparse matrix of linked CUDA devices.
 
cudaStream_t stream_ = {}
 CUDA stream linked to the task.
 

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::AbstractCUDATask< TaskOutput, TaskInputs >

Abstract Task specialized for CUDA computation.

At initialization, the device is set to the task (cudaSetDevice), and a stream is created and bound to the task (cudaStreamCreate). During shutdown, the stream is destroyed (cudaStreamDestroy).

Virtual functions
Execute::execute (one for each of TaskInputs)
AbstractCUDATask::copy (only used if number of threads is greater than 1 or used in an ExecutionPipeline)
AbstractCUDATask::initializeCuda
AbstractCUDATask::shutdownCuda
Node::canTerminate
Node::extraPrintingInformation
Template Parameters
TaskOutputTask output type
TaskInputsTask input types

Definition at line 78 of file abstract_cuda_task.h.

Constructor & Destructor Documentation

◆ AbstractCUDATask() [1/3]

template<class TaskOutput , class ... TaskInputs>
hh::AbstractCUDATask< TaskOutput, TaskInputs >::AbstractCUDATask ( size_t  numberThreads = 1)
inlineexplicit

Default constructor for an AbstractCUDATask.

Default constructor with as optional parameter numberThread set to 1. The default name set is "CudaTask", the task won't start automatically, and the peer access is enable.

Parameters
numberThreadsTask's number of threads

Definition at line 92 of file abstract_cuda_task.h.

Here is the call graph for this function:

◆ AbstractCUDATask() [2/3]

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

Constructor for an AbstractCUDATask with name as mandatory parameter and the number of threads as optional parameter.

The task won't start automatically, and the peer access is enable.

Parameters
nameTask's name
numberThreadsTask's number of threads

Definition at line 103 of file abstract_cuda_task.h.

Here is the call graph for this function:

◆ AbstractCUDATask() [3/3]

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

Constructor for an AbstractCUDATask with name, number of threads, automaticStart and enablePeerAccess as mandatory parameter.

Parameters
nameTask's name
numberThreadsTask's number of threads
automaticStartTask's automatic start
enablePeerAccessPeer access enabling

Definition at line 115 of file abstract_cuda_task.h.

Here is the call graph for this function:

Member Function Documentation

◆ enablePeerAccess()

template<class TaskOutput , class ... TaskInputs>
bool hh::AbstractCUDATask< TaskOutput, TaskInputs >::enablePeerAccess ( ) const
inline

Accessor for peer access choice.

Returns
True if peer access is enabled, else False

Definition at line 169 of file abstract_cuda_task.h.

◆ hasPeerAccess()

template<class TaskOutput , class ... TaskInputs>
bool hh::AbstractCUDATask< TaskOutput, TaskInputs >::hasPeerAccess ( int  peerDeviceId)
inline

Accessor for peer access enabled for a specific device id.

Parameters
peerDeviceIdDevice id to test
Returns
True if peer access enable for device id peerDeviceId, else False

Definition at line 178 of file abstract_cuda_task.h.

◆ stream()

template<class TaskOutput , class ... TaskInputs>
cudaStream_t hh::AbstractCUDATask< TaskOutput, TaskInputs >::stream ( ) const
inline

Getter for CUDA task's stream.

Returns
CUDA stream

Definition at line 173 of file abstract_cuda_task.h.


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