interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / docs / SM121_INSTRUCTION_SPEC.md

163 lines · 9927 bytes Raw Blame History Source

Authoritative SM121 Instruction Specification Format

This document specifies the authoritative single instruction-field table format implemented in om/encoder/bw_spec_sm121.om, following Drake's three-layer architecture (Meaning -> Realization -> Encoding) described in the Omega/encoder direction.

Overview

In Blackwell (SM121 / GB10), instructions are represented as 128-bit words (four 32-bit little-endian words w[0..3]).

Instead of writing imperative bit-shifting procedures for encoding and separate pattern-matching tables for decoding, both operations are derived from one authoritative specification table in native .om.

The binary64 register forms (IR 68..78) are implemented in the seeded bw_enc_sm121.om codegen encoder, not this older table's 0..62 catalog. See Binary64 BlackwellIR register forms for their independently derived encoding facts, simulator precision contract and chip runbook.

The specification defines:

  1. Instruction Form Identification:
    • op: Blackwell IR opcode (0..62).
    • var: Variant selector when multiple forms share an opcode (e.g., IMAD_RRR vs IMAD_RRU vs IMAD_RRI).
    • Fixed bits and masks for words w[0..2].
    • Default control word w[3].
    • Field count nf (number of parameterized fields in the instruction).
  2. Parameterized Fields:
    • role: Field semantic role (dest register, source register, predicate, immediate).
    • word: Word index (0, 1, or 2) in the 128-bit instruction.
    • shift: Bit position within the 32-bit word.
    • width: Bit width of the field.
    • is_s: Signedness (1 for signed two's complement, 0 for unsigned).
    • min_v: Minimum valid value (bounds check).
    • max_v: Maximum valid value (bounds check).

Field Roles

The following integer constants represent semantic field roles in bw_spec_sm121.om:

Role IDConstantMeaningSource in IR (o[])Bounds Check
0R_NONEUnused slotN/ANone
1R_RDDestination GPR (0..255)o[1]0 <= v <= 255
2R_RASource 1 GPR (0..255)o[2]0 <= v <= 255
3R_RBSource 2 GPR (0..255)o[3]0 <= v <= 255
4R_RCSource 3 GPR (0..255)o[4]0 <= v <= 255
5R_URDDestination Uniform Reg (0..31)o[1]0 <= v <= 31
6R_URASource 1 Uniform Reg (0..31)o[2]0 <= v <= 31
7R_URBSource 2 Uniform Reg (0..31)o[5] or o[1]0 <= v <= 31
8R_PRED4-bit Guard Predicatepred(o)0 <= v <= 7 (or 8)
9R_IMM3232-bit Immediateo[6]Full 32-bit range
10R_OFF24Signed 24-bit byte offseto[6]-8388608 <= v <= 8388607
11R_IMM1616-bit Immediateo[6]0 <= v <= 65535
12R_BARBarrier registero[11]Declared form bounds
13R_BSSYRelative instruction deltao[6]Declared bounds and exact representability of (v - 1) * 16
14R_BRABranch deltao[6]Unsigned 32-bit IR representation
15R_LDCConstant-bank offseto[6]Declared bounds and exact alignment/field representation
16R_SHFLShuffle immediateo[6]Raw value, no masking before validation
17R_LUTLOP3 LUTo[6]Raw value, no masking before validation
18R_S2RSpecial-register indexo[6]Declared form bounds
19R_LDSWShared-memory offseto[6]Declared form bounds and exact representation
20R_FSETFSETP comparison encodingo[6]Declared form bounds; zero selects the default encoding
21R_PRED3Predicate destination/sourceo[1] or o[4]Raw value, no masking before validation

Specification Table Representation

The reusable module is function-mode Omega: no global pools and no main. The owner allocates a zero-filled fixed-size ulong 3001 workspace once per encoding batch and passes it explicitly. Slots 0..2999 retain the authoritative flat specification table; slot 3000 is the initialization marker, written only after every table initializer completes. sp_init is idempotent for that owner. sp_enc and sp_dec initialize on first use, including a cold decoder call.

The workspace is private process state, not an authenticated input format. Do not accept it from a caller or serialized artifact, mutate it after initialization, or race/share it across concurrent owners. Reuse it within one batch rather than rebuilding the table for every instruction. Fixed-size array parameters occupy one seeded argument slot. Initialization setters use at most six arguments.

Public signatures are sp_init(state edit ulong 3001), sp_enc(state edit ulong 3001, o view ulong 16, w edit ulong 4) -> ulong, and sp_dec(state edit ulong 3001, w view ulong 4, o edit ulong 16) -> ulong. Emit words only after E_OK: a failed encoder call may have already written partial output. A native adapter must store these validated words directly, including padding NOPs, rather than re-encode through the reference oracle.

Standalone assertions now live in om/encoder/bw_spec_test.om; concatenate that driver after the reusable module for executable mode. No source stripping or second encoder table is needed. The original audit source remains frozen at CUDApp 85c059cc15edf704c9833fe4832f18c052ee83b3 (draft PR #160).

Each instruction form header occupies 10 slots:

Following the header, each of the nf fields occupies 7 slots:

Total slots per form is 10 + 5 * 7 = 45. For 63 forms, the table uses 63 * 45 = 2835 slots.

Error Refusal Codes

The encoder refuses invalid input with explicit error codes instead of truncating or wrapping:

Dual Derivation

  1. sp_enc state o w -> err:
    • Matches o to an instruction form.
    • Sets fixed word bits w0_fix..w2_fix and control word w3.
    • Validates the raw semantic operand before inserting masked bits.
    • Checks special-layout immediates by decoding their inserted representation and requiring exact equality.
  2. sp_dec state w o -> err:
    • Initializes its owner-private table automatically, including standalone cold calls.
    • Searches sp_tbl for a form whose fixed bits match: (w[k] & mask) == fix.
    • Extracts each field: val = (w[word] >> shift) & mask.
    • Populates decoded IR array o[].
  3. Host verification:
    • Compares every active semantic role after decoding, not just the opcode. Inactive IR packing slots are not operands.
    • Canonicalizations are explicit: absent source operands for LOP3/SHF/IMAD.HI mean RZ; zero control selects the form default; zero FSETP immediate selects its default encoding.
    • IMAD RRU has a GPR destination and a uniform second source. Corpus generation verifies that each intended form actually dispatches.
    • Boundary fixtures select representable aligned immediates; separate audit regressions require refusal of raw lossy values.
    • sh tools/test_bw_spec_encoder.sh checks reference bytes, active operands, cold decode, malformed streams and the operands printed by an independent decoder: Omega's own sm_121 disassembler (SM121DIS, make test-om-spec-encoder) by default, or NVIDIA's offline nvdisasm with SPEC_ENCODER_ORACLE=nvdisasm (make test-om-spec-encoder-nvdisasm-oracle). Producer failure, truncated records and read errors fail closed.
    • All checks are host-only. Physical qualification of the changed encoder remains NOT_RUN until an authorized chip run. Frozen historical receipts are unchanged.

Function-mode host regression

OMEGA_BRIDGE=/path/to/omega-bridge sh tools/test_bw_spec_encoder.sh also compiles the reusable module plus bw_spec_native.om as function bytes and executes the generated bridge binding through the existing C oracle driver. The semantic assertions remain in Omega. They cover cold decoder initialization, private workspace isolation, warmed-table mutation without accidental reinit, full RRU destination/source semantics, a deliberately corrupted expected operand (return 1), and actual raw SHFL refusal (return E_RANGE, 2). Build, bridge, compiler-pin, ELF-image and binding-status failures are not semantic mutant kills.

The exact compiler remains omega-mv e5b32567a7aff3ce594e3254a622a846a6cd190b, SHA-256 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f. The unchanged bridge source src/native.om is pinned by SHA-256 c77a5922f91d53d4a0bbd4e7b1c4703f7098263abc843be2918db1ece7496782. This command proves a host function binding, not physical GPU qualification or the downstream bc_encode consumer; that consumer requires its own native runtime fixture at its exact integrated source pin. Physical qualification is NOT_RUN. Historical audit and device receipts are not rewritten.

The native probe executes AArch64 function bytes, so it runs only with an AArch64 C target. Elsewhere the script prints NOT_RUN for it and exits 3, unless BW_SPEC_NATIVE_PROBE_NOT_RUN_OK=1 accepts that row as NOT_RUN; make test-om-spec-encoder sets it on non-AArch64 hosts only.