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

Processes MemoryData between two ITasks using a memory pool. More...

#include <htgs/core/memory/MemoryManager.hpp>

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

Public Member Functions

 MemoryManager (std::string name, size_t memoryPoolSize, std::shared_ptr< IMemoryAllocator< T >> memoryAllocator, MMType type)
 Creates the MemoryManager with the specified memory pool size and allocator. More...
 
 ~MemoryManager () override
 Destructor.
 
void initialize () override
 Initializes the MemoryManager, getting the size of the memory pool, and filling the memory pool with allocated data. More...
 
void shutdown () override
 Shuts down the MemoryManager memory is only released when the underlying graph destructs the memory manager.
 
void executeTask (std::shared_ptr< MemoryData< T >> data) override
 Processes memory data. More...
 
void debug () override
 Provides debug output for MemoryManager.
 
virtual std::string getName () override
 Gets the name of the MemoryManager. More...
 
virtual MemoryManager< T > * copy () override
 Creates a shallow copy of the MemoryManager. More...
 
virtual size_t getMemoryPoolSize ()
 Virtual function to gets the size of the MemoryPool. More...
 
virtual std::shared_ptr< IMemoryAllocator< T > > getAllocator ()
 Gets the allocator that is responsible for allocating and freeing memory for the MemoryPool. More...
 
std::string getMemoryManagerName ()
 Gets the name of the memory manager. More...
 
std::string typeName ()
 Gets the demangled type name of the connector. More...
 
MMType getType () const
 Gets the memory manager type. More...
 
virtual std::string genDot (int flags, std::string dotId, std::shared_ptr< AnyConnector > input, std::shared_ptr< AnyConnector > output) override
 Virtual function that generates the input/output and per-task dot notation. More...
 
std::string getDotFillColor () override
 Gets the color for filling the shape for graphviz dot. More...
 
- Public Member Functions inherited from htgs::ITask< MemoryData< T >, MemoryData< T > >
 ITask ()
 Creates an ITask with number of threads equal to 1.
 
 ITask (size_t numThreads)
 Constructs an ITask with a specified number of threads. More...
 
 ITask (size_t numThreads, bool isStartTask, bool poll, size_t microTimeoutTime)
 Constructs an ITask with a specified number of threads as well as additional scheduling options. More...
 
void initialize (size_t pipelineId, size_t numPipeline, TaskManager< MemoryData< T >, MemoryData< T > > *ownerTask)
 Function that is called when an ITask is being initialized by it's owner thread. More...
 
virtual void executeTask (std::shared_ptr< MemoryData< T > > data)=0
 Pure virtual function that is called when an ITask's thread is to execute on data. More...
 
virtual bool canTerminate (std::shared_ptr< AnyConnector > inputConnector) override
 
virtual void executeTaskFinal () override
 
virtual std::string getDotLabelName () override
 
virtual std::string getDotShapeColor () override
 
virtual std::string getDotShape () override
 
virtual std::string getDotCustomProfile () override
 Adds the string text to the profiling of this task in the graphviz dot visualization. More...
 
virtual void printProfile () override
 
virtual size_t getNumGraphsSpawned ()
 Gets the number of graphs spawned by this ITask. More...
 
virtual std::string genDotProducerEdgeToTask (std::map< std::shared_ptr< AnyConnector >, AnyITask * > &inputConnectorDotMap, int dotFlags) override
 
virtual std::string genDotConsumerEdgeFromConnector (std::shared_ptr< AnyConnector > connector, int flags) override
 
virtual std::string genDotProducerEdgeFromConnector (std::shared_ptr< AnyConnector > connector, int flags)
 
ITask< MemoryData< T >, MemoryData< T > > * copyITask (bool deep) override
 Copies the ITask (including a copy of all memory edges) More...
 
void addResult (std::shared_ptr< MemoryData< T > > result)
 Adds results to the output list to be sent to the next connected ITask in a TaskGraph. More...
 
void addResult (MemoryData< T > *result)
 Adds results to the output list to be sent to the next connected ITask in a TaskGraph. More...
 
m_data_t< V > getMemory (std::string name, IMemoryReleaseRule *releaseRule)
 Retrieves memory from a memory edge. More...
 
m_data_t< V > getDynamicMemory (std::string name, IMemoryReleaseRule *releaseRule, size_t numElems)
 Retrieves memory from a memory edge. More...
 
void releaseMemory (m_data_t< V > memory)
 Releases memory onto a memory edge, which is transferred by the graph communicator. More...
 
void resetProfile ()
 Resets profile data.
 
size_t getThreadID ()
 Gets the thread ID associated with this task. More...
 
unsigned long long int getTaskComputeTime () const
 Gets the task's compute time. More...
 
std::string inTypeName () override final
 
std::string outTypeName () override final
 
