17typedef unsigned char byte;
19#define MEM_ALIGNMENT 32
66 virtual bool flush() {
return true;};
74 virtual size_t size()
const;
90 virtual void fill(
unsigned char c);
152 mem.alignement = MEM_ALIGNMENT;
167 std::cerr <<
"Error: " << __FILE__ <<
" " << __LINE__ <<
" destroying a live object" <<
"\n";
177 size_t alignement_tmp;
181 long int ref_cnt_tmp;
223inline size_t align_number(
size_t al,
size_t number)
225 return number + ((number % al) != 0)*(al - number % al);
234inline void *align( std::size_t alignment, std::size_t size,
235 void *&ptr, std::size_t &space ) {
236 std::uintptr_t pn =
reinterpret_cast< std::uintptr_t
>( ptr );
237 std::uintptr_t aligned = ( pn + alignment - 1 ) & - alignment;
238 std::size_t padding = aligned - pn;
239 if ( space < size + padding )
return nullptr;
241 return ptr =
reinterpret_cast< void *
>( aligned );
This class allocate, and destroy CPU memory.
virtual void decRef()
Decrement the reference counter.
HeapMemory(HeapMemory &&mem) noexcept
virtual bool flush()
flush the memory
virtual void incRef()
Increment the reference counter.
bool copyFromPointer(const void *ptr, size_t sz)
copy from Pointer to Heap
byte * dmOrig
original pointer (before alignment)
void setAlignment(size_t align)
Set alignment the memory will be aligned with this number.
static constexpr bool isDeviceHostSame()
Return true if the device and the host pointer are the same.
virtual long int ref()
Return the reference counter.
virtual void fill(unsigned char c)
fill host and device memory with the selected byte
virtual void hostToDevice(size_t start, size_t stop)
Do nothing.
virtual bool resize(size_t sz)
resize the memory allocated
virtual void * getPointer()
get a readable pointer with the data
virtual void deviceToHost(size_t start, size_t stop)
Do nothing.
virtual size_t size() const
the the size of the allocated memory
virtual void deviceToHost()
Do nothing.
virtual bool copy(const memory &m)
copy memory
long int ref_cnt
Reference counter.
bool isInitialized()
Allocated Memory is never initialized.
void swap(HeapMemory &mem)
Swap the memory.
virtual void hostToDevice()
Do nothing.
HeapMemory()
Constructor, we choose a default alignment of 32 for avx.
size_t alignement
memory alignment
size_t sz
Size of the memory.
virtual void * getDevicePointer()
get a device pointer for HeapMemory getPointer and getDevicePointer are equivalents
virtual void destroy()
destroy memory
bool copyDeviceToDevice(const HeapMemory &m)
copy from same Heap to Heap
this class is a functor for "for_each" algorithm