cudaDeviceSynchronize Explained
Why the CPU must wait for the GPU.
The CPU Does Not Wait
After a launch, the CPU rushes ahead while the GPU is still working. To pause and wait, you call cudaDeviceSynchronize. ⏳
myKernel<<<g, b>>>(p);
cudaDeviceSynchronize();What Synchronize Means
cudaDeviceSynchronize blocks the host until every queued GPU task has finished. Only then does your next CPU line run.
All lessons in this course
- Anatomy of a Kernel
- The Triple-Angle-Bracket Launch
- printf Inside a Kernel
- cudaDeviceSynchronize Explained