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

Abstract Task specialized for CUDA computation. More...

#include "abstract_cuda_task.h"

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

Public Member Functions

 AbstractCUDATask (std::string const &name, size_t numberThreads, bool enablePeerAccess, bool automaticStart=false)
 AbstractCUDATask full constructor.
 
 AbstractCUDATask (std::string const name="CudaTask", size_t numberThreads=1)
 Main constructor for a AbstractCUDATask.
 
 AbstractCUDATask (std::shared_ptr< hh::core::CoreTask< Separator, AllTypes... > > coreTask, bool enablePeerAccess)
 Custom core task constructor.
 
 ~AbstractCUDATask () override
 Default destructor.
 
void initialize () final
 Initialize an AbstractCUDATask to bind 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.
 
cudaStream_t stream () const
 Getter for CUDA task's stream.
 
bool hasPeerAccess (int peerDeviceId)
 Accessor for peer access enabled for a specific device id.
 
- Public Member Functions inherited from hh::AbstractTask< Separator, AllTypes... >
 AbstractTask ()
 Default constructor (Task with one thread named "Task")
 
 AbstractTask (std::string const &name, size_t const numberThreads=1, bool const automaticStart=false)
 AbstractTask main constructor.
 
 AbstractTask (std::shared_ptr< hh::core::CoreTask< Separator, AllTypes... > > coreTask)
 Construct a task from a user-defined core.
 
 ~AbstractTask () override=default
 Default task destructor.
 
size_t graphId () const
 Belonging graph id accessor.
 
bool canTerminate () const override
 Default termination rule, it terminates if there is no predecessor connection and there is no input data.
 
- 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< AbstractTask< 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< AbstractTask< Separator, AllTypes... > const * > group () const
 Get the group of nodes that hold the current nodes.
 
virtual std::shared_ptr< AbstractTask< 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

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

- Protected Member Functions inherited from hh::AbstractTask< Separator, AllTypes... >
std::shared_ptr< hh::core::CoreTask< Separator, AllTypes... > > const & coreTask () const
 Accessor to the core task.
 
int deviceId ()
 Accessor to device id linked to the task (default 0 for CPU task)
 

Detailed Description

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

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
SeparatorSeparator position between input types and output types
AllTypesList of input and output types

Definition at line 46 of file abstract_cuda_task.h.

Constructor & Destructor Documentation

◆ AbstractCUDATask() [1/3]

template<size_t Separator, class ... AllTypes>
hh::AbstractCUDATask< Separator, AllTypes >::AbstractCUDATask ( std::string const &  name,
size_t  numberThreads,
bool  enablePeerAccess,
bool  automaticStart = false 
)
inline

AbstractCUDATask full constructor.

Parameters
nameTask name
numberThreadsNumber of threads for the task
enablePeerAccessEnable peer access for NVIDIA GPUs
automaticStartFlag for automatic start (Cf. AbstractTask)

Definition at line 58 of file abstract_cuda_task.h.

Here is the call graph for this function:

◆ AbstractCUDATask() [2/3]

template<size_t Separator, class ... AllTypes>
hh::AbstractCUDATask< Separator, AllTypes >::AbstractCUDATask ( std::string const  name = "CudaTask",
size_t  numberThreads = 1 
)
inlineexplicit

Main constructor for a AbstractCUDATask.

Parameters
nameName of the AbstractCUDATask
numberThreadsNumber of thread for this task (default 1)

Definition at line 68 of file abstract_cuda_task.h.

◆ AbstractCUDATask() [3/3]

template<size_t Separator, class ... AllTypes>
hh::AbstractCUDATask< Separator, AllTypes >::AbstractCUDATask ( std::shared_ptr< hh::core::CoreTask< Separator, AllTypes... > >  coreTask,
bool  enablePeerAccess 
)
inline

Custom core task constructor.

Parameters
coreTaskCustom core to use
enablePeerAccessEnable per access for NVIDIA GPUs

Definition at line 74 of file abstract_cuda_task.h.

Here is the call graph for this function:

◆ ~AbstractCUDATask()

template<size_t Separator, class ... AllTypes>
hh::AbstractCUDATask< Separator, AllTypes >::~AbstractCUDATask ( )
inlineoverride

Default destructor.

Definition at line 82 of file abstract_cuda_task.h.

Here is the call graph for this function:

Member Function Documentation

◆ enablePeerAccess()

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

Accessor for peer access choice.

Returns
True if peer access is enabled, else False

Definition at line 136 of file abstract_cuda_task.h.

◆ hasPeerAccess()

template<size_t Separator, class ... AllTypes>
bool hh::AbstractCUDATask< Separator, AllTypes >::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 145 of file abstract_cuda_task.h.

◆ initialize()

template<size_t Separator, class ... AllTypes>
void hh::AbstractCUDATask< Separator, AllTypes >::initialize ( )
inlinefinalvirtual

Initialize an AbstractCUDATask to bind it to a CUDA device, and do the peer access if enabled. At the end will call AbstractCUDATask::initializeCuda.

Reimplemented from hh::behavior::TaskNode.

Definition at line 90 of file abstract_cuda_task.h.

Here is the call graph for this function:

◆ initializeCuda()

template<size_t Separator, class ... AllTypes>
virtual void hh::AbstractCUDATask< Separator, AllTypes >::initializeCuda ( )
inlinevirtual

Virtual initialization step, where user defined data structure can be initialized.

Definition at line 129 of file abstract_cuda_task.h.

Here is the caller graph for this function:

◆ shutdown()

template<size_t Separator, class ... AllTypes>
void hh::AbstractCUDATask< Separator, AllTypes >::shutdown ( )
inlinefinalvirtual

Shutdown an AbstractCUDATask to destroy the task's CUDA stream created during AbstractCUDATask::initialize. First calls AbstractCUDATask::shutdownCuda.

Reimplemented from hh::behavior::TaskNode.

Definition at line 123 of file abstract_cuda_task.h.

Here is the call graph for this function:

◆ shutdownCuda()

template<size_t Separator, class ... AllTypes>
virtual void hh::AbstractCUDATask< Separator, AllTypes >::shutdownCuda ( )
inlinevirtual

Virtual shutdown step, where user defined data structure can be destroyed.

Definition at line 132 of file abstract_cuda_task.h.

Here is the caller graph for this function:

◆ stream()

template<size_t Separator, class ... AllTypes>
cudaStream_t hh::AbstractCUDATask< Separator, AllTypes >::stream ( ) const
inline

Getter for CUDA task's stream.

Returns
CUDA stream

Definition at line 140 of file abstract_cuda_task.h.

Member Data Documentation

◆ enablePeerAccess_

template<size_t Separator, class ... AllTypes>
bool hh::AbstractCUDATask< Separator, AllTypes >::enablePeerAccess_ = false
private

Enable CUDA Peer Access through all CUDA devices available.

Definition at line 48 of file abstract_cuda_task.h.

◆ peerDeviceIds_

template<size_t Separator, class ... AllTypes>
std::unordered_set<int> hh::AbstractCUDATask< Separator, AllTypes >::peerDeviceIds_ = {}
private

Sparse matrix of linked CUDA devices.

Definition at line 49 of file abstract_cuda_task.h.

◆ stream_

template<size_t Separator, class ... AllTypes>
cudaStream_t hh::AbstractCUDATask< Separator, AllTypes >::stream_ = {}
private

CUDA stream linked to the task.

Definition at line 50 of file abstract_cuda_task.h.