GPU Programming
A program that launches a very small kernel thousands of times in a row is slow. What is the most suitable improvement?
- AReduce the number of launches, for example by fusing several small kernels into one
- BInsert delays between kernel launches
- CUse one thread per block
Show answer and explanation
Answer: A. Reduce the number of launches, for example by fusing several small kernels into one
Each kernel launch costs a fixed few microseconds of CPU-side processing and GPU setup. If the kernel body is shorter than that, launch overhead dominates. Fusing several operations into one kernel reduces launches and also avoids writing intermediate results to memory and reading them back. Mechanisms that record a sequence of launches and submit them at once, such as CUDA Graphs, are also used.
- A. Correct. It reduces fixed per-launch overhead.
- B. Adding delays makes it slower still.
- C. That throws away the GPU's parallelism.