Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
hh::AbstractMemoryManager Class Referenceabstract

Abstract Memory manager. More...

#include "abstract_memory_manager.h"

Inheritance diagram for hh::AbstractMemoryManager:
Inheritance graph
Collaboration diagram for hh::AbstractMemoryManager:
Collaboration graph

Public Member Functions

 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.
 

Protected Member Functions

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

std::mutex memoryManagerMutex_ = {}
 Mutex for user interface.
 

Private Attributes

int deviceId_ = 0
 Device Id of linked task.
 
bool initialized_ = false
 Flag to determine if AbstractMemoryManager has been initialized.
 
std::unique_ptr< tool::Pool< ManagedMemory > > pool_ = {}
 Inside pool to store the data.
 
std::shared_ptr< NvtxProfilerprofiler_ = nullptr
 NVTX profiler instance to follow memory manager state.
 

Detailed Description

Abstract Memory manager.

Present a thread safe pool of Managed memory

Definition at line 41 of file abstract_memory_manager.h.

Constructor & Destructor Documentation

◆ AbstractMemoryManager()

hh::AbstractMemoryManager::AbstractMemoryManager ( size_t const &  capacity)
inlineexplicit

Only used constructor.

Parameters
capacityMemory Manager capacity, number of elements available, set to 1 if 0

Definition at line 53 of file abstract_memory_manager.h.

◆ ~AbstractMemoryManager()

virtual hh::AbstractMemoryManager::~AbstractMemoryManager ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ capacity()

size_t hh::AbstractMemoryManager::capacity ( ) const
inline

Capacity accessor.

Returns
Pool's capacity

Definition at line 76 of file abstract_memory_manager.h.

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

◆ copy()

virtual std::shared_ptr< AbstractMemoryManager > hh::AbstractMemoryManager::copy ( )
pure virtual

Virtual copy method used for task duplication and execution pipeline.

Returns
Return a copy of this specialised AbstractMemoryManager

Implemented in hh::MemoryManager< T >, and hh::StaticMemoryManager< T, Args >.

◆ currentSize()

size_t hh::AbstractMemoryManager::currentSize ( )
inline

Return the current size of the inside pool.

Lock the api user mutex before getting the current size of the inside pool

Returns
The current number of available data

Definition at line 67 of file abstract_memory_manager.h.

Here is the call graph for this function:

◆ deviceId() [1/2]

int hh::AbstractMemoryManager::deviceId ( ) const
inline

Device Id accessor.

Returns
Device id

Definition at line 62 of file abstract_memory_manager.h.

◆ deviceId() [2/2]

void hh::AbstractMemoryManager::deviceId ( int  deviceId)
inline

Device id setter.

Parameters
deviceIdTask's device id to set

Definition at line 82 of file abstract_memory_manager.h.

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

◆ getManagedMemory()

virtual std::shared_ptr< ManagedMemory > hh::AbstractMemoryManager::getManagedMemory ( )
pure virtual

Get an available managed memory, block if none are available.

Returns
An available managed memory

Implemented in hh::MemoryManager< T >, and hh::StaticMemoryManager< T, Args >.

◆ initialize()

virtual void hh::AbstractMemoryManager::initialize ( )
pure virtual

Initialize the memory manager.

Lock the user api mutex, fill the pool with default constructed data, and call initializeMemoryManager()

Implemented in hh::MemoryManager< T >, and hh::StaticMemoryManager< T, Args >.

◆ initialized()

void hh::AbstractMemoryManager::initialized ( )
inlineprotected

Flag the memory manager has initialized.

Definition at line 130 of file abstract_memory_manager.h.

Here is the caller graph for this function:

◆ isInitialized()

bool hh::AbstractMemoryManager::isInitialized ( ) const
inlineprotected

Initialized flag accessor.

Returns
True is the memory manager has been initialized, else False

Definition at line 123 of file abstract_memory_manager.h.

Here is the caller graph for this function:

◆ managedType()

virtual std::string hh::AbstractMemoryManager::managedType ( ) const
pure virtual

Return the real managed type under the form of a string.

Returns
Real managed type under the form of a string

Implemented in hh::MemoryManager< T >, and hh::StaticMemoryManager< T, Args >.

◆ memoryManagerMutex()

std::mutex & hh::AbstractMemoryManager::memoryManagerMutex ( )
inlineprotected

User api mutex accessor.

Returns
User api mutex

Definition at line 127 of file abstract_memory_manager.h.

◆ pool()

std::unique_ptr< tool::Pool< ManagedMemory > > const & hh::AbstractMemoryManager::pool ( ) const
inlineprotected

Inside pool accessor.

Returns
Inside pool

Definition at line 119 of file abstract_memory_manager.h.

Here is the caller graph for this function:

◆ profiler() [1/2]

std::shared_ptr< NvtxProfiler > const & hh::AbstractMemoryManager::profiler ( ) const
inlineprotected

Accessor to NVTX profiler.

Returns
Attached NVTX profiler

Definition at line 113 of file abstract_memory_manager.h.

Here is the caller graph for this function:

◆ profiler() [2/2]

void hh::AbstractMemoryManager::profiler ( const std::shared_ptr< NvtxProfiler > &  profiler)
inline

NVTX profiler setter.

Parameters
profilerNVTX profiler to set

Definition at line 86 of file abstract_memory_manager.h.

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

◆ recycleMemory()

virtual void hh::AbstractMemoryManager::recycleMemory ( std::shared_ptr< ManagedMemory > const &  managedMemory)
pure virtual

Recycle memory.

Lock the user api mutex before call used(), canBeRecycled() and if true, clean() and push it back into the pool

Parameters
managedMemoryData to clean

Implemented in hh::MemoryManager< T >, and hh::StaticMemoryManager< T, Args >.

Here is the caller graph for this function:

Member Data Documentation

◆ deviceId_

int hh::AbstractMemoryManager::deviceId_ = 0
private

Device Id of linked task.

Definition at line 43 of file abstract_memory_manager.h.

◆ initialized_

bool hh::AbstractMemoryManager::initialized_ = false
private

Flag to determine if AbstractMemoryManager has been initialized.

Definition at line 44 of file abstract_memory_manager.h.

◆ memoryManagerMutex_

std::mutex hh::AbstractMemoryManager::memoryManagerMutex_ = {}
protected

Mutex for user interface.

Definition at line 48 of file abstract_memory_manager.h.

◆ pool_

std::unique_ptr<tool::Pool<ManagedMemory> > hh::AbstractMemoryManager::pool_ = {}
private

Inside pool to store the data.

Definition at line 45 of file abstract_memory_manager.h.

◆ profiler_

std::shared_ptr<NvtxProfiler> hh::AbstractMemoryManager::profiler_ = nullptr
private

NVTX profiler instance to follow memory manager state.

Definition at line 46 of file abstract_memory_manager.h.