7 #ifndef EXTPREALLOC_HPP_ 8 #define EXTPREALLOC_HPP_ 26 template<
typename Mem>
46 std::cerr <<
"Error: " << __FILE__ <<
" " << __LINE__ <<
" destroying a live object" <<
"\n";
76 return mem->copyDeviceToDevice(*m.
mem);
89 mem->deviceToDevice(ptr,start,stop,offset);
92 constexpr
static bool isDeviceHostSame()
94 return Mem::isDeviceHostSame();
118 virtual void fill(
unsigned char c)
143 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error requesting more memory than the allocated one" << std::endl;
176 return (
char *)
mem->getPointer() +
l_size;
186 return (
char *)
mem->getDevicePointer() +
l_size;
196 return mem->getPointer();
209 {
return (((
unsigned char *)
mem->getDevicePointer()) +
a_seq );}
230 mem->hostToDevice(start,stop);
242 mem->deviceToHost(start,stop);
252 return (((
unsigned char *)
mem->getPointer()) +
a_seq );
262 return (((
unsigned char *)
mem->getPointer()) +
a_seq);
272 return (((
unsigned char *)
mem->getPointer()) + offset);
340 for (
size_t i = 0 ; i < mm.size() ; i++)
bool isInitialized()
Allocated Memory is never initialized.
virtual size_t size() const
Get the size of the LAST allocated memory.
virtual void deviceToHost()
Do nothing.
virtual const void * getPointer() const
Return the pointer of the last allocation.
long int ref_cnt
Reference counter.
virtual void * getPointer()
Return the pointer of the last allocation.
size_t getOffsetEnd()
Get offset.
void shift_forward(size_t sz)
shift the pointer forward
virtual void hostToDevice(size_t start, size_t stop)
Return the pointer of the last allocation.
void shift_backward(size_t sz)
shift the pointer backward
size_t a_seq
Actual allocation pointer.
virtual bool allocate(size_t sz)
Allocate a chunk of memory.
void * getDevicePointerEnd()
Return the device end pointer of the previous allocated memory.
ExtPreAlloc()
Default constructor.
virtual void fill(unsigned char c)
fill host and device memory with the selected byte
virtual long int ref()
Return the reference counter.
virtual void hostToDevice()
Return the pointer of the last allocation.
size_t l_size
Last allocation size.
ExtPreAlloc(size_t size, Mem &mem)
Preallocated memory sequence.
size_t getOffset()
Get offset.
virtual bool flush()
flush the memory
void * getPointerOffset(size_t offset)
Get the base memory pointer increased with an offset.
bool copyDeviceToDevice(const ExtPreAlloc< Mem > &m)
Copy the memory from device to device.
bool allocate_nocheck(size_t sz)
Allocate a chunk of memory.
virtual void incRef()
Increment the reference counter.
virtual bool copy(const memory &m)
Copy memory.
void deviceToDevice(void *ptr, size_t start, size_t stop, size_t offset)
special function to move memory from a raw device pointer
virtual bool resize(size_t sz)
Allocate or resize the allocated memory.
virtual void deviceToHost(size_t start, size_t stop)
Do nothing.
void * getPointerBase()
The the base pointer of the preallocate memory.
void destroy()
Destroy memory.
virtual void decRef()
Decrement the reference counter.
void reset()
Reset the internal counters.
Mem * mem
Main class for memory allocation.
virtual void * getDevicePointer()
Return the pointer of the last allocation.
static size_t calculateMem(std::vector< size_t > &mm)
Calculate the total memory required to pack the message.
void * getPointerEnd()
Return the end pointer of the previous allocated memory.