std::string getAddress () override final
 
void setTaskManager (TaskManager< MemoryData< T >, MemoryData< T > > *ownerTask)
 Sets the owner task manager for this ITask. More...
 
TaskManager< MemoryData< T >, MemoryData< T > > * getOwnerTaskManager ()
 Gets the owner task manager for this ITask. More...
 
virtual void gatherProfileData (std::map< AnyTaskManager *, TaskManagerProfile * > *taskManagerProfiles)
 Gathers profile data. More...
 
- Public Member Functions inherited from htgs::AnyITask
 AnyITask ()
 Creates an ITask with number of threads equal to 1.
 
 AnyITask (size_t numThreads)
 Constructs an ITask with a specified number of threads. More...
 
 AnyITask (size_t numThreads, bool isStartTask, bool poll, size_t microTimeoutTime)
 Constructs an ITask with a specified number of threads as well as additional scheduling options. More...
 
virtual ~AnyITask ()
 Destructor.
 
virtual std::string genDot (int flags, std::string dotId, std::shared_ptr< htgs::AnyConnector > input, std::shared_ptr< htgs::AnyConnector > output)
 Virtual function that generates the input/output and per-task dot notation. More...
 
virtual std::string getConsumerDotIds ()
 
virtual std::string getProducerDotIds ()
 
virtual std::string genDot (int flags, std::string dotId)
 Virtual function that adds additional dot attributes to this node. More...
 
virtual std::string genCustomDot (ProfileUtils *profileUtils, int colorFlag)
 Virtual function to generate customized dot file. More...
 
virtual std::string debugDotNode ()
 Provides debug output for a node in the dot graph. More...
 
virtual void profile ()
 Virtual function that is called to provide profile output for the ITask. More...
 
virtual std::string profileStr ()
 Virtual function that is called after executionTask is called. More...
 
void initialize (size_t pipelineId, size_t numPipeline)
 Virtual function that is called when an ITask is being initialized by it's owner thread. More...
 
void setPipelineId (size_t pipelineId)
 Sets the pipeline Id for this ITask. More...
 
size_t getPipelineId ()
 Gets the pipeline ID. More...
 
void setNumPipelines (size_t numPipelines)
 Sets the number of pipelines that this ITask belongs too. More...
 
size_t getNumPipelines () const
 Sets the task graph communicator. More...
 
size_t getNumThreads () const
 Gets the number of threads associated with this ITask. More...
 
bool isStartTask () const
 Gets whether this ITask is a starting task. More...
 
bool isPoll () const
 Gets whether this ITask is polling for data or not. More...
 
size_t getMicroTimeoutTime () const
 Gets the timeout time for polling. More...
 
void copyMemoryEdges (AnyITask *iTaskCopy)
 Copies the memory edges from this AnyITask to another AnyITask. More...
 
std::string genDot (int flags, std::shared_ptr< AnyConnector > input, std::shared_ptr< AnyConnector > output)
 Creates a dot notation representation for this task. More...
 
void profileITask ()
 Provides profile output for the ITask,. More...
 
std::string getDotId ()
 Gets the id used for dot nodes. More...
 
std::string getNameWithPipelineId ()
 Gets the name of the ITask with it's pipeline ID. More...
 
const std::shared_ptr< ConnectorMap > & getMemoryEdges () const
 Gets the memory edges for the task. More...
 
const std::shared_ptr< ConnectorMap > & getReleaseMemoryEdges () const
 Gets the memory edges for releasing memory for the memory manager, used to shutdown the memory manager. More...
 
bool hasMemoryEdge (std::string name)
 Checks whether this ITask contains a memory edge for a specified name. More...
 
void attachMemoryEdge (std::string name, std::shared_ptr< AnyConnector > getMemoryConnector, std::shared_ptr< AnyConnector > releaseMemoryConnector, MMType type)
 Attaches a memory edge to this ITask to get memory. More...
 
unsigned long long int getMemoryWaitTime () const
 Gets the amount of time the task was waiting for memory. More...
 
void incMemoryWaitTime (unsigned long long int val)
 Increments memory wait time. More...
 

Private Attributes

std::shared_ptr< IMemoryAllocator< T > > allocator
 The allocator used for allocating and freeing memory.
 
size_t memoryPoolSize
 The size of the memory pool.
 
MemoryPool< T > * pool
 The memory pool.
 
std::string name
 The name of the memory manager.
 
MMType type
 The memory manager type.
 

Detailed Description

template<class T>
class htgs::MemoryManager< T >

Processes MemoryData between two ITasks using a memory pool.

The memory pool is allocated using the IMemoryAllocator interface. As soon as data is available in the pool, it is pushed to the ITask associated with the memory.

