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

Detailed Description

Definition at line 58 of file CudaMemory.cuh.

+ Inheritance diagram for CudaMemory:

Public Member Functions

bool copyDeviceToDevice (const CudaMemory &m)
 copy from GPU to GPU buffer directly
 
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 from a General device
 
virtual size_t size () const
 the the size of the allocated memory
 
virtual bool resize (size_t sz)
 resize the momory 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 readable pointer with the data
 
virtual void hostToDevice ()
 Move memory from host to device.
 
virtual void deviceToHost ()
 Move memory from device to host.
 
virtual void deviceToHost (size_t start, size_t stop)
 Move memory from device to host, just the selected chunk.
 
virtual void hostToDevice (size_t start, size_t top)
 Move memory from host to device, just the selected chunk.
 
void hostToDevice (CudaMemory &mem)
 host to device using external memory (this host memory is copied into mem device memory)
 
void deviceToHost (CudaMemory &mem)
 device to host using external memory (this device memory is copied into mem host memory)
 
virtual void fill (unsigned char c)
 fill the buffer with a byte
 
void isNotSync ()
 
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.
 
CudaMemoryoperator= (const CudaMemory &mem)
 
 CudaMemory (const CudaMemory &mem)
 
 CudaMemory (CudaMemory &&mem) EXCEPT_MC
 
 CudaMemory ()
 Constructor.
 
 CudaMemory (size_t sz)
 Constructor.
 
 ~CudaMemory ()
 Destructor.
 
void deviceToDevice (void *ptr, size_t start, size_t stop, size_t offset)
 copy memory from device to device
 
void swap (CudaMemory &mem)
 Swap the memory.
 
void * toKernel ()
 return the device 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

void allocate_host (size_t sz) const
 Allocate an host buffer.
 
bool copyFromPointer (const void *ptr)
 copy from Pointer to GPU
 

Private Attributes

bool is_hm_sync
 Is the host memory synchronized with the GPU memory.
 
size_t sz
 Size of the memory.
 
void * dm
 device memory
 
void * hm
 host memory
 
size_t ref_cnt
 Reference counter.
 

Constructor & Destructor Documentation

◆ CudaMemory() [1/4]

CudaMemory::CudaMemory ( const CudaMemory mem)
inline

Definition at line 169 of file CudaMemory.cuh.

◆ CudaMemory() [2/4]

CudaMemory::CudaMemory ( CudaMemory &&  mem)
inline

Definition at line 176 of file CudaMemory.cuh.

◆ CudaMemory() [3/4]

CudaMemory::CudaMemory ( )
inline

Constructor.

Definition at line 193 of file CudaMemory.cuh.

◆ CudaMemory() [4/4]

CudaMemory::CudaMemory ( size_t  sz)
inline

Constructor.

Definition at line 196 of file CudaMemory.cuh.

◆ ~CudaMemory()

CudaMemory::~CudaMemory ( )
inline

Destructor.

Definition at line 202 of file CudaMemory.cuh.

Member Function Documentation

◆ allocate()

bool CudaMemory::allocate ( size_t  sz)
virtual

allocate memory

Allocate a chunk of 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 38 of file CudaMemory.cu.

◆ allocate_host()

void CudaMemory::allocate_host ( size_t  sz) const
private

Allocate an host buffer.

Allocate the host buffer.

Allocate the host buffer

Definition at line 133 of file CudaMemory.cu.

◆ copy()

bool CudaMemory::copy ( const memory m)
virtual

copy from a General device

copy from memory

copy from memory

Parameters
ma memory interface

Here we try to cast memory into OpenFPMwdeviceCudaMemory

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

Implements memory.

Definition at line 216 of file CudaMemory.cu.

◆ copyDeviceToDevice()

bool CudaMemory::copyDeviceToDevice ( const CudaMemory m)

copy from GPU to GPU buffer directly

copy from device to device

copy a piece of memory from device to device

Parameters
CudaMemoryfrom where to copy
Returns
true is success

The source buffer is too big to copy it

Copy the memory

Definition at line 187 of file CudaMemory.cu.

◆ copyFromPointer()

bool CudaMemory::copyFromPointer ( const void *  ptr)
private

copy from Pointer to GPU

copy the data from a pointer

copy the data from a pointer

Parameters
ptr
Returns
true if success

Definition at line 157 of file CudaMemory.cu.

◆ decRef()

virtual void CudaMemory::decRef ( )
inlinevirtual

Decrement the reference counter.

Implements memory.

Definition at line 142 of file CudaMemory.cuh.

◆ destroy()

void CudaMemory::destroy ( )
virtual

destroy memory

destroy a chunk of memory

Destroy a chunk of memory

Release the allocated memory

we invalidate hm

Implements memory.

Definition at line 80 of file CudaMemory.cu.

◆ deviceToDevice()

void CudaMemory::deviceToDevice ( void *  ptr,
size_t  start,
size_t  stop,
size_t  offset 
)

copy memory from device to device

Parameters
externaldevice pointer
startsource starting point (where it start to copy)
stopend point
offsetwhere to copy in the device pointer
Parameters
externaldevice pointer
startsource starting point (where it start to copy)
stopend point
offsetwhere to copy in the device pointer

Definition at line 119 of file CudaMemory.cu.

◆ deviceToHost() [1/3]

void CudaMemory::deviceToHost ( )
virtual

Move memory from device to host.

Return a readable pointer with your data.

