14#define SharedSmall (8)
20#if defined(__has_feature)
21#if __has_feature(leak_sanitizer)
22#define ASAN_LEAK_CHECK
27#include <sanitizer/asan_interface.h>
28#include <sanitizer/common_interface_defs.h>
29#include <sanitizer/lsan_interface.h>
30#define LEAK_CHECK(A) { __lsan_do_recoverable_leak_check(); }
32#define LEAK_CHECK(A) { }
42 std::cout <<
"MemoryManager: Total non-mmapped bytes (arena): "<< (size_t)mi.arena<<std::endl;
43 std::cout <<
"MemoryManager: # of free chunks (ordblks): "<< (size_t)mi.ordblks<<std::endl;
44 std::cout <<
"MemoryManager: # of free fastbin blocks (smblks): "<< (size_t)mi.smblks<<std::endl;
45 std::cout <<
"MemoryManager: # of mapped regions (hblks): "<< (size_t)mi.hblks<<std::endl;
46 std::cout <<
"MemoryManager: Bytes in mapped regions (hblkhd): "<< (size_t)mi.hblkhd<<std::endl;
47 std::cout <<
"MemoryManager: Max. total allocated space (usmblks): "<< (size_t)mi.usmblks<<std::endl;
48 std::cout <<
"MemoryManager: Free bytes held in fastbins (fsmblks): "<< (size_t)mi.fsmblks<<std::endl;
49 std::cout <<
"MemoryManager: Total allocated space (uordblks): "<< (size_t)mi.uordblks<<std::endl;
50 std::cout <<
"MemoryManager: Total free space (fordblks): "<< (size_t)mi.fordblks<<std::endl;
51 std::cout <<
"MemoryManager: Topmost releasable block (keepcost): "<< (size_t)mi.keepcost<<std::endl;
59 std::cout <<
" MemoryManager : ------------------------------------ "<<std::endl;
60 std::cout <<
" MemoryManager : PrintBytes "<<std::endl;
61 std::cout <<
" MemoryManager : ------------------------------------ "<<std::endl;
62 std::cout <<
" MemoryManager : "<<(
total_shared>>20)<<
" shared Mbytes "<<std::endl;
63 std::cout <<
" MemoryManager : "<<(
total_device>>20)<<
" accelerator Mbytes "<<std::endl;
64 std::cout <<
" MemoryManager : "<<(
total_host>>20) <<
" cpu Mbytes "<<std::endl;
67 std::cout <<
" MemoryManager : "<<(cacheBytes>>20) <<
" cpu cache Mbytes "<<std::endl;
69 std::cout <<
" MemoryManager : "<<(cacheBytes>>20) <<
" acc cache Mbytes "<<std::endl;
71 std::cout <<
" MemoryManager : "<<(cacheBytes>>20) <<
" shared cache Mbytes "<<std::endl;
96 if ( ptr == (
void *) NULL ) {
100 std::cout <<
"AcceleratorAllocate "<<std::endl;
112#ifdef GRID_MM_VERBOSE
113 std::cout <<
"AcceleratorFree "<<std::endl;
121 if ( ptr == (
void *) NULL ) {
124#ifdef GRID_MM_VERBOSE
125 std::cout <<
"SharedAllocate "<<std::endl;
137#ifdef GRID_MM_VERBOSE
138 std::cout <<
"SharedFree "<<std::endl;
147 if ( ptr == (
void *) NULL ) {
150#ifdef GRID_MM_VERBOSE
151 std::cout <<
"CpuAllocate "<<std::endl;
164#ifdef GRID_MM_VERBOSE
165 std::cout <<
"CpuFree "<<std::endl;
174 if ( ptr == (
void *) NULL ) {
177#ifdef GRID_MM_VERBOSE
178 std::cout <<
"CpuAllocate "<<std::endl;
191#ifdef GRID_MM_VERBOSE
192 std::cout <<
"CpuFree "<<std::endl;
207 str= getenv(
"GRID_ALLOC_NCACHE_LARGE");
217 str= getenv(
"GRID_ALLOC_NCACHE_HUGE");
227 str= getenv(
"GRID_ALLOC_NCACHE_SMALL");
245 std::cout <<
GridLogMessage<<
"MemoryManager::Init() setting up"<<std::endl;
246#ifdef ALLOCATION_CACHE
253 std::cout <<
GridLogMessage<<
"MemoryManager::Init() Unified memory space"<<std::endl;
255 std::cout <<
GridLogMessage<<
"MemoryManager::Init() Using cudaMallocManaged"<<std::endl;
258 std::cout <<
GridLogMessage<<
"MemoryManager::Init() Using hipMallocManaged"<<std::endl;
261 std::cout <<
GridLogMessage<<
"MemoryManager::Init() Using SYCL malloc_shared"<<std::endl;
264 std::cout <<
GridLogMessage<<
"MemoryManager::Init() Non unified: Caching accelerator data in dedicated memory"<<std::endl;
266 std::cout <<
GridLogMessage<<
"MemoryManager::Init() Using cudaMalloc"<<std::endl;
269 std::cout <<
GridLogMessage<<
"MemoryManager::Init() Using hipMalloc"<<std::endl;
272 std::cout <<
GridLogMessage<<
"MemoryManager::Init() Using SYCL malloc_device"<<std::endl;
280#ifdef ALLOCATION_CACHE
295 assert(omp_in_parallel()==0);
298 if (ncache == 0)
return ptr;
303 for(
int e=0;e<ncache;e++) {
304 if ( entries[e].valid==0 ) {
312 victim = (victim+1)%ncache;
315 if ( entries[v].valid ) {
317 cacheBytes -= entries[v].
bytes;
318 entries[v].
valid = 0;
320 entries[v].
bytes = 0;
324 entries[v].
bytes =bytes;
333#ifdef ALLOCATION_CACHE
348 assert(omp_in_parallel()==0);
350 for(
int e=0;e<ncache;e++){
351 if ( entries[e].valid && ( entries[e].bytes == bytes ) ) {
352 entries[e].
valid = 0;
353 cacheBytes -= entries[e].
bytes;
void * acceleratorAllocShared(size_t bytes)
void * acceleratorAllocDevice(size_t bytes)
void acceleratorFreeShared(void *ptr)
void acceleratorFreeCpu(void *ptr)
void * acceleratorAllocCpu(size_t bytes)
void acceleratorFreeDevice(void *ptr)
GridLogger GridLogMessage(1, "Message", GridLogColours, "NORMAL")
#define GRID_ALLOC_SMALL_LIMIT
#define GRID_ALLOC_HUGE_LIMIT
#define NAMESPACE_BEGIN(A)
static int Victim[NallocType]
static const int NallocCacheMax
static uint64_t DeviceCacheBytes()
static void * Lookup(size_t bytes, int type)
static void CpuFree(void *ptr, size_t bytes)
static const int NallocType
static void PrintBytes(void)
static void InitMessage(void)
static void DisplayMallinfo(void)
static uint64_t HostCacheBytes()
static void * Insert(void *ptr, size_t bytes, int type)
static uint64_t DeviceMaxBytes
static void * CpuAllocate(size_t bytes)
static int Ncache[NallocType]
static void NotifyDeletion(void *CpuPtr)
static uint64_t CacheBytes[NallocType]
static void SharedFree(void *ptr, size_t bytes)
static AllocationCacheEntry Entries[NallocType][NallocCacheMax]
static void * SharedAllocate(size_t bytes)
static void * AcceleratorAllocate(size_t bytes)
static void AcceleratorFree(void *ptr, size_t bytes)