interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / docs / GPU_DRIVER.md

113 lines · 8295 bytes Raw Blame History Rendered
1# My own GPU driver for the Spark (GB10)
2
3Written for Drake. Ledger L332. Status at the bottom; every number has its source next to it.
4
5## What a GPU driver does here
6
7The GB10 graphics chip is a separate computer inside the Spark. It has its own small processor (NVIDIA calls it GSP)
8that runs NVIDIA's own program, and it has job queues my code fills with work. A driver is the software on the main
9processor that:
10
111. wakes the chip up and starts the chip's small processor with NVIDIA's program,
122. sets up memory so the chip and the main processor see the same model weights,
133. opens a job queue (a "channel") and tells the chip where it is,
144. after that, stays out of the way while my code puts work in the queue and rings a doorbell.
15
16Today NVIDIA's open-source Linux driver (two main pieces, `nvidia.ko` and `nvidia-uvm.ko`, plus two display pieces,
17`nvidia_modeset` and `nvidia_drm`) does steps 1 to 3. Omega and physics already do step 4 themselves: they write the
18work into the queue and ring the doorbell straight from my own program, with no call into the driver at all
19(physics nvrm/nvrm.c: the doorbell is a single memory write to a page the driver handed me once).
20
21## What NVIDIA's driver costs me today
22
23Rung 0 measures it. Results go in evidence/own-gpu-driver/rung0/ with the table below filled from them.
24
25| What | Today with NVIDIA | Source |
26|---|---|---|
27| Driver calls per generated word | expected zero (work submit never calls the driver) | rung 0 cell (a), pending the window |
28| Processor time the driver burns while idle | the display piece spins one core forever on this headless box | L158; rung 0 idle cells |
29| Start-up calls before the first job | pending | rung 0 strace cell |
30| Time to load the driver and wake the chip | not measured (never reloaded since boot) | rung 2 window 0, step 6 |
31
32## What mine does instead
33
34The driver core is written as device contracts: short, checked descriptions of the chip (registers, job queues, the
35order things must happen in) that my compiler (`crates/aienos-devc`, ADR 0021) turns into C code. The first one is the
36job queue: `native/kernel/gpu/contract/gb10_chan.devc`. Every number in it is tied to a quoted line of NVIDIA's own
37source. The compiler refuses a contract that would be unsafe on the chip, for example one that rings the doorbell before
38the work is published, forgets the memory barrier between the two, lets the queue overflow, or keeps memory in the
39chip's cache that the main processor writes while the chip reads it (the mistake that cost two days in October).
40
41The generated code has to behave exactly like the hand-written version from L193: same 225 checks, and a side-by-side
42trace of every register write and the whole simulated memory after each of about 330 operations must match byte for byte.
43
44The second contract is the chip start-up: `native/kernel/gpu/contract/gb10_gsp.devc`. It describes the eleven register
45steps that hand NVIDIA's signed start-up package to the chip's security processor (SEC2), wait for it to check and start
46the chip's own operating program, and confirm that program is running. The compiler refuses a start-up that writes the
47package while an older message is still there, rings the bell before the message is complete, touches the chip's main
48processor before the security processor releases it, or waits on anything without a time limit. A hand-written version
49(`native/kernel/gpu/gsp_mmio.c`) runs against a simulated security processor; the generated one must pass the same 67
50checks and make the very same register accesses in 16 scenarios, including every way the start-up can fail. Twenty
51deliberate small errors in each version are all caught. None of this has run on the chip yet.
52
53On Linux, a small add-on module `aien-gpu` (native/linux/aien-gpu) will host that core in place of NVIDIA's driver.
54Its first version only reads the chip's identity, loads NVIDIA's firmware file and sets up one big shared memory area;
55it binds to the chip only when told to, after NVIDIA's driver is gone.
56
57## What stays on loan from NVIDIA, and why
58
59The chip's small processor only runs a program signed by NVIDIA. A security block on the chip checks the signature before
60it lets that program start (on the GB10 that is the SEC2 processor; this chip has no FSP), and I do not have NVIDIA's
61signing key. So these files stay NVIDIA's, loaded the way
62I load model weights, named here:
63
641. `gsp_ga10x.bin` (75,012,080 bytes, /lib/firmware/nvidia/580.173.02/), the chip's operating program.
652. The GSP boot loader and the signed first-stage loader (FMC) for GB10B, which ship inside nvidia.ko as embedded data
66 (g_bindata_kgspGetBinArchiveGspRmBoot_GB10B.c, GspRmFmcGfwProdSigned_GB10B.c in the open driver source), together with
67 the hash, signature and public key the driver hands to the security processor in one 868-byte message.
68
69Everything on the main processor side becomes mine. If evidence ever shows the signature check can be satisfied another
70way, it goes in as an open question with an experiment, and nothing is tried that could damage the chip.
71
72## The rungs
73
740. Measure what NVIDIA's driver costs (above).
751. The driver core in my contract language, proven on the simulator (job queue and chip start-up done; next the
76 shared memory area the chip program needs and the first message exchange with it).
772. Run it on the real chip under Linux, in a window the coordinator schedules, because it takes the GPU away from
78 everything else for a while. Window 0 only reads the chip and gives it back (evidence/own-gpu-driver/rung2/RUNBOOK.md).
79 Window 1, after window 0 passes, starts NVIDIA's signed chip program with my own code: my small Linux module lets
80 my start-up tool touch only the 12 start-up registers (6 of them writable) and ring the security processor once;
81 the tool builds the start-up package, hands it over and waits for the chip program to say it is ready. Every
82 register access is recorded with its time. The one real risk: if the restart afterwards does not fully reset the
83 GPU, it needs a power cycle at the wall before NVIDIA's driver works again. Status 2026-10-22: window 1 is built
84 and passes its 56 simulator checks, with the real firmware package checked against its pinned fingerprints; it waits
85 for window 0. Still open until it runs: whether the chip program asks my side to run a short list of chores before
86 it says it is ready (if so, window 1 records the request and stops there).
873. The same core inside my own operating system on the Spark, once that boots natively (L318).
88
89## Known unknowns (tested on the chip, never assumed)
90
91- How the GB10 makes a channel runnable without NVIDIA's chip program: today the chip program does it on request.
92- The doorbell's address on the chip when NVIDIA's driver is not there to hand me the page.
93- Whether the main processor may write the address-translation flush register directly.
94- GB10B keeps some cache lines "sticky" until flushed (uvm_gpu.h:1135, NVIDIA bug 4577236, fixed only in later chips):
95 memory the main processor polls must be set up uncached; the contract compiler enforces that rule.
96
97## The CPU sequencer
98
99NVIDIA's driver runs a short program the chip sends back (`kgspExecuteSequencerBuffer` in
100kernel_gsp.c of open-gpu-kernel-modules 580.173.02): register write, modify, poll, a delay, a
101save, and four core operations. That program is now mine (`native/kernel/gpu/gsp_seq.c`). It
102refuses an unknown opcode, a short payload, a save index of 8 or more, and any core operation
103unless the caller supplies the callback, because those restart the chip. A copy with the save-index
104check removed fails the test. The window-1 simulator runs a register-write sequencer and then
105reaches INIT-DONE; an empty sequencer request still stops, as before. This has not run on the chip.
106The live `nvidia.ko` is not replaced by this commit.
107
108## Status
109
110Hardware status of every rung, with receipts: the register [hardware-gates.tsv](hardware-gates.tsv)
111(rows AX-GSP-C and OGD-*), explained in [HARDWARE_GATES.md](HARDWARE_GATES.md). A physical row
112there says PASS only once an attended run on the GB10 has committed its receipt. The historical handoff ~/handoffs/2026-10-21-own-gpu-driver.md and ledger line
113L332 are operator-local and are not evidence.