CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / tools / figures / make_figures.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """Draw the README figures (docs/img/*.svg) from this repository's own data. |
| 4 | |
| 5 | Run from the repository root: python3 tools/figures/make_figures.py |
| 6 | Check they are current: python3 tools/figures/make_figures.py --check |
| 7 | |
| 8 | Nothing here is drawn by an image generator. The machine-code figures read the |
| 9 | instruction words straight out of src/omega_blackwell_encoder.c and decode them |
| 10 | with the field positions my encoder uses (src/omega_blackwell_codegen.c, |
| 11 | "Control words"). The numbers on the other figures are the receipts named on |
| 12 | each figure. Colours are the aienos.com "Turing look" tokens. |
| 13 | """ |
| 14 | import os |
| 15 | import re |
| 16 | import sys |
| 17 | from html import escape |
| 18 | |
| 19 | ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) |
| 20 | OUT = os.path.join(ROOT, "docs", "img") |
| 21 | |
| 22 | # ---- Turing look tokens (aienos.com public/assets/turing-look.css) ---------------- |
| 23 | BG, CARD, CARD2 = "#08090c", "#0e1219", "#131822" |
| 24 | LINE, LINE2 = "#1c2536", "#2a3648" |
| 25 | INK, INK2, INK3 = "#f1f5f9", "#94a3b8", "#64748b" |
| 26 | BLUE, BLUE_SOFT, GREEN = "#2d7ff9", "#7db4ff", "#00e599" |
| 27 | AMBER, VIOLET, ROSE, CYAN = "#f59e0b", "#a78bfa", "#fb7185", "#22d3ee" |
| 28 | |
| 29 | SANS = "Inter, ui-sans-serif, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif" |
| 30 | MONO = "ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace" |
| 31 | |
| 32 | |
| 33 | # ---- tiny SVG writer --------------------------------------------------------------- |
| 34 | class Svg: |
| 35 | def __init__(self, w, h, title, desc): |
| 36 | self.w, self.h = w, h |
| 37 | self.parts = [] |
| 38 | self.title, self.desc = title, desc |
| 39 | |
| 40 | def add(self, s): |
| 41 | self.parts.append(s) |
| 42 | |
| 43 | def rect(self, x, y, w, h, fill="none", stroke="none", rx=0.0, sw=1.0, op=1.0, dash=None, extra=""): |
| 44 | d = f' stroke-dasharray="{dash}"' if dash else "" |
| 45 | o = f' opacity="{op}"' if op != 1 else "" |
| 46 | self.add(f'<rect x="{x:.1f}" y="{y:.1f}" width="{w:.1f}" height="{h:.1f}" rx="{rx}" ' |
| 47 | f'fill="{fill}" stroke="{stroke}" stroke-width="{sw}"{d}{o}{extra}/>') |
| 48 | |
| 49 | def text(self, x, y, s, size=16.0, fill=INK, weight=400, anchor="start", mono=False, op=1.0, ls=None, italic=False, strike=False): |
| 50 | fam = MONO if mono else SANS |
| 51 | size = max(size, 12.5) # README width scales figures to about 0.73: keep the smallest text readable |
| 52 | o = f' opacity="{op}"' if op != 1 else "" |
| 53 | l = f' letter-spacing="{ls}"' if ls is not None else "" |
| 54 | it = ' font-style="italic"' if italic else "" |
| 55 | it += ' text-decoration="line-through"' if strike else "" |
| 56 | self.add(f'<text x="{x:.1f}" y="{y:.1f}" font-family="{fam}" font-size="{size}" font-weight="{weight}" ' |
| 57 | f'fill="{fill}" text-anchor="{anchor}"{o}{l}{it}>{escape(s)}</text>') |
| 58 | |
| 59 | def lines(self, x, y, rows, size=15.0, fill=INK2, gap=None, **kw): |
| 60 | gap = gap or size * 1.4 |
| 61 | for i, r in enumerate(rows): |
| 62 | self.text(x, y + i * gap, r, size=size, fill=fill, **kw) |
| 63 | |
| 64 | def line(self, x1, y1, x2, y2, stroke=LINE2, sw=1.5, dash=None, arrow=False, op=1.0): |
| 65 | d = f' stroke-dasharray="{dash}"' if dash else "" |
| 66 | a = ' marker-end="url(#arrow)"' if arrow else "" |
| 67 | o = f' opacity="{op}"' if op != 1 else "" |
| 68 | self.add(f'<line x1="{x1:.1f}" y1="{y1:.1f}" x2="{x2:.1f}" y2="{y2:.1f}" stroke="{stroke}" ' |
| 69 | f'stroke-width="{sw}"{d}{a}{o}/>') |
| 70 | |
| 71 | def path(self, d, stroke=LINE2, sw=1.5, fill="none", arrow=False, dash=None, op=1.0): |
| 72 | a = ' marker-end="url(#arrow)"' if arrow else "" |
| 73 | ds = f' stroke-dasharray="{dash}"' if dash else "" |
| 74 | o = f' opacity="{op}"' if op != 1 else "" |
| 75 | self.add(f'<path d="{d}" stroke="{stroke}" stroke-width="{sw}" fill="{fill}"{a}{ds}{o}/>') |
| 76 | |
| 77 | def circle(self, x, y, r, fill=INK, stroke="none", sw=1.0): |
| 78 | self.add(f'<circle cx="{x:.1f}" cy="{y:.1f}" r="{r}" fill="{fill}" stroke="{stroke}" stroke-width="{sw}"/>') |
| 79 | |
| 80 | def pill(self, x, y, label, color, size=13.0, h=24.0, filled=False, w=None): |
| 81 | w = w or (len(label) * size * 0.62 + 22) |
| 82 | if filled: |
| 83 | self.rect(x, y, w, h, fill=color, rx=h / 2, op=0.16) |
| 84 | self.rect(x, y, w, h, stroke=color, rx=h / 2, sw=1, op=0.7) |
| 85 | else: |
| 86 | self.rect(x, y, w, h, stroke=color, rx=h / 2, sw=1.2) |
| 87 | self.text(x + w / 2, y + h / 2 + size * 0.36, label, size=size, fill=color, weight=600, anchor="middle", |
| 88 | mono=True) |
| 89 | return w |
| 90 | |
| 91 | def kicker(self, x, y, s, color=BLUE_SOFT): |
| 92 | self.text(x, y, s.upper(), size=14, fill=color, weight=600, mono=True, ls=1.5) |
| 93 | |
| 94 | def frame(self): |
| 95 | self.rect(0.5, 0.5, self.w - 1, self.h - 1, fill=BG, stroke=LINE, rx=22) |
| 96 | self.rect(0.5, 0.5, self.w - 1, self.h - 1, fill="url(#glow)", rx=22) |
| 97 | |
| 98 | def svg(self): |
| 99 | head = (f'<svg xmlns="http://www.w3.org/2000/svg" width="{self.w}" height="{self.h}" ' |
| 100 | f'viewBox="0 0 {self.w} {self.h}" role="img" aria-labelledby="t d">' |
| 101 | f'<title id="t">{escape(self.title)}</title><desc id="d">{escape(self.desc)}</desc>' |
| 102 | '<defs>' |
| 103 | '<radialGradient id="glow" cx="22%" cy="-10%" r="85%">' |
| 104 | f'<stop offset="0" stop-color="{BLUE}" stop-opacity="0.16"/>' |
| 105 | f'<stop offset="0.55" stop-color="{BLUE}" stop-opacity="0.03"/>' |
| 106 | f'<stop offset="1" stop-color="{BLUE}" stop-opacity="0"/></radialGradient>' |
| 107 | '<radialGradient id="glow2" cx="92%" cy="8%" r="45%">' |
| 108 | f'<stop offset="0" stop-color="{GREEN}" stop-opacity="0.08"/>' |
| 109 | f'<stop offset="1" stop-color="{GREEN}" stop-opacity="0"/></radialGradient>' |
| 110 | '<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" ' |
| 111 | f'orient="auto-start-reverse"><path d="M0 0 L10 5 L0 10 z" fill="{INK2}"/></marker>' |
| 112 | '</defs>') |
| 113 | return head + "".join(self.parts) + "</svg>\n" |
| 114 | |
| 115 | |
| 116 | def card(s, x, y, w, h, accent=None, fill=CARD, rx=16.0, sw=1.0, dash=None): |
| 117 | s.rect(x, y, w, h, fill=fill, stroke=accent or LINE2, rx=rx, sw=sw, dash=dash) |
| 118 | |
| 119 | |
| 120 | # ---- the first kernel's words, read from the encoder source ------------------------ |
| 121 | def vecadd_words(): |
| 122 | src = open(os.path.join(ROOT, "src", "omega_blackwell_encoder.c")).read() |
| 123 | rows = re.findall(r'/\* ([0-9a-f]{4}) \*/ \{ \{ (0x[0-9a-f]+), (0x[0-9a-f]+), (0x[0-9a-f]+), (0x[0-9a-f]+) \}, ' |
| 124 | r'"([^"]+)" \}', src) |
| 125 | if len(rows) != 32: |
| 126 | sys.exit(f"expected 32 vecadd instructions in src/omega_blackwell_encoder.c, found {len(rows)}") |
| 127 | out = [] |
| 128 | for addr, w0, w1, w2, w3, mn in rows: |
| 129 | w = [int(v, 16) for v in (w0, w1, w2, w3)] |
| 130 | bits = w[0] | (w[1] << 32) | (w[2] << 64) | (w[3] << 96) |
| 131 | out.append({"addr": addr, "w": w, "bits": bits, "mn": mn, **decode_control(w[3])}) |
| 132 | return out |
| 133 | |
| 134 | |
| 135 | def decode_control(w3): |
| 136 | # src/omega_blackwell_codegen.c, "Control words": stall = bits 9..12 of w[3], yield = 13, |
| 137 | # write barrier = 14..16, read barrier = 17..19, wait mask = 20..25; 7 in a barrier field means none. |
| 138 | return {"stall": (w3 >> 9) & 0xF, "yield": (w3 >> 13) & 1, "wbar": (w3 >> 14) & 7, |
| 139 | "rbar": (w3 >> 17) & 7, "wait": [i for i in range(6) if (w3 >> (20 + i)) & 1], |
| 140 | "reuse": (w3 >> 26) & 0xF} |
| 141 | |
| 142 | |
| 143 | # Bit fields as drawn (bit 0 = lowest bit of word 0). |
| 144 | FIELDS = [ # (lo, hi, name, colour) |
| 145 | (0, 11, "opcode and operand form", BLUE), |
| 146 | (12, 15, "guard predicate", VIOLET), |
| 147 | (16, 31, "destination and first source register", GREEN), |
| 148 | (32, 63, "second source: register, immediate or constant address", CYAN), |
| 149 | (64, 104, "third source, predicate operands, modifiers", INK2), |
| 150 | (105, 127, "scheduling: stall, yield, scoreboards, reuse", AMBER), |
| 151 | ] |
| 152 | |
| 153 | |
| 154 | def field_colour(b): |
| 155 | for lo, hi, _, c in FIELDS: |
| 156 | if lo <= b <= hi: |
| 157 | return c |
| 158 | return INK2 |
| 159 | |
| 160 | |
| 161 | def short_mn(mn): |
| 162 | pred = "" |
| 163 | if mn.startswith("@"): |
| 164 | pred, mn = mn.split(" ", 1) |
| 165 | pred += " " |
| 166 | return pred + mn.split(" ")[0] |
| 167 | |
| 168 | |
| 169 | # ---- figure 1: hero ------------------------------------------------------------------ |
| 170 | def fig_hero(words): |
| 171 | s = Svg(1280, 680, "CUDA++ for the NVIDIA DGX Spark (GB10, sm_121): my own path from a program to the GPU", |
| 172 | "Title, the supported hardware (the GB10 in the NVIDIA DGX Spark), three measured facts, and the 32 " |
| 173 | "instructions of the first kernel CUDA++ ran, drawn bit by bit from src/omega_blackwell_encoder.c.") |
| 174 | s.frame() |
| 175 | s.rect(0.5, 0.5, s.w - 1, s.h - 1, fill="url(#glow2)", rx=22) |
| 176 | s.kicker(64, 92, "NVIDIA DGX Spark · GB10 · sm_121") |
| 177 | s.text(58, 196, "CUDA++", size=104, weight=800, ls=-3) |
| 178 | s.lines(64, 250, ["For the NVIDIA DGX Spark (GB10, sm_121): my own", |
| 179 | "machine code, runtime, libraries and driver client.", |
| 180 | "No CUDA toolkit, no nvcc, no PTX, no libcuda."], size=22, fill=INK2, gap=32) |
| 181 | facts = [("0", GREEN, "CUDA libraries loaded in the live", "35B model server (2026-10-21)"), |
| 182 | ("115.14", GREEN, "TFLOPS tensor-core peak, measured", "by my own probe kernel"), |
| 183 | ("59", GREEN, "instruction kinds my encoder", "writes for sm_121")] |
| 184 | for i, (num, col, l1, l2) in enumerate(facts): |
| 185 | y = 372 + i * 80 |
| 186 | card(s, 64, y, 500, 66, fill=CARD) |
| 187 | s.rect(64, y, 4, 66, fill=col, rx=2) |
| 188 | s.text(88, y + 44, num, size=34, weight=800, fill=col, ls=-1) |
| 189 | s.lines(232, y + 28, [l1, l2], size=16, fill=INK2, gap=21) |
| 190 | |
| 191 | x0, y0, cw, rh = 620, 168, 3.4, 13.5 |
| 192 | s.kicker(x0, 92, "the first kernel: vector add", INK2) |
| 193 | s.text(x0, 116, "32 instructions × 128 bits, every bit written by my encoder", size=15, fill=INK3) |
| 194 | for i, (lo, hi, name, col) in enumerate(FIELDS): |
| 195 | label = {BLUE: "opcode", VIOLET: "predicate", GREEN: "registers", CYAN: "operand", |
| 196 | INK2: "modifiers", AMBER: "scheduling"}[col] |
| 197 | lx = x0 + i * 100 |
| 198 | s.rect(lx, 133, 10, 10, fill=col, rx=2) |
| 199 | s.text(lx + 15, 142, label, size=13, fill=INK2) |
| 200 | for r, ins in enumerate(words): |
| 201 | y = y0 + r * rh |
| 202 | nop = ins["mn"] == "NOP" |
| 203 | for lo, hi, _, col in FIELDS: |
| 204 | s.rect(x0 + lo * cw, y, (hi - lo + 1) * cw - 0.8, rh - 3, fill=col, op=0.07 if not nop else 0.04) |
| 205 | for b in range(128): |
| 206 | if (ins["bits"] >> b) & 1: |
| 207 | s.rect(x0 + b * cw, y, cw - 0.8, rh - 3, fill=field_colour(b), op=0.95 if not nop else 0.35) |
| 208 | s.text(x0 + 128 * cw + 14, y + rh - 4.5, ins["addr"], size=11.5, fill=INK3, mono=True) |
| 209 | s.text(x0 + 128 * cw + 52, y + rh - 4.5, short_mn(ins["mn"]), size=11.5, fill=INK2 if not nop else INK3, |
| 210 | mono=True, op=1 if not nop else 0.6) |
| 211 | for b in (0, 32, 64, 96, 127): |
| 212 | s.line(x0 + b * cw + cw / 2, y0 + 32 * rh - 1, x0 + b * cw + cw / 2, y0 + 32 * rh + 4, stroke=INK3, sw=1) |
| 213 | s.text(x0 + b * cw + cw / 2, y0 + 32 * rh + 17, str(b), size=11, fill=INK3, anchor="middle", mono=True) |
| 214 | s.text(x0, y0 + 32 * rh + 40, "bit 0 to bit 127 of each instruction · lit = 1 · src/omega_blackwell_encoder.c", |
| 215 | size=13, fill=INK2, mono=True) |
| 216 | return s |
| 217 | |
| 218 | |
| 219 | # ---- figure 2: the two stacks ---------------------------------------------------------- |
| 220 | def fig_stack(): |
| 221 | s = Svg(1200, 930, "CUDA and CUDA++, layer by layer", |
| 222 | "Left: the NVIDIA CUDA stack. Right: CUDA++. The four closed layers above the kernel module are " |
| 223 | "replaced by my own code; the open kernel module is NVIDIA's until my own GB10 driver replaces it, " |
| 224 | "and the signed GPU firmware stays NVIDIA's.") |
| 225 | s.frame() |
| 226 | s.kicker(48, 60, "the stack") |
| 227 | s.text(48, 100, "What runs between your program and the GPU", size=30, weight=800, ls=-0.5) |
| 228 | lx, rx, cw, mid = 48, 664, 488, 600 |
| 229 | s.text(lx, 150, "CUDA", size=22, weight=700, fill=INK2) |
| 230 | s.text(rx, 150, "CUDA++", size=22, weight=700, fill=GREEN) |
| 231 | rows = [ |
| 232 | ("program", ("Your program", "CUDA C++ kernels and host code"), |
| 233 | ("Your program", "C calls to the kernel builder; Omega's languages next (bar C1)")), |
| 234 | ("closed", ("nvcc · NVVM · PTX · ptxas", "compiler, closed"), |
| 235 | ("Kernel builder · allocator · sm_121 encoder", "src/omega_blackwell_codegen*.c, _encoder.c, _qmd.c")), |
| 236 | ("closed", ("cuBLAS · cuDNN · CUB", "maths libraries, closed"), |
| 237 | ("Matmul · attention · MoE · reductions", "src/omega_gpu_*_api.c")), |
| 238 | ("closed", ("libcudart", "runtime API, closed"), |
| 239 | ("Session · command lists · job engine", "src/omega_gpu_session.c, _cmdlist.c, _engine.c")), |
| 240 | ("closed", ("libcuda", "driver API, closed"), |
| 241 | ("Driver client: nvrm + m16", "nvrm/nvrm.c, m16/: ioctls from the open headers")), |
| 242 | ("open", ("nvidia.ko · nvidia-uvm.ko", "NVIDIA's open kernel module"), |
| 243 | ("nvidia.ko · nvidia-uvm.ko, for now", "my own GB10 driver (L332) replaces it; not run on GB10 yet")), |
| 244 | ("fw", ("GSP firmware", "runs inside the GPU, signed by NVIDIA"), |
| 245 | ("GSP firmware", "stays NVIDIA's: the chip checks its signature")), |
| 246 | ("hw", ("NVIDIA GB10 GPU", "DGX Spark, sm_121"), ("NVIDIA GB10 GPU", "DGX Spark, sm_121")), |
| 247 | ] |
| 248 | marks = {"closed": ("replaced", GREEN), "open": ("replacing", VIOLET), "fw": ("stays", AMBER)} |
| 249 | y, rh, gap = 172, 72, 14 |
| 250 | for i, (kind, left, right) in enumerate(rows): |
| 251 | if i == 5: |
| 252 | y += 30 |
| 253 | s.line(36, y - 22, s.w - 36, y - 22, stroke=INK3, sw=1, dash="6 6") |
| 254 | w = 196 |
| 255 | s.rect(mid - w / 2, y - 33, w, 22, fill=BG) |
| 256 | s.text(mid, y - 17, "user space ↑ kernel ↓", size=13, fill=INK2, anchor="middle", mono=True) |
| 257 | # left |
| 258 | if kind == "closed": |
| 259 | card(s, lx, y, cw, rh, accent=LINE2, fill=CARD) |
| 260 | s.text(lx + 22, y + 32, left[0], size=19, weight=650, fill=INK3, strike=True) |
| 261 | s.text(lx + 22, y + 56, left[1], size=14, fill=INK3) |
| 262 | else: |
| 263 | acc = {"program": LINE2, "open": BLUE, "fw": AMBER, "hw": LINE2}[kind] |
| 264 | card(s, lx, y, cw, rh, accent=acc, fill=CARD) |
| 265 | s.text(lx + 22, y + 32, left[0], size=19, weight=650) |
| 266 | s.text(lx + 22, y + 56, left[1], size=14, fill=INK2) |
| 267 | # right |
| 268 | acc = {"program": LINE2, "closed": GREEN, "open": BLUE, "fw": AMBER, "hw": LINE2}[kind] |
| 269 | fill = "#0b1a17" if kind == "closed" else CARD |
| 270 | card(s, rx, y, cw, rh, accent=acc, fill=fill, sw=1.4 if kind == "closed" else 1) |
| 271 | s.text(rx + 22, y + 32, right[0], size=19, weight=650, fill=INK) |
| 272 | s.text(rx + 22, y + 56, right[1], size=14 if kind != "closed" else 13.5, fill=INK2, |
| 273 | mono=(kind in ("closed",))) |
| 274 | if kind in marks: |
| 275 | lab, col = marks[kind] |
| 276 | w = len(lab) * 8.6 + 18 |
| 277 | s.line(lx + cw + 4, y + rh / 2, mid - w / 2, y + rh / 2, stroke=col, sw=1.6, op=0.8) |
| 278 | s.line(mid + w / 2, y + rh / 2, rx - 10, y + rh / 2, stroke=col, sw=1.6, arrow=True, op=0.8) |
| 279 | s.rect(mid - w / 2, y + rh / 2 - 12, w, 24, fill=BG, rx=12) |
| 280 | s.pill(mid - w / 2, y + rh / 2 - 12, lab, col, size=13, w=w, filled=True) |
| 281 | y += rh + gap |
| 282 | ly = y + 16 |
| 283 | for lab, col, x in (("closed, replaced by CUDA++", INK3, 48), ("first-party, Apache-2.0+LLVM", GREEN, 300), |
| 284 | ("NVIDIA open source, being replaced", BLUE, 560), ("NVIDIA signed firmware, stays", AMBER, 840)): |
| 285 | s.rect(x, ly - 11, 14, 14, stroke=col, fill="#0b1a17" if col == GREEN else CARD, rx=3, sw=1.5) |
| 286 | s.text(x + 22, ly + 1, lab, size=14, fill=INK2) |
| 287 | return s |
| 288 | |
| 289 | |
| 290 | # ---- figure 3: one instruction, every bit --------------------------------------------- |
| 291 | def fig_instruction(words): |
| 292 | ins = next(w for w in words if w["mn"].startswith("IADD3")) |
| 293 | s = Svg(1200, 800, "One instruction, all 128 bits: IADD3 R9, PT, PT, R2, R5, RZ", |
| 294 | "The add of vector add, decoded field by field, with its scheduling bits enlarged.") |
| 295 | s.frame() |
| 296 | s.kicker(48, 60, "one instruction, all 128 bits") |
| 297 | s.text(48, 102, "IADD3 R9, PT, PT, R2, R5, RZ", size=32, weight=800, mono=True, ls=-0.5) |
| 298 | s.text(48, 134, f"R9 = R2 + R5: the add in vector add, at offset 0x{ins['addr']}. " |
| 299 | "Sixteen bytes, four 32-bit words.", size=17, fill=INK2) |
| 300 | x0, y0, cw, ch, wg = 56, 196, 8.2, 38, 10 |
| 301 | |
| 302 | def bx(b): |
| 303 | return x0 + b * cw + (b // 32) * wg |
| 304 | |
| 305 | for k in range(4): |
| 306 | s.text(bx(32 * k), y0 - 12, f"word {k} 0x{ins['w'][k]:08x}", size=14, fill=INK2, mono=True) |
| 307 | for b in range(128): |
| 308 | on = (ins["bits"] >> b) & 1 |
| 309 | col = field_colour(b) |
| 310 | s.rect(bx(b), y0, cw - 1.2, ch, fill=col, op=0.95 if on else 0.12, rx=1.5) |
| 311 | for b in (0, 31, 32, 63, 64, 95, 96, 127): |
| 312 | s.text(bx(b) + cw / 2, y0 + ch + 16, str(b), size=11.5, fill=INK3, anchor="middle", mono=True) |
| 313 | |
| 314 | def bracket(lo, hi, row, title, value, col): |
| 315 | x1, x2 = bx(lo) + 1.5, bx(hi) + cw - 2.7 |
| 316 | yb = y0 + ch + 30 + row * 60 |
| 317 | s.path(f"M{x1:.1f} {yb - 6} L{x1:.1f} {yb} L{x2:.1f} {yb} L{x2:.1f} {yb - 6}", stroke=col, sw=1.6) |
| 318 | s.line((x1 + x2) / 2, yb, (x1 + x2) / 2, yb + 8, stroke=col, sw=1.6) |
| 319 | s.text(x1, yb + 26, value, size=16, weight=700, fill=col, mono=True) |
| 320 | s.text(x1, yb + 45, title, size=13, fill=INK2) |
| 321 | |
| 322 | rd, ra = (ins["w"][0] >> 16) & 0xFF, (ins["w"][0] >> 24) & 0xFF |
| 323 | rb, rc = ins["w"][1] & 0xFF, ins["w"][2] & 0xFF |
| 324 | g = (ins["w"][0] >> 12) & 7 |
| 325 | reg = lambda r: "RZ" if r == 255 else f"R{r}" |
| 326 | bracket(0, 11, 0, "opcode + operand form", f"0x{ins['w'][0] & 0xfff:03x} IADD3", BLUE) |
| 327 | bracket(12, 15, 1, "guard predicate", "@PT" if g == 7 else f"@P{g}", VIOLET) |
| 328 | bracket(16, 23, 2, "destination", reg(rd), GREEN) |
| 329 | bracket(24, 31, 0, "source A", reg(ra), GREEN) |
| 330 | bracket(32, 39, 1, "source B", reg(rb), CYAN) |
| 331 | bracket(64, 71, 0, "source C", reg(rc), INK2) |
| 332 | bracket(72, 104, 1, "carry predicates, modifiers", "PT, PT", INK2) |
| 333 | bracket(105, 127, 0, "scheduling (enlarged below)", "control", AMBER) |
| 334 | |
| 335 | # enlarged control bits |
| 336 | zy, zx, zw = 530, 70, 44 |
| 337 | card(s, 40, zy - 40, 1120, 240, fill=CARD) |
| 338 | s.text(60, zy - 12, "bits 105 to 127: how the warp scheduler treats this instruction", size=16, weight=700, |
| 339 | fill=AMBER) |
| 340 | for i, b in enumerate(range(105, 128)): |
| 341 | on = (ins["bits"] >> b) & 1 |
| 342 | s.rect(zx + i * zw, zy + 8, zw - 4, 40, fill=AMBER, op=0.9 if on else 0.12, rx=4) |
| 343 | s.text(zx + i * zw + (zw - 4) / 2, zy + 35, str(on), size=17, weight=700, fill=BG if on else INK2, |
| 344 | anchor="middle", mono=True) |
| 345 | s.text(zx + i * zw + (zw - 4) / 2, zy + 64, str(b), size=11, fill=INK3, anchor="middle", mono=True) |
| 346 | c = ins |
| 347 | sub = [(105, 108, "stall", f"{c['stall']} cycles"), (109, 109, "yield", str(c["yield"])), |
| 348 | (110, 112, "sets SB", "none" if c["wbar"] == 7 else f"SB{c['wbar']}"), |
| 349 | (113, 115, "read SB", "none" if c["rbar"] == 7 else f"SB{c['rbar']}"), |
| 350 | (116, 121, "waits on", ", ".join(f"SB{i}" for i in c["wait"]) or "none"), |
| 351 | (122, 125, "reuse", str(c["reuse"])), (126, 127, "unused", "0")] |
| 352 | for lo, hi, name, val in sub: |
| 353 | x1 = zx + (lo - 105) * zw |
| 354 | x2 = zx + (hi - 105) * zw + zw - 4 |
| 355 | yb = zy + 76 |
| 356 | s.path(f"M{x1} {yb} L{x1} {yb + 6} L{x2} {yb + 6} L{x2} {yb}", stroke=AMBER, sw=1.4) |
| 357 | s.text(x1, yb + 30, val, size=15, weight=700, fill=INK, mono=True) |
| 358 | s.text(x1, yb + 49, name, size=13, fill=INK2) |
| 359 | s.text(60, zy + 180, "SB4 is the scoreboard both loads (LDG.E R2 and LDG.E R5) set: the add waits until both " |
| 360 | "values have arrived from memory.", size=14, fill=INK2) |
| 361 | s.text(48, s.h - 24, "Field positions: src/omega_blackwell_codegen.c (\"Control words\"), learned from nvcc output " |
| 362 | "on my own probe kernels and Mesa NAK, believed only after the GB10 ran them.", |
| 363 | size=13, fill=INK3) |
| 364 | return s |
| 365 | |
| 366 | |
| 367 | # ---- figure 4: scoreboards in vector add ------------------------------------------------- |
| 368 | def fig_listing(words): |
| 369 | body = words[:21] |
| 370 | rh, top = 30, 196 |
| 371 | s = Svg(1200, top + len(body) * rh + 90, "Vector add, instruction by instruction, with its scoreboards", |
| 372 | "The 21 real instructions of the first kernel. Lines on the left join an instruction that sets a " |
| 373 | "scoreboard to the later instruction that waits on it; amber bars are fixed stall cycles.") |
| 374 | s.frame() |
| 375 | s.kicker(48, 60, "the first kernel, decoded") |
| 376 | s.text(48, 100, "How vector add waits for its data", size=30, weight=800, ls=-0.5) |
| 377 | s.lines(48, 132, ["Slow instructions (constant loads, special registers, memory loads) set one of six scoreboards. " |
| 378 | "A later instruction", |
| 379 | "that needs the result waits on it. Fast instructions stall a fixed number of cycles instead. " |
| 380 | "My encoder writes these bits."], size=15, fill=INK2, gap=21) |
| 381 | sbcol = [CYAN, VIOLET, GREEN, ROSE, AMBER, BLUE] |
| 382 | lane = lambda k: 228 - k * 34 |
| 383 | hy = top - 14 |
| 384 | for lab, x in (("offset", 270), ("instruction", 336), ("stall", 760), ("sets", 940), ("waits on", 1040)): |
| 385 | s.text(x, hy, lab.upper(), size=12, fill=INK3, mono=True, ls=1) |
| 386 | for k in range(5): |
| 387 | s.text(lane(k), hy, f"SB{k}", size=12, fill=sbcol[k], anchor="middle", mono=True, weight=700) |
| 388 | ry = lambda r: top + r * rh + rh / 2 |
| 389 | for r, ins in enumerate(body): |
| 390 | if r % 2 == 0: |
| 391 | s.rect(250, top + r * rh, 920, rh, fill=CARD, rx=6) |
| 392 | y = ry(r) + 5 |
| 393 | s.text(270, y, ins["addr"], size=14, fill=INK3, mono=True) |
| 394 | s.text(336, y, ins["mn"], size=14.5, fill=INK, mono=True) |
| 395 | if ins["stall"]: |
| 396 | s.rect(760, ry(r) - 6, ins["stall"] * 11, 12, fill=AMBER, rx=3, op=0.85) |
| 397 | s.text(760 + ins["stall"] * 11 + 8, y, str(ins["stall"]), size=12, fill=INK3, mono=True) |
| 398 | if ins["wbar"] != 7: |
| 399 | s.pill(940, ry(r) - 11, f"SB{ins['wbar']}", sbcol[ins["wbar"]], size=12, h=22, filled=True, w=52) |
| 400 | for j, k in enumerate(ins["wait"]): |
| 401 | s.pill(1040 + j * 60, ry(r) - 11, f"SB{k}", sbcol[k], size=12, h=22, w=52) |
| 402 | # lanes: every wait joins the setters of that scoreboard since its previous wait |
| 403 | pending = {k: [] for k in range(6)} |
| 404 | for r, ins in enumerate(body): |
| 405 | for k in ins["wait"]: |
| 406 | setters = pending[k] |
| 407 | if setters: |
| 408 | x = lane(k) |
| 409 | s.line(x, ry(setters[0]), x, ry(r), stroke=BG, sw=7) |
| 410 | s.line(x, ry(setters[0]), x, ry(r), stroke=sbcol[k], sw=2.4) |
| 411 | for sr in setters: |
| 412 | s.line(x, ry(sr), 246, ry(sr), stroke=BG, sw=6) |
| 413 | s.line(x, ry(sr), 246, ry(sr), stroke=sbcol[k], sw=1.4, op=0.7, dash="3 4") |
| 414 | s.circle(x, ry(sr), 5, fill=sbcol[k], stroke=BG, sw=2) |
| 415 | s.line(x, ry(r), 252, ry(r), stroke=BG, sw=6) |
| 416 | s.line(x, ry(r), 252, ry(r), stroke=sbcol[k], sw=1.8, arrow=True) |
| 417 | pending[k] = [] |
| 418 | if ins["wbar"] != 7: |
| 419 | pending[ins["wbar"]].append(r) |
| 420 | s.text(48, s.h - 30, "Instruction words: src/omega_blackwell_encoder.c. Decoded by tools/figures/make_figures.py with the " |
| 421 | "encoder's own field positions.", size=13, fill=INK3) |
| 422 | return s |
| 423 | |
| 424 | |
| 425 | # ---- figure 5: how the machine code was learned --------------------------------------------- |
| 426 | def fig_reverse(): |
| 427 | s = Svg(1200, 760, "How I learned the GB10's machine code", |
| 428 | "Three sources and one rule: NVIDIA's compiler output on my own probe kernels, Mesa's open NAK " |
| 429 | "compiler, and the chip itself. Nothing is believed until the GPU runs it and gives the right answer.") |
| 430 | s.frame() |
| 431 | s.kicker(48, 60, "the reverse engineering") |
| 432 | s.text(48, 100, "How I learned the GB10's machine code", size=30, weight=800, ls=-0.5) |
| 433 | s.text(48, 132, "NVIDIA publishes no instruction encoding for its GPUs. I worked it out, and checked every " |
| 434 | "answer on the chip.", size=16, fill=INK2) |
| 435 | |
| 436 | def box(x, y, w, h, n, title, sub, col): |
| 437 | card(s, x, y, w, h, accent=col, fill=CARD) |
| 438 | s.text(x + 18, y + 30, n, size=13, fill=col, mono=True, weight=700) |
| 439 | s.text(x + 18, y + 56, title, size=17, weight=700) |
| 440 | s.lines(x + 18, y + 80, sub, size=13.5, fill=INK2, gap=19) |
| 441 | |
| 442 | s.text(48, 180, "LEARN", size=13, fill=INK3, mono=True, ls=2, weight=700) |
| 443 | W, H, y1 = 258, 150, 194 |
| 444 | xs = [48, 334, 620, 906] |
| 445 | box(xs[0], y1, W, H, "01", "My own probe kernel", ["a few lines of CUDA C++ I", "wrote, e.g. one add"], BLUE_SOFT) |
| 446 | box(xs[1], y1, W, H, "02", "nvcc, once, offline", ["nvcc 13.0.88 -arch=sm_121", "-cubin. Never run by", "CUDA++ itself."], INK2) |
| 447 | box(xs[2], y1, W, H, "03", "Read the bytes back", ["cuobjdump -sass: 16 bytes", "next to each mnemonic"], INK2) |
| 448 | box(xs[3], y1, W, H, "04", "Change one detail", ["a register, an immediate, a", "predicate, a modifier; diff", "the bits that moved"], BLUE_SOFT) |
| 449 | for a, b in zip(xs, xs[1:]): |
| 450 | s.line(a + W + 4, y1 + H / 2, b - 6, y1 + H / 2, stroke=INK2, sw=1.6, arrow=True) |
| 451 | |
| 452 | s.text(48, 404, "PROVE", size=13, fill=INK3, mono=True, ls=2, weight=700) |
| 453 | y2 = 418 |
| 454 | box(48, y2, 258, 150, "05", "Field hypothesis", ["bits 16..23 are the", "destination register,", "and so on"], GREEN) |
| 455 | box(334, y2, 258, 150, "06", "My encoder writes it", ["src/omega_blackwell_", "encoder.c, codegen*.c"], GREEN) |
| 456 | box(620, y2, 258, 150, "07", "The GB10 runs it", ["a real launch on the chip,", "answers checked on the CPU"], GREEN) |
| 457 | box(906, y2, 258, 150, "08", "Golden words", ["kept in the tests; read by", "our own decoder"], GREEN) |
| 458 | s.path(f"M{xs[3] + W / 2} {y1 + H + 4} C {xs[3] + W / 2} 392, 177 380, 177 {y2 - 8}", stroke=INK2, sw=1.6, |
| 459 | arrow=True) |
| 460 | s.line(306 + 4, y2 + 75, 334 - 6, y2 + 75, stroke=INK2, sw=1.6, arrow=True) |
| 461 | s.line(592 + 4, y2 + 75, 620 - 6, y2 + 75, stroke=INK2, sw=1.6, arrow=True) |
| 462 | s.line(878 + 4, y2 + 75, 906 - 6, y2 + 75, stroke=GREEN, sw=2, arrow=True) |
| 463 | s.text(892, y2 - 10, "right, bit for bit ↘", size=12.5, fill=GREEN, anchor="middle", mono=True) |
| 464 | s.path(f"M749 {y2 + H + 4} C 749 {y2 + H + 52}, 177 {y2 + H + 52}, 177 {y2 + H + 8}", stroke=ROSE, sw=1.6, |
| 465 | arrow=True, dash="5 5") |
| 466 | s.text(463, y2 + H + 56, "wrong answer: back to the hypothesis", size=13, fill=ROSE, anchor="middle", mono=True) |
| 467 | |
| 468 | yb = 652 |
| 469 | card(s, 48, yb, 540, 84, accent=VIOLET, fill=CARD) |
| 470 | s.text(66, yb + 30, "Mesa NAK (MIT), cited, no code copied", size=15, weight=700, fill=VIOLET) |
| 471 | s.lines(66, yb + 54, ["sm70_encode.rs opcodes and bit positions, sm120 latencies,", "qmd.rs launch descriptor layout"], |
| 472 | size=13, fill=INK2, gap=18) |
| 473 | card(s, 612, yb, 552, 84, accent=AMBER, fill=CARD) |
| 474 | s.text(630, yb + 30, "Arithmetic the documents leave open", size=15, weight=700, fill=AMBER) |
| 475 | s.lines(630, yb + 54, ["tensor-core BF16: 2,048 chosen cases until one model matched", "every output bit (tests/gpu_tc_probe_test.c)"], |
| 476 | size=13, fill=INK2, gap=18) |
| 477 | return s |
| 478 | |
| 479 | |
| 480 | # ---- figure 6: the driver client's objects ------------------------------------------------ |
| 481 | def fig_driver(): |
| 482 | s = Svg(1200, 1160, "The driver client: every object CUDA++ asks NVIDIA's kernel module for", |
| 483 | "Device files on the left, the resource-manager object tree in the middle, the unified-memory " |
| 484 | "registrations on the right, all from nvrm/nvrm.c.") |
| 485 | s.frame() |
| 486 | s.kicker(48, 60, "the driver client, part by part") |
| 487 | s.text(48, 100, "What replaces libcuda: nvrm/nvrm.c", size=30, weight=800, ls=-0.5) |
| 488 | s.lines(48, 132, ["About 900 lines of C that talk to NVIDIA's open kernel module through ioctls, written from its " |
| 489 | "MIT headers. Each box is", |
| 490 | "one object CUDA++ allocates (RM_ALLOC), with its class name, the header that defines it, and the " |
| 491 | "function that creates it."], size=15, fill=INK2, gap=21) |
| 492 | |
| 493 | # device files |
| 494 | s.text(48, 196, "DEVICE FILES", size=12, fill=INK3, mono=True, ls=1.5, weight=700) |
| 495 | devs = [("/dev/nvidiactl", ["resource manager: allocate", "objects, controls, free"], BLUE), |
| 496 | ("/dev/nvidia0", ["this GPU: CPU mappings of", "memory and the doorbell page"], BLUE), |
| 497 | ("/dev/nvidia-uvm", ["unified memory: GPU page", "tables of the address space"], VIOLET)] |
| 498 | for i, (name, sub, col) in enumerate(devs): |
| 499 | y = 210 + i * 118 |
| 500 | card(s, 48, y, 236, 100, accent=col) |
| 501 | s.text(66, y + 32, name, size=16, weight=700, mono=True, fill=col) |
| 502 | s.lines(66, y + 58, sub, size=13, fill=INK2, gap=18) |
| 503 | |
| 504 | # object tree |
| 505 | s.text(316, 196, "RESOURCE-MANAGER OBJECTS", size=12, fill=INK3, mono=True, ls=1.5, weight=700) |
| 506 | nodes = [ # depth, title, class, header, note, colour, creator |
| 507 | (0, "Root client", "NV01_ROOT_CLIENT", "cl0000.h", "the handle that owns everything below", BLUE, "nvrm_open"), |
| 508 | (1, "Device", "NV01_DEVICE_0", "cl0080.h", "the GPU; its class list names the Blackwell classes", BLUE, ""), |
| 509 | (2, "Subdevice", "NV20_SUBDEVICE_0", "cl2080.h", "SM version (sm_121) and GPU UUID", BLUE, ""), |
| 510 | (3, "Usermode page", "HOPPER_USERMODE_A", "clc661.h", "64 KiB of GPU registers; holds the doorbell", AMBER, ""), |
| 511 | (2, "Virtual memory", "NV01_MEMORY_VIRTUAL", "cl0070.h", "the GPU address range CUDA++ may use", BLUE, ""), |
| 512 | (2, "Address space", "FERMI_VASPACE_A", "cl90f1.h", "page faulting, handed to UVM to manage", VIOLET, ""), |
| 513 | (2, "Memory, one per buffer", "NV01_MEMORY_SYSTEM", "cl003e.h", "GB10 has no VRAM: same address for CPU and GPU", GREEN, "nvrm_alloc"), |
| 514 | (2, "Channel group", "KEPLER_CHANNEL_GROUP_A", "cla06c.h", "scheduled on the graphics/compute engine", BLUE, "nvrm_channel"), |
| 515 | (3, "Context share", "FERMI_CONTEXT_SHARE_A", "cl9067.h", "binds the channel to the address space", BLUE, ""), |
| 516 | (3, "Command ring (GPFIFO)", "BLACKWELL_CHANNEL_GPFIFO_A", "clc96f.h", "1,024 entries + USERD control page; submit token", GREEN, ""), |
| 517 | (4, "Compute object", "BLACKWELL_COMPUTE_B", "clcec0.h", "the engine every kernel launch runs on", GREEN, ""), |
| 518 | ] |
| 519 | tx, nw, nh, ng, ind = 316, 560, 64, 12, 30 |
| 520 | pos = [] |
| 521 | for i, (d, title, cls, hdr, note, col, fn) in enumerate(nodes): |
| 522 | x, y = tx + d * ind, 210 + i * (nh + ng) |
| 523 | w = nw - d * ind |
| 524 | card(s, x, y, w, nh, accent=col if col != BLUE else LINE2) |
| 525 | s.rect(x, y + 10, 3, nh - 20, fill=col, rx=1.5) |
| 526 | s.text(x + 16, y + 25, title, size=15.5, weight=700) |
| 527 | if fn: |
| 528 | s.text(x + 22 + len(title) * 8.4, y + 25, fn + "()", size=12, fill=INK3, mono=True) |
| 529 | s.text(x + w - 14, y + 25, cls, size=12, fill=col, mono=True, anchor="end") |
| 530 | s.text(x + 16, y + 48, note, size=13, fill=INK2) |
| 531 | s.text(x + w - 14, y + 48, hdr, size=11.5, fill=INK3, mono=True, anchor="end") |
| 532 | pos.append((d, x, y)) |
| 533 | # connectors: each node joins its parent (the closest earlier node one level up) |
| 534 | for i, (d, x, y) in enumerate(pos): |
| 535 | if d == 0: |
| 536 | continue |
| 537 | p = next(j for j in range(i - 1, -1, -1) if pos[j][0] == d - 1) |
| 538 | px = pos[p][1] + 14 |
| 539 | s.path(f"M{px} {pos[p][2] + nh} L{px} {y + nh / 2} L{x} {y + nh / 2}", stroke=LINE2, sw=1.4) |
| 540 | # device files feed the objects: control node to the root, GPU node to the usermode mapping |
| 541 | s.path(f"M284 260 C 300 260, 300 242, {tx - 4} 242", stroke=BLUE, sw=1.3, dash="3 4", arrow=True) |
| 542 | s.path(f"M284 378 C 300 378, 300 {pos[3][2] + 32}, {pos[3][1] - 4} {pos[3][2] + 32}", stroke=AMBER, sw=1.3, |
| 543 | dash="3 4", arrow=True) |
| 544 | |
| 545 | # UVM registrations |
| 546 | ux = 912 |
| 547 | s.text(ux, 196, "UNIFIED MEMORY (UVM) CALLS", size=12, fill=INK3, mono=True, ls=1.5, weight=700) |
| 548 | uvm = [("UVM_INITIALIZE", "open the UVM session", 210), |
| 549 | ("UVM_REGISTER_GPU", "this GPU, by UUID", 286), |
| 550 | ("UVM_REGISTER_GPU_VASPACE", "the address space", 590), |
| 551 | ("UVM_CREATE_EXTERNAL_RANGE", "per buffer: reserve the range", 666), |
| 552 | ("UVM_MAP_EXTERNAL_ALLOCATION", "per buffer: map it for the GPU", 742), |
| 553 | ("UVM_REGISTER_CHANNEL", "64 MiB for the channel's context", 894)] |
| 554 | for name, sub, y in uvm: |
| 555 | card(s, ux, y, 250, 64, accent=VIOLET) |
| 556 | s.text(ux + 14, y + 26, name, size=11.8, weight=700, fill=VIOLET, mono=True) |
| 557 | s.text(ux + 14, y + 48, sub, size=13, fill=INK2) |
| 558 | # dotted links from UVM calls to the objects they bind |
| 559 | links = [(286, 2), (590, 5), (666, 6), (742, 6), (894, 9)] |
| 560 | for uy, ni in links: |
| 561 | d, x, y = pos[ni] |
| 562 | s.line(ux - 4, uy + 32, tx + nw + 6, y + nh / 2, stroke=VIOLET, sw=1.5, dash="4 4", op=0.95) |
| 563 | |
| 564 | by = 210 + len(nodes) * (nh + ng) + 8 |
| 565 | card(s, 48, by, 1104, 70, accent=INK3, fill=CARD2, dash="6 5") |
| 566 | s.text(68, by + 30, "Below this line: NVIDIA's open kernel module (nvidia.ko, nvidia-uvm.ko) and the GSP " |
| 567 | "firmware inside the GPU.", size=15, fill=INK) |
| 568 | s.text(68, by + 53, "My own GB10 driver (L332) replaces the module; it has not run on the GB10 yet. " |
| 569 | "The signed firmware stays NVIDIA's.", size=14, fill=INK2) |
| 570 | return s |
| 571 | |
| 572 | |
| 573 | # ---- figure 7: life of one launch ------------------------------------------------------------ |
| 574 | def fig_launch(): |
| 575 | s = Svg(1200, 1010, "The life of one kernel launch", |
| 576 | "Five CPU steps write into memory the CPU and GPU share, one store rings the doorbell, the GPU reads " |
| 577 | "the ring, the pushbuffer and the launch descriptor, runs the grid and writes a completion marker the " |
| 578 | "CPU polls.") |
| 579 | s.frame() |
| 580 | s.kicker(48, 60, "the launch path") |
| 581 | s.text(48, 100, "The life of one kernel launch", size=30, weight=800, ls=-0.5) |
| 582 | s.text(48, 132, "On the GB10 the CPU and the GPU share one memory, and CUDA++ maps every buffer at the same " |
| 583 | "address on both. Nothing is copied.", size=15.5, fill=INK2) |
| 584 | cx, mx, gx = 48, 440, 820 |
| 585 | cw, mw, gw = 350, 300, 332 |
| 586 | s.text(cx, 186, "CPU (your process)", size=13, fill=BLUE_SOFT, mono=True, weight=700, ls=1) |
| 587 | s.text(mx, 186, "SHARED MEMORY", size=13, fill=GREEN, mono=True, weight=700, ls=1) |
| 588 | s.text(gx, 186, "GPU", size=13, fill=AMBER, mono=True, weight=700, ls=1) |
| 589 | s.rect(mx - 14, 168, mw + 28, 740, fill=GREEN, rx=18, op=0.035) |
| 590 | |
| 591 | def step(x, y, w, n, title, sub, col, h=104): |
| 592 | card(s, x, y, w, h, accent=col) |
| 593 | s.circle(x + 26, y + 28, 14, fill=col) |
| 594 | s.text(x + 26, y + 33, str(n), size=14, weight=800, fill=BG, anchor="middle") |
| 595 | s.text(x + 50, y + 33, title, size=16, weight=700) |
| 596 | s.lines(x + 18, y + 60, sub, size=13, fill=INK2, gap=18) |
| 597 | |
| 598 | def buf(y, title, sub, col=GREEN, h=68, dash=None): |
| 599 | card(s, mx, y, mw, h, accent=col, dash=dash) |
| 600 | s.text(mx + 16, y + 27, title, size=15, weight=700, fill=col) |
| 601 | s.text(mx + 16, y + 50, sub, size=12.5, fill=INK2, mono=True) |
| 602 | |
| 603 | rows = [206, 326, 446, 566, 686] |
| 604 | step(cx, rows[0], cw, 1, "Build the kernel", ["IR instructions, register allocation,", "16-byte machine words"], BLUE_SOFT) |
| 605 | step(cx, rows[1], cw, 2, "Describe the launch", ["QMD: grid, block, registers, shared", "memory, code address. Arguments", "go in constant bank 0."], BLUE_SOFT, h=110) |
| 606 | step(cx, rows[2], cw, 3, "Write the methods", ["INVALIDATE_SHADER_CACHES,", "WAIT_FOR_IDLE, SEND_PCAS_A (the", "QMD), then the completion tail"], BLUE_SOFT, h=110) |
| 607 | step(cx, rows[3], cw, 4, "Queue one ring entry", ["8 bytes: pushbuffer address + length;", "then advance USERD.GPPut"], BLUE_SOFT) |
| 608 | step(cx, rows[4], cw, 5, "Ring the doorbell", ["one 32-bit store of the channel's", "work-submit token"], AMBER) |
| 609 | |
| 610 | buf(rows[0] + 18, "Code buffer", "written once, executed by the GPU") |
| 611 | buf(rows[1] + 18, "QMD + constant bank 0", "384 B QMD · 224 driver words · args") |
| 612 | buf(rows[2] + 18, "Pushbuffer", "method headers + data words") |
| 613 | buf(rows[3] + 18, "GPFIFO ring + USERD", "1,024 entries · GPPut (GPU-uncached)") |
| 614 | buf(rows[4] + 18, "Usermode page (GPU registers)", "doorbell register", col=AMBER, dash="5 4") |
| 615 | buf(826, "Marker page (GPU-uncached)", "0x44444444, then 0x46464646") |
| 616 | |
| 617 | for r in range(5): |
| 618 | s.line(cx + cw + 4, rows[r] + 52, mx - 6, rows[r] + 52, stroke=BLUE_SOFT if r < 4 else AMBER, sw=1.6, |
| 619 | arrow=True) |
| 620 | |
| 621 | gsteps = [(286, 6, "Host engine fetches", ["reads the new ring entry, then", "the pushbuffer's methods"]), |
| 622 | (446, 7, "Compute engine launches", ["invalidates caches, reads the QMD", "and constant bank, starts the", "grid on the SMs"]), |
| 623 | (606, 8, "The grid finishes", ["semaphore release writes the", "marker, L2_FLUSH_DIRTY, then", "the second marker"])] |
| 624 | for y, n, t, sub in gsteps: |
| 625 | step(gx, y, gw, n, t, sub, AMBER, h=118) |
| 626 | # GPU reads: two buses on the right of the memory column, one per GPU step |
| 627 | bx6, bx7 = mx + mw + 18, mx + mw + 40 |
| 628 | for r in (2, 3): |
| 629 | s.line(mx + mw, rows[r] + 52, bx6, rows[r] + 52, stroke=INK2, sw=1.3) |
| 630 | s.line(bx6, rows[3] + 52, bx6, 345, stroke=INK2, sw=1.3) |
| 631 | s.line(bx6, 345, gx - 6, 345, stroke=INK2, sw=1.3, arrow=True) |
| 632 | for r in (0, 1): |
| 633 | s.line(mx + mw, rows[r] + 52, bx7, rows[r] + 52, stroke=INK2, sw=1.3) |
| 634 | s.line(bx7, rows[0] + 52, bx7, 505, stroke=INK2, sw=1.3) |
| 635 | s.line(bx7, 505, gx - 6, 505, stroke=INK2, sw=1.3, arrow=True) |
| 636 | for r in (2, 3): |
| 637 | s.circle(bx6, rows[r] + 52, 3.5, fill=INK2) |
| 638 | for r in (0, 1): |
| 639 | s.circle(bx7, rows[r] + 52, 3.5, fill=INK2) |
| 640 | s.text(gx + 4, 278, "reads ring + pushbuffer", size=11.5, fill=INK3, mono=True) |
| 641 | s.text(gx + 4, 438, "reads QMD, bank, code", size=11.5, fill=INK3, mono=True) |
| 642 | # the doorbell wakes the host engine |
| 643 | dy = rows[4] + 52 |
| 644 | s.path(f"M{mx + mw + 4} {dy} L802 {dy} L802 395 L{gx - 6} 395", stroke=BG, sw=7) |
| 645 | s.path(f"M{mx + mw + 4} {dy} L802 {dy} L802 395 L{gx - 6} 395", stroke=AMBER, sw=1.8, arrow=True) |
| 646 | s.add(f'<text transform="translate(796 {dy - 30}) rotate(-90)" font-family="{MONO}" font-size="12" ' |
| 647 | f'fill="{AMBER}" text-anchor="start">wakes the GPU</text>') |
| 648 | s.path(f"M{gx + gw / 2} {606 + 118 + 4} L{gx + gw / 2} 860 L{mx + mw + 6} 860", stroke=AMBER, sw=1.8, |
| 649 | arrow=True) |
| 650 | s.text(gx + gw / 2 - 8, 848, "writes the markers", size=12, fill=AMBER, mono=True, anchor="end") |
| 651 | step(cx, 806, cw, 9, "Wait, then retire", ["poll the marker with a hard deadline", "and a stall deadline; results are", "already in shared memory"], BLUE_SOFT, h=110) |
| 652 | s.line(mx - 4, 860, cx + cw + 6, 860, stroke=BLUE_SOFT, sw=1.6, arrow=True) |
| 653 | s.text(48, 958, "Blue: the CPU writes. Amber: the GPU acts. Dashed: GPU registers mapped into the process, " |
| 654 | "not memory.", size=13, fill=INK2) |
| 655 | s.text(48, 980, "Measured on the GB10: 24 to 31 µs per extra dependent launch with wait-for-idle " |
| 656 | "(evidence/OWN30B-LAUNCH-COST-20261014T0120Z). Command lists put many launches in one submission.", |
| 657 | size=13, fill=INK3) |
| 658 | return s |
| 659 | |
| 660 | |
| 661 | # ---- figure 8: replacement map ------------------------------------------------------------- |
| 662 | STATUS_COL = {"PASS": GREEN, "PARTIAL": BLUE_SOFT, "BUILDING": VIOLET, "MISSING": INK2, "STAYS": AMBER} |
| 663 | |
| 664 | |
| 665 | def fig_status(): |
| 666 | rows = [ # piece, job, replacement, status, note |
| 667 | ("nvcc · NVVM · PTX · ptxas", "compile kernels", "sm_121 encoder + register allocator", "PASS", "every kernel this stack runs"), |
| 668 | ("libcuda", "user-space driver", "nvrm + m16 driver client", "PARTIAL", "M16 raw logs unavailable"), |
| 669 | ("libcudart", "device, memory, launch", "session, command lists, job engine", "PARTIAL", "one device, one process"), |
| 670 | ("cuBLAS", "matrix multiply", "matmul, tensor-core GEMM, FP8, BF16", "PARTIAL", "model shapes; any-shape GEMM is C3"), |
| 671 | ("cuDNN · FlashAttention", "attention, layers", "decode and prefill attention", "PARTIAL", "model-shaped"), |
| 672 | ("CUB · Thrust", "reductions, scans, sorts", "frozen-order reductions", "PARTIAL", "E1-CLOSURE; scans and sorts are C3"), |
| 673 | ("cuobjdump · nvdisasm", "read machine code back", "my own sm_121 disassembler", "BUILDING", "Omega decoder: 3,191 kernels agree"), |
| 674 | ("Nsight", "measure", "ceiling probes", "PARTIAL", "115.14 TFLOPS, 195.1 GB/s"), |
| 675 | ("cuFFT · cuRAND", "FFT, random numbers", "xoshiro256** RNG, batched FFT", "PARTIAL", "one GB10 run; power-of-two complex FFT"), |
| 676 | ("nvidia.ko", "kernel driver", "my own GB10 driver (L332)", "BUILDING", "aien-gpu, omega-gpu-driver, aienux#441; not run on GB10"), |
| 677 | ("nvidia-uvm.ko", "page tables, faults", "my own GB10 driver (L332)", "BUILDING", "MMU simulator, 225 checks; not run on GB10"), |
| 678 | ("nvidia-smi · NVML", "status, clocks, power", "not started", "MISSING", ""), |
| 679 | ("GSP firmware", "runs inside the GPU", "stays NVIDIA's: signature-checked", "STAYS", "never shipped by CUDA++"), |
| 680 | ] |
| 681 | rh, top = 52, 200 |
| 682 | s = Svg(1200, top + len(rows) * rh + 80, "Every NVIDIA piece on the Spark and what replaces it", |
| 683 | "One row per NVIDIA component with the CUDA++ replacement and its status (ROADMAP.md).") |
| 684 | s.frame() |
| 685 | s.kicker(48, 60, "the replacement map") |
| 686 | s.text(48, 100, "Every NVIDIA piece on the Spark, and what replaces it", size=30, weight=800, ls=-0.5) |
| 687 | s.text(48, 132, "PASS means a receipt on a named commit. The full table with every receipt is ROADMAP.md.", |
| 688 | size=15.5, fill=INK2) |
| 689 | hx = [48, 330, 560, 900, 1040] |
| 690 | for lab, x in zip(("NVIDIA piece", "its job", "CUDA++", "status", ""), hx): |
| 691 | s.text(x, top - 16, lab.upper(), size=12.5, fill=INK2, mono=True, ls=1, weight=700) |
| 692 | for i, (p, job, rep, st, note) in enumerate(rows): |
| 693 | y = top + i * rh |
| 694 | if i % 2 == 0: |
| 695 | s.rect(36, y, 1128, rh, fill=CARD, rx=8) |
| 696 | s.text(48, y + 22, p, size=15, weight=700, mono=True, fill=INK if st != "STAYS" else AMBER) |
| 697 | s.text(330, y + 22, job, size=14, fill=INK2) |
| 698 | s.text(560, y + 22, rep, size=14.5, fill=INK) |
| 699 | if note: |
| 700 | s.text(560, y + 41, note, size=12.5, fill=INK2, op=0.85) |
| 701 | col = STATUS_COL[st] |
| 702 | s.pill(900, y + 12, st, col, size=12, h=24, filled=True, w=108) |
| 703 | tot = {k: sum(1 for r in rows if r[3] == k) for k in STATUS_COL} |
| 704 | x = 48 |
| 705 | yb = top + len(rows) * rh + 40 |
| 706 | for k, col in STATUS_COL.items(): |
| 707 | s.rect(x, yb - 12, 14, 14, fill=col, rx=3, op=0.85) |
| 708 | lab = f"{k} {tot[k]}" |
| 709 | s.text(x + 22, yb, lab, size=14, fill=INK2, mono=True) |
| 710 | x += 40 + len(lab) * 9 |
| 711 | return s |
| 712 | |
| 713 | |
| 714 | # ---- figure 9: ceilings ------------------------------------------------------------------------- |
| 715 | def fig_ceiling(): |
| 716 | import math |
| 717 | peak, bw = 115.14e12, 195.1e9 # evidence/OWN30B-T3-TC-PEAK-BW-5faa0f70-20261013T2236Z |
| 718 | s = Svg(1200, 660, "The two ceilings I measured on the GB10", |
| 719 | "Roofline: attainable speed against operations per byte, from the measured 115.14 TFLOPS tensor-core " |
| 720 | "peak and 195.1 GB/s read bandwidth.") |
| 721 | s.frame() |
| 722 | s.kicker(48, 60, "speed against the machine's ceiling") |
| 723 | s.text(48, 100, "The two ceilings I measured on the GB10", size=30, weight=800, ls=-0.5) |
| 724 | s.text(48, 132, "Every speed claim is held against these: the tensor-core peak and the memory read rate my " |
| 725 | "own probes reached.", size=15.5, fill=INK2) |
| 726 | px, py, pw, ph = 130, 170, 700, 380 |
| 727 | xmin, xmax, ymin, ymax = -2, 4, 9, 15 # log10 FLOP/byte, log10 FLOP/s |
| 728 | X = lambda v: px + (math.log10(v) - xmin) / (xmax - xmin) * pw |
| 729 | Y = lambda v: py + ph - (math.log10(v) - ymin) / (ymax - ymin) * ph |
| 730 | s.rect(px, py, pw, ph, fill=CARD, rx=10) |
| 731 | for e in range(xmin, xmax + 1): |
| 732 | s.line(X(10 ** e), py, X(10 ** e), py + ph, stroke=LINE, sw=1) |
| 733 | s.text(X(10 ** e), py + ph + 22, f"{10 ** e:g}", size=12.5, fill=INK3, anchor="middle", mono=True) |
| 734 | for e in range(ymin, ymax + 1): |
| 735 | s.line(px, Y(10 ** e), px + pw, Y(10 ** e), stroke=LINE, sw=1) |
| 736 | lab = {9: "1 G", 10: "10 G", 11: "100 G", 12: "1 T", 13: "10 T", 14: "100 T", 15: "1 P"}[e] |
| 737 | s.text(px - 12, Y(10 ** e) + 4, lab, size=12.5, fill=INK3, anchor="end", mono=True) |
| 738 | s.text(px + pw / 2, py + ph + 48, "operations per byte moved (log)", size=13.5, fill=INK2, anchor="middle") |
| 739 | s.add(f'<text transform="translate({px - 70} {py + ph / 2}) rotate(-90)" font-family="{SANS}" font-size="13.5" ' |
| 740 | f'fill="{INK2}" text-anchor="middle">operations per second (log)</text>') |
| 741 | ridge = peak / bw |
| 742 | pts = [(10 ** xmin, bw * 10 ** xmin), (ridge, peak), (10 ** xmax, peak)] |
| 743 | d = " ".join(("M" if i == 0 else "L") + f"{X(a):.1f} {Y(b):.1f}" for i, (a, b) in enumerate(pts)) |
| 744 | s.path(d, stroke=GREEN, sw=3) |
| 745 | s.line(X(ridge), Y(peak), X(ridge), py + ph, stroke=GREEN, sw=1, dash="4 5", op=0.6) |
| 746 | s.text(X(ridge) + 8, py + ph - 10, f"ridge: {ridge:.0f} ops/byte", size=12.5, fill=GREEN, mono=True) |
| 747 | s.text(X(ridge) - 14, Y(peak) + 5, "tensor-core peak 115.14 TFLOPS", size=14, fill=GREEN, mono=True, weight=700, |
| 748 | anchor="end") |
| 749 | ang = math.degrees(math.atan((ph / (ymax - ymin)) / (pw / (xmax - xmin)))) |
| 750 | s.add(f'<text transform="translate({X(0.012):.1f} {Y(bw * 0.012) - 12:.1f}) rotate(-{ang:.2f})" ' |
| 751 | f'font-family="{MONO}" font-size="14" font-weight="700" fill="{GREEN}">memory reads 195.1 GB/s</text>') |
| 752 | marks = [(1 / 12, "vector add", "1 add per 12 bytes moved", CYAN), |
| 753 | (1.0, "decode, BF16 matrix-vector", "multiply + add per 2-byte weight", AMBER), |
| 754 | (4096 / 3, "large BF16 GEMM (4096³)", "each byte reused many times", ROSE)] |
| 755 | for v, lab, sub, col in marks: |
| 756 | yv = min(bw * v, peak) |
| 757 | s.circle(X(v), Y(yv), 6, fill=col, stroke=BG, sw=2) |
| 758 | # legend panel |
| 759 | lx = 880 |
| 760 | for i, (v, lab, sub, col) in enumerate(marks): |
| 761 | y = 196 + i * 92 |
| 762 | s.circle(lx + 8, y - 5, 6, fill=col) |
| 763 | s.text(lx + 24, y, lab, size=15, weight=700, fill=col) |
| 764 | s.text(lx + 24, y + 21, sub, size=13, fill=INK2) |
| 765 | bound = "memory-bound" if v < ridge else "compute-bound" |
| 766 | num = f"{v:,.0f}" if v >= 10 else (f"{v:.0f}" if v == 1 else f"{v:.3f}") |
| 767 | s.text(lx + 24, y + 40, f"{num} ops/byte: {bound}", size=12.5, fill=INK2, mono=True) |
| 768 | s.lines(lx, 488, ["A generated word reads every active", "weight once, so its speed is set by", "the memory line, not the tensor cores."], |
| 769 | size=13.5, fill=INK2, gap=19) |
| 770 | s.text(48, s.h - 40, "The two lines are measured: evidence/OWN30B-T3-TC-PEAK-BW-5faa0f70-20261013T2236Z " |
| 771 | "(peak.log, bw.log). The dots are arithmetic, not measurements.", size=13, fill=INK2) |
| 772 | s.text(48, s.h - 20, "One op is one add or one multiply; a fused multiply-add counts as two.", size=13, fill=INK3) |
| 773 | return s |
| 774 | |
| 775 | |
| 776 | # ---- figure 10: timeline ------------------------------------------------------------------------ |
| 777 | def fig_timeline(): |
| 778 | ev = [("2026-09-26", "First native kernel", ["vector add qualified on the", "GB10; first tensor-core matmul"]), |
| 779 | ("2026-10-02", "Numerics closed on chip", ["reductions, 9 functions over", "all 2^32 inputs, 148 ld/st kernels"]), |
| 780 | ("2026-10-13", "Ceilings measured", ["115.14 TFLOPS tensor peak,", "195.1 GB/s reads, own probes"]), |
| 781 | ("2026-10-21", "A 35B model, no CUDA", ["served on this code with zero", "CUDA libraries in the process"])] |
| 782 | s = Svg(1200, 270, "Under four weeks, one DGX Spark", |
| 783 | "Milestones from the first native kernel to a 35B model served with no CUDA library loaded.") |
| 784 | s.frame() |
| 785 | s.kicker(48, 56, "under four weeks, one DGX Spark") |
| 786 | y = 120 |
| 787 | s.path(f"M80 {y} L950 {y}", stroke=GREEN, sw=2.5, op=0.6) |
| 788 | for i, (d, t, sub) in enumerate(ev): |
| 789 | x = 80 + i * 290 |
| 790 | s.circle(x, y, 9, fill=BG, stroke=GREEN, sw=3) |
| 791 | anchor = "start" |
| 792 | s.text(x, y - 22, d, size=13.5, fill=GREEN, mono=True, anchor=anchor, weight=700) |
| 793 | s.text(x, y + 40, t, size=17, weight=700, anchor=anchor) |
| 794 | for j, l in enumerate(sub): |
| 795 | s.text(x, y + 64 + j * 20, l, size=14, fill=INK2, anchor=anchor) |
| 796 | return s |
| 797 | |
| 798 | |
| 799 | FIGS = { |
| 800 | "hero.svg": lambda w: fig_hero(w), |
| 801 | "stack.svg": lambda w: fig_stack(), |
| 802 | "instruction.svg": lambda w: fig_instruction(w), |
| 803 | "vecadd-scoreboards.svg": lambda w: fig_listing(w), |
| 804 | "reverse-engineering.svg": lambda w: fig_reverse(), |
| 805 | "driver-objects.svg": lambda w: fig_driver(), |
| 806 | "launch-path.svg": lambda w: fig_launch(), |
| 807 | "replacement-map.svg": lambda w: fig_status(), |
| 808 | "ceilings.svg": lambda w: fig_ceiling(), |
| 809 | "timeline.svg": lambda w: fig_timeline(), |
| 810 | } |
| 811 | |
| 812 | |
| 813 | def main(): |
| 814 | check = "--check" in sys.argv |
| 815 | words = vecadd_words() |
| 816 | os.makedirs(OUT, exist_ok=True) |
| 817 | stale = [] |
| 818 | for name, fn in FIGS.items(): |
| 819 | data = fn(words).svg() |
| 820 | path = os.path.join(OUT, name) |
| 821 | if check: |
| 822 | if not os.path.exists(path) or open(path).read() != data: |
| 823 | stale.append(name) |
| 824 | else: |
| 825 | with open(path, "w") as f: |
| 826 | f.write(data) |
| 827 | print(f"wrote docs/img/{name} ({len(data)} bytes)") |
| 828 | if check: |
| 829 | if stale: |
| 830 | sys.exit("stale figures (run python3 tools/figures/make_figures.py): " + ", ".join(stale)) |
| 831 | print(f"figures current: {len(FIGS)}") |
| 832 | |
| 833 | |
| 834 | if __name__ == "__main__": |
| 835 | main() |