OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
HeapMemory Class Reference

This class allocate, and destroy CPU memory. More...

Detailed Description

This class allocate, and destroy CPU memory.

Allocate memory

Resize memory

Shrink memory

Definition at line 39 of file HeapMemory.hpp.

#include <HeapMemory.hpp>

+ Inheritance diagram for HeapMemory:

Public Member Functions

bool copyDeviceToDevice (const HeapMemory &m)
 copy from same Heap to Heap
 
virtual bool flush ()
 flush the memory
 
virtual bool allocate (size_t sz)
 allocate memory
 
virtual void destroy ()
 destroy memory
 
virtual bool copy (const memory &m)
 copy memory
 
virtual size_t size () const
 the the size of the allocated memory
 
virtual bool resize (size_t sz)
 resize the memory allocated
 
virtual void * getPointer ()
 get a readable pointer with the data
 
virtual const void * getPointer () const
 get a readable pointer with the data
 
virtual void * getDevicePointer ()
 get a device pointer for HeapMemory getPointer and getDevicePointer are equivalents
 
virtual void fill (unsigned char c)
 fill host and device memory with the selected byte
 
virtual void hostToDevice ()
 Do nothing.
 
virtual void deviceToHost ()
 Do nothing.
 
virtual void deviceToHost (size_t start, size_t stop)
 Do nothing.
 
virtual void hostToDevice (size_t start, size_t stop)
 Do nothing.
 
virtual void incRef ()
 Increment the reference counter.
 
virtual void decRef ()
 Decrement the reference counter.
 
virtual long int ref ()
 Return the reference counter.
 
bool isInitialized ()
 Allocated Memory is never initialized.
 
HeapMemoryoperator= (const HeapMemory &mem)
 
 HeapMemory (const HeapMemory &mem)
 
 HeapMemory (HeapMemory &&mem) noexcept
 
 HeapMemory ()
 Constructor, we choose a default alignment of 32 for avx.
 
void swap (HeapMemory &mem)
 Swap the memory.
 
- Public Member Functions inherited from memory
virtual ~memory ()
 destructor
 

Static Public Member Functions

static constexpr bool isDeviceHostSame ()
 Return true if the device and the host pointer are the same.
 

Private Member Functions

bool copyFromPointer (const void *ptr, size_t sz)
 copy from Pointer to Heap
 
void setAlignment (size_t align)
 Set alignment the memory will be aligned with this number.
 

Private Attributes

size_t alignement
 memory alignment
 
size_t sz
 Size of the memory.
 
byte * dm
 device memory
 
byte * dmOrig
 original pointer (before alignment)
 
long int ref_cnt
 Reference counter.
 

Constructor & Destructor Documentation

◆ HeapMemory() [1/3]

HeapMemory::HeapMemory ( const HeapMemory mem)
inline

Definition at line 136 of file HeapMemory.hpp.

◆ HeapMemory() [2/3]

HeapMemory::HeapMemory ( HeapMemory &&  mem)
inlinenoexcept

move

Definition at line 143 of file HeapMemory.hpp.

◆ HeapMemory() [3/3]

HeapMemory::HeapMemory ( )
inline

Constructor, we choose a default alignment of 32 for avx.

Definition at line 160 of file HeapMemory.hpp.

◆ ~HeapMemory()

virtual HeapMemory::~HeapMemory ( )
inlinevirtualnoexcept

Definition at line 162 of file HeapMemory.hpp.

Member Function Documentation

◆ allocate()

bool HeapMemory::allocate ( size_t  sz)
virtual

allocate memory

Allocate a chunk of memory.

Parameters
szsize of the chunk of memory to allocate in byte

Allocate the device memory

Implements memory.

Definition at line 33 of file HeapMemory.cpp.

◆ copy()

bool HeapMemory::copy ( const memory m)
virtual

copy memory

copy the memory

Parameters
ma memory interface

Here we try to cast memory into HeapMemory

if we fail we get the pointer and simply copy from the pointer

Implements memory.

Definition at line 123 of file HeapMemory.cpp.

◆ copyDeviceToDevice()

bool HeapMemory::copyDeviceToDevice ( const HeapMemory m)

copy from same Heap to Heap

copy from device to device

copy a piece of memory from device to device

Parameters
mfrom where to copy

The source buffer is too big to copy it

Definition at line 103 of file HeapMemory.cpp.

◆ copyFromPointer()

bool HeapMemory::copyFromPointer ( const void *  ptr,
size_t  sz 
)
private

copy from Pointer to Heap

copy the data from a pointer

Parameters
ptr

Definition at line 89 of file HeapMemory.cpp.

◆ decRef()

virtual void HeapMemory::decRef ( )
inlinevirtual

Decrement the reference counter.

Implements memory.

Definition at line 109 of file HeapMemory.hpp.

◆ destroy()

void HeapMemory::destroy ( )
virtual

destroy memory

Destroy the internal memory.

Implements memory.

Definition at line 73 of file HeapMemory.cpp.

