GPU Programming
In CUDA, what generally happens right after the CPU-side program launches a kernel?
- AThe CPU always halts and can do nothing until the kernel finishes
- BThe kernel runs on the CPU
- CThe launch is asynchronous, so the CPU proceeds without waiting for the kernel to finish and must synchronize before using the results
Show answer and explanation
Answer: C. The launch is asynchronous, so the CPU proceeds without waiting for the kernel to finish and must synchronize before using the results
A kernel launch merely appends work to the GPU's command queue, and control returns to the CPU immediately. The CPU can therefore prepare the next data while the GPU computes. Before reading results on the CPU, however, it must confirm the kernel has finished, with cudaDeviceSynchronize or a copy of the results (which, in the same stream, waits for prior work). Timing measurements likewise need synchronization to capture kernel time correctly.
- A. The launch call returns immediately.
- B. The kernel runs on the GPU.
- C. Correct. The CPU can do other work in the meantime.