What happens when you run a CUDA kernel?

273 points · 31 comments on HN · read original →

Points and comments are a snapshot, not live.

A deep dive into the software and hardware path of a CUDA kernel from source to GPU execution.

The article traces a simple CUDA vector addition kernel through the nvcc compilation pipeline (PTX, SASS, fatbin), host launch stub, and driver interaction via ioctl. It explains how the driver loads the kernel code, packs arguments into a constant bank, and writes a QMD launch descriptor into a pushbuffer. The GPU's host engine is notified via a memory-mapped doorbell register. The article includes strace output and disassembly, covering the GPFIFO, USERD, and work distribution.

It also notes that CUDA 12.2 made module loading lazy by default, deferring SASS upload until the first kernel launch.

What commenters are saying

Commenters praised the article's detailed explanation of the doorbell and QMD, noting it connects CUDA syntax to hardware submission. Several recommended using the driver API instead of the runtime API for better visibility and hot-reloadability, linking wrapper libraries. A sub-thread discussed kernel optimization: some argued that Nvidia driver bugs consume significant engineer time, while others noted that optimization strategies are workload-specific. A minor correction was made regarding control code encoding.