Returns
a readable pointer with your data

copy from device to host memory

Implements memory.

Definition at line 369 of file CudaMemory.cu.

◆ deviceToHost() [2/3]

void CudaMemory::deviceToHost ( CudaMemory mem)

device to host using external memory (this device memory is copied into mem host memory)

It transfer to device memory from the host of another memory.

Parameters
memthe other memory object

copy from device to host memory

Definition at line 388 of file CudaMemory.cu.

◆ deviceToHost() [3/3]

void CudaMemory::deviceToHost ( size_t  start,
size_t  stop 
)
virtual

Move memory from device to host, just the selected chunk.

Return a readable pointer with your data.

Returns
a readable pointer with your data

copy from device to host memory

Implements memory.

Definition at line 450 of file CudaMemory.cu.

◆ fill()

void CudaMemory::fill ( unsigned char  c)
virtual

fill the buffer with a byte

fill host and device memory with the selected byte

Implements memory.

Definition at line 485 of file CudaMemory.cu.

◆ flush()

bool CudaMemory::flush ( )
virtual

flush the memory

Move the memory into device.

Returns
true if the memory is correctly flushed

copy from host to device memory

Implements memory.

Definition at line 15 of file CudaMemory.cu.

◆ getDevicePointer()

void * CudaMemory::getDevicePointer ( )
virtual

get a readable pointer with the data

Return the CUDA device pointer.

Returns
CUDA device pointer

Implements memory.

Definition at line 503 of file CudaMemory.cu.

◆ getPointer() [1/2]

void * CudaMemory::getPointer ( )
virtual

get a readable pointer with the data

Return a readable pointer with your data.

Returns
a readable pointer with your data

Implements memory.

Definition at line 354 of file CudaMemory.cu.

◆ getPointer() [2/2]

const void * CudaMemory::getPointer ( ) const
virtual

get a readable pointer with the data

Return a readable pointer with your data.

Returns
a readable pointer with your data

Implements memory.

Definition at line 472 of file CudaMemory.cu.

◆ hostToDevice() [1/3]

void CudaMemory::hostToDevice ( )
virtual

Move memory from host to device.

Return a readable pointer with your data.

Returns
a readable pointer with your data

copy from device to host memory

Implements memory.

Definition at line 514 of file CudaMemory.cu.

◆ hostToDevice() [2/3]

void CudaMemory::hostToDevice ( CudaMemory mem)

host to device using external memory (this host memory is copied into mem device memory)

It transfer to device memory from the host of another memory.

Parameters
memthe other memory object

copy from device to host memory

Definition at line 414 of file CudaMemory.cu.

◆ hostToDevice() [3/3]

void CudaMemory::hostToDevice ( size_t  start,
size_t  top 
)
virtual

Move memory from host to device, just the selected chunk.

copy from device to host memory

Implements memory.

Definition at line 431 of file CudaMemory.cu.

◆ incRef()

virtual void CudaMemory::incRef ( )
inlinevirtual

Increment the reference counter.

Implements memory.

Definition at line 136 of file CudaMemory.cuh.

◆ isDeviceHostSame()

static constexpr bool CudaMemory::isDeviceHostSame ( )
inlinestaticconstexpr

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

Returns
true if they are the same

Definition at line 227 of file CudaMemory.cuh.

◆ isInitialized()

bool CudaMemory::isInitialized ( )
inlinevirtual

Allocated Memory is never initialized.

Returns
false

Implements memory.

Definition at line 156 of file CudaMemory.cuh.

◆ isNotSync()

void CudaMemory::isNotSync ( )
inline

This function notify that the device memory is not sync with the host memory, is called when a task is performed that write on the buffer

Definition at line 131 of file CudaMemory.cuh.

◆ operator=()

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

Definition at line 162 of file CudaMemory.cuh.

◆ ref()

virtual long int CudaMemory::ref ( )
inlinevirtual

Return the reference counter.

Implements memory.

Definition at line 146 of file CudaMemory.cuh.

◆ resize()

bool CudaMemory::resize ( size_t  sz)
virtual

resize the momory 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

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

copy from the old buffer to the new one

copy from the old buffer to the new one

free the old buffer

change to the new buffer

Implements memory.

Definition at line 261 of file CudaMemory.cu.

◆ size()

size_t CudaMemory::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 245 of file CudaMemory.cu.

◆ swap()

void CudaMemory::swap ( CudaMemory mem)

Swap the memory.

Parameters
memmemory to swap

Definition at line 534 of file CudaMemory.cu.

◆ toKernel()

void * CudaMemory::toKernel ( )
inline

return the device memory

See also
equivalent to getDevicePointer()

Definition at line 237 of file CudaMemory.cuh.

Field Documentation

◆ dm

void* CudaMemory::dm
private

device memory

Definition at line 67 of file CudaMemory.cuh.

◆ hm

void* CudaMemory::hm
mutableprivate

host memory

Definition at line 70 of file CudaMemory.cuh.

◆ is_hm_sync

bool CudaMemory::is_hm_sync
private

Is the host memory synchronized with the GPU memory.

Definition at line 61 of file CudaMemory.cuh.

◆ ref_cnt

size_t CudaMemory::ref_cnt
private

Reference counter.

Definition at line 73 of file CudaMemory.cuh.

◆ sz

size_t CudaMemory::sz
private

Size of the memory.

Definition at line 64 of file CudaMemory.cuh.


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