Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/docs/ARCHITECTURE.md # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / docs / ARCHITECTURE.md` 154 lines · 13257 bytes Raw Blame History Rendered 1 # CUDApp architecture: today's layers and the portable-top / thin-backend split 2 3 **Status:** PROPOSED design (2026-10-27). Only the host-side pieces listed in §3a are implemented. No code moves until 4 the gate below is met. The decision record is ADR 0043 in aien-dev/aien-architecture-mv 5 (`docs/adr/0043-gpu-stack-portable-top-thin-backend.md`, draft). Read that first; this file is the 6 file-level map for CUDApp at main ``780a0af1``. 7 8 **Companions, not repeated here:** `docs/runtime/PORTABILITY.md` and `portability_table.tsv` (per-file 9 chip and OS binding, checked by `make test-runtime-portability`; this file agrees with its finding that 10 the session, command list and kernel APIs hide the driver but not the GPU). PORTABILITY.md cites 11 `docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md` and `OMEGA_GPU_ENGINE.md`; those live in omega-mv 12 (present on omega-mv main ``e5b32567``), not in this repo. 13 14 **Gate.** Work under this design starts after P0 publishes a same-box head-to-head and bars C2–C5 are 15 QUALIFIED on the GB10 (GPU-stack plan, phases P2–P4). 16 17 **Language.** Existing C stays where it is and is not reworked. New host-runtime code, every new 18 backend and the backend ABI are written in Omega (`.om`). Any new C needs a missing-feature reason with 19 an Omega extension proposal filed, behind a `migration-pending` build switch. 20 21 ## 1. Target layers 22 23 ``` 24 Omegese kernels ──► kernel IR + checker2 (omega-mv, pinned) 25 │ per-target lowering 26 ┌──────────────── portable top (.om, CUDApp) ───────────────────┐ 27 │ model graphs, decode scheduling, batching, serving, memory │ 28 │ planner (weights, KV pool, scratch), streams/events, sharing, │ 29 │ watchdog policy, public runtime API │ 30 └───────────────────────┬────────────────────────────────────────┘ 31 OmegaBackend ABI 2.0: 30 calls (backend/abi.om) 32 ┌────────────┬────────────┬─────────────┬───────────┬───────────┐ 33 │ gb10 │ amd │ vulkan │ metal │ cpu-ref │ 34 │ sm_121 │ gfx942 / │ SPIR-V │ MSL text │ AArch64 │ 35 │ nvrm + UVM │ gfx1151 │ (loader: │ (needs │ CI and │ 36 │ QMD/PB │ KFD + AQL │ needs E2) │ E2) │ negative │ 37 │ │ (needs E1) │ │ │ controls │ 38 └────────────┴────────────┴─────────────┴───────────┴───────────┘ 39 Integrations (omega-bridge connected repos): ggml-omega, vLLM platform plugin, ORT plugin EP 40 ``` 41 42 E1, E2 and E3 are the Omega extension proposals named in ADR 0043: E1 a KFD `devctl` allowlist, E2 43 checked shared-library calls and Mach-O output, E3 IR v7 (subgroup width, shared budget, nesting cap and 44 accuracy class as target parameters; address spaces, atomics, f16/bf16/fp8, one tiled MMA op), filed as 45 aien-dev/omega-mv#883. 46 47 ## 2. Where today's files sit 48 49 Classes: **TOP** portable; **ENC** encoder, QMD, pushbuffer words; **KER** tuned sm_121 kernel 50 generators; **DRV** driver client; **MIXED** has to be split logically. Line numbers are at ``780a0af1``. 51 52 | Class | Files | 53 |---|---| 54 | TOP | `omega_core`, `omega_canonical`, `omega_types.h`, `omega_vector`, `sha256`, `omega_runtime_api.h`, `omega_gpu_platform.{c,h}` (interface), `omega_gpu_engine` (interface), `omega_gpu_wait`, `omega_gpu_mem_cached`, `omega_gpu_serving`, `omega_gpu_chip`, `omega_gpu_hostmath`, `omega_gpu_fmt` | 55 | ENC | `omega_blackwell_codegen.{c,h}` core (BlackwellIR, regalloc, encode), `omega_blackwell_encoder`, `omega_blackwell_qmd`, `omega_bw_em.h`, `omega_bw_em_q.h`, `omega_bw_reconv.h`, `omega_gpu_code_alloc.h`, `omega_cubin`, `omega_blackwell_realize`, `omega_blackwell_matmul` | 56 | KER | `omega_blackwell_codegen_{attn,bf16,dec,gemm,moe,moe2,pattn,pf,pfhost,qg,qmma,router,tc,tc2,tern}`, the matmul generators inside `omega_blackwell_codegen.c`, `omega_gpu_fp8_pack.c`, `omega_gpu_pfgemm.c` | 57 | DRV | `nvrm/` (`nvrm.c` 908 lines, RM client against the 580.173.02 headers), `m16/`, `omega_gpu_platform_linux.c`, `omega_blackwell_engine.c`, `omega_blackwell_submit.c` | 58 | MIXED | `omega_gpu_session.c` (QMD and pushbuffer construction in `omega_gpu_session_launch` :445; includes qmd/submit :18-19), `omega_gpu_cmdlist.c` (`emit_tail` :199, `emit_stamp` :219, `emit_inline_qmd` :226, PCAS method words :308-309), `omega_native_artifact.c` (packaging is TOP, QMD template bytes are ENC), every `omega_gpu_*_api.c` (tensor lifetime is TOP; inline emitters in `attention_api.c` :69-143 and `elementwise_api.c` :61-145 are KER) | 59 | Already `.om` | `native/nvrm/context.om`, `native/blackwell/{trace-emit,trace,vector,launch}.om`; in the default hosted build: `om/encoder/bw_enc_sm121.om`, `om/cubin/cubin_elf.om`, `om/encoder/ampere_enc_sm86.om`, `om/encoder/amp_runtime.om` and the aien-gpu platform's decisions and request bytes, `native/aiengpu/context.om` (CUDApp#128; its effects stay migration-pending C). `om/units.sh` emits separate portable `src/cudapp_om_*.c` units through the pinned omega-bridge, with source-to-C provenance in `src/cudapp_om_units.ident`. No AArch64 executable-code trampoline is needed on x86. Historical C encoder/cubin bodies remain only for freestanding or differential-oracle switches. Ampere qualification is [NOT_RUN](PORT-AMPERE.md). | 60 61 Three structural defects the split removes (in the `.om` stack; the C stack is frozen, not reworked): 62 63 1. **Two backend tables over one driver client.** `OmegaGpuPlatform` 1.2 (`omega_gpu_platform.h`, 22 64 function pointers) under session and cmdlist; `OmegaGpuBackend` (`omega_gpu_engine.h`, 15 ops, 65 VECTOR_1D only) under the job engine, installed at `omega_blackwell_submit.c:102`. 66 2. **Raw NVIDIA method words cross the seam.** `queue_submit(words)` makes QMD and pushbuffer encoding 67 happen above the backend, in session and cmdlist. 68 3. **Two bypasses.** `omega_blackwell_engine.c` (:125-516) and `omega_blackwell_submit.c` (:185-328) call 69 `nvrm_*` and `m16_native_*` directly. 70 71 ## 3. The backend ABI (30 calls) 72 73 The full contract table, with today's GB10 function for each call, is in ADR 0043 Decision 2. 74 75 | Group | Calls | 76 |---|---| 77 | Negotiate and device (7) | `ob_negotiate`, `ob_device_count`, `ob_device_open`, `ob_device_close`, `ob_device_caps`, `ob_device_status`, `ob_diag_text` | 78 | Memory (7) | `ob_mem_alloc`, `ob_mem_import_host` (zero-copy), `ob_mem_free`, `ob_mem_flush`, `ob_mem_invalidate`, `ob_mem_advise`, `ob_mem_info` | 79 | Code (3) | `ob_code_load`, `ob_code_info`, `ob_code_free` | 80 | Queues and dispatch (4) | `ob_queue_open`, `ob_queue_close`, `ob_dispatch`, `ob_submit` | 81 | Graphs (4) | `ob_graph_begin`, `ob_graph_end`, `ob_graph_launch` (one doorbell per token, patch list), `ob_graph_free` | 82 | Sync and recovery (5) | `ob_fence_wait`, `ob_event_record`, `ob_queue_wait_event`, `ob_queue_reset`, `ob_clock_ns` | 83 84 Leaving the backend compared with `OmegaGpuPlatform` 1.2: `time_now_ms/ns`, `wait_ms`, `lock`, `unlock`, 85 `host_alloc`, `host_free` (the top gets them from Omega host words), `mmio_*` and `irq_wait` (NULL on 86 Linux today), `queue_submit(words)` (replaced by `ob_dispatch` + `ob_submit`). 87 88 Code-object formats accepted by `ob_code_load`: `SM121_RAW`, `AMDGPU_HSACO`, `SPIRV_VK`, `SPIRV_CL` 89 (OpenCL-environment SPIR-V: Kernel capability, Physical64 addressing, for OpenCL runtimes), 90 `MSL_SOURCE`, `AARCH64`. `CUBIN` is reserved and unused. omega-mv #864 (`seed/sm80/cubin.om`) was closed unmerged; see `docs/CUBIN_WRITERS.md`. 91 92 ### 3a. First pieces that exist (IMPLEMENTED; host EXERCISED; hardware NOT_RUN off the GB10) 93 94 PLAN P3 lets multi-target work that needs no GB10 time start before the gate above; no existing file 95 moves. All of it is seeded Omega except one migration-pending C launcher. 96 97 | Piece | File | Status | 98 |---|---|---| 99 | Target table, one row per GPU family; `make doctor OMC=…` prints it | `backend/targets.om` (`targets doctor`) | IMPLEMENTED. GB10 (sm_121) SUPPORTED; every other GPU row PLANNED, hardware NOT_RUN; PoCL and lavapipe rows are HOST-ONLY (not a GPU) | 100 | Code-object loader checks for `ob_code_load` | `backend/targets.om` (`targets load FORMAT FILE [ENTRY or gfx]`) | IMPLEMENTED: SPIR-V header, instruction stream, capability/addressing/memory model per environment, entry point; HSACO ELF64, HSA OSABI with code object v4/v5, EM_AMDGPU, e_flags mach, PT_NOTE NT_AMDGPU_METADATA msgpack (`amdhsa.target`, `amdhsa.version`, `amdhsa.kernels`); SM121_RAW shape. MSL_SOURCE and AARCH64 refused (PLANNED), CUBIN refused (reserved) | 101 | SPIR-V builder: FP32 vadd and FP32 16-term sum (`fsum16`), OpenCL and Vulkan forms, plus planted-wrong mutants | `backend/spirv/emit.om` | IMPLEMENTED; every module passes `spirv-val`. Hand-built words because the pinned seed omc IR mode lacks the needed floating-point operations. E3 (omega-mv#883) tracks OSC IRv7, a separate compiler path; it does not by itself enable this seed SPIR-V path | 102 | Host reference and bit compare | `backend/spirv/conform.om` | IMPLEMENTED; vadd reference digest equals `hello_gpu --sim` output digest | 103 | Launcher that hands a module to PoCL (CPU) or Mesa lavapipe (CPU) | `tools/multitarget/spirv-host.c` | migration-pending C, `CUDAPP_MIGRATION_PENDING_SPIRV_HOST` default OFF; reason: no checked shared-library call (E2, omega-mv#888); successors `backend/opencl/host.om`, `backend/vulkan/host.om` | 104 | gfx1151 vadd code object | `backend/amd/vadd-gfx1151.s` | ORACLE fixture assembled by `llvm-mc` + `ld.lld` to test the loader (see §6); not a first-party encoder | 105 106 `make test-multitarget OMC=…` (`tests/multitarget/run.sh`) runs all of it with negative controls: 107 corrupted modules fail `spirv-val` and the loader, wrong environment or entry is refused, planted-wrong 108 kernels and a flipped output byte fail the compare, the launcher's isolation scan fails when told to 109 forbid the CPU driver it loads, and patched HSACO copies (wrong gfx, e_flags, OSABI, ABI version, note 110 type, note target, truncation) are refused. Bit-exact on PoCL and lavapipe means those CPU 111 implementations only; no AMD, Intel, Apple, Qualcomm, Arm, Imagination, Broadcom or Vortex device has run 112 anything (hardware NOT_RUN). A real AMD run next needs a queue: KFD + AQL through E1 (KFD `devctl` 113 allowlist) or the HSA runtime through E2, on a machine with that GPU. 114 115 ## 4. Per-token path, today and target (GB10) 116 117 | | Today (`omega_gpu_decode_graph`, Qwen3-30B-A3B) | Target | 118 |---|---|---| 119 | Launches per token | 436 (9 per layer × 48 + 4) | same graph | 120 | Submissions / doorbells | 1 / 1 (PCAS mode, cmdlist.c:325-333) | 1 / 1 via `ob_graph_launch` | 121 | CPU writes per token | 1 KB constants + 1 KB QMD per launch, ≈872 KiB [INFERENCE] | patch list only; QMDs pre-encoded at `ob_graph_end` | 122 | Weights | copied: `omega_gpu_fp8_api.c:269-275` `memcpy` + sync | mmapped file mapped by `ob_mem_import_host` | 123 124 Every row in the Target column is PROPOSED and needs a paired A/B receipt before it is described as 125 faster. 126 127 ## 5. Public API consequences 128 129 - `docs/runtime/omega_runtime_api.manifest` (ABI `omega_runtime 0.1`, 91 functions, 21 STABLE) stays 130 as is until a cutover. Moving STABLE `omega_gpu_session_launch` / `OmegaGpuLaunch` to a code object 131 is a MAJOR bump. 132 - The decode-path APIs are not in the manifest today: fp8, fp8gemm, bf16_gemv, decode_attn, router, 133 tern, tcgemm, prefill*, moe, decode_graph. They enter it as EXPERIMENTAL before any of them changes 134 (CUDApp#124). 135 - `aien-serve-http` is not in CUDApp (aien-dev/aien-sovereign-core-mv `crates/aien-serve-http`, pin 136 ``754c07b1``); it consumes this library through that repo's FFI crate [INFERENCE]. 137 138 ## 6. Provenance rules for any backend 139 140 - Encodings come from Mesa NAK (MIT) plus chip tests (`THIRD_PARTY.md` §2). `docs/HOW_I_DID_IT.md` line 36 141 records a preference for nvcc output where it and NAK disagree; every encoder field gets a NAK 142 citation or a chip test before the GB10 encoder is declared the backend. 143 - Nothing derived from omega-mv #864 (`seed/sm80/cubin.om`) enters a backend. That pull request was closed unmerged on 2026-10-27. See `docs/CUBIN_WRITERS.md`. 144 - AMD encodings come from AMD's published ISA reference guides; LLVM (`llvm-mc`, `llvm-readelf`) is a 145 verification oracle only. The terms of the ISA guides are an open item for the IP-lawyer review. 146 `backend/amd/vadd-gfx1151.s` is such an oracle fixture: it exists to test the loader, is labelled 147 ORACLE, and is not the AMD backend's encoder. 148 - Apple: MSL text through Apple's public compiler; no AGX reverse engineering. 149 150 ## 7. Review 151 152 See `docs/REVIEWING.md` and `.github/CODEOWNERS`. GitHub enforces code-owner review only after the 153 default-branch ruleset requires it. That ruleset is Drake's change. `@drakestapleton` is the only 154 owner until the GPU-core and IP-review teams exist and are added back with write access.