sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / gpu / cuda-crack / isa / README.md
| 1 | # isa/: sm_121 (GB10) encoding tables |
| 2 | |
| 3 | `sm121-forms.txt` is generated by `gen/run.sh`: the Omega program `gen/isa.om` is compiled together with my Omega encoder `gen/bw_enc_sm121.om` (CUDApp `b774723f`, sha256 `fe16b024c3242d12c7c8ef759d84c34a22c7d21cba676cd987f4f3a1ff56ba86`) by the pinned omc (sha256 `3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194`). Two runs give the same file, sha256 `587d81e2bc8b3dc6fdb48d477a76b717300732ccdb984f05f5b3df658e58e2d7`. |
| 4 | |
| 5 | ## How the tables are derived |
| 6 | |
| 7 | For every IR op 0..63 and every selector (which operands are present, uniform flag, guard predicate), the generator encodes one base instruction, then flips one input bit at a time: each bit of the destination and three source register numbers, the uniform register, the 32-bit immediate and the barrier register. It compares the 96 instruction bits of words 0..2. Word 3 is the scheduling control word and is kept whole. |
| 8 | |
| 9 | - Bits that never move are the form's **fixed bits**: opcode, modifiers, and RZ (255) in absent register slots. |
| 10 | - Bits that move belong to an **operand field**. |
| 11 | - Identical forms are listed once. Op 255 is the NOP the encoder pads programs with. |
| 12 | |
| 13 | ## Format |
| 14 | |
| 15 | All numbers are decimal. Words are 32-bit, little-endian in memory; bit `n` of the 128-bit instruction is bit `n mod 32` of word `n / 32`. |
| 16 | |
| 17 | ``` |
| 18 | F id op sel fix0 fix1 fix2 msk0 msk1 msk2 ctl |
| 19 | D id field m0 m1 m2 start width |
| 20 | ``` |
| 21 | |
| 22 | - `F` is one instruction form. `op` is the CUDApp BlackwellIR opcode number (the op list is `src/omega_blackwell_codegen.c` and `om/encoder/bw_enc_sm121.om` in CUDApp). `fix0..2` are the fixed bits, `msk0..2` mark the operand-field bits, and `ctl` is the default control word. |
| 23 | - `sel` bits: 0 destination, 1 source 1, 2 source 2, 3 source 3, 4 uniform register present; 5 uniform; 6 guard `@P0`; 7 guard negated. |
| 24 | - `D` is one operand field of form `id`. `field`: 0 destination, 1 source 1, 2 source 2, 3 source 3, 4 uniform register, 5 immediate, 6 barrier register. `m0..m2` are its bit mask. |
| 25 | - `start` is the instruction bit that input bit 0 lands on. `width` is how many input bits map one-to-one onto consecutive bits from there. `width` 0 means the field is not a plain bit copy: for example a branch offset stored as `imm - 1`, a 24-bit signed offset, or a sign extension. |
| 26 | |
| 27 | An instruction belongs to a form when its bits outside the form's mask equal the form's fixed bits. |
| 28 | |
| 29 | ## Check |
| 30 | |
| 31 | `check/check.sh` checks the table in two stages. |
| 32 | |
| 33 | **1. The D records are checked against the F records.** For each form: |
| 34 | - its operand fields never overlap; |
| 35 | - the union of its field masks is exactly the form's mask; |
| 36 | - every field with `width` > 0 covers exactly the bits from `start` to `start + width - 1`. |
| 37 | |
| 38 | The table has 859 D records: 845 have `width` > 0 and 14 have `width` 0. |
| 39 | |
| 40 | **2. The 70 kernels that ran on the GB10 (E2/E3) are rebuilt from this file alone.** For each instruction, the check finds the first form that explains it, then writes three things: the form's fixed bits, the instruction's operand-field bits and its control word. All 70 rebuilt kernels match the sha256 list recorded on the chip run (`kernels-om.sha256`). |
| 41 | |
| 42 | There are four negative controls, and each must fail: |
| 43 | - Flipping one fixed bit in the table makes 67 kernels differ. |
| 44 | - Flipping one opcode bit in a kernel makes that instruction match no form. |
| 45 | - Reducing one field's `width` by one fails stage 1. |
| 46 | - Clearing one bit of one field's mask fails stage 1. |
| 47 | |
| 48 | The output is in `check/CHECK.txt`. |
| 49 | |
| 50 | **What the check proves:** |
| 51 | - Every bit of all 13,520 chip-run instructions is either a fixed bit of a listed form or inside one of that form's operand fields. |
| 52 | - The D records partition each form's operand bits exactly. |
| 53 | - Each linear field's `start` and `width` match its mask. |
| 54 | |
| 55 | **What it does not prove:** how the 14 `width` 0 fields transform their input, for example a branch offset or a sign extension. That transform lives in the encoder source (`gen/bw_enc_sm121.om`). Regenerating the table (`gen/run.sh && git diff --exit-code isa/`) shows that the whole file, D records included, is what the encoder produces. |
| 56 | |
| 57 | ## Known limit |
| 58 | |
| 59 | The encoder honours guard predicates only on BRA, EXIT, BAR and one store. So `sel` bits 6 and 7 change the encoding only for ops 22, 45, 46, 54 and 55. The tables reflect the encoder as it is; they do not add predicates it does not emit. |