mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
fix evict scheme, slab alloc
This commit is contained in:
parent
01652d8cfe
commit
32ff766dbd
@ -227,12 +227,13 @@ uint64_t MemoryManager::AcceleratorViewOpen(uint64_t CpuPtr,size_t bytes,ViewMod
|
|||||||
// Find if present, otherwise get or force an empty
|
// Find if present, otherwise get or force an empty
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
if ( EntryPresent(CpuPtr)==0 ){
|
if ( EntryPresent(CpuPtr)==0 ){
|
||||||
EvictVictims(bytes);
|
|
||||||
EntryCreate(CpuPtr,bytes,mode,hint);
|
EntryCreate(CpuPtr,bytes,mode,hint);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto AccCacheIterator = EntryLookup(CpuPtr);
|
auto AccCacheIterator = EntryLookup(CpuPtr);
|
||||||
auto & AccCache = AccCacheIterator->second;
|
auto & AccCache = AccCacheIterator->second;
|
||||||
|
if (!AccCache.AccPtr)
|
||||||
|
EvictVictims(bytes);
|
||||||
|
|
||||||
assert((mode==AcceleratorRead)||(mode==AcceleratorWrite)||(mode==AcceleratorWriteDiscard));
|
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
|
// Find if present, otherwise get or force an empty
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
if ( EntryPresent(CpuPtr)==0 ){
|
if ( EntryPresent(CpuPtr)==0 ){
|
||||||
EvictVictims(bytes);
|
|
||||||
EntryCreate(CpuPtr,bytes,mode,transient);
|
EntryCreate(CpuPtr,bytes,mode,transient);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto AccCacheIterator = EntryLookup(CpuPtr);
|
auto AccCacheIterator = EntryLookup(CpuPtr);
|
||||||
auto & AccCache = AccCacheIterator->second;
|
auto & AccCache = AccCacheIterator->second;
|
||||||
|
if (!AccCache.AccPtr)
|
||||||
|
EvictVictims(bytes);
|
||||||
|
|
||||||
assert((mode==CpuRead)||(mode==CpuWrite));
|
assert((mode==CpuRead)||(mode==CpuWrite));
|
||||||
assert(AccCache.accLock==0); // Programming error
|
assert(AccCache.accLock==0); // Programming error
|
||||||
|
@ -36,6 +36,9 @@ NAMESPACE_BEGIN(Grid);
|
|||||||
#define GRID_DEVICE_HEAP_SLAB_THRESHOLD (1024*1024)
|
#define GRID_DEVICE_HEAP_SLAB_THRESHOLD (1024*1024)
|
||||||
#define GRID_DEVICE_HEAP_SLAB_SIZE (2*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 *acceleratorAllocDeviceCUDA(size_t bytes) {
|
||||||
void *ptr=NULL;
|
void *ptr=NULL;
|
||||||
auto err = cudaMalloc((void **)&ptr,bytes);
|
auto err = cudaMalloc((void **)&ptr,bytes);
|
||||||
@ -43,11 +46,16 @@ void *acceleratorAllocDeviceCUDA(size_t bytes) {
|
|||||||
ptr = (void *) NULL;
|
ptr = (void *) NULL;
|
||||||
printf(" cudaMalloc failed for %d %s \n",bytes,cudaGetErrorString(err));
|
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;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void acceleratorFreeDeviceCUDA(void *ptr) {
|
void acceleratorFreeDeviceCUDA(void *ptr) {
|
||||||
cudaFree(ptr);
|
cudaFree(ptr);
|
||||||
|
currentDeviceAlloc -= ptr_size[ptr];
|
||||||
|
std::cout << "Current device alloc: " << currentDeviceAlloc << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct grid_device_heap_slab_t {
|
struct grid_device_heap_slab_t {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user