The memoryPoolSize should be large enough to process the algorithm based on the release rules added to the MemoryData when an ITask gets memory from a memory manager. These release rules should be satisfied by the traversal of data that is specific to an algorithm and system memory capacity requirements.

There are two types of memory managers: (1) Static (2) Dynamic

Static memory managers allocate memory at initialization, and free memory using the destructor.

Dynamic memory managers do not allocate memory. Memory allocation is moved to the ITask. Memory returned from an ITask will be freed when the IMemoryRelease rule indicates the memory is ready to be released.

Template Parameters
Tthe input/output MemoryData type for the MemoryManager; i.e., double *

Constructor & Destructor Documentation

◆ MemoryManager()

template<class T>
htgs::MemoryManager< T >::MemoryManager ( std::string  name,
size_t  memoryPoolSize,
std::shared_ptr< IMemoryAllocator< T >>  memoryAllocator,
MMType  type 
)
inline

Creates the MemoryManager with the specified memory pool size and allocator.

Specifies 1 thread and that it should immediately start executing as soon as a thread is bound to it.

Parameters
namethe name of the memory manager edge
memoryPoolSizethe size of the memory pool.
memoryAllocatorthe allocator for how the memory pool allocates the memory.
typethe type of memory manager to create

Member Function Documentation

◆ copy()

template<class T>
virtual MemoryManager<T>* htgs::MemoryManager< T >::copy ( )
inlineoverridevirtual

Creates a shallow copy of the MemoryManager.

Does not copy the contents of the MemoryPool.

Returns
the shallow copy of the MemoryManager

Implements htgs::ITask< MemoryData< T >, MemoryData< T > >.

Reimplemented in htgs::CudaMemoryManager< T >.

◆ executeTask()

template<class T>
void htgs::MemoryManager< T >::executeTask ( std::shared_ptr< MemoryData< T >>  data)
inlineoverride

Processes memory data.

When data enters the MemoryManager, if the data is nullptr, then it will add all data to its output edge. If the data is not nullptr, then the MemoryData::memoryUsed() is called to update the state of the memory and checks if the memory can be recycled back into the memory pool with MemoryData::canReleaseMemory().

Parameters
datathe MemoryData being processed

◆ genDot()

template<class T>
virtual std::string htgs::MemoryManager< T >::genDot ( int  flags,
std::string  dotId,
std::shared_ptr< AnyConnector input,
std::shared_ptr< AnyConnector output 
)
inlineoverridevirtual

Virtual function that generates the input/output and per-task dot notation.

Parameters
flagsthe DOTGEN flags
dotIdthe id for this task
inputthe input connector for this task
outputthe output connector for this task
Returns
the dot that represents the interaction between the input/output and the internal custom dot notation
Note
This function will generate no dot notation if DOTGEN_FLAG_HIDE_MEM_EDGES is added to flags.

◆ getAllocator()

template<class T>
virtual std::shared_ptr<IMemoryAllocator<T> > htgs::MemoryManager< T >::getAllocator ( )
inlinevirtual

Gets the allocator that is responsible for allocating and freeing memory for the MemoryPool.

Returns
the allocator

◆ getDotFillColor()

template<class T>
std::string htgs::MemoryManager< T >::getDotFillColor ( )
inlineoverridevirtual

Gets the color for filling the shape for graphviz dot.

Returns
the fill color

Reimplemented from htgs::ITask< MemoryData< T >, MemoryData< T > >.

◆ getMemoryManagerName()

template<class T>
std::string htgs::MemoryManager< T >::getMemoryManagerName ( )
inline

Gets the name of the memory manager.

Will match the name of the memory edge that it is managing.

Returns
the name of the memory manager

◆ getMemoryPoolSize()

template<class T>
virtual size_t htgs::MemoryManager< T >::getMemoryPoolSize ( )
inlinevirtual

Virtual function to gets the size of the MemoryPool.

This can be overriden to provide custom memory pool sizes during initialization.

Returns

◆ getName()

template<class T>
virtual std::string htgs::MemoryManager< T >::getName ( )
inlineoverridevirtual

Gets the name of the MemoryManager.

Returns

Reimplemented from htgs::ITask< MemoryData< T >, MemoryData< T > >.

Reimplemented in htgs::CudaMemoryManager< T >.

◆ getType()

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

Gets the memory manager type.

Returns
the memory manager type.

◆ initialize()

template<class T>
void htgs::MemoryManager< T >::initialize ( )
inlineoverridevirtual

Initializes the MemoryManager, getting the size of the memory pool, and filling the memory pool with allocated data.

All the memory is allocated once a thread has been bound to ITask.

Reimplemented from htgs::ITask< MemoryData< T >, MemoryData< T > >.

◆ typeName()

template<class T>
std::string htgs::MemoryManager< T >::typeName ( )
inline

Gets the demangled type name of the connector.

Returns
the demangled type name

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