1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-04 19:25:56 +01:00

fix evict scheme, slab alloc

This commit is contained in:
Christoph Lehner 2020-09-13 14:02:53 -04:00
parent 01652d8cfe
commit 32ff766dbd
2 changed files with 12 additions and 2 deletions

View File

@ -227,12 +227,13 @@ uint64_t MemoryManager::AcceleratorViewOpen(uint64_t CpuPtr,size_t bytes,ViewMod
// Find if present, otherwise get or force an empty
////////////////////////////////////////////////////////////////////////////
if ( EntryPresent(CpuPtr)==0 ){
EvictVictims(bytes);
EntryCreate(CpuPtr,bytes,mode,hint);
}
auto AccCacheIterator = EntryLookup(CpuPtr);
auto & AccCache = AccCacheIterator->second;
if (!AccCache.AccPtr)
EvictVictims(bytes);
assert((mode==AcceleratorRead)||(mode==AcceleratorWrite)||(mode==AcceleratorWriteDiscard));
@ -361,12 +362,13 @@ uint64_t MemoryManager::CpuViewOpen(uint64_t CpuPtr,size_t bytes,ViewMode mode,V
// Find if present, otherwise get or force an empty
////////////////////////////////////////////////////////////////////////////
if ( EntryPresent(CpuPtr)==0 ){
EvictVictims(bytes);
EntryCreate(CpuPtr,bytes,mode,transient);
}
auto AccCacheIterator = EntryLookup(CpuPtr);
auto & AccCache = AccCacheIterator->second;
if (!AccCache.AccPtr)
EvictVictims(bytes);
assert((mode==CpuRead)||(mode==CpuWrite));
assert(AccCache.accLock==0); // Programming error

View File

@ -36,6 +36,9 @@ NAMESPACE_BEGIN(Grid);
#define GRID_DEVICE_HEAP_SLAB_THRESHOLD (1024*1024)
#define GRID_DEVICE_HEAP_SLAB_SIZE (2*1024*1024)
size_t currentDeviceAlloc = 0;
std::unordered_map<void*,size_t> ptr_size;
void *acceleratorAllocDeviceCUDA(size_t bytes) {
void *ptr=NULL;
auto err = cudaMalloc((void **)&ptr,bytes);
@ -43,11 +46,16 @@ void *acceleratorAllocDeviceCUDA(size_t bytes) {
ptr = (void *) NULL;
printf(" cudaMalloc failed for %d %s \n",bytes,cudaGetErrorString(err));
}
currentDeviceAlloc += bytes;
ptr_size[ptr] = bytes;
std::cout << "Current device alloc: " << currentDeviceAlloc << std::endl;
return ptr;
}
void acceleratorFreeDeviceCUDA(void *ptr) {
cudaFree(ptr);
currentDeviceAlloc -= ptr_size[ptr];
std::cout << "Current device alloc: " << currentDeviceAlloc << std::endl;
}
struct grid_device_heap_slab_t {