◆ deviceToHost() [1/2]

virtual void HeapMemory::deviceToHost ( )
inlinevirtual

Do nothing.

Implements memory.

Definition at line 96 of file HeapMemory.hpp.

◆ deviceToHost() [2/2]

virtual void HeapMemory::deviceToHost ( size_t  start,
size_t  stop 
)
inlinevirtual

Do nothing.

Implements memory.

Definition at line 99 of file HeapMemory.hpp.

◆ fill()

void HeapMemory::fill ( unsigned char  c)
virtual

fill host and device memory with the selected byte

Parameters
byteto fill

Implements memory.

Definition at line 22 of file HeapMemory.cpp.

◆ flush()

virtual bool HeapMemory::flush ( )
inlinevirtual

flush the memory

Implements memory.

Definition at line 66 of file HeapMemory.hpp.

◆ getDevicePointer()

void * HeapMemory::getDevicePointer ( )
virtual

get a device pointer for HeapMemory getPointer and getDevicePointer are equivalents

Return a readable pointer with your data.

Return a readable pointer with your data

Implements memory.

Definition at line 218 of file HeapMemory.cpp.

◆ getPointer() [1/2]

void * HeapMemory::getPointer ( )
virtual

get a readable pointer with the data

Return a readable pointer with your data.

Return a readable pointer with your data

Implements memory.

Definition at line 228 of file HeapMemory.cpp.

◆ getPointer() [2/2]

const void * HeapMemory::getPointer ( ) const
virtual

get a readable pointer with the data

Return a readable pointer with your data.

Return a readable pointer with your data

Implements memory.

Definition at line 239 of file HeapMemory.cpp.

◆ hostToDevice() [1/2]

virtual void HeapMemory::hostToDevice ( )
inlinevirtual

Do nothing.

Implements memory.

Definition at line 93 of file HeapMemory.hpp.

◆ hostToDevice() [2/2]

virtual void HeapMemory::hostToDevice ( size_t  start,
size_t  stop 
)
inlinevirtual

Do nothing.

Implements memory.

Definition at line 102 of file HeapMemory.hpp.

◆ incRef()

virtual void HeapMemory::incRef ( )
inlinevirtual

Increment the reference counter.

Implements memory.

Definition at line 105 of file HeapMemory.hpp.

◆ isDeviceHostSame()

static constexpr bool HeapMemory::isDeviceHostSame ( )
inlinestaticconstexpr

Return true if the device and the host pointer are the same.

Returns
true if they are the same

Definition at line 207 of file HeapMemory.hpp.

◆ isInitialized()

bool HeapMemory::isInitialized ( )
inlinevirtual

Allocated Memory is never initialized.

Returns
false

Implements memory.

Definition at line 123 of file HeapMemory.hpp.

◆ operator=()

HeapMemory & HeapMemory::operator= ( const HeapMemory mem)
inline

Definition at line 129 of file HeapMemory.hpp.

◆ ref()

virtual long int HeapMemory::ref ( )
inlinevirtual

Return the reference counter.

Implements memory.

Definition at line 113 of file HeapMemory.hpp.

◆ resize()

bool HeapMemory::resize ( size_t  sz)
virtual

resize the memory allocated

Resize the allocated memory.

Resize the allocated memory, if request is smaller than the allocated memory is not resized

Parameters
szsize
Returns
true if the resize operation complete correctly

Allocate the device memory if not done yet

Create a new buffer if sz is bigger than the actual size

size plus alignment

align it

copy from the old buffer to the new one

free the old buffer

change to the new buffer

Implements memory.

Definition at line 167 of file HeapMemory.cpp.

◆ setAlignment()

void HeapMemory::setAlignment ( size_t  align)
private

Set alignment the memory will be aligned with this number.

set the memory block to be aligned by this number

Definition at line 64 of file HeapMemory.cpp.

◆ size()

size_t HeapMemory::size ( ) const
virtual

the the size of the allocated memory

Get the size of the allocated memory.

Get the size of the allocated memory

Returns
the size of the allocated memory

Implements memory.

Definition at line 153 of file HeapMemory.cpp.

◆ swap()

void HeapMemory::swap ( HeapMemory mem)
inline

Swap the memory.

Parameters
memmemory to swap

Definition at line 175 of file HeapMemory.hpp.

Field Documentation

◆ alignement

size_t HeapMemory::alignement
private

memory alignment

Definition at line 42 of file HeapMemory.hpp.

◆ dm

byte* HeapMemory::dm
private

device memory

Definition at line 48 of file HeapMemory.hpp.

◆ dmOrig

byte* HeapMemory::dmOrig
private

original pointer (before alignment)

Definition at line 50 of file HeapMemory.hpp.

◆ ref_cnt

long int HeapMemory::ref_cnt
private

Reference counter.

Definition at line 52 of file HeapMemory.hpp.

◆ sz

size_t HeapMemory::sz
private

Size of the memory.

Definition at line 45 of file HeapMemory.hpp.


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