cudaMemset for Initialization
Zeroing or filling device buffers.
Fresh Memory Is Dirty
A buffer from cudaMalloc holds leftover bytes, not zeros. Before you trust it, you often want to initialize the whole thing. 🧼
Meet cudaMemset
cudaMemset fills a device buffer with one repeated byte value. It is the GPU cousin of the C library memset.
cudaMemset(d_data, 0, n * sizeof(float));All lessons in this course
- cudaMalloc and cudaFree
- Pointers to GPU Memory
- cudaMemset for Initialization
- Avoiding Leaks and Double-Frees