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/backend/amd/kfd/launch/README.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 / backend / amd / kfd / launch / README.md` 203 lines · 16724 bytes Raw Blame History Rendered 1 # Direct gfx942 KFD launcher 2 3 Intent: 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 ``` 10 python3 -I tests/amd-kfd-launch/check.py /absolute/path/to/omega-mv/seed/out/omc 11 ``` 12 13 For release readiness, run the repository target below. It first runs the AMD, 14 KFD, execution and multitarget suites with their original seeded compiler, then 15 the launcher suite with its own newer pin. This catches shared-CLI compatibility 16 and binary-output regressions as well as native-launcher failures. Both compiler 17 paths are explicit and independently digest-checked; a missing tool or pin fails. 18 19 ``` 20 make test-amd-release OMEGA_OMC=/absolute/path/to/original/omc AMD_LAUNCH_OMC=/absolute/path/to/launcher/omc 21 ``` 22 23 On 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 ``` 28 omega-launch plan PLAN.bin CODE_OBJECT... WEIGHT_FILE... [TIMEOUT_NS] 29 omega-launch inspect OBJECT.hsaco KERNEL 30 omega-launch vadd VADD.hsaco vadd [TIMEOUT_NS] 31 omega-launch run OBJECT.hsaco KERNEL GROUPS_X GROUPS_Y ARGS.bin INPUT... OUTPUT.bin 32 ``` 33 34 The 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 36 The 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 40 All 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 42 A missing timeout or zero means no automatic deadline. A positive timeout is the 43 caller-selected watchdog in nanoseconds. Generic run takes the same zero/unlimited 44 convention from its argument manifest. Dispatches over ten seconds emit a one-time 45 warning while waiting and may still complete. The threshold is not a refusal limit. 46 47 Exit 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 51 Select 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 53 Discovery reads `gpu_id` before properties, skips CPU nodes (`gpu_id=0`), and 54 skips nodes whose files cannot be opened or read. Each skipped failure records 55 its errno and node number. It accepts `gfx_target_version 90402`, logs the chosen 56 node/GPU ID/render minor, and opens that exact render device. If the container 57 does not expose it, `render_open` fails explicitly; another GPU's render device 58 is 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 60 node-3-only GPU fixture. Mutants that abort on either skipped node must fail. 61 62 Each device step emits `OMEGA step NAME ok|fail errno=N phase=before|after detail=N`. 63 A `before` row means the step is about to be attempted, not that it succeeded. 64 Detail identifies the node, selected GPU, render minor, buffer index, doorbell 65 offset, byte count or packet count as applicable. Kernel errno is preserved; 66 contract failures use EINVAL, I/O/readback failures EIO, missing gfx942 ENODEV, 67 and polling timeout ETIMEDOUT. Raw `OMEGA error=N` and existing refusal exits 68 remain for syscall failures. All allocation/map buffers have separate rows. 69 70 Queue 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 72 The launcher owns a zero-initialized 4096-byte AMD queue object. Its write and 73 read dispatch IDs are at bytes 56 and 128 of the same live mapping. CREATE_QUEUE 74 receives the same opaque queue handle for both pointers, with zero address 75 bytes in the caller header. The compiler selects the fixed AMD AQL layout, 76 binds base+56 and base+128, and validates the complete 2304-byte amd_queue_v2_t ABI object, 77 handle lifetime and writable kind. The launcher owns and clears a 4096-byte 78 allocation containing that object. 79 80 The HSA prefix names the ring, queue size and ID. The queue's read-pointer base 81 offset is 128, pointer mode at byte 180 is 2, and the inactive USER signal is a 82 separate live allocation. GET_PROCESS_APERTURES_NEW supplies LDS and scratch 83 aperture high words for the selected GPU, with exactly one matching record 84 required. A zero-count query obtains the inventory size; a checked owned mapping 85 holds the records with one spare slot. A full reply grows the mapping and retries, 86 so the launcher has no fixed GPU-count table. The u32 ABI field bounds the count. 87 Empty, oversized, duplicate, invalid or unmatched results are refused. The CPU 88 gate includes 80 devices and an inventory that grows between query and fill. 89 CU and wave limits come from the selected node's topology properties. The trusted 90 kernel subset still excludes private scratch and queue-pointer arguments. 91 92 The AQL ring is executable, readable, writable, coherent GTT memory (allocation 93 flags 0xe6000002). Both the full queue layout and executable ring were required 94 in the MI300X tests. A non-executable ring generated a GPU memory fault at the 95 ring address; setting executable alone with the old minimal queue still timed 96 out. No diagnostic observer, event injection, HIP or ROCr participates in the 97 production path. The CPU gate checks the entire queue image and zeroed tail, 98 ring permission, aperture selection and inactive signal, and rejects deliberately 99 broken versions. 100 101 The 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 103 Success and timeout also emit `OMEGA diag NAME VALUE` decimal rows, read only 104 from existing owned mappings: queue read/write pointers, queue properties and read-pointer base offset, signal kind/value, 105 last published packet slot/header and actual packet kernel/kernarg addresses, 106 descriptor fields, and the first eight available output words. Vadd reports 107 counts matching its expected sum and NaN fill. `create_queue_input_qword_N` 108 reconstructs the input u64 at byte offset `8*N`, including addresses that the 109 pinned compiler binds privately; queue ID and full doorbell offset are outputs. 110 The CPU instrument compares all input qwords with the actual intercepted ioctl 111 block and tests untouched output, output without signal completion, and normal 112 completion. These rows are observations, not a timeout diagnosis. 113 114 No 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 119 x86 executable and vadd object into `cell.py`, using xz then base85. Source commits 120 and hashes are generated into `bundle.json`; README and SHA256SUMS are generated. 121 The manifest covers every delivered file except itself. 122 123 The targeted diagnostic bundle is `notebook-probe/launch4/`. It runs the corrected 124 Omega vadd once, while the Python parent samples the child's KFD proc queue, 125 occupancy and VRAM files read-only. Missing files are explicit. After Omega exits, 126 even on timeout, it runs the identical object and inputs once through the installed 127 torch-loaded HIP runtime, labelled `REFERENCE (AMD runtime loading our object, not 128 the Omega launcher)`. Torch supplies the runtime, not kernels or a correctness 129 oracle. No other kernels, doorbell variants or added Omega packets are run. 130 131 The cell persists `amdserve-launch4.txt` after every line and retains raw child 132 stdout/stderr. CONTROLS is first; topology and every launcher stdout line are 133 included; RESULT is last even on exceptions. `notebook-check.py NEW_DIR GATE_DIR` 134 checks both parsers, real x86/qemu refusals and absent-device behavior, receipt 135 streaming, read-only proc sampling while a real child waits, and digest refusal. 136 137 The earlier launch4 bundle remains a vadd diagnostic harness. Hardware evidence 138 for the full queue fix is recorded separately: the uninstrumented x86 executable 139 ``fd85139a4ea58a892a74b910c6432038feb5edbe41c6e4f118357cc57f30aa60`` 140 passed vadd, 200 repeated vadd packets across ring wrap, fsum16, SGEMM and FP8 GEMV 141 with exact fixture outputs on MI300X. These kernel checks do not establish full 142 27B 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 147 relocations before opening KFD. The format is specified in [PLAN.md](PLAN.md). 148 Plans and kernels are trusted first-party executable input. This is a command-line 149 inference executor; it does not expose an HTTP service or accept untrusted plans. 150 151 Code objects load once. Model buffers occupy checked, page-aligned slices of one 152 VRAM allocation and one coherent GTT allocation. A buffer's relocations may address 153 only its declared byte range, excluding alignment padding. This avoids consuming a 154 runtime map handle for each model tensor. Normal weight ranges copy directly from 155 files; BF16 vectors widen exactly into F32. Initialization and zero fill precede 156 timing. Kernargs and packet templates are built once. Each step replays the list, 157 with ring backpressure and one completion signal on the last dispatch. The plan 158 ring grows from the established 1024-byte minimum to a power of two large enough 159 for the complete step. Its size must fit the KFD UAPI byte-count field. The host 160 invalidates owned slots, copies packet bodies in contiguous chunks, fences, 161 publishes aligned headers, then fences before publishing the write pointer and 162 one doorbell per step. Static kernargs reside in VRAM. No performance claim 163 follows from those implementation choices without a matching card measurement. The host 164 writes 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 167 through the step completion signal. `OMEGA_PLAN ids=[...]` contains exactly the 168 requested generated IDs after successful cleanup. A timeout exits 75 and never 169 prints the completion marker. Prefill is token-by-token; decode statistics exclude 170 prompt steps. Allocation, weight loading, template construction and text decoding 171 are outside these per-step timings. Compare these boundaries explicitly with any 172 other runtime's numbers. 173 174 The CPU gate also runs `plan-check.py`: malformed plans on both target parsers, 175 independent code objects, raw file ranges, BF16 widening, data-pool initialization, 176 shared allocation offsets, ring wrap, output IDs, missing completion and cleanup. 177 `publication.c` observes a nonzero group-segment size and rejects a deliberate 178 swap of the packet's group/private fields. CPU simulation is not card proof. 179 180 The 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 182 and kernarg sizes. Missing source and changed-object controls must be caught. 183 A notebook carrying an unlanded object cannot qualify the release tree. 184 185 ## Full-model hardware qualification 186 187 The [November 13 scratch-refusal native model receipt](../../../../evidence/amd-qwen38-native-refusal-`20261113`/README.md) 188 records the final hardware-qualified executable, the exact coding reference check, five longer 189 requests compared with an independent AMD execution path, and the archived 190 Spark comparison. It retains raw IDs, timings, controls, source/compiler hashes, 191 external reproduction instruments and the cross-engine numerical differences. 192 The receipt states timing boundaries and memory-accounting limits explicitly. 193 194 Plan parser refusals print `OMEGA refuse plan field=REASON` before exit 64. 195 The CPU table checks the reason and runs a valid positive twin through the same 196 argument builder before counting a refusal. ABI publication checks call both real 197 packet writers, comparing private=20/group=4096 with the independent AQL encoder; 198 this synthetic unit does not expand the ELF loader's supported scratch subset. 199 200 Numeric refusals preserve empty payload stdout and report 201 `OMEGA refuse number field=N` on stderr with exit 2. The six field IDs are 202 specified at the shared CLI parser's diagnostic helper. Valid numeric parsing 203 and its unsigned bounds are unchanged.