Hi All,
I was fighting for a long time with memory leaks control in my application. I figured out that cuda API does not free the resources as I would expect.
The following code
#include <stdlib.h>
#include <stdio.h>
#include <sys/sysinfo.h>
#include <cuda_runtime_api.h>
#include <cutil_inline.h>
void PrintFreeMemory()
{
struct sysinfo myinfo;
unsigned long total_bytes;
sysinfo(&myinfo);
total_bytes = myinfo.mem_unit * myinfo.freeram;
printf(" usable main memory is %lu B, %lu MB\n",
total_bytes, total_bytes/1024/1024);
}
int main( int argc, char** argv )
{
printf("Starting point :\t\t");
PrintFreeMemory();
cudaSetDevice(0);
printf("After cudaSetDevice :\t\t");
PrintFreeMemory();
cudaEvent_t startEvent;
cutilSafeCall( cudaEventCreate( &startEvent ) );
printf("After creating an event :\t");
PrintFreeMemory();
cutilSafeCall( cudaEventDestroy( startEvent) );
printf("After destroying an event :\t");
PrintFreeMemory();
cudaThreadExit();
printf("After cudaThreadExit :\t\t");
PrintFreeMemory();
}
gives the result like:
Starting point : usable main memory is 908730368 B, 866 MB
After cudaSetDevice : usable main memory is 903778304 B, 861 MB
After creating an event : usable main memory is 888094720 B, 846 MB
After destroying an event : usable main memory is 888094720 B, 846 MB
After cudaThreadExit : usable main memory is 903524352 B, 861 MB
Can somebody please explain me what I do wrong? I use Ubuntu 10.4, driver 195.36.24 and CUDA 3.0.
Thanks,
K.