25 #ifndef _GEMA_MEMORY_H_ 26 #define _GEMA_MEMORY_H_ 35 #define GM_CACHE_LINE_SIZE 64 40 #define GM_CACHE_ALIGNED __declspec(align(GM_CACHE_LINE_SIZE)) 43 #define GmAlignedMalloc(size, align) _aligned_malloc((size), (align)) 46 #define GmAlignedFree(ptr) _aligned_free(ptr) 50 #define GM_CACHE_ALIGNED __attribute__((aligned(GM_CACHE_LINE_SIZE))) 52 inline void* GmAlignedMalloc(
size_t size,
size_t align)
55 if(align <
sizeof(
void*))
56 align =
sizeof(
void*);
57 return posix_memalign(&ptr, align, size) ? NULL : ptr;
60 #define GmAlignedFree(ptr) ::free(ptr) 67 void* p = GmAlignedMalloc(size, align);
71 throw std::bad_alloc();
77 return (((quintptr)ptr) & (align-1)) == 0;
92 if(QTypeInfo<T>::isComplex)
94 for(
int i = 0; i < n; i++, ptr++)
107 if(QTypeInfo<T>::isComplex)
109 for(
int i = 0; i < n; i++, ptr++)
125 if(QTypeInfo<T>::isComplex)
127 int objectOffset = ceil(
sizeof(T)/(
double)align) * align;
128 for(
int i = 0; i < n; i++)
131 ptr = (T*)(((
char*)ptr) + objectOffset);
146 if(QTypeInfo<T>::isComplex)
148 int objectOffset = ceil(
sizeof(T)/(
double)align) * align;
149 for(
int i = 0; i < n; i++)
152 ptr = (T*)(((
char*)ptr) + objectOffset);
167 inline void*
GmPmemcpy(
void* dst,
const void* src,
size_t n,
int nt = 0,
168 size_t min = 10 * 1024 * 1024)
172 return memcpy(dst, src, n);
182 size_t ln = bn + n % nt;
184 #pragma omp parallel for num_threads(nt) 185 for(
int i = 0; i < nt; i++)
186 memcpy(((
char*)dst) + i * bn, ((
const char*)src) + i * bn, i < nt - 1 ? bn : ln);
190 Q_UNUSED(nt); Q_UNUSED(min);
191 return memcpy(dst, src, n);
197 #ifdef ARMA_USE_GEMA_MEMORY_POOL #define GM_CACHE_LINE_SIZE
Cache line size. TODO: Get this from a configuration parameter.
Definition: gmMemory.h:35
void * GmAlignedMallocThrow(size_t size, size_t align)
A version of GmAlignedMalloc that throws a bad_alloc exception on failure.
Definition: gmMemory.h:65
void * GmPmemcpy(void *dst, const void *src, size_t n, int nt=0, size_t min=10 *1024 *1024)
Parallel (thread enabled) version of memcpy using OpenMP.
Definition: gmMemory.h:167
Declaration of helper functions for using OpenMP that translate into "empty" statements if compiled w...
void GmConstructObjectsInMemory(T *ptr, int n=1)
Calls the default T constructor for creating 'n' consecutive objects in the memory area pointed by pt...
Definition: gmMemory.h:90
Declaration of usefull configuration definitions for the Core library.
void GmDestroyAlignedObjectsInMemory(T *ptr, int align, int n)
Calls T destructor for 'n' aligned objects in the memory area pointed by ptr.
Definition: gmMemory.h:142
bool GmIsCacheAligned(void *ptr)
Checks if a pointer is cache aligned or not.
Definition: gmMemory.h:81
int GmOmpAdjustNumThreads(int nt)
Adjusts the given number of threads. If nt <= 0 or if nt > maximum number of omp threads,...
Definition: gmOmp.h:51
bool GmMemoryIsAligned(void *ptr, int align)
Checks if a pointer is aligned to the given align (which must be a power of two)
Definition: gmMemory.h:75
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
void GmDestroyObjectsInMemory(T *ptr, int n=1)
Calls T destructor for 'n' consecutive objects in the memory area pointed by ptr.
Definition: gmMemory.h:105
void GmConstructAlignedObjectsInMemory(T *ptr, int align, int n)
Calls the default T constructor for creating 'n' aligned objects in the memory area pointed by ptr.
Definition: gmMemory.h:121