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 / PROVENANCE.md
| 1 | # Provenance: where CUDA++'s hardware knowledge comes from |
| 2 | |
| 3 | This file is the rule for adding hardware facts (instruction encodings, container layouts, launch |
| 4 | descriptors, latencies) to CUDA++, and the record of how the existing ones were obtained. It is an |
| 5 | engineering record, not legal advice. Questions that need a lawyer are listed at the end and are open. |
| 6 | |
| 7 | `THIRD_PARTY.md` lists third-party material and its licences. `docs/HOW_I_DID_IT.md` describes the method. |
| 8 | This file says which inputs are allowed, which are not, and what every new fact must record. |
| 9 | |
| 10 | ## 1. The licence terms this follows |
| 11 | |
| 12 | Checked 2026-10-27 against the primary texts (copies and SHA-256 values are kept with the review that |
| 13 | produced this file): |
| 14 | |
| 15 | - **CUDA Toolkit EULA** (https://docs.nvidia.com/cuda/eula/index.html; online copy "Last updated: January |
| 16 | 7, 2025", `/usr/local/cuda/EULA.txt` of CUDA 13.0 "Last updated: January 12, 2025"). It covers nvcc, |
| 17 | ptxas, cuobjdump, nvdisasm and the CUDA libraries. |
| 18 | - §1.2(1): "You may not reverse engineer, decompile or disassemble, or remove copyright or other |
| 19 | proprietary notices from any portion of the SDK or copies of the SDK." |
| 20 | - §1.2(8): "You may not reverse engineer, decompile or disassemble any portion of the output generated |
| 21 | using SDK elements for the purpose of translating such output artifacts to target a non-NVIDIA |
| 22 | platform." |
| 23 | - §1.1.2(4): "Unless a developer tool is identified in this Agreement as distributable, it is delivered |
| 24 | for your internal use only." nvcc, ptxas, cuobjdump and nvdisasm are not in the distributable list |
| 25 | (Attachment A). |
| 26 | - §2.1 (CUDA supplement): "The SDK is licensed for you to develop applications only for use in systems |
| 27 | with NVIDIA GPUs." |
| 28 | - **NVIDIA Driver License Agreement** (driver 580, `/usr/share/doc/libnvidia-compute-580/copyright`): |
| 29 | §2.1 firmware only on NVIDIA platforms and never translated; §2.2 "You may not reverse engineer, |
| 30 | decompile, or disassemble the SOFTWARE provided in binary form". |
| 31 | - **NVIDIA open GPU kernel modules**: MIT per file (`third_party/nvidia-open-580.173.02/COPYING`). |
| 32 | - **Mesa NAK/NVK**: MIT. **LLVM**: Apache-2.0 WITH LLVM-exception. **CUTLASS**: BSD-3-Clause. |
| 33 | |
| 34 | ## 2. Allowed sources |
| 35 | |
| 36 | | Class | Source | How it may be used | |
| 37 | |---|---|---| |
| 38 | | A. Public documentation | PTX ISA, CUDA Binary Utilities (including its SASS instruction lists), CUDA Driver API reference, NVIDIA `open-gpu-doc` | Read and cite. | |
| 39 | | A. Open source under a permissive licence | NVIDIA open kernel module headers (MIT), Mesa NAK/NVK (MIT), LLVM `BinaryFormat/ELF.h` (Apache-2.0 WITH LLVM-exception), CUTLASS (BSD-3-Clause) | Cite the file and commit for each fact. Code is copied only with its notice, and only into `third_party/`. | |
| 40 | | A. The chip | Running my own bytes on my own NVIDIA GPU | Any fact; the receipt is the evidence. | |
| 41 | | B. NVIDIA SDK tools, oracle only | `nvcc`, `ptxas`, `cuobjdump`, `nvdisasm` installed on my own machine under the CUDA EULA | Only on inputs I wrote: my own probe kernels (CUDA C or PTX I authored) and bytes my own encoder emitted. Only for NVIDIA-GPU targets. Record the tool version. The tools are never shipped, wrapped or run by CUDA++ itself. | |
| 42 | |
| 43 | ## 3. Not allowed |
| 44 | |
| 45 | 1. Running any tool on, extracting from, or reading the machine code or container bytes of an NVIDIA |
| 46 | binary: `libcuda`, cuBLAS, cuDNN, cuFFT, TensorRT, NCCL, the compiler binaries, the firmware or any |
| 47 | other driver or SDK file (CUDA EULA §1.2(1); driver licence §2.2). This includes the cubins embedded in |
| 48 | NVIDIA libraries. |
| 49 | 2. Using anything learned from NVIDIA tool output (class B) for a non-NVIDIA target (CUDA EULA §1.2(8)). |
| 50 | Non-NVIDIA backends take their facts from class A sources for that vendor only. |
| 51 | 3. Committing SDK files, NVIDIA headers other than the MIT open-module headers, NVIDIA binaries, or |
| 52 | firmware. |
| 53 | 4. Giving MAX (Modular) source or binaries to an AI system in order to produce software that reimplements |
| 54 | or substitutes for MAX (MAX License §1.4, "Last Modified: October 21, 2026"). Reading MAX to |
| 55 | interoperate with it is allowed by the same clause. |
| 56 | 5. Describing the work as a reverse-engineered copy of NVIDIA's software. It is not: see section 5. |
| 57 | |
| 58 | ## 4. What every new hardware fact records |
| 59 | |
| 60 | In the source comment next to the fact, or in the test that pins it: |
| 61 | |
| 62 | - the class (A or B) and the exact source: document and section, file and commit, or tool and version; |
| 63 | - for class B, the probe input (path of the `.cu`/`.ptx` I wrote) and the command line; |
| 64 | - the chip receipt that confirmed it, or NOT_RUN; |
| 65 | - for golden words: whether they were written independently (from class A plus the chip) or copied from |
| 66 | class B output. Copied words are a regression pin, not independent evidence |
| 67 | (see the `independent-sass-opcode-goldens` practice in the omega-harness skills). |
| 68 | |
| 69 | Stored NVIDIA tool listings are kept only when a test needs them, under `tests/` or `evidence/`, and each |
| 70 | is listed in section 6. |
| 71 | |
| 72 | ## 5. How the existing knowledge was obtained (inventory, 2026-10-27) |
| 73 | |
| 74 | | Area | Files | Class | Notes | |
| 75 | |---|---|---|---| |
| 76 | | Kernel-module interface (ioctls, classes) | `nvrm/`, `m16/`, `third_party/nvidia-open-580.173.02/` | A | 67 MIT headers copied unchanged. | |
| 77 | | SASS encodings | `src/omega_blackwell_encoder.c`, `src/omega_blackwell_codegen*.c/.h` | A + B | Mesa NAK facts cited; words matched against `nvcc 13.0.88 -arch=sm_121 -cubin` + `cuobjdump -sass` of probe kernels I wrote (`docs/HOW_I_DID_IT.md` step 2). Chip receipts in `evidence/`. | |
| 78 | | Instruction latencies, QMD, dispatch order | `src/omega_gpu_elementwise_api.c`, `src/omega_gpu_cmdlist.c` | A | Mesa `sm120_instr_latencies.rs`, `qmd.rs`, `nvk_cmd_dispatch.c` (MIT). | |
| 79 | | Tensor-core arithmetic model | `tests/gpu_tc_probe_test.c`, `tests/bw_hmma_model.h` | A (chip) | Fitted on chip outputs. | |
| 80 | | cubin container writer | `src/omega_cubin.c`, `src/omega_cubin.h` | B | Layout read from a `ptxas 13.0.88 -arch=sm_121` reference output with `readelf`/`cuobjdump -elf` (the source does not name the probe input; the next change to the file records it). Header constants are also public in LLVM `ELF.h` (class A). No bytes copied. | |
| 81 | | Decode cross-checks | `tests/gpu_reconv_test.c`, `tests/device-trace/run-emitter-checks.sh`, `tools/artifact_smoke.sh` | B | `nvdisasm`/`cuobjdump` read my own bytes. Since 2026-11-05 `gpu_reconv_test.c` reads them with Omega's own decoder (`om/disasm/sm121_dis.om`), and NVIDIA's `nvdisasm` runs only in the named oracle targets (`make test-sm121dis`, `tools/sm121dis/README.md`). `artifact_smoke.sh` skips unavailable tools; `run-emitter-checks.sh` requires `nvdisasm` on `PATH`. | |
| 82 | |
| 83 | No source comment or record in this repository says a fact was obtained by disassembling an NVIDIA |
| 84 | library, driver or firmware. A fact found to have such an origin is removed and re-derived from class A |
| 85 | or B, and the removal is recorded here. |
| 86 | |
| 87 | ## 6. NVIDIA tool output stored in this repository |
| 88 | |
| 89 | #84 stored `tests/device-trace/expected.sass`, an `nvdisasm 13.0 --binary SM121` listing of the |
| 90 | trace emitter's own words, as a regression pin. #93 (2026-10-27) removed it: |
| 91 | `tests/device-trace/run-emitter-checks.sh` now keeps the listing in a temporary directory and checks |
| 92 | hand-written expectations (opcode counts and the address-path instructions). |
| 93 | |
| 94 | Stored now: each is `nvdisasm` V13.0.85 `--binary SM121` reading words my own encoder emitted (class B on |
| 95 | my own bytes); the input bytes sit beside the listing; no NVIDIA-generated code is involved. They are |
| 96 | kept as review evidence that the independent decoder agrees with the encoder. No test reads them: the |
| 97 | gates run `nvdisasm` live and check fixed expectations (`make test-om-encoder-ldg`, |
| 98 | `make test-om-encoder-atomg`, `make test-om-encoder-guard`, `make test-sm121dis-opmove`). |
| 99 | |
| 100 | | Listing | Input (my bytes) | Why kept | |
| 101 | |---|---|---| |
| 102 | | `evidence/ldg-offset-20261107/nvdisasm.txt` | `ldg_words.bin`: four LDG.E rows of #373's encoder fix | Shows the offsets 0, +0x40, -0x100000 and +0x7fffff decode as encoded. | |
| 103 | | `evidence/atomg-min-20261107/nvdisasm.txt` | `min_words.bin`: the three ATOMG.E.MIN.64.STRONG.SYS rows of `om/encoder/atomg_min_test.om` | Shows op 64's words decode as the intended instruction and registers. | |
| 104 | | `evidence/atomg-min-20261107/atomg_field_probe_nvdisasm.txt` | `atomg_field_probe.bin`: ATOMG_ADD_STRONG_SYS's words with the operation field (w2 bits 23..26) set to 0..15 and the type field (bits 9..11) to 0..7 | Records how operation 1 = MIN and type 2 = .64 were identified. | |
| 105 | | `evidence/guard-pred-20261107/nvdisasm-after.txt` | `guard_words.bin`: the 135 instructions of `om/encoder/guard_pred_test.om bin` at the DRA-483 fix (@P0 / @!P0 forms of 63 ops, 4 LDCU guard probes, 5 omega-mv #1044 bool/trap rows) | Shows every guard decodes as encoded, and that LDCU's guard bits name UP0. | |
| 106 | | `evidence/guard-pred-20261107/nvdisasm-before.txt` | `guard_words_before.bin`: the same rows from the encoder before the fix | Shows the @P0 / @!P0 forms of 58 ops (MOV and STG.E among them) decoded with no guard (always), and @!P0 EXIT as @P0. | |
| 107 | | `evidence/INTEG-280-20261110/opmove-nvdisasm.txt` | `opmove_words.bin`: the sixteen rows of `om/disasm/opmove_test.om bin`, one per BlackwellIR op 64..79 after the #280 numbering move | Shows each moved op's words decode as the intended instruction, and gave the exact text of the decoder rows added for them. | |
| 108 | |
| 109 | No listing of nvcc-generated code and no NVIDIA binary is stored. |
| 110 | The C1b guard gate (`make test-om-encoder-guard`) uses nvdisasm 13.0.85 |
| 111 | `-b SM121 -hex` only on bytes emitted by our seeded encoder and its own |
| 112 | uniform-predicate probe words. Listings stay in ignored `build/om-encoder/`. |
| 113 | No new instruction form is introduced by this guard correction. |
| 114 | `make test-om-encoder-ldg` uses the same pinned oracle only on our emitted |
| 115 | LDG.E words. It checks the existing C #373 signed byte-offset field, restored |
| 116 | in the seeded encoder and its spec table after operand parity exposed the |
| 117 | omitted field. The listing remains ignored; no new instruction form is added. |
| 118 | |
| 119 | ### LDG.E signed byte offset, ham/encoder-ldg-offset |
| 120 | |
| 121 | Class A decision source: Mesa NAK (MIT), commit |
| 122 | `8190c11866dfb23e4dfacaea2f7cb795596d1fb1`, |
| 123 | [sm70_encode.rs, OpLd::encode](https://gitlab.freedesktop.org/mesa/mesa/-/blob/8190c11866dfb23e4dfacaea2f7cb795596d1fb1/src/nouveau/compiler/nak/sm70_encode.rs#L3437-3512): |
| 124 | global load selects opcode `0x981` with UGPR addressing, then unconditionally |
| 125 | encodes `self.offset` in `40..64`. Its signed type is `i32` in |
| 126 | [ir.rs, OpLd](https://gitlab.freedesktop.org/mesa/mesa/-/blob/8190c11866dfb23e4dfacaea2f7cb795596d1fb1/src/nouveau/compiler/nak/ir.rs#L6501-6516). |
| 127 | Thus the existing C offset field is right; the seeded encoder and spec omitted it. |
| 128 | The nvdisasm 13.0.85 LDG gate is secondary verification on our bytes only, not |
| 129 | the decision source. Chip execution for this correction: NOT_RUN. |
| 130 | |
| 131 | ## 7. Open questions for a lawyer |
| 132 | |
| 133 | 1. Is compiling my own probe kernels with nvcc and reading the result with cuobjdump, to learn the |
| 134 | encoding of NVIDIA instructions for an NVIDIA-GPU toolchain, within the CUDA EULA? §1.2(8) is limited to |
| 135 | translation to non-NVIDIA platforms; does any other clause reach it? |
| 136 | 2. Is a toolchain that replaces nvcc on NVIDIA GPUs an "application" developed "only for use in systems |
| 137 | with NVIDIA GPUs" (§2.1)? |
| 138 | 3. Can tool listings of my own code (section 6) be published, given §1.1.2(4)? |
| 139 | |
| 140 | ## 8. gfx942 host-only code-object writer (2026-11-12) |
| 141 | |
| 142 | `backend/amd/gfx942/hsaco.om` is a first-party seeded-Omega writer for the fixed FP32 `vadd` |
| 143 | kernel, not a general AMD assembler or a qualified AMD runtime. It reads the instruction-table |
| 144 | data in `vadd.isa`, packs the words, resolves its forward branch, and serializes the ELF64 HSA v5 |
| 145 | object, kernel descriptor, dynamic/static symbols, SysV hash and MessagePack metadata note. |
| 146 | The producing path uses no LLVM, linker, shell serializer, C, Rust or Python. |
| 147 | `tests/amd/run.sh` coordinates builds and compares against public LLVM tools; it opens no GPU. |
| 148 | |
| 149 | All AMD facts are class A, independently sourced from **LLVM 18.1.3**, Apache-2.0 WITH |
| 150 | LLVM-exception. These are the exact public sources used (tag `llvmorg-18.1.3`): |
| 151 | |
| 152 | | Fact | Source | |
| 153 | |---|---| |
| 154 | | HSA ELF64 header/flags, metadata keys, kernel descriptor/entry state and wave64 ABI | [AMDGPUUsage](https://releases.llvm.org/18.1.3/docs/AMDGPUUsage.html), sections “ELF Code Object”, “Kernel Descriptor”, “Initial Kernel Execution State”, “Code Object V5 Metadata”, and assembler `.amdhsa_kernel` directives | |
| 155 | | `EM_AMDGPU=224`, HSA OSABI=64, ABI v5=3, gfx942 mach=0x4c, XNACK/SRAMECC ANY flags, note type 32 | [llvm/include/llvm/BinaryFormat/ELF.h](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/include/llvm/BinaryFormat/ELF.h) | |
| 156 | | Descriptor offsets and RSRC1/2/3/kernel-property bit fields | [llvm/include/llvm/Support/AMDHSAKernelDescriptor.h](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/include/llvm/Support/AMDHSAKernelDescriptor.h) | |
| 157 | | SMEM field layout and scalar-load opcodes | [SMInstructions.td](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/SMInstructions.td), `SMEM_Real_vi`, `SM_Real_Loads_vi` | |
| 158 | | SOP1/SOP2/SOPP layouts and shifts, saveexec, branch, wait/end opcodes | [SOPInstructions.td](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/SOPInstructions.td), `SOP1_Real`, `SOP2_Real32`, `SOPP_Real_32`, `_vi` and gfx6–gfx10 definitions | |
| 159 | | VOP1 move layout/opcode | [VOP1Instructions.td](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOP1Instructions.td), `VOP1e`, `V_MOV_B32` `_vi` | |
| 160 | | VOP2 FP32 add, integer add/carry, shifts and mask layout/opcodes | [VOP2Instructions.td](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOP2Instructions.td), `VOP2e`, `_vi` and gfx9 definitions | |
| 161 | | VOPC unsigned bounds compare | [VOPCInstructions.td](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOPCInstructions.td), `VOPCe`, `V_CMP_GT_U32` `_vi` | |
| 162 | | GLOBAL load/store and 64-bit VGPR address form | [FLATInstructions.td](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/FLATInstructions.td), `FLAT_Real`, `FLAT_Real_gfx940`, `GLOBAL_LOAD_DWORD`, `GLOBAL_STORE_DWORD` | |
| 163 | | VGPR/SGPR resource granules and extra special SGPRs | [AMDGPUBaseInfo.cpp](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp), `getVGPREncodingGranule`, `getSGPREncodingGranule`, `getNumExtraSGPRs` | |
| 164 | |
| 165 | The ORACLE assembly `vadd-gfx942.s` was copied from the ended `t_bd34e75b` lane's untracked |
| 166 | `backend/amd/gfx942/vadd-gfx942.s`; the original was not modified. Its kernel-argument layout |
| 167 | was checked against `backend/amd/vadd-gfx1151.s` (a/b/c pointers at 0/8/16, count at 24, |
| 168 | 28 bytes). The new oracle fixes the copied single-VGPR `gid << 2` address path by preserving |
| 169 | the high address bits and propagating addition carries; it also explicitly preserves FP32 |
| 170 | denormals (the assembler default flushes them). Resource declarations match the changed kernel. |
| 171 | Only public AMD LLVM sources/tools informed these changes; no NVIDIA-tool fact was used. |
| 172 | |
| 173 | Read-only prior art inspected: CUDApp unmerged `feat/native-amd-agx-lab` at |
| 174 | `268a2e9d`, `native/gpulab/{amd.om,test-amd.om,amd-oracle-input.om,README.md}`. |
| 175 | That is a different gfx1100 integer lab/ABI; no code, instruction words or encoding constants |
| 176 | from it were reused. The new table packs public LLVM field definitions and is checked against |
| 177 | `llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -filetype=obj`. |
| 178 | |
| 179 | Verification-only installed oracles: Ubuntu LLVM 18.1.3 `llvm-mc-18`, `llvm-objdump-18`, |
| 180 | `llvm-readelf-18` and `llvm-objcopy-18`. They are not dependencies of the producer binary. |
| 181 | `llvm-objcopy --dump-section` receives an explicit disposable output so it never rewrites |
| 182 | the emitted input. The oracle is relocatable: no `ld.lld` was installed and none was installed |
| 183 | for this work. The gate compares `.text` bytes, rebased disassembly, metadata, and descriptor |
| 184 | bytes excluding its relocated entry displacement; it does **not** claim linked-file identity. |
| 185 | New logs/listings and tool/source digests are filed under `evidence/AMD-GFX942-HOST-*/`. |
| 186 | `AMD-GFX942-HOST-20261112T210312Z` records the first commit `6ebd47b0`; `AMD-GFX942-HOST-20261112T214517Z` |
| 187 | records the reviewed source (MessagePack values and lengths in their full spec encodings, with a gate case |
| 188 | comparing both sides of every width boundary and the uint64 maximum to hand-written spec bytes, and two mutants that the comparison catches). |
| 189 | The emitted vadd object is the same in both. |
| 190 | |
| 191 | Status: host byte/format checks only. AMD loader interoperability, queue dispatch, numeric FP32 |
| 192 | outputs, boundary vectors, performance, Qwen execution and every AMD hardware row are **NOT_RUN**. |
| 193 | |
| 194 | ## 9. AMD KFD and AQL host data layer (2026-11-12) |
| 195 | |
| 196 | `backend/amd/kfd/` is first-party seeded Omega: the 64-byte AQL kernel dispatch packet |
| 197 | (`aql.om`), the vadd kernel-argument block (`kernarg.om`), table-driven byte records for twelve |
| 198 | KFD requests plus aperture, event-wait and GPU-ID entries (`records.om` reading `requests.tsv`), |
| 199 | and a sequential model of the order in which a host publishes a packet into a user-mode queue |
| 200 | (`ring.om`). It opens no device and issues no request: the pinned compiler refuses every KFD |
| 201 | `devctl` request (error 9), and the gate keeps one compile-only reproduction per request. |
| 202 | |
| 203 | Sources of the facts, each read for the fact named and nothing copied: |
| 204 | |
| 205 | | Fact | Source | |
| 206 | |---|---| |
| 207 | | KFD request numbers, record sizes, field offsets and widths (interface 1.14) | installed `/usr/include/linux/kfd_ioctl.h`, Ubuntu `linux-libc-dev:arm64` 6.8.0-139.139, sha256 `4123a021f00f85235e3e8dda4e0b4c4ec8ed4f7ce30e8882529f68652f765247`, AMD MIT-style permission notice in the header; public upstream [include/uapi/linux/kfd_ioctl.h at v6.8](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/kfd_ioctl.h?h=v6.8) (the installed file is digest-pinned, not assumed identical) | |
| 208 | | The same layouts for x86-64 | installed `/usr/x86_64-linux-gnu/include/linux/kfd_ioctl.h`, `linux-libc-dev-amd64-cross` 6.8.0-25.25cross1, sha256 `d9bf51d2cde26ea18e2ec287674bb022d7b23a0858a14cdd55c55d3eb3ec339e` | |
| 209 | | AQL packet layout, header bit fields, packet types, fence scopes, doorbell packet-ID rule | ROCR-Runtime tag `rocm-6.2.0` (commit `1d1b8456c3530e7b464f6d74ed0baa2b28345126`) [src/inc/hsa.h](https://raw.githubusercontent.com/ROCm/ROCR-Runtime/rocm-6.2.0/src/inc/hsa.h), sha256 `2b23a43eef5b869b1a0c2245aa59e2b3da0f0c074dea5dae8d049ea4bf3a8e3b`, University of Illinois/NCSA licence; no runtime code linked | |
| 210 | | Code object v5 and its metadata | LLVM 18.1.3 [AMDGPUUsage.rst](https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-18.1.3/llvm/docs/AMDGPUUsage.rst), sha256 `4222ab6cb3f1c73f5cdbdaedf8690a638528a9f6ba6ea3cca35ed325b8242c4c`, Apache-2.0 WITH LLVM-exception | |
| 211 | | vadd kernel-argument layout (a, b, c at 0, 8, 16; count at 24; 28 bytes) | `backend/amd/vadd-gfx1151.s` in this repository, sha256 `cb653f777801f65199f5243bb3db0c67f966cafc13bc99f8632c90dc0fcc1f2e`; the gfx942 kernel of section 8 uses the same layout | |
| 212 | |
| 213 | `requests.tsv` was generated once by the test-only C program `tests/amd-kfd/layout-oracle.c` |
| 214 | from the installed header, and the gate regenerates it from the live header every run and |
| 215 | compares the whole table. `tests/amd-kfd/oracle.py` packs the expected bytes independently with |
| 216 | the Python standard `struct` module. Both are verification oracles, never on the producer path. |
| 217 | Test tools: GCC 13.3.0-6ubuntu2~24.04.1 (native and `x86_64-linux-gnu-gcc`), LLVM 18.1.3 |
| 218 | `llvm-mc-18`, `llvm-readelf-18`, `llvm-objcopy-18`, Python 3.12.3 run with `-I`. No NVIDIA tool |
| 219 | and no fact learned from one was used. |
| 220 | |
| 221 | Status: host byte and order checks only. The ring model is an execution model of publication |
| 222 | order, not a proof of memory ordering or doorbell coherency. KFD calls, queue creation, GPU |
| 223 | memory, dispatch, completion and every AMD hardware row are **NOT_RUN**. |
| 224 | |
| 225 | ## 10. gfx942 host instruction executor (2026-11-12) |
| 226 | |
| 227 | `backend/amd/gfx942/exec/` (`fp.om`, `fma.om`, `main.om`, concatenated as one unit) is a first-party |
| 228 | seeded-Omega executor for the gfx942 instructions used by the kernels in sections 8, 11 and 12. It decodes the raw |
| 229 | `.text` words of the emitted code object (the gate extracts `.text` through the ELF section headers) |
| 230 | and runs wave64 workgroups over a flat byte file holding the kernel arguments and arrays. |
| 231 | Every instruction and branch target is checked before memory is opened; anything outside the subset is |
| 232 | a refusal with a defined exit (65 malformed, 66 unsupported encoding, 67 memory range). Binary32 |
| 233 | addition is integer arithmetic (guard, round and sticky bits, ties to even, subnormals kept, no host |
| 234 | floating point); NaN results are the canonical quiet NaN `0x7fc00000`, a policy of this model and not |
| 235 | a claim about the hardware's NaN payloads. |
| 236 | |
| 237 | Facts: instruction formats and opcodes from the LLVM 18.1.3 sources already listed in section 8; |
| 238 | IEEE 754-2019 for binary32 addition. `tests/amd-exec/oracle.py` (test only, Python standard library, |
| 239 | run with `-I`) computes every expected output with binary64 addition rounded to binary32 by `struct`, |
| 240 | which is exact for binary32 addition, and checks all output bits plus untouched words past `count`. |
| 241 | |
| 242 | Status: host execution model only. Waits complete at once and memory is sequential, so this checks |
| 243 | what the kernel computes, not timing, races or the GPU's memory model. Every AMD hardware row is |
| 244 | **NOT_RUN**. |
| 245 | |
| 246 | ## 11. gfx942 fsum16 and table-defined kernel metadata (2026-11-12) |
| 247 | |
| 248 | `backend/amd/gfx942/fsum16.isa` specifies the frozen left-to-right binary32 reduction already |
| 249 | defined by `backend/spirv/emit.om`: each active row loads its first input and adds the remaining |
| 250 | inputs in order, rounding after every addition. It does not start from zero or reassociate. |
| 251 | The ABI is global pointers `x` and `o` followed by uint `n`; one wave64 workgroup covers consecutive |
| 252 | rows. Both address paths compute the high and low halves before adding the pointers. |
| 253 | |
| 254 | The producer `backend/amd/gfx942/hsaco.om` reads its kernel name, arguments, sizes, register counts |
| 255 | and descriptor resource words from `K`/`A` table rows (schema in `vadd.isa`). It no longer selects |
| 256 | metadata by a hardcoded kernel name. Identifier bytes are streamed from the seekable table, and |
| 257 | MessagePack and ELF sizes are derived from those bytes. This schema supports contiguous global-pointer |
| 258 | and uint arguments; absent/duplicate kernel declarations, unsupported argument kinds and layout gaps |
| 259 | are refusals with exit 4 before object output. The complete vadd object retains its previous digest, |
| 260 | checked by both gates. |
| 261 | |
| 262 | `backend/amd/gfx942/fsum16-gfx942.s` is an independently written LLVM 18.1.3 oracle. The host gate |
| 263 | compares its `.text`, metadata note and descriptor fields with the Omega object and checks the |
| 264 | resolved kernel-entry displacement. Its metadata uses LLVM's explicit `!str n` tag: plain `n`, |
| 265 | quoted `"n"` and YAML's `!!str n` all gave LLVM's `invalid HSA metadata` error in this run. |
| 266 | Instruction formats and opcodes use only the public sources in section 8; this kernel introduces |
| 267 | no executor opcodes or new production dependency. |
| 268 | |
| 269 | The executor interface is `exec RAW_TEXT MEMORY GRID_X GRID_Y`, with explicit decimal work-item |
| 270 | extents and local size `(64,1,1)`. The one-dimensional vadd/fsum16 callers pass their count and |
| 271 | one; tests deliberately overdispatch zero-size inputs to exercise masking. The decoder does not |
| 272 | infer a kernel from its filename, metadata or kernarg layout. Addition and canonical NaNs are unchanged. |
| 273 | |
| 274 | `tests/amd-exec/oracle.py` computes each reduction independently by applying its rounded binary32 |
| 275 | reference after every addition. It checks all output bits, inputs, arguments and guard bytes, and |
| 276 | reverses the load offsets in a test-only mutant table. The recorded order-sensitive row is |
| 277 | `[0x4c000000, 0xcc000000, 0x3f800000, thirteen zero words]`: the Python reference measured |
| 278 | left-to-right bits `0x3f800000`, reverse-order bits `0x00000000`; the executed mutant was caught. |
| 279 | The earlier attempted row with `0x4b800000`/`0xcb800000` was not order-sensitive and was replaced |
| 280 | after the oracle's explicit inequality assertion failed. No numerical tolerance is used. |
| 281 | |
| 282 | Status: IMPLEMENTED and EXERCISED on the Linux AArch64 host. Receipts under |
| 283 | `evidence/AMD-GFX942-FSUM16-*` record the compiler pin, inputs, commands, output digests, failures |
| 284 | and passing gates. AMD dispatch, timing, race behaviour, hardware NaN payloads and Qwen inference |
| 285 | remain **NOT_RUN**. This is host code-object and instruction-model evidence, not hardware qualification. |
| 286 | |
| 287 | ## 12. gfx942 ordered-FMA SGEMM (2026-11-12) |
| 288 | |
| 289 | `backend/amd/gfx942/sgemm.isa` implements row-major `C[M,N] = A[M,K] * B[K,N]`. |
| 290 | Its ABI is three global pointers followed by uint `M`, `N`, `K` (36 bytes). One wave computes a |
| 291 | 64-column tile of one row: `s2` is group x, `s3` group y, and `v0` the lane. The descriptor enables |
| 292 | both workgroup-ID SGPRs. Each output starts at positive zero and executes |
| 293 | `acc = fma(A[m,k], B[k,n], acc)` in increasing `k`; `K=0` writes positive zero without input loads. |
| 294 | The code uses `v_fmac_f32`, whose destination is its third source, not a rounded multiply plus add. |
| 295 | Address construction uses full high/low 32-bit products and carry propagation. |
| 296 | |
| 297 | Instruction authority is LLVM **llvmorg-18.1.3**: |
| 298 | - [VOP2Instructions.td](https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOP2Instructions.td), |
| 299 | `V_FMAC_F32` tied destination/source2 declaration and gfx9/VI opcode `0x3b`; `V_MUL_F32` opcode |
| 300 | `0x05` is implemented for the executed separate-multiply/add negative control. |
| 301 | - [SOPInstructions.td](https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/SOPInstructions.td), |
| 302 | `S_MOV_B32_vi`, `S_ADD_U32_vi`, `S_SUB_U32_vi`, `S_ADDC_U32_vi`, `S_LSHL_B64_vi`, |
| 303 | `S_MUL_I32_vi`, `S_MUL_HI_U32_vi`, and `S_CBRANCH_SCC0`/`S_CBRANCH_SCC1`. |
| 304 | Existing format fields remain those listed in section 8. SCC is explicit executor state. |
| 305 | |
| 306 | The table writer stores numeric labels in a growable anonymous file. References resolve to checked |
| 307 | signed 16-bit word offsets relative to the next instruction; duplicate/undefined labels and either |
| 308 | overflow direction refuse with exit 4 before object output. There is no fixed label-count capacity. |
| 309 | The gate checks both signed boundaries and both overflow controls; SGEMM's actual backward branch |
| 310 | and complete instruction text independently match `llvm-mc-18 -mcpu=gfx942` assembly. |
| 311 | |
| 312 | `exec/fma.om` represents the exact finite product plus addend as an integer scaled by `2^298`. |
| 313 | Binary32's exponent and significand limits require at most 554 bits, held in nine unsigned 64-bit |
| 314 | limbs. It adds or subtracts exact magnitudes, then rounds once using a halfway bit, sticky bits and |
| 315 | even-significand tie-breaking, retaining denormals. Overflow is handled after cancellation and |
| 316 | rounding. Signed zeros and infinities follow the stated IEEE nearest-even model; NaNs remain the |
| 317 | model's canonical `0x7fc00000` policy, not a promise of hardware payload parity. |
| 318 | |
| 319 | `tests/amd-exec/sgemm.py` is an independent **test-only** Python `fractions.Fraction` oracle. |
| 320 | It rounds arbitrary rational results directly to binary32, with no host float FMA or double |
| 321 | rounding. A streaming probe covers special-value combinations, seeded random triples, cancellation, |
| 322 | subnormal halfway cases and overflow canceled before rounding. Matrix cases cover dimensions |
| 323 | 1, 3, 64, 65, empty dimensions and `K=0`; extra groups in both X and Y must preserve every guard. |
| 324 | The mutant replaces the actual fused instruction by separately executed `v_mul_f32`/`v_add_f32` |
| 325 | and must fail bit-for-bit comparison. Host gates retain all vadd/fsum16 controls and exact object |
| 326 | digests, compare SGEMM metadata/descriptor bytes with independent assembly (including the group-Y |
| 327 | enable bit), and build both executables and objects twice for byte identity. |
| 328 | |
| 329 | Receipts live under `evidence/AMD-GFX942-SGEMM-*`. AMD dispatch, performance, GPU memory ordering, |
| 330 | hardware NaN payloads and Qwen inference remain **NOT_RUN**. This host model is not hardware qualification. |
| 331 | |
| 332 | ### 12.1. CDNA3 semantics correction and complete subset audit |
| 333 | |
| 334 | The initial SGEMM host receipt at `df9c14a74c549adb029d243eaed5cb10fceecc84` established |
| 335 | encoding/model agreement, **not correct ISA semantics**: `S_SUB_U32` incorrectly set SCC for |
| 336 | no-borrow, and the kernel used branches matching that error. The correction uses SCC = borrow |
| 337 | (`S1 > S0`), exits a row on SCC0, stores zero for empty K on SCC1, and continues K on SCC0. |
| 338 | The historical receipt is retained unchanged; the correction receipt is a separate record. |
| 339 | |
| 340 | Semantic authority is the AMD *Instinct MI300 Instruction Set Architecture (CDNA3)* manual, |
| 341 | local source `~/docs/amd-gpu/AMD_Instinct_MI300_CDNA3_ISA.txt`. Page numbers below are **physical |
| 342 | PDF pages** (`doc-page amd-gpu/AMD_Instinct_MI300_CDNA3_ISA PAGE`), not the printed footer. |
| 343 | LLVM 18 remains the independent encoding oracle, not an instruction-semantics oracle. |
| 344 | |
| 345 | | Implemented instruction | PDF page | Audited operation and side effects | |
| 346 | |---|---:|---| |
| 347 | | S_LOAD_DWORD | 68, 146 | One dword; each address component ignores its low two bits; flags unchanged. | |
| 348 | | S_LOAD_DWORDX2 | 68, 70, 146 | Two consecutive dwords; even destination SGPR pair. | |
| 349 | | S_LOAD_DWORDX4 | 68, 70, 147 | Four consecutive dwords; quad-aligned destination SGPRs. | |
| 350 | | S_ADD_U32 | 97 | Low32 sum; SCC is unsigned carry-out. | |
| 351 | | S_SUB_U32 | 97 | Low32 difference; SCC is unsigned **borrow** (`S1 > S0`). | |
| 352 | | S_ADDC_U32 | 98 | Sum includes incoming SCC; replaces SCC with carry-out. | |
| 353 | | S_LSHL_B32 | 103 | Shift count masked to five bits; SCC is nonzero result. | |
| 354 | | S_LSHL_B64 | 103 | Shift count masked to six bits; even pairs, low word first; SCC is nonzero full result. | |
| 355 | | S_MUL_I32 | 104 | Low32 product, signed/unsigned low bits identical; preserves SCC. | |
| 356 | | S_MUL_HI_U32 | 106–107 | High32 unsigned product; preserves SCC. | |
| 357 | | S_MOV_B32 | 115 | Bitwise copy; preserves SCC. | |
| 358 | | S_AND_SAVEEXEC_B64 | 124–125 | Read source and old EXEC, AND into EXEC, save old EXEC to destination, SCC = new EXEC nonzero. Source/destination alias follows the pseudocode on p125. | |
| 359 | | S_ENDPGM | 138 | Terminates the wave; implicit wait is satisfied by synchronous memory. | |
| 360 | | S_CBRANCH_SCC0 | 139 | Branch iff SCC=0; signed16 DWORD displacement relative to next instruction; preserves flags. | |
| 361 | | S_CBRANCH_SCC1 | 139 | Branch iff SCC=1; same displacement; preserves flags. | |
| 362 | | S_CBRANCH_EXECZ | 140 | Branch iff whole EXEC=0; same displacement; preserves flags. | |
| 363 | | S_WAITCNT | 141 | Supported vmcnt/lgkmcnt waits complete immediately in the synchronous model; no flag writes. | |
| 364 | | V_ADD_F32 | 169 | FP32 add, nearest-even, input/output denormals retained. | |
| 365 | | V_MUL_F32 | 170 | FP32 multiply with one rounding; implemented by exact FMA with a product-signed zero. | |
| 366 | | V_LSHRREV_B32 | 173 | Unsigned right shift of S1 by S0[4:0]; no flags. | |
| 367 | | V_LSHLREV_B32 | 173 | Low32 left shift of S1 by S0[4:0]; no flags. | |
| 368 | | V_AND_B32 | 174 | Bitwise AND; no flags. | |
| 369 | | V_ADD_CO_U32 | 175, 22 | Low32 sum; VCC receives carry-out for active lanes and zero for inactive lanes. | |
| 370 | | V_ADDC_CO_U32 | 176, 22 | Includes incoming per-lane VCC, then replaces the whole VCC mask. | |
| 371 | | V_ADD_U32 | 183 | Low32 sum; no carry-in or carry-out, preserves VCC. | |
| 372 | | V_FMAC_F32 | 185 | Destination is third input; exact multiply-add followed by one rounding. | |
| 373 | | V_MOV_B32 | 186 | Bitwise copy to active lanes only; no flags. | |
| 374 | | V_CMP_GT_U32 | 251, 22 | Unsigned greater-than, VCC = EXEC AND comparison mask; EXEC unchanged. | |
| 375 | | GLOBAL_LOAD_DWORD | 87, 90, 503–504 | 64-bit even VGPR address pair plus signed13 byte offset; active lanes load a dword. | |
| 376 | | GLOBAL_STORE_DWORD | 87, 90, 505 | Same address calculation; active lanes store a dword. | |
| 377 | |
| 378 | All vector source operands observe the incoming VCC, including scalar VCC halves used as sources. |
| 379 | All VCC-writing instructions replace the whole mask (p22), including when EXEC is zero. |
| 380 | These rules fix inactive carry bits and read-after-write contamination in the sequential host lane loop. |
| 381 | The scalar-memory fix masks each address component separately (p68), not their sum. |
| 382 | Misaligned multi-dword SGPR destinations and 64-bit VGPR address pairs refuse with exit 66 (pp20–21, |
| 383 | 70). Negative immediate SMEM offsets with SOE=0 are undefined on p68 and refuse with exit 66: |
| 384 | the general format table calls the field unsigned (p67), while individual load descriptions call |
| 385 | it signed (pp146–147); the executor does not guess at this undefined case. |
| 386 | |
| 387 | General FP controls are p45: round mode 0 is nearest-even and denorm mode 3 retains inputs and |
| 388 | outputs, matching the descriptors. The exact integer FP implementations and independent Fraction |
| 389 | checks remain as described above. The canonical-NaN host policy is explicit; NaN payload propagation, |
| 390 | exceptions, XNACK replay/clause hazards, memory races, timing, and hardware dispatch are not modeled. |
| 391 | Only the kernels' synchronous flat-memory contract is exercised; this audit does not qualify hardware. |
| 392 | |
| 393 | `tests/amd-exec/semantics.py` contains manual-derived register/flag input/output cases, not expected |
| 394 | values generated from the executor. A test-only sparse-state adapter calls the same production |
| 395 | `step` routine used by wave execution, with actual encoded instruction words. Cases check inputs |
| 396 | and untouched registers, flags, lane 63, inactive lanes, carry/borrow edges, masked shifts, signed |
| 397 | branches, literals, SMEM component alignment, and GLOBAL offsets and memory guards. Executable |
| 398 | mutants independently restore each corrected old behavior, including the inverted SCC, and each |
| 399 | must fail its corresponding case. The final PASS derives the case count from the actual case table; |
| 400 | all previous vadd/fsum16/SGEMM counts and controls remain. Hardware remains **NOT_RUN**. |
| 401 | |
| 402 | ## 13. gfx942 E4M3FNUZ GEMV |
| 403 | |
| 404 | `backend/amd/gfx942/fp8gemv.isa` defines `fp8gemv(W,x,s,y,M,K)`: four 64-bit |
| 405 | global pointers followed by two unsigned 32-bit dimensions, a 40-byte kernarg. |
| 406 | W is row-major M-by-K **E4M3FNUZ** bytes; x[K], s[M], and y[M] are FP32. |
| 407 | For each row m, acc starts at positive zero. In ascending k order, compute |
| 408 | `acc = RN32(dequant(W[m*K+k]) * x[k] + acc)` with a single fused rounding. |
| 409 | After the loop, compute `y[m] = RN32(s[m] * acc)` **once**, not a scale on each |
| 410 | product or each accumulation step. K=0 still applies the scale to positive zero. |
| 411 | The grid is `(M,1,1)`, local size `(64,1,1)`; each lane owns one row. The EXEC |
| 412 | guard excludes every row at or beyond M, including deliberately extra groups. |
| 413 | Pointer products and additions retain both 32-bit halves. |
| 414 | |
| 415 | ### Format and encoding authority |
| 416 | |
| 417 | AMD [HIP 6.2.4 FP8 Numbers](https://rocm.docs.amd.com/projects/HIP/en/docs-6.2.4/reference/fp8_numbers.html), |
| 418 | “Supported Devices”, explicitly lists **gfx940/gfx941/gfx942: FNUZ FP8 Yes, |
| 419 | OCP FP8 No**. Its text says: “if you use this on gfx94x GPU, it will be fnuz |
| 420 | number”, and defines NaN as sign set with all exponent and mantissa bits zero. |
| 421 | LLVM [18.1.3 APFloat.h lines 162–179](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/include/llvm/ADT/APFloat.h#L162-L179) |
| 422 | defines E5M2FNUZ bias16 and E4M3FNUZ bias8, with no infinity or signed zero; |
| 423 | NaN occupies the negative-zero encoding. This kernel uses E4M3FNUZ only. |
| 424 | It does not interpret weights as OCP E4M3FN (bias7, signed zero, other NaN codes). |
| 425 | |
| 426 | The AMD Instinct MI300 CDNA3 ISA, physical PDF pp58–60 (same locally hashed |
| 427 | manual as section12.1), gives the FP8 format table and conversion rules. |
| 428 | FP8 is E4M3, bias8, sole NaN0x80, sole zero0x00; exponent15 values are finite. |
| 429 | The BF8 table's INF entry conflicts with its NaN entry; no BF8 operation is |
| 430 | implemented or inferred from that cell. The explicit LLVM/HIP FNUZ definitions |
| 431 | above establish the BF8 format name, not hardware qualification. |
| 432 | |
| 433 | LLVM18 [VOP1Instructions.td lines 589–621](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOP1Instructions.td#L589-L621) |
| 434 | selects SDWA for byte0 under `HasCvtFP8VOP1Bug`. |
| 435 | [Lines 1418–1444](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOP1Instructions.td#L1418-L1444) |
| 436 | assign CVT_F32_FP8 opcode0x54 and fix SDWA destination selector bits42–40 to6. |
| 437 | The kernel uses that SDWA BYTE0 form even where a non-SDWA encoding might exist. |
| 438 | [VOP3Instructions.td lines1604–1611](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOP3Instructions.td#L1604-L1611) |
| 439 | assign MUL_LO_U32=0x285 and MUL_HI_U32=0x286. The format definitions cited in |
| 440 | section8 supply VOP3A and SDWA bit positions. FLATInstructions.td's gfx9 GLOBAL |
| 441 | table assigns unsigned-byte load opcode0x10. The host gate assembles the |
| 442 | independent `fp8gemv-gfx942.s` with `llvm-mc-18 -mcpu=gfx942` and compares |
| 443 | the complete instruction section, metadata note, and non-relocated descriptor |
| 444 | bytes, rather than treating an accepted mnemonic as encoding proof. |
| 445 | |
| 446 | | Added instruction | Physical PDF page | Semantics and state effects checked by single-step cases | |
| 447 | | --- | --- | --- | |
| 448 | | V_CVT_F32_FP8 SDWA BYTE0 | 58–60, 211–212 | Convert low byte from E4M3FNUZ; active lanes only; preserve EXEC, VCC, SCC. All byte values checked, upper source bytes ignored. | |
| 449 | | V_MUL_LO_U32 | 361 | Low32 of unsigned 32-by-32 multiplication; preserve flags and inactive destinations. | |
| 450 | | V_MUL_HI_U32 | 361 | High32 of the same unsigned 64-bit product; preserve flags and inactive destinations. | |
| 451 | | GLOBAL_LOAD_UBYTE | 87, 90, 503 | Same global address rule as dword load; exactly one byte read and zero-extended, including final byte of memory. | |
| 452 | |
| 453 | The executor accepts only conversion BYTE0 with LLVM's fixed destination selector |
| 454 | and zero modifiers. Other selectors, non-SDWA conversion, other conversion opcodes, |
| 455 | and unsupported modifiers refuse66. Its VOP3 multiply subset accepts a VGPR src0 |
| 456 | and an SGPR or VGPR src1, no src2 or modifiers. Byte loads retain address/range |
| 457 | refusals67 and I/O refusals74. Validation still decodes every word before opening |
| 458 | memory for execution. The conversion is integer-only in seeded Omega: extract |
| 459 | the sign/exponent/fraction, normalize an FP8 subnormal, and construct exact FP32 |
| 460 | bits. No finite value requires rounding. The host maps the sole FP8 NaN to |
| 461 | canonical FP32 0x7fc00000; this does **not** claim hardware NaN payload parity. |
| 462 | FP32 multiplication and accumulation retain the exact integer FMA implementation |
| 463 | and one nearest-even rounding, with denormals preserved. |
| 464 | |
| 465 | The producer's former eight-format array is replaced with an anonymous-file |
| 466 | registry, growing with declared formats. Each record's field capacity derives |
| 467 | from the maximum64 instruction bits; it does not bound the number of formats. |
| 468 | Format IDs are keys, not array offsets. Branch references retain reserved SOPP |
| 469 | format ID4. Registry checks cover sparse high IDs, extra unused formats with an |
| 470 | unchanged object, and undeclared-format refusal before output. All earlier code |
| 471 | objects must remain byte-identical to the corrected SGEMM chain. |
| 472 | |
| 473 | ### Acceptance and hardware boundary |
| 474 | |
| 475 | `tests/amd-exec/fp8gemv.py` independently decodes the format into exact Python |
| 476 | Fractions, then uses the rational FP32 rounding oracle. The single-step table |
| 477 | checks every byte's conversion without GEMV or scaling hiding an error. The |
| 478 | kernel gate also runs an all-byte matrix, the Cartesian M/K shape table, empty |
| 479 | rows, finite/special FP32 inputs and scales, and whole-memory guards. Executable |
| 480 | controls substitute a complete OCP E4M3FN converter and replace the scale |
| 481 | multiply with a move; each must produce a bit mismatch. Earlier gates, shapes, |
| 482 | SCC/VCC/addressing controls, and wrong-compiler preflight refusal remain. |
| 483 | Final PASS counts are derived from the test tables. Gate receipts record actual |
| 484 | commands, logs, compiler errors, outputs, hashes and observed exits. |
| 485 | |
| 486 | **Hardware NOT_RUN — required notebook check:** the manual's exact text on |
| 487 | physical PDF p60 is: “The register SH_MEM_CONFIG, bit[8] must be set to 1 to |
| 488 | produce the correct results for BF8 and FP8 operations.” When that bit is set, |
| 489 | this kernel assumes **E4M3FNUZ** weight bytes (bias8, unsigned zero0x00, NaN0x80), |
| 490 | not OCP E4M3FN. This host executor neither reads nor writes SH_MEM_CONFIG. |
| 491 | The notebook must establish that register precondition through an authorized |
| 492 | hardware path before dispatch. No register state, GPU dispatch, timing, |
| 493 | throughput, ROCr loading, or device-output parity has been measured here. |
| 494 | |
| 495 | ## 14. gfx942 BF16 GEMV |
| 496 | |
| 497 | `backend/amd/gfx942/bf16gemv.isa` defines `bf16gemv(W,x,y,M,K)`: three |
| 498 | 64-bit global pointers at offsets0/8/16, unsigned32 M/K at24/28, a32-byte |
| 499 | kernarg. W is row-major little-endian BF16, two bytes per element; x[K] and |
| 500 | y[M] are FP32. Each row starts with acc=positive zero, then, for ascending k, |
| 501 | `acc = RN32(BF16(W[m*K+k]) * x[k] + acc)` with **one fused rounding**. |
| 502 | The output is acc; K=0 writes positive zero and M=0 writes nothing. |
| 503 | The grid is `(M,1,1)` with local size `(64,1,1)`, one row per lane. EXEC |
| 504 | excludes over-dispatched rows. The row product is multiplied and doubled |
| 505 | with both32-bit halves and carry propagation; valid arrays must fit the |
| 506 | machine's64-bit address space. No input is rounded to BF16. |
| 507 | |
| 508 | ### Exact widening and the instruction choice |
| 509 | |
| 510 | BF16 is S1E8M7, bias127. LLVM18.1.3 |
| 511 | [APFloat.cpp lines127–129](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Support/APFloat.cpp#L127-L129) |
| 512 | gives BF16 and FP32 the same exponent range, with precisions8 and24. |
| 513 | **BF16-to-FP32 widening is exactly `uint32(bf16_bits) << 16`**: no finite |
| 514 | rounding, zero flushing, or reinterpretation as IEEE FP16. Signed zeros, |
| 515 | infinities and NaN sign/payload bits are carried by the widening itself. |
| 516 | Subsequent FMA uses the existing explicit canonical-NaN host policy, which |
| 517 | does not establish device NaN payload parity. |
| 518 | |
| 519 | The CDNA3 manual physical PDF p507 specifies `GLOBAL_LOAD_SHORT_D16_HI`: |
| 520 | `VDATA[31 : 16].b16 = MEM[addr].b16; // VDATA[15:0] is preserved.` |
| 521 | That pseudocode is not the configured target's unused-half behavior. The fixed |
| 522 | executor profile `mi300x-vf-rocm722-d16-zero` follows raw observations from the |
| 523 | MI300X VF / ROCm7.2.2 recorded in |
| 524 | `AMD-MI300X-CODEX-20261113T0315Z/amdserve-d16probe.txt`, SHA256 |
| 525 | `af7365ee4f2f0da6db6e995cda83c4ac4a6ee6da3df3446936621ca96c4ac0c7`. |
| 526 | Every probed unsigned-byte, signed-byte and short D16 low/high form zeroed |
| 527 | its unused half, including nonzero prefills, delayed/copy/overwrite cases and |
| 528 | identical repeated dispatches; all six no-load controls were caught. RAS was |
| 529 | enabled in the recorded environment. Section9.1.6 documents ECC-dependent |
| 530 | zeroing for buffer D16 loads; that is context, not proof of this GLOBAL |
| 531 | instruction's cause. The executor supports only SHORT_D16_HI and now zeros |
| 532 | its low16. The other five probed forms remain refused. This named fixed |
| 533 | profile does not claim behavior for every gfx942 configuration. |
| 534 | Initialize v7 once with `V_MOV_B32 v7,0` (p186), then use this high-half load |
| 535 | for each weight. Nothing in the loop changes v7's low16 bits. This performs |
| 536 | load and exact widening in **one instruction per weight**, rather than a |
| 537 | ushort load followed by a shift. This is an instruction-count choice, not |
| 538 | a measured throughput claim. Each iteration waits for VM_CNT before FMA |
| 539 | and before the next partial-register load. BF16 has no FP8 format-select |
| 540 | precondition: this path is a bitwise load followed by FP32 FMA; descriptor |
| 541 | FP32 round mode0 and denorm mode3 retain input/output denormals (p45). |
| 542 | |
| 543 | ### Semantics and encoding authority |
| 544 | |
| 545 | The manual is the same physical-page-numbered CDNA3 source as section12.1. |
| 546 | All instructions used by this kernel are listed below, including reused |
| 547 | ones. Encoding links name the pinned LLVM18.1.3 format/opcode definitions; |
| 548 | the independent `bf16gemv-gfx942.s` is assembled by `llvm-mc-18 -mcpu=gfx942`. |
| 549 | The gate compares **complete .text**, metadata note, descriptor bytes other |
| 550 | than the ET_REL entry relocation, and checks the resolved entry separately. |
| 551 | |
| 552 | | Instruction | CDNA3 physical PDF page | Semantics | LLVM18.1.3 encoding | |
| 553 | | --- | --- | --- | --- | |
| 554 | | S_LOAD_DWORDX4 | 68,70,147 | Four dwords; component alignment, quad SGPR destination; flags unchanged. | [SMInstructions.td][bf16-sm], SMEM and `_vi` opcode | |
| 555 | | S_LSHL_B32 | 103 | Low32 shift, count masked5bits; SCC=result nonzero. | [SOPInstructions.td][bf16-sop], SOP2 | |
| 556 | | S_SUB_U32 | 97 | Low32 difference; SCC=unsigned borrow. | [SOPInstructions.td][bf16-sop], SOP2 | |
| 557 | | S_AND_SAVEEXEC_B64 | 124–125 | Save old EXEC, AND source into EXEC; SCC=new EXEC nonzero. | [SOPInstructions.td][bf16-sop], SOP1 | |
| 558 | | S_CBRANCH_EXECZ | 140 | Branch iff whole EXEC zero; signed16 DWORD displacement from next PC. | [SOPInstructions.td][bf16-sop], SOPP | |
| 559 | | S_CBRANCH_SCC0 / S_CBRANCH_SCC1 | 139 | Branch iff SCC=0 / SCC=1; same displacement; flags unchanged. | [SOPInstructions.td][bf16-sop], SOPP | |
| 560 | | S_WAITCNT | 141 | Wait for lgkmcnt/vmcnt0; no flag writes. | [SOPInstructions.td][bf16-sop], SOPP | |
| 561 | | S_ENDPGM | 138 | End wave; implicit memory wait. | [SOPInstructions.td][bf16-sop], SOPP | |
| 562 | | V_AND_B32 | 174 | Bitwise AND, flags unchanged. | [VOP2Instructions.td][bf16-vop2], VOP2e | |
| 563 | | V_ADD_U32 | 183 | Low32 sum, no carry flags. | [VOP2Instructions.td][bf16-vop2], gfx9 | |
| 564 | | V_CMP_GT_U32 | 22,251 | VCC=EXEC AND unsigned greater-than mask. | [VOPCInstructions.td][bf16-vopc], VOPCe | |
| 565 | | V_LSHLREV_B32 / V_LSHRREV_B32 | 173 | Left / unsigned right shift, count masked5bits; flags unchanged. | [VOP2Instructions.td][bf16-vop2], VOP2e | |
| 566 | | V_MUL_LO_U32 / V_MUL_HI_U32 | 361 | Low / high32 unsigned product; flags unchanged. | [VOP3Instructions.td][bf16-vop3], opcodes0x285/0x286 | |
| 567 | | V_MOV_B32 | 186 | Bitwise copy to active lanes; flags unchanged. | [VOP1Instructions.td][bf16-vop1], VOP1e | |
| 568 | | V_ADD_CO_U32 | 22,175 | Low32 sum; replace VCC with active-lane carry mask. | [VOP2Instructions.td][bf16-vop2], VOP2e | |
| 569 | | V_ADDC_CO_U32 | 22,176 | Include incoming lane carry; replace VCC. | [VOP2Instructions.td][bf16-vop2], VOP2e | |
| 570 | | GLOBAL_LOAD_SHORT_D16_HI | 87,90,507 plus target-profile receipt above | Read exactly two bytes into high16 and zero low16 for the observed MI300X VF target; flags/inactive lanes unchanged. | [FLATInstructions.td][bf16-flat], `FLAT_Real_AllAddr_vi<0x25>` | |
| 571 | | GLOBAL_LOAD_DWORD | 87,90,503–504 | Active-lane32-bit load, VGPR64 address plus signed13 offset. | [FLATInstructions.td][bf16-flat], opcode0x14 | |
| 572 | | GLOBAL_STORE_DWORD | 87,90,505 | Corresponding active-lane32-bit store. | [FLATInstructions.td][bf16-flat], opcode0x1c | |
| 573 | | V_FMAC_F32 | 185 | Exact product plus destination, one nearest-even FP32 rounding. | [VOP2Instructions.td][bf16-vop2], gfx940 opcode0x3b | |
| 574 | |
| 575 | [bf16-sm]: https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/SMInstructions.td |
| 576 | [bf16-sop]: https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/SOPInstructions.td |
| 577 | [bf16-vop1]: https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOP1Instructions.td |
| 578 | [bf16-vop2]: https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOP2Instructions.td |
| 579 | [bf16-vopc]: https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOPCInstructions.td |
| 580 | [bf16-vop3]: https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOP3Instructions.td#L1604-L1611 |
| 581 | [bf16-flat]: https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/FLATInstructions.td#L1969-L1993 |
| 582 | |
| 583 | The only new executor instruction is `GLOBAL_LOAD_SHORT_D16_HI`, with the |
| 584 | existing restricted GLOBAL VGPR64/off addressing, no cache modifiers. |
| 585 | It reads exactly two little-endian bytes and zeroes destination low16 in the |
| 586 | fixed target profile above. Other D16 forms or modifiers refuse66; insufficient |
| 587 | memory refuses67, I/O failure74. Single-step expectations combine the loaded-half |
| 588 | definition on p507 with the measured unused-half behavior. Cases include lane63, |
| 589 | inactive lanes, unchanged flags, negative offsets, the final two bytes of memory, |
| 590 | and truncated-memory refusals. A low-half-preserving mutant must now fail the |
| 591 | nonzero-prefill case. The earlier preserve model and its inverse control remain |
| 592 | in immutable historical receipts, not as a selectable fallback. |
| 593 | |
| 594 | ### Acceptance and hardware boundary |
| 595 | |
| 596 | `tests/amd-exec/bf16gemv.py` independently reconstructs BF16 finite values |
| 597 | as exact Fractions and applies the existing rational single-rounding FMA |
| 598 | oracle, not host floating arithmetic. The gate runs the Cartesian shape |
| 599 | table M={0,1,63,64,65}, K={0,1,3,64,65,130} for finite and special inputs. |
| 600 | The weight base is two-byte aligned but not dword aligned, so odd K tests |
| 601 | both row-end alignments. Every byte of memory is checked: output elements, |
| 602 | guard words, inputs, kernarg, and deliberately over-dispatched rows. |
| 603 | An additional isolated-weight matrix checks each special class without an |
| 604 | earlier NaN masking later operations. Controls execute a big-endian weight |
| 605 | loader and an instruction-table mutant that truncates x's low16 bits before |
| 606 | FMA; both must produce output-bit mismatches, not compilation/refusal errors. |
| 607 | Previous kernel objects remain byte-identical and all prior gate cases |
| 608 | remain. Final PASS counts come from the actual case tables. |
| 609 | |
| 610 | **Hardware NOT_RUN:** no AMD device, dispatch, memory-ordering/timing, |
| 611 | throughput, ROCr loading, model weights, or Qwen end-to-end inference was |
| 612 | exercised. The binary/text and host semantic gates are not GPU qualification. |
| 613 | |
| 614 | ## 15. gfx942 wave-parallel FP8/BF16 GEMV |
| 615 | |
| 616 | `fp8gemv2.isa` and `bf16gemv2.isa` are separate kernel symbols and objects; |
| 617 | the previous five kernels and producer remain unchanged. Their argument |
| 618 | layouts and datatypes are the same as sections13–14. **Launch workgroup |
| 619 | size64, GRID_X=64*M, GRID_Y=1.** Workgroup X is the output row; lane0 alone |
| 620 | stores. An extra row group safely returns before touching vector memory. |
| 621 | The descriptor does not request workgroup Y. The new kernels are not |
| 622 | drop-in replacements for the old kernels' launch geometry. |
| 623 | |
| 624 | ### Hardware observation and design |
| 625 | |
| 626 | The operator's MI300X notebook record |
| 627 | `~/handoffs/hive/amdserve/evidence/AMD-MI300X-NOTEBOOK-20261112T224000Z` |
| 628 | reports bit-exact old-kernel results. FP8 times for MxK |
| 629 | 17408x5120, 5120x17408, 5120x5120 were0.7472,2.5073,0.7295ms; |
| 630 | BF16 times were0.7402,2.5001,0.7399ms. Time followed K rather than weight |
| 631 | bytes. That observation motivates removing the dependent load/wait for |
| 632 | every scalar k; it does not establish a tuned-kernel speedup. |
| 633 | |
| 634 | The CDNA3 manual physical PDF p12 defines a wavefront as64 work-items. |
| 635 | [AMD's MI300 architecture description][gemv2-arch] specifies304 active CUs. |
| 636 | One wave per row supplies M independently schedulable workgroups rather |
| 637 | than the old ceil(M/64) groups. The [ROCm Compute Profiler7.2.2 vector-L1 |
| 638 | description][gemv2-cache] specifies64B cache lines and explains address |
| 639 | coalescing and backpressure from outstanding requests. Each lane owns four |
| 640 | consecutive columns. Across the wave, a chunk accesses contiguous weight |
| 641 | and x ranges, instead of loading one scalar from widely separated rows. |
| 642 | FP8 packs those four weights into one DWORD; BF16 uses DWORDX2; x uses |
| 643 | DWORDX4. These are consecutive-byte accesses, not a claim that a memory |
| 644 | instruction is a single cache transaction. |
| 645 | |
| 646 | The main loop prefetches four chunks into disjoint VGPRs: four weight loads |
| 647 | and four x loads before one `s_waitcnt vmcnt(0)`. The CDNA3 manual p141 |
| 648 | defines this wait in terms of outstanding vector-memory operations; it |
| 649 | does not require a wait after each issue. The load group processes1024 |
| 650 | columns before advancing pointers. The remaining columns use guarded |
| 651 | scalar loads with EXEC saved/restored for every element. The batch size is |
| 652 | a tuning choice, not an imposed input-size limit. No input is truncated. |
| 653 | Resource use and the complete instruction stream are compared against |
| 654 | LLVM18 gfx942, including all wide loads, FMAC, EXEC moves and DS operations. |
| 655 | |
| 656 | No LDS storage or barrier is used. `DS_BPERMUTE_B32` (p437) says: |
| 657 | “This does not access LDS memory and may be called even if no LDS memory |
| 658 | is allocated to the wave. It uses LDS hardware to implement an arbitrary |
| 659 | swizzle across threads in a wavefront.” Its LLVM18 instruction declaration |
| 660 | is under `let Uses = [EXEC]`; no M0/LDS-range setup is required here. |
| 661 | Each permutation is followed by `s_waitcnt lgkmcnt(0)` before the add. |
| 662 | |
| 663 | ### Exact accumulation order |
| 664 | |
| 665 | For lane L, start P[L]=+0. Visit chunks q=0,1,... in ascending order and |
| 666 | j=0,1,2,3 within each chunk. When k=256*q+4*L+j is less than K, set |
| 667 | P[L]=RN32_FMA(decode(W[row,k]),x[k],P[L]). The unrolled load grouping does |
| 668 | not change this order. Then perform six simultaneous butterfly stages |
| 669 | with distance32,16,8,4,2,1, in that exact order: |
| 670 | `next[L] = RN32_ADD(P[L], P[L XOR distance])`. Each stage reads a snapshot |
| 671 | of the previous stage. Store lane0, applying one final RN32 scale |
| 672 | multiplication for FP8 only. Missing tail elements cause no arithmetic, |
| 673 | not artificial zero products that might alter signed zero or NaN results. |
| 674 | K=0 still follows the defined zero reduction and FP8 scaling. |
| 675 | |
| 676 | `tests/amd-exec/gemv2.py` records this algorithm using exact `Fraction` |
| 677 | arithmetic and the independent binary32 rounding/FMA reference. Its add |
| 678 | is the exact rational equivalent FMA(a,1,b), not host float arithmetic. |
| 679 | The Omega executor's integer FP32 add/FMA paths retain denormals and use |
| 680 | round-to-nearest-even; the explicit canonical-NaN policy from section10 |
| 681 | remains. Arithmetic order differs deliberately from the old serial GEMV. |
| 682 | The tree-order control places +2^24,+1,-2^24 in lanes0,16,32 respectively; |
| 683 | swapping the first two stages must change the output, not merely the code. |
| 684 | |
| 685 | ### Added instruction semantics and refusal boundary |
| 686 | |
| 687 | All reused instructions retain the manual audit in sections12–14. |
| 688 | New operations below have manual-derived single-step input/output/flag |
| 689 | cases, including inactive lanes and refusals. The bounded source/destination |
| 690 | subset is explicit: this is an executor, not a claim of complete gfx942. |
| 691 | |
| 692 | | Instruction | CDNA3 physical PDF page | Implemented semantics and boundary | LLVM18.1.3 source | |
| 693 | | --- | --- | --- | --- | |
| 694 | | S_MOV_B64 | 20,115 | Even SGPR pair to EXEC only; exact64-bit copy, SCC/VCC unchanged. Other forms refuse66. | [SOPInstructions.td][bf16-sop], SOP1 opcode1 | |
| 695 | | V_XOR_B32 | 174 | Active-lane bitwise XOR; no flag writes or modifiers. | [VOP2Instructions.td][bf16-vop2], opcode21 | |
| 696 | | GLOBAL_LOAD_DWORDX2 / DWORDX4 | 87,90,504 | Sequential2/4 little-endian dwords from the existing VGPR64/off address; flags and inactive lanes preserved. Full range checked before writes. | [FLATInstructions.td][bf16-flat], opcodes21/23 | |
| 697 | | DS_BPERMUTE_B32 | 437 | Source lane=((address+offset)/4)%64, disabled source returns0, disabled destination unchanged; all source reads precede all writes. GDS/accumulator/DATA1 modifiers refuse66. | [DSInstructions.td][gemv2-ds], `DS_Real_vi`, opcode63 | |
| 698 | |
| 699 | Instruction words alone drive execution; the executor does not recognize |
| 700 | kernel names, ISA tables, metadata, or expected answers. Unknown encodings |
| 701 | refuse66. Truncated/bad text refuses65, flat-memory bounds67, I/O74, CLI64; |
| 702 | the gate rejects a wrong compiler digest69 before invoking any compiler. |
| 703 | The64-entry permutation temporary is the physical wave width, not an |
| 704 | arbitrary software capacity. Per-instruction controls deliberately lose |
| 705 | SCC on MOV64, substitute OR for XOR, omit a wide-load dword, and read an |
| 706 | aliased permutation source live; all must fail the manual expectations. |
| 707 | |
| 708 | ### Host acceptance and hardware handoff |
| 709 | |
| 710 | The gate retains all prior shapes and cases. New shape tables are the |
| 711 | union of both old GEMV tables plus chunk-boundary/tail cases; the final |
| 712 | PASS line derives its counts from the actual tables. Finite and special |
| 713 | inputs check every output bit and every unchanged memory byte, including |
| 714 | past-M guards. Additional controls change the reduction order, drop the |
| 715 | tail, or change the row stride and must produce output mismatches. |
| 716 | For each of the three notebook shapes, a test-only row entry executes |
| 717 | first, middle and last rows with the real full M/K and full matrix address |
| 718 | layout. All other output bytes must stay untouched. The production |
| 719 | executor CLI is unchanged. The sampled row results are recorded in a TSV. |
| 720 | Both compiler builds and emitted objects must be byte-identical. |
| 721 | |
| 722 | **Tuned hardware NOT_RUN:** performance, cache traffic, memory scheduling, |
| 723 | device NaN payloads and device results require the parent's MI300X run. |
| 724 | Host execution is not a memory-bandwidth measurement. BF16 uses exact |
| 725 | widening; FP8 assumes E4M3FNUZ (bias8, sole NaN0x80). Beside that hardware |
| 726 | row, the exact manual p60 precondition remains: |
| 727 | “The register SH_MEM_CONFIG, bit[8] must be set to 1 to produce the correct |
| 728 | results for BF8 and FP8 operations.” |
| 729 | |
| 730 | [gemv2-arch]: https://rocm.docs.amd.com/en/docs-6.3.1/conceptual/gpu-arch/mi300.html |
| 731 | [gemv2-cache]: https://rocm.docs.amd.com/projects/rocprofiler-compute/en/docs-7.2.2/conceptual/vector-l1-cache.html |
| 732 | [gemv2-ds]: https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/DSInstructions.td |
| 733 | |
| 734 | ## 16. gfx942 tiled full-attention core (27B) |
| 735 | |
| 736 | ### Model and boundary |
| 737 | |
| 738 | The exact [Qwen3.8-27B-FP8 config at revision |
| 739 | 017b9c7af6b5689d5dd426a76e0bc077eb5ca20a][attn-config] is filed unchanged at |
| 740 | `tests/amd-exec/model/qwen38-27b-fp8-config.json`. Its digest is checked |
| 741 | against the historical Q27 manifest, rather than a mutable model name. |
| 742 | Its `text_config` specifies `num_attention_heads=24`, |
| 743 | `num_key_value_heads=4`, `head_dim=256`, `attn_output_gate=true`, |
| 744 | `output_gate_type="swish"`, and full attention every fourth layer. |
| 745 | The same configuration specifies `rms_norm_eps=1e-6`, |
| 746 | `partial_rotary_factor=0.25`, and `rope_theta=10000000`. |
| 747 | |
| 748 | This commit implements **only the attention core**: Q is FP32, already |
| 749 | Q-normalized and rotated; the BF16 K/V cache already contains the newest |
| 750 | token. It writes FP32 attention values before the output gate. Q/K |
| 751 | normalization, RoPE, cache append, and the output swish/sigmoid gate belong |
| 752 | to separate kernels, not an implicit assumption that they are unnecessary. |
| 753 | The mathematical reference is `tests/gpu_decode_attn256_test.c`: lines |
| 754 | 50–52 establish24/4 heads and6 queries per KV head, lines61–66 give the |
| 755 | cache layout, and lines125–143 specify GQA mapping, the scaled dot product, |
| 756 | max-subtracted softmax, and weighted V. Lines100–111 describe the preceding |
| 757 | zero-centered `(1+w)` Q/K normalization and partial RoPE; lines118–123 |
| 758 | describe K/V BF16 cache append. These are model-math references, not |
| 759 | NVIDIA tool or instruction facts. |
| 760 | |
| 761 | Both kernels share a48-byte kernarg: |
| 762 | Q pointer at0, K at8, V at16, partials at24, output at32, token count T |
| 763 | at40, cache capacity at44; the last two fields are unsigned32-bit. |
| 764 | Q and output are `[24][256]` FP32. K and V are `[4][capacity][256]` BF16. |
| 765 | T means **number of valid tokens**, not the newest zero-based position; |
| 766 | the caller requires T<=capacity. A prep launch appending position P feeds |
| 767 | T=P+1 to this core. Nonfinite model inputs are outside the numerical |
| 768 | qualification fixtures; unsupported instructions and memory violations |
| 769 | still have the executor's defined refusals. |
| 770 | |
| 771 | `attn256_part`: launch `(ceil(T/64),24)` workgroups of64 lanes, with |
| 772 | workgroup X selecting a64-token tile and workgroup Y selecting the Q head. |
| 773 | Both dimensions may be overdispatched: invalid tiles/heads return without |
| 774 | accessing arrays. `attn256_merge`: launch `(1,24)` workgroups of64 lanes. |
| 775 | The executor CLI takes **work-item grid X**, so its X argument is64 times |
| 776 | the workgroup count, not the count itself. Both descriptors enable |
| 777 | workgroup-id Y; the gate compares their descriptor bytes with LLVM18 and |
| 778 | checks that bit explicitly. |
| 779 | |
| 780 | Partials contain `[24][ceil(T/64)]` records of1040 bytes: FP32 maximum |
| 781 | at0, denominator at4, eight untouched padding bytes at8, and256 FP32 |
| 782 | unnormalized weighted sums at16. T=0 reads no Q/K/V/partial records and |
| 783 | writes zero output. Partial buffers are scratch, not a persistent KV |
| 784 | cache or a host computation dependency. |
| 785 | |
| 786 | ### Scheduling and exact arithmetic order |
| 787 | |
| 788 | The wave64,304-CU and64-byte cache-line references in section15 apply here. |
| 789 | One wave per head alone would offer only24 workgroups. Tiling the context |
| 790 | adds independently schedulable workgroups without atomics or cross-wave |
| 791 | barriers. Each lane owns four adjacent dimensions. Q loads use DWORDX4; |
| 792 | the K and V loads for a token are DWORDX2, both issued before a single |
| 793 | `vmcnt(0)` wait. Thus all lanes cover contiguous512-byte BF16 rows, not |
| 794 | one strided scalar each. DS_BPERMUTE uses no allocated LDS; its lgkm wait |
| 795 | and snapshot semantics are unchanged from section15. Hardware bandwidth, |
| 796 | occupancy and performance remain NOT_RUN. |
| 797 | |
| 798 | Within each tile, visit tokens in ascending order. Each lane starts its |
| 799 | dot accumulator at +0 and executes four RN32 FMA operations for dimensions |
| 800 | `4*lane+j`, j=0,1,2,3. Six simultaneous XOR butterfly adds at distances |
| 801 | 32,16,8,4,2,1 follow. Multiply the resulting score by exact FP32 |
| 802 | `1/sqrt(256)=1/16=0.0625`. Every active lane obtains the same score. |
| 803 | Initialize maximum m=-infinity, denominator l=+0, and each sum a=+0. |
| 804 | For score s, set: |
| 805 | |
| 806 | * n=MAX32(m,s). |
| 807 | * alpha=EXP2_32(RN32_MUL(RN32_SUB(m,n),LOG2E32)). |
| 808 | * beta=EXP2_32(RN32_MUL(RN32_SUB(s,n),LOG2E32)). |
| 809 | * l=RN32_ADD(RN32_MUL(l,alpha),beta). |
| 810 | * a[d]=RN32_FMA(beta,V[d],RN32_MUL(a[d],alpha)). |
| 811 | * m=n. |
| 812 | |
| 813 | LOG2E32 is the binary32 constant0x3fb8aa3b. The merge visits tile records |
| 814 | in ascending tile order, reweights old and tile statistics by their |
| 815 | maxima in the same manner, and uses FMA for both the merged denominator |
| 816 | and sums. Finally it computes RCP32(l) once and multiplies each sum by it. |
| 817 | It does not claim the same rounding order as a monolithic softmax or the |
| 818 | Spark reduction. |
| 819 | |
| 820 | ### Transcendental model and manual audit |
| 821 | |
| 822 | Ordinary add/subtract/multiply/FMA retain the executor's exact RN-even |
| 823 | integer algorithms and denormal preservation. EXP and RCP are different: |
| 824 | the ISA promises1ULP, not device-identical answer bits. The executor |
| 825 | selects one representative within that allowance. EXP uses binary64 |
| 826 | range reduction, an18-term Taylor polynomial of exp(r*ln2), and exact |
| 827 | binary64 powers of two before RN32 conversion. RCP uses binary64 division |
| 828 | then RN32 conversion. Both implement the manual's input/output FTZ and |
| 829 | special-value behavior. This binary64 use is in seeded Omega, not a host |
| 830 | library or a production Python dependency. |
| 831 | |
| 832 | Recorded Wolfram query: |
| 833 | `{N[Log[2],22], N[2 Log[2]^19/19!,22], N[1/Log[2],22], 1/Sqrt[256]}` |
| 834 | returned ln2=0.69314718055994530941723212145817656807, |
| 835 | the Taylor remainder bound1.55460168577147128381779943180201880963e-20, |
| 836 | log2(e)=1.44269504088896340735992468100189213743, and1/16. |
| 837 | The finite-precision implementation is additionally checked against |
| 838 | independent Decimal120-digit enclosures, not justified by the polynomial |
| 839 | remainder alone. |
| 840 | |
| 841 | | Instruction | CDNA3 physical PDF page | Semantics, flags, refusal boundary | LLVM18.1.3 source | |
| 842 | | --- | --- | --- | --- | |
| 843 | | S_LSHR_B32 | 103 | Unsigned source shifted by low5 shift-count bits; SCC iff result nonzero. Other flags unchanged. | [SOPInstructions.td][bf16-sop], opcode30 | |
| 844 | | V_SUB_F32 | 169 | RN32 subtract, denormals preserved; active lanes only, EXEC/VCC/SCC unchanged. | [VOP2Instructions.td][bf16-vop2], opcode2 | |
| 845 | | V_MAX_F32 | 172 | IEEE signaling-NaN quieting first, quiet NaN selects numeric operand, +0 preferred to -0; active lanes only, flags unchanged. | [VOP2Instructions.td][bf16-vop2], opcode11 | |
| 846 | | V_EXP_F32 | 195 | pow(2,S0),1ULP, input/output denormals flushed; -infinity maps0, signed zero maps1, +infinity maps+infinity. | [VOP1Instructions.td][attn-vop1], opcode32 | |
| 847 | | V_RCP_F32 | 196 | Reciprocal,1ULP, input/output denormals flushed; signed zero/infinity map to signed infinity/zero. | [VOP1Instructions.td][attn-vop1], opcode34 | |
| 848 | |
| 849 | Every new opcode has manual-derived single-step cases checking results |
| 850 | and flags; the shared vector-lane dispatcher retains its inactive-lane cases. The |
| 851 | gate retains all earlier cases. Literal/source/modifier refusal boundaries |
| 852 | remain those in sections10–15; no kernel-name recognition is introduced. |
| 853 | |
| 854 | `attention.py` independently uses Fraction arithmetic with RN-even at |
| 855 | each ordinary instruction boundary and Decimal120-digit EXP reference |
| 856 | values. It encloses the manual's1ULP allowance and rounds interval |
| 857 | endpoints outward; an interval is a conservative enclosure, not a claim |
| 858 | that every value inside is an allowed device result. These intervals are |
| 859 | propagated through every reweighting, accumulation and final reciprocal. |
| 860 | Every partial statistic and output must lie inside its own interval. |
| 861 | All inputs, cache tails, padding, and guard bytes must stay unchanged. |
| 862 | Per-output exact rational interval bounds and widths are emitted as JSON; |
| 863 | each case prints the widest interval. No fixed arbitrary output tolerance |
| 864 | replaces the per-instruction bound. Controls remove max subtraction, |
| 865 | mis-map GQA, and load V from K; each must produce a numerical mismatch. |
| 866 | |
| 867 | **Hardware NOT_RUN:** MI300X execution of these attention objects, timing, |
| 868 | the actual transcendental choices, and end-to-end model output require |
| 869 | the parent's hardware bundle. Host byte parity and bounded numerical |
| 870 | checks are not hardware qualification or a measured speedup. |
| 871 | |
| 872 | [attn-config]: https://huggingface.co/Qwen/Qwen3.8-27B-FP8/resolve/017b9c7af6b5689d5dd426a76e0bc077eb5ca20a/config.json |
| 873 | [attn-vop1]: https://github.com/llvm/llvm-project/blob/llvmorg-18.1.3/llvm/lib/Target/AMDGPU/VOP1Instructions.td |
| 874 | |
| 875 | ## 17. gfx942 fused full-attention preparation and output gate |
| 876 | |
| 877 | This follows the same pinned [Q27 config][attn-config] as section16. |
| 878 | The gate verifies its digest and the compiled specialization:24 Q heads, |
| 879 | 4 KV heads,256 dimensions, epsilon1e-6, theta10000000, and64 rotary |
| 880 | dimensions (partial factor0.25). This is the text decode path: the three |
| 881 | MRoPE position axes all equal P, so interleaving sections[11,11,10] |
| 882 | does not change the32 inverse-frequency indices. Multimodal unequal-axis |
| 883 | position construction is not implemented by this text-position producer. |
| 884 | |
| 885 | ### Reference and layouts |
| 886 | |
| 887 | Reference: [Transformers v5.8.0 modeling_qwen3_5.py][prep-reference]. |
| 888 | Lines128–140 define inverse frequencies; lines147–175 form/interleave |
| 889 | the position embeddings. Lines541–545 define `rotate_half(x)` as |
| 890 | `[-x_second_half, x_first_half]`; lines570–585 apply it only to the |
| 891 | rotary prefix. Lines659–665 split each512-element Q projection head into |
| 892 | Q256 and gate256, then apply Q/K norms. Lines668–672 apply RoPE and append |
| 893 | K/V. Lines710–723 define zero-centered RMSNorm with `(1 + weight)`. |
| 894 | Line690 multiplies attention output by **sigmoid(gate)**; this is not |
| 895 | `silu(gate)`. The latter belongs to the gated-delta norm at lines177–190. |
| 896 | The config's `output_gate_type: swish` must not override the full-attention |
| 897 | reference. The existing mathematical reference |
| 898 | `tests/gpu_decode_attn256_test.c:100–123` agrees on norm/rotation/append |
| 899 | and line19 explicitly places sigmoid outside the attention core. |
| 900 | |
| 901 | This implementation's explicit ABI uses FP32 projection/norm values and |
| 902 | position embeddings, then rounds only K/V cache storage to BF16. |
| 903 | It follows the reference formulas, not a claim of PyTorch BF16-intermediate |
| 904 | bit identity. Norm weights are FP32 views of model weights, shared across |
| 905 | heads. No weight values, epsilon, or gate data are invented by the kernel. |
| 906 | |
| 907 | `attn256_prep` has80-byte kernarg, alignment8: |
| 908 | |
| 909 | | Byte offset | Argument | Layout/type | |
| 910 | | --- | --- | --- | |
| 911 | | 0 | Q_gate | FP32 `[24][512]`, Q then gate in each head | |
| 912 | | 8 | K_raw | FP32 `[4][256]` | |
| 913 | | 16 | V_raw | FP32 `[4][256]` | |
| 914 | | 24 | Q_weight | FP32 `[256]`, zero-centered | |
| 915 | | 32 | K_weight | FP32 `[256]`, zero-centered | |
| 916 | | 40 | cos_sin | FP32 cos32 followed by sin32, shared token position | |
| 917 | | 48 | Q_out | FP32 `[24][256]` | |
| 918 | | 56 | K_cache | BF16 `[4][capacity][256]` | |
| 919 | | 64 | V_cache | BF16 `[4][capacity][256]` | |
| 920 | | 72 | P | u32 append position | |
| 921 | | 76 | capacity | u32 allocated cache capacity | |
| 922 | |
| 923 | Launch24 by1 workgroups of64 lanes. Head=`s2`, Y=`s3` must be0. |
| 924 | Overdispatched heads/Y and P>=capacity write nothing. This is the real |
| 925 | allocated-memory boundary, not an arbitrary token cap. After this launch, |
| 926 | the core's token count is `T=P+1`. Each wave handles one Q head; the first |
| 927 | four waves also process the corresponding K/V head. Inputs must not alias |
| 928 | outputs or the cache append slices. Historical cache positions, packed |
| 929 | gate halves, raw projections, norm weights and guard bytes remain unchanged. |
| 930 | |
| 931 | Norm order: lane i visits dimensions4i+j, j0..3, with FP32 FMA of x*x |
| 932 | into+0. All64 lanes use snapshot XOR32,16,8,4,2,1 ADD reductions. |
| 933 | Multiply the sum by1/256, add epsilon (separate RN32 operations), then |
| 934 | V_RSQ_F32. Multiply x by this reciprocal norm, then by RN32(1+weight). |
| 935 | For each rotary pair d,d+32, d0..31, output is separately rounded |
| 936 | `x[d]*cos[d] + (-x[d+32])*sin[d]` and |
| 937 | `x[d+32]*cos[d] + x[d]*sin[d]`. This is **half pairing**, not adjacent |
| 938 | even/odd pairing. The DS_BPERMUTE address XOR is32 bytes (lane XOR8), |
| 939 | with all16 participating lanes active. Dimensions64..255 are unchanged |
| 940 | after norm. No FMA contraction is substituted across the two rotation |
| 941 | products/addition. |
| 942 | |
| 943 | K and V use integer RN-even BF16 conversion: add0x7fff and retained |
| 944 | low-bit parity, then shift16. Infinities and signed zero survive; |
| 945 | any NaN becomes quiet0x7fc0, preventing signaling/low-payload NaNs from |
| 946 | turning into infinity. Two BF16 values are packed into each existing |
| 947 | GLOBAL_STORE_DWORD, so no new store opcode or misaligned write is needed. |
| 948 | |
| 949 | `attn256_gate` has24-byte kernarg: Q_gate pointer0, core attention FP32 |
| 950 | `[24][256]` pointer8, output of that shape pointer16. Launch96 by1 groups |
| 951 | of64; overdispatch is guarded. It reads the packed gate half at |
| 952 | `head*512+256+dimension`. It computes t=exp2(RN32(-abs(g)*LOG2E32)), |
| 953 | r=rcp(RN32(1+t)), then sigma=r for nonnegative g and sigma=RN32(t*r) |
| 954 | for negative g. Output is RN32(attention*sigma), not multiplied by g. |
| 955 | This stable form avoids positive exponent overflow. The gate is a separate |
| 956 | tiny kernel before o_proj; the existing GEMV2 objects remain unchanged. |
| 957 | The gate declares32 VGPRs (highest referenced v30), not the prep kernel's48. |
| 958 | |
| 959 | ### Seeded host position-embedding producer |
| 960 | |
| 961 | `backend/amd/gfx942/rope.om` accepts exactly one little-endian u32 P |
| 962 | on stdin and emits256 bytes: cos32 then sin32 as little-endian FP32. |
| 963 | Missing/trailing input refuses64 with no output; I/O failure is74. |
| 964 | It is compiled with the same seeded pin, uses only Omega native arithmetic |
| 965 | and syscalls, and has no Python/libm/runtime dependency. |
| 966 | |
| 967 | Inverse frequency is RN32(1 / RN32(theta^(i/32))), i0..31; position |
| 968 | is converted to FP32 and multiplied at a FP32 boundary. Power uses |
| 969 | binary64 range reduction and18 exponential terms. The test-only |
| 970 | `ropefreq-probe.om` compares all32 frequencies bit-for-bit with independent |
| 971 | Decimal120-digit power followed by the two required FP32 roundings. |
| 972 | For sin/cos the producer reduces the FP32 angle with a split pi/2 in |
| 973 | binary64, computes21st/20th-degree sine/cosine series, selects the quadrant, |
| 974 | and rounds once to FP32. The64 generated values are shared across every |
| 975 | attention layer for this token; no head recomputes them on the GPU. |
| 976 | |
| 977 | Recorded calculations: |
| 978 | |
| 979 | * Wolfram `N[Log[10000000],22]` ->16.11809565095831978812594; |
| 980 | `N[2/Pi,22]` ->0.6366197723675813430755351. |
| 981 | * Wolfram `N[Pi/2-157079601287841796875/10^20,30]` |
| 982 | ->3.13916478650481321691639751442e-7. |
| 983 | Python byte encoding, `struct.unpack("<Q",struct.pack("<d", |
| 984 | 3.139164786504813216916397514420985846996875529075603e-7))[0]` |
| 985 | ->0x3e95110b4611a626, used as a binary64 bitcast to avoid the pinned |
| 986 | compiler's long fractional-literal parser limit. |
| 987 | * Wolfram `N[Pi,125]` supplied the independent oracle's recorded pi |
| 988 | constant; it is not read from the producer. |
| 989 | * Wolfram `{N[(786/1000)^23/23!,24],N[(786/1000)^22/22!,24], |
| 990 | N[2^-42+2^-53+40*2^-52,24],N[2^-39,24]}` |
| 991 | ->{1.52133245558152738690949e-25,4.45173619317749744261046e-24, |
| 992 | 2.36366481942695827456191e-13,1.81898940354585647583008e-12}. |
| 993 | |
| 994 | MODELED binary64 allowance, not a formal Lean proof: the21-significant-bit |
| 995 | high pi/2 part times the at-most32-bit quadrant index is exact in binary64; |
| 996 | its first subtraction is exact. The low-part representation/product |
| 997 | errors contribute at most2^-42 over u32 positions. The residual stays |
| 998 | within0.786 despite quotient rounding; series truncation is bounded by |
| 999 | the recorded terms, with conservative binary64 roundoff accounting |
| 1000 | 2^-53+40*2^-52. The gate's absolute check allows2^-39 plus half a final |
| 1001 | FP32 ULP against independent Decimal120 sine/cosine, including P=2^32-1. |
| 1002 | This allowance is only for generated embeddings; the GPU applies their |
| 1003 | actual bits and gets no added arbitrary output tolerance. |
| 1004 | |
| 1005 | ### New opcode audit and gates |
| 1006 | |
| 1007 | | Instruction | CDNA3 physical PDF page | Semantics and side effects | LLVM18.1.3 source | |
| 1008 | | --- | --- | --- | --- | |
| 1009 | | V_RSQ_F32 | 197 | Reciprocal square root,1ULP, input/output FTZ; -0 -> -inf, +0 -> +inf,4 ->0.5,+inf ->+0,-inf -> negative quiet NaN. Active lanes only; EXEC/VCC/SCC and inactive registers unchanged. | [VOP1Instructions.td][attn-vop1], opcode36 | |
| 1010 | | Floating inline selectors240..248 | 42, Table23 | FP32 bits for ±0.5, ±1, ±2, ±4 and the manual's exact0x3e22f983 for1/(2*pi). Scalar/vector MOV preserve flags; inactive vector lanes remain untouched. | Operand encodings, not new opcodes | |
| 1011 | | S_NOP | 138 | Issue delay1..16 clocks from low4 immediate bits; no register, flag or memory changes. The functional executor advances PC only and does not model elapsed cycles. | SOPP opcode0 | |
| 1012 | |
| 1013 | The executor uses native binary64 sqrt/divide followed by FP32/FTZ as |
| 1014 | a bounded representative, not the actual MI300X approximation. Manual |
| 1015 | single-step cases include both end lanes, inactive-lane sentinels, signed |
| 1016 | zeros, subnormals, negative input, infinities and4. Replacing RSQ by |
| 1017 | RCP must be CAUGHT. The bulk probe checks4096 independent positive normal |
| 1018 | inputs against Decimal120 and the manual1ULP enclosure. S_NOP is the only |
| 1019 | other new opcode; earlier audit tables and refusal boundaries apply. |
| 1020 | Every added inline selector has scalar and vector single-step cases, plus |
| 1021 | V_ADD_F32 with inline1.0. Restoring the old refusal must be CAUGHT. |
| 1022 | LLVM selects inline1.0 instead of a literal DWORD; the production tables |
| 1023 | use selector242 so their bytes, lengths and branch displacements match. |
| 1024 | |
| 1025 | CDNA3 pp28–29, Table11: “The hardware does not check for the following |
| 1026 | dependencies; they must be resolved by inserting NOPs or independent |
| 1027 | instructions.” A VALU transcendental followed by a consuming non-trans |
| 1028 | VALU needs one wait state. The merge's RCP and gate's EXP therefore have |
| 1029 | `s_nop 0`; other EXP/RSQ results already have independent intervening |
| 1030 | instructions. `tests/amd/scheduling.py` checks LLVM-decoded bytes from |
| 1031 | every emitted object for this rule, including all earlier GEMV versions. |
| 1032 | It emits real mutant objects with those NOPs removed and requires |
| 1033 | both scheduling failures. This is a static check for this specific hazard, |
| 1034 | not a cycle model or a claim that all other hardware hazards are covered. |
| 1035 | S_NOP single-step cases check low/high immediate bits and unchanged flags; |
| 1036 | a mutant clearing SCC must be CAUGHT. |
| 1037 | |
| 1038 | The prep oracle propagates RSQ intervals through every norm and rotation |
| 1039 | operation, checks every Q output and every appended K/V element, and |
| 1040 | requires all input/history/guard bytes unchanged. BF16 V conversion is |
| 1041 | bit-for-bit including denormals, ties, signed zero, infinities and NaNs. |
| 1042 | For K it reports any BF16 result made ambiguous by the allowed RSQ interval |
| 1043 | rather than hiding it. Exact per-Q-output intervals/widths are filed as |
| 1044 | JSON; each case prints its widest interval. Controls omit the norm's1, |
| 1045 | use the wrong half-pair, write the wrong cache position, truncate BF16, |
| 1046 | multiply the sigmoid result by g, and use the wrong packed-head stride. |
| 1047 | Host-producer controls corrupt rotary dimension and malformed input. |
| 1048 | All earlier gate counts and controls remain. Both new code objects and |
| 1049 | the producer/executor get two byte-identical builds, with LLVM instruction |
| 1050 | and complete descriptor/note parity as before. |
| 1051 | |
| 1052 | **Hardware NOT_RUN:** preparation/gate objects, RSQ/EXP/RCP choices, |
| 1053 | generated-position end-to-end model quality and timing require the |
| 1054 | parent's MI300X bundle. This does not claim complete serving. |
| 1055 | |
| 1056 | [prep-reference]: https://github.com/huggingface/transformers/blob/v5.8.0/src/transformers/models/qwen3_5/modeling_qwen3_5.py |
| 1057 | |
| 1058 | ## 18. Token MLP activation and mandatory scheduling check |
| 1059 | |
| 1060 | The first MI300X attention-core exercise is filed separately in |
| 1061 | `evidence/AMD-GFX942-ATTENTION-DEVICE-20261113T000755Z/`. The corrected |
| 1062 | RCP-consumer delay is exercised on device; the earlier raw diagnostic and |
| 1063 | its BF16 reference-input defect remain visible. This is not qualification |
| 1064 | of the complete token path. The Table11 static scheduling gate stays |
| 1065 | mandatory for **every** future object; functional executor parity alone |
| 1066 | does not test issue timing. |
| 1067 | |
| 1068 | `mlpsilu` implements [Transformers v5.8.0 Qwen3_5MLP lines695–707][prep-reference]: |
| 1069 | `down_proj(silu(gate_proj(x)) * up_proj(x))`. The pinned config revision |
| 1070 | 017b9c7a has hidden5120, intermediate17408 and SiLU activation. This |
| 1071 | kernel consumes the FP32 gate/up outputs of the existing GEMV2 kernels, |
| 1072 | and produces the FP32 vector consumed by GEMV2 down. It is not the |
| 1073 | attention-output sigmoid-only gate. |
| 1074 | |
| 1075 | ABI: gate pointer0, up pointer8, output pointer16, N:u32 at24;28bytes. |
| 1076 | Launch ceil(N/64) workgroups in X, one in Y,64threads. N=0 and extra X/Y |
| 1077 | groups write nothing; the final partial wave masks its inactive lanes. |
| 1078 | Inputs and output must not overlap. Each active lane computes: |
| 1079 | |
| 1080 | 1. t = EXP2(RN32(-abs(g) * LOG2E32)), LOG2E32=0x3fb8aa3b. |
| 1081 | 2. r = RCP(RN32(1+t)); if g has its sign bit set, r = RN32(r*t). |
| 1082 | 3. s = RN32(g*r); output = RN32(s*up). |
| 1083 | |
| 1084 | EXP/RCP use the same CDNA3 pp195–1961ULP/FTZ contract as §16/17, not an |
| 1085 | assumption of device-identical transcendental bits. The reference uses |
| 1086 | independent Fraction round-to-nearest-even arithmetic and Decimal120 |
| 1087 | transcendental enclosures at those exact instruction boundaries. |
| 1088 | The finite-input contract includes signed zeros, subnormals and large |
| 1089 | finite magnitudes. The explicit EXP-consumer NOP and independent |
| 1090 | instructions after RCP satisfy Table11. No instruction is newly added to |
| 1091 | the executor: the manual-derived instruction cases in earlier sections |
| 1092 | remain applicable, including carry, EXEC restoration and SCC. |
| 1093 | |
| 1094 | The gate retains every earlier case and adds counts0,1,63,64,65,17408, |
| 1095 | checks every output interval and every untouched input/guard byte, and |
| 1096 | requires actual wrong-object controls omitting the SiLU input multiply |
| 1097 | and reading gate instead of up to be CAUGHT. Host and LLVM gates build |
| 1098 | twice and compare bytes; the latter checks the full descriptor and |
| 1099 | instruction encodings and runs the scheduling check over all objects. |
| 1100 | |
| 1101 | `tests/amd-exec/token_ref.py` and `section.py` generate code-only notebook |
| 1102 | sections from the actual fixture functions and their arithmetic dependency |
| 1103 | closure. Inputs and all exact results/intervals are computed in the cell: |
| 1104 | no full memory image or interval list is embedded. Generation executes |
| 1105 | that same code and checks every reconstructed case against the host |
| 1106 | oracle, with a missing-case drift control. An emitted-source byte-size |
| 1107 | alarm checks the operator's target below15KB per section, to fit the |
| 1108 | external relay's approximately60KB cell limit. Other kernels' torch |
| 1109 | branches are removed by AST specialization, not by a second handwritten |
| 1110 | implementation. The generated section's `run_section(ctx)` tests small |
| 1111 | cases, measures event/warm-wall/cold-wall timings at17408, checks every |
| 1112 | timed output and guard (all cold copies, not sampled), records wrong-object |
| 1113 | controls, and labels the separate torch measurement |
| 1114 | “(AMD library, not Omega)”. Cold inputs occupy distinct addresses exceeding |
| 1115 | the notebook's COLD_BYTES. No notebook timing is inferred from host runs. |
| 1116 | Each exported source is executed in the loader's fresh empty namespace; |
| 1117 | all generated/decorated/nested function code is also checked for unresolved |
| 1118 | global lookups before export. A control removes the math import and must |
| 1119 | be CAUGHT in the deferred interval checker. Factory execution alone does |
| 1120 | not exercise that checker; hardware notebook execution stays NOT_RUN. |
| 1121 | |
| 1122 | ## 19. Standalone zero-centered RMSNorm5120 |
| 1123 | |
| 1124 | `rmsnorm5120` follows [Transformers v5.8.0 lines710–723][prep-reference]: |
| 1125 | FP32 x*rsqrt(mean(x²)+epsilon), then multiply by (1+weight). This is the |
| 1126 | input, post-attention and final norm, not the gated delta net's norm |
| 1127 | (whose weight is not zero-centered). The pinned config in §17 supplies |
| 1128 | hidden5120 and epsilon1e-6. All input, weight and output elements are FP32; |
| 1129 | the decoder's BF16 weight can be widened exactly before this interface. |
| 1130 | |
| 1131 | ABI: input pointer0, weight pointer8, output pointer16, rows:u32 at24. |
| 1132 | Input/output layout [rows][5120], one shared weight[5120]. The buffers |
| 1133 | must not overlap. Launch X=rows, Y=1, block64; zero rows and additional |
| 1134 | X/Y groups do not write. No arbitrary row cap is introduced. |
| 1135 | |
| 1136 | The instruction order is specified: each lane accumulates80 squares |
| 1137 | using RN-even FMA in ascending chunk/j order, at index256*chunk+4*lane+j |
| 1138 | (chunk0..19, j0..3). All lanes reduce by snapshot XOR32,16,8,4,2,1 using |
| 1139 | RN-even ADD. Multiply by RN32(1/5120), add RN32(epsilon), RSQ, then each |
| 1140 | output uses separately rounded x*inv and result*RN32(1+weight). |
| 1141 | RSQ has the manual pp1971ULP/FTZ enclosure; no guessed device bit pattern. |
| 1142 | The kernel reloads inputs after reduction rather than keeping all rows in |
| 1143 | registers. The host executor's already-audited dwordx4, bpermute, carry |
| 1144 | and loop semantics are reused; no new opcode or gate exception is added. |
| 1145 | The RSQ-consumer delay is explicit and the all-object scheduling gate |
| 1146 | remains mandatory. |
| 1147 | |
| 1148 | Recorded independent calculation: |
| 1149 | `tests/amd-exec/sgemm.py round32(Fraction(1,5120)) -> 0x394ccccd`; |
| 1150 | `tests/amd-exec/norm.py` asserts it at every invocation. The Fraction |
| 1151 | oracle reproduces the declared reduction order, propagates the Decimal120 |
| 1152 | RSQ enclosure through each later rounding, and reports every output's |
| 1153 | interval plus the widest observed interval. Cases include zero rows, |
| 1154 | zero vectors, several rows, subnormal inputs and large finite magnitudes. |
| 1155 | Wrong-object controls omit the zero-centered1, use the wrong mean divisor, |
| 1156 | and omit the last accumulation chunk. Every original case is retained. |
| 1157 | |
| 1158 | The generated `rmsnorm5120.py` notebook section uses the same instrument |
| 1159 | as §18: all outputs/guards, genuine wrong-object controls, event and |
| 1160 | warm/cold wall timing with every timed copy checked, and a separate torch |
| 1161 | line labeled “(AMD library, not Omega)”. Kernel and notebook hardware |
| 1162 | execution remain NOT_RUN until the parent runs that section on MI300X. |
| 1163 | |
| 1164 | ## 20. Gated delta net BF16 causal convolution |
| 1165 | |
| 1166 | `gdnconv4` implements the single-token cached convolution in |
| 1167 | [Transformers v5.8.0 lines211–225 and455–463][prep-reference]. |
| 1168 | The pinned config revision017b9c7a (§17) has kernel4, key heads16, |
| 1169 | value heads48, head dimensions128 and BF16 model weights. The channel |
| 1170 | layout is Q[16][128], K[16][128], V[48][128], totaling10240. |
| 1171 | |
| 1172 | The dtype boundaries follow the reference, not a new FP32-only variant: |
| 1173 | line220 concatenates the existing cache and projected token and converts |
| 1174 | to the weight dtype; line221 copies the last state_len entries back; |
| 1175 | line222 runs the grouped BF16 convolution, whose result is BF16; |
| 1176 | line223 applies SiLU to that BF16 result, producing BF16; line224 converts |
| 1177 | back to the incoming hidden-state dtype. This interface takes the incoming |
| 1178 | projection as FP32, explicitly rounds it to BF16 for the append, uses BF16 |
| 1179 | weights/cache and FP32 accumulating FMA, rounds the convolution result to |
| 1180 | BF16 before SiLU, and rounds SiLU to BF16 before widening its output to |
| 1181 | FP32. Subsequent Q/K normalization therefore receives those widened values. |
| 1182 | |
| 1183 | ABI (40 bytes): input pointer0, weight pointer8, old_cache pointer16, |
| 1184 | new_cache pointer24, output pointer32. Input/output are [10240] FP32; |
| 1185 | weight/old_cache/new_cache are [10240][4] BF16, tap-major inside each |
| 1186 | channel. All buffers are disjoint. The new state is old[1],old[2],old[3], |
| 1187 | RN_BF16(input). Old state is immutable; the caller swaps old/new pointers |
| 1188 | after the launch. Grid X=160, Y=1, block64; additional X/Y groups return. |
| 1189 | |
| 1190 | For each channel, start the accumulator at +0 and FMA the four new-cache |
| 1191 | samples and weights in ascending tap order. BF16 conversion is RN-even |
| 1192 | with signed-zero preservation, infinity preservation and canonical NaN |
| 1193 | 0x7fc0. SiLU uses the stable sigmoid order in §18 on the widened BF16 |
| 1194 | convolution result. The manual's EXP/RCP error enclosures are propagated |
| 1195 | through FP32 operations and the final BF16 rounding. Every output must |
| 1196 | also lie on the BF16 bit lattice; interval membership alone is insufficient. |
| 1197 | Every new-cache halfword is checked exactly. Existing audited instructions |
| 1198 | are reused, and the all-object scheduling gate is mandatory. |
| 1199 | |
| 1200 | `tests/amd-exec/gdnconv.py` independently constructs the updated cache, |
| 1201 | performs Fraction FMA and BF16 rounding at each stated boundary, and reports |
| 1202 | every output interval and its maximum width. Its cases include zero cache, |
| 1203 | different histories, BF16 ties, subnormals, large values, infinities/NaNs, |
| 1204 | partial dispatch and full10240-channel overdispatch. Separate controls |
| 1205 | remove each of the three BF16 conversions or shift the cache incorrectly. |
| 1206 | The generated notebook section checks all state/output/guard bytes, |
| 1207 | every timed cold copy, genuine wrong objects, and a separately labeled |
| 1208 | BF16 torch grouped-convolution reference. Hardware remains NOT_RUN. |
| 1209 | |
| 1210 | ## 21. BF16 GDN query/key normalization and FP32 recurrent state |
| 1211 | |
| 1212 | Model fields remain pinned to config revision |
| 1213 | `017b9c7af6b5689d5dd426a76e0bc077eb5ca20a`: 16 key heads, |
| 1214 | 48 value heads, key/value dimensions 128. The reference is |
| 1215 | Transformers v5.8.0 `modeling_qwen3_5.py`, lines 228–231 |
| 1216 | (`l2norm`), 317–328 (normalize before the FP32 cast, then scale Q), |
| 1217 | 343–350 (decay, key/state reduction, delta, state update, query/state |
| 1218 | reduction), 354 (core output back to initial dtype), and 506–507 |
| 1219 | (repeat each key head for its three value heads). |
| 1220 | |
| 1221 | This is the torch fallback contract without the optional FLA package. |
| 1222 | The model BF16 contract is retained even though kernel boundaries carry |
| 1223 | FP32 words: BF16 values are widened exactly, not treated as unconstrained |
| 1224 | FP32 values and silently advertised as the model's BF16 path. |
| 1225 | |
| 1226 | | Kernel | Kernarg byte offsets | Launch, block | |
| 1227 | | --- | --- | --- | |
| 1228 | | `gdnqknorm` | input Q/K 0, output Q/K 8; two pointers | 32 x 1 workgroups, 64 lanes | |
| 1229 | | `gdnstate` | Q/K 0, V 8, old state 16, new state 24, output 32, decay 40, beta 48; seven pointers | 3 x 16 workgroups, 64 lanes | |
| 1230 | |
| 1231 | All buffers are row-major FP32 words. Q/K layout is `[2][16][128]`; |
| 1232 | V/core output is `[48][128]`; state is `[48][128][128]` in |
| 1233 | `[value head][key row][value column]` order; decay/beta are `[48]`. |
| 1234 | Q/K input is the BF16-rounded, widened convolution output. Q/K output |
| 1235 | contains normalized K widened from BF16 and normalized Q widened from |
| 1236 | BF16 then scaled in FP32. Decay and beta are inputs here, not substituted |
| 1237 | constants or claimed fused gate computations. Old/new states must be |
| 1238 | distinct; the old state is immutable, and the caller swaps the pointers |
| 1239 | after the completed launch. |
| 1240 | |
| 1241 | For normalization, each lane squares x[lane] and x[lane+64], rounding |
| 1242 | each product to BF16 before widening. It adds those two in FP32, then |
| 1243 | executes snapshot XOR adds with shifts 32,16,8,4,2,1. The result is |
| 1244 | rounded to BF16. The epsilon scalar is first converted to BF16, as |
| 1245 | the BF16 tensor operation does; the sum with epsilon is rounded to |
| 1246 | BF16. V_RSQ_F32's manual interval is rounded to BF16, and each x*inverse |
| 1247 | product is rounded to BF16. Query heads alone then multiply by FP32 |
| 1248 | `0x3db504f3`. This constant is checked by the recorded Python query |
| 1249 | `round32(Fraction(Decimal(1)/Decimal(128).sqrt()))` at precision 120; |
| 1250 | the assertion lives in `gdn.py`. BF16 conversion is RN-even with |
| 1251 | canonical NaNs, using the same existing instruction sequence as conv4. |
| 1252 | |
| 1253 | For recurrence, value head `3*group_y+group_x` uses key head `group_y`. |
| 1254 | Each lane handles columns lane and lane+64. All operations below round |
| 1255 | separately to FP32; there is no implicit contraction into FMA: |
| 1256 | `decayed = old * decay`; `kv = sum(decayed[row] * k[row])`; |
| 1257 | `delta = (v - kv) * beta`; `new = decayed + k * delta`; |
| 1258 | `output = sum(new[row] * q[row])`. Both sums start at +0 and add rows |
| 1259 | in ascending order 0 through 127. New state remains FP32. Core output |
| 1260 | is rounded to BF16 and widened, matching the reference's final cast. |
| 1261 | The reference library may use another reduction tree; we state this |
| 1262 | kernel's order rather than claiming its library reductions are bit-equal. |
| 1263 | |
| 1264 | No new instruction is introduced. The gate still compares every |
| 1265 | instruction word and descriptor to LLVM's oracle, runs the all-object |
| 1266 | scheduling check, and checks two builds for byte identity. `gdn.py` |
| 1267 | checks every state/output bit (or the RSQ-derived interval for Q/K), |
| 1268 | all unchanged input bytes and guards, and over-dispatch in X and Y. |
| 1269 | Controls change scale, epsilon, upper-half contributions, BF16 |
| 1270 | normalization rounding, decay, beta, key-head selection, row stride, |
| 1271 | and BF16 core rounding. The full gate summary derives both new case |
| 1272 | counts from the test module, retaining all prior counts. |
| 1273 | |
| 1274 | `torch_gdn_probe.py` is an optional, CPU-only independent verification |
| 1275 | instrument, not a build/production dependency. The isolated reference |
| 1276 | is torch 2.9.0+cpu. It checks the fallback's BF16 operation dtypes and |
| 1277 | epsilon scalar conversion over every positive finite BF16 encoding. |
| 1278 | The ARM CPU BF16 `rsqrt` is not the numerical oracle: for input bits |
| 1279 | `0x425e0000`, it returns `0x3e0a0000`, whereas a precision-120 Decimal |
| 1280 | square root, independently rounded to BF16, gives `0x3e090000`. The CPU |
| 1281 | answer lies outside the CDNA3 RSQ one-ULP interval after BF16 conversion. |
| 1282 | The probe asserts that disagreement rather than widening the interval. |
| 1283 | For a second normalization reference, it substitutes only the FP64 |
| 1284 | `rsqrt` primitive rounded to BF16; all other operations retain Torch's |
| 1285 | BF16 boundaries. It also compares every recurrent state/output bit using |
| 1286 | independent Torch operations in the explicitly declared reduction order. |
| 1287 | This is not a claim of bit parity with unmodified CPU Torch. The notebook |
| 1288 | timing reference retains Torch's own primitives/reduction tree and is |
| 1289 | labelled AMD-library work, not Omega. |
| 1290 | |
| 1291 | The compact notebook sections generate all fixtures and oracle outputs |
| 1292 | in-cell and pass the same fresh-namespace dependency check as section 18. |
| 1293 | Hardware execution and performance qualification remain NOT_RUN until |
| 1294 | the device notebook actually runs these objects. |
| 1295 | |
| 1296 | ## 22. Remaining decode kernels and bounded access instruments |
| 1297 | |
| 1298 | The seeded objects in this section use the same explicit FP32-word ABI |
| 1299 | as the preceding kernels. BF16 boundary values are exactly widened; |
| 1300 | packed BF16 occurs only in the embedding input and attention KV cache. |
| 1301 | The implementation source is the `.isa` instruction table. Companion |
| 1302 | `.s` files are independently assembled by LLVM 18 solely as byte/descriptor |
| 1303 | oracles. Neither Python nor LLVM is a production kernel dependency. |
| 1304 | |
| 1305 | `gdnparams` consumes per-value-head a, b, A_log, and dt_bias. It rounds a/b |
| 1306 | to BF16, computes sigmoid(b), rounds beta to BF16, and emits FP32 |
| 1307 | `exp(-exp(A_log)*softplus(a+dt_bias))` for the recurrent decay. Softplus |
| 1308 | uses the stable positive/negative split with the Torch threshold at 20. |
| 1309 | For small t, `log1p(t)` is evaluated as |
| 1310 | `log(1+t)*t/((1+t)-1)` using explicitly rounded operations; when `1+t` |
| 1311 | rounds to one it returns t. This avoids both cancellation and overflow. |
| 1312 | All transcendental operations retain the documented CDNA3 intervals. |
| 1313 | |
| 1314 | The added executor `V_LOG_F32` implementation computes log2 using a |
| 1315 | native binary64 mantissa reduction and odd atanh series. `log.py` checks |
| 1316 | it against a precision-120 Decimal logarithm and the ISA one-ULP |
| 1317 | enclosure; opcode special cases have independent exact-bit tests. |
| 1318 | An identity-instead-of-log control must fail. |
| 1319 | |
| 1320 | `gdnrmsgate` consumes BF16-rounded core/weight values widened to FP32, |
| 1321 | and rounds the FP32 projection z to BF16 before evaluating swish. |
| 1322 | Its RMS variance is FP32 with the documented wave-XOR sum, epsilon |
| 1323 | 1e-6, normalization rounded to BF16, weight multiplication rounded to |
| 1324 | BF16, then FP32 swish(z) and final BF16 rounding. This is the ordering |
| 1325 | of Transformers' `Qwen3_5RMSNormGated`, not a reordered fused expression. |
| 1326 | Old/new recurrent states remain separate immutable-input/output buffers. |
| 1327 | |
| 1328 | `residual5120` rounds both FP32-word operands to BF16, adds in FP32, |
| 1329 | then rounds the result to BF16. This admits the FP32 projection output |
| 1330 | without losing the model's BF16 residual-add boundary. `embed5120` |
| 1331 | loads one selected, packed BF16 embedding row and widens it. The caller |
| 1332 | must validate the token index and bind the selected row pointer |
| 1333 | `embedding_base + token*10240`; this object does not accept an entire |
| 1334 | unbounded matrix or claim to validate a host token pointer. |
| 1335 | |
| 1336 | `argmax_part` reduces all 248320 FP32 logits into 3880 (ordered key, |
| 1337 | original index) pairs. `argmax_final` consumes all pairs and emits one |
| 1338 | uint32 token. Ties, including opposite signed zeros, select the first |
| 1339 | index. NaNs outrank numeric values and the first NaN wins, matching |
| 1340 | Torch argmax's selection behavior. Ordered integer keys preserve all |
| 1341 | finite FP32 ordering without lossy arithmetic or reduction additions. |
| 1342 | |
| 1343 | `decode.py`, `gdn.py`, and `prep_section.py` construct independent |
| 1344 | Fraction/Decimal or exact-bit oracles, adversarial fixtures, in-bounds |
| 1345 | numerical controls, and compact notebook sections. Prep checks Q/K RMS |
| 1346 | normalization, exactly 64 rotated dimensions out of 256, BF16 KV append, |
| 1347 | and unchanged prior cache rows. The attention gate remains sigmoid, |
| 1348 | whereas GDN's post-norm gate is swish. Library timing is labelled |
| 1349 | separately; it never substitutes for the interval oracle. |
| 1350 | |
| 1351 | `token_access.py` is a verification instrument, not a production runtime. |
| 1352 | It builds a seeded executor with per-buffer access checks for each |
| 1353 | concrete fixture, records every buffer's largest actually touched read |
| 1354 | and write byte, and executes numerical controls under the same checks. |
| 1355 | A separately compiled short-input-bound control must exit 68. |
| 1356 | `token-access.json` records those measurements. Hardware memory safety |
| 1357 | and timing remain NOT_RUN: a functional executor is not a GPU. |
| 1358 | |
| 1359 | After the host/executor gates and optional Torch probe have written |
| 1360 | `host.log`, `exec.log`, and `torch.log` under an evidence directory, |
| 1361 | `tests/amd-exec/token_bundle.py EVIDENCE NEW_DESTINATION` generates the |
| 1362 | notebook transport bundle. It derives object hashes, source head, |
| 1363 | kernarg offsets/types, launch dimensions, exact fixture buffer lengths, |
| 1364 | measured access maxima, case errors, and caught controls from the actual |
| 1365 | tables and gate outputs. `list.json` is the machine-readable list; |
| 1366 | `list.md` and `SHA256SUMS` are generated views. An existing destination is |
| 1367 | refused so an earlier evidence bundle cannot be silently replaced. |
| 1368 | |
| 1369 | ### D16-independent embedding control |
| 1370 | |
| 1371 | `embed5120-low-bits` now inserts `V_XOR_B32 v8,1,v8` after the D16 load's |
| 1372 | `S_WAITCNT`, before its full-width store. The production destination is |
| 1373 | zero-initialized, so preservation and unused-half zeroing produce the same |
| 1374 | baseline. The control flips the settled output bit rather than relying on a |
| 1375 | nonzero prefill surviving the load. No oracle interval or expected output is |
| 1376 | changed. The previous prefill mutation belongs in the raw D16 semantics |
| 1377 | probe, not among portable numerical controls. |
| 1378 | |
| 1379 | ## 23. Device-stepped replay variants |
| 1380 | |
| 1381 | The new `*_step` objects retain their original numerical bodies. Position |
| 1382 | and token IDs are loaded through VMEM, then transferred with |
| 1383 | `V_READFIRSTLANE_B32`; they are not fetched through the scalar data cache. |
| 1384 | The CDNA3 manual physical p187 specifies the lowest active lane, or lane0 |
| 1385 | when EXEC is empty, and no flag changes. The executor accepts only the |
| 1386 | VOP1 opcode2 form with a VGPR source and an ordinary SGPR0..101 destination; |
| 1387 | special registers, scalar sources and modifiers remain refused. LLVM18 |
| 1388 | `VOP1Instructions.td` provides the independent encoding oracle. |
| 1389 | `semantics.py` covers empty, sparse, high-bit and full masks, unchanged |
| 1390 | registers/flags, invalid operands and a forced-lane-zero control. |
| 1391 | |
| 1392 | CDNA3 physical p29's dependency table requires two wait states between a |
| 1393 | VALU SGPR write and a VALU constant read. Explicit `S_NOP 1` barriers follow |
| 1394 | the transfers in these variants. The functional executor does not model |
| 1395 | pipeline timing; `readfirst_probe` supplies a separate physical-card check. |
| 1396 | `tests/amd/scheduling.py` statically checks every emitted object for this |
| 1397 | row on v_readlane/v_readfirstlane writes (VALU constant read 2 wait |
| 1398 | states, v_readlane/v_writelane lane select 4, VMEM read 5), along |
| 1399 | fall-through and branch paths, and requires a real `readfirst_probe` mutant |
| 1400 | with its `S_NOP 1` removed to fail, plus hand-written row controls for each |
| 1401 | case. SALU reads have no Table11 entry, so the `S_NOP 1` before an SALU-only |
| 1402 | consumer is not required by the manual and its removal is not a failure. |
| 1403 | SGPR writes by v_cmp or carry-out are not audited by this check. |
| 1404 | |
| 1405 | `attn256_prep_step` selects one256-byte cos32/sin32 row from a precomputed |
| 1406 | FP32 table. Part and merge derive T=position+1 and retain their active |
| 1407 | tile-count workspace stride. The part launch can use the fixed capacity |
| 1408 | grid: extra tiles return and merge never reads them. Conv and GDN state |
| 1409 | arguments are fixed banks A/B: even positions read A/write B, odd positions |
| 1410 | read B/write A. Use these variants from position0, or normalize bank |
| 1411 | orientation before capture. `embed5120_step` selects the row from the |
| 1412 | device token written by `argmax_final`. `step_advance` updates the single |
| 1413 | u32 position once, after all layers and argmax, and refuses wrap/exhaustion |
| 1414 | at the caller's physical cache capacity. |
| 1415 | |
| 1416 | Capture does not execute. Keep every argument buffer and RoPE row alive, |
| 1417 | use one ordered stream, and issue no more replays than available cache |
| 1418 | positions. No host parameter changes, table copies or state-pointer swaps |
| 1419 | belong inside replay. `tests/amd-exec/replay.py` records bit-exact |
| 1420 | consecutive-step comparisons with the original kernels, exact kernarg and |
| 1421 | per-buffer access bounds, and caught stale-value/wrong-bank/truncated-buffer |
| 1422 | controls. `replay_bundle.py EVIDENCE DEST GOLDEN CONFIG` derives the capacity |
| 1423 | and vocabulary from those pinned inputs and exports objects, ABI, access |
| 1424 | records and the readfirst card probe. Card execution remains a separate receipt. |
| 1425 | |
| 1426 | ## Kernel/main integration |
| 1427 | |
| 1428 | The kernel line and the reviewed main executor/KFD chain are combined without |
| 1429 | changing the target-specific D16 profile or promoting host evidence to hardware |
| 1430 | qualification. Nested wave, validation and grid loops coexist with the extended |
| 1431 | instruction subset. The SMEM bit-20 refusal uses the manual's explicit ambiguity, |
| 1432 | not an assertion that all immediate offsets are signed. Unsupported-instruction |
| 1433 | controls use S_CBRANCH_VCCZ because S_NOP is now supported. |
| 1434 | |
| 1435 | Acceptance is regenerated by `tests/amd/run.sh`, `tests/amd-kfd/run.sh`, |
| 1436 | `tests/amd-exec/run.sh`, and the private-output instruments `fp8block.py`, |
| 1437 | `fp8block_fast.py`, and `gdnstate_w.py` in `tests/amd-exec`. Their output directories |
| 1438 | contain the actual commands, hashes, control outcomes and generated summaries; |
| 1439 | the NumPy dependency is an external test oracle, not product code. |
| 1440 | Integration evidence is filed beside the integration clone as |
| 1441 | `kmain-gates-<shortHEAD>/SUMMARY`, with a fresh-clone `suite2.sh` run using the |
| 1442 | integration clone as its source. The conflict decisions are in |
| 1443 | `kmain-resolution.md` beside the clone. Existing receipts remain historical |
| 1444 | evidence for their named revisions; this integration does not rewrite them or |
| 1445 | claim fresh device execution, serving throughput, review, landing or deployment. |
| 1446 | |
| 1447 | ## Seeded direct-KFD gfx942 launcher |
| 1448 | |
| 1449 | `backend/amd/kfd/launch/` is the direct syscall path. Its `COMPILER` pin names |
| 1450 | the seeded omega-mv compiler with checked KFD words. The Linux UAPI layout |
| 1451 | oracle compares installed `linux/kfd_ioctl.h` to `backend/amd/kfd/requests.tsv`; |
| 1452 | the executable does not link that oracle, libc, ROCr, HIP, or a Python runtime. |
| 1453 | The acceptance gate's ptrace simulation never opens a real GPU pathname. |
| 1454 | |
| 1455 | For the FP8 prerequisite, the named upstream source is Linux **v6.18**, not a |
| 1456 | claim about an uninspected ROCm 7.2.2 driver: |
| 1457 | - [register_process, kfd_device_queue_manager.c](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c?h=v6.18), |
| 1458 | lines 1404–1441, calls the ASIC's `update_qpd` at line 1429. |
| 1459 | - [update_qpd_v9, kfd_device_queue_manager_v9.c](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager_v9.c?h=v6.18) |
| 1460 | initializes `sh_mem_config` (alignment/retry and F8_MODE for GC 9.4.3/9.4.4) |
| 1461 | and `sh_mem_bases` (LDS/scratch apertures), clearing the alternate aperture. |
| 1462 | SET_MEMORY_POLICY changes cache policy; it is not required to initialize these |
| 1463 | bases. The launcher therefore does not request that extra ioctl. It does not |
| 1464 | enable debugger RUNTIME_ENABLE either. |
| 1465 | - The AMD Instinct MI300 CDNA3 ISA manual, physical PDF p60 (local extracted |
| 1466 | `AMD_Instinct_MI300_CDNA3_ISA.txt`, lines 3104–3105), requires |
| 1467 | SH_MEM_CONFIG bit 8 to be set for correct BF8/FP8 results. Source inspection |
| 1468 | explains the intended driver default; device output remains the required test. |
| 1469 | |
| 1470 | Queue-context sizing and MI300 AQL's zero EOP allocation follow |
| 1471 | [ROCT-Thunk-Interface rocm-6.2.0, src/queues.c](https://github.com/ROCm/ROCT-Thunk-Interface/blob/rocm-6.2.0/src/queues.c) |
| 1472 | and its `hsakmttypes.h` context-save header. Dimensions come from the selected |
| 1473 | topology node. The coherent USER signal layout follows |
| 1474 | [ROCR-Runtime rocm-6.2.0, src/inc/amd_hsa_signal.h](https://github.com/ROCm/ROCR-Runtime/blob/rocm-6.2.0/src/inc/amd_hsa_signal.h): |
| 1475 | kind at offset zero, value at offset eight. These pinned sources are references, |
| 1476 | not runtime dependencies, and no ROCm 7.2.2 driver-source equivalence is claimed. |
| 1477 | |
| 1478 | The launcher publishes the AQL body before its valid header, then write pointer |
| 1479 | and doorbell, with fences and system-scope packet semantics. A native |
| 1480 | instruction-step test observes ordering, and an early-header mutant must fail. |
| 1481 | The generic CLI ring-wrap and missing-completion controls exercise repeats and |
| 1482 | timeout, separately from the GPU. |
| 1483 | |
| 1484 | The notebook is an external Python-standard-library measuring instrument. |
| 1485 | Its rational scalar oracle checks the finite fixture calculations against the |
| 1486 | fmaf wave64-lane reference. `libm.so.6` supplies only that independent reference. |
| 1487 | Optional `libamdhip64` is a labelled AMD_LIBRARY comparison, never a fallback |
| 1488 | for the Omega path; the cell records its actual runtime version. QEMU, the host |
| 1489 | C compiler and ptrace are test instruments only. Exact object source commits, |
| 1490 | digests, compiler pin, cell and binary hashes come from the bundle generator. |
| 1491 | The correct attention-merge digest is an explicit integration input; the |
| 1492 | silicon-wrong predecessor is rejected rather than silently substituted. |
| 1493 | |
| 1494 | Hardware qualification is scoped by executable and fixture. The direct queue |
| 1495 | results below establish selected kernels, mappings and completion. Register |
| 1496 | state, full Qwen 27B serving, attention through this launcher and a like-for-like |
| 1497 | Spark comparison remain outside those kernel checks. |
| 1498 | |
| 1499 | ### Direct queue layout and executable AQL ring |
| 1500 | |
| 1501 | The queue layout follows AMD ROCr's named release sources, also checked against |
| 1502 | ROCm 7.2.2 during the device investigation: |
| 1503 | - [amd_hsa_queue.h, rocm-6.2.0](https://raw.githubusercontent.com/ROCm/ROCR-Runtime/rocm-6.2.0/src/inc/amd_hsa_queue.h) places write_dispatch_id at 56, read_dispatch_id at 128, the read-pointer base offset at 136, queue_properties at 180 and queue_inactive_signal at 192. IS_PTR64 is bit 1. |
| 1504 | - [amd_aql_queue.cpp, rocm-6.2.0](https://raw.githubusercontent.com/ROCm/ROCR-Runtime/rocm-6.2.0/src/core/runtime/amd_aql_queue.cpp) initializes the full queue, aperture high words and CU/wave limits, and passes the dispatch-ID addresses to KFD. |
| 1505 | - [Linux KFD UAPI](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/kfd_ioctl.h?h=v6.18) defines GET_PROCESS_APERTURES_NEW and executable GPU allocation permission. Runtime apertures are selected by the actual GPU ID; they are not hard-coded from one card. |
| 1506 | |
| 1507 | The launcher now owns the full zeroed queue object, an inactive USER signal, and |
| 1508 | an executable GTT ring. The compiler-owned AMD queue-object binding places the dispatch pointers at |
| 1509 | bytes 56 and 128 within that same live queue map. Caller address fields stay |
| 1510 | zero, and the compiler checks the complete 2304-byte amd_queue_v2_t ABI object extent. The CPU oracle checks every queue byte and allocation |
| 1511 | permission before CREATE_QUEUE and rejects wrong pointer mode, a dirty tail, |
| 1512 | missing execute permission and malformed aperture results. The loader still |
| 1513 | refuses queue-pointer SGPR and private-scratch requirements outside its trusted |
| 1514 | kernel subset. |
| 1515 | |
| 1516 | MI300X diagnostic controls established that neither the old minimal queue with |
| 1517 | execute permission nor the full queue without execute permission completed. |
| 1518 | The latter produced a memory-fault event at the ring VA. The combined production |
| 1519 | fix then passed uninstrumented vadd, 200-packet ring wrap, fsum16, SGEMM and FP8 |
| 1520 | GEMV with exact fixture outputs, executable SHA-256 |
| 1521 | `fd85139a4ea58a892a74b910c6432038feb5edbe41c6e4f118357cc57f30aa60`. |
| 1522 | These kernel results do not qualify a complete model-serving path. Earlier |
| 1523 | failed diagnostic receipts remain separate evidence and are not overwritten. |
| 1524 | |
| 1525 | The descriptor requirement bit is defined by the pinned LLVM llvmorg-19.1.7 |
| 1526 | [AMDHSAKernelDescriptor.h](https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-19.1.7/llvm/include/llvm/Support/AMDHSAKernelDescriptor.h), |
| 1527 | `KERNEL_CODE_PROPERTY(ENABLE_SGPR_QUEUE_PTR, 2, 1)`. This is a format reference, |
| 1528 | not a production compiler dependency. The loader trusts the first-party writer's |
| 1529 | explicit kernarg ABI; it does not interpret hidden-argument metadata from arbitrary |
| 1530 | third-party code objects. In particular, rejecting the queue-pointer SGPR bit |
| 1531 | is not a general proof that an unknown kernel never consumes a queue pointer. |
| 1532 | |
| 1533 | ### Dynamic KFD process aperture inventory |
| 1534 | |
| 1535 | The native launcher uses the count-query form of |
| 1536 | [Linux v6.18 kfd_ioctl_get_process_apertures_new](https://raw.githubusercontent.com/torvalds/linux/v6.18/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c): |
| 1537 | zero num_of_nodes returns the process inventory size; a nonzero request copies at |
| 1538 | most that many 56-byte records. A full reply does not prove completeness. The |
| 1539 | launcher allocates checked owned memory with a spare slot and grows on full |
| 1540 | replies. The compiler supplies the owned mapping address, while caller pointer |
| 1541 | bytes remain zero. Host oracle cases exercise inventories beyond the former |
| 1542 | 64-record buffer, growth between query and fill, malformed counts and duplicate |
| 1543 | selected GPU IDs. This changes discovery, not the card-tested dispatch kernels. |
| 1544 | |
| 1545 | ### Launcher packet fields, topology mapping and caller deadlines |
| 1546 | |
| 1547 | The existing backend/amd/kfd/aql.om restates the published HSA dispatch layout |
| 1548 | from [ROCr rocm-6.2.0 hsa.h](https://raw.githubusercontent.com/ROCm/ROCR-Runtime/rocm-6.2.0/src/inc/hsa.h): |
| 1549 | packet private bytes 24..27 and group bytes 28..31. AMD code descriptors use the |
| 1550 | opposite group/private order at bytes 0 and 4. The launcher translates that |
| 1551 | order in both writers; nonzero-LDS ELF fixtures and a byte comparison with the |
| 1552 | existing AQL encoder detect either swapped writer. |
| 1553 | |
| 1554 | [ROCT rocm-6.2.0 topology.c](https://raw.githubusercontent.com/ROCm/ROCT-Thunk-Interface/rocm-6.2.0/src/topology.c) |
| 1555 | maps array_count to a temporary SIMD-array count and simd_arrays_per_engine to |
| 1556 | NumArrays, then assigns NumShaderBanks from their quotient. |
| 1557 | Pinned statement anchors are in |
| 1558 | `tests/amd-kfd-launch/reference/sources.json`; the gate derives and verifies the |
| 1559 | raw-file ranges shown in reference/README.md. The existing queues.c wave formula subsequently divides |
| 1560 | NumShaderBanks by NumArrays. Both divisions in the native sysfs formula are |
| 1561 | required. The array-bound-dominant fixture and missing-division mutant exercise it. |
| 1562 | |
| 1563 | A caller chooses a deadline through the generic argument manifest or a trailing |
| 1564 | plan/vadd CLI argument. Zero/default is unlimited. The ten-second threshold |
| 1565 | produces an alarm, not a cap. No new model-plan field or wire version was needed. |
| 1566 | |
| 1567 | The same conversion was also checked in the environment-matched |
| 1568 | [ROCm 7.2.2 topology.c](https://raw.githubusercontent.com/ROCm/rocm-systems/rocm-7.2.2/projects/rocr-runtime/libhsakmt/src/topology.c), |
| 1569 | with its statement anchors and digest in the same canonical reference manifest. |
| 1570 | Derived line numbers refer to the downloaded source, not a web reader's extracted |
| 1571 | line numbering. |
| 1572 | |
| 1573 | ## Launcher review-round-2 corrective checks |
| 1574 | |
| 1575 | The independent RCCA is retained with the release receipt. Corrective actions |
| 1576 | live in the launcher gate and REVIEW-LESSONS.md: the batch publication unit uses |
| 1577 | plantemplate, both packet writers compare private20/group4096 against aql.om, |
| 1578 | nonzero-private ELF is explicitly refused, alarm absence/re-arming have mutation |
| 1579 | controls, and every malformed-plan refusal has a fresh valid twin plus a specific |
| 1580 | reason line. Upstream topology/queue/kernel producer files are retained unchanged |
| 1581 | with their original licenses and SHA256SUMS in tests/amd-kfd-launch/reference; |
| 1582 | README.md records exact URLs and raw-file line ranges. The arithmetic is unchanged. |
| 1583 | |
| 1584 | ## Final launcher hardware receipt, November 13 |
| 1585 | |
| 1586 | `evidence/amd-qwen38-native-final-20261113/` qualifies launcher source |
| 1587 | 0c1bed70e87466375dfc7aab7e0169a68f8f4e5f and x86 executable |
| 1588 | 373e76cd29edab8d92d5e05d7d351474083c0937ed239d1f2e4521431cf187a4. |
| 1589 | Normal/nonzero-LDS vadd and original coding24 pass; warmup plus five longer |
| 1590 | requests match all256 IDs of the previously measured independent AMD HIP graph. |
| 1591 | Five decode medians:26.58,26.493,26.55,26.602,26.624 ms; median26.58 ms/token, |
| 1592 | 37.6223 reciprocal median-step tokens/s. Historical Spark graph time125.4 ms/token |
| 1593 | implies4.7178x graph decode ratio. Median prefill776.861 ms is slower than saved |
| 1594 | Spark507 ms. No fresh Spark run, startup-ratio claim,256-token bitwise Spark |
| 1595 | parity, model-quality equivalence or HTTP service is implied. Raw data, code |
| 1596 | identity, numerical limits, units and reproducible calculations are retained. |
| 1597 | |
| 1598 | Launcher CA6 close-out adds nine missing semantic-plan rows and an explicit |
| 1599 | word-width helper boundary. The shared CLI unsigned parser now emits distinct |
| 1600 | machine-readable reason lines on its existing exit2 paths; valid parsing and |
| 1601 | numeric bounds are unchanged. Every deadline refusal has a valid zero twin. |
| 1602 | These diagnostic-source changes produce a new executable and require a new |
| 1603 | hardware receipt; the earlier373e receipt remains an immutable historical run. |
| 1604 | |
| 1605 | Shared-CLI compatibility correction: numeric refusal diagnostics use a local fixed |
| 1606 | record and stderr, retaining exit2 and empty binary-output stdout. The existing |
| 1607 | full-write helper now accepts an fd internally; emit preserves its stdout API. |
| 1608 | The original2c824 seed KFD suite and the26540 launcher gate passed their |
| 1609 | compatibility checks; exact counts are in the corresponding gate summaries. |
| 1610 | Requalification of the new executable is required. |
| 1611 | |
| 1612 | ## Compatible launcher hardware receipt |
| 1613 | |
| 1614 | The historical compatible receipt is evidence/amd-qwen38-native-compatible-20261113. It qualifies |
| 1615 | committed launcher source230a57b618ac62ceb628518507321762a1aaa5cd and executable |
| 1616 | f646ea5d16d545b5c9c6efcab74d1e9a522de2d9dd3a06e4638a3eb2f6b9c504, |
| 1617 | with normal/nonzero-LDS vadd, original coding24/control, and warmup plus five |
| 1618 | accepted lighthouse256 runs. All256 IDs agree with the reused independent AMD |
| 1619 | HIP graph. Five medians26.726,26.783,26.765,26.718,26.717 ms give26.726 ms/token, |
| 1620 | 37.4167 reciprocal median-step tokens/s and4.6921x the dated125.4 ms Spark graph |
| 1621 | baseline. AMD median prefill781.661 ms is slower than saved Spark507 ms. |
| 1622 | Earlier receipts remain immutable. No fresh Spark run or full Spark token parity, |
| 1623 | startup speed ratio, quality equivalence or HTTP deployment is claimed. |
| 1624 | |
| 1625 | The native launcher refuses scratch-enable, private-segment-buffer, flat-scratch |
| 1626 | initializer, private-segment-size SGPR and dynamic-stack descriptor requests even |
| 1627 | when private_segment_fixed_size is zero. The queue has no scratch backing. Bit |
| 1628 | positions are pinned in tests/amd-kfd-launch/reference/sources.json from ROCm |
| 1629 | 7.2.2 AMDHSAKernelDescriptor.h; fresh ELF inspect twins cover each independently |
| 1630 | on both host targets. This admission change requires a separate exact-binary |
| 1631 | card receipt; the latest qualification below supplies it. |
| 1632 | |
| 1633 | Launcher object refusals now include a machine-readable field ID on stderr, |
| 1634 | preserving exit65 and empty payload stdout. The IDs distinguish existing guard |
| 1635 | sites in common.om and elf.om. Inspect mutation rows assert their exact reason; |
| 1636 | manifest magic and ring-limit rows assert their own distinct diagnostic. This |
| 1637 | is diagnostic observability, with unchanged valid object parsing. The latest |
| 1638 | qualification below records the changed executable; older receipts remain dated |
| 1639 | proof for their recorded binary only. |
| 1640 | |
| 1641 | ## Scratch-refusal launcher hardware qualification |
| 1642 | |
| 1643 | The latest hardware qualification is |
| 1644 | [evidence/amd-qwen38-native-refusal-20261113](evidence/amd-qwen38-native-refusal-20261113/README.md). |
| 1645 | It records the exact committed source, compiler, executable and model identities |
| 1646 | for the scratch-admission and precise-refusal update. Normal/nonzero-LDS vector |
| 1647 | checks, the original coding reference and corrupted-weight comparison, and a |
| 1648 | warmup plus five longer requests all completed. Every accepted longer request |
| 1649 | matches the reused independent AMD graph. The receipt owns the raw records and |
| 1650 | recomputed metrics, including the dated Spark comparison and its limits. |
| 1651 | Release checks, independent review and forge landing remain separate stages. |