mirror of
https://github.com/paboyle/Grid.git
synced 2026-09-03 16:29:37 +01:00
Better memory logging
This commit is contained in:
@@ -84,6 +84,31 @@ MemoryManager::AllocationCacheEntry MemoryManager::Entries[MemoryManager::Nalloc
|
|||||||
int MemoryManager::Victim[MemoryManager::NallocType];
|
int MemoryManager::Victim[MemoryManager::NallocType];
|
||||||
int MemoryManager::Ncache[MemoryManager::NallocType] = { 2, 0, 8, 8, 0, 16, 8, 0, 16 };
|
int MemoryManager::Ncache[MemoryManager::NallocType] = { 2, 0, 8, 8, 0, 16, 8, 0, 16 };
|
||||||
uint64_t MemoryManager::CacheBytes[MemoryManager::NallocType];
|
uint64_t MemoryManager::CacheBytes[MemoryManager::NallocType];
|
||||||
|
uint64_t MemoryManager::DeviceAllocCalls;
|
||||||
|
uint64_t MemoryManager::DeviceFreeCalls;
|
||||||
|
uint64_t MemoryManager::DeviceAllocBytes;
|
||||||
|
uint64_t MemoryManager::DeviceFreeBytes;
|
||||||
|
uint64_t MemoryManager::DeviceCacheHits;
|
||||||
|
|
||||||
|
void MemoryManager::PrintAllocCounts(void)
|
||||||
|
{
|
||||||
|
std::cout << GridLogMemory << "MemoryManager: device allocator calls: acceleratorAllocDevice "
|
||||||
|
<< DeviceAllocCalls <<" ("<< DeviceAllocBytes <<" bytes), acceleratorFreeDevice "
|
||||||
|
<< DeviceFreeCalls <<" ("<< DeviceFreeBytes <<" bytes), served from ring cache "
|
||||||
|
<< DeviceCacheHits << std::endl;
|
||||||
|
std::cout << GridLogMemory << "MemoryManager: view traffic: HostToDevice "
|
||||||
|
<< HostToDeviceXfer <<" transfers ("<< HostToDeviceBytes <<" bytes), DeviceToHost "
|
||||||
|
<< DeviceToHostXfer <<" transfers ("<< DeviceToHostBytes <<" bytes), evictions "
|
||||||
|
<< DeviceEvictions << std::endl;
|
||||||
|
}
|
||||||
|
void MemoryManager::Snapshot(const std::string &where)
|
||||||
|
{
|
||||||
|
if ( !GridLogMemory.isActive() ) return;
|
||||||
|
std::cout << GridLogMemory << "---------------- memory snapshot: "<< where <<" ----------------"<<std::endl;
|
||||||
|
PrintAllocCounts();
|
||||||
|
PrintBytes();
|
||||||
|
acceleratorMem();
|
||||||
|
}
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Actual allocation and deallocation utils
|
// Actual allocation and deallocation utils
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
@@ -93,6 +118,11 @@ void *MemoryManager::AcceleratorAllocate(size_t bytes)
|
|||||||
void *ptr = (void *) Lookup(bytes,Acc);
|
void *ptr = (void *) Lookup(bytes,Acc);
|
||||||
if ( ptr == (void *) NULL ) {
|
if ( ptr == (void *) NULL ) {
|
||||||
ptr = (void *) acceleratorAllocDevice(bytes);
|
ptr = (void *) acceleratorAllocDevice(bytes);
|
||||||
|
DeviceAllocCalls++; DeviceAllocBytes+=bytes;
|
||||||
|
std::cout << GridLogMemory << "MemoryManager: acceleratorAllocDevice size "<< bytes
|
||||||
|
<<" AccPtr "<< std::hex << (uint64_t)ptr << std::dec << std::endl;
|
||||||
|
} else {
|
||||||
|
DeviceCacheHits++;
|
||||||
}
|
}
|
||||||
#ifdef GRID_MM_VERBOSE
|
#ifdef GRID_MM_VERBOSE
|
||||||
std::cout <<"AcceleratorAllocate "<<std::endl;
|
std::cout <<"AcceleratorAllocate "<<std::endl;
|
||||||
@@ -103,9 +133,13 @@ void *MemoryManager::AcceleratorAllocate(size_t bytes)
|
|||||||
void MemoryManager::AcceleratorFree (void *ptr,size_t bytes)
|
void MemoryManager::AcceleratorFree (void *ptr,size_t bytes)
|
||||||
{
|
{
|
||||||
total_device-=bytes;
|
total_device-=bytes;
|
||||||
void *__freeme = Insert(ptr,bytes,Acc);
|
size_t freed_bytes=0;
|
||||||
|
void *__freeme = Insert(ptr,bytes,Acc,&freed_bytes);
|
||||||
if ( __freeme ) {
|
if ( __freeme ) {
|
||||||
acceleratorFreeDevice(__freeme);
|
acceleratorFreeDevice(__freeme);
|
||||||
|
DeviceFreeCalls++; DeviceFreeBytes+=freed_bytes;
|
||||||
|
std::cout << GridLogMemory << "MemoryManager: acceleratorFreeDevice size "<< freed_bytes
|
||||||
|
<<" AccPtr "<< std::hex << (uint64_t)__freeme << std::dec << std::endl;
|
||||||
}
|
}
|
||||||
#ifdef GRID_MM_VERBOSE
|
#ifdef GRID_MM_VERBOSE
|
||||||
std::cout <<"AcceleratorFree "<<std::endl;
|
std::cout <<"AcceleratorFree "<<std::endl;
|
||||||
@@ -272,7 +306,7 @@ void MemoryManager::InitMessage(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
void *MemoryManager::Insert(void *ptr,size_t bytes,int type)
|
void *MemoryManager::Insert(void *ptr,size_t bytes,int type,size_t *freed)
|
||||||
{
|
{
|
||||||
#ifdef ALLOCATION_CACHE
|
#ifdef ALLOCATION_CACHE
|
||||||
int cache;
|
int cache;
|
||||||
@@ -280,7 +314,7 @@ void *MemoryManager::Insert(void *ptr,size_t bytes,int type)
|
|||||||
else if (bytes >= GRID_ALLOC_HUGE_LIMIT) cache = type + 1;
|
else if (bytes >= GRID_ALLOC_HUGE_LIMIT) cache = type + 1;
|
||||||
else cache = type;
|
else cache = type;
|
||||||
|
|
||||||
return Insert(ptr,bytes,Entries[cache],Ncache[cache],Victim[cache],CacheBytes[cache]);
|
return Insert(ptr,bytes,Entries[cache],Ncache[cache],Victim[cache],CacheBytes[cache],freed);
|
||||||
#else
|
#else
|
||||||
return ptr;
|
return ptr;
|
||||||
#endif
|
#endif
|
||||||
@@ -326,7 +360,7 @@ void MemoryManager::DropCache(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *MemoryManager::Insert(void *ptr,size_t bytes,AllocationCacheEntry *entries,int ncache,int &victim, uint64_t &cacheBytes)
|
void *MemoryManager::Insert(void *ptr,size_t bytes,AllocationCacheEntry *entries,int ncache,int &victim, uint64_t &cacheBytes,size_t *freed)
|
||||||
{
|
{
|
||||||
#ifdef GRID_OMP
|
#ifdef GRID_OMP
|
||||||
GRID_ASSERT(omp_in_parallel()==0);
|
GRID_ASSERT(omp_in_parallel()==0);
|
||||||
@@ -351,6 +385,7 @@ void *MemoryManager::Insert(void *ptr,size_t bytes,AllocationCacheEntry *entries
|
|||||||
|
|
||||||
if ( entries[v].valid ) {
|
if ( entries[v].valid ) {
|
||||||
ret = entries[v].address;
|
ret = entries[v].address;
|
||||||
|
if ( freed ) *freed = entries[v].bytes; // the DISPLACED block is what actually gets freed
|
||||||
cacheBytes -= entries[v].bytes;
|
cacheBytes -= entries[v].bytes;
|
||||||
entries[v].valid = 0;
|
entries[v].valid = 0;
|
||||||
entries[v].address = NULL;
|
entries[v].address = NULL;
|
||||||
|
|||||||
@@ -108,9 +108,9 @@ private:
|
|||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
// Free pool
|
// Free pool
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
static void *Insert(void *ptr,size_t bytes,int type) ;
|
static void *Insert(void *ptr,size_t bytes,int type,size_t *freed=nullptr) ;
|
||||||
static void *Lookup(size_t bytes,int type) ;
|
static void *Lookup(size_t bytes,int type) ;
|
||||||
static void *Insert(void *ptr,size_t bytes,AllocationCacheEntry *entries,int ncache,int &victim,uint64_t &cbytes) ;
|
static void *Insert(void *ptr,size_t bytes,AllocationCacheEntry *entries,int ncache,int &victim,uint64_t &cbytes,size_t *freed=nullptr) ;
|
||||||
static void *Lookup(size_t bytes,AllocationCacheEntry *entries,int ncache,uint64_t &cbytes) ;
|
static void *Lookup(size_t bytes,AllocationCacheEntry *entries,int ncache,uint64_t &cbytes) ;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -137,6 +137,18 @@ public:
|
|||||||
static uint64_t DeviceToHostXfer;
|
static uint64_t DeviceToHostXfer;
|
||||||
static uint64_t DeviceEvictions;
|
static uint64_t DeviceEvictions;
|
||||||
static uint64_t DeviceDestroy;
|
static uint64_t DeviceDestroy;
|
||||||
|
// Calls that actually reach the runtime, as distinct from the Evict/Clone traffic above:
|
||||||
|
// a free only reaches acceleratorFreeDevice when displaced from the allocation ring cache,
|
||||||
|
// and an allocate only reaches acceleratorAllocDevice on a ring miss.
|
||||||
|
static uint64_t DeviceAllocCalls;
|
||||||
|
static uint64_t DeviceFreeCalls;
|
||||||
|
static uint64_t DeviceAllocBytes;
|
||||||
|
static uint64_t DeviceFreeBytes;
|
||||||
|
static uint64_t DeviceCacheHits;
|
||||||
|
static void PrintAllocCounts(void);
|
||||||
|
// Labelled snapshot: allocator counts + footprint + device free/total. Silent unless
|
||||||
|
// --log Memory is on, so it can be left in hot code.
|
||||||
|
static void Snapshot(const std::string &where);
|
||||||
|
|
||||||
static uint64_t DeviceCacheBytes();
|
static uint64_t DeviceCacheBytes();
|
||||||
static uint64_t HostCacheBytes();
|
static uint64_t HostCacheBytes();
|
||||||
|
|||||||
Reference in New Issue
Block a user