CudaHostAlloc throwing an exception

I am having an issue with some of my code that tries to ‘page’ things on and off the GPU when necessary. My calls to cudaHostAlloc is throwing an access violation yet I don’t think I am doing anything odd.

The code that seems to be relevant is:

float* newAddress = NULL;
//Some checks here to make sure this hostAlloc is possible and sensible

if (cudaSuccess == cudaHostAlloc(&newAddress,sizeof(float) * m_currentDataElements, cudaHostAllocWriteCombined)
{
   cudaMemcpy(newAddress, m_dData, sizeof(float) * m_currentDataElements, cudaMemcpyDeviceToHost);
   cudaFree(m_dData);
   m_dData = NULL;
}
else
{
//do other stuff
}

Basically trying to cudaHostAlloc 4MB into the newAddress is just throwing the exception and I cannot fathom why?

Cheers,
Tiomat

Your if statement appears to be missing a close parenthesis.

Is there a reason you think you want to use write-combined memory? It should not be necessary for typical usage.

Beyond that, we’ll need some more information, because your code works correctly for me.

What do you mean by “throwing an access violation”? Do you mean that the call to cudaHostAlloc is returning an error? Can you provide a simple, complete application that demonstrates the error? What operating system are you using, and are you compiling a 32 or 64 bit code?