cudaFree with __device__ variables

I have a program structured below to minimize memory allocation on a C870

///////////////////////////////////////////

device float* array;

main()
{
AllocateMemory();

  //main calculations

 DeallocateMemory();

}

//////////////////////////////////////////

NB the declaration of array

In AllocateMemory I call cudaMalloc to allocate memory on the device for array, and it works with the calculations. But when I call cudaFree in DeallocateMemory I get a launch failure error message.

Why?

Where should I declare array in order for this to work?

You cannot do “cudaMalloc” with a device pointer. You have to use a host pointer for it. and then cudaMemcpyToSymbol() function to copy that pointer to the device pointer.

Ricky Ponting