HTGS  v2.0
The Hybrid Task Graph Scheduler
htgs::MemoryData< T > Class Template Reference

Describes memory allocated by a MemoryManager to manage shared memory across multiple ITask. More...

#include <htgs/api/MemoryData.hpp>

Inheritance diagram for htgs::MemoryData< T >:
Inheritance graph
Collaboration diagram for htgs::MemoryData< T >:
Collaboration graph

Public Member Functions

 MemoryData (std::shared_ptr< IMemoryAllocator< T >> allocator, std::weak_ptr< Connector< MemoryData< T >>> memoryManagerConnector, std::string memoryManagerName, MMType type)
 Creates MemoryData with the specified IMemoryAllocator. More...
 
 ~MemoryData ()
 Destructor that releases IMemoryAllocator memory.
 
void releaseMemory ()
 Gets the address of the memory manager that allocated this memory data. More...
 
void setPipelineId (size_t id)
 Sets the pipelineId associated with the MemoryManager that allocated the memory. More...
 
size_t getPipelineId () const
 Gets the pipelineId associated with the MemoryManager that allocated the memory. More...
 
size_t getSize () const
 Gets the size of the memory that was allocated. More...
 
void setMemoryReleaseRule (IMemoryReleaseRule *rule)
 Sets the memory release rule. More...
 
IMemoryReleaseRulegetMemoryReleaseRule () const
 Gets the memory release rule associated with the memory data. More...
 
bool canReleaseMemory ()
 Checks whether the memory can be recycled/released by the MemoryManager. More...
 
void memoryUsed ()
 Updates the state of the memory when it is received by the MemoryManager. More...
 
void memAlloc ()
 Allocates the memory that this MemoryData is using. More...
 
T * get ()
 Gets the memory that this MemoryData is managing. More...
 
const T & get (size_t idx) const
 Gets the data that is held by this memory data at the specified index. More...
 
T & get (size_t idx)
 Gets the data that is held by this memory data at the specified index. More...
 
const T & operator[] (size_t idx) const
 Gets the value for memory at index. More...
 
T & operator[] (size_t idx)
 Gets the value for memory at index. More...
 
void memFree ()
 Frees the memory that this MemoryData is managing. More...
 
MMType getType () const
 Gets the type of memory that is associated with the memory manager. More...
 
MemoryData< T > * copy ()
 Creates a copy of this MemoryData. More...
 
void memAlloc (size_t size)
 Allocates the memory that this memory data is managed with the specified size. More...
 
const std::string & getMemoryManagerName () const
 Gets the memory manager name. More...
 
- Public Member Functions inherited from htgs::IData
 IData ()
 Constructs an IData with default ordering = 0.
 
 IData (size_t order)
 Constructs IData with integer ordering. More...
 
virtual ~IData ()
 Destructor.
 
bool operator() (const std::shared_ptr< IData > p1, const std::shared_ptr< IData > p2) const
 Compares two IData pointers for ordering. More...
 
virtual bool compare (const std::shared_ptr< IData > p2) const
 Virtual IData comparison function, can be used for custom ordering. More...
 
size_t getOrder () const
 Gets the order of this IData. More...
 

Private Attributes

MMType type
 The type of memory manager.
 
std::string memoryManagerName
 The name of the memory manager that allocated the memory.
 
std::weak_ptr< Connector< MemoryData< T > > > memoryManagerConnector
 The pointer to the connector that owns this memory.
 
size_t pipelineId
 The pipelineId associated with where this memory was managed.
 
T * memory
 The memory.
 
size_t size
 The size of the memory (in elements)
 
IMemoryReleaseRulememoryReleaseRule
 The memory release rule associated with the memory.
 
std::shared_ptr< IMemoryAllocator< T > > allocator
 The allocator associated with the memory.
 

Detailed Description

template<class T>
class htgs::MemoryData< T >

Describes memory allocated by a MemoryManager to manage shared memory across multiple ITask.

Provides mechanisms for allocation, freeing, and memory release strategies associated with memory. Using these mechanisms the MemoryManager can process the memory and recycle it only when the IMemoryReleaseRule indicates it is ready to be released.

In order to properly share this data, it should be forwarded along with other IData until the ITask responsible for releasing the data back to its MemoryManager is called.

To receive memory from the MemoryManager use ITask::getMemory. To send memory to the MemoryManager use ITask::releaseMemory

Use htgs::m_data_t<Type> from <htgs/types/Types.hpp> when handling MemoryData to reduce code size.

Example Usage:

ITask::executeTask(std::shared_ptr<Data1> data)
{
...
// Shared memory getter
// If you don't use m_data_t -> std::shared_ptr<htgs::MemoryData<int>>
htgs::m_data_t<int> readBuffer = this->memGet<int>("readMemory", new ReleaseCountRule(1));
readData(data->getFile(), readBuffer->get());
// Shared memory release example
this->releaseMemory("otherMemory", data->getMemory());
addResult(new Data2(readBuffer));
...
}

Example attaching MemoryManager:

taskGraph->addMemoryManagerEdge("readMemory", readTask, new ReadMemoryAllocator(), readMemoryPoolSize);
Template Parameters
Tthe type of memory to be held by the MemoryData, this will automatically be converted to a pointer type

