diff --git a/lib/THC/THCCachingAllocator.cpp b/lib/THC/THCCachingAllocator.cpp index ab9528e1..a4978fb8 100644 --- a/lib/THC/THCCachingAllocator.cpp +++ b/lib/THC/THCCachingAllocator.cpp @@ -212,7 +212,7 @@ struct THCCachingAllocator auto it = blocks.lower_bound(&search_key); for (;it != blocks.end() && *it && (*it)->device == dev_id; ++it) { size_t blocksize = (*it)->size; - total += blocksize; + *total += blocksize; if (blocksize > *largest) *largest = blocksize; } diff --git a/lib/THC/THCGeneral.c b/lib/THC/THCGeneral.c index 403c4fa6..547e060e 100644 --- a/lib/THC/THCGeneral.c +++ b/lib/THC/THCGeneral.c @@ -732,7 +732,7 @@ cudaError_t THCudaMemGetInfo(THCState *state, size_t* freeBytes, size_t* totalB if (allocator->cacheInfo != NULL) allocator->cacheInfo(allocator->state, device, &cachedBytes, &largestBlock); - + /* Adjust resulting free bytes number. largesBlock unused for now */ *freeBytes += cachedBytes; return cudaSuccess; diff --git a/test/test_shutdown.lua b/test/test_shutdown.lua index a5221642..e48a058d 100644 --- a/test/test_shutdown.lua +++ b/test/test_shutdown.lua @@ -10,8 +10,6 @@ local function test_cudaEvent() local t1View = t1:narrow(1, 10000000, 1) t1:fill(1) - print('Memory usage after some allocations [free memory], [total memory]') - print(cutorch.getMemoryUsage()) -- Event is created here local event = cutorch.Event() @@ -26,13 +24,41 @@ local function test_cudaEvent() cutorch.setStream(0) end -print ("cutorch.hasHalf is ", cutorch.hasHalf) +local Gig = 1024*1024*1024 + +local function test_getMemInfo() + local sz = Gig*0.1 + local t1 = torch.CudaTensor(sz):zero() + print('Memory usage after 1st allocation [free memory], [total memory]') + local total, free = cutorch.getMemoryUsage() + print(free/Gig, total/Gig) + local t2 = torch.CudaTensor(sz*1.3):zero() + print('Memory usage after 2nd allocation [free memory], [total memory]') + local total, free = cutorch.getMemoryUsage() + print(free/Gig, total/Gig) + t1 = nil + collectgarbage() + print('Memory usage after 1st deallocation [free memory], [total memory]') + local total, free = cutorch.getMemoryUsage() + print(free/Gig, total/Gig) + t2 = nil + collectgarbage() + print('Memory usage after 2nd deallocation [free memory], [total memory]') + total, free = cutorch.getMemoryUsage() + print(free/Gig, total/Gig) +end +print ("cutorch.hasHalf is ", cutorch.hasHalf) print('Memory usage before intialization of threads [free memory], [total memory]') -print(cutorch.getMemoryUsage()) -threads = Threads(100, function() require 'cutorch'; test_cudaEvent(); end) +local total, free = cutorch.getMemoryUsage() +print(free/Gig, total/Gig) +threads = Threads(20, function() require 'cutorch'; test_getMemInfo(); test_cudaEvent(); end) print('Memory usage after intialization of threads [free memory], [total memory]') -print(cutorch.getMemoryUsage()) +total, free = cutorch.getMemoryUsage() +print(free/Gig, total/Gig) threads:terminate() +collectgarbage() print('Memory usage after termination of threads [free memory], [total memory]') -print(cutorch.getMemoryUsage()) +total, free = cutorch.getMemoryUsage() +print(free/Gig, total/Gig) +