Hi, thanks for the reply, very helpful indeed.
I have one issue though, it works perfectly in XP but in Vista all calls to cuMemGetInfo are returning the same values after allocations and frees.
The other thing I was surprised to note was how much memory is used before really doing anything in Cuda, around 31MB on my system is used when I just allocate a very small buffer, thereafter memory is used up roughly as I’d expect (but it seems to be padding it a bit too roughly).
I was a bit surprised to see it report a different total bytes figure in XP and Vista too!
I am using drivers 178.08 in both XP and Vista.
I’ve included the code below incase anybody can spot something silly I am doing (I know I am mixing Driver and Runtime APIs but I gather from [post=“0”]here[/post] this is ok when doing this kind of thing).
[codebox]// memory_stats_test.cpp : Defines the entry point for the console application.
//
#include “stdafx.h”
#include “cuda.h”
#include “cuda_runtime_api.h”
#include <stdio.h>
bool cuda_get_memory_stats(unsigned int* free_mem, unsigned int* total_mem)
{
CUresult cu_status;
CUcontext temporary_context;
CUdevice temporary_device;
*total_mem = *free_mem = 0;
cu_status = cuInit(0);
if(cu_status != CUDA_SUCCESS) return false;
cu_status = cuDeviceGet(&temporary_device, 0);
if(cu_status != CUDA_SUCCESS) return false;
cu_status = cuCtxCreate(&temporary_context, 0, temporary_device);
if(cu_status != CUDA_SUCCESS) return false;
cu_status = cuMemGetInfo(free_mem, total_mem);
if(cu_status != CUDA_SUCCESS) return false;
cu_status = cuCtxDetach(temporary_context);
if(cu_status != CUDA_SUCCESS) return false;
return true;
}
void show_result(unsigned int free_mem, unsigned int total_mem, bool ret)
{
// show result
if(ret == true)
printf("Total bytes: %d, Free bytes: %d\n", total_mem, free_mem);
else
printf("Encountered error\n");
}
int _tmain(int argc, _TCHAR* argv)
{
unsigned int free_mem_bytes = 0;
unsigned int total_mem_bytes = 0;
cudaError_t status;
bool ret;
float* tmp_mem1;
float* tmp_mem2;
float* tmp_mem3;
float* tmp_mem4;
// get initial memory stats
ret = cuda_get_memory_stats(&free_mem_bytes, &total_mem_bytes);
show_result(free_mem_bytes, total_mem_bytes, ret);
// allocate
status = cudaMalloc((void **) &tmp_mem1, 128 * sizeof(float));
// get memory stats
ret = cuda_get_memory_stats(&free_mem_bytes, &total_mem_bytes);
show_result(free_mem_bytes, total_mem_bytes, ret);
// allocate
status = cudaMalloc((void **) &tmp_mem2, 10000000 * sizeof(float));
// get memory stats
ret = cuda_get_memory_stats(&free_mem_bytes, &total_mem_bytes);
show_result(free_mem_bytes, total_mem_bytes, ret);
// allocate
status = cudaMalloc((void **) &tmp_mem3, 10000000 * sizeof(float));
// get memory stats
ret = cuda_get_memory_stats(&free_mem_bytes, &total_mem_bytes);
show_result(free_mem_bytes, total_mem_bytes, ret);
// allocate
status = cudaMalloc((void **) &tmp_mem4, 8194 * sizeof(float));
// get memory stats
ret = cuda_get_memory_stats(&free_mem_bytes, &total_mem_bytes);
show_result(free_mem_bytes, total_mem_bytes, ret);
// free memory
status = cudaFree(tmp_mem4);
ret = cuda_get_memory_stats(&free_mem_bytes, &total_mem_bytes);
show_result(free_mem_bytes, total_mem_bytes, ret);
status = cudaFree(tmp_mem3);
ret = cuda_get_memory_stats(&free_mem_bytes, &total_mem_bytes);
show_result(free_mem_bytes, total_mem_bytes, ret);
status = cudaFree(tmp_mem2);
ret = cuda_get_memory_stats(&free_mem_bytes, &total_mem_bytes);
show_result(free_mem_bytes, total_mem_bytes, ret);
status = cudaFree(tmp_mem1);
ret = cuda_get_memory_stats(&free_mem_bytes, &total_mem_bytes);
show_result(free_mem_bytes, total_mem_bytes, ret);
return 0;
}[/codebox]
In XP it returns on my 8600GT with 256MB:
[i]Total bytes: 268107776, Free bytes: 222431744
Total bytes: 268107776, Free bytes: 189007872
Total bytes: 268107776, Free bytes: 148965376
Total bytes: 268107776, Free bytes: 108922880
Total bytes: 268107776, Free bytes: 108857344
Total bytes: 268107776, Free bytes: 108922880
Total bytes: 268107776, Free bytes: 148965376
Total bytes: 268107776, Free bytes: 189007872
Total bytes: 268107776, Free bytes: 189007872[/i]
In Vista it returns:
[i]Total bytes: 268435456, Free bytes: 233373696
Total bytes: 268435456, Free bytes: 233373696
Total bytes: 268435456, Free bytes: 233373696
Total bytes: 268435456, Free bytes: 233373696
Total bytes: 268435456, Free bytes: 233373696
Total bytes: 268435456, Free bytes: 233373696
Total bytes: 268435456, Free bytes: 233373696
Total bytes: 268435456, Free bytes: 233373696
Total bytes: 268435456, Free bytes: 233373696[/i]