MagmaDNN  1.0
c++NeuralNetworkFramework
magmadnn::MemoryManager< T > Class Template Reference

Public Member Functions

 MemoryManager (unsigned int size, memory_t mem_type, device_t device_id)
 
 MemoryManager (const MemoryManager &that)
 
MemoryManageroperator= (const MemoryManager &that)
 
 ~MemoryManager ()
 
magmadnn_error_t copy_from (const MemoryManager< T > &src, unsigned int begin_idx, unsigned int size)
 
magmadnn_error_t copy_from (const MemoryManager< T > &src, unsigned int size)
 
magmadnn_error_t copy_from (const MemoryManager< T > &src)
 
magmadnn_error_t copy_from_host (T *src, unsigned int begin_idx, unsigned int size)
 
magmadnn_error_t sync (bool gpu_was_modified=true)
 
magmadnn_error_t set_device (device_t device_id)
 
get (unsigned int idx) const
 
void set (unsigned int idx, T val)
 
T * get_host_ptr ()
 
T * get_ptr ()
 
unsigned int get_size () const
 
memory_t get_memory_type () const
 

Constructor & Destructor Documentation

◆ MemoryManager() [1/2]

template<typename T >
magmadnn::MemoryManager< T >::MemoryManager ( unsigned int  size,
memory_t  mem_type,
device_t  device_id 
)

MemoryManager class to keep track of a memory address across devices.

Parameters
sizethe size of the memory to allocate/manage
mem_typewhat memory type will this data belong to
device_idwhat device will the data reside on (preferred if mem_type is CUDA_MANAGED)
Here is the call graph for this function:

◆ MemoryManager() [2/2]

template<typename T >
magmadnn::MemoryManager< T >::MemoryManager ( const MemoryManager< T > &  that)

Copy Constructor

Parameters
that
Here is the call graph for this function:

◆ ~MemoryManager()

template<typename T >
magmadnn::MemoryManager< T >::~MemoryManager< T > ( )

Destroys the memory manager object and releases all its data.

Member Function Documentation

◆ copy_from() [1/3]

template<typename T >
magmadnn_error_t magmadnn::MemoryManager< T >::copy_from ( const MemoryManager< T > &  src,
unsigned int  begin_idx,
unsigned int  size 
)

Copies the data from src memory manager into the pointer here. Asserts that src and this have the same size.

Parameters
srcthe memorymanager to copy data from
Returns
the error code (0 - no error, 1 - src ptr not allocated)
Here is the caller graph for this function:

◆ copy_from() [2/3]

template<typename T >
magmadnn_error_t magmadnn::MemoryManager< T >::copy_from ( const MemoryManager< T > &  src,
unsigned int  size 
)

Copies the data from src memory manager into the pointer here. Asserts that src and this have the same size.

Parameters
srcthe memorymanager to copy data from
Returns
the error code (0 - no error, 1 - src ptr not allocated)
Here is the call graph for this function:

◆ copy_from() [3/3]

template<typename T >
magmadnn_error_t magmadnn::MemoryManager< T >::copy_from ( const MemoryManager< T > &  src)

Copies the data from src memory manager into the pointer here. Asserts that src and this have the same size.

Parameters
srcthe memorymanager to copy data from
Returns
the error code (0 - no error, 1 - src ptr not allocated)
Here is the call graph for this function:

◆ copy_from_host()

template<typename T >
magmadnn_error_t magmadnn::MemoryManager< T >::copy_from_host ( T *  src,
unsigned int  begin_idx,
unsigned int  size 
)

copies memory from a host ptr into this memorymanager. will throw an error if it reaches the end of src allocated mem before this is filled.

Parameters
srcthe array to copy into this.
Returns
the error code (0 - good, 1 - not enough memory)

◆ get()

template<typename T >
T magmadnn::MemoryManager< T >::get ( unsigned int  idx) const

Returns the value at idx. Error if idx is out of range.

Parameters
idxindex to retrieve
Returns
the value at index idx.

◆ get_host_ptr()

template<typename T >
T * magmadnn::MemoryManager< T >::get_host_ptr ( )

returns a CPU pointer to the data.

Returns
cpu pointer

◆ get_memory_type()

template<typename T>
memory_t magmadnn::MemoryManager< T >::get_memory_type ( ) const
inline

Returns the memory type of this memory manager.

Returns
memory_t

◆ get_ptr()

template<typename T >
T * magmadnn::MemoryManager< T >::get_ptr ( )

Returns a pointer to whatever memory type this is using. For MANAGED memory type it returns the device pointer.

Returns
the data ptr

◆ get_size()

template<typename T>
unsigned int magmadnn::MemoryManager< T >::get_size ( ) const
inline

Returns the size of this memorymanager

Returns
unsigned int the size of this memory manager

◆ operator=()

template<typename T >
MemoryManager< T > & magmadnn::MemoryManager< T >::operator= ( const MemoryManager< T > &  that)

Copy assignment operator.

Parameters
that
Returns
MemoryManager&
Here is the call graph for this function:

◆ set()

template<typename T >
void magmadnn::MemoryManager< T >::set ( unsigned int  idx,
val 
)

Sets the value at idx to val. Error if idx is out of range.

Parameters
idxindex to set
valvalue to set at idx

◆ set_device()

template<typename T >
magmadnn_error_t magmadnn::MemoryManager< T >::set_device ( device_t  device_id)

Changes the device this memory manager points to. Note that the memory type is still the same, but the device_id will be different.

Returns
an error code (0 - ok)
Here is the caller graph for this function:

◆ sync()

template<typename T >
magmadnn_error_t magmadnn::MemoryManager< T >::sync ( bool  gpu_was_modified = true)

If MANAGED or CUDA_MANAGED this ensures that data is the same on all devices. It will wait for any gpu kernels to finish before copying data. If HOST or DEVICE memory this does nothing.

Parameters
gpu_was_modifiedIf true then data will be copied from gpu to cpu, else if false vice-versa. By default true.
Returns
an error code

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