I’m getting different values for the total memory on calls to cudaMemGetInfo after allocating memory.
It should be be noted that i am running this via the matlab mex interface, perhaps this has something to do with it?
This code is executed inside a matlab for loop from 0 to 511
...
/* Check GPU memory before allocation. */
size_t freeMemBefore = 0;
size_t totalMem = 0;
size_t freeMemAfterAlloc = 0;
size_t freeMemAfterFree = 0;
mexPrintf("* Memory available before allocation.\n");
cudaMemGetInfo(&freeMemBefore, &totalMem);
mexPrintf("Total GPU memory: %lu\n",&totalMem);
mexPrintf("GPU memory available: %lu\n",&freeMemBefore);
/* Pointers for the device memory */
float *a;
double *b;
float *c, *d; // Complex
/* Allocate memory on the device */
cudaMalloc( (void **) &a, sizeof(float)*999);
cudaMalloc( (void **) &b, sizeof(double)*999);
cudaMalloc( (void **) &c, sizeof(double)*512);
cudaMalloc( (void **) &d, sizeof(double)*512);
mexPrintf("** Memory available after allocation.\n");
cudaMemGetInfo(&freeMemAfterAlloc, &totalMem);
mexPrintf("Total GPU memory: %lu\n",totalMem);
mexPrintf("GPU memory available: %lu, Consumed: %lu\n",freeMemAfterAlloc,(freeMemBefore - freeMemAfterAlloc));
... some cudaMemcpy's (cudaMemcpyHostToDevice) here ...
... launch kernel here ...
... some cudaMemcpy's (cudaMemcpyDeviceToHost) here ...
... cudaFree(a, b,c,d) here ...
mexPrintf("*** Memory available after free'ing.\n");
cudaMemGetInfo(&freeMemAfterFree, &totalMem);
mexPrintf("Total GPU memory: %lu\n",totalMem);
mexPrintf("GPU memory available: %lu\n\n",freeMemAfterFree);
return;
results:
index = 0
- Memory available before allocation.
Total GPU memory: 68245376
GPU memory available: 68245400
** Memory available after allocation.
Total GPU memory: 2818572288
GPU memory available: 2331492352, Consumed: 2097152
*** Memory available after free’ing.
Total GPU memory: 2818572288
GPU memory available: 2331492352
index = 1
- Memory available before allocation.
Total GPU memory: 68245376
GPU memory available: 68245400
** Memory available after allocation.
Total GPU memory: 2818572288
GPU memory available: 2331492352, Consumed: 0
*** Memory available after free’ing.
Total GPU memory: 2818572288
GPU memory available: 2331492352
index = 2
- Memory available before allocation.
Total GPU memory: 68251232
GPU memory available: 68251256
** Memory available after allocation.
Total GPU memory: 2818572288
GPU memory available: 2331492352, Consumed: 0
*** Memory available after free’ing.
Total GPU memory: 2818572288
GPU memory available: 2331492352
Then the total GPU memory is the same for each printed line.
index = 509
- Memory available before allocation.
Total GPU memory: 68251232
GPU memory available: 68251256
** Memory available after allocation.
Total GPU memory: 2818572288
GPU memory available: 2323103744, Consumed: 0
*** Memory available after free’ing.
Total GPU memory: 2818572288
GPU memory available: 2323103744
index = 510
- Memory available before allocation.
Total GPU memory: 68251232
GPU memory available: 68251256
** Memory available after allocation.
Total GPU memory: 2818572288
GPU memory available: 2323103744, Consumed: 0
*** Memory available after free’ing.
Total GPU memory: 2818572288
GPU memory available: 2323103744
index = 511
- Memory available before allocation.
Total GPU memory: 68251232
GPU memory available: 68251256
** Memory available after allocation.
Total GPU memory: 2818572288
GPU memory available: 2323103744, Consumed: 0
*** Memory available after free’ing.
Total GPU memory: 2818572288
GPU memory available: 2323103744
what i would like to know is, why is the total GPU memory different between the cudaMalloc calls and why is the consumed memory 0 after the first iteration of the loop?
FYI: im running a Tesla C2050 card with close to 3 GB memory.
Thanks in advance.