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 / backend / amd / kfd / launch / README.md

203 lines · 16724 bytes Raw Blame History Rendered
1# Direct gfx942 KFD launcher
2
3Intent: exercise our seeded gfx942 code objects through Omega on MI300X, with a CPU-checkable host path and honest hardware receipts. The executable uses Linux/KFD syscalls directly; neither ROCr nor HIP is in its production path. Python and C under `tests/amd-kfd-launch/` are external test instruments and notebook measurements only.
4
5## Build and CPU acceptance
6
7`COMPILER` records the omega-mv source head and the seeded compiler digest; it is generated from the root `PIN` by `make pin-compiler` (the `regen` line of the root `REPIN`; pin-follow.sh moves PIN), never edited by hand, and `make test-pin-sync` (part of `make test`) fails when it differs. Concatenate `om2`, `common.om`, `elf.om`, `device.om`, `dispatch.om`, `plan.om`, `main.om`, then `../cli.om`, and pipe into that compiler. Prefix `target x86linux` before `om2` for x86. The gate performs this composition, validates the compiler digest before execution/output, and builds both targets:
8
9```
10python3 -I tests/amd-kfd-launch/check.py /absolute/path/to/omega-mv/seed/out/omc
11```
12
13For release readiness, run the repository target below. It first runs the AMD,
14KFD, execution and multitarget suites with their original seeded compiler, then
15the launcher suite with its own newer pin. This catches shared-CLI compatibility
16and binary-output regressions as well as native-launcher failures. Both compiler
17paths are explicit and independently digest-checked; a missing tool or pin fails.
18
19```
20make test-amd-release OMEGA_OMC=/absolute/path/to/original/omc AMD_LAUNCH_OMC=/absolute/path/to/launcher/omc
21```
22
23On Spark run CPU jobs through the assigned pool lock, nice and CPU affinity. `AMD_KFD_LAUNCH_OUT` chooses a new evidence directory; do not overwrite an old receipt. The gate emits `results.json`, `summary.json`, binaries, malformed objects and calculation queries/results. It exercises native and qemu-x86_64 ELF parsing and absent-device errno; a native ptrace instrument replaces device opens with memfds and all KFD ioctls with checked replies. It checks GPU identity, UAPI layout, same-VA render mappings, separate KFD doorbell mapping, queue fields, generic CLI ring wrap, output bytes and cleanup. A second instrument checks each native instruction's packet publication order. Wrong GPU records, early valid headers and missing completion must fail. These instruments are not a GPU emulator, shader executor or hardware qualification.
24
25## Commands
26
27```
28omega-launch plan PLAN.bin CODE_OBJECT... WEIGHT_FILE... [TIMEOUT_NS]
29omega-launch inspect OBJECT.hsaco KERNEL
30omega-launch vadd VADD.hsaco vadd [TIMEOUT_NS]
31omega-launch run OBJECT.hsaco KERNEL GROUPS_X GROUPS_Y ARGS.bin INPUT... OUTPUT.bin
32```
33
34The generic grid is groups X/Y with workgroup dimensions 64/1/1 (wave64). The vadd smoke uses our vadd object and checks every output bit. `inspect` validates without opening a device. Objects are trusted first-party kernels, not an untrusted-code sandbox.
35
36The loader accepts ELF64 little-endian AMDHSA code-object V5, gfx942, bounded nonoverlapping load segments and a defined `.kd` descriptor. It loads segments at their virtual offsets and zeroes BSS; no relocations, negative entry offsets, wave32, scratch/private-segment requirement, an ENABLE_SGPR_QUEUE_PTR requirement, or oversize LDS. No LLVM-generated object substitutes for our seeded writer. Malformed input is refused before GPU allocation.
37
38### Argument manifest
39
40All integers are little-endian. The header is `OMKFD001`, followed by five u64 fields: raw kernarg byte length, output byte length, repeat count, timeout nanoseconds and relocation count. Each relocation is two u64 values: raw-kernarg byte offset and input-buffer index. Raw kernarg bytes follow the relocation pairs. There must be exactly that many bytes and the raw size must equal the descriptor's kernarg size. Pointer slots must be aligned, in bounds, unique and initially zero. Indices refer to the positional input files; the index equal to their count means the output buffer. The launcher writes only these slots with addresses of its own mapped allocations. Other scalar fields remain as supplied.
41
42A missing timeout or zero means no automatic deadline. A positive timeout is the
43caller-selected watchdog in nanoseconds. Generic run takes the same zero/unlimited
44convention from its argument manifest. Dispatches over ten seconds emit a one-time
45warning while waiting and may still complete. The threshold is not a refusal limit.
46
47Exit classes: 64 CLI/argument contract; 65 ELF/span contract; 66 topology; 67 insufficient KFD ABI; 74 syscall or I/O failure; 75 completion timeout; 77 `/dev/kfd` absent (prints `errno=2`). Compiler handle/span refusals remain documented traps. Normal completion destroys the queue, releases mappings/allocations and closes fds. On an error exit Linux releases the process's descriptors and KFD context; no persistent service or queue is created.
48
49## Memory and dispatch
50
51Select a gfx942 topology node and its DRM render minor; use that node's GPU ID, never an NVIDIA identifier. GET_VERSION requires KFD 1.14 or later, then ACQUIRE_VM binds the render fd. Each buffer has one 2 MiB-aligned reservation and 64-bit sizes. ALLOC receives its compiler-bound address, MAP_MEMORY its checked GPU-ID span, and the returned mmap offset is mapped through the render fd at that same reserved address. Public VRAM holds code, inputs and output; In the generic command, GTT holds kernargs and queue state. The persistent plan places static kernargs in VRAM; its token cell and queue state stay in coherent GTT. The doorbell is instead mapped through `/dev/kfd`. No raw caller-provided ioctl address is trusted.
52
53Discovery reads `gpu_id` before properties, skips CPU nodes (`gpu_id=0`), and
54skips nodes whose files cannot be opened or read. Each skipped failure records
55its errno and node number. It accepts `gfx_target_version 90402`, logs the chosen
56node/GPU ID/render minor, and opens that exact render device. If the container
57does not expose it, `render_open` fails explicitly; another GPU's render device
58is never silently substituted. The CPU gate injects EPERM at the syscall boundary
59(including under root) for both `gpu_id` and `properties`, with CPU nodes and a
60node-3-only GPU fixture. Mutants that abort on either skipped node must fail.
61
62Each device step emits `OMEGA step NAME ok|fail errno=N phase=before|after detail=N`.
63A `before` row means the step is about to be attempted, not that it succeeded.
64Detail identifies the node, selected GPU, render minor, buffer index, doorbell
65offset, byte count or packet count as applicable. Kernel errno is preserved;
66contract failures use EINVAL, I/O/readback failures EIO, missing gfx942 ENODEV,
67and polling timeout ETIMEDOUT. Raw `OMEGA error=N` and existing refusal exits
68remain for syscall failures. All allocation/map buffers have separate rows.
69
70Queue state includes ring, write/read pointers, context save and a coherent USER signal. The signal starts at the repeat count; each dispatch decrements it. Context sizes follow the cited ROCT gfx942 formula using actual node SIMD, shader-array and XCC properties, rather than a card-name constant. gfx942 AQL needs no EOP allocation. Context debug headers follow the ROCT ABI. The ring's configured size is not a limit on repeats: read-pointer backpressure permits wraparound.
71
72The launcher owns a zero-initialized 4096-byte AMD queue object. Its write and
73read dispatch IDs are at bytes 56 and 128 of the same live mapping. CREATE_QUEUE
74receives the same opaque queue handle for both pointers, with zero address
75bytes in the caller header. The compiler selects the fixed AMD AQL layout,
76binds base+56 and base+128, and validates the complete 2304-byte amd_queue_v2_t ABI object,
77handle lifetime and writable kind. The launcher owns and clears a 4096-byte
78allocation containing that object.
79
80The HSA prefix names the ring, queue size and ID. The queue's read-pointer base
81offset is 128, pointer mode at byte 180 is 2, and the inactive USER signal is a
82separate live allocation. GET_PROCESS_APERTURES_NEW supplies LDS and scratch
83aperture high words for the selected GPU, with exactly one matching record
84required. A zero-count query obtains the inventory size; a checked owned mapping
85holds the records with one spare slot. A full reply grows the mapping and retries,
86so the launcher has no fixed GPU-count table. The u32 ABI field bounds the count.
87Empty, oversized, duplicate, invalid or unmatched results are refused. The CPU
88gate includes 80 devices and an inventory that grows between query and fill.
89CU and wave limits come from the selected node's topology properties. The trusted
90kernel subset still excludes private scratch and queue-pointer arguments.
91
92The AQL ring is executable, readable, writable, coherent GTT memory (allocation
93flags 0xe6000002). Both the full queue layout and executable ring were required
94in the MI300X tests. A non-executable ring generated a GPU memory fault at the
95ring address; setting executable alone with the old minimal queue still timed
96out. No diagnostic observer, event injection, HIP or ROCr participates in the
97production path. The CPU gate checks the entire queue image and zeroed tail,
98ring permission, aperture selection and inactive signal, and rejects deliberately
99broken versions.
100
101The packet body is written while its header is INVALID. A CPU fence precedes the final aligned header write; further fences precede write-pointer and 8-byte doorbell publication. The dispatch has system acquire/release fence scopes and barrier semantics. The launcher bounds host polling by the requested monotonic timeout, waits for signal zero, fences, and copies output. It reports `OMEGA dispatch_ns=... packets=...`; this is host-monotonic dispatch-and-wait time, not GPU event time and not model tokens/s.
102
103Success and timeout also emit `OMEGA diag NAME VALUE` decimal rows, read only
104from existing owned mappings: queue read/write pointers, queue properties and read-pointer base offset, signal kind/value,
105last published packet slot/header and actual packet kernel/kernarg addresses,
106descriptor fields, and the first eight available output words. Vadd reports
107counts matching its expected sum and NaN fill. `create_queue_input_qword_N`
108reconstructs the input u64 at byte offset `8*N`, including addresses that the
109pinned compiler binds privately; queue ID and full doorbell offset are outputs.
110The CPU instrument compares all input qwords with the actual intercepted ioctl
111block and tests untouched output, output without signal completion, and normal
112completion. These rows are observations, not a timeout diagnosis.
113
114No SET_MEMORY_POLICY or debugger RUNTIME_ENABLE is needed by this path. Kernel registration configures SH_MEM bases/config; the gfx9.4.3/9.4.4 path sets F8_MODE. The default/alternate cache-policy ioctl is not the initializer. This is a source-based prerequisite, not a measurement of an installed remote driver's register state. See root `PROVENANCE.md` for the named kernel tag and manual requirement.
115
116## One-cell notebook bundle
117
118`tests/amd-kfd-launch/bundle.py --gate GATE_DIR --out NEW_DIR` packages the verified
119x86 executable and vadd object into `cell.py`, using xz then base85. Source commits
120and hashes are generated into `bundle.json`; README and SHA256SUMS are generated.
121The manifest covers every delivered file except itself.
122
123The targeted diagnostic bundle is `notebook-probe/launch4/`. It runs the corrected
124Omega vadd once, while the Python parent samples the child's KFD proc queue,
125occupancy and VRAM files read-only. Missing files are explicit. After Omega exits,
126even on timeout, it runs the identical object and inputs once through the installed
127torch-loaded HIP runtime, labelled `REFERENCE (AMD runtime loading our object, not
128the Omega launcher)`. Torch supplies the runtime, not kernels or a correctness
129oracle. No other kernels, doorbell variants or added Omega packets are run.
130
131The cell persists `amdserve-launch4.txt` after every line and retains raw child
132stdout/stderr. CONTROLS is first; topology and every launcher stdout line are
133included; RESULT is last even on exceptions. `notebook-check.py NEW_DIR GATE_DIR`
134checks both parsers, real x86/qemu refusals and absent-device behavior, receipt
135streaming, read-only proc sampling while a real child waits, and digest refusal.
136
137The earlier launch4 bundle remains a vadd diagnostic harness. Hardware evidence
138for the full queue fix is recorded separately: the uninstrumented x86 executable
139`fd85139a4ea58a892a74b910c6432038feb5edbe41c6e4f118357cc57f30aa60`
140passed vadd, 200 repeated vadd packets across ring wrap, fsum16, SGEMM and FP8 GEMV
141with exact fixture outputs on MI300X. These kernel checks do not establish full
14227B serving or a like-for-like Spark comparison.
143
144## Persistent model plans
145
146`plan` validates an OMPLAN01 file, all code descriptors, weight-file extents and
147relocations before opening KFD. The format is specified in [PLAN.md](PLAN.md).
148Plans and kernels are trusted first-party executable input. This is a command-line
149inference executor; it does not expose an HTTP service or accept untrusted plans.
150
151Code objects load once. Model buffers occupy checked, page-aligned slices of one
152VRAM allocation and one coherent GTT allocation. A buffer's relocations may address
153only its declared byte range, excluding alignment padding. This avoids consuming a
154runtime map handle for each model tensor. Normal weight ranges copy directly from
155files; BF16 vectors widen exactly into F32. Initialization and zero fill precede
156timing. Kernargs and packet templates are built once. Each step replays the list,
157with ring backpressure and one completion signal on the last dispatch. The plan
158ring grows from the established 1024-byte minimum to a power of two large enough
159for the complete step. Its size must fit the KFD UAPI byte-count field. The host
160invalidates owned slots, copies packet bodies in contiguous chunks, fences,
161publishes aligned headers, then fences before publishing the write pointer and
162one doorbell per step. Static kernargs reside in VRAM. No performance claim
163follows from those implementation choices without a matching card measurement. The host
164writes prompt tokens, then reads generated IDs from the coherent token buffer.
165
166`OMEGA_STEP i tok=T us=U` measures monotonic wall time from the first packet write
167through the step completion signal. `OMEGA_PLAN ids=[...]` contains exactly the
168requested generated IDs after successful cleanup. A timeout exits 75 and never
169prints the completion marker. Prefill is token-by-token; decode statistics exclude
170prompt steps. Allocation, weight loading, template construction and text decoding
171are outside these per-step timings. Compare these boundaries explicitly with any
172other runtime's numbers.
173
174The CPU gate also runs `plan-check.py`: malformed plans on both target parsers,
175independent code objects, raw file ranges, BF16 widening, data-pool initialization,
176shared allocation offsets, ring wrap, output IDs, missing completion and cleanup.
177`publication.c` observes a nonzero group-segment size and rejects a deliberate
178swap of the packet's group/private fields. CPU simulation is not card proof.
179
180The release gate rebuilds every object in the native Qwen fixture manifest
181`tests/amd-kfd-launch/qwen38-objects.json` and requires byte-identical code objects
182and kernarg sizes. Missing source and changed-object controls must be caught.
183A notebook carrying an unlanded object cannot qualify the release tree.
184
185## Full-model hardware qualification
186
187The [November 13 scratch-refusal native model receipt](../../../../evidence/amd-qwen38-native-refusal-20261113/README.md)
188records the final hardware-qualified executable, the exact coding reference check, five longer
189requests compared with an independent AMD execution path, and the archived
190Spark comparison. It retains raw IDs, timings, controls, source/compiler hashes,
191external reproduction instruments and the cross-engine numerical differences.
192The receipt states timing boundaries and memory-accounting limits explicitly.
193
194Plan parser refusals print `OMEGA refuse plan field=REASON` before exit 64.
195The CPU table checks the reason and runs a valid positive twin through the same
196argument builder before counting a refusal. ABI publication checks call both real
197packet writers, comparing private=20/group=4096 with the independent AQL encoder;
198this synthetic unit does not expand the ELF loader's supported scratch subset.
199
200Numeric refusals preserve empty payload stdout and report
201`OMEGA refuse number field=N` on stderr with exit 2. The six field IDs are
202specified at the shared CLI parser's diagnostic helper. Valid numeric parsing
203and its unsigned bounds are unchanged.