Constructor & Destructor Documentation

◆ MemoryData()

template<class T>
htgs::MemoryData< T >::MemoryData ( std::shared_ptr< IMemoryAllocator< T >>  allocator,
std::weak_ptr< Connector< MemoryData< T >>>  memoryManagerConnector,
std::string  memoryManagerName,
MMType  type 
)
inline

Creates MemoryData with the specified IMemoryAllocator.

Parameters
allocatorthe memory allocator
memoryManagerConnectorthe pointer to the connector that owns this memory
memoryManagerNamethe name of the memory manager that allocated this memory
typethe type of the memory manager that allocated this memory

Member Function Documentation

◆ canReleaseMemory()

template<class T>
bool htgs::MemoryData< T >::canReleaseMemory ( )
inline

Checks whether the memory can be recycled/released by the MemoryManager.

Returns
whether the memory is ready to be recycled/released by the MemoryManager
Note
This function should only be called by the HTGS API

◆ copy()

template<class T>
MemoryData<T>* htgs::MemoryData< T >::copy ( )
inline

Creates a copy of this MemoryData.

Returns
the copy
Note
This function should only be called by the HTGS API

◆ get() [1/3]

template<class T>
T* htgs::MemoryData< T >::get ( )
inline

Gets the memory that this MemoryData is managing.

Returns
the memory attached to the MemoryData

◆ get() [2/3]

template<class T>
const T& htgs::MemoryData< T >::get ( size_t  idx) const
inline

Gets the data that is held by this memory data at the specified index.

Parameters
idxthe index
Returns
the data

◆ get() [3/3]

template<class T>
T& htgs::MemoryData< T >::get ( size_t  idx)
inline

Gets the data that is held by this memory data at the specified index.

Parameters
idxthe index
Returns
the data

◆ getMemoryManagerName()

template<class T>
const std::string& htgs::MemoryData< T >::getMemoryManagerName ( ) const
inline

Gets the memory manager name.

Returns
the memory manager name

◆ getMemoryReleaseRule()

template<class T>
IMemoryReleaseRule* htgs::MemoryData< T >::getMemoryReleaseRule ( ) const
inline

Gets the memory release rule associated with the memory data.

Returns
the memory release rule

◆ getPipelineId()

template<class T>
size_t htgs::MemoryData< T >::getPipelineId ( ) const
inline

Gets the pipelineId associated with the MemoryManager that allocated the memory.

Returns
the pipelineId

◆ getSize()

template<class T>
size_t htgs::MemoryData< T >::getSize ( ) const
inline

Gets the size of the memory that was allocated.

Returns
the memory size

◆ getType()

template<class T>
MMType htgs::MemoryData< T >::getType ( ) const
inline

Gets the type of memory that is associated with the memory manager.

Returns
the type of memory (either Dynamic or Static)

◆ memAlloc() [1/2]

template<class T>
void htgs::MemoryData< T >::memAlloc ( )
inline

Allocates the memory that this MemoryData is using.

Note
This function should only be called by the HTGS API

◆ memAlloc() [2/2]

template<class T>
void htgs::MemoryData< T >::memAlloc ( size_t  size)
inline

Allocates the memory that this memory data is managed with the specified size.

Parameters
sizethe number of elements to allocate

◆ memFree()

template<class T>
void htgs::MemoryData< T >::memFree ( )
inline

Frees the memory that this MemoryData is managing.

Note
This function should only be called by the HTGS API

◆ memoryUsed()

template<class T>
void htgs::MemoryData< T >::memoryUsed ( )
inline

Updates the state of the memory when it is received by the MemoryManager.

Note
This function should only be called by the HTGS API

◆ operator[]() [1/2]

template<class T>
const T& htgs::MemoryData< T >::operator[] ( size_t  idx) const
inline

Gets the value for memory at index.

Parameters
idxthe index
Returns
the value at index
Note
T must be a pointer to memory to use this functionality.

◆ operator[]() [2/2]

template<class T>
T& htgs::MemoryData< T >::operator[] ( size_t  idx)
inline

Gets the value for memory at index.

Parameters
idxthe index
Returns
the value at index
Note
T must be a pointer to memory to use this functionality.

◆ releaseMemory()

template<class T>
void htgs::MemoryData< T >::releaseMemory ( )
inline

Gets the address of the memory manager that allocated this memory data.

Returns
the address of the memory manager that allocated the memory data Releases the MemoryData and returns it to the htgs::MemoryManager that allocated it. The memory will be recycled based on the specified htgs::IMemoryReleaseRule.

◆ setMemoryReleaseRule()

template<class T>
void htgs::MemoryData< T >::setMemoryReleaseRule ( IMemoryReleaseRule rule)
inline

Sets the memory release rule.

Parameters
rulethe new rule that manages the memory

◆ setPipelineId()

template<class T>
void htgs::MemoryData< T >::setPipelineId ( size_t  id)
inline

Sets the pipelineId associated with the MemoryManager that allocated the memory.

Parameters
idthe pipielineId
Note
This function should only be called by the HTGS API

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