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/benchmarks-mv/blob/main/prime-drag-race/evidence/2026-10-05-campaign/astra/astra.patch # benchmarks-mv Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `benchmarks-mv / prime-drag-race / evidence / 2026-10-05-campaign / astra / astra.patch` 257 lines ยท 13577 bytes Raw Blame History 1 diff --git a/bench/prime_race/tests/gb10_sieve_host_test.c b/bench/prime_race/tests/gb10_sieve_host_test.c 2 index `1be5d3b`..`cf82a60` 100644 3 --- a/bench/prime_race/tests/gb10_sieve_host_test.c 4 +++ b/bench/prime_race/tests/gb10_sieve_host_test.c 5 @@ -235,6 +235,132 @@ static int sb_hazards(const BlackwellIRProgram *p, int verbose) { 6 return bad; 7 } 8 9 +/* Fixed RAW checks use ENCODED delays, allocated registers and both successors 10 + * of conditional branches, including back-edges. No credit is taken for extra 11 + * scoreboard/memory delays. This covers the scalar ALU/FMA and predicate classes 12 + * changed by the emitter; wide producers and variable latency remain the job 13 + * of the existing schedule and scoreboard checker. 14 + * Independent reference: NAK sm100/reg_raw.csv (reader rows, writer columns) 15 + * plus sm120_instr_latencies.rs's +1. ALU/dual-ALU -> ALU/dual-ALU and FMA -> 16 + * FMA are 5, mixed and address consumers at most 6 for these producers. 17 + * ISETP -> guard is 14 via sm70.rs paw_latency, NOT the 5-cycle ISETP operand 18 + * predicate latency. WAW/WAR for these scalar classes are <= 2, below our floor. 19 + */ 20 +static int latency_class(BlackwellIROpcode op) { 21 + switch (op) { 22 + case BW_IR_ISETP_GE_U32: case BW_IR_ISETP_GE: case BW_IR_FSETP: return 3; 23 + case BW_IR_IMAD: case BW_IR_IMAD_HI_U32: 24 + case BW_IR_FADD: case BW_IR_FSUB: case BW_IR_FMUL: case BW_IR_FFMA: return 2; 25 + case BW_IR_MOV_IMM: case BW_IR_MOV_RZ: case BW_IR_IADD3: 26 + case BW_IR_LOP3_LUT: case BW_IR_LOP3_XOR: 27 + case BW_IR_SHF_R: case BW_IR_SHF_L_U32: return 1; 28 + default: return 0; 29 + } 30 +} 31 + 32 +static uint32_t encoded_control(const OmegaBlackwellKernel *k, size_t i) { 33 + uint32_t c; 34 + memcpy(&c, k->code + i * 16 + 12, sizeof c); 35 + return c; 36 +} 37 + 38 +static int reg_contains(const BlackwellIRProgram *p, int v, unsigned sub, int phys) { 39 + if (v < 0) return 0; 40 + int first = p->regalloc.vreg_to_phys[v] + (int)sub; 41 + /* Conservatively count the rest of a bundle as read/written. The changed 42 + * producers are scalar; this includes both halves of address consumers. */ 43 + return phys >= first && phys < p->regalloc.vreg_to_phys[v] + 44 + (int)p->regalloc.intervals[v].bundle_size; 45 +} 46 + 47 +static int relax_successors(const BlackwellIRProgram *p, size_t i, unsigned a, 48 + unsigned *age) { 49 + const BlackwellIRInsn *in = &p->insns[i]; 50 + int next[2], n = 0, changed = 0; 51 + if (in->op == BW_IR_BRA) next[n++] = (int)i + (int32_t)in->imm; 52 + if ((in->op != BW_IR_BRA && in->op != BW_IR_EXIT) || in->predicate_p0) 53 + next[n++] = (int)i + 1; 54 + for (int s = 0; s < n; s++) { 55 + if (next[s] < 0 || (size_t)next[s] >= p->count) return -1; 56 + if (a < age[next[s]]) { age[next[s]] = a; changed = 1; } 57 + } 58 + return changed; 59 +} 60 + 61 +static int fixed_hazards(const BlackwellIRProgram *p, const OmegaBlackwellKernel *k) { 62 + /* The encoder pads short programs to 32 instructions. */ 63 + if (p->count > BW_MAX_IR_INSNS || k->code_size < p->count * 16) return 1; 64 + int bad = 0; 65 + for (size_t w = 0; w < p->count; w++) { 66 + const BlackwellIRInsn *writer = &p->insns[w]; 67 + int cls = latency_class(writer->op), pred = cls == 3; 68 + if (!cls || (!pred && (writer->dst_vreg < 0 || writer->is_uniform))) continue; 69 + int phys = pred ? -1 : p->regalloc.vreg_to_phys[writer->dst_vreg] + writer->dst_subreg; 70 + unsigned age[BW_MAX_IR_INSNS], bound = pred ? 14 : 6; 71 + for (size_t i = 0; i < p->count; i++) age[i] = 255; 72 + unsigned delay = (encoded_control(k, w) >> 9) & 15u; 73 + if (delay == 0) { bad++; continue; } /* zero-delay/co-issue is outside this model */ 74 + if (relax_successors(p, w, delay, age) < 0) return 1; 75 + int changed; 76 + do { 77 + changed = 0; 78 + for (size_t i = 0; i < p->count; i++) { 79 + if (age[i] >= bound) continue; 80 + const BlackwellIRInsn *in = &p->insns[i]; 81 + int kills = pred ? latency_class(in->op) == 3 : 82 + (!in->is_uniform && reg_contains(p, in->dst_vreg, in->dst_subreg, phys)); 83 + if (kills && !in->predicate_p0) continue; 84 + unsigned d = (encoded_control(k, i) >> 9) & 15u; 85 + int r = relax_successors(p, i, age[i] + d, age); 86 + if (r < 0) return 1; 87 + changed |= r; 88 + } 89 + } while (changed); 90 + for (size_t i = 0; i < p->count; i++) { 91 + if (age[i] >= bound) continue; 92 + const BlackwellIRInsn *in = &p->insns[i]; 93 + int reads = pred ? (in->predicate_p0 || in->op == BW_IR_FSEL) : 94 + (reg_contains(p, in->src1_vreg, in->src1_subreg, phys) || 95 + reg_contains(p, in->src2_vreg, in->src2_subreg, phys) || 96 + reg_contains(p, in->src3_vreg, in->src3_subreg, phys)); 97 + int reader_cls = latency_class(in->op); 98 + unsigned need = pred ? 14 : 99 + ((cls == 2 && reader_cls == 2) || 100 + (cls == 1 && (reader_cls == 1 || reader_cls == 3)) ? 5 : 6); 101 + if (reads && age[i] < need) bad++; 102 + } 103 + } 104 + return bad; 105 +} 106 + 107 +static void fixed_schedule_check(const BlackwellIRProgram *p, const OmegaBlackwellKernel *k) { 108 + int hz = fixed_hazards(p, k); 109 + CHECK(hz == 0, "encoded fixed RAW hazards: %d", hz); 110 + OmegaBlackwellKernel bad = *k; 111 + bad.code = malloc(k->code_size); 112 + CHECK(bad.code != NULL, "fixed schedule negative-control allocation"); 113 + if (!bad.code) return; 114 + int shortened_alu = 0, shortened_pred = 0, alu_hz = 0, pred_hz = 0; 115 + for (size_t i = 0; i < p->count; i++) { 116 + uint32_t c = encoded_control(k, i); 117 + int cls = latency_class(p->insns[i].op); 118 + if ((!shortened_alu && cls > 0 && cls < 3 && ((c >> 9) & 15u) == 5) || 119 + (!shortened_pred && cls == 3)) { 120 + memcpy(bad.code, k->code, k->code_size); 121 + uint32_t short_c = (c & ~(15u << 9)) | ((cls == 3 ? 13u : 4u) << 9); 122 + memcpy(bad.code + i * 16 + 12, &short_c, sizeof short_c); 123 + int h = fixed_hazards(p, &bad); 124 + if (h > hz) { 125 + if (cls == 3) { shortened_pred = 1; pred_hz = h; } 126 + else { shortened_alu = 1; alu_hz = h; } 127 + } 128 + } 129 + } 130 + CHECK(shortened_alu && shortened_pred, "fixed RAW checker missed a short ALU/predicate delay"); 131 + printf("fixed RAW: %d hazards; negative controls ALU=4: %d, predicate=13: %d\n", hz, alu_hz, pred_hz); 132 + free(bad.code); 133 +} 134 + 135 /* ------------------------------------------------------------- nvdisasm */ 136 /* every word decodes, the new ops appear, and every BRA lands where the IR says */ 137 static const char *const MUST_GLOBAL[] = { "LOP3.LUT", "SHF.L.U32", "IMAD.HI.U32", "@P0 BRA", "@!P0 BRA", "@P0 EXIT", "STG.E", "LDG.E" }; 138 @@ -335,6 +461,22 @@ int main(int argc, char **argv) { 139 int fx = omega_blackwell_verify_codegen_fixtures_intops(); 140 CHECK(fx == 0, "golden words LOP3_LUT / SHF_L_U32 / IMAD_HI_U32 (rc %d)", fx); 141 142 + /* The scheduling pass is shared by every elementwise family. This is 143 + * codegen only: no public launcher or device session is called. */ 144 + for (int op = OMEGA_GPU_EW_EX2; op <= OMEGA_GPU_EW_PRIME_SIEVE_SHARED; op++) { 145 + for (int mutant = 0; mutant <= 1; mutant++) { 146 + BlackwellIRProgram *p = calloc(1, sizeof *p); 147 + OmegaBlackwellKernel code = {0}; 148 + int rc = p ? omega_gpu_elementwise_codegen_ir((OmegaGpuEwOp)op, mutant, p, &code) : -1; 149 + CHECK(rc == OMEGA_GPU_EW_OK, "schedule codegen op %d mutant %d rc %d", op, mutant, rc); 150 + if (rc == OMEGA_GPU_EW_OK) { 151 + CHECK(sb_hazards(p, 0) == 0, "schedule scoreboard op %d mutant %d", op, mutant); 152 + CHECK(fixed_hazards(p, &code) == 0, "schedule fixed RAW op %d mutant %d", op, mutant); 153 + } 154 + free(code.code); free(p); 155 + } 156 + } 157 + 158 /* 2. oracle self-check against pi(x) */ 159 static const struct { uint64_t x, pi; } pis[] = { {10, 4}, {100, 25}, {1000, 168}, {10000, 1229}, {100000, 9592}, {`1000000`, 78498} }; 160 for (size_t i = 0; i < sizeof pis / sizeof pis[0]; i++) { 161 @@ -357,6 +499,7 @@ int main(int argc, char **argv) { 162 CHECK(k.gpr_count <= 64, "GPR budget %u > 64", k.gpr_count); 163 CHECK(memcmp(k.code_digest, mk.code_digest, 32) != 0, "mutant kernel differs from production"); 164 nvdisasm_check(&k, prog, MUST_GLOBAL, "global table"); 165 + fixed_schedule_check(prog, &k); 166 { 167 int hz = sb_hazards(prog, 1); 168 CHECK(hz == 0, "scoreboard hazards in the sieve kernel: %d", hz); 169 @@ -445,6 +588,7 @@ int main(int argc, char **argv) { 170 printf("\n"); 171 CHECK(sk.gpr_count <= 64, "staged GPR budget %u > 64", sk.gpr_count); 172 nvdisasm_check(&sk, sp, MUST_STAGED, "staged"); 173 + fixed_schedule_check(sp, &sk); 174 int hz = sb_hazards(sp, 1); 175 CHECK(hz == 0, "scoreboard hazards in the staged kernel: %d", hz); 176 int sfail = 0, sn = 0; 177 diff --git a/src/omega_gpu_elementwise_api.c b/src/omega_gpu_elementwise_api.c 178 index `34dd61f`..`ad807c1` 100644 179 --- a/src/omega_gpu_elementwise_api.c 180 +++ b/src/omega_gpu_elementwise_api.c 181 @@ -11,11 +11,11 @@ 182 * a scoreboard; the producer stalls >= 2 and the consumer waits on that SB; 183 * - a fixed-latency result (FADD FMUL FFMA IMAD IADD3 MOV LOP3 SHF) has no 184 * scoreboard: the producer stalls >= 5 before its consumer (we use 6); 185 - * - a predicate producer (ISETP) stalls 13 before @P0 use (the codegen default); 186 + * - a predicate producer (ISETP) stalls 14 before @P0 use (NAK SM120 padding); 187 * - stores (STG, STS) set a read barrier so the next instruction cannot overwrite 188 * the source register early. 189 * The emitter below serialises: every instruction waits on everything still 190 - * pending. Slow and safe; speed is a later cut. 191 + * pending. A final local pass tightens supported adjacent ALU pairs to 5 cycles. 192 */ 193 #include "omega_gpu_elementwise_api.h" 194 #include "omega_blackwell_codegen.h" 195 @@ -55,7 +55,7 @@ static void emit(Em *e, BlackwellIRInsn in, int kind) { 196 uint32_t wait = e->pending; 197 switch (kind) { 198 case K_FIXED: in.control = CW(6, SB_NONE, SB_NONE, wait); e->pending = 0; break; 199 - case K_PRED: in.control = CW(13, SB_NONE, SB_NONE, wait); e->pending = 0; break; 200 + case K_PRED: in.control = CW(14, SB_NONE, SB_NONE, wait); e->pending = 0; break; 201 case K_VAR: in.control = CW(4, SB_GPR, SB_NONE, wait) | CW_YIELD; e->pending = 1u << SB_GPR; break; 202 case K_UVAR: in.control = CW(4, SB_UGPR, SB_NONE, wait) | CW_YIELD; e->pending = 1u << SB_UGPR; break; 203 case K_STORE: in.control = CW(4, SB_NONE, SB_RD, wait) | CW_YIELD; e->pending = 1u << SB_RD; break; 204 @@ -495,6 +495,45 @@ static int check_loop_invariant(const Em *e) { 205 206 #define EW_GPR_BUDGET 64u /* the QMD declares 64 registers, as the matmul launcher does */ 207 208 +/* Mesa NAK sm120_instr_latencies.rs + sm100/reg_raw.csv: ALU/dual-ALU pairs 209 + * and FMA/FMA pairs need 4 + 1 cycles; mixed pairs need 5 + 1. CSV rows are 210 + * READERS, columns WRITERS (see lat_rs_gen.py), not the reverse. IMAD.WIDE 211 + * has operand-specific latencies and is deliberately excluded here. 212 + * 213 + * Retain at least 5 cycles after every fixed producer. Thus the next reader 214 + * uses the pair-specific bound and later readers are >= 9 cycles away (the 215 + * next instruction in a tightened pair is itself fixed). No instruction, 216 + * branch target, wait, barrier assignment or register allocation is changed. 217 + * IADD3's encoder still supplies its historical control word; do not pretend 218 + * to schedule that producer here. Its existing 5-cycle delay is unchanged. 219 + * 220 + * Predicate-to-guard uses NAK paw_latency -> raw(write, None): reader 221 + * RedirectedFp64, writer Dualalu = 13, plus SM120's 1 = 14, in emit above. 222 + * NVIDIA's public ISA docs are silent about SASS control-word semantics. 223 + */ 224 +static int fixed_pair_class(BlackwellIROpcode op) { 225 + switch (op) { 226 + case BW_IR_MOV_RZ: case BW_IR_MOV_IMM: case BW_IR_IADD3: 227 + case BW_IR_LOP3_XOR: case BW_IR_LOP3_LUT: 228 + case BW_IR_SHF_R: case BW_IR_SHF_L_U32: return 1; 229 + case BW_IR_IMAD: case BW_IR_IMAD_HI_U32: 230 + case BW_IR_FADD: case BW_IR_FSUB: case BW_IR_FMUL: case BW_IR_FFMA: return 2; 231 + default: return 0; 232 + } 233 +} 234 + 235 +static void schedule_fixed_pairs(BlackwellIRProgram *p) { 236 + for (size_t i = 0; i + 1 < p->count; i++) { 237 + BlackwellIRInsn *a = &p->insns[i]; 238 + const BlackwellIRInsn *b = &p->insns[i + 1]; 239 + int cls = fixed_pair_class(a->op); 240 + if (!cls || cls != fixed_pair_class(b->op) || a->op == BW_IR_IADD3 || 241 + a->predicate_p0 || b->predicate_p0 || ((a->control >> 9) & 15u) != 6) 242 + continue; 243 + a->control = (a->control & ~(15u << 9)) | (5u << 9); 244 + } 245 +} 246 + 247 static int build_kernel(OmegaGpuEwOp op, int mutant, OmegaBlackwellKernel *kernel, BlackwellIRProgram *prog_out) { 248 BlackwellIRProgram *prog = calloc(1, sizeof *prog); 249 if (!prog) return OMEGA_GPU_EW_CODEGEN_FAIL; 250 @@ -510,6 +549,7 @@ static int build_kernel(OmegaGpuEwOp op, int mutant, OmegaBlackwellKernel *kerne 251 case OMEGA_GPU_EW_PRIME_SIEVE_SHARED: gen_prime_sieve(&e, mutant, 1); break; 252 default: e.err = -1; break; 253 } 254 + schedule_fixed_pairs(prog); 255 int rc = OMEGA_GPU_EW_CODEGEN_FAIL; 256 int ra_rc = (e.err == 0) ? omega_bw_regalloc_solve(prog) : -1; 257 int loop_rc = (ra_rc == 0) ? check_loop_invariant(&e) : -1;