0PricingLogin
CUDA Academy · Lesson

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

  1. cudaMalloc and cudaFree
  2. Pointers to GPU Memory
  3. cudaMemset for Initialization
  4. Avoiding Leaks and Double-Frees
← Back to CUDA Academy