0Pricing
CUDA Academy · Lesson

printf Inside a Kernel

Seeing output from device threads.

Printing from the GPU

Believe it or not, you can call printf right inside a kernel. It is the simplest way to peek at what your threads are doing. 👀

__global__ void hi() {
    printf("Hello from the GPU\n");
}

Every Thread Prints

Remember the kernel runs in every thread, so a single printf line fires once per thread. Launch 256 threads and you get 256 lines.

hi<<<1, 256>>>(); // 256 hellos

All lessons in this course

  1. Anatomy of a Kernel
  2. The Triple-Angle-Bracket Launch
  3. printf Inside a Kernel
  4. cudaDeviceSynchronize Explained
← Back to CUDA Academy