interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / docs / runtime / PORTABILITY.md

167 lines · 18599 bytes Raw Blame History Rendered
1# Omega portability: what is tied to the chip, what is not
2
3Slice R3 of the runtime roadmap (omega-mv#596, tracking #593). Written for a developer who has never seen this
4repository and wants to know how much of Omega they would have to change to run it on another GPU, another operating
5system, or no operating system. Every claim names the file it comes from. Where a source is missing the claim is marked
6UNVERIFIED. Nothing here was run on a GPU; this slice is read-only analysis plus a host-side check.
7
8Companion documents, not repeated here: `docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md` (which driver call each part makes
9today and which cut removes it) and `docs/numeric/OMEGA_GPU_ENGINE.md` (the engine contract).
10
11Current Ampere work is audited in [`../PORT-AMPERE.md`](../PORT-AMPERE.md).
12Its sm_86 encoder, QMD3 and discrete-memory path do not make GA102/GA104
13qualified: both remain device NOT_RUN. The Blackwell inventory below explains
14the original R3 boundary; target-specific Ampere files now participate in the
15same table gate.
16
17## 1. Two separate questions
18
19Porting Omega means answering two questions that are easy to mix up:
20
211. **Chip.** Does this file know something about GB10 (Grace Blackwell, sm_121) or Ampere (sm_86)? Machine-code
22 words, launch-descriptor fields, class numbers, cache behaviour.
232. **Operating system and driver.** Does this file need Linux, the NVIDIA open driver, or a C library?
24
25The table `docs/runtime/portability_table.tsv` answers both, one row per `src/omega_gpu_*`, `src/omega_blackwell_*`,
26`src/omega_bw_*` and `src/omega_ampere_*` file. The table is the current inventory; the M17/M18 gate suite `omega_blackwell_gates.{c,h}` stays in Omega, which runs it against this library:
27
28| Column | Values | Meaning |
29|---|---|---|
30| `class` | `CHIP_SPECIFIC`, `PORTABLE` | `CHIP_SPECIFIC`: the file carries knowledge of a target GPU or its driver interface, so a different GPU or driver means reviewing or replacing it. `PORTABLE`: it carries neither. |
31| `reason` | text | Why, with the evidence (an include list, a constant, a make target). |
32| `os_binding` | `FREESTANDING_PROVEN`, `NO_HOSTED_INCLUDE`, `HOSTED_LIBC`, `LINUX_DRIVER` | `FREESTANDING_PROVEN`: a `.c` file in `GPU_FS_SRCS` (`mk/omega-gpu-engine.mk`), built by `make gpu-engine-freestanding` with no hosted headers. `NO_HOSTED_INCLUDE`: no hosted header by include scan only (a header, or a `.c` outside that build). `HOSTED_LIBC`: includes stdio, stdlib, time, errno, math or pthread. `LINUX_DRIVER`: includes `nvrm.h`, `m16_native.h` or `omega_gpu_platform_linux.h`. |
33
34Totals at base commit a8ffd2b9: 87 files are `CHIP_SPECIFIC` and 15 are `PORTABLE`. By `os_binding`: 13 `FREESTANDING_PROVEN`,
3577 `NO_HOSTED_INCLUDE`, 9 `HOSTED_LIBC`, 3 `LINUX_DRIVER`. The small `PORTABLE` count is the honest result: almost everything
36in `src/omega_gpu_*` launches a Blackwell kernel. CUDApp#125 adds 21 `CHIP_SPECIFIC` rows for the files the omega-mv
37carries (#120, #121) brought (15 `NO_HOSTED_INCLUDE`, 6 `HOSTED_LIBC`). The sync to omega-mv b5ab3fe9 (trains r1 #971 and
38r2 #972) adds 5 `CHIP_SPECIFIC` rows (`src/omega_bw_hazard.{c,h}`, omega-mv#554; `src/omega_gpu_fp8_slots.{c,h}` and
39`src/omega_gpu_fp8_internal.h`, #961) and carries omega's review of the public headers (#954): `omega_gpu_matmul_api.h`,
40`omega_gpu_moe_api.h`, `omega_gpu_platform.h`, `omega_gpu_serving.{c,h}` and `omega_gpu_session.h` become `CHIP_SPECIFIC`,
41`omega_gpu_scan_ref.c` becomes `PORTABLE` (section 3). At that sync, the totals were 120 `CHIP_SPECIFIC`, 11 `PORTABLE`; 13
42`FREESTANDING_PROVEN`, 98 `NO_HOSTED_INCLUDE`, 17 `HOSTED_LIBC`, 3 `LINUX_DRIVER`. Current totals at CUDApp main b774723f
43(150 rows, including the Ampere files and the four bf16 training GEMM rows, omega-mv#596): 137 `CHIP_SPECIFIC`, 13 `PORTABLE`;
4413 `FREESTANDING_PROVEN`, 114 `NO_HOSTED_INCLUDE`, 18 `HOSTED_LIBC`, 5 `LINUX_DRIVER`. Command to recount: section 7.
45The four bf16 training GEMM rows added by omega-mv#596 after train r5 #996
46are carried here as `omega_blackwell_codegen_tgemm.{c,h}` and
47`omega_gpu_tgemm_api.{c,h}`. Omega's corresponding inventory at f0cc9d6a53b7
48has 132 rows; that total is not CUDApp's separate Ampere-inclusive inventory.
49The Omega migration inventory also includes API-view, graph-record, GDN
50admission, Blackwell field/policy and platform-oracle headers. Host-math's
51hosted Omega ABI shell is `HOSTED_LIBC`; its numeric operations being
52OS-independent does not make its failure-handling includes freestanding.
53
54`make test-runtime-portability` (host only, no compiler, no GPU) checks the table against the tree: every file has a row,
55every row names a real file, a `PORTABLE` row's file includes no Linux or NVRM header and no Blackwell header, and the
56`os_binding` column agrees with the includes and with the freestanding file list. It proves rows and includes agree. It
57does not prove a reason is right; the reasons are human claims and each cites what to check. The include scan reads
58direct `#include` lines only, and skips lines inside `#ifndef OMEGA_GPU_NO_POSIX` (the hosted-only branch) and
59`#ifdef OMEGA_ATTN_DEBUG` (a debug trace).
60
61## 2. What is tied to the chip
62
63| Piece | Where | What is chip-specific about it |
64|---|---|---|
65| Machine-code encoder | `src/omega_blackwell_encoder.c`, `.h` | Packs instructions into 16-byte words (`OMEGA_BW_INSTRUCTION_BYTES`). A different instruction set needs a new encoder. |
66| Kernel generators | `src/omega_blackwell_codegen*.c`, `src/omega_bw_*.h` | Every kernel (vector add, matmul, FP8 GEMV, attention, router, tensor-core GEMM, ternary GEMV) is generated as sm_121 instructions with scheduling rules proven on the chip (`src/omega_bw_em.h`). Some ops are patched in after encoding because the shared encoder lacks them (`src/omega_blackwell_codegen_qmma.h`, values from an nvcc sm_121 oracle). |
67| Launch descriptor (QMD) | `src/omega_blackwell_qmd.h`, `.c` | A 96-word, 384-byte structure the GPU reads to start a kernel (`OMEGA_BW_QMD_BYTES`). Each field has an evidence tier: documented in NVIDIA's `clcdc0qmd.h`, observed on silicon, or reverse engineered. |
68| Class numbers and setup words | `src/omega_gpu_session.c` (`SETUP_WORDS`), `src/omega_gpu_cmdlist.c`, `src/omega_blackwell_engine.c`, `src/omega_blackwell_submit.c` and seven more files | The pushbuffer words that select compute class `0xcec0` (Blackwell compute B) and set up the engine. The same 18-word block is copied into 11 files under `src/` (`grep -l 0x0000cec0 src/*.c src/runtime/*.c`). Method numbers such as `WAIT_FOR_IDLE 0x0110` and `SEND_PCAS_A 0x02b4` are in `src/omega_gpu_cmdlist.c`. The channel and user-mode classes (`clc96f.h`, `clc661.h`) are used by `physics/nvrm/nvrm.c`, outside this repository. |
69| Cache rules | `src/omega_gpu_platform.c` (check at the cache-policy refusal), `src/omega_gpu_mem_cached.h`, `src/omega_gpu_cmdlist.h`, `src/omega_gpu_prefill.h` | Anything the CPU polls for a GPU write must be GPU-uncached, because GPU-cacheable system memory "will not be coherent with direct CPU mappings" (nvidia-open 580.173.02 `nvos.h`, quoted in `src/omega_gpu_platform.h`). Read-only weights may be GPU-cached only if the CPU wrote them once and never reads them. A command list ends with an L2 flush and a second marker on an uncached page. A chip with coherent memory could relax these rules. |
70| Code buffer tail | `src/omega_gpu_code_alloc.h` | Code buffers stay mapped for 2 KB after the last instruction (`OMEGA_GPU_CODE_PREFETCH_TAIL`) because the instruction cache prefetches past it. The rule comes from Mesa NVK; that it was the cause of the GB10 fault in omega#323 is INFERRED until the chip confirms, per the header. |
71| Target facts | `src/omega_bw_target.h` on branch `rig/gb20x` | Compute class, QMD version, shared-memory configuration, SM count and cache sizes in one table row per chip. Only the GB10 row is chip-proven. |
72
73**A finding that corrects a simple reading of the architecture.** The session (`src/omega_gpu_session.c`), the command
74list, and the matmul and attention APIs are free of the operating system: the first, the matmul and the attention API are
75in the freestanding build. They are not free of the chip. They embed `SETUP_WORDS`, method numbers, QMD use and sm_121
76stall counts. The platform contract hides the *driver*; it does not hide the *GPU*. The table marks those files
77`CHIP_SPECIFIC` with `os_binding` `FREESTANDING_PROVEN` for that reason.
78
79## 3. What is portable
80
81| Piece | Where | Why it is portable |
82|---|---|---|
83| Platform validation implementation | `src/omega_gpu_platform.c` | Reusable capability negotiation and handle-table checks, included in `make gpu-engine-freestanding`. This does not make the header contract chip-neutral: `omega_gpu_platform.h` specifies NVIDIA cache policy and GPFIFO queue semantics and is classified separately as `CHIP_SPECIFIC`. |
84| Engine state machine | `src/omega_gpu_engine.c`, `.h` | Open, validate, submit, verify, close, with a named failing step. Talks to a backend through a function table (`OmegaGpuBackend`). No chip knowledge. |
85| Bounded wait | `src/omega_gpu_wait.c` | Clock and hooks come from the caller; the freestanding build has no default clock. |
86| Text and host math | `src/omega_gpu_fmt.c`, `src/omega_gpu_hostmath.c` | A bounded formatter and libm-free log, exp, pow. |
87| Scan host reference | `src/omega_gpu_scan_ref.c` | The frozen reduction and prefix-sum order depends only on n and the element index (`docs/numeric/E1_REDUCTION_CONTRACT.md`); the u32 prefix sum and the stable LSD radix sort are plain C on the CPU. Its header `omega_gpu_scan.h` is `CHIP_SPECIFIC` and pulls in `omega_blackwell_codegen.h`, so reuse elsewhere needs the reference declarations split out. |
88
89Plain C signatures are not evidence of a chip-neutral contract. The matmul header exposes Blackwell tile macros (16/8/16), the MoE header defines tile-major packing and column alignment, and the session header exposes QMD fields/defaults and the two-marker/L2-flush launch protocol. All three are `CHIP_SPECIFIC`. The platform header also requires review for another chip because its queue contract names GPFIFO and its host-polled rights require the NVIDIA GPU-uncached visibility rule. The serving header describes the GB10 reservation/cache contract; `omega_gpu_serving.c` calls those matmul/attention reservation APIs rather than implementing generic allocation accounting. Both serving files are therefore `CHIP_SPECIFIC`, even though the implementation builds without hosted headers.
90
91A hardware name in an example or historical comment alone is not a machine dependency. The classifications above are based on exposed layout, tile, visibility, queue or backend-call semantics. The remaining portable engine/math/formatter/wait helpers do not prove that their consumer or a complete backend supports another GPU.
92
93What the freestanding build proves, and what it does not, is in `docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md` section 1 and
94section 4: the listed files link with only `memcpy`, `memmove`, `memset`, `memcmp`, `strlen` and `strcmp` undefined, and
95nothing there opens a device. The table adds the other direction: which files are outside that build and why.
96
97## 4. Three ways to reach the GPU
98
99| | Linux open driver | WSL2 under Windows (`/dev/dxg`) | Native AIENOS |
100|---|---|---|---|
101| Status | Runs on the DGX Spark (GB10). The only backend with chip evidence. | Host-tested only. Nothing has touched a real `/dev/dxg` or an RTX 5070 (`docs/rig/dxg-backend.md` on `rig/gb20x`, section 5, status line). | Not built. The boot image that looks for the GPU has not been booted on hardware (aienos `docs/GB10_NATIVE_STATUS.md`). NOT_RUN. |
102| How it talks | `/dev/nvidiactl`, `/dev/nvidia0`, `/dev/nvidia-uvm` through `physics/nvrm` and `physics/m16`. Omega rings the GPU itself through a channel it owns. | D3DKMT ioctls on `/dev/dxg` (Microsoft's `dxgkrnl`), which forwards to the Windows NVIDIA driver. No doorbell ioctl exists; each submit is an ioctl (`docs/WINDOWS-GPU-PATH.md` section 1, aien-rig branch `app/v0`). | AIENOS drives PCI, SMMU, firmware load, queues and doorbells itself. |
103| Platform contract | `src/omega_gpu_platform_linux.c` implements it (reference only, hosted only). The vector executor `src/omega_blackwell_submit.c` and engine backend `src/omega_blackwell_engine.c` still call `m16_native_*` directly. | **Does not use it.** The branch defines its own interface, `OmegaSubmitOps` in `src/omega_gpu_submit_iface.h`, with an nvrm and a dxg implementation. No `OmegaGpuBackend` sits on it yet (`dxg-backend.md` section 5). | Designed around it: the contract's native owners per driver responsibility are listed in the boundary doc section 2. No native implementation exists (boundary doc section 6, "C, remaining"). |
104| Biggest open question | none for the GB10 | NVIDIA's private driver data blobs and whether the Windows driver accepts Omega's own Blackwell method stream at all (`dxg-backend.md` section 4: "the largest open question"). `docs/WINDOWS-GPU-PATH.md` section 3 found no public project doing raw NVIDIA submission over `/dev/dxg`. | Everything the Linux driver does today: GSP firmware, memory, page tables, queues, interrupts, reset (boundary doc section 2, all rows NOT_RUN). |
105| Chip code reused | all | The same encoder and QMD; the target table lists the RTX 5070 as sm_120, "THEORETICAL: built from public sources only, never run on the chip" (`src/omega_bw_target.h` on `rig/gb20x`). | The encoder and QMD builder are plain C with no Linux dependency (aienos `docs/GB10_NATIVE_DEPENDENCY_MAP.md`, plain-English summary, item 1); the freestanding build checks that for the files in `GPU_FS_SRCS`. |
106
107Two caveats a reader should keep:
108
109- The aienos dependency map is pinned to an older Omega commit (`2ae8677c`, its "Pins" table). Where it disagrees with the
110 boundary doc, which tracks `omega_gpu_session.c` moving onto the platform contract, the boundary doc is newer.
111- The `rig/gb20x` interface and the platform contract describe the same job (open a device, allocate, queue, submit,
112 wait) with different shapes. The branch's own text does not mention the platform contract
113 (`grep -i platform docs/rig/dxg-backend.md` finds nothing). Whether the two should be merged is a design question for
114 the lane that owns that branch (ledger L024); this note does not decide it and did not edit the branch.
115
116## 5. What a new GPU needs
117
118For a GPU in the same family (another Blackwell part such as the RTX 5070, sm_120), the work is mostly *measuring*. For a
119different family it is *rewriting*. In order:
120
1211. **Identify the chip.** Add a target row: PCI ids, architecture and implementation ids, SM version as the driver
122 reports it, compute and channel and user-mode class numbers, QMD version and shared-memory fields, SM count, L2 size,
123 memory model (unified like GB10 or discrete VRAM), host barrier. The shape of this row is `OmegaBwTarget` in
124 `src/omega_bw_target.h` on `rig/gb20x`; each field there carries an evidence grade, and fields nobody has published are
125 `UNKNOWN` until measured on the card. Then admit it in the library: add its PCI device id and SM version to
126 `chip_target` in `om/admission/chip_admit.om` and to the reference table in `tests/test_chip_admission.c`. Until then
127 `nvrm_open` refuses the chip with one sentence before it opens any `/dev/nvidia` node.
1282. **Machine code.** Same family: check whether `src/omega_blackwell_encoder.c` output is valid on the new chip. For
129 sm_120 versus sm_121 the branch records "no sm_120 vs sm_121 encoding split is public" (`omega_bw_target.c`, field
130 `isa`, evidence INFERRED). Different family: a new encoder, new generators for every `omega_blackwell_codegen_*.c` kernel
131 you need, and new emitter helpers (the whole `CHIP_SPECIFIC` block of the table).
1323. **Launch descriptor.** Confirm or replace the QMD builder (`src/omega_blackwell_qmd.c`) and the constant-bank layout.
1334. **Class numbers and setup words.** Replace the `0xcec0` setup block. It lives in 11 files; today a change means 11
134 edits (`grep -l 0x0000cec0 src/*.c src/runtime/*.c`). Folding the copies into one is a cleanup this slice records but
135 does not make.
1365. **Cache and coherence rules.** Decide for the new memory model which buffers may be GPU-cached, which must be
137 uncached, and what flush ends a command list. The contract refuses a cached host-polled buffer
138 (`OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY`); a chip with coherent memory would change that rule in one place
139 (`src/omega_gpu_platform.c`) and in the cache notes of `mem_cached`, `cmdlist`, `prefill`.
1406. **Code buffer tail.** Check whether the new chip also prefetches past the last instruction (`src/omega_gpu_code_alloc.h`).
1417. **A platform implementation.** Provide the services in `OMEGA_GPU_SVC_REQUIRED_V1` (time, wait, lock, MMIO, DMA, sync,
142 completion) and `OMEGA_GPU_SVC_REQUIRED_SESSION` (device, queue, clock, host memory), at ABI 1.2, and pass
143 `omega_gpu_platform_check_for`. `tests/test_omega_gpu_platform.c` reaches every refusal; use it as the starting test.
144 The Linux reference (`src/omega_gpu_platform_linux.c`) is the worked example.
1458. **A backend.** Either the vector backend (`OmegaGpuBackend`, example `src/omega_blackwell_engine.c`) or the session path.
1469. **Qualification on the chip.** The M17 and M18 gates (Omega `src/omega_blackwell_gates.c`) and the poison-word vector add are
147 the first correctness check; nothing is claimed for a chip until they pass there.
14810. **Update the table.** `make test-runtime-portability` refuses a new `omega_gpu_*`, `omega_blackwell_*`, `omega_bw_*` or `omega_ampere_*`
149 file that has no row.
150
151## 6. Limits of this note
152
153- It reads source. No GPU, WSL2 machine or native boot was used; every "works" in the table of section 4 is a claim of the
154 source it cites, and the WSL2 and native columns have no chip evidence at all.
155- `class` is a judgement per file. The mechanical parts (includes, the freestanding list) are checked; whether a reason is
156 right is not.
157- The dxg and native documents live on other branches and repositories and can change. They were read from
158 `origin/rig/gb20x` (`12e17891`), aien-rig `origin/app/v0`, and aienos `origin/main` on 2026-10-19.
159
160## 7. Reproduce
161
162```
163make test-runtime-portability # the check plus the negative controls; host only
164awk -F'\t' '!/^#/ && $1!="file" {n[$2]++} END {for (c in n) print c, n[c]}' docs/runtime/portability_table.tsv
165```
166
167Evidence of the controls and of the freestanding build is in `evidence/RUNTIME-R3-PORT/`.