Search code examples
c++ccudamallocmemset

Does cudaMalloc() initialize the array to 0?


Or do I need to perform cudaMemset() if I want to make sure the array contains all 0? I can't find it in the documentation. Thank you.


Solution

  • The cudaMalloc documentation says:

    Allocates size bytes of linear memory on the device and returns in *devPtr a pointer to the allocated memory. The allocated memory is suitably aligned for any kind of variable. The memory is not cleared.

    So, you will need cudaMemset to initialize the memory.