Every kernel launch is an ioctl into ring 0
Tracing one CUDA vadd kernel on an RTX 4090 from nvcc through ioctls and the doorbell register down to warp scheduling on the SMs.
Adding two vectors of a million floats on an RTX 4090 is one line of CUDA, vadd<<<4096, 256>>>(da, db, dc, n). Getting that line to compute 1+1=2 a million times takes tens of millions of CPU instructions, a couple of device files, around nine hundred ioctls, and a single write to a memory-mapped doorbell register. Fergus Finn’s walkthrough follows one vadd kernel from source down to the warps and back up to the answer.
From source to SASS
nvcc is not really a compiler, it is a driver program that runs several and combines their output. Pass --keep and the whole pipeline lands on disk. cicc, an LLVM-based compiler, turns the device code into PTX, and ptxas turns the PTX into SASS, the machine code for the target architecture (sm_89 here).
PTX is a virtual ISA with infinitely many typed registers and no notion of how many the hardware has. It reads more longhand than you would guess. Forming one global address takes three PTX instructions, because CUDA pointers are generic by default and could name global, shared or local memory. cvta.to.global asserts the pointer is global so a cheaper load can be used, mul.wide.s32 turns the index into a byte offset, and add.s64 adds it to the base. ptxas collapses all of that for the real hardware. Ten-odd virtual registers become seven named ones (ncu reports 16 registers per thread once the ABI and alignment are counted), the two multiply-and-add sequences fuse into a single IMAD.WIDE, and the cvta conversions disappear into the addressing.
The kernel arguments do not travel on a stack. They sit in constant bank 0, a small driver-managed region, at fixed offsets: the pointers a, b and c at 0x160, 0x168 and 0x170, the size n at 0x178, with the launch geometry alongside. Every thread reads the identical pointers, so the constant cache serves all 32 lanes of a warp in one shot.
What nvcc emits is a single host executable with the GPU code nested inside it. The SASS lives in a cubin, which is an ordinary ELF object, the same container Linux uses for executables and shared libraries. The cubin plus a compressed copy of the PTX form a fatbin, and the fatbin occupies .nv_fatbin and related sections inside the host ELF. The SASS is what runs on this 4090; the PTX rides along so the driver can JIT fresh SASS if you take the binary to an architecture the cubin does not cover.
Crossing into the kernel driver
On the host side, cudafe++ inserts a hidden constructor that runs before main and registers the embedded fatbin, mapping the host-side vadd function pointer to the kernel’s mangled device name. The <<<>>> expression becomes a launch stub that packs the arguments into a host buffer at offsets 0, 8, 16 and 24 (the same values that land at 0x160 onward in constant bank 0) and calls __cudaLaunch with the address of the empty host vadd as a lookup key. The runtime resolves that key to the device symbol and crosses into the closed-source user-mode driver, libcuda.so.1 (here libcuda.so.590.48.01).
Since CUDA 12.2 module loading is lazy by default. The driver does not upload a kernel’s SASS to the card until the first time that specific kernel launches. That keeps first-launch cost off startup; set CUDA_MODULE_LOADING=EAGER if you would rather pay it up front.
Under libcuda sits the kernel-mode driver, nvidia.ko, reached by ioctl on device files. This is where the roughly nine hundred ioctls go. A GPU does not take function calls. It sits across PCIe and reads a stream of commands out of host memory. The structures carrying those commands make up a channel. The pushbuffer holds methods, each a GPU register address paired with a value. The GPFIFO is a ring of pointers into the pushbuffer, and two cursors track it: GP_PUT (how far the driver has written) and GP_GET (how far the GPU has read), both in a per-channel USERD structure.
To launch, the driver streams a Queue Meta Data block (the QMD) into the pushbuffer with SET_INLINE_QMD_ADDRESS and a run of LOAD_INLINE_QMD_DATA. The QMD is the launch descriptor: grid and block dimensions (the 4096 and 256), registers and shared memory per thread, the address of the SASS, and the address of the constant bank holding the arguments. The driver points a GPFIFO entry at the span and advances GP_PUT.
On Turing and later the host engine no longer snoops USERD, so advancing GP_PUT does nothing until the engine is told to look. It is told through the doorbell. The GPU maps a small window of its registers into the process, and the driver writes the channel’s work-submit token there. That write is the submit, a store to a mapped register rather than a syscall. The host engine reads GP_PUT, walks to the pushbuffer span, DMAs the methods out, and hands the QMD to the compute work distributor. cuLaunchKernel returned the moment the doorbell rang; the call is asynchronous, so the CPU runs on while the kernel does.
On the card
The RTX 4090 is NVIDIA’s AD102-300-A1 with 128 SMs enabled (16 of the 144 physical SMs fused off for yield). The compute work distributor keeps all 128 busy. The SASS sits as one linear sequence in VRAM; each SM caches it locally, and since Volta every thread carries its own program counter, though issue is still per warp.
Occupancy here is bound by thread count, not registers. Each SM caps at 1,536 active threads and has a 65,536-register file. At 256 threads per block and 16 registers per thread, registers alone would allow 16 resident blocks, but the 1,536-thread cap allows only 6. So each SM holds 6 blocks, 48 warps, spread evenly across four sub-partitions, giving each of the four schedulers 12 warps to choose from. Every cycle a scheduler picks one eligible warp and dispatches across 32 lanes.
Eligibility is mostly decided ahead of time. A GPU hides latency by switching between resident warps rather than reordering one thread’s instructions, so the compiler schedules the timing it can predict and the hardware falls back to lightweight scoreboards for the rest. Every 128-bit SASS instruction carries control bits from ptxas: a static stall count for fixed-latency math, telling the scheduler how many cycles to park the warp before its next instruction, and a yield hint telling it whether to hand scheduling priority to another warp.
Keep Reading
post-quantum-cryptographyCloudflare moves its post-quantum deadline up to 2027
Cloudflare moved its fully post-quantum deadline to 2027, with encryption largely done and authentication via Merkle Tree Certificates still in flight.
CODESYSCODESYS disclosed a no-password code-execution flaw this week
CVE-2026-127148 (CVSS 9.8) lets an attacker run code on CODESYS Control PLC runtimes unauthenticated, needing only network reach to the online services.
app store securityApple pulled 19 fake Meta apps on December 2
Fake Meta Ads Manager apps passed App Store review with a decoy, flipped on a hidden Facebook login after approval, and bought Apple's top search ad.
Latest on the Wire
Full wire →- Acronis Backup Flaw Actively Exploited in Targeted AttacksBleepingComputer
- Active Exploitation of Patched Veeam Console Flaws ConfirmedBleepingComputer
- AI-Powered Attack Exposes DoorDash User DataBleepingComputer
- AI Removes the Easy Work. That's the Hard Part.Hacker News
New signal daily · RSS
Stay in the loop
New writing delivered when it's ready. No schedule, no spam.