Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
hh::StaticMemoryManager< T, Args > Class Template Reference

Static memory manager. More...

#include "static_memory_manager.h"

Inheritance diagram for hh::StaticMemoryManager< T, Args >:
Inheritance graph
Collaboration diagram for hh::StaticMemoryManager< T, Args >:
Collaboration graph

Public Member Functions

 StaticMemoryManager (size_t const &capacity, Args ... args)
 Constructor to a static memory manager.
 
 StaticMemoryManager (StaticMemoryManager< T, Args... > const &rhs)
 Copy constructor.
 
 ~StaticMemoryManager () override=default
 Default destructor.
 
std::shared_ptr< ManagedMemorygetManagedMemory () final
 Get a managed memory from the pool.
 
std::shared_ptr< AbstractMemoryManagercopy () override
 Default copy method.
 
virtual void initializeMemoryManager ()
 User-definable initialization step for a memory manager.
 
- Public Member Functions inherited from hh::AbstractMemoryManager
 AbstractMemoryManager (size_t const &capacity)
 Only used constructor.
 
virtual ~AbstractMemoryManager ()=default
 Default destructor.
 
int deviceId () const
 Device Id accessor.
 
size_t currentSize ()
 Return the current size of the inside pool.
 
size_t capacity () const
 Capacity accessor.
 
void deviceId (int deviceId)
 Device id setter.
 
void profiler (const std::shared_ptr< NvtxProfiler > &profiler)
 NVTX profiler setter.
 
virtual std::shared_ptr< ManagedMemorygetManagedMemory ()=0
 Get an available managed memory, block if none are available.
 
virtual void recycleMemory (std::shared_ptr< ManagedMemory > const &managedMemory)=0
 Recycle memory.
 
virtual std::shared_ptr< AbstractMemoryManagercopy ()=0
 Virtual copy method used for task duplication and execution pipeline.
 
virtual void initialize ()=0
 Initialize the memory manager.
 
virtual std::string managedType () const =0
 Return the real managed type under the form of a string.
 

Private Member Functions

void recycleMemory (std::shared_ptr< ManagedMemory > const &managedMemory) final
 Recycling mechanism for managed memory.
 
void initialize () final
 Initialize the memory manager.
 
template<size_t... Is>
void initialize (std::index_sequence< Is... >)
 Initialize implementation using the tuple of arguments stored.
 
std::string managedType () const final
 Getter to real managed type as string.
 

Private Attributes

std::tuple< Args... > args_ = {}
 Values to pass to the constructor.
 

Additional Inherited Members

- Protected Member Functions inherited from hh::AbstractMemoryManager
std::shared_ptr< NvtxProfiler > const & profiler () const
 Accessor to NVTX profiler.
 
std::unique_ptr< tool::Pool< ManagedMemory > > const & pool () const
 Inside pool accessor.
 
bool isInitialized () const
 Initialized flag accessor.
 
std::mutex & memoryManagerMutex ()
 User api mutex accessor.
 
void initialized ()
 Flag the memory manager has initialized.
 
- Protected Attributes inherited from hh::AbstractMemoryManager
std::mutex memoryManagerMutex_ = {}
 Mutex for user interface.
 

Detailed Description

template<class T, class ... Args>
class hh::StaticMemoryManager< T, Args >

Static memory manager.

Static Memory manager with custom created managed object. The type T managed has to present a constructor with a signature that matches exactly the template argument list Args...

Template Parameters
TType managed
ArgsList of types that should match the constructor of T parameters

Definition at line 38 of file static_memory_manager.h.

Constructor & Destructor Documentation

◆ StaticMemoryManager() [1/2]

template<class T , class ... Args>
hh::StaticMemoryManager< T, Args >::StaticMemoryManager ( size_t const &  capacity,
Args ...  args 
)
inlineexplicit

Constructor to a static memory manager.

Construct a static memory manager from its capacity, and the arguments used to construct all elements in the pool.

Parameters
capacityMemory manager capacity
argsArguments used to construct every elements in the pool

Definition at line 49 of file static_memory_manager.h.

◆ StaticMemoryManager() [2/2]

template<class T , class ... Args>
hh::StaticMemoryManager< T, Args >::StaticMemoryManager ( StaticMemoryManager< T, Args... > const &  rhs)
inline

Copy constructor.

Parameters
rhsStaticMemoryManager to construct from

Definition at line 54 of file static_memory_manager.h.

◆ ~StaticMemoryManager()

template<class T , class ... Args>
hh::StaticMemoryManager< T, Args >::~StaticMemoryManager ( )
overridedefault

Default destructor.

Member Function Documentation

◆ copy()

template<class T , class ... Args>
std::shared_ptr< AbstractMemoryManager > hh::StaticMemoryManager< T, Args >::copy ( )
inlineoverridevirtual

Default copy method.

Attention
Need to be overloaded by the end user if the memory manager is inherited
Returns
Create another MemoryManager from this

Implements hh::AbstractMemoryManager.

Definition at line 74 of file static_memory_manager.h.

◆ getManagedMemory()

template<class T , class ... Args>
std::shared_ptr< ManagedMemory > hh::StaticMemoryManager< T, Args >::getManagedMemory ( )
inlinefinalvirtual

Get a managed memory from the pool.

Get a managed memory from the pool. If the pool is empty, the call will block until a new element get available.

Returns
A managed memory

Implements hh::AbstractMemoryManager.

Definition at line 64 of file static_memory_manager.h.

Here is the call graph for this function:

◆ initialize() [1/2]

template<class T , class ... Args>
void hh::StaticMemoryManager< T, Args >::initialize ( )
inlinefinalprivatevirtual

Initialize the memory manager.

Thread safe initialization, fill the pool with custom constructed object

Implements hh::AbstractMemoryManager.

Definition at line 100 of file static_memory_manager.h.

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

◆ initialize() [2/2]

template<class T , class ... Args>
template<size_t... Is>
void hh::StaticMemoryManager< T, Args >::initialize ( std::index_sequence< Is... >  )
inlineprivate

Initialize implementation using the tuple of arguments stored.

Template Parameters
IsIndex of the arguments tuple

Definition at line 113 of file static_memory_manager.h.

Here is the call graph for this function:

◆ initializeMemoryManager()

template<class T , class ... Args>
virtual void hh::StaticMemoryManager< T, Args >::initializeMemoryManager ( )
inlinevirtual

User-definable initialization step for a memory manager.

Definition at line 79 of file static_memory_manager.h.

Here is the caller graph for this function:

◆ managedType()

template<class T , class ... Args>
std::string hh::StaticMemoryManager< T, Args >::managedType ( ) const
inlinefinalprivatevirtual

Getter to real managed type as string.

Returns
String of the real managed type

Implements hh::AbstractMemoryManager.

Definition at line 125 of file static_memory_manager.h.

◆ recycleMemory()

template<class T , class ... Args>
void hh::StaticMemoryManager< T, Args >::recycleMemory ( std::shared_ptr< ManagedMemory > const &  managedMemory)
inlinefinalprivatevirtual

Recycling mechanism for managed memory.

Thread safe recycle that will in sequence:

Implements hh::AbstractMemoryManager.

Definition at line 88 of file static_memory_manager.h.

Here is the call graph for this function:

Member Data Documentation

◆ args_

template<class T , class ... Args>
std::tuple<Args...> hh::StaticMemoryManager< T, Args >::args_ = {}
private

Values to pass to the constructor.

Definition at line 42 of file static_memory_manager.h.