27#ifndef CUDA_MEMORY_CUH_
28#define CUDA_MEMORY_CUH_
30#define EXCEPT_MC noexcept
36#include "util/cuda_util.hpp"
38extern size_t TotCudaMemoryAllocated;
50__device__
inline size_t align_number_device(
size_t al,
size_t number)
52 return number + ((number % al) != 0)*(al - number % al);
56static __device__
unsigned char global_cuda_error_array[256];
95 virtual size_t size()
const;
126 virtual void fill(
unsigned char c);
185 mem.is_hm_sync =
false;
207 std::cerr <<
"Error: " << __FILE__ <<
" " << __LINE__ <<
" destroying a live object" <<
"\n";
218 void deviceToDevice(
void * ptr,
size_t start,
size_t stop,
size_t offset);
virtual void * getDevicePointer()
get a readable pointer with the data
void * toKernel()
return the device memory
void deviceToDevice(void *ptr, size_t start, size_t stop, size_t offset)
copy memory from device to device
virtual void incRef()
Increment the reference counter.
virtual void deviceToHost()
Move memory from device to host.
virtual bool resize(size_t sz)
resize the momory allocated
virtual bool copy(const memory &m)
copy from a General device
virtual bool flush()
flush the memory
virtual long int ref()
Return the reference counter.
virtual void hostToDevice()
Move memory from host to device.
size_t ref_cnt
Reference counter.
bool is_hm_sync
Is the host memory synchronized with the GPU memory.
virtual void decRef()
Decrement the reference counter.
virtual size_t size() const
the the size of the allocated memory
CudaMemory(size_t sz)
Constructor.
bool copyFromPointer(const void *ptr)
copy from Pointer to GPU
virtual void fill(unsigned char c)
fill the buffer with a byte
void swap(CudaMemory &mem)
Swap the memory.
static constexpr bool isDeviceHostSame()
Return true if the device and the host pointer are the same.
size_t sz
Size of the memory.
virtual void * getPointer()
get a readable pointer with the data
void allocate_host(size_t sz) const
Allocate an host buffer.
bool copyDeviceToDevice(const CudaMemory &m)
copy from GPU to GPU buffer directly
virtual void destroy()
destroy memory
bool isInitialized()
Allocated Memory is never initialized.
this class is a functor for "for_each" algorithm