8 #ifndef HEAP_MEMORY_HPP 9 #define HEAP_MEMORY_HPP 17 typedef 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);
167 std::cerr <<
"Error: " << __FILE__ <<
" " << __LINE__ <<
" destroying a live object" <<
"\n";
177 size_t alignement_tmp;
181 long int ref_cnt_tmp;
223 inline size_t align_number(
size_t al,
size_t number)
225 return number + ((number % al) != 0)*(al - number % al);
234 inline 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 );
HeapMemory(HeapMemory &&mem) noexcept
virtual void hostToDevice(size_t start, size_t stop)
Do nothing.
void swap(HeapMemory &mem)
Swap the memory.
virtual void fill(unsigned char c)
fill host and device memory with the selected byte
virtual void deviceToHost()
Do nothing.
virtual bool flush()
flush the memory
virtual bool allocate(size_t sz)
allocate memory
virtual void decRef()
Decrement the reference counter.
virtual void incRef()
Increment the reference counter.
virtual void deviceToHost(size_t start, size_t stop)
Do nothing.
virtual void hostToDevice()
Do nothing.
long int ref_cnt
Reference counter.
void setAlignment(size_t align)
Set alignment the memory will be aligned with this number.
HeapMemory()
Constructor, we choose a default alignment of 32 for avx.
This class allocate, and destroy CPU memory.
size_t alignement
memory alignment
virtual void * getPointer()
get a readable pointer with the data
virtual void destroy()
destroy memory
byte * dmOrig
original pointer (before alignment)
virtual size_t size() const
the the size of the allocated memory
virtual void * getDevicePointer()
get a device pointer for HeapMemory getPointer and getDevicePointer are equivalents
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 bool resize(size_t sz)
resize the memory allocated
bool copyFromPointer(const void *ptr, size_t sz)
copy from Pointer to Heap
bool isInitialized()
Allocated Memory is never initialized.
virtual bool copy(const memory &m)
copy memory
size_t sz
Size of the memory.
bool copyDeviceToDevice(const HeapMemory &m)
copy from same Heap to Heap