cudaMalloc() 是否将数组初始化为 0?

Does cudaMalloc() initialize the array to 0?

或者如果我想确保数组包含全0,我是否需要执行cudaMemset()?我在文档中找不到它。 谢谢。

cudaMalloc documentation 说:

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.

所以,你需要cudaMemset初始化内存。