how to return a float value from device

Hi,

I am using GPU to play with an array. Did some calculation and get the average value of the array.

Now how can I return this average value to the host?

I tried

[codebox]cudaMemcpy(aver_d, aver_h, sizeof(float), cudaMemcpyHostToDevice);

cudaMemcpy(aver_h, aver_d, sizeof(float), cudaMemcpyDeviceToHost);[/codebox]

but I got error as

[codebox]argument of type “float” is incompatible with parameter of type “void *”[/codebox]

Thanks,

Yuping

I’ll assume aver_d and aver_h are defined as type “float”. In this case, you need to specify them as a pointer and cast cast to void*:

cudaMemcpy((void*)&aver_d, (void*)&aver_h …

Hope this helps,

Peter

I tried this before, but failed. I moved the calculation of average to the host side at last.

Anyway, thanks a lot!

Yuping

The return typr of kernel is void( returning nothing) U have to write the value to a global mem, I suppose