Rippalka
Rippalka

Reputation: 380

Real memory allocation done by cudaMallocPitch

While debugging a memory leak in my cuda code, I was running some tests and wondered what was allocated on the GPU besides what I asked for.

Here is the test I am running:

__HOST__ __forceinline__
double memoryUsage()
{
    size_t free_byte = 0;
    size_t total_byte = 1;
    cudaMemGetInfo(&free_byte, &total_byte);
    return free_byte;
}

...
double mem = memoryUsage();
cudaMallocPitch((float**)&device_ptr, &pitch, width * sizeof(T), height);
ASSERT(mem - memoryUsage() == pitch * height);
...

Of course the assertion here fails. I simplified the code a bit, but note that I check for any error from cudaMallocPitch.

Does someone have an explanation for this? Could the memory managment system on the GPU (malloc) use this memory? Or did I simply mis-understand something?

If it can help, here are some values I get for some allocations of 400 x 400 x sizeof(uint16_t) arrays:

pitch= 1024; mem-memoryUsage()= 0; pitch*height= 409600
pitch= 1024; mem-memoryUsage()= 1.04858e+006; pitch*height= 501760
pitch= 1536; mem-memoryUsage()= 1.04858e+006; pitch*height= 838656

Thanks for your help.

Upvotes: 0

Views: 237

Answers (1)

Rippalka
Rippalka

Reputation: 380

I am going to answer my own question.

The answer to this question (Why doesn't CudaFree seem to free memory?) is apparently what is happening. 1.04858e+006 is the page size that is used to allocate memory on the GPU in my case.

Upvotes: 1

Related Questions