Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/src/omega_numeric_provenance.c # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / src / omega_numeric_provenance.c` 246 lines ยท 14542 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "omega_numeric_provenance.h" 18 #include "omega_numeric.h" 19 #include "omega_blackwell_encoder.h" 20 21 #include 22 #include 23 24 #define ORACLE "nvdisasm 13.0.88 -b SM121 decode of these words (2026-09-30); " \ 25 "scoreboard pattern from ptxas 13.0.88 sm_121; GB10 parity: receipt only" 26 #define ORACLE_E1 "nvdisasm 13.0.88 -b SM121 decode of these words (2026-09-30, E1 WP-C); " \ 27 "scoreboard pattern from ptxas 13.0.88 sm_121; GB10 parity: receipt only" 28 29 static const OmegaOpcodeProvenance PROVENANCE_TABLE[] = { 30 { "FADD", "FADD R9, R2, R5", 0x7221, "FP32 add, RNE, subnormals kept", ORACLE, 31 0x02097221, 0x00000005, 0x00000000, false }, 32 { "FSUB", "FADD R9, R2, -R5", 0x7221, "FP32 subtract (FADD, src2 negate bit 63)", ORACLE, 33 0x02097221, 0x80000005, 0x00000000, false }, 34 { "FMUL", "FMUL R9, R2, R5", 0x7220, "FP32 multiply, RNE, subnormals kept", ORACLE, 35 0x02097220, 0x00000005, 0x00400000, false }, 36 { "FFMA", "FFMA R9, R2, R5, R1", 0x7223, "FP32 fused multiply-add, c in R1", ORACLE, 37 0x02097223, 0x00000005, 0x00000001, false }, 38 { "FSETP_GE_R2_R5", "FSETP.GE.AND P0, PT, R2, R5, PT", 0x720b, 39 "ordered >= (false on NaN); the earlier 0x03f0e000 form decodes as GEU", ORACLE, 40 0x0200720b, 0x00000005, 0x03f06000, false }, 41 { "FSEL_R2_R5_P0", "FSEL R9, R2, R5, P0", 0x7208, "select a if P0 else b", ORACLE, 42 0x02097208, 0x00000005, 0x00000000, false }, 43 { "FSETP_GE_R2_RZ", "FSETP.GE.AND P0, PT, R2, RZ, PT", 0x720b, "ordered a >= +0", ORACLE, 44 0x0200720b, 0x000000ff, 0x03f06000, false }, 45 { "FSEL_R5_R2_P0", "FSEL R9, R5, R2, P0", 0x7208, "select b if P0 else a", ORACLE, 46 0x05097208, 0x00000002, 0x00000000, false }, 47 { "FMNMX_MIN", "FMNMX R9, R2, R5, PT", 0x7209, "FP32 minimum", ORACLE, 48 0x02097209, 0x00000005, 0x03800000, false }, 49 { "FMNMX_MAX", "FMNMX R9, R2, R5, !PT", 0x7209, "FP32 maximum", ORACLE, 50 0x02097209, 0x00000005, 0x07800000, false }, 51 { "I2FP", "I2FP.F32.S32 R9, R2", 0x7245, "int32 to FP32, RNE", ORACLE, 52 0x00097245, 0x00000002, 0x00201400, false }, 53 { "F2I", "F2I.TRUNC.NTZ R9, R2", 0x7305, "FP32 to int32, truncate", ORACLE, 54 0x00097305, 0x00000002, 0x0020f100, true }, 55 { "MUFU_RCP", "MUFU.RCP R9, R2", 0x7308, "reciprocal seed (never bit-compared)", ORACLE, 56 0x00097308, 0x00000002, 0x00001000, true }, 57 { "MUFU_RSQ", "MUFU.RSQ R9, R2", 0x7308, "reciprocal square root seed (never bit-compared)", ORACLE, 58 0x00097308, 0x00000002, 0x00001400, true }, 59 { "SHFL_DOWN_1", "SHFL.DOWN PT, R9, R2, 0x1, 0x1f", 0x7f89, "warp shuffle down by one lane", ORACLE, 60 0x02097f89, 0x08201f00, 0x000e0000, true }, 61 { "SHFL_DOWN_16", "SHFL.DOWN PT, R9, R2, 0x10, 0x1f", 0x7f89, "declared-order reduction step 1: lane i + 16", ORACLE, 62 0x02097f89, 0x0a001f00, 0x000e0000, true }, 63 { "SHFL_DOWN_8", "SHFL.DOWN PT, R9, R2, 0x8, 0x1f", 0x7f89, "declared-order reduction step 2: lane i + 8", ORACLE, 64 0x02097f89, 0x09001f00, 0x000e0000, true }, 65 { "SHFL_DOWN_4", "SHFL.DOWN PT, R9, R2, 0x4, 0x1f", 0x7f89, "declared-order reduction step 3: lane i + 4", ORACLE, 66 0x02097f89, 0x08801f00, 0x000e0000, true }, 67 { "SHFL_DOWN_2", "SHFL.DOWN PT, R9, R2, 0x2, 0x1f", 0x7f89, "declared-order reduction step 4: lane i + 2", ORACLE, 68 0x02097f89, 0x08401f00, 0x000e0000, true }, 69 { "FADD_R2_R2_R9", "FADD R2, R2, R9", 0x7221, "running sum += shuffled value (RNE, subnormals kept)", ORACLE, 70 0x02027221, 0x00000009, 0x00000000, false }, 71 { "FADD_R9_R2_R9", "FADD R9, R2, R9", 0x7221, "last reduction step, result into R9 for the STG", ORACLE, 72 0x02097221, 0x00000009, 0x00000000, false }, 73 { "SHF_L_R8_R0_2", "SHF.L.U32 R8, R0, 0x2, RZ", 0x7819, "shared byte offset of word tid.x (tid * 4)", ORACLE, 74 0x00087819, 0x00000002, 0x000006ff, false }, 75 { "LOP3_R10_R8_XOR_FC", "LOP3.LUT R10, R8, 0xfc, RZ, 0x3c, !PT", 0x7812, 76 "partner offset (tid ^ 63) * 4, bounded by the 64-thread CTA", ORACLE, 77 0x080a7812, 0x000000fc, 0x078e3cff, false }, 78 { "STS_R8_R2", "STS [R8+URZ], R2", 0x7988, 79 "32-bit shared store at raw offset R8 (NVK/NAK form; ptxas bases on SR_CgaCtaId + 0x400, " 80 "first suspect if the chip disagrees)", ORACLE, 81 0x08007988, 0x00000002, 0x080008ff, false }, 82 { "BAR_SYNC_0", "BAR.SYNC.DEFER_BLOCKING 0x0", 0x7b1d, "CTA barrier 0 between the store and the load", ORACLE, 83 0x00007b1d, 0x00000000, 0x00010000, false }, 84 { "LDS_R9_R10", "LDS R9, [R10+URZ]", 0x7984, "32-bit shared load of the partner word", ORACLE, 85 0x0a097984, 0x000000ff, 0x08000800, true }, 86 /* ---- E1 scalar contract ops (E1 WP-C) ---- */ 87 #define FSETP_ROW(key_, txt_, code_, desc_) \ 88 { key_, txt_, 0x720b, desc_, ORACLE_E1, 0x0200720b, 0x00000005, 0x03f00000u | ((code_) << 12), false } 89 FSETP_ROW("FSETP_LT_R2_R5", "FSETP.LT.AND P0, PT, R2, R5, PT", 0x1u, "ordered a < b (false on NaN)"), 90 FSETP_ROW("FSETP_EQ_R2_R5", "FSETP.EQ.AND P0, PT, R2, R5, PT", 0x2u, "ordered a == b (false on NaN)"), 91 FSETP_ROW("FSETP_LE_R2_R5", "FSETP.LE.AND P0, PT, R2, R5, PT", 0x3u, "ordered a <= b (false on NaN)"), 92 FSETP_ROW("FSETP_GT_R2_R5", "FSETP.GT.AND P0, PT, R2, R5, PT", 0x4u, "ordered a > b (false on NaN)"), 93 FSETP_ROW("FSETP_NE_R2_R5", "FSETP.NE.AND P0, PT, R2, R5, PT", 0x5u, "ordered a != b (false on NaN)"), 94 FSETP_ROW("FSETP_NUM_R2_R5", "FSETP.NUM.AND P0, PT, R2, R5, PT", 0x7u, "neither a nor b is NaN"), 95 FSETP_ROW("FSETP_NAN_R2_R5", "FSETP.NAN.AND P0, PT, R2, R5, PT", 0x8u, "a or b is NaN"), 96 FSETP_ROW("FSETP_LTU_R2_R5", "FSETP.LTU.AND P0, PT, R2, R5, PT", 0x9u, "unordered a < b (true on NaN)"), 97 FSETP_ROW("FSETP_EQU_R2_R5", "FSETP.EQU.AND P0, PT, R2, R5, PT", 0xau, "unordered a == b (true on NaN)"), 98 FSETP_ROW("FSETP_LEU_R2_R5", "FSETP.LEU.AND P0, PT, R2, R5, PT", 0xbu, "unordered a <= b (true on NaN)"), 99 FSETP_ROW("FSETP_GTU_R2_R5", "FSETP.GTU.AND P0, PT, R2, R5, PT", 0xcu, "unordered a > b (true on NaN)"), 100 FSETP_ROW("FSETP_NEU_R2_R5", "FSETP.NEU.AND P0, PT, R2, R5, PT", 0xdu, "unordered a != b (true on NaN)"), 101 FSETP_ROW("FSETP_GEU_R2_R5", "FSETP.GEU.AND P0, PT, R2, R5, PT", 0xeu, "unordered a >= b (true on NaN)"), 102 #undef FSETP_ROW 103 { "F2I_FLOOR", "F2I.FLOOR.NTZ R9, R2", 0x7305, "FP32 -> S32, round toward -inf, NaN -> 0, saturating", ORACLE_E1, 104 0x00097305, 0x00000002, 0x00207100, true }, 105 { "F2I_CEIL", "F2I.CEIL.NTZ R9, R2", 0x7305, "FP32 -> S32, round toward +inf, NaN -> 0, saturating", ORACLE_E1, 106 0x00097305, 0x00000002, 0x0020b100, true }, 107 { "F2I_RNI", "F2I.NTZ R9, R2", 0x7305, "FP32 -> S32, round to nearest even (no rounding suffix = RN)", ORACLE_E1, 108 0x00097305, 0x00000002, 0x00203100, true }, 109 { "F2U", "F2I.U32.TRUNC.NTZ R9, R2", 0x7305, "FP32 -> U32, truncate, NaN and negatives -> 0, saturating", ORACLE_E1, 110 0x00097305, 0x00000002, 0x0020f000, true }, 111 { "I2FP_U32", "I2FP.F32.U32 R9, R2", 0x7245, "U32 -> FP32, round to nearest even (fixed latency)", ORACLE_E1, 112 0x00097245, 0x00000002, 0x00201000, false }, 113 { "F2F_F16_F32", "F2F.F16.F32 R9, R2", 0x7304, 114 "FP32 -> binary16 RNE in [15:0]; [31:16] expected zero (ptxas stores it unmasked), checked by the receipt", ORACLE_E1, 115 0x00097304, 0x00000002, 0x00200800, true }, 116 { "F2F_BF16_F32", "F2F.BF16.F32 R9, R2", 0x7304, 117 "FP32 -> bfloat16 RNE in [15:0]; [31:16] expected zero (ptxas stores it unmasked), checked by the receipt", ORACLE_E1, 118 0x00097304, 0x00000002, 0x00202000, true }, 119 { "HADD2_F32_R2_H0", "HADD2.F32 R9, -RZ, R2.H0_H0", 0x7230, "binary16 [15:0] -> FP32 (-0 + h), ptxas form of cvt.f32.f16", ORACLE_E1, 120 0xff097230, 0x20000002, 0x00004100, false }, 121 { "SHF_L_R9_R2_16", "SHF.L.U32 R9, R2, 0x10, RZ", 0x7819, 122 "bfloat16 [15:0] -> FP32 by shift (ptxas form of cvt.f32.bf16); not a hardware conversion unit", ORACLE_E1, 123 0x02097819, 0x00000010, 0x000006ff, false }, 124 { "LDC64_R10_C3A0", "LDC.64 R10, c[0x0][0x3a0]", 0x7b82, "c pointer from kernel argument words 8..9", ORACLE_E1, 125 0xff0a7b82, 0x0000e800, 0x00000a00, true }, 126 { "IMAD_WIDE_R10_R9_4", "IMAD.WIDE.U32 R10, R9, 0x4, R10", 0x7825, "&c[i] = c + index * 4", ORACLE_E1, 127 0x090a7825, 0x00000004, 0x078e000a, false }, 128 { "LDG_R11_R10", "LDG.E R11, desc[UR4][R10.64]", 0x7981, "32-bit global load of c[i]", ORACLE_E1, 129 0x0a0b7981, 0x00000004, 0x0c1e1900, true }, 130 { "FFMA_R9_R2_R5_R11", "FFMA R9, R2, R5, R11", 0x7223, "FP32 fused multiply-add, c[i] per element", ORACLE_E1, 131 0x02097223, 0x00000005, 0x0000000b, false }, 132 }; 133 134 #define PROVENANCE_COUNT (sizeof(PROVENANCE_TABLE) / sizeof(PROVENANCE_TABLE[0])) 135 136 size_t omega_numeric_get_opcode_count(void) { return PROVENANCE_COUNT; } 137 138 const OmegaOpcodeProvenance *omega_numeric_get_opcode(size_t index) { 139 return index < PROVENANCE_COUNT ? &PROVENANCE_TABLE[index] : NULL; 140 } 141 142 static unsigned ctrl_wbar(uint32_t w3) { return (w3 >> 14) & 7u; } 143 static unsigned ctrl_wait(uint32_t w3) { return (w3 >> 20) & 0x3fu; } 144 145 #define LOAD_BARRIER_MASK (1u << 4) /* both LDG.E of the vecadd baseline set SB4 */ 146 147 int omega_numeric_verify_fixture_table(const OmegaOpcodeProvenance *table, size_t n, bool verbose) { 148 int problems = 0; 149 #define PROBLEM(...) do { problems++; if (verbose) { fprintf(stderr, "provenance: " __VA_ARGS__); fputc('\n', stderr); } } while (0) 150 if (!table || n == 0 || n > 64) { 151 PROBLEM("empty or oversized table"); 152 return problems; 153 } 154 bool used[64] = { false }; 155 156 for (size_t i = 0; i < n; i++) { 157 const OmegaOpcodeProvenance *p = &table[i]; 158 if (!p->key || !p->mnemonic || !p->description || !p->evidence_source || p->opcode == 0) { 159 PROBLEM("entry %zu incomplete", i); 160 continue; 161 } 162 if (p->opcode != (p->fixture_w0 & 0xffffu)) PROBLEM("%s: opcode 0x%04x != w0 low half", p->key, p->opcode); 163 for (size_t j = 0; j < i; j++) { 164 if (table[j].key && strcmp(table[j].key, p->key) == 0) PROBLEM("%s: duplicate key", p->key); 165 } 166 } 167 168 uint8_t base[0x200]; 169 size_t base_len = 0; 170 if (omega_blackwell_encode_vecadd(base, sizeof(base), &base_len) != 0 || base_len < 0x140) { 171 PROBLEM("vecadd baseline could not be encoded"); 172 return problems; 173 } 174 uint32_t stg[4], ex[4]; 175 memcpy(stg, base + 0x120, 16); 176 memcpy(ex, base + 0x130, 16); 177 178 for (size_t k = 0; k < omega_numeric_op_count(); k++) { 179 const OmegaNumericOpInfo *info = omega_numeric_op_at(k); 180 OmegaNumericPatchInsn patch[OMEGA_NUMERIC_PATCH_MAX]; 181 int m = omega_numeric_patch_words(info->op, patch); 182 if (omega_numeric_op_whole_kernel(info->op)) { 183 /* DIV/SQRT: whole-program kernels (src/omega_numeric_divsqrt_gb10.c, 184 * own structural check + nvdisasm digest); no vecadd patch. */ 185 if (m != OMEGA_NUMERIC_ERR_NOT_ENCODED) PROBLEM("%s: whole-program op has patch words", info->name); 186 continue; 187 } 188 if (!info->gb10_encoded) { 189 if (m != OMEGA_NUMERIC_ERR_NOT_ENCODED) PROBLEM("%s: not encoded but has patch words", info->name); 190 continue; 191 } 192 if (m <= 0) { 193 PROBLEM("%s: encoded but no patch words", info->name); 194 continue; 195 } 196 if (!(ctrl_wait(patch[0].w[3]) & LOAD_BARRIER_MASK)) 197 PROBLEM("%s: first instruction does not wait on the load barrier SB4", info->name); 198 int pending_bar = -1; 199 for (int t = 0; t < m; t++) { 200 const OmegaNumericPatchInsn *w = &patch[t]; 201 if (pending_bar >= 0) { 202 if (!(ctrl_wait(w->w[3]) & (1u << pending_bar))) 203 PROBLEM("%s: instruction %d does not wait on SB%d set by the variable-latency op before it", 204 info->name, t, pending_bar); 205 pending_bar = -1; 206 } 207 if (!w->provenance_key) { 208 bool is_stg = w->w[0] == stg[0] && w->w[1] == stg[1] && w->w[2] == stg[2]; 209 bool is_exit = w->w[0] == ex[0] && w->w[1] == ex[1] && w->w[2] == ex[2]; 210 if (!is_stg && !is_exit) PROBLEM("%s: unkeyed word %d is neither baseline STG nor EXIT", info->name, t); 211 continue; 212 } 213 const OmegaOpcodeProvenance *p = NULL; 214 for (size_t i = 0; i < n; i++) { 215 if (table[i].key && strcmp(table[i].key, w->provenance_key) == 0) { p = &table[i]; used[i] = true; } 216 } 217 if (!p) { 218 PROBLEM("%s: no provenance entry for %s", info->name, w->provenance_key); 219 continue; 220 } 221 if (p->fixture_w0 != w->w[0] || p->fixture_w1 != w->w[1] || p->fixture_w2 != w->w[2]) 222 PROBLEM("%s: executor words for %s differ from the provenance fixture", info->name, p->key); 223 if (p->variable_latency) { 224 unsigned bar = ctrl_wbar(w->w[3]); 225 if (bar > 5) PROBLEM("%s: variable-latency %s sets no write barrier", info->name, p->key); 226 else pending_bar = (int)bar; 227 } 228 } 229 if (pending_bar >= 0) { 230 /* Single-instruction patch: the baseline STG at 0x120 follows. */ 231 if (m == 1 && !(ctrl_wait(stg[3]) & (1u << pending_bar))) 232 PROBLEM("%s: baseline STG does not wait on SB%d", info->name, pending_bar); 233 else if (m != 1) 234 PROBLEM("%s: variable-latency result never waited on", info->name); 235 } 236 } 237 for (size_t i = 0; i < n; i++) { 238 if (!used[i]) PROBLEM("%s: entry not submitted by any encoded op", table[i].key ? table[i].key : "?"); 239 } 240 #undef PROBLEM 241 return problems; 242 } 243 244 int omega_numeric_verify_all_fixtures(void) { 245 return omega_numeric_verify_fixture_table(PROVENANCE_TABLE, PROVENANCE_COUNT, true); 246 }