Initilize Array to Zero


Is there anyway to initialize array elements to zero automatically when using cudamalloc or we need to handle that by our own?

thank you

There is no CUDA equivalent of calloc(), but there is cudaMemset(), which will do what you want reasonably efficiently.

thanks for the reply… seems like cudamemset is for int types. i have a float3 1D array which in need to initialize all elements to 0.0f. Can this be done?

Yes, you can use cudaMemset() for that. The size argument just needs to be sizeof(float3)*N. That will put 0 into every byte, which is the equivalent of setting every float3 to {0.f,0.f,0.f}.