Calculate memory usage How can I estemate the memory usage on the device?

Hi I’m trying to estimate how much memory I need to store data on the device. Something I thought would be pretty straightforward and I wrote the following code.

[codebox]cout<<“Memory status before allocation”<<endl;

uint freeB, freeA;

uint total;

getMemoryStatus(&freeB, &total, true);

unsigned int memSizePFloat4 = sizeof(float) * 4 * m_params->noOfParticles;

unsigned int memSizePFloat = sizeof(float) * m_params->noOfParticles;

unsigned int memSizePUInt = sizeof(uint) * m_params->noOfParticles;

unsigned int memSizeGUInt = sizeof(uint) * m_params->noOfGrids;

allocateArray((void**)&m_dPos, memSizePFloat4);

allocateArray((void**)&m_dSortedPos,memSizePFloat4 );

allocateArray((void**)&m_dVel, memSizePFloat4);

allocateArray((void**)&m_dSortedVel, memSizePFloat4);

allocateArray((void**)&m_dAcceleration, memSizePFloat4);

allocateArray((void**)&m_dDensity, memSizePFloat);

allocateArray((void**)&m_dPressure, memSizePFloat);

allocateArray((void**)&m_dGridParticleHash, memSizePUInt);

allocateArray((void**)&m_dGridParticleIndex, memSizePUInt);

cout<<“Memory status after allocation”<<endl;

getMemoryStatus(&freeA, &total, true);

uint eMemoryUsage=(5memSizePFloat+2memSizePFloat+2*memSizePUInt

);

cout<<"Memory used: "<<freeB-freeA<<endl;

cout<<"Estemated memory use: "<<eMemoryUsage<<endl;

cout<<“--------------”<<endl;

cout<<"Diff: "<<freeB-freeA -eMemoryUsage<<endl;[/codebox]

Here is the output:

[indent]

Memory status before allocation

Free : 95158272 bytes (92928 KB) (90 MB)

Total : 536150016 bytes (523584 KB) (511 MB)

17.748441510817748679% free, 82.251558489182258427% used

Memory status after allocation

Free : 82903040 bytes (80960 KB) (79 MB)

Total : 536150016 bytes (523584 KB) (511 MB)

15.46265737684879582% free, 84.53734262315120418% used

Memory used: 12255232

Estemated memory use: 4532472


Diff: 7722760[/indent]

(I’m pretty certain that the code to get the available memory is correct)

As you can see, the memory I estimated I would use is way of. It seams to me that there is more going on during the memory allocation than I first though. Can it have something to do about how different data types are aligned in device memory? I don’t know. Does anyone know where it goes wrong? Any solutions? I appreciate any kind of help.

Cheers,

Would you mind posting the code to your getMemoryStatus(…) method?