Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
hh::StaticMemoryManager< ManagedMemory, Args > Class Template Reference

Derived class from AbstractMemoryManager for statically allocated MemoryData, used for example for GPU computation to avoid synchronisation during dynamic allocation. More...

#include "static_memory_manager.h"

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

Classes

class  HasConstructor
 SFINAE construct to test if ManagedMemory has a constructor with Args... as parameter. More...
 

Public Member Functions

 StaticMemoryManager ()=delete
 Deleted default constructor.
 
 StaticMemoryManager (size_t const &capacity, Args ... args)
 Constructor to use defining the pool capacity and the arguments to give the type constructor. More...
 
 StaticMemoryManager (StaticMemoryManager< ManagedMemory, Args... > &rhs)
 Copy constructor used by the copy method. More...
 
void initialize () final
 Initialize method, calling the private initialize method with the pack arguments, and the user definable initializeMemoryManager.
 
std::shared_ptr< AbstractMemoryManager< ManagedMemory > > copy () override
 Copy method used for task duplication and execution pipeline. More...
 
- Public Member Functions inherited from hh::AbstractMemoryManager< ManagedMemory >
 AbstractMemoryManager ()=delete
 Deleted Default constructor.
 
 AbstractMemoryManager (size_t const &capacity)
 Only used constructor. More...
 
virtual ~AbstractMemoryManager ()=default
 Default destructor.
 
void deviceId (int deviceId)
 Device id setter. More...
 
void profiler (const std::shared_ptr< NvtxProfiler > &profiler)
 NVTX profiler setter. More...
 
size_t currentSize ()
 Return the current size of the inside pool. More...
 
std::shared_ptr< ManagedMemory > getManagedMemory ()
 Get an available managed memory, block if none are available. More...
 
void recycleMemory (std::shared_ptr< MemoryData< ManagedMemory >> managedMemory)
 Recycle memory. More...
 
virtual void initializeMemoryManager ()
 User-definable initialization step for a memory manager.
 

Private Member Functions

template<size_t... Is>
void initialize (std::index_sequence< Is... >)
 Private initialize method to call a specific constructor for the type. More...
 

Private Attributes

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

Additional Inherited Members

- Protected Member Functions inherited from hh::AbstractMemoryManager< ManagedMemory >
int deviceId () const
 Device Id accessor. More...
 
std::unique_ptr< behavior::Pool< ManagedMemory > > const & pool () const
 Inside pool accessor. More...
 
size_t capacity () const
 Capacity accessor. More...
 
bool isInitialized () const
 Initialized flag accessor. More...
 
std::mutex & memoryManagerMutex ()
 User api mutex accessor. More...
 
void initialized ()
 Flag the memory manager has initialized.
 
- Protected Attributes inherited from hh::AbstractMemoryManager< ManagedMemory >
std::mutex memoryManagerMutex_
 Mutex for user interface.
 

Detailed Description

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

Derived class from AbstractMemoryManager for statically allocated MemoryData, used for example for GPU computation to avoid synchronisation during dynamic allocation.

The main difference between the AbstractMemoryManager and the StaticMemoryManager, is the allocation process. Instead of filling the pool with default constructed data, the data will be constructed with a specific constructor. In order to select the constructor, the parameter's type(s) of the constructor that will be used as part of the template list of the StaticMemoryManager. For example, we can build a class A as:

class A : public MemoryData<A>{
A(){/*[...]*/}; // Default constructor
A(int, float){/*[...]*/}; // Int, float constructor
A(int, float, double){/*[...]*/}; // Int, float, double constructor
~A() { ... } // Free/delete memory allocated in constructors
};

So the memory manager

StaticMemoryManager<A> smm(10);

will fill a pool with 10 A, calling the constructor:

A(){/*[...]*/}; // Default constructor

The memory manager

StaticMemoryManager<A, int, float> smm(12, 42, 6.5);

will fill a pool with 12 A, calling the constructor:

A(int, float){/*[...]*/}; // Int, float constructor

with 42 (int) and 6.5 (float) as values. So the memory manager

StaticMemoryManager<A, int, float, double> smm(0, 42, 6.5, 3.14159);

will fill a pool with 1 A (a pool can not be empty), calling the constructor:

A(int, float, double){/*[...]*/}; // Int, float, double constructor

with 42 (int), 6.5 (float), 3.14159 (double) as values.

Attention
Memory that is allocated from a user-defined MemoryData's constructor should be deallocated within its destructor. The destructor will be called when all references to its std::shared_ptr have been lost. The MemoryData::recycle should be used only if user-defined allocation occurs outside of the constructor.

Because the static memory manager is made to be used "as is", a copy method has been implemented using the copy constructor. So if the StaticMemoryManager needs to be derived, use the copy constructor of the StaticMemoryManager to transfer mandatory attributes to the copy.

Virtual Functions
AbstractMemoryManager::initializeMemoryManager
Template Parameters
ManagedMemoryType to be managed by the memory manager
ArgsList of types corresponding to the constructor list of types

Definition at line 83 of file static_memory_manager.h.

Constructor & Destructor Documentation

◆ StaticMemoryManager() [1/2]

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

Constructor to use defining the pool capacity and the arguments to give the type constructor.

Parameters
capacityPool capacity
argsList of arguments to give the type constructor

Definition at line 120 of file static_memory_manager.h.

◆ StaticMemoryManager() [2/2]

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

Copy constructor used by the copy method.

Parameters
rhsStaticMemoryManager to copy

Definition at line 126 of file static_memory_manager.h.

Member Function Documentation

◆ copy()

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

Copy method used for task duplication and execution pipeline.

Returns
The copy of the current (this) StaticMemoryManager

Reimplemented from hh::AbstractMemoryManager< ManagedMemory >.

Definition at line 142 of file static_memory_manager.h.

◆ initialize()

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

Private initialize method to call a specific constructor for the type.

Template Parameters
IsIndex sequence to iterate over the args

Definition at line 150 of file static_memory_manager.h.

Here is the call graph for this function:

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