OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
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 More...
 
virtual bool flush ()
 flush the memory More...
 
virtual bool allocate (size_t sz)
 allocate memory More...
 
virtual void destroy ()
 destroy memory More...
 
virtual bool copy (const memory &m)
 copy from a General device More...
 
virtual size_t size () const
 the the size of the allocated memory More...
 
virtual bool resize (size_t sz)
 resize the momory allocated More...
 
virtual void * getPointer ()
 get a readable pointer with the data More...
 
virtual const void * getPointer () const
 get a readable pointer with the data More...
 
virtual void * getDevicePointer ()
 get a readable pointer with the data More...
 
virtual void hostToDevice ()
 Move memory from host to device. More...
 
virtual void deviceToHost ()
 Move memory from device to host. More...
 
virtual void deviceToHost (size_t start, size_t stop)
 Move memory from device to host, just the selected chunk. More...
 
virtual void hostToDevice (size_t start, size_t top)
 Move memory from host to device, just the selected chunk. More...
 
void hostToDevice (CudaMemory &mem)
 host to device using external memory (this host memory is copied into mem device memory) More...
 
void deviceToHost (CudaMemory &mem)
 device to host using external memory (this device memory is copied into mem host memory) More...
 
virtual void fill (unsigned char c)
 fill the buffer with a byte More...
 
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. More...
 
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 More...
 
void swap (CudaMemory &mem)
 Swap the memory. More...
 
void * toKernel ()
 return the device memory More...
 
- Public Member Functions inherited from memory
virtual ~memory ()
 destructor More...
 

Static Public Member Functions

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

Private Member Functions

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

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.
 

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 214 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.

◆ 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

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 367 of file CudaMemory.cu.

◆ deviceToHost() [2/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 444 of file CudaMemory.cu.

◆ deviceToHost() [3/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 386 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 479 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 497 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 352 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 466 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 508 of file CudaMemory.cu.

◆ hostToDevice() [2/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 425 of file CudaMemory.cu.

◆ hostToDevice() [3/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 408 of file CudaMemory.cu.

◆ isDeviceHostSame()

static constexpr bool CudaMemory::isDeviceHostSame ( )
inlinestatic

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.

◆ 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 259 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 243 of file CudaMemory.cu.

◆ swap()

void CudaMemory::swap ( CudaMemory mem)

Swap the memory.

Parameters
memmemory to swap

Definition at line 528 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.


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