From 6c5fa8dcd875bb9fb5e50b25adb8534711bdc4da Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Sat, 20 Jun 2020 14:34:29 -0400 Subject: [PATCH] Aligned allocate on CPU put through this interface --- Grid/threads/Accelerator.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Grid/threads/Accelerator.h b/Grid/threads/Accelerator.h index 5bf17072..74a3ea22 100644 --- a/Grid/threads/Accelerator.h +++ b/Grid/threads/Accelerator.h @@ -336,12 +336,11 @@ inline void acceleratorCopyFromDevice(void *from,void *to,size_t bytes){ hipMemc ////////////////////////////////////////////// // CPU Target - No accelerator just thread instead ////////////////////////////////////////////// +#define GRID_ALLOC_ALIGN (2*1024*1024) // 2MB aligned #if ( (!defined(GRID_SYCL)) && (!defined(GRID_CUDA)) && (!defined(GRID_HIP)) ) #undef GRID_SIMT -#define GRID_ALLOC_ALIGN (2*1024*1024) // 2MB aligned - #define accelerator #define accelerator_inline strong_inline #define accelerator_for(iterator,num,nsimd, ... ) thread_for(iterator, num, { __VA_ARGS__ }); @@ -367,6 +366,14 @@ inline void acceleratorFreeDevice(void *ptr){free(ptr);}; #endif // CPU target +#ifdef HAVE_MM_MALLOC_H +inline void *acceleratorAllocCpu(size_t bytes){return _mm_malloc(bytes,GRID_ALLOC_ALIGN);}; +inline void acceleratorFreeCpu (void *ptr){_mm_free(ptr);}; +#else +inline void *acceleratorAllocCpu(size_t bytes){return memalign(GRID_ALLOC_ALIGN,bytes);}; +inline void acceleratorFreeCpu (void *ptr){free(ptr);}; +#endif + /////////////////////////////////////////////////// // Synchronise across local threads for divergence resynch ///////////////////////////////////////////////////