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 hellosAll lessons in this course
- Anatomy of a Kernel
- The Triple-Angle-Bracket Launch
- printf Inside a Kernel
- cudaDeviceSynchronize Explained