#include NAMESPACE_BEGIN(Grid); /*Allocation types, saying which pointer cache should be used*/ #define Cpu (0) #define CpuHuge (1) #define CpuSmall (2) #define Acc (3) #define AccHuge (4) #define AccSmall (5) #define Shared (6) #define SharedHuge (7) #define SharedSmall (8) #undef GRID_MM_VERBOSE uint64_t total_shared; uint64_t total_device; uint64_t total_host;; #if defined(__has_feature) #if __has_feature(leak_sanitizer) #define ASAN_LEAK_CHECK #endif #endif #ifdef ASAN_LEAK_CHECK #include #include #include #define LEAK_CHECK(A) { __lsan_do_recoverable_leak_check(); } #else #define LEAK_CHECK(A) { } #endif void MemoryManager::DisplayMallinfo(void) { #ifdef __linux__ struct mallinfo mi; // really want mallinfo2, but glibc version isn't uniform mi = mallinfo(); std::cout << "MemoryManager: Total non-mmapped bytes (arena): "<< (size_t)mi.arena<>20)<<" shared Mbytes "<>20)<<" accelerator Mbytes "<>20) <<" cpu Mbytes "<>20) <<" cpu cache Mbytes "<>20) <<" acc cache Mbytes "<>20) <<" shared cache Mbytes "<=0) && (Nc < NallocCacheMax)) { Ncache[Cpu]=Nc; Ncache[Acc]=Nc; Ncache[Shared]=Nc; } } str= getenv("GRID_ALLOC_NCACHE_HUGE"); if ( str ) { Nc = atoi(str); if ( (Nc>=0) && (Nc < NallocCacheMax)) { Ncache[CpuHuge]=Nc; Ncache[AccHuge]=Nc; Ncache[SharedHuge]=Nc; } } str= getenv("GRID_ALLOC_NCACHE_SMALL"); if ( str ) { Nc = atoi(str); if ( (Nc>=0) && (Nc < NallocCacheMax)) { Ncache[CpuSmall]=Nc; Ncache[AccSmall]=Nc; Ncache[SharedSmall]=Nc; } } } void MemoryManager::InitMessage(void) { #ifndef GRID_UVM std::cout << GridLogMessage << "MemoryManager Cache "<< MemoryManager::DeviceMaxBytes <<" bytes "<= GRID_ALLOC_HUGE_LIMIT) cache = type + 1; else cache = type; return Insert(ptr,bytes,Entries[cache],Ncache[cache],Victim[cache],CacheBytes[cache]); #else return ptr; #endif } void *MemoryManager::Insert(void *ptr,size_t bytes,AllocationCacheEntry *entries,int ncache,int &victim, uint64_t &cacheBytes) { #ifdef GRID_OMP assert(omp_in_parallel()==0); #endif if (ncache == 0) return ptr; void * ret = NULL; int v = -1; for(int e=0;e= GRID_ALLOC_HUGE_LIMIT) cache = type + 1; else cache = type; return Lookup(bytes,Entries[cache],Ncache[cache],CacheBytes[cache]); #else return NULL; #endif } void *MemoryManager::Lookup(size_t bytes,AllocationCacheEntry *entries,int ncache,uint64_t & cacheBytes) { #ifdef GRID_OMP assert(omp_in_parallel()==0); #endif for(int e=0;e