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 / evidence / 2026-11-06-codegen-base / oracle-base.gcov

4058 lines · 256716 bytes Raw Blame History
1 -: 0:Source:src/omega_blackwell_codegen.c
2 -: 0:Graph:~/work/cudastack/lanes/CodegenBaseOm/build/codegen-base-om/oracle_base.gcno
3 -: 0:Data:~/work/cudastack/lanes/CodegenBaseOm/build/codegen-base-om/oracle_base.gcda
4 -: 0:Runs:1
5 -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
6 -: 2:#include "omega_blackwell_codegen.h"
7 -: 3:#include "omega_blackwell_submit.h"
8 -: 4:#include "sha256.h"
9 -: 5:#include "omega_path_check.h"
10 -: 6:#include <string.h>
11 -: 7:#include "cudapp_native.h"
12 -: 8:#include "omega_bw_bind.h"
13 -: 9:/* The seeded allocator and matmul builders run through portable generated C (om/units.sh), which still uses
14 -: 10: * hosted trap handling; the freestanding build keeps the migration-pending C, as the encoder does below. */
15 -: 11:#if defined(OMEGA_GPU_NO_POSIX) || defined(CUDAPP_MIGRATION_PENDING_C_REGALLOC)
16 -: 12:#define BW_RA_C_PRIMARY 1
17 -: 13:#endif
18 -: 14:#if defined(OMEGA_GPU_NO_POSIX) || defined(CUDAPP_MIGRATION_PENDING_C_CODEGEN_MATMUL)
19 -: 15:#define BW_MATMUL_C_PRIMARY 1
20 -: 16:#endif
21 -: 17:#include "omega_gpu_om_ir.h"
22 -: 18:#include "omega_bw_fields.h"
23 -: 19:/* native v1 P07 cut A.2 (aienos#286, docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md): with OMEGA_GPU_NO_POSIX this file
24 -: 20: * builds -ffreestanding. Code generation then runs only through the allocation-free entry points
25 -: 21: * (omega_blackwell_kernel_encode_into: the caller supplies the code buffer and its capacity); the allocating
26 -: 22: * generators, their diagnostics and the printing variation self-test exist only in the hosted build. */
27 -: 23:#ifndef OMEGA_GPU_NO_POSIX
28 -: 24:#include <fcntl.h>
29 -: 25:#include <stdio.h>
30 -: 26:#include <stdlib.h>
31 -: 27:#include <unistd.h>
32 -: 28:#define BW_DIAG(...) fprintf(stderr, __VA_ARGS__)
33 -: 29:#else
34 -: 30:#define BW_DIAG(...) ((void)0)
35 -: 31:#endif
36 -: 32:
37function legacy_omega_bw_ir_init called 572 returned 100% blocks executed 75%
38 572: 33:void omega_bw_ir_init(BlackwellIRProgram *prog) {
39 572*: 34: if (!prog) return;
40branch 0 taken 0 (fallthrough)
41branch 1 taken 572
42 572: 35: memset(prog, 0, sizeof(*prog));
43 -: 36:}
44 -: 37:
45 -: 38:#ifdef BW_RA_C_PRIMARY
46 -: 39:int omega_bw_ir_alloc_vreg(BlackwellIRProgram *prog) {
47 -: 40: if (!prog || prog->regalloc.num_vregs >= BW_MAX_VREGS) return -1;
48 -: 41: int v = prog->regalloc.num_vregs++;
49 -: 42: prog->regalloc.intervals[v].vreg = v;
50 -: 43: prog->regalloc.intervals[v].first_def = -1;
51 -: 44: prog->regalloc.intervals[v].last_use = -1;
52 -: 45: prog->regalloc.intervals[v].phys_reg = -1;
53 -: 46: prog->regalloc.intervals[v].bundle_size = 1;
54 -: 47: prog->regalloc.intervals[v].is_pair = false;
55 -: 48: prog->regalloc.intervals[v].is_quad = false;
56 -: 49: prog->regalloc.intervals[v].active = false;
57 -: 50: prog->regalloc.vreg_to_phys[v] = -1;
58 -: 51: return v;
59 -: 52:}
60 -: 53:
61 -: 54:int omega_bw_ir_alloc_vreg64(BlackwellIRProgram *prog) {
62 -: 55: if (!prog || prog->regalloc.num_vregs >= BW_MAX_VREGS) return -1;
63 -: 56: int v = prog->regalloc.num_vregs++;
64 -: 57: prog->regalloc.intervals[v].vreg = v;
65 -: 58: prog->regalloc.intervals[v].first_def = -1;
66 -: 59: prog->regalloc.intervals[v].last_use = -1;
67 -: 60: prog->regalloc.intervals[v].phys_reg = -1;
68 -: 61: prog->regalloc.intervals[v].bundle_size = 2;
69 -: 62: prog->regalloc.intervals[v].is_pair = true;
70 -: 63: prog->regalloc.intervals[v].is_quad = false;
71 -: 64: prog->regalloc.intervals[v].active = false;
72 -: 65: prog->regalloc.vreg_to_phys[v] = -1;
73 -: 66: return v;
74 -: 67:}
75 -: 68:
76 -: 69:int omega_bw_ir_alloc_vreg128(BlackwellIRProgram *prog) {
77 -: 70: if (!prog || prog->regalloc.num_vregs >= BW_MAX_VREGS) return -1;
78 -: 71: int v = prog->regalloc.num_vregs++;
79 -: 72: prog->regalloc.intervals[v].vreg = v;
80 -: 73: prog->regalloc.intervals[v].first_def = -1;
81 -: 74: prog->regalloc.intervals[v].last_use = -1;
82 -: 75: prog->regalloc.intervals[v].phys_reg = -1;
83 -: 76: prog->regalloc.intervals[v].bundle_size = 4;
84 -: 77: prog->regalloc.intervals[v].is_pair = false;
85 -: 78: prog->regalloc.intervals[v].is_quad = true;
86 -: 79: prog->regalloc.intervals[v].active = false;
87 -: 80: prog->regalloc.vreg_to_phys[v] = -1;
88 -: 81: return v;
89 -: 82:}
90 -: 83:
91 -: 84:int omega_bw_ir_alloc_uvreg(BlackwellIRProgram *prog) {
92 -: 85: if (!prog || prog->regalloc.num_uvregs >= BW_MAX_UVREGS) return -1;
93 -: 86: int uv = prog->regalloc.num_uvregs++;
94 -: 87: prog->regalloc.uintervals[uv].vreg = uv;
95 -: 88: prog->regalloc.uintervals[uv].first_def = -1;
96 -: 89: prog->regalloc.uintervals[uv].last_use = -1;
97 -: 90: prog->regalloc.uintervals[uv].phys_reg = -1;
98 -: 91: prog->regalloc.uintervals[uv].is_pair = false;
99 -: 92: prog->regalloc.uintervals[uv].active = false;
100 -: 93: prog->regalloc.uvreg_to_phys[uv] = -1;
101 -: 94: return uv;
102 -: 95:}
103 -: 96:
104 -: 97:int omega_bw_ir_alloc_uvreg64(BlackwellIRProgram *prog) {
105 -: 98: if (!prog || prog->regalloc.num_uvregs >= BW_MAX_UVREGS) return -1;
106 -: 99: int uv = prog->regalloc.num_uvregs++;
107 -: 100: prog->regalloc.uintervals[uv].vreg = uv;
108 -: 101: prog->regalloc.uintervals[uv].first_def = -1;
109 -: 102: prog->regalloc.uintervals[uv].last_use = -1;
110 -: 103: prog->regalloc.uintervals[uv].phys_reg = -1;
111 -: 104: prog->regalloc.uintervals[uv].is_pair = true;
112 -: 105: prog->regalloc.uintervals[uv].active = false;
113 -: 106: prog->regalloc.uvreg_to_phys[uv] = -1;
114 -: 107: return uv;
115 -: 108:}
116 -: 109:
117 -: 110:int omega_bw_ir_append(BlackwellIRProgram *prog, const BlackwellIRInsn *insn) {
118 -: 111: if (!prog || !insn || prog->count >= BW_MAX_IR_INSNS) return -1;
119 -: 112: int idx = (int)prog->count++;
120 -: 113: prog->insns[idx] = *insn;
121 -: 114:
122 -: 115: /* Live-interval def/use tracking. Only LDCU/LDCU64 write a uniform register (the encoder's rule,
123 -: 116: * bw_c_encode_insn and om/encoder/bw_enc_sm121.om isuld); every other dst is a GPR, also when
124 -: 117: * is_uniform marks a uniform SOURCE operand. */
125 -: 118: const bool uniform_dst = insn->op == BW_IR_LDCU || insn->op == BW_IR_LDCU64;
126 -: 119: if (insn->dst_vreg >= 0 && insn->dst_vreg < prog->regalloc.num_vregs) {
127 -: 120: if (!uniform_dst) {
128 -: 121: OmegaLiveInterval *iv = &prog->regalloc.intervals[insn->dst_vreg];
129 -: 122: if (iv->first_def < 0) iv->first_def = idx;
130 -: 123: if (idx > iv->last_use) iv->last_use = idx;
131 -: 124: }
132 -: 125: }
133 -: 126: if (insn->src1_vreg >= 0 && insn->src1_vreg < prog->regalloc.num_vregs) {
134 -: 127: OmegaLiveInterval *iv = &prog->regalloc.intervals[insn->src1_vreg];
135 -: 128: if (iv->first_def < 0) iv->first_def = idx;
136 -: 129: if (idx > iv->last_use) iv->last_use = idx;
137 -: 130: }
138 -: 131: if (insn->src2_vreg >= 0 && insn->src2_vreg < prog->regalloc.num_vregs) {
139 -: 132: OmegaLiveInterval *iv = &prog->regalloc.intervals[insn->src2_vreg];
140 -: 133: if (iv->first_def < 0) iv->first_def = idx;
141 -: 134: if (idx > iv->last_use) iv->last_use = idx;
142 -: 135: }
143 -: 136: if (insn->src3_vreg >= 0 && insn->src3_vreg < prog->regalloc.num_vregs) {
144 -: 137: OmegaLiveInterval *iv = &prog->regalloc.intervals[insn->src3_vreg];
145 -: 138: if (iv->first_def < 0) iv->first_def = idx;
146 -: 139: if (idx > iv->last_use) iv->last_use = idx;
147 -: 140: }
148 -: 141:
149 -: 142: /* Uniform register def/use tracking */
150 -: 143: if (uniform_dst && insn->dst_vreg >= 0 && insn->dst_vreg < prog->regalloc.num_uvregs) {
151 -: 144: OmegaLiveInterval *uiv = &prog->regalloc.uintervals[insn->dst_vreg];
152 -: 145: if (uiv->first_def < 0) uiv->first_def = idx;
153 -: 146: if (idx > uiv->last_use) uiv->last_use = idx;
154 -: 147: }
155 -: 148: if (insn->ureg >= 0 && insn->ureg < prog->regalloc.num_uvregs) {
156 -: 149: OmegaLiveInterval *uiv = &prog->regalloc.uintervals[insn->ureg];
157 -: 150: if (uiv->first_def < 0) uiv->first_def = idx;
158 -: 151: if (idx > uiv->last_use) uiv->last_use = idx;
159 -: 152: }
160 -: 153:
161 -: 154: return idx;
162 -: 155:}
163 -: 156:#else
164 -: 157:/* ABI shell only: Omega decides capacity, operand membership and interval updates. */
165function bw_ra_decide called 488711 returned 100% blocks executed 83%
166 488711: 158:static int bw_ra_decide(uint64_t kind, int64_t a, int64_t b) {
167 488711: 159: uint64_t result = UINT64_MAX;
168 488711*: 160: if (omega_ra_ir(&result, kind, (uint64_t)a, (uint64_t)b) != 0) return -1;
169call 0 returned 488711
170branch 1 taken 0 (fallthrough)
171branch 2 taken 488711
172 488711: 161: return (int)result;
173 -: 162:}
174 -: 163:
175function bw_ra_alloc called 18493 returned 100% blocks executed 90%
176 18493: 164:static int bw_ra_alloc(BlackwellIRProgram *prog, unsigned width, bool uniform) {
177 18493*: 165: if (!prog) return -1;
178branch 0 taken 0 (fallthrough)
179branch 1 taken 18493
180 18493: 166: OmegaRegAlloc *ra = &prog->regalloc;
181 18493: 167: int *count = uniform ? &ra->num_uvregs : &ra->num_vregs;
182branch 0 taken 250 (fallthrough)
183branch 1 taken 18243
184 18493: 168: int v = bw_ra_decide(0, *count, uniform ? BW_MAX_UVREGS : BW_MAX_VREGS);
185branch 0 taken 250 (fallthrough)
186branch 1 taken 18243
187call 2 returned 18493
188 18493*: 169: if (v < 0) return -1;
189branch 0 taken 0 (fallthrough)
190branch 1 taken 18493
191 18493: 170: OmegaLiveInterval *iv = uniform ? &ra->uintervals[v] : &ra->intervals[v];
192branch 0 taken 250 (fallthrough)
193branch 1 taken 18243
194 18493: 171: iv->vreg = v; iv->first_def = -1; iv->last_use = -1; iv->phys_reg = -1;
195 18493: 172: iv->is_pair = width == 2; iv->active = false;
196 18493: 173: if (!uniform) { iv->bundle_size = width; iv->is_quad = width == 4; }
197branch 0 taken 18243 (fallthrough)
198branch 1 taken 250
199 18493: 174: if (uniform) ra->uvreg_to_phys[v] = -1;
200branch 0 taken 250 (fallthrough)
201branch 1 taken 18243
202 18243: 175: else ra->vreg_to_phys[v] = -1;
203 18493: 176: *count = v + 1;
204 18493: 177: return v;
205 -: 178:}
206function legacy_omega_bw_ir_alloc_vreg called 14671 returned 100% blocks executed 100%
207 14671: 179:int omega_bw_ir_alloc_vreg(BlackwellIRProgram *p) { return bw_ra_alloc(p, 1, false); }
208call 0 returned 14671
209function legacy_omega_bw_ir_alloc_vreg64 called 3571 returned 100% blocks executed 100%
210 3571: 180:int omega_bw_ir_alloc_vreg64(BlackwellIRProgram *p) { return bw_ra_alloc(p, 2, false); }
211call 0 returned 3571
212function legacy_omega_bw_ir_alloc_vreg128 called 1 returned 100% blocks executed 100%
213 1: 181:int omega_bw_ir_alloc_vreg128(BlackwellIRProgram *p) { return bw_ra_alloc(p, 4, false); }
214call 0 returned 1
215function legacy_omega_bw_ir_alloc_uvreg called 67 returned 100% blocks executed 100%
216 67: 182:int omega_bw_ir_alloc_uvreg(BlackwellIRProgram *p) { return bw_ra_alloc(p, 1, true); }
217call 0 returned 67
218function legacy_omega_bw_ir_alloc_uvreg64 called 183 returned 100% blocks executed 100%
219 183: 183:int omega_bw_ir_alloc_uvreg64(BlackwellIRProgram *p) { return bw_ra_alloc(p, 2, true); }
220call 0 returned 183
221 -: 184:
222function bw_ra_touch called 96042 returned 100% blocks executed 100%
223 96042: 185:static void bw_ra_touch(OmegaLiveInterval *iv, int at) {
224 96042: 186: iv->first_def = bw_ra_decide(1, iv->first_def, at);
225call 0 returned 96042
226 96042: 187: iv->last_use = bw_ra_decide(2, iv->last_use, at);
227call 0 returned 96042
228 96042: 188:}
229function legacy_omega_bw_ir_append called 39681 returned 100% blocks executed 96%
230 39681: 189:int omega_bw_ir_append(BlackwellIRProgram *prog, const BlackwellIRInsn *insn) {
231 39681*: 190: if (!prog || !insn || bw_ra_decide(5, (int64_t)prog->count, 0) != 1) return -1;
232branch 0 taken 39681 (fallthrough)
233branch 1 taken 0
234branch 2 taken 39681 (fallthrough)
235branch 3 taken 0
236call 4 returned 39681
237branch 5 taken 0 (fallthrough)
238branch 6 taken 39681
239 39681: 191: int idx = (int)prog->count++;
240 39681: 192: prog->insns[idx] = *insn;
241 39681: 193: OmegaRegAlloc *ra = &prog->regalloc;
242 39681: 194: int udst = bw_ra_decide(4, insn->op, 0);
243call 0 returned 39681
244 39681: 195: if (!udst && bw_ra_decide(3, insn->dst_vreg, ra->num_vregs) == 1)
245branch 0 taken 39497 (fallthrough)
246branch 1 taken 184
247call 2 returned 39497
248branch 3 taken 31556 (fallthrough)
249branch 4 taken 7941
250 31556: 196: bw_ra_touch(&ra->intervals[insn->dst_vreg], idx);
251call 0 returned 31556
252 39681: 197: const int src[] = {insn->src1_vreg, insn->src2_vreg, insn->src3_vreg};
253 158724: 198: for (unsigned i = 0; i < 3; ++i)
254branch 0 taken 119043
255branch 1 taken 39681 (fallthrough)
256 119043: 199: if (bw_ra_decide(3, src[i], ra->num_vregs) == 1)
257call 0 returned 119043
258branch 1 taken 61518 (fallthrough)
259branch 2 taken 57525
260 61518: 200: bw_ra_touch(&ra->intervals[src[i]], idx);
261call 0 returned 61518
262 39681: 201: if (udst && bw_ra_decide(3, insn->dst_vreg, ra->num_uvregs) == 1)
263branch 0 taken 184 (fallthrough)
264branch 1 taken 39497
265call 2 returned 184
266branch 3 taken 182 (fallthrough)
267branch 4 taken 2
268 182: 202: bw_ra_touch(&ra->uintervals[insn->dst_vreg], idx);
269call 0 returned 182
270 39681: 203: if (bw_ra_decide(3, insn->ureg, ra->num_uvregs) == 1)
271call 0 returned 39681
272branch 1 taken 2786 (fallthrough)
273branch 2 taken 36895
274 2786: 204: bw_ra_touch(&ra->uintervals[insn->ureg], idx);
275call 0 returned 2786
276 39681: 205: return idx;
277 -: 206:}
278 -: 207:#endif
279 -: 208:
280 -: 209:#if defined(BW_RA_C_PRIMARY) || defined(CUDAPP_REGALLOC_DIFFERENTIAL)
281 -: 210:int omega_bw_regalloc_c_oracle(BlackwellIRProgram *prog) {
282 -: 211: if (!prog) return -1;
283 -: 212: OmegaRegAlloc *ra = &prog->regalloc;
284 -: 213:
285 -: 214: /*
286 -: 215: * Bounded deterministic linear-scan register allocator.
287 -: 216: * Computes genuine live intervals across virtual registers and assigns
288 -: 217: * available physical GPRs (R2..R127, or up to the program's opt-in gpr_limit) and UGPRs (UR4..UR31).
289 -: 218: * Enforces even-alignment and dual-register reservation for 64-bit pairs.
290 -: 219: */
291 -: 220: const int gpr_lim = ra->gpr_limit ? (int)ra->gpr_limit : BW_PHYS_GPR_MAX;
292 -: 221: bool gpr_busy[BW_PHYS_GPR_HW_LIMIT];
293 -: 222: memset(gpr_busy, 0, sizeof(gpr_busy));
294 -: 223:
295 -: 224: int max_phys_used = BW_PHYS_GPR_START;
296 -: 225:
297 -: 226: /* Sort virtual register indices chronologically by first_def (Poletto & Sarkar Linear Scan) */
298 -: 227: int order[BW_MAX_VREGS];
299 -: 228: int count = 0;
300 -: 229: for (int v = 0; v < ra->num_vregs; v++) {
301 -: 230: if (ra->intervals[v].first_def >= 0) {
302 -: 231: order[count++] = v;
303 -: 232: } else {
304 -: 233: ra->intervals[v].phys_reg = BW_PHYS_GPR_START;
305 -: 234: ra->vreg_to_phys[v] = ra->intervals[v].phys_reg;
306 -: 235: }
307 -: 236: }
308 -: 237: for (int i = 0; i < count - 1; i++) {
309 -: 238: for (int j = i + 1; j < count; j++) {
310 -: 239: if (ra->intervals[order[i]].first_def > ra->intervals[order[j]].first_def) {
311 -: 240: int tmp = order[i];
312 -: 241: order[i] = order[j];
313 -: 242: order[j] = tmp;
314 -: 243: }
315 -: 244: }
316 -: 245: }
317 -: 246:
318 -: 247: for (int idx = 0; idx < count; idx++) {
319 -: 248: int v = order[idx];
320 -: 249: OmegaLiveInterval *iv = &ra->intervals[v];
321 -: 250:
322 -: 251: /* Free physical registers whose virtual live intervals have ended */
323 -: 252: for (int p = 0; p < ra->num_vregs; p++) {
324 -: 253: if (ra->intervals[p].active && ra->intervals[p].last_use < iv->first_def) {
325 -: 254: int freed = ra->intervals[p].phys_reg;
326 -: 255: if (freed >= 0 && freed < gpr_lim) {
327 -: 256: uint32_t bsize = ra->intervals[p].bundle_size ? ra->intervals[p].bundle_size : (ra->intervals[p].is_pair ? 2 : (ra->intervals[p].is_quad ? 4 : 1));
328 -: 257: for (uint32_t k = 0; k < bsize && (freed + (int)k) < gpr_lim; k++) {
329 -: 258: gpr_busy[freed + k] = false;
330 -: 259: }
331 -: 260: }
332 -: 261: ra->intervals[p].active = false;
333 -: 262: }
334 -: 263: }
335 -: 264:
336 -: 265: /* Find lowest available physical register */
337 -: 266: int assigned = -1;
338 -: 267: uint32_t bsize = iv->bundle_size ? iv->bundle_size : (iv->is_pair ? 2 : (iv->is_quad ? 4 : 1));
339 -: 268: if (bsize == 4) {
340 -: 269: /* 128-bit quad requires 4-alignment and 4 contiguous free registers */
341 -: 270: int start = (BW_PHYS_GPR_START + 3) & ~3;
342 -: 271: for (int p = start; p <= gpr_lim - 4; p += 4) {
343 -: 272: if (!gpr_busy[p] && !gpr_busy[p + 1] && !gpr_busy[p + 2] && !gpr_busy[p + 3]) {
344 -: 273: assigned = p;
345 -: 274: for (int k = 0; k < 4; k++) gpr_busy[p + k] = true;
346 -: 275: break;
347 -: 276: }
348 -: 277: }
349 -: 278: } else if (bsize == 2) {
350 -: 279: /* 64-bit pair requires even alignment and contiguous free registers */
351 -: 280: int start = (BW_PHYS_GPR_START + 1) & ~1;
352 -: 281: for (int p = start; p <= gpr_lim - 2; p += 2) {
353 -: 282: if (!gpr_busy[p] && !gpr_busy[p + 1]) {
354 -: 283: assigned = p;
355 -: 284: gpr_busy[p] = true;
356 -: 285: gpr_busy[p + 1] = true;
357 -: 286: break;
358 -: 287: }
359 -: 288: }
360 -: 289: } else {
361 -: 290: for (int p = BW_PHYS_GPR_START; p < gpr_lim; p++) {
362 -: 291: if (!gpr_busy[p]) {
363 -: 292: assigned = p;
364 -: 293: gpr_busy[p] = true;
365 -: 294: break;
366 -: 295: }
367 -: 296: }
368 -: 297: }
369 -: 298:
370 -: 299: if (assigned < 0) {
371 -: 300: /* Hardware register capacity exceeded: fail closed loudly */
372 -: 301: return -1;
373 -: 302: }
374 -: 303:
375 -: 304: iv->phys_reg = assigned;
376 -: 305: iv->active = true;
377 -: 306: ra->vreg_to_phys[v] = assigned;
378 -: 307:
379 -: 308: int top = assigned + (int)bsize - 1;
380 -: 309: if (top > max_phys_used) {
381 -: 310: max_phys_used = top;
382 -: 311: }
383 -: 312: }
384 -: 313: ra->peak_gpr_usage = (uint32_t)(max_phys_used + 1);
385 -: 314:
386 -: 315: /* Allocate uniform registers */
387 -: 316: int cur_u = BW_PHYS_UGPR_START;
388 -: 317: for (int uv = 0; uv < ra->num_uvregs; uv++) {
389 -: 318: OmegaLiveInterval *uiv = &ra->uintervals[uv];
390 -: 319: if (uiv->is_pair) {
391 -: 320: if (cur_u % 2 != 0) cur_u++;
392 -: 321: if (cur_u + 1 >= BW_PHYS_UGPR_MAX) return -1;
393 -: 322: uiv->phys_reg = cur_u;
394 -: 323: ra->uvreg_to_phys[uv] = cur_u;
395 -: 324: cur_u += 2;
396 -: 325: } else {
397 -: 326: if (cur_u >= BW_PHYS_UGPR_MAX) return -1;
398 -: 327: uiv->phys_reg = cur_u;
399 -: 328: ra->uvreg_to_phys[uv] = cur_u++;
400 -: 329: }
401 -: 330: }
402 -: 331: ra->peak_ugpr_usage = (uint32_t)cur_u;
403 -: 332:
404 -: 333: return 0;
405 -: 334:}
406 -: 335:#endif
407 -: 336:
408function legacy_omega_bw_regalloc_solve called 513 returned 100% blocks executed 92%
409 513: 337:int omega_bw_regalloc_solve(BlackwellIRProgram *prog) {
410 -: 338:#ifdef BW_RA_C_PRIMARY
411 -: 339: return omega_bw_regalloc_c_oracle(prog);
412 -: 340:#else
413 513*: 341: if (!prog) return -1;
414branch 0 taken 0 (fallthrough)
415branch 1 taken 513
416 513: 342: OmegaRegAlloc *ra = &prog->regalloc;
417 513: 343: uint64_t wire[4096] = {0};
418 513: 344: wire[0] = ra->num_vregs;
419 513: 345: wire[1] = ra->num_uvregs;
420 513: 346: wire[2] = ra->gpr_limit;
421 513: 347: wire[3] = ra->peak_gpr_usage;
422 513: 348: wire[4] = ra->peak_ugpr_usage;
423 148257: 349: for (unsigned v = 0; v < BW_MAX_VREGS + BW_MAX_UVREGS; ++v) {
424branch 0 taken 147744
425branch 1 taken 513 (fallthrough)
426 147744: 350: const OmegaLiveInterval *iv = v < BW_MAX_VREGS
427branch 0 taken 131328 (fallthrough)
428branch 1 taken 16416
429 16416: 351: ? &ra->intervals[v] : &ra->uintervals[v - BW_MAX_VREGS];
430 147744: 352: uint64_t *p = &wire[16 + 10 * v];
431 147744: 353: p[0] = iv->vreg; p[1] = iv->first_def; p[2] = iv->last_use;
432 147744: 354: p[3] = iv->phys_reg; p[4] = iv->bundle_size; p[5] = iv->is_pair;
433 147744: 355: p[6] = iv->is_quad; p[7] = iv->active;
434 147744: 356: p[8] = v < BW_MAX_VREGS ? ra->vreg_to_phys[v] : ra->uvreg_to_phys[v - BW_MAX_VREGS];
435branch 0 taken 131328 (fallthrough)
436branch 1 taken 16416
437 -: 357: }
438 513: 358: uint64_t result = UINT64_MAX;
439 513*: 359: if (omega_ra_run(&result, wire, 4096) != 0) return -1;
440call 0 returned 513
441branch 1 taken 0 (fallthrough)
442branch 2 taken 513
443 -: 360: /* The oracle exposes partial assignments on exhaustion; preserve that contract. */
444 148257: 361: for (unsigned v = 0; v < BW_MAX_VREGS + BW_MAX_UVREGS; ++v) {
445branch 0 taken 147744
446branch 1 taken 513 (fallthrough)
447 147744: 362: OmegaLiveInterval *iv = v < BW_MAX_VREGS
448 147744: 363: ? &ra->intervals[v] : &ra->uintervals[v - BW_MAX_VREGS];
449branch 0 taken 131328 (fallthrough)
450branch 1 taken 16416
451 147744: 364: const uint64_t *p = &wire[16 + 10 * v];
452 147744: 365: iv->phys_reg = (int)p[3]; iv->active = p[7] != 0;
453 147744: 366: if (v < BW_MAX_VREGS) ra->vreg_to_phys[v] = (int)p[8];
454branch 0 taken 131328 (fallthrough)
455branch 1 taken 16416
456 16416: 367: else ra->uvreg_to_phys[v - BW_MAX_VREGS] = (int)p[8];
457 -: 368: }
458 513: 369: ra->peak_gpr_usage = (uint32_t)wire[3];
459 513: 370: ra->peak_ugpr_usage = (uint32_t)wire[4];
460 513: 371: return (int)result;
461 -: 372:#endif
462 -: 373:}
463 -: 374:
464 -: 375:/* ---- sm_121 instruction encoder (aien-dev/CUDApp#79) ---------------------------------------------------
465 -: 376: * The hosted build encodes through om/encoder/bw_enc_sm121.om, translated by the pinned omega-bridge into
466 -: 377: * portable src/cudapp_om_bw_enc_sm121.c (generated by om/units.sh; never edited by hand). The C encoder
467 -: 378: * below is migration-pending and is compiled only:
468 -: 379: * - in the freestanding build (OMEGA_GPU_NO_POSIX), because the current portable binding still uses hosted
469 -: 380: * POSIX trap handling; a freestanding caller-stack binding is a separate requirement;
470 -: 381: * - with CUDAPP_MIGRATION_PENDING_C_ENCODER, the differential oracle build (make CUDAPP_ENCODER=c);
471 -: 382: * - with CUDAPP_MIGRATION_PENDING_ENCODER_DIFF, which encodes every instruction and program both ways, aborts on
472 -: 383: * any byte difference and logs each agreement to $CUDAPP_ENCODER_DIFF_LOG (make CUDAPP_ENCODER=diff).
473 -: 384: * Successor of the C body: bw_enc_sm121.om; it is deleted once the freestanding binding lands. */
474 -: 385:#if defined(OMEGA_GPU_NO_POSIX) || defined(CUDAPP_MIGRATION_PENDING_C_ENCODER)
475 -: 386:#define BW_ENC_C_PRIMARY 1
476 -: 387:#endif
477 -: 388:#if defined(BW_ENC_C_PRIMARY) && defined(CUDAPP_MIGRATION_PENDING_ENCODER_DIFF)
478 -: 389:#error "CUDAPP_MIGRATION_PENDING_ENCODER_DIFF needs the .om encoder: not with OMEGA_GPU_NO_POSIX or the C encoder"
479 -: 390:#endif
480 -: 391:#if defined(BW_ENC_C_PRIMARY) || defined(CUDAPP_MIGRATION_PENDING_ENCODER_DIFF)
481 -: 392:static int bw_c_encode_insn(const BlackwellIRInsn *insn, const OmegaRegAlloc *ra, uint32_t w[4]) {
482 -: 393: memset(w, 0, 16);
483 -: 394:
484 -: 395: int dst = (insn->dst_vreg >= 0) ? (ra->vreg_to_phys[insn->dst_vreg] + insn->dst_subreg) : 0;
485 -: 396: int src1 = (insn->src1_vreg >= 0) ? (ra->vreg_to_phys[insn->src1_vreg] + insn->src1_subreg) : 0;
486 -: 397: int src2 = (insn->src2_vreg >= 0) ? (ra->vreg_to_phys[insn->src2_vreg] + insn->src2_subreg) : 0;
487 -: 398: int src3 = (insn->src3_vreg >= 0) ? (ra->vreg_to_phys[insn->src3_vreg] + insn->src3_subreg) : 0xff; /* Default to RZ (0xff) */
488 -: 399: int ureg = (insn->ureg >= 0) ? ra->uvreg_to_phys[insn->ureg] : 0;
489 -: 400:
490 -: 401: if ((insn->op == BW_IR_LDCU || insn->op == BW_IR_LDCU64) && insn->dst_vreg >= 0) {
491 -: 402: dst = ra->uvreg_to_phys[insn->dst_vreg];
492 -: 403: }
493 -: 404:
494 -: 405: switch (insn->op) {
495 -: 406: case BW_IR_NOP:
496 -: 407: w[0] = 0x00007918;
497 -: 408: w[1] = 0x00000000;
498 -: 409: w[2] = 0x00000000;
499 -: 410: w[3] = insn->control ? insn->control : 0x000fc000; /* control: a timed pause (fragment matmul) */
500 -: 411: break;
501 -: 412:
502 -: 413: case BW_IR_MOV_RZ:
503 -: 414: /* MOV Rd, RZ */
504 -: 415: w[0] = 0x7202 | ((uint32_t)(dst & 0xff) << 16);
505 -: 416: w[1] = 0x000000ff;
506 -: 417: w[2] = 0x00000f00;
507 -: 418: w[3] = insn->control ? insn->control : 0x000fe200;
508 -: 419: break;
509 -: 420:
510 -: 421: case BW_IR_MOV_IMM:
511 -: 422: /* MOV Rd, imm32 */
512 -: 423: w[0] = 0x7802 | ((uint32_t)(dst & 0xff) << 16);
513 -: 424: w[1] = insn->imm;
514 -: 425: w[2] = 0x00000f00;
515 -: 426: w[3] = insn->control ? insn->control : 0x000fe200;
516 -: 427: break;
517 -: 428:
518 -: 429: case BW_IR_S2R:
519 -: 430: /* S2R Rd, SR */
520 -: 431: w[0] = 0x7919 | ((uint32_t)(dst & 0xff) << 16);
521 -: 432: w[1] = 0x0;
522 -: 433: w[2] = (insn->imm & 0xff) << 8;
523 -: 434: w[3] = insn->control ? insn->control : 0x000e2200;
524 -: 435: break;
525 -: 436:
526 -: 437: case BW_IR_LDC:
527 -: 438: /* LDC Rd, c[0x0][imm] */
528 -: 439: w[0] = 0xff007b82 | ((uint32_t)(dst & 0xff) << 16);
529 -: 440: w[1] = (insn->imm << 6) & 0x00ffff00;
530 -: 441: w[2] = 0x00000800;
531 -: 442: w[3] = insn->control ? insn->control : 0x000fe200;
532 -: 443: break;
533 -: 444:
534 -: 445: case BW_IR_LDC64:
535 -: 446: /* LDC.64 Rd:Rd+1, c[0x0][imm] */
536 -: 447: w[0] = 0xff007b82 | ((uint32_t)(dst & 0xff) << 16);
537 -: 448: w[1] = (insn->imm << 6) & 0x00ffff00;
538 -: 449: w[2] = 0x00000a00;
539 -: 450: w[3] = insn->control ? insn->control : 0x000e2200;
540 -: 451: break;
541 -: 452:
542 -: 453: case BW_IR_LDCU:
543 -: 454: /* LDCU URd, c[0x0][imm] */
544 -: 455: w[0] = 0xff0077ac | ((uint32_t)(dst & 0xff) << 16);
545 -: 456: w[1] = (insn->imm << 5) & 0x00ffff00;
546 -: 457: w[2] = 0x08000800;
547 -: 458: w[3] = insn->control ? insn->control : 0x000e2200;
548 -: 459: break;
549 -: 460:
550 -: 461: case BW_IR_LDCU64:
551 -: 462: /* LDCU.64 URd:URd+1, c[0x0][imm] */
552 -: 463: w[0] = 0xff0077ac | ((uint32_t)(dst & 0xff) << 16);
553 -: 464: w[1] = (insn->imm << 5) & 0x00ffff00;
554 -: 465: w[2] = 0x08000a00;
555 -: 466: w[3] = insn->control ? insn->control : 0x000e6e00;
556 -: 467: break;
557 -: 468:
558 -: 469: case BW_IR_IMAD:
559 -: 470: if (insn->src2_vreg >= 0) {
560 -: 471: /* Register-register: IMAD Rd, Ra, Rb, Rc (0x7224) */
561 -: 472: w[0] = 0x7224 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
562 -: 473: w[1] = (uint32_t)(src2 & 0xff);
563 -: 474: w[2] = 0x078e0200 | (uint32_t)(src3 & 0xff);
564 -: 475: w[3] = insn->control ? insn->control : 0x001fca00;
565 -: 476: } else if (insn->is_uniform && insn->ureg >= 0) {
566 -: 477: /* Uniform register multiplier: IMAD Rd, Ra, URb, Rc (0x7c24) */
567 -: 478: w[0] = 0x7c24 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
568 -: 479: w[1] = (uint32_t)(ureg & 0xff);
569 -: 480: w[2] = 0x0f8e0200 | (uint32_t)(src3 & 0xff);
570 -: 481: w[3] = insn->control ? insn->control : 0x001fca00;
571 -: 482: } else {
572 -: 483: /* Immediate multiplier: IMAD Rd, Ra, imm, Rc (0x7824) */
573 -: 484: w[0] = 0x7824 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
574 -: 485: w[1] = insn->imm;
575 -: 486: w[2] = 0x078e0200 | (uint32_t)(src3 & 0xff);
576 -: 487: w[3] = insn->control ? insn->control : 0x001fca00;
577 -: 488: }
578 -: 489: break;
579 -: 490:
580 -: 491: case BW_IR_IMAD_WIDE:
581 -: 492: /* IMAD.WIDE.U32 Rd:Rd+1, Ra, imm, Rc:Rc+1 */
582 -: 493: w[0] = 0x7825 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
583 -: 494: w[1] = insn->imm;
584 -: 495: w[2] = 0x078e0000 | (uint32_t)(src3 & 0xff);
585 -: 496: w[3] = insn->control ? insn->control : 0x001fcc00;
586 -: 497: break;
587 -: 498:
588 -: 499: case BW_IR_ISETP_GE:
589 -: 500: if (insn->is_uniform && insn->ureg >= 0) {
590 -: 501: w[0] = 0x7c0c | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
591 -: 502: w[1] = (uint32_t)(ureg & 0xff);
592 -: 503: w[2] = 0x0bf06070;
593 -: 504: w[3] = insn->control ? insn->control : 0x002fda00;
594 -: 505: } else {
595 -: 506: w[0] = 0x780c | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
596 -: 507: w[1] = insn->imm;
597 -: 508: w[2] = 0x03f06270;
598 -: 509: w[3] = insn->control ? insn->control : 0x001fda00;
599 -: 510: }
600 -: 511: break;
601 -: 512:
602 -: 513: case BW_IR_LDG_E: {
603 -: 514: /* LDG.E Rd, desc[URd][Ra.64+imm]: the 32-bit size (4) of the LDG.E.64 / LDG.E.128 words below; imm as there
604 -: 515: * (signed 24-bit byte offset at bits 40..63, w[1] bits 8..31), unchanged words when imm is 0. */
605 -: 516: int32_t off = (int32_t)insn->imm;
606 -: 517: if (off < -(1 << 23) || off >= (1 << 23)) return -1;
607 -: 518: w[0] = 0x7981 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
608 -: 519: w[1] = (uint32_t)(ureg & 0xff) | (((uint32_t)off & 0xffffffU) << 8);
609 -: 520: w[2] = 0x0c1e1900;
610 -: 521: w[3] = insn->control ? insn->control : 0x000f2200;
611 -: 522: break;
612 -: 523: }
613 -: 524:
614 -: 525: case BW_IR_STG_E: {
615 -: 526: /* STG.E desc[URd][Ra.64+imm], Rb. imm = signed 24-bit byte offset at bits 40..63 (w[1] bits
616 -: 527: * 8..31), as for LDG; words from nvcc 13.0.88 -arch=sm_121 (omega_blackwell_verify_codegen_fixtures_fragmm,
617 -: 528: * 2026-10-12: STG.E desc[UR4][R4.64+0x4], R9 = 0x0000040904007986 0x000fe8000c101904). */
618 -: 529: int32_t off = (int32_t)insn->imm;
619 -: 530: if (off < -(1 << 23) || off >= (1 << 23)) return -1;
620 -: 531: w[0] = 0x7986 | ((uint32_t)(src1 & 0xff) << 24);
621 -: 532: w[1] = (uint32_t)(src2 & 0xff) | (((uint32_t)off & 0xffffffU) << 8);
622 -: 533: w[2] = 0x0c101900 | (uint32_t)(ureg & 0xff);
623 -: 534: w[3] = insn->control ? insn->control : 0x000fe200;
624 -: 535: break;
625 -: 536: }
626 -: 537:
627 -: 538: case BW_IR_STG_EF:
628 -: 539: /* STG.E.MMIO.GPU. Uncached store, meant to be visible without a fence. */
629 -: 540: w[0] = 0x7986 | ((uint32_t)(src1 & 0xff) << 24);
630 -: 541: w[1] = (uint32_t)(src2 & 0xff);
631 -: 542: w[2] = 0x0c111900 | (uint32_t)(ureg & 0xff);
632 -: 543: w[3] = insn->control ? insn->control : 0x000fe200;
633 -: 544: break;
634 -: 545:
635 -: 546: case BW_IR_IADD3:
636 -: 547: /* IADD3 Rd, PT, PT, Ra, Rb, Rc */
637 -: 548: w[0] = 0x7210 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
638 -: 549: w[1] = (uint32_t)(src2 & 0xff);
639 -: 550: w[2] = 0x07ffe0ff;
640 -: 551: w[3] = insn->control ? insn->control : 0x010fca00; /* omega-mv#545: the emitter's waits, not a fixed SB4 wait */
641 -: 552: break;
642 -: 553:
643 -: 554: case BW_IR_HMMA_F16:
644 -: 555: case BW_IR_HMMA_BF16: {
645 -: 556: /* HMMA.16816.F32[.BF16] Rd, Ra, Rb, Rc */
646 -: 557: w[0] = 0x723c | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
647 -: 558: w[1] = (uint32_t)(src2 & 0xff);
648 -: 559: uint32_t prec_bit = (insn->op == BW_IR_HMMA_BF16) ? 0x00040000 : 0x00000000;
649 -: 560: w[2] = (uint32_t)(src3 & 0xff) | (0x18 << 8) | prec_bit;
650 -: 561: w[3] = insn->control ? insn->control : 0x000fe200;
651 -: 562: break;
652 -: 563: }
653 -: 564:
654 -: 565: case BW_IR_SHF_R:
655 -: 566: /* SHF.R.U32.HI Rd, RZ, imm, Ra */
656 -: 567: w[0] = 0x7819U | ((uint32_t)(dst & 0xff) << 16) | (0xffU << 24);
657 -: 568: w[1] = (uint32_t)insn->imm;
658 -: 569: w[2] = 0x00011600 | (uint32_t)(src1 & 0xff);
659 -: 570: w[3] = insn->control ? insn->control : 0x001fca00;
660 -: 571: break;
661 -: 572:
662 -: 573: case BW_IR_LOP3_AND:
663 -: 574: /* LOP3.LUT Rd, Ra, imm, RZ, 0xc0, !PT */
664 -: 575: w[0] = 0x7812U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
665 -: 576: w[1] = (uint32_t)insn->imm;
666 -: 577: w[2] = 0x078ec0ff;
667 -: 578: w[3] = insn->control ? insn->control : 0x001fca00;
668 -: 579: break;
669 -: 580:
670 -: 581: case BW_IR_LDG_E_64:
671 -: 582: case BW_IR_LDG_E_128: {
672 -: 583: /* LDG.E.64 / LDG.E.128 Rd, desc[URd][Ra.64+imm]. imm = signed 24-bit byte offset at
673 -: 584: * bits 40..63 (w[1] bits 8..31); size field in w[2] bits 9..11 (32 = 4, 64 = 5, 128 = 6).
674 -: 585: * Words from nvcc 13.0.88 -arch=sm_121 (omega_blackwell_verify_codegen_fixtures_fragmm). */
675 -: 586: int32_t off = (int32_t)insn->imm;
676 -: 587: if (off < -(1 << 23) || off >= (1 << 23)) return -1;
677 -: 588: w[0] = 0x7981U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
678 -: 589: w[1] = (uint32_t)(ureg & 0xff) | (((uint32_t)off & 0xffffffU) << 8);
679 -: 590: w[2] = insn->op == BW_IR_LDG_E_64 ? 0x0c1e1b00U : 0x0c1e1d00U;
680 -: 591: w[3] = insn->control ? insn->control : 0x000f2200;
681 -: 592: break;
682 -: 593: }
683 -: 594:
684 -: 595: case BW_IR_LDG_E_U16:
685 -: 596: /* LDG.E.U16 Rd, desc[URd][Ra.64] */
686 -: 597: w[0] = 0x7981U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
687 -: 598: w[1] = (uint32_t)(ureg & 0xff);
688 -: 599: w[2] = 0x0c1e1500;
689 -: 600: w[3] = insn->control ? insn->control : 0x000f2200;
690 -: 601: break;
691 -: 602:
692 -: 603: case BW_IR_LDG_STRONG_SYS:
693 -: 604: /* LDG.E.STRONG.SYS. Same shape as LDG.E; w[2] carries the
694 -: 605: * system-scope bits (0x0c1e1900 -> 0x0c1f5900). */
695 -: 606: w[0] = 0x7981 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
696 -: 607: w[1] = (uint32_t)(ureg & 0xff);
697 -: 608: w[2] = 0x0c1f5900;
698 -: 609: w[3] = insn->control ? insn->control : 0x000f2200;
699 -: 610: break;
700 -: 611:
701 -: 612: case BW_IR_LDG_MMIO:
702 -: 613: /* LDG.E.MMIO.GPU, as required by BW_IR_LDG_MMIO. Mesa NAK's sm_80+ fields (sm70_encode.rs
703 -: 614: * set_mem_access): eviction 84..86 = 1 (normal, not .EF = 0), memory order 77..80 = 0x8, a value
704 -: 615: * NAK does not list (weak = 0 would be a cached load); nvdisasm 13.0.85 decodes it as MMIO.GPU.
705 -: 616: * Pinned by tests/bw_ldg_mmio_test.c (issue #205); GB10 behaviour NOT_RUN. */
706 -: 617: w[0] = 0x7981 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
707 -: 618: w[1] = (uint32_t)(ureg & 0xff);
708 -: 619: w[2] = 0x0c1f1900;
709 -: 620: w[3] = insn->control ? insn->control : 0x000f2200;
710 -: 621: break;
711 -: 622:
712 -: 623: case BW_IR_STG_STRONG_SYS:
713 -: 624: w[0] = 0x7986 | ((uint32_t)(src1 & 0xff) << 24);
714 -: 625: if (insn->predicate_p0) {
715 -: 626: uint32_t pred = insn->predicate_not ? 0x8u : 0x0u;
716 -: 627: w[0] = (w[0] & ~0xF000u) | (pred << 12);
717 -: 628: }
718 -: 629: w[1] = (uint32_t)(src2 & 0xff);
719 -: 630: w[2] = 0x0c115900 | (uint32_t)(ureg & 0xff);
720 -: 631: w[3] = insn->control ? insn->control : 0x000fe200;
721 -: 632: break;
722 -: 633:
723 -: 634: case BW_IR_MEMBAR_ALL_SYS:
724 -: 635: w[0] = 0x00007992;
725 -: 636: w[1] = 0x00000000;
726 -: 637: w[2] = 0x0000b000;
727 -: 638: w[3] = insn->control ? insn->control : 0x000fec00;
728 -: 639: break;
729 -: 640:
730 -: 641: case BW_IR_MEMBAR_SC_SYS:
731 -: 642: w[0] = 0x00007992;
732 -: 643: w[1] = 0x00000000;
733 -: 644: w[2] = 0x00003000;
734 -: 645: w[3] = insn->control ? insn->control : 0x000fec00;
735 -: 646: break;
736 -: 647:
737 -: 648: case BW_IR_CCTL_IVALL:
738 -: 649: w[0] = 0xff00798f;
739 -: 650: w[1] = 0x00000000;
740 -: 651: w[2] = 0x02000000;
741 -: 652: w[3] = insn->control ? insn->control : 0x000fe800;
742 -: 653: break;
743 -: 654:
744 -: 655: case BW_IR_ATOMG_ADD_STRONG_SYS:
745 -: 656: w[0] = 0x79a8 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
746 -: 657: w[1] = (uint32_t)(src2 & 0xff) | 0x80000000u;
747 -: 658: w[2] = 0x081f5100 | (uint32_t)(ureg & 0xff);
748 -: 659: w[3] = insn->control ? insn->control : 0x00321e00;
749 -: 660: break;
750 -: 661:
751 -: 662: case BW_IR_ATOMG_EXCH_STRONG_SYS:
752 -: 663: w[0] = 0x79a8 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
753 -: 664: w[1] = (uint32_t)(src2 & 0xff) | 0x80000000u;
754 -: 665: w[2] = 0x0c1f5100 | (uint32_t)(ureg & 0xff);
755 -: 666: w[3] = insn->control ? insn->control : 0x00321e00;
756 -: 667: break;
757 -: 668:
758 -: 669: case BW_IR_ATOMG_ADD_F32_STRONG_SYS:
759 -: 670: case BW_IR_ATOMG_ADD_F32_STRONG_GPU:
760 -: 671: /* ATOMG.E.ADD.F32.FTZ.RN.STRONG.{SYS,GPU} PT, Rd|RZ, desc[UR][Ra.64], Rb (omega_blackwell_verify_codegen_fixtures_atomf32).
761 -: 672: * Float opcode 0x9a3; w2 bit 26 selects the desc[] form, type 9 (w2 bits 9..12) is F32.FTZ.RN, order (w2 bits
762 -: 673: * 13..16) 0xa = SYS, 0x7 = GPU. No destination vreg encodes RZ (the generic default 0 would clobber R0). */
763 -: 674: w[0] = 0x79a3 | ((uint32_t)(insn->dst_vreg < 0 ? 0xff : (dst & 0xff)) << 16) | ((uint32_t)(src1 & 0xff) << 24);
764 -: 675: w[1] = (uint32_t)(src2 & 0xff) | 0x80000000u;
765 -: 676: w[2] = (insn->op == BW_IR_ATOMG_ADD_F32_STRONG_GPU ? 0x0c1ef300u : 0x0c1f5300u) | (uint32_t)(ureg & 0xff);
766 -: 677: w[3] = insn->control ? insn->control : 0x00321e00;
767 -: 678: break;
768 -: 679:
769 -: 680: case BW_IR_ISETP_GE_U32:
770 -: 681: /* ISETP.GE.U32.AND P0, PT, Ra, Rb, PT. Checked with nvdisasm -b SM121. */
771 -: 682: w[0] = 0x720c | ((uint32_t)(src1 & 0xff) << 24);
772 -: 683: w[1] = (uint32_t)(src2 & 0xff);
773 -: 684: w[2] = 0x03f06070;
774 -: 685: w[3] = insn->control ? insn->control : 0x001fda00;
775 -: 686: break;
776 -: 687:
777 -: 688: case BW_IR_LOP3_XOR:
778 -: 689: /* LOP3.LUT Rd, Ra, Rb, RZ, 0x3c, !PT. Checked with nvdisasm -b SM121. */
779 -: 690: w[0] = 0x7212 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
780 -: 691: w[1] = (uint32_t)(src2 & 0xff);
781 -: 692: w[2] = 0x078e3cff;
782 -: 693: w[3] = insn->control ? insn->control : 0x001fca00;
783 -: 694: break;
784 -: 695:
785 -: 696: case BW_IR_FADD:
786 -: 697: /* FADD Rd, Ra, Rb */
787 -: 698: w[0] = 0x7221U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
788 -: 699: w[1] = (uint32_t)(src2 & 0xff);
789 -: 700: w[2] = 0x00000000;
790 -: 701: w[3] = insn->control ? insn->control : 0x004fc400;
791 -: 702: break;
792 -: 703:
793 -: 704: case BW_IR_FSUB:
794 -: 705: /* FSUB Rd, Ra, Rb (FADD Rd, Ra, -Rb) */
795 -: 706: w[0] = 0x7221U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
796 -: 707: w[1] = (uint32_t)(src2 & 0xff) | 0x80000000U;
797 -: 708: w[2] = 0x00000000;
798 -: 709: w[3] = insn->control ? insn->control : 0x004fc400;
799 -: 710: break;
800 -: 711:
801 -: 712: case BW_IR_FMUL:
802 -: 713: /* FMUL Rd, Ra, Rb */
803 -: 714: w[0] = 0x7220U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
804 -: 715: w[1] = (uint32_t)(src2 & 0xff);
805 -: 716: w[2] = 0x00400000;
806 -: 717: w[3] = insn->control ? insn->control : 0x004fc400;
807 -: 718: break;
808 -: 719:
809 -: 720: case BW_IR_FFMA:
810 -: 721: /* FFMA Rd, Ra, Rb, Rc */
811 -: 722: w[0] = 0x7223U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
812 -: 723: w[1] = (uint32_t)(src2 & 0xff);
813 -: 724: w[2] = (uint32_t)(src3 & 0xff);
814 -: 725: w[3] = insn->control ? insn->control : 0x004fc400;
815 -: 726: break;
816 -: 727:
817 -: 728: case BW_IR_FSETP:
818 -: 729: /* FSETP.cond.AND P0, PT, Ra, Rb, PT */
819 -: 730: w[0] = 0x720bU | ((uint32_t)(dst & 0x7) << 16) | ((uint32_t)(src1 & 0xff) << 24);
820 -: 731: w[1] = (uint32_t)(src2 & 0xff);
821 -: 732: w[2] = insn->imm ? insn->imm : 0x03f06000; /* Default GE condition */
822 -: 733: w[3] = insn->control ? insn->control : 0x004fc400;
823 -: 734: break;
824 -: 735:
825 -: 736: case BW_IR_FSEL:
826 -: 737: /* FSEL Rd, Ra, Rb, P0 */
827 -: 738: w[0] = 0x7208U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
828 -: 739: w[1] = (uint32_t)(src2 & 0xff);
829 -: 740: w[2] = (uint32_t)(src3 & 0x7);
830 -: 741: w[3] = insn->control ? insn->control : 0x000fca00;
831 -: 742: break;
832 -: 743:
833 -: 744: case BW_IR_FMNMX_MIN:
834 -: 745: /* FMNMX Rd, Ra, Rb, PT (minimum) */
835 -: 746: w[0] = 0x7209U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
836 -: 747: w[1] = (uint32_t)(src2 & 0xff);
837 -: 748: w[2] = 0x03800000;
838 -: 749: w[3] = insn->control ? insn->control : 0x004fc400;
839 -: 750: break;
840 -: 751:
841 -: 752: case BW_IR_FMNMX_MAX:
842 -: 753: /* FMNMX Rd, Ra, Rb, !PT (maximum) */
843 -: 754: w[0] = 0x7209U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
844 -: 755: w[1] = (uint32_t)(src2 & 0xff);
845 -: 756: w[2] = 0x07800000;
846 -: 757: w[3] = insn->control ? insn->control : 0x004fc400;
847 -: 758: break;
848 -: 759:
849 -: 760: case BW_IR_I2FP:
850 -: 761: /* I2FP.F32.S32 Rd, Ra */
851 -: 762: w[0] = 0x7245U | ((uint32_t)(dst & 0xff) << 16);
852 -: 763: w[1] = (uint32_t)(src1 & 0xff);
853 -: 764: w[2] = 0x00201400;
854 -: 765: w[3] = insn->control ? insn->control : 0x004fe200;
855 -: 766: break;
856 -: 767:
857 -: 768: case BW_IR_F2I:
858 -: 769: /* F2I.TRUNC.NTZ Rd, Ra */
859 -: 770: w[0] = 0x7305U | ((uint32_t)(dst & 0xff) << 16);
860 -: 771: w[1] = (uint32_t)(src1 & 0xff);
861 -: 772: w[2] = 0x0020f100;
862 -: 773: w[3] = insn->control ? insn->control : 0x004e2200;
863 -: 774: break;
864 -: 775:
865 -: 776: case BW_IR_MUFU_RCP:
866 -: 777: /* MUFU.RCP Rd, Ra */
867 -: 778: w[0] = 0x7308U | ((uint32_t)(dst & 0xff) << 16);
868 -: 779: w[1] = (uint32_t)(src1 & 0xff);
869 -: 780: w[2] = 0x00001000;
870 -: 781: w[3] = insn->control ? insn->control : 0x000e2400;
871 -: 782: break;
872 -: 783:
873 -: 784: case BW_IR_MUFU_LG2:
874 -: 785: /* MUFU.LG2 Rd, Ra (nvdisasm 13.0 -b SM121 decodes sub-op 0x0c00 as MUFU.LG2) */
875 -: 786: w[0] = 0x7308U | ((uint32_t)(dst & 0xff) << 16);
876 -: 787: w[1] = (uint32_t)(src1 & 0xff);
877 -: 788: w[2] = 0x00000c00;
878 -: 789: w[3] = insn->control ? insn->control : 0x000e2400;
879 -: 790: break;
880 -: 791:
881 -: 792: case BW_IR_MUFU_RSQ:
882 -: 793: /* MUFU.RSQ Rd, Ra */
883 -: 794: w[0] = 0x7308U | ((uint32_t)(dst & 0xff) << 16);
884 -: 795: w[1] = (uint32_t)(src1 & 0xff);
885 -: 796: w[2] = 0x00001400;
886 -: 797: w[3] = insn->control ? insn->control : 0x000e2400;
887 -: 798: break;
888 -: 799:
889 -: 800: case BW_IR_SHFL_DOWN:
890 -: 801: /* SHFL.DOWN PT, Rd, Ra, offset, 0x1f */
891 -: 802: w[0] = 0x7f89U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
892 -: 803: w[1] = 0x08001f00U | (((uint32_t)insn->imm & 0x1f) << 21);
893 -: 804: w[2] = 0x000e0000;
894 -: 805: w[3] = insn->control ? insn->control : 0x000e2400;
895 -: 806: break;
896 -: 807:
897 -: 808: case BW_IR_SHFL_BFLY:
898 -: 809: /* SHFL.BFLY PT, Rd, Ra, lane, 0x1f: SHFL.DOWN with bit 58 (w[1] bit 26) set
899 -: 810: * (omega_blackwell_verify_codegen_fixtures_bfly_f2fp) */
900 -: 811: w[0] = 0x7f89U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
901 -: 812: w[1] = 0x0c001f00U | (((uint32_t)insn->imm & 0x1f) << 21);
902 -: 813: w[2] = 0x000e0000;
903 -: 814: w[3] = insn->control ? insn->control : 0x000e2400;
904 -: 815: break;
905 -: 816:
906 -: 817: case BW_IR_F2FP_BF16_PACK:
907 -: 818: /* F2FP.BF16.F32.PACK_AB Rd, Ra, Rb (omega_blackwell_verify_codegen_fixtures_bfly_f2fp). The default control
908 -: 819: * is FMNMX's: the kernels emitted this as a patched FMNMX_MAX before R5 and their bytes must not move. */
909 -: 820: w[0] = 0x723eU | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
910 -: 821: w[1] = (uint32_t)(src2 & 0xff);
911 -: 822: w[2] = 0x000010ff;
912 -: 823: w[3] = insn->control ? insn->control : 0x004fc400;
913 -: 824: break;
914 -: 825:
915 -: 826: case BW_IR_LDS:
916 -: 827: /* LDS Rd, [Ra] */
917 -: 828: w[0] = 0x7984U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
918 -: 829: w[1] = 0x00000000;
919 -: 830: w[2] = (uint32_t)(insn->imm & 0xffff);
920 -: 831: w[3] = insn->control ? insn->control : 0x000fe200;
921 -: 832: break;
922 -: 833:
923 -: 834: case BW_IR_STS:
924 -: 835: /* STS [Ra], Rb */
925 -: 836: w[0] = 0x7388U | ((uint32_t)(src1 & 0xff) << 24);
926 -: 837: w[1] = (uint32_t)(src2 & 0xff);
927 -: 838: w[2] = (uint32_t)(insn->imm & 0xffff);
928 -: 839: w[3] = insn->control ? insn->control : 0x000fe200;
929 -: 840: break;
930 -: 841:
931 -: 842: case BW_IR_EXIT:
932 -: 843: w[0] = insn->predicate_p0 ? 0x0000094d : 0x0000794d;
933 -: 844: w[1] = 0x00000000;
934 -: 845: w[2] = 0x03800000;
935 -: 846: w[3] = insn->control ? insn->control : 0x000fea00;
936 -: 847: break;
937 -: 848:
938 -: 849: case BW_IR_BRA: {
939 -: 850: /* sm_121 BRA. Distance is (target - this) - 1, split across the
940 -: 851: * low six bits at instruction bits 18..23 and the rest at bit 34.
941 -: 852: * Predicate bits 12..15: 7 = always, 0 = @P0, 8 = @!P0.
942 -: 853: * A zero delta with no predicate keeps the self-branch word the
943 -: 854: * existing kernels already emit after EXIT. */
944 -: 855: int32_t delta = (int32_t)insn->imm;
945 -: 856: int32_t rel = delta - 1;
946 -: 857: uint32_t pred_field = 0x7u;
947 -: 858: if (insn->predicate_p0)
948 -: 859: pred_field = insn->predicate_not ? 0x8u : 0x0u;
949 -: 860: w[0] = 0x947u | (pred_field << 12) | (((uint32_t)rel & 0x3fu) << 18);
950 -: 861: w[1] = (uint32_t)(rel >> 6) << 2;
951 -: 862: w[2] = (rel < 0) ? 0x0383ffffu : 0x03800000u;
952 -: 863: if (insn->control)
953 -: 864: w[3] = insn->control;
954 -: 865: else if (delta == 0 && !insn->predicate_p0)
955 -: 866: w[3] = 0x000fc000u;
956 -: 867: else
957 -: 868: w[3] = 0x000fea00u;
958 -: 869: break;
959 -: 870: }
960 -: 871:
961 -: 872: case BW_IR_BSSY: {
962 -: 873: /* BSSY.RECONVERGENT Bn, target (omega #308). nvcc 13.0.88 -arch=sm_121:
963 -: 874: * [0070] BSSY.RECONVERGENT B0, 0x140 ; 0x000000c000007945 0x000fe20003800200
964 -: 875: * opcode 0x945 (NAK sm70_encode.rs:4165), barrier id at bits 16..19 (set_bar_dst
965 -: 876: * 16..20), guard predicate at bits 12..15 like BRA, relative byte offset
966 -: 877: * target - (this + 16) at bit 32 (NAK: field 34.. in 4-byte units), the cond
967 -: 878: * predicate PT at bits 87..89 (0x0380 << 16 in w[2]) and bit 73 (0x200 in w[2]),
968 -: 879: * which the disassembler prints as .RECONVERGENT; nvcc sets it on every BSSY/BSYNC
969 -: 880: * for sm_121 and Mesa NAK does not. We follow nvcc. The target is the instruction
970 -: 881: * after the matching BSYNC, so the delta is at least 2; smaller is refused. */
971 -: 882: int32_t delta = (int32_t)insn->imm;
972 -: 883: if (delta < 2 || insn->bar_reg >= BW_RECONV_MAX_BAR) return -1;
973 -: 884: uint32_t pred_field = 0x7u;
974 -: 885: if (insn->predicate_p0)
975 -: 886: pred_field = insn->predicate_not ? 0x8u : 0x0u;
976 -: 887: w[0] = 0x945u | (pred_field << 12) | ((uint32_t)insn->bar_reg << 16);
977 -: 888: w[1] = (uint32_t)(delta - 1) * 16u;
978 -: 889: w[2] = 0x03800200u;
979 -: 890: w[3] = insn->control ? insn->control : 0x000fe200u;
980 -: 891: break;
981 -: 892: }
982 -: 893:
983 -: 894: case BW_IR_BSYNC: {
984 -: 895: /* BSYNC.RECONVERGENT Bn: [0130] BSYNC.RECONVERGENT B0 ; 0x0000000000007941 0x000fea0003800200
985 -: 896: * opcode 0x941 (NAK sm70_encode.rs:4179), barrier id bits 16..19, cond PT, bit 73. */
986 -: 897: if (insn->bar_reg >= BW_RECONV_MAX_BAR) return -1;
987 -: 898: uint32_t pred_field = 0x7u;
988 -: 899: if (insn->predicate_p0)
989 -: 900: pred_field = insn->predicate_not ? 0x8u : 0x0u;
990 -: 901: w[0] = 0x941u | (pred_field << 12) | ((uint32_t)insn->bar_reg << 16);
991 -: 902: w[1] = 0;
992 -: 903: w[2] = 0x03800200u;
993 -: 904: w[3] = insn->control ? insn->control : 0x000fea00u;
994 -: 905: break;
995 -: 906: }
996 -: 907:
997 -: 908: case BW_IR_MUFU_EX2:
998 -: 909: /* MUFU.EX2 Rd, Ra. nvdisasm 13.0 -b SM121: 0x7308 with sub-op 0x0800 decodes
999 -: 910: * "MUFU.EX2 R2, R4" (RCP is 0x1000, RSQ 0x1400 above). */
1000 -: 911: w[0] = 0x7308U | ((uint32_t)(dst & 0xff) << 16);
1001 -: 912: w[1] = (uint32_t)(src1 & 0xff);
1002 -: 913: w[2] = 0x00000800;
1003 -: 914: w[3] = insn->control ? insn->control : 0x000e2400;
1004 -: 915: break;
1005 -: 916:
1006 -: 917: case BW_IR_BAR_SYNC:
1007 -: 918: /* BAR.SYNC.DEFER_BLOCKING 0x0: the exact words src/omega_numeric.c:885 runs on
1008 -: 919: * the chip (nvdisasm: "BAR.SYNC.DEFER_BLOCKING 0x0"). No registers. */
1009 -: 920: w[0] = 0x00007b1dU;
1010 -: 921: w[1] = 0x00000000;
1011 -: 922: w[2] = 0x00010000;
1012 -: 923: w[3] = insn->control ? insn->control : 0x000fec00;
1013 -: 924: break;
1014 -: 925:
1015 -: 926: case BW_IR_LDS128: {
1016 -: 927: /* LDS.128 Rd..Rd+3, [Ra+imm]. nvcc 13.0.88 -arch=sm_121 words (fixtures below):
1017 -: 928: * LDS.128 R4, [R20] ; 0x0000000014047984 0x000fe80000000c00
1018 -: 929: * LDS.128 R8, [R20+0x40] ; 0x0000400014087984 0x000e280000000c00
1019 -: 930: * imm = byte offset at w[1] bits 8..31; size field 6 (128) at w[2] bits 9..11. */
1020 -: 931: if (insn->imm >= (1u << 23)) return -1;
1021 -: 932: w[0] = 0x7984U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
1022 -: 933: w[1] = (insn->imm & 0xffffffU) << 8;
1023 -: 934: w[2] = 0x00000c00U;
1024 -: 935: w[3] = insn->control ? insn->control : 0x000fe800;
1025 -: 936: break;
1026 -: 937: }
1027 -: 938:
1028 -: 939: case BW_IR_LDS32:
1029 -: 940: /* LDS Rd, [Ra+URZ] (32-bit), the src/omega_numeric.c:886 form. */
1030 -: 941: w[0] = 0x7984U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24);
1031 -: 942: w[1] = 0x000000ff;
1032 -: 943: w[2] = 0x08000800;
1033 -: 944: w[3] = insn->control ? insn->control : 0x000e2800;
1034 -: 945: break;
1035 -: 946:
1036 -: 947: case BW_IR_STS32:
1037 -: 948: /* STS [Ra+URZ], Rb (32-bit), the src/omega_numeric.c:884 form. */
1038 -: 949: w[0] = 0x7988U | ((uint32_t)(src1 & 0xff) << 24);
1039 -: 950: w[1] = (uint32_t)(src2 & 0xff);
1040 -: 951: w[2] = 0x080008ffU;
1041 -: 952: w[3] = insn->control ? insn->control : 0x000fe200;
1042 -: 953: break;
1043 -: 954:
1044 -: 955: /* Prime race cut (2026-10-05). An absent operand is RZ for these three ops. */
1045 -: 956: case BW_IR_LOP3_LUT: {
1046 -: 957: /* LOP3.LUT Rd, Ra, Rb, Rc, imm8, !PT. LOP3_XOR above is this form with Rc = RZ, LUT 0x3c. */
1047 -: 958: uint32_t a = (insn->src1_vreg >= 0) ? (uint32_t)(src1 & 0xff) : 0xffU;
1048 -: 959: uint32_t b = (insn->src2_vreg >= 0) ? (uint32_t)(src2 & 0xff) : 0xffU;
1049 -: 960: w[0] = 0x7212U | ((uint32_t)(dst & 0xff) << 16) | (a << 24);
1050 -: 961: w[1] = b;
1051 -: 962: w[2] = 0x078e0000U | ((insn->imm & 0xffU) << 8) | (uint32_t)(src3 & 0xff);
1052 -: 963: w[3] = insn->control ? insn->control : 0x001fca00;
1053 -: 964: break;
1054 -: 965: }
1055 -: 966:
1056 -: 967: case BW_IR_SHF_L_U32: {
1057 -: 968: /* SHF.L.U32 Rd, Ra, Rb, Rc: register-amount form (0x7219) of SHF_R's 0x7819, with the
1058 -: 969: * .R (w[2] bit 12) and .HI (bit 16) flags clear. Rc is the funnel high word (RZ). */
1059 -: 970: uint32_t a = (insn->src1_vreg >= 0) ? (uint32_t)(src1 & 0xff) : 0xffU;
1060 -: 971: uint32_t b = (insn->src2_vreg >= 0) ? (uint32_t)(src2 & 0xff) : 0xffU;
1061 -: 972: w[0] = 0x7219U | ((uint32_t)(dst & 0xff) << 16) | (a << 24);
1062 -: 973: w[1] = b;
1063 -: 974: w[2] = 0x00000600U | (uint32_t)(src3 & 0xff);
1064 -: 975: w[3] = insn->control ? insn->control : 0x001fca00;
1065 -: 976: break;
1066 -: 977: }
1067 -: 978:
1068 -: 979: case BW_IR_IMAD_HI_U32: {
1069 -: 980: /* IMAD.HI.U32 Rd, Ra, Rb, Rc: opcode 0x227 with the IMAD.WIDE.U32 modifier word. */
1070 -: 981: uint32_t a = (insn->src1_vreg >= 0) ? (uint32_t)(src1 & 0xff) : 0xffU;
1071 -: 982: uint32_t b = (insn->src2_vreg >= 0) ? (uint32_t)(src2 & 0xff) : 0xffU;
1072 -: 983: w[0] = 0x7227U | ((uint32_t)(dst & 0xff) << 16) | (a << 24);
1073 -: 984: w[1] = b;
1074 -: 985: w[2] = 0x078e0000U | (uint32_t)(src3 & 0xff);
1075 -: 986: w[3] = insn->control ? insn->control : 0x001fca00;
1076 -: 987: break;
1077 -: 988: }
1078 -: 989:
1079 -: 990: default:
1080 -: 991: return -1;
1081 -: 992: }
1082 -: 993: return 0;
1083 -: 994:}
1084 -: 995:#endif /* C encoder, migration-pending */
1085 -: 996:
1086 -: 997:#ifdef BW_ENC_C_PRIMARY
1087 -: 998:static int encode_single_insn(const BlackwellIRInsn *insn, const OmegaRegAlloc *ra, uint32_t w[4]) {
1088 -: 999: return bw_c_encode_insn(insn, ra, w);
1089 -: 1000:}
1090 -: 1001:#else
1091 -: 1002:#include "cudapp_native.h"
1092 -: 1003:/* The .om unit reads the IR as 8 ulongs per instruction and the allocation as one 288-entry table; these are the
1093 -: 1004: * layouts its source documents (om/encoder/bw_enc_sm121.om), so the enum values and sizes are pinned here. */
1094 -: 1005:#define BW_OM_INS_LEN 8192u /* BW_MAX_IR_INSNS * 8 */
1095 -: 1006:#define BW_OM_PHYS_LEN 288u /* BW_MAX_VREGS + BW_MAX_UVREGS */
1096 -: 1007:#define BW_OM_CODE_LEN 16384u /* BW_MAX_IR_INSNS * 16 */
1097 -: 1008:_Static_assert(BW_MAX_IR_INSNS == 1024 && BW_MAX_VREGS == 256 && BW_MAX_UVREGS == 32, "bw_enc_sm121.om array sizes");
1098 -: 1009:_Static_assert(BW_IR_NOP == 0 && BW_IR_MOV_RZ == 1 && BW_IR_MOV_IMM == 2 && BW_IR_S2R == 3 && BW_IR_LDC == 4 &&
1099 -: 1010: BW_IR_LDC64 == 5 && BW_IR_LDCU == 6 && BW_IR_LDCU64 == 7 && BW_IR_IMAD == 8 && BW_IR_IMAD_WIDE == 9 &&
1100 -: 1011: BW_IR_ISETP_GE == 10 && BW_IR_LDG_E == 11 && BW_IR_STG_E == 12 && BW_IR_STG_EF == 13 &&
1101 -: 1012: BW_IR_IADD3 == 14 && BW_IR_HMMA_F16 == 15 && BW_IR_HMMA_BF16 == 16 && BW_IR_SHF_R == 17 &&
1102 -: 1013: BW_IR_LOP3_AND == 18 && BW_IR_LDG_E_U16 == 19 && BW_IR_LDG_STRONG_SYS == 20 && BW_IR_LDG_MMIO == 21 &&
1103 -: 1014: BW_IR_STG_STRONG_SYS == 22 && BW_IR_MEMBAR_ALL_SYS == 23 && BW_IR_MEMBAR_SC_SYS == 24 &&
1104 -: 1015: BW_IR_CCTL_IVALL == 25 && BW_IR_ATOMG_ADD_STRONG_SYS == 26 && BW_IR_ATOMG_EXCH_STRONG_SYS == 27 &&
1105 -: 1016: BW_IR_ISETP_GE_U32 == 28 && BW_IR_LOP3_XOR == 29, "bw_enc_sm121.om opcode numbers 0-29");
1106 -: 1017:_Static_assert(BW_IR_FADD == 30 && BW_IR_FSUB == 31 && BW_IR_FMUL == 32 && BW_IR_FFMA == 33 && BW_IR_FSETP == 34 &&
1107 -: 1018: BW_IR_FSEL == 35 && BW_IR_FMNMX_MIN == 36 && BW_IR_FMNMX_MAX == 37 && BW_IR_I2FP == 38 &&
1108 -: 1019: BW_IR_F2I == 39 && BW_IR_MUFU_RCP == 40 && BW_IR_MUFU_RSQ == 41 && BW_IR_SHFL_DOWN == 42 &&
1109 -: 1020: BW_IR_LDS == 43 && BW_IR_STS == 44 && BW_IR_EXIT == 45 && BW_IR_BRA == 46 && BW_IR_MUFU_EX2 == 47 &&
1110 -: 1021: BW_IR_BAR_SYNC == 48 && BW_IR_LDS32 == 49 && BW_IR_STS32 == 50 && BW_IR_LOP3_LUT == 51 &&
1111 -: 1022: BW_IR_SHF_L_U32 == 52 && BW_IR_IMAD_HI_U32 == 53 && BW_IR_BSSY == 54 && BW_IR_BSYNC == 55 &&
1112 -: 1023: BW_IR_LDG_E_64 == 56 && BW_IR_LDG_E_128 == 57 && BW_IR_LDS128 == 58 && BW_IR_MUFU_LG2 == 59,
1113 -: 1024: "bw_enc_sm121.om opcode numbers 30-59");
1114 -: 1025:_Static_assert(BW_IR_SHFL_BFLY == 60 && BW_IR_F2FP_BF16_PACK == 61 && BW_IR_ATOMG_ADD_F32_STRONG_SYS == 62 &&
1115 -: 1026: BW_IR_ATOMG_ADD_F32_STRONG_GPU == 63, "bw_enc_sm121.om opcode numbers 60-63");
1116 -: 1027:
1117 -: 1028:/* Encodes n instructions through the .om unit into code (BW_OM_CODE_LEN bytes). pad != 0 is program mode (NOP
1118 -: 1029: * padding to a multiple of 8, at least 32). Returns the bytes written; 0 = refused. */
1119function bw_om_encode called 528 returned 100% blocks executed 91%
1120 528: 1030:static size_t bw_om_encode(const BlackwellIRInsn *insns, size_t n, const OmegaRegAlloc *ra, int pad, uint8_t *code) {
1121 528*: 1031: if (n > BW_MAX_IR_INSNS) return 0;
1122branch 0 taken 0 (fallthrough)
1123branch 1 taken 528
1124 -: 1032: uint64_t ins[BW_OM_INS_LEN], phys[BW_OM_PHYS_LEN];
1125 16317: 1033: for (size_t i = 0; i < n; i++) {
1126branch 0 taken 15789
1127branch 1 taken 528 (fallthrough)
1128 15789: 1034: const BlackwellIRInsn *in = &insns[i];
1129 15789: 1035: uint64_t *r = &ins[i * 8];
1130 -: 1036:#ifdef CUDAPP_MIGRATION_PENDING_C_CODEGEN_BASE
1131 15789: 1037: r[0] = (uint64_t)(int64_t)(int)in->op;
1132 15789: 1038: r[1] = (uint64_t)(int64_t)in->dst_vreg;
1133 15789: 1039: r[2] = (uint64_t)(int64_t)in->src1_vreg;
1134 15789: 1040: r[3] = (uint64_t)(int64_t)in->src2_vreg;
1135 15789: 1041: r[4] = (uint64_t)(int64_t)in->src3_vreg;
1136 15789: 1042: r[5] = (uint64_t)(int64_t)in->ureg;
1137 15789: 1043: r[6] = (uint64_t)in->imm | (uint64_t)in->control << 32;
1138 15789: 1044: r[7] = (uint64_t)in->is_uniform | (uint64_t)in->predicate_p0 << 1 | (uint64_t)in->predicate_not << 2 |
1139 15789: 1045: (uint64_t)in->bar_reg << 8 | (uint64_t)in->dst_subreg << 16 | (uint64_t)in->src1_subreg << 24 |
1140 15789: 1046: (uint64_t)in->src2_subreg << 32 | (uint64_t)in->src3_subreg << 40;
1141 -: 1047:#else
1142 -: 1048: if (omega_bw_fields_pack(in, r) != 0) return 0;
1143 -: 1049:#endif
1144 -: 1050: }
1145 4199592: 1051: for (size_t i = n * 8; i < BW_OM_INS_LEN; i++) ins[i] = 0;
1146branch 0 taken 4199064
1147branch 1 taken 528 (fallthrough)
1148 135696: 1052: for (int i = 0; i < BW_MAX_VREGS; i++) phys[i] = (uint64_t)(int64_t)ra->vreg_to_phys[i];
1149branch 0 taken 135168
1150branch 1 taken 528 (fallthrough)
1151 17424: 1053: for (int i = 0; i < BW_MAX_UVREGS; i++) phys[BW_MAX_VREGS + i] = (uint64_t)(int64_t)ra->uvreg_to_phys[i];
1152branch 0 taken 16896
1153branch 1 taken 528 (fallthrough)
1154 528: 1054: uint64_t bytes = 0;
1155 528: 1055: if (omega_bw_enc_sm121(&bytes, ins, BW_OM_INS_LEN, phys, BW_OM_PHYS_LEN, (uint64_t)n, pad ? 1u : 0u, code,
1156branch 0 taken 272 (fallthrough)
1157branch 1 taken 256
1158call 2 returned 528
1159branch 3 taken 0 (fallthrough)
1160branch 4 taken 528
1161 -: 1056: BW_OM_CODE_LEN) != OMEGA_OK)
1162 #####: 1057: return 0;
1163 528: 1058: return (size_t)bytes;
1164 -: 1059:}
1165 -: 1060:
1166 -: 1061:#ifdef CUDAPP_MIGRATION_PENDING_ENCODER_DIFF
1167 -: 1062:/* One line per agreement, appended; any disagreement aborts the process after naming it. */
1168 -: 1063:static void bw_enc_diff_note(const char *what, size_t insns, const uint8_t *code, size_t len, int agree) {
1169 -: 1064: char hex[17] = "-";
1170 -: 1065: if (len) {
1171 -: 1066: uint8_t d[SHA256_DIGEST_SIZE]; sha256_hash(code, len, d);
1172 -: 1067: for (int i = 0; i < 8; i++) snprintf(hex + 2 * i, 3, "%02x", (unsigned)d[i]);
1173 -: 1068: }
1174 -: 1069: const char *path = getenv("CUDAPP_ENCODER_DIFF_LOG");
1175 -: 1070: if (path && path[0]) {
1176 -: 1071: int fd = open(path, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0600);
1177 -: 1072: if (fd >= 0) {
1178 -: 1073: char line[160];
1179 -: 1074: int k = snprintf(line, sizeof line, "%s insns=%zu bytes=%zu sha16=%s %s\n", what, insns, len, hex,
1180 -: 1075: agree ? "SAME" : "DIFFER");
1181 -: 1076: if (k > 0 && write(fd, line, (size_t)k) != k) BW_DIAG("encoder diff: short log write\n");
1182 -: 1077: close(fd);
1183 -: 1078: }
1184 -: 1079: }
1185 -: 1080: if (!agree) {
1186 -: 1081: BW_DIAG("ENCODER DIFF: .om and C encoders disagree (%s, %zu insns)\n", what, insns);
1187 -: 1082: abort();
1188 -: 1083: }
1189 -: 1084:}
1190 -: 1085:#endif
1191 -: 1086:
1192function encode_single_insn called 256 returned 100% blocks executed 90%
1193 256: 1087:static int encode_single_insn(const BlackwellIRInsn *insn, const OmegaRegAlloc *ra, uint32_t w[4]) {
1194 -: 1088: uint8_t code[BW_OM_CODE_LEN];
1195 256*: 1089: int rc = bw_om_encode(insn, 1, ra, 0, code) == 16 ? 0 : -1;
1196call 0 returned 256
1197branch 1 taken 256 (fallthrough)
1198branch 2 taken 0
1199 256: 1090: memset(w, 0, 16);
1200 -: 1091:#ifdef CUDAPP_MIGRATION_PENDING_C_CODEGEN_BASE
1201 256: 1092: if (rc == 0)
1202branch 0 taken 256 (fallthrough)
1203branch 1 taken 0
1204 1280: 1093: for (int k = 0; k < 4; k++)
1205branch 0 taken 1024
1206branch 1 taken 256 (fallthrough)
1207 1024: 1094: w[k] = (uint32_t)code[4 * k] | (uint32_t)code[4 * k + 1] << 8 | (uint32_t)code[4 * k + 2] << 16 |
1208 1024: 1095: (uint32_t)code[4 * k + 3] << 24;
1209 -: 1096:#else
1210 -: 1097: if (rc == 0) {
1211 -: 1098: uint64_t raw[16], record[8] = {0}, result = 0;
1212 -: 1099: for (int k = 0; k < 16; ++k) raw[k] = code[k];
1213 -: 1100: if (omega_cg_fields(&result, 2, raw, 16, record, 8) != OMEGA_OK || result != 0) rc = -1;
1214 -: 1101: else for (int k = 0; k < 4; ++k) w[k] = (uint32_t)raw[k];
1215 -: 1102: }
1216 -: 1103:#endif
1217 -: 1104:#ifdef CUDAPP_MIGRATION_PENDING_ENCODER_DIFF
1218 -: 1105: uint32_t c[4];
1219 -: 1106: int crc = bw_c_encode_insn(insn, ra, c);
1220 -: 1107: bw_enc_diff_note("insn", 1, rc == 0 ? code : NULL, rc == 0 ? 16 : 0,
1221 -: 1108: crc == rc && (rc != 0 || memcmp(c, w, 16) == 0));
1222 -: 1109:#endif
1223 256: 1110: return rc;
1224 -: 1111:}
1225 -: 1112:#endif
1226 -: 1113:
1227 -: 1114:/* Prime race cut (2026-10-05): golden words for LOP3_LUT, SHF_L_U32 and IMAD_HI_U32.
1228 -: 1115: * Each expected (w0, w1, w2) is the low 96 bits of an instruction nvcc 13.0.88 emitted
1229 -: 1116: * for sm_121 (nvcc -arch=sm_121 -cubin, cuobjdump -sass; source and dump in
1230 -: 1117: * bench/prime_race/tests/encoding_oracle.md). Control words (w3) are scheduler output and
1231 -: 1118: * not compared. nvcc is an offline oracle only; nothing here links CUDA. 0 = all good. */
1232function legacy_omega_blackwell_verify_codegen_fixtures_intops called 0 returned 0% blocks executed 0%
1233 #####: 1119:int omega_blackwell_verify_codegen_fixtures_intops(void) {
1234 -: 1120: OmegaRegAlloc ra;
1235 #####: 1121: memset(&ra, 0, sizeof(ra));
1236 -: 1122: static const int phys[] = { 0, 2, 6, 7, 9, 11, 13 };
1237 #####: 1123: for (int i = 0; i < (int)(sizeof phys / sizeof phys[0]); i++) ra.vreg_to_phys[i] = phys[i];
1238branch 0 never executed
1239branch 1 never executed (fallthrough)
1240 -: 1124: enum { R0 = 0, R2, R6, R7, R9, R11, R13, RZ = -1 };
1241 -: 1125: static const struct {
1242 -: 1126: BlackwellIROpcode op; int d, a, b, c; uint32_t imm; uint32_t w0, w1, w2; const char *text;
1243 -: 1127: } fx[] = {
1244 -: 1128: { BW_IR_LOP3_LUT, R9, R7, R0, RZ, 0xfc, 0x07097212U, 0x00000000U, 0x078efcffU, "LOP3.LUT R9, R7, R0, RZ, 0xfc, !PT" },
1245 -: 1129: { BW_IR_LOP3_LUT, R11, R6, R7, R0, 0x78, 0x060b7212U, 0x00000007U, 0x078e7800U, "LOP3.LUT R11, R6, R7, R0, 0x78, !PT" },
1246 -: 1130: { BW_IR_LOP3_LUT, R13, R6, R7, R0, 0x10, 0x060d7212U, 0x00000007U, 0x078e1000U, "LOP3.LUT R13, R6, R7, R0, 0x10, !PT" },
1247 -: 1131: { BW_IR_LOP3_LUT, R7, RZ, R9, RZ, 0x33, 0xff077212U, 0x00000009U, 0x078e33ffU, "LOP3.LUT R7, RZ, R9, RZ, 0x33, !PT" },
1248 -: 1132: { BW_IR_SHF_L_U32, R7, R9, R2, RZ, 0, 0x09077219U, 0x00000002U, 0x000006ffU, "SHF.L.U32 R7, R9, R2, RZ" },
1249 -: 1133: { BW_IR_SHF_L_U32, R7, R0, R7, RZ, 0, 0x00077219U, 0x00000007U, 0x000006ffU, "SHF.L.U32 R7, R0, R7, RZ" },
1250 -: 1134: { BW_IR_IMAD_HI_U32, R9, R9, R0, R6, 0, 0x09097227U, 0x00000000U, 0x078e0006U, "IMAD.HI.U32 R9, R9, R0, R6" },
1251 -: 1135: { BW_IR_IMAD_HI_U32, R7, R0, R7, RZ, 0, 0x00077227U, 0x00000007U, 0x078e00ffU, "IMAD.HI.U32 R7, R0, R7, RZ" },
1252 -: 1136: };
1253 #####: 1137: for (int i = 0; i < (int)(sizeof fx / sizeof fx[0]); i++) {
1254branch 0 never executed
1255branch 1 never executed (fallthrough)
1256 -: 1138: BlackwellIRInsn in;
1257 #####: 1139: memset(&in, 0, sizeof in);
1258 #####: 1140: in.op = fx[i].op; in.dst_vreg = fx[i].d; in.src1_vreg = fx[i].a; in.src2_vreg = fx[i].b;
1259 #####: 1141: in.src3_vreg = fx[i].c; in.ureg = -1; in.imm = fx[i].imm;
1260 -: 1142: uint32_t w[4];
1261 #####: 1143: if (encode_single_insn(&in, &ra, w) != 0) return -(2 * i + 1);
1262call 0 never executed
1263branch 1 never executed (fallthrough)
1264branch 2 never executed
1265 #####: 1144: if (w[0] != fx[i].w0 || w[1] != fx[i].w1 || w[2] != fx[i].w2) return -(2 * i + 2);
1266branch 0 never executed (fallthrough)
1267branch 1 never executed
1268branch 2 never executed (fallthrough)
1269branch 3 never executed
1270branch 4 never executed (fallthrough)
1271branch 5 never executed
1272 -: 1145: }
1273 #####: 1146: return 0;
1274 -: 1147:}
1275 -: 1148:
1276function legacy_omega_blackwell_encode_one called 256 returned 100% blocks executed 92%
1277 256: 1149:int omega_blackwell_encode_one(const BlackwellIRInsn *insn, uint32_t w[4]) {
1278 256*: 1150: if (!insn || !w) return -1;
1279branch 0 taken 256 (fallthrough)
1280branch 1 taken 0
1281branch 2 taken 0 (fallthrough)
1282branch 3 taken 256
1283 -: 1151: OmegaRegAlloc ra;
1284 256: 1152: memset(&ra, 0, sizeof ra);
1285 65792: 1153: for (int i = 0; i < BW_MAX_VREGS; i++) ra.vreg_to_phys[i] = i;
1286branch 0 taken 65536
1287branch 1 taken 256 (fallthrough)
1288 8448: 1154: for (int i = 0; i < BW_MAX_UVREGS; i++) ra.uvreg_to_phys[i] = i;
1289branch 0 taken 8192
1290branch 1 taken 256 (fallthrough)
1291 256: 1155: return encode_single_insn(insn, &ra, w);
1292call 0 returned 256
1293 -: 1156:}
1294 -: 1157:
1295 -: 1158:/* omega #328: golden words for the fragment-major matmul. Oracle: nvcc 13.0.88 -arch=sm_121
1296 -: 1159: * -cubin -O3, cuobjdump -sass, on a kernel with uint2 / uint4 loads at immediate offsets and a
1297 -: 1160: * dependent mma.m16n8k16 bf16 chain (source and dump sealed in
1298 -: 1161: * ~/workspace/investigations/2026-10-07-qwen3-decode-matmul/oracle/frag_plain.{cu,sass}):
1299 -: 1162: * LDG.E.64 R2, desc[UR8][R30.64] ; 0x000000081e027981 0x000ea8000c1e1b00
1300 -: 1163: * LDG.E.64 R28, desc[UR8][R30.64+0x100] ; 0x000100081e1c7981 0x000ee8000c1e1b00
1301 -: 1164: * LDG.E.128 R8, desc[UR8][R32.64] ; 0x0000000820087981 0x000ea8000c1e1d00
1302 -: 1165: * LDG.E.128 R20, desc[UR8][R32.64+0x1000] ; 0x0010000820147981 0x000e9e000c1e1d00
1303 -: 1166: * HMMA.16816.F32.BF16 R8, R12, R6, R8 ; 0x000000060c08723c 0x010fe20000041808
1304 -: 1167: * NOP ; 0x0000000000007918 0x000fdc0000000000
1305 -: 1168: * The dependent HMMA chain nvcc emits is HMMA (stall 15) then NOP (stall 14): 29 cycles from
1306 -: 1169: * one HMMA to the next that reads its accumulator. w3 is compared for the NOP only (it is the
1307 -: 1170: * whole point of that instruction). 0 = all good. */
1308function legacy_omega_blackwell_verify_codegen_fixtures_fragmm called 0 returned 0% blocks executed 0%
1309 #####: 1171:int omega_blackwell_verify_codegen_fixtures_fragmm(void) {
1310 -: 1172: static const struct {
1311 -: 1173: BlackwellIROpcode op; int d, a, b, c, u; uint32_t imm, control; uint32_t w0, w1, w2, w3; const char *text;
1312 -: 1174: } fx[] = {
1313 -: 1175: { BW_IR_LDG_E_64, 2, 30, -1, -1, 8, 0, 0, 0x1e027981U, 0x00000008U, 0x0c1e1b00U, 0, "LDG.E.64 R2, desc[UR8][R30.64]" },
1314 -: 1176: { BW_IR_LDG_E_64, 28, 30, -1, -1, 8, 0x100, 0, 0x1e1c7981U, 0x00010008U, 0x0c1e1b00U, 0, "LDG.E.64 R28, desc[UR8][R30.64+0x100]" },
1315 -: 1177: { BW_IR_LDG_E_128, 8, 32, -1, -1, 8, 0, 0, 0x20087981U, 0x00000008U, 0x0c1e1d00U, 0, "LDG.E.128 R8, desc[UR8][R32.64]" },
1316 -: 1178: { BW_IR_LDG_E_128, 20, 32, -1, -1, 8, 0x1000, 0, 0x20147981U, 0x00100008U, 0x0c1e1d00U, 0, "LDG.E.128 R20, desc[UR8][R32.64+0x1000]" },
1317 -: 1179: { BW_IR_HMMA_BF16, 8, 12, 6, 8, -1, 0, 0, 0x0c08723cU, 0x00000006U, 0x00041808U, 0, "HMMA.16816.F32.BF16 R8, R12, R6, R8" },
1318 -: 1180: { BW_IR_NOP, -1, -1, -1, -1, -1, 0, 0x000fdc00U, 0x00007918U, 0, 0, 0x000fdc00U, "NOP (stall 14)" },
1319 -: 1181: /* LDS.128 with an immediate offset (attention batched loads, 2026-10-12): nvcc 13.0.88 -arch=sm_121 on
1320 -: 1182: * float4 shared reads at register + constant offsets (fixture source in the omega speed/attention-batched-loads PR) */
1321 -: 1183: { BW_IR_LDS128, 4, 20, -1, -1, -1, 0, 0, 0x14047984U, 0x00000000U, 0x00000c00U, 0, "LDS.128 R4, [R20]" },
1322 -: 1184: { BW_IR_LDS128, 8, 20, -1, -1, -1, 0x40, 0, 0x14087984U, 0x00004000U, 0x00000c00U, 0, "LDS.128 R8, [R20+0x40]" },
1323 -: 1185: { BW_IR_LDS128, 12, 20, -1, -1, -1, 0x100, 0, 0x140c7984U, 0x00010000U, 0x00000c00U, 0, "LDS.128 R12, [R20+0x100]" },
1324 -: 1186: /* STG.E with an immediate offset (blocked prefill matmul, 2026-10-12): nvcc 13.0.88 -arch=sm_121 on float stores
1325 -: 1187: * at register + constant offsets (~/.claude/jobs/ade3c837/tmp/stg-oracle/stg.cu); the second word is the
1326 -: 1188: * offset-free STG word with UR4 */
1327 -: 1189: { BW_IR_STG_E, -1, 4, 8, -1, 4, 0, 0, 0x04007986U, 0x00000008U, 0x0c101904U, 0, "STG.E desc[UR4][R4.64], R8" },
1328 -: 1190: { BW_IR_STG_E, -1, 4, 9, -1, 4, 0x4, 0, 0x04007986U, 0x00000409U, 0x0c101904U, 0, "STG.E desc[UR4][R4.64+0x4], R9" },
1329 -: 1191: { BW_IR_STG_E, -1, 4, 10, -1, 4, 0x4000, 0, 0x04007986U, 0x0040000aU, 0x0c101904U, 0, "STG.E desc[UR4][R4.64+0x4000], R10" },
1330 -: 1192: { BW_IR_STG_E, -1, 6, 11, -1, 4, 0xfff00000u, 0, 0x06007986U, 0xf000000bU, 0x0c101904U, 0, "STG.E desc[UR4][R6.64+-0x100000], R11" },
1331 -: 1193: };
1332 #####: 1194: for (int i = 0; i < (int)(sizeof fx / sizeof fx[0]); i++) {
1333branch 0 never executed
1334branch 1 never executed (fallthrough)
1335 -: 1195: BlackwellIRInsn in;
1336 #####: 1196: memset(&in, 0, sizeof in);
1337 #####: 1197: in.op = fx[i].op; in.dst_vreg = fx[i].d; in.src1_vreg = fx[i].a; in.src2_vreg = fx[i].b;
1338 #####: 1198: in.src3_vreg = fx[i].c; in.ureg = fx[i].u; in.imm = fx[i].imm; in.control = fx[i].control;
1339 -: 1199: uint32_t w[4];
1340 #####: 1200: if (omega_blackwell_encode_one(&in, w) != 0) return -(2 * i + 1);
1341call 0 never executed
1342branch 1 never executed (fallthrough)
1343branch 2 never executed
1344 #####: 1201: if (w[0] != fx[i].w0 || w[1] != fx[i].w1 || w[2] != fx[i].w2 || (fx[i].w3 && w[3] != fx[i].w3)) return -(2 * i + 2);
1345branch 0 never executed (fallthrough)
1346branch 1 never executed
1347branch 2 never executed (fallthrough)
1348branch 3 never executed
1349branch 4 never executed (fallthrough)
1350branch 5 never executed
1351branch 6 never executed (fallthrough)
1352branch 7 never executed
1353branch 8 never executed (fallthrough)
1354branch 9 never executed
1355 -: 1202: }
1356 -: 1203: /* offsets outside the signed 24-bit field are refused, not wrapped */
1357 -: 1204: BlackwellIRInsn big;
1358 #####: 1205: memset(&big, 0, sizeof big);
1359 #####: 1206: big.op = BW_IR_LDG_E_64; big.dst_vreg = 2; big.src1_vreg = 30; big.src2_vreg = -1; big.src3_vreg = -1; big.ureg = 8;
1360 #####: 1207: big.imm = 1u << 23;
1361 -: 1208: uint32_t w[4];
1362 #####: 1209: if (omega_blackwell_encode_one(&big, w) == 0) return -100;
1363call 0 never executed
1364branch 1 never executed (fallthrough)
1365branch 2 never executed
1366 #####: 1210: big.imm = (uint32_t)-(1 << 23);
1367 #####: 1211: if (omega_blackwell_encode_one(&big, w) != 0) return -101;
1368call 0 never executed
1369branch 1 never executed (fallthrough)
1370branch 2 never executed
1371 #####: 1212: return 0;
1372 -: 1213:}
1373 -: 1214:
1374 -: 1215:/* omega #308: BSSY / BSYNC golden words. Oracle: nvcc 13.0.88 -arch=sm_121 -cubin -O3 on the
1375 -: 1216: * kernels in docs/gpu-reconvergence-308.md, cuobjdump -sass (low 64-bit word, then high; the
1376 -: 1217: * top 23 bits of the high word are the control word and are not compared here):
1377 -: 1218: * k_loop [0070] BSSY.RECONVERGENT B0, 0x140 ; 0x000000c000007945 0x000fe20003800200 (delta 13)
1378 -: 1219: * k_nested [0070] BSSY.RECONVERGENT B0, 0x300 ; 0x0000028000007945 0x000fe20003800200 (delta 41)
1379 -: 1220: * k_break [0070] BSSY.RECONVERGENT B0, 0x110 ; 0x0000009000007945 0x000fe20003800200 (delta 10)
1380 -: 1221: * k_loop [0130] BSYNC.RECONVERGENT B0 ; 0x0000000000007941 0x000fea0003800200
1381 -: 1222: * Barrier ids other than B0 and the predicated forms are decoded by tools/reconv_nvdisasm_check.sh
1382 -: 1223: * (nvdisasm -b SM121 text), not by this table. */
1383function legacy_omega_blackwell_verify_codegen_fixtures_reconv called 0 returned 0% blocks executed 0%
1384 #####: 1224:int omega_blackwell_verify_codegen_fixtures_reconv(void) {
1385 -: 1225: static const struct { BlackwellIROpcode op; int delta; int bar; uint32_t w0, w1, w2; } fx[] = {
1386 -: 1226: { BW_IR_BSSY, 13, 0, 0x00007945U, 0x000000c0U, 0x03800200U },
1387 -: 1227: { BW_IR_BSSY, 41, 0, 0x00007945U, 0x00000280U, 0x03800200U },
1388 -: 1228: { BW_IR_BSSY, 10, 0, 0x00007945U, 0x00000090U, 0x03800200U },
1389 -: 1229: { BW_IR_BSYNC, 0, 0, 0x00007941U, 0x00000000U, 0x03800200U },
1390 -: 1230: };
1391 #####: 1231: for (int i = 0; i < (int)(sizeof fx / sizeof fx[0]); i++) {
1392branch 0 never executed
1393branch 1 never executed (fallthrough)
1394 -: 1232: BlackwellIRInsn in;
1395 #####: 1233: memset(&in, 0, sizeof in);
1396 #####: 1234: in.op = fx[i].op; in.dst_vreg = -1; in.src1_vreg = -1; in.src2_vreg = -1; in.src3_vreg = -1; in.ureg = -1;
1397 #####: 1235: in.imm = (uint32_t)fx[i].delta; in.bar_reg = (uint8_t)fx[i].bar;
1398 -: 1236: uint32_t w[4];
1399 #####: 1237: if (omega_blackwell_encode_one(&in, w) != 0) return -(2 * i + 1);
1400call 0 never executed
1401branch 1 never executed (fallthrough)
1402branch 2 never executed
1403 #####: 1238: if (w[0] != fx[i].w0 || w[1] != fx[i].w1 || w[2] != fx[i].w2) return -(2 * i + 2);
1404branch 0 never executed (fallthrough)
1405branch 1 never executed
1406branch 2 never executed (fallthrough)
1407branch 3 never executed
1408branch 4 never executed (fallthrough)
1409branch 5 never executed
1410 -: 1239: /* control word defaults mirror nvcc's: BSSY 0x000fe200, BSYNC 0x000fea00 */
1411 #####: 1240: if (w[3] != (fx[i].op == BW_IR_BSSY ? 0x000fe200U : 0x000fea00U)) return -(2 * i + 2);
1412branch 0 never executed (fallthrough)
1413branch 1 never executed
1414branch 2 never executed (fallthrough)
1415branch 3 never executed
1416 -: 1241: }
1417 -: 1242: /* refusals: a BSSY must name a later instruction (delta >= 2), barrier ids stop at B15 */
1418 -: 1243: BlackwellIRInsn bad; uint32_t w[4];
1419 #####: 1244: memset(&bad, 0, sizeof bad); bad.op = BW_IR_BSSY; bad.dst_vreg = bad.src1_vreg = bad.src2_vreg = bad.src3_vreg = bad.ureg = -1;
1420 #####: 1245: bad.imm = 1; bad.bar_reg = 0;
1421 #####: 1246: if (omega_blackwell_encode_one(&bad, w) == 0) return -101;
1422call 0 never executed
1423branch 1 never executed (fallthrough)
1424branch 2 never executed
1425 #####: 1247: bad.imm = (uint32_t)-3;
1426 #####: 1248: if (omega_blackwell_encode_one(&bad, w) == 0) return -102;
1427call 0 never executed
1428branch 1 never executed (fallthrough)
1429branch 2 never executed
1430 #####: 1249: bad.imm = 5; bad.bar_reg = 16;
1431 #####: 1250: if (omega_blackwell_encode_one(&bad, w) == 0) return -103;
1432call 0 never executed
1433branch 1 never executed (fallthrough)
1434branch 2 never executed
1435 #####: 1251: bad.op = BW_IR_BSYNC; bad.imm = 0; bad.bar_reg = 16;
1436 #####: 1252: if (omega_blackwell_encode_one(&bad, w) == 0) return -104;
1437call 0 never executed
1438branch 1 never executed (fallthrough)
1439branch 2 never executed
1440 #####: 1253: bad.bar_reg = 15;
1441 #####: 1254: if (omega_blackwell_encode_one(&bad, w) != 0 || w[0] != (0x00007941U | (15U << 16))) return -105;
1442call 0 never executed
1443branch 1 never executed (fallthrough)
1444branch 2 never executed
1445branch 3 never executed (fallthrough)
1446branch 4 never executed
1447 #####: 1255: return 0;
1448 -: 1256:}
1449 -: 1257:
1450 -: 1258:
1451 -: 1259:/* Training R5 (2026-10-15): golden words for SHFL.BFLY and F2FP.BF16.F32.PACK_AB, the two instructions the prefill
1452 -: 1260: * kernels emitted as placeholders patched after encoding until R5. Oracle: nvcc 13.0.88 -arch=sm_121, cuobjdump -sass,
1453 -: 1261: * sealed in evidence/OWN30B-T3-TC-PEAK-BW-5faa0f70-20261013T2236Z/fa_ops.{cu,sass} (low 64-bit word, then high; the top
1454 -: 1262: * 23 bits of the high word are the control word and are not compared):
1455 -: 1263: * SHFL.BFLY PT, R5, R0, 0x1, 0x1f ; 0x0c201f0000057f89 0x004e2800000e0000
1456 -: 1264: * SHFL.BFLY PT, R7, R8, 0x1, 0x1f ; 0x0c201f0008077f89 0x008e6200000e0000
1457 -: 1265: * SHFL.BFLY PT, R4, R9, 0x2, 0x1f ; 0x0c401f0009047f89 0x000e2800000e0000
1458 -: 1266: * SHFL.BFLY PT, R6, R11, 0x2, 0x1f ; 0x0c401f000b067f89 0x000e6200000e0000
1459 -: 1267: * F2FP.BF16.F32.PACK_AB R9, R3, R0 ; 0x000000000309723e 0x000fe200000010ff
1460 -: 1268: * F2FP.BF16.F32.PACK_AB R13, R13, R10 ; 0x0000000a0d0d723e 0x000fe400000010ff
1461 -: 1269: * SHFL.BFLY is SHFL.DOWN (oracle words in omega_numeric.c, lanes 16 .. 1) with bit 58 set (Mesa NAK mode field 58..59: Idx 0,
1462 -: 1270: * Up 1, Down 2, Bfly 3; same lane field 53..57); the lane check below covers every lane 0 .. 31 against that rule. 0 = all good. */
1463function legacy_omega_blackwell_verify_codegen_fixtures_bfly_f2fp called 0 returned 0% blocks executed 0%
1464 #####: 1271:int omega_blackwell_verify_codegen_fixtures_bfly_f2fp(void) {
1465 -: 1272: static const struct {
1466 -: 1273: BlackwellIROpcode op; int d, a, b; uint32_t imm; uint32_t w0, w1, w2; const char *text;
1467 -: 1274: } fx[] = {
1468 -: 1275: { BW_IR_SHFL_BFLY, 5, 0, -1, 1, 0x00057f89U, 0x0c201f00U, 0x000e0000U, "SHFL.BFLY PT, R5, R0, 0x1, 0x1f" },
1469 -: 1276: { BW_IR_SHFL_BFLY, 7, 8, -1, 1, 0x08077f89U, 0x0c201f00U, 0x000e0000U, "SHFL.BFLY PT, R7, R8, 0x1, 0x1f" },
1470 -: 1277: { BW_IR_SHFL_BFLY, 4, 9, -1, 2, 0x09047f89U, 0x0c401f00U, 0x000e0000U, "SHFL.BFLY PT, R4, R9, 0x2, 0x1f" },
1471 -: 1278: { BW_IR_SHFL_BFLY, 6, 11, -1, 2, 0x0b067f89U, 0x0c401f00U, 0x000e0000U, "SHFL.BFLY PT, R6, R11, 0x2, 0x1f" },
1472 -: 1279: { BW_IR_F2FP_BF16_PACK, 9, 3, 0, 0, 0x0309723eU, 0x00000000U, 0x000010ffU, "F2FP.BF16.F32.PACK_AB R9, R3, R0" },
1473 -: 1280: { BW_IR_F2FP_BF16_PACK, 13, 13, 10, 0, 0x0d0d723eU, 0x0000000aU, 0x000010ffU, "F2FP.BF16.F32.PACK_AB R13, R13, R10" },
1474 -: 1281: };
1475 -: 1282: uint32_t w[4];
1476 #####: 1283: for (int i = 0; i < (int)(sizeof fx / sizeof fx[0]); i++) {
1477branch 0 never executed
1478branch 1 never executed (fallthrough)
1479 -: 1284: BlackwellIRInsn in;
1480 #####: 1285: memset(&in, 0, sizeof in);
1481 #####: 1286: in.op = fx[i].op; in.dst_vreg = fx[i].d; in.src1_vreg = fx[i].a; in.src2_vreg = fx[i].b;
1482 #####: 1287: in.src3_vreg = -1; in.ureg = -1; in.imm = fx[i].imm;
1483 #####: 1288: if (omega_blackwell_encode_one(&in, w) != 0) return -(2 * i + 1);
1484call 0 never executed
1485branch 1 never executed (fallthrough)
1486branch 2 never executed
1487 #####: 1289: if (w[0] != fx[i].w0 || w[1] != fx[i].w1 || w[2] != fx[i].w2) return -(2 * i + 2);
1488branch 0 never executed (fallthrough)
1489branch 1 never executed
1490branch 2 never executed (fallthrough)
1491branch 3 never executed
1492branch 4 never executed (fallthrough)
1493branch 5 never executed
1494 -: 1290: }
1495 #####: 1291: for (uint32_t lane = 0; lane < 32; lane++) {
1496branch 0 never executed
1497branch 1 never executed (fallthrough)
1498 -: 1292: BlackwellIRInsn in; uint32_t d[4];
1499 #####: 1293: memset(&in, 0, sizeof in);
1500 #####: 1294: in.op = BW_IR_SHFL_DOWN; in.dst_vreg = 9; in.src1_vreg = 2; in.src2_vreg = in.src3_vreg = in.ureg = -1; in.imm = lane;
1501 #####: 1295: if (omega_blackwell_encode_one(&in, d) != 0) return -100;
1502call 0 never executed
1503branch 1 never executed (fallthrough)
1504branch 2 never executed
1505 #####: 1296: in.op = BW_IR_SHFL_BFLY;
1506 #####: 1297: if (omega_blackwell_encode_one(&in, w) != 0) return -101;
1507call 0 never executed
1508branch 1 never executed (fallthrough)
1509branch 2 never executed
1510 #####: 1298: if (w[0] != d[0] || w[1] != (d[1] | 0x04000000U) || w[2] != d[2] || w[3] != d[3]) return -102;
1511branch 0 never executed (fallthrough)
1512branch 1 never executed
1513branch 2 never executed (fallthrough)
1514branch 3 never executed
1515branch 4 never executed (fallthrough)
1516branch 5 never executed
1517branch 6 never executed (fallthrough)
1518branch 7 never executed
1519 -: 1299: }
1520 #####: 1300: return 0;
1521 -: 1301:}
1522 -: 1302:
1523 -: 1303:/* Training R5 part 2: f32 global atomic add. Starting map from Mesa NAK sm70_encode.rs (a08a0b9, sm >= 90 float ATOMG;
1524 -: 1304: * Mesa ranges are half-open): opcode 0x9a3, op 87..90 (Add 0, Min 2, Max 4), type 73..76 (F32 = 9, which is .FTZ.RN;
1525 -: 1305: * 12 decodes as .RN without FTZ), order 77..80 (Strong System 0xa, Strong GPU 0x7), pred-dst 81..83 = PT, eviction
1526 -: 1306: * 84..86 = 1, bit 63 = Ra.64, bit 91 = UR form. Then every word below was decoded offline with nvdisasm -b SM121
1527 -: 1307: * (CUDA 13.0) to the text shown. Where Mesa and the decoder disagree the decoder (and the chip probe) win: this word
1528 -: 1308: * sets bit 90 (w2 bit 26), which falls inside Mesa's op field, yet it decodes as .ADD with desc[UR][R.64]; without it
1529 -: 1309: * the same word decodes as [R.64+UR]. (Bit 88 decodes as .MIN, so the op field is there.)
1530 -: 1310: * 0x80000005020479a3 0x00321e000c1f5306 ATOMG.E.ADD.F32.FTZ.RN.STRONG.SYS PT, R4, desc[UR6][R2.64], R5 ;
1531 -: 1311: * 0x800000070a0979a3 0x00321e000c1f5304 ATOMG.E.ADD.F32.FTZ.RN.STRONG.SYS PT, R9, desc[UR4][R10.64], R7 ;
1532 -: 1312: * 0x8000000502ff79a3 0x00321e000c1f5306 ATOMG.E.ADD.F32.FTZ.RN.STRONG.SYS PT, RZ, desc[UR6][R2.64], R5 ;
1533 -: 1313: * 0x80000005020479a3 0x00321e000c1ef306 ATOMG.E.ADD.F32.FTZ.RN.STRONG.GPU PT, R4, desc[UR6][R2.64], R5 ;
1534 -: 1314: * 0x800000070a0979a3 0x00321e000c1ef304 ATOMG.E.ADD.F32.FTZ.RN.STRONG.GPU PT, R9, desc[UR4][R10.64], R7 ;
1535 -: 1315: * 0x8000000502ff79a3 0x00321e000c1ef306 ATOMG.E.ADD.F32.FTZ.RN.STRONG.GPU PT, RZ, desc[UR6][R2.64], R5 ;
1536 -: 1316: * Rows with d = -1 (no destination vreg) must encode RZ, not R0. These are host golden words.
1537 -: 1317: * The GB10 probe tests/gpu_atomf32_probe_test.c is NOT QUALIFIED (pending a receipt). See docs/status.md.
1538 -: 1318: * 0 = all good. */
1539function legacy_omega_blackwell_verify_codegen_fixtures_atomf32 called 0 returned 0% blocks executed 0%
1540 #####: 1319:int omega_blackwell_verify_codegen_fixtures_atomf32(void) {
1541 -: 1320: static const struct { BlackwellIROpcode op; int d, a, b, u; uint32_t w0, w1, w2; } fx[] = {
1542 -: 1321: { BW_IR_ATOMG_ADD_F32_STRONG_SYS, 4, 2, 5, 6, 0x020479a3U, 0x80000005U, 0x0c1f5306U },
1543 -: 1322: { BW_IR_ATOMG_ADD_F32_STRONG_SYS, 9, 10, 7, 4, 0x0a0979a3U, 0x80000007U, 0x0c1f5304U },
1544 -: 1323: { BW_IR_ATOMG_ADD_F32_STRONG_SYS, 255, 2, 5, 6, 0x02ff79a3U, 0x80000005U, 0x0c1f5306U },
1545 -: 1324: { BW_IR_ATOMG_ADD_F32_STRONG_SYS, -1, 2, 5, 6, 0x02ff79a3U, 0x80000005U, 0x0c1f5306U },
1546 -: 1325: { BW_IR_ATOMG_ADD_F32_STRONG_GPU, 4, 2, 5, 6, 0x020479a3U, 0x80000005U, 0x0c1ef306U },
1547 -: 1326: { BW_IR_ATOMG_ADD_F32_STRONG_GPU, 9, 10, 7, 4, 0x0a0979a3U, 0x80000007U, 0x0c1ef304U },
1548 -: 1327: { BW_IR_ATOMG_ADD_F32_STRONG_GPU, -1, 2, 5, 6, 0x02ff79a3U, 0x80000005U, 0x0c1ef306U },
1549 -: 1328: };
1550 -: 1329: uint32_t w[4];
1551 #####: 1330: for (int i = 0; i < (int)(sizeof fx / sizeof fx[0]); i++) {
1552branch 0 never executed
1553branch 1 never executed (fallthrough)
1554 -: 1331: BlackwellIRInsn in;
1555 #####: 1332: memset(&in, 0, sizeof in);
1556 #####: 1333: in.op = fx[i].op; in.dst_vreg = fx[i].d; in.src1_vreg = fx[i].a; in.src2_vreg = fx[i].b;
1557 #####: 1334: in.src3_vreg = -1; in.ureg = fx[i].u;
1558 #####: 1335: if (omega_blackwell_encode_one(&in, w) != 0) return -(2 * i + 1);
1559call 0 never executed
1560branch 1 never executed (fallthrough)
1561branch 2 never executed
1562 #####: 1336: if (w[0] != fx[i].w0 || w[1] != fx[i].w1 || w[2] != fx[i].w2 || w[3] != 0x00321e00U) return -(2 * i + 2);
1563branch 0 never executed (fallthrough)
1564branch 1 never executed
1565branch 2 never executed (fallthrough)
1566branch 3 never executed
1567branch 4 never executed (fallthrough)
1568branch 5 never executed
1569branch 6 never executed (fallthrough)
1570branch 7 never executed
1571 -: 1337: }
1572 #####: 1338: return 0;
1573 -: 1339:}
1574 -: 1340:/* FB-1 cut 4: word-level fixtures for the four additive ops (checked against the
1575 -: 1341: * nvdisasm decodes recorded in docs/numeric/FB1_CUT4_ELEMENTWISE.md). 0 = all good. */
1576function legacy_omega_blackwell_verify_codegen_fixtures_fb1cut4 called 0 returned 0% blocks executed 0%
1577 #####: 1342:int omega_blackwell_verify_codegen_fixtures_fb1cut4(void) {
1578 -: 1343: OmegaRegAlloc ra;
1579 #####: 1344: memset(&ra, 0, sizeof(ra));
1580 #####: 1345: ra.vreg_to_phys[0] = 2; /* R2 */
1581 #####: 1346: ra.vreg_to_phys[1] = 4; /* R4 */
1582 #####: 1347: ra.vreg_to_phys[2] = 9; /* R9 */
1583 #####: 1348: ra.vreg_to_phys[3] = 10; /* R10 */
1584 #####: 1349: ra.vreg_to_phys[4] = 8; /* R8 */
1585 -: 1350: uint32_t w[4];
1586 -: 1351:
1587 -: 1352: /* MUFU.EX2 R2, R4 */
1588 #####: 1353: BlackwellIRInsn ex2 = { .op = BW_IR_MUFU_EX2, .dst_vreg = 0, .src1_vreg = 1 };
1589 #####: 1354: if (encode_single_insn(&ex2, &ra, w) != 0) return -1;
1590call 0 never executed
1591branch 1 never executed (fallthrough)
1592branch 2 never executed
1593 #####: 1355: if (w[0] != 0x00027308U || w[1] != 4 || w[2] != 0x00000800U) return -2;
1594branch 0 never executed (fallthrough)
1595branch 1 never executed
1596branch 2 never executed (fallthrough)
1597branch 3 never executed
1598branch 4 never executed (fallthrough)
1599branch 5 never executed
1600 -: 1356: /* BAR.SYNC.DEFER_BLOCKING 0x0 */
1601 #####: 1357: BlackwellIRInsn bar = { .op = BW_IR_BAR_SYNC };
1602 #####: 1358: if (encode_single_insn(&bar, &ra, w) != 0) return -3;
1603call 0 never executed
1604branch 1 never executed (fallthrough)
1605branch 2 never executed
1606 #####: 1359: if (w[0] != 0x00007b1dU || w[1] != 0 || w[2] != 0x00010000U || w[3] != 0x000fec00U) return -4;
1607branch 0 never executed (fallthrough)
1608branch 1 never executed
1609branch 2 never executed (fallthrough)
1610branch 3 never executed
1611branch 4 never executed (fallthrough)
1612branch 5 never executed
1613branch 6 never executed (fallthrough)
1614branch 7 never executed
1615 -: 1360: /* LDS R9, [R10+URZ] */
1616 #####: 1361: BlackwellIRInsn lds = { .op = BW_IR_LDS32, .dst_vreg = 2, .src1_vreg = 3 };
1617 #####: 1362: if (encode_single_insn(&lds, &ra, w) != 0) return -5;
1618call 0 never executed
1619branch 1 never executed (fallthrough)
1620branch 2 never executed
1621 #####: 1363: if (w[0] != 0x0a097984U || w[1] != 0xff || w[2] != 0x08000800U) return -6;
1622branch 0 never executed (fallthrough)
1623branch 1 never executed
1624branch 2 never executed (fallthrough)
1625branch 3 never executed
1626branch 4 never executed (fallthrough)
1627branch 5 never executed
1628 -: 1364: /* STS [R8+URZ], R2 */
1629 #####: 1365: BlackwellIRInsn sts = { .op = BW_IR_STS32, .src1_vreg = 4, .src2_vreg = 0 };
1630 #####: 1366: if (encode_single_insn(&sts, &ra, w) != 0) return -7;
1631call 0 never executed
1632branch 1 never executed (fallthrough)
1633branch 2 never executed
1634 #####: 1367: if (w[0] != 0x08007988U || w[1] != 2 || w[2] != 0x080008ffU) return -8;
1635branch 0 never executed (fallthrough)
1636branch 1 never executed
1637branch 2 never executed (fallthrough)
1638branch 3 never executed
1639branch 4 never executed (fallthrough)
1640branch 5 never executed
1641 #####: 1368: return 0;
1642 -: 1369:}
1643 -: 1370:
1644 -: 1371:/* Kernel capture (C6 of docs/OMEGA.md, tools/sm121dis): with OMEGA_KERNEL_DUMP_DIR set, every encoded kernel is written
1645 -: 1372: * there as <first 16 hex of its SHA-256>.bin, once per distinct body, so the disassembler can be checked against nvdisasm on
1646 -: 1373: * every kernel the library builds. Unset (the normal case) it does nothing; the freestanding build has no files. */
1647function legacy_omega_kernel_dump called 271 returned 100% blocks executed 15%
1648 271: 1374:void omega_kernel_dump(const uint8_t *code, size_t len) {
1649 -: 1375:#ifndef OMEGA_GPU_NO_POSIX
1650 271: 1376: const char *env = getenv("OMEGA_KERNEL_DUMP_DIR");
1651call 0 returned 271
1652 271*: 1377: if (!env || !env[0] || !code || !len) return;
1653branch 0 taken 0 (fallthrough)
1654branch 1 taken 271
1655branch 2 never executed (fallthrough)
1656branch 3 never executed
1657branch 4 never executed (fallthrough)
1658branch 5 never executed
1659branch 6 never executed (fallthrough)
1660branch 7 never executed
1661 -: 1378: /* Only the checked copy (src/omega_path_check.h) is opened; a refused directory is a diagnostic, which
1662 -: 1379: * tools/sm121dis/corpus.sh fails on, never a silent skip. */
1663 -: 1380: char dir[4000];
1664 #####: 1381: if (omega_path_copy(dir, sizeof dir, env) != 0) {
1665call 0 never executed
1666branch 1 never executed (fallthrough)
1667branch 2 never executed
1668 #####: 1382: BW_DIAG("omega_kernel_dump: OMEGA_KERNEL_DUMP_DIR refused (src/omega_path_check.h)\n");
1669call 0 never executed
1670 #####: 1383: return;
1671 -: 1384: }
1672 #####: 1385: uint8_t d[SHA256_DIGEST_SIZE]; sha256_hash(code, len, d);
1673call 0 never executed
1674 -: 1386: char path[4096];
1675 #####: 1387: int n = snprintf(path, sizeof path, "%s/%02x%02x%02x%02x%02x%02x%02x%02x.bin",
1676 #####: 1388: dir, (unsigned)d[0], (unsigned)d[1], (unsigned)d[2], (unsigned)d[3],
1677 #####: 1389: (unsigned)d[4], (unsigned)d[5], (unsigned)d[6], (unsigned)d[7]);
1678 #####: 1390: if (n < 0 || (size_t)n >= sizeof path) return;
1679branch 0 never executed (fallthrough)
1680branch 1 never executed
1681branch 2 never executed (fallthrough)
1682branch 3 never executed
1683 -: 1391: /* Private, exclusive creation: an existing body or symlink is left alone. */
1684 #####: 1392: int fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW | O_CLOEXEC, 0600);
1685call 0 never executed
1686 #####: 1393: if (fd < 0) return;
1687branch 0 never executed (fallthrough)
1688branch 1 never executed
1689 #####: 1394: FILE *f = fdopen(fd, "wb");
1690call 0 never executed
1691 #####: 1395: if (!f) { close(fd); unlink(path); BW_DIAG("omega_kernel_dump: write failed, removed %s\n", path); return; }
1692branch 0 never executed (fallthrough)
1693branch 1 never executed
1694call 2 never executed
1695call 3 never executed
1696call 4 never executed
1697 -: 1396: /* A body cut short (a full disk) must not stay under its full-content name: it would be compared as a smaller kernel
1698 -: 1397: * and, created O_EXCL, never rewritten. tools/sm121dis/corpus.sh fails on these diagnostics. */
1699 #####: 1398: int bad = fwrite(code, 1, len, f) != len;
1700call 0 never executed
1701 #####: 1399: if (fclose(f) != 0) bad = 1;
1702call 0 never executed
1703branch 1 never executed (fallthrough)
1704branch 2 never executed
1705 #####: 1400: if (bad) { unlink(path); BW_DIAG("omega_kernel_dump: write failed, removed %s\n", path); }
1706branch 0 never executed (fallthrough)
1707branch 1 never executed
1708call 2 never executed
1709call 3 never executed
1710 -: 1401:#else
1711 -: 1402: (void)code; (void)len;
1712 -: 1403:#endif
1713 -: 1404:}
1714 -: 1405:
1715 -: 1406:#ifdef BW_ENC_C_PRIMARY
1716 -: 1407:static int bw_encode_program_bytes(const BlackwellIRProgram *prog, uint8_t *code_buf, size_t req_bytes) {
1717 -: 1408: size_t padded_insns = req_bytes / 16;
1718 -: 1409: uint8_t *p = code_buf;
1719 -: 1410: for (size_t i = 0; i < padded_insns; i++) {
1720 -: 1411: uint32_t w[4];
1721 -: 1412: if (i < prog->count) {
1722 -: 1413: if (encode_single_insn(&prog->insns[i], &prog->regalloc, w) != 0) {
1723 -: 1414: return -1;
1724 -: 1415: }
1725 -: 1416: } else {
1726 -: 1417: /* Pad with NOP */
1727 -: 1418: w[0] = 0x00007918;
1728 -: 1419: w[1] = 0x00000000;
1729 -: 1420: w[2] = 0x00000000;
1730 -: 1421: w[3] = 0x000fc000;
1731 -: 1422: }
1732 -: 1423: for (int k = 0; k < 4; k++) {
1733 -: 1424: p[4 * k] = (uint8_t)(w[k] & 0xff);
1734 -: 1425: p[4 * k + 1] = (uint8_t)((w[k] >> 8) & 0xff);
1735 -: 1426: p[4 * k + 2] = (uint8_t)((w[k] >> 16) & 0xff);
1736 -: 1427: p[4 * k + 3] = (uint8_t)((w[k] >> 24) & 0xff);
1737 -: 1428: }
1738 -: 1429: p += 16;
1739 -: 1430: }
1740 -: 1431: return 0;
1741 -: 1432:}
1742 -: 1433:#else
1743function bw_encode_program_bytes called 272 returned 100% blocks executed 100%
1744 272: 1434:static int bw_encode_program_bytes(const BlackwellIRProgram *prog, uint8_t *code_buf, size_t req_bytes) {
1745 -: 1435: uint8_t code[BW_OM_CODE_LEN];
1746 272: 1436: size_t got = bw_om_encode(prog->insns, prog->count, &prog->regalloc, 1, code);
1747call 0 returned 272
1748 272: 1437: int rc = (got == req_bytes && got != 0) ? 0 : -1;
1749branch 0 taken 271 (fallthrough)
1750branch 1 taken 1
1751branch 2 taken 271 (fallthrough)
1752branch 3 taken 0
1753 -: 1438:#ifdef CUDAPP_MIGRATION_PENDING_ENCODER_DIFF
1754 -: 1439: /* The C oracle encodes the same program, instruction by instruction, NOP-padded the same way. */
1755 -: 1440:#ifdef CUDAPP_ENCODER_DIFF_SELFTEST
1756 -: 1441: if (rc == 0) code[0] ^= 1; /* red check of the comparison itself: one flipped bit must abort */
1757 -: 1442:#endif
1758 -: 1443: uint8_t ref[BW_OM_CODE_LEN];
1759 -: 1444: int crc = 0;
1760 -: 1445: for (size_t i = 0; i < req_bytes / 16 && crc == 0; i++) {
1761 -: 1446: uint32_t w[4] = { 0x00007918, 0, 0, 0x000fc000 };
1762 -: 1447: if (i < prog->count) crc = bw_c_encode_insn(&prog->insns[i], &prog->regalloc, w);
1763 -: 1448: for (int k = 0; k < 16; k++) ref[16 * i + (size_t)k] = (uint8_t)(w[k / 4] >> (8 * (k % 4)));
1764 -: 1449: }
1765 -: 1450: bw_enc_diff_note("program", prog->count, rc == 0 ? code : NULL, rc == 0 ? req_bytes : 0,
1766 -: 1451: crc == rc && (rc != 0 || memcmp(code, ref, req_bytes) == 0));
1767 -: 1452:#endif
1768 272: 1453: if (rc == 0) memcpy(code_buf, code, req_bytes);
1769branch 0 taken 271 (fallthrough)
1770branch 1 taken 1
1771 272: 1454: return rc;
1772 -: 1455:}
1773 -: 1456:#endif
1774 -: 1457:
1775function legacy_omega_bw_encode_program called 272 returned 100% blocks executed 86%
1776 272: 1458:int omega_bw_encode_program(const BlackwellIRProgram *prog, uint8_t *code_buf, size_t max_len, size_t *out_len) {
1777 272*: 1459: if (!prog || !code_buf || !out_len) return -1;
1778branch 0 taken 272 (fallthrough)
1779branch 1 taken 0
1780branch 2 taken 272 (fallthrough)
1781branch 3 taken 0
1782branch 4 taken 0 (fallthrough)
1783branch 5 taken 272
1784 -: 1460:
1785 -: 1461:#ifndef BW_BIND_C_PRIMARY
1786 272: 1462: uint8_t bw[256] = {0};
1787 272: 1463: int64_t fit = omega_bw_bind(6, (uint64_t)prog->count, max_len, bw);
1788call 0 returned 272
1789 272*: 1464: if (fit < 0) return -1;
1790branch 0 taken 0 (fallthrough)
1791branch 1 taken 272
1792 272: 1465: size_t req_bytes = (size_t)fit;
1793 -: 1466:#else
1794 -: 1467: size_t padded_insns = (prog->count + 7) & ~7ULL;
1795 -: 1468: if (padded_insns < 32) padded_insns = 32;
1796 -: 1469:
1797 -: 1470: size_t req_bytes = padded_insns * 16;
1798 -: 1471: if (max_len < req_bytes) return -1;
1799 -: 1472:#endif
1800 -: 1473:
1801 272: 1474: if (bw_encode_program_bytes(prog, code_buf, req_bytes) != 0) return -1;
1802call 0 returned 272
1803branch 1 taken 1 (fallthrough)
1804branch 2 taken 271
1805 -: 1475:#ifdef CUDAPP_AMPERE_CORPUS
1806 -: 1476: /* Offline-only capture of the original solved IR, before family raw patches. */
1807 -: 1477: extern void omega_ampere_corpus_capture(const BlackwellIRProgram *, const uint8_t *, size_t);
1808 -: 1478: omega_ampere_corpus_capture(prog, code_buf, req_bytes);
1809 -: 1479:#endif
1810 -: 1480:
1811 271: 1481: omega_kernel_dump(code_buf, req_bytes);
1812call 0 returned 271
1813 271: 1482: *out_len = req_bytes;
1814 271: 1483: return 0;
1815 -: 1484:}
1816 -: 1485:
1817 -: 1486:#ifndef BW_MATMUL_C_PRIMARY
1818 -: 1487:/* ABI and memory routing only; validation, schedules and lifetime hints are seeded Omega. */
1819function bw_om_matprog called 0 returned 0% blocks executed 0%
1820 #####: 1488:static int bw_om_matprog(OmegaOmIrUnit unit, const OmegaMatMulSpec *s, uint32_t grid,
1821 -: 1489: uint32_t u, uint32_t rt, uint32_t ct, int mutant, BlackwellIRProgram *p) {
1822 #####: 1490: if (!s || !p) return -1;
1823branch 0 never executed (fallthrough)
1824branch 1 never executed
1825branch 2 never executed (fallthrough)
1826branch 3 never executed
1827 #####: 1491: uint64_t controls = UINT64_MAX;
1828 #####: 1492: if (omega_cg_par(&controls, grid, u, rt, ct, (uint64_t)(int64_t)mutant) != 0 ||
1829call 0 never executed
1830branch 1 never executed (fallthrough)
1831branch 2 never executed
1832 #####: 1493: controls == UINT64_MAX) return -1;
1833branch 0 never executed (fallthrough)
1834branch 1 never executed
1835 #####: 1494: uint64_t a = (uint64_t)s->m | ((uint64_t)s->k << 32);
1836 #####: 1495: uint64_t b = (uint64_t)s->n | ((uint64_t)(uint32_t)s->precision << 32);
1837 #####: 1496: return omega_gpu_om_ir_replay(unit, 0, a, b, controls, p, NULL) == OMEGA_OM_IR_OK ? 0 : -1;
1838call 0 never executed
1839branch 1 never executed (fallthrough)
1840branch 2 never executed
1841 -: 1497:}
1842 -: 1498:#endif
1843 -: 1499:#ifdef BW_MATMUL_C_PRIMARY
1844 -: 1500:int omega_blackwell_codegen_matmul_i32_prog(const OmegaMatMulSpec *spec, BlackwellIRProgram *prog) {
1845 -: 1501: if (!spec || !prog) return -1;
1846 -: 1502: if (spec->m == 0 || spec->k == 0 || spec->n == 0) return -1;
1847 -: 1503:
1848 -: 1504: /* Fail closed loudly if K exceeds bounded unroll limit */
1849 -: 1505: if (spec->k > 32) {
1850 -: 1506: BW_DIAG("ERROR: MatMul integer codegen exceeds bounded unroll limit (K=%u > 32)\n", spec->k);
1851 -: 1507: return -1;
1852 -: 1508: }
1853 -: 1509:
1854 -: 1510: omega_bw_ir_init(prog);
1855 -: 1511:
1856 -: 1512: /* 1. Allocate virtual registers */
1857 -: 1513: /* 64-bit base pointers */
1858 -: 1514: int v_ptr_a = omega_bw_ir_alloc_vreg64(prog);
1859 -: 1515: int v_ptr_b = omega_bw_ir_alloc_vreg64(prog);
1860 -: 1516: int v_ptr_c = omega_bw_ir_alloc_vreg64(prog);
1861 -: 1517: int uv_desc = omega_bw_ir_alloc_uvreg64(prog);
1862 -: 1518:
1863 -: 1519: /* 32-bit CTA / Thread indexing */
1864 -: 1520: int v_ctaid_x = omega_bw_ir_alloc_vreg(prog);
1865 -: 1521: int v_ctaid_y = omega_bw_ir_alloc_vreg(prog);
1866 -: 1522: int v_tid_x = omega_bw_ir_alloc_vreg(prog);
1867 -: 1523: int v_tid_y = omega_bw_ir_alloc_vreg(prog);
1868 -: 1524:
1869 -: 1525: /* 2D Coordinates & loop invariants */
1870 -: 1526: int v_col = omega_bw_ir_alloc_vreg(prog);
1871 -: 1527: int v_row = omega_bw_ir_alloc_vreg(prog);
1872 -: 1528: int v_row_k = omega_bw_ir_alloc_vreg(prog);
1873 -: 1529: int v_const_1 = omega_bw_ir_alloc_vreg(prog);
1874 -: 1530: int v_acc = omega_bw_ir_alloc_vreg(prog);
1875 -: 1531:
1876 -: 1532: /* Working registers for memory address and operands */
1877 -: 1533: int v_idx_a = omega_bw_ir_alloc_vreg(prog);
1878 -: 1534: int v_off_a = omega_bw_ir_alloc_vreg64(prog);
1879 -: 1535: int v_val_a = omega_bw_ir_alloc_vreg(prog);
1880 -: 1536:
1881 -: 1537: int v_idx_b = omega_bw_ir_alloc_vreg(prog);
1882 -: 1538: int v_off_b = omega_bw_ir_alloc_vreg64(prog);
1883 -: 1539: int v_val_b = omega_bw_ir_alloc_vreg(prog);
1884 -: 1540:
1885 -: 1541: int v_idx_c = omega_bw_ir_alloc_vreg(prog);
1886 -: 1542: int v_off_c = omega_bw_ir_alloc_vreg64(prog);
1887 -: 1543:
1888 -: 1544: if (v_off_c < 0) return -1;
1889 -: 1545:
1890 -: 1546: /* 2. Load 64-bit global memory descriptor into uniform register pair */
1891 -: 1547: /* LDCU.64 uv_desc, c[0x0][0x358] */
1892 -: 1548: BlackwellIRInsn insn_desc = { .op = BW_IR_LDCU64, .dst_vreg = uv_desc, .imm = 0x358, .is_uniform = true };
1893 -: 1549: omega_bw_ir_append(prog, &insn_desc);
1894 -: 1550:
1895 -: 1551: /* 3. Load 64-bit base pointers from Constant Bank 0 */
1896 -: 1552: /* LDC.64 v_ptr_a, c[0x0][0x380] */
1897 -: 1553: BlackwellIRInsn insn_ptra = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_a, .imm = 0x380 };
1898 -: 1554: omega_bw_ir_append(prog, &insn_ptra);
1899 -: 1555:
1900 -: 1556: /* LDC.64 v_ptr_b, c[0x0][0x388] */
1901 -: 1557: BlackwellIRInsn insn_ptrb = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_b, .imm = 0x388 };
1902 -: 1558: omega_bw_ir_append(prog, &insn_ptrb);
1903 -: 1559:
1904 -: 1560: /* LDC.64 v_ptr_c, c[0x0][0x390] */
1905 -: 1561: BlackwellIRInsn insn_ptrc = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_c, .imm = 0x390 };
1906 -: 1562: omega_bw_ir_append(prog, &insn_ptrc);
1907 -: 1563:
1908 -: 1564: /* 4. Query 2D CTA and Thread coordinates */
1909 -: 1565: /* S2R v_ctaid_x, SR_CTAID.X */
1910 -: 1566: BlackwellIRInsn insn_ctax = { .op = BW_IR_S2R, .dst_vreg = v_ctaid_x, .imm = BW_SR_CTAID_X };
1911 -: 1567: omega_bw_ir_append(prog, &insn_ctax);
1912 -: 1568:
1913 -: 1569: /* S2R v_ctaid_y, SR_CTAID.Y */
1914 -: 1570: BlackwellIRInsn insn_ctay = { .op = BW_IR_S2R, .dst_vreg = v_ctaid_y, .imm = BW_SR_CTAID_Y };
1915 -: 1571: omega_bw_ir_append(prog, &insn_ctay);
1916 -: 1572:
1917 -: 1573: /* S2R v_tid_x, SR_TID.X */
1918 -: 1574: BlackwellIRInsn insn_tidx = { .op = BW_IR_S2R, .dst_vreg = v_tid_x, .imm = BW_SR_TID_X };
1919 -: 1575: omega_bw_ir_append(prog, &insn_tidx);
1920 -: 1576:
1921 -: 1577: /* S2R v_tid_y, SR_TID.Y */
1922 -: 1578: BlackwellIRInsn insn_tidy = { .op = BW_IR_S2R, .dst_vreg = v_tid_y, .imm = BW_SR_TID_Y };
1923 -: 1579: omega_bw_ir_append(prog, &insn_tidy);
1924 -: 1580:
1925 -: 1581: /* 5. Compute 2D (row, col) coordinates */
1926 -: 1582: /* Standard 16x16 tile threads: col = ctaid_x * 16 + tid_x */
1927 -: 1583: BlackwellIRInsn insn_col = { .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_ctaid_x, .src2_vreg = -1, .imm = 16, .src3_vreg = v_tid_x };
1928 -: 1584: omega_bw_ir_append(prog, &insn_col);
1929 -: 1585:
1930 -: 1586: /* row = ctaid_y * 16 + tid_y */
1931 -: 1587: BlackwellIRInsn insn_row = { .op = BW_IR_IMAD, .dst_vreg = v_row, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = 16, .src3_vreg = v_tid_y };
1932 -: 1588: omega_bw_ir_append(prog, &insn_row);
1933 -: 1589:
1934 -: 1590: /* 6. Precompute row base index: v_row_k = v_row * K + RZ */
1935 -: 1591: BlackwellIRInsn insn_row_k = { .op = BW_IR_IMAD, .dst_vreg = v_row_k, .src1_vreg = v_row, .src2_vreg = -1, .imm = spec->k, .src3_vreg = -1 };
1936 -: 1592: omega_bw_ir_append(prog, &insn_row_k);
1937 -: 1593:
1938 -: 1594: /* 7. Initialize v_const_1 = 1 for immediate linear indexing */
1939 -: 1595: BlackwellIRInsn insn_c1 = { .op = BW_IR_MOV_IMM, .dst_vreg = v_const_1, .imm = 1 };
1940 -: 1596: omega_bw_ir_append(prog, &insn_c1);
1941 -: 1597:
1942 -: 1598: /* 8. Initialize accumulator to zero: MOV v_acc, RZ */
1943 -: 1599: BlackwellIRInsn insn_init_acc = { .op = BW_IR_MOV_RZ, .dst_vreg = v_acc };
1944 -: 1600: omega_bw_ir_append(prog, &insn_init_acc);
1945 -: 1601:
1946 -: 1602: /* 9. Synthesize inner accumulation loop across K iterations */
1947 -: 1603: for (uint32_t step = 0; step < spec->k; step++) {
1948 -: 1604: /* A[row, step]: idx_a = v_row_k + step = v_const_1 * step + v_row_k */
1949 -: 1605: BlackwellIRInsn insn_idxa = { .op = BW_IR_IMAD, .dst_vreg = v_idx_a, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = step, .src3_vreg = v_row_k };
1950 -: 1606: omega_bw_ir_append(prog, &insn_idxa);
1951 -: 1607:
1952 -: 1608: /* off_a = v_ptr_a + idx_a * 4 */
1953 -: 1609: BlackwellIRInsn insn_offa = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off_a, .src1_vreg = v_idx_a, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_a };
1954 -: 1610: omega_bw_ir_append(prog, &insn_offa);
1955 -: 1611:
1956 -: 1612: /* Load A[row, step]: LDG.E v_val_a, desc[uv_desc][v_off_a.64] */
1957 -: 1613: BlackwellIRInsn insn_lda = { .op = BW_IR_LDG_E, .dst_vreg = v_val_a, .src1_vreg = v_off_a, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x001ea800 };
1958 -: 1614: omega_bw_ir_append(prog, &insn_lda);
1959 -: 1615:
1960 -: 1616: /* B[step, col]: idx_b = step * N + col = v_const_1 * (step * N) + v_col */
1961 -: 1617: uint32_t step_n = step * spec->n;
1962 -: 1618: BlackwellIRInsn insn_idxb = { .op = BW_IR_IMAD, .dst_vreg = v_idx_b, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = step_n, .src3_vreg = v_col };
1963 -: 1619: omega_bw_ir_append(prog, &insn_idxb);
1964 -: 1620:
1965 -: 1621: /* off_b = v_ptr_b + idx_b * 4 */
1966 -: 1622: BlackwellIRInsn insn_offb = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off_b, .src1_vreg = v_idx_b, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_b };
1967 -: 1623: omega_bw_ir_append(prog, &insn_offb);
1968 -: 1624:
1969 -: 1625: /* Load B[step, col]: LDG.E v_val_b, desc[uv_desc][v_off_b.64] */
1970 -: 1626: BlackwellIRInsn insn_ldb = { .op = BW_IR_LDG_E, .dst_vreg = v_val_b, .src1_vreg = v_off_b, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x002ea800 };
1971 -: 1627: omega_bw_ir_append(prog, &insn_ldb);
1972 -: 1628:
1973 -: 1629: /* Multiply and accumulate: IMAD v_acc, v_val_a, v_val_b, v_acc */
1974 -: 1630: BlackwellIRInsn insn_acc = { .op = BW_IR_IMAD, .dst_vreg = v_acc, .src1_vreg = v_val_a, .src2_vreg = v_val_b, .src3_vreg = v_acc, .control = 0x004fca00 };
1975 -: 1631: omega_bw_ir_append(prog, &insn_acc);
1976 -: 1632: }
1977 -: 1633:
1978 -: 1634: /* 10. Compute output index: idx_c = row * N + col */
1979 -: 1635: BlackwellIRInsn insn_idxc = { .op = BW_IR_IMAD, .dst_vreg = v_idx_c, .src1_vreg = v_row, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_col };
1980 -: 1636: omega_bw_ir_append(prog, &insn_idxc);
1981 -: 1637:
1982 -: 1638: /* off_c = v_ptr_c + idx_c * 4 */
1983 -: 1639: BlackwellIRInsn insn_offc = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off_c, .src1_vreg = v_idx_c, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c };
1984 -: 1640: omega_bw_ir_append(prog, &insn_offc);
1985 -: 1641:
1986 -: 1642: /* Store C[row, col]: STG.E desc[uv_desc][v_off_c.64], v_acc */
1987 -: 1643: BlackwellIRInsn insn_stc = { .op = BW_IR_STG_E, .src1_vreg = v_off_c, .src2_vreg = v_acc, .src3_vreg = -1, .ureg = uv_desc };
1988 -: 1644: omega_bw_ir_append(prog, &insn_stc);
1989 -: 1645:
1990 -: 1646: /* 11. Kernel termination */
1991 -: 1647: BlackwellIRInsn insn_exit = { .op = BW_IR_EXIT, .predicate_p0 = false };
1992 -: 1648: omega_bw_ir_append(prog, &insn_exit);
1993 -: 1649:
1994 -: 1650: BlackwellIRInsn insn_bra = { .op = BW_IR_BRA };
1995 -: 1651: omega_bw_ir_append(prog, &insn_bra);
1996 -: 1652:
1997 -: 1653: /* 12. Solve bounded deterministic register allocation */
1998 -: 1654: if (omega_bw_regalloc_solve(prog) != 0) {
1999 -: 1655: return -1;
2000 -: 1656: }
2001 -: 1657: return 0;
2002 -: 1658:}
2003 -: 1659:#else
2004function legacy_omega_blackwell_codegen_matmul_i32_prog called 0 returned 0% blocks executed 0%
2005 #####: 1660:int omega_blackwell_codegen_matmul_i32_prog(const OmegaMatMulSpec *s, BlackwellIRProgram *p) {
2006 #####: 1661: return bw_om_matprog(omega_cg_i32, s, 0, 0, 0, 0, 0, p);
2007call 0 never executed
2008 -: 1662:}
2009 -: 1663:#endif
2010 -: 1664:
2011 -: 1665:/* ---- native v1 P07 cut A.2: allocation-free kernel encoding ---------------------------------
2012 -: 1666: * The one place a solved IR program becomes a kernel. Hosted and freestanding builds both encode
2013 -: 1667: * through it, so the two produce the same bytes for the same program (make test-codegen-freestanding
2014 -: 1668: * compares them). */
2015function legacy_omega_bw_program_code_bytes called 0 returned 0% blocks executed 0%
2016 #####: 1669:size_t omega_bw_program_code_bytes(const BlackwellIRProgram *prog) {
2017 #####: 1670: if (!prog) return 0;
2018branch 0 never executed (fallthrough)
2019branch 1 never executed
2020 -: 1671:#ifndef BW_BIND_C_PRIMARY
2021 #####: 1672: uint8_t w[256] = {0};
2022 #####: 1673: return (size_t)omega_bw_bind(5, (uint64_t)prog->count, 0, w);
2023call 0 never executed
2024 -: 1674:#else
2025 -: 1675: size_t padded_insns = (prog->count + 7) & ~(size_t)7;
2026 -: 1676: if (padded_insns < 32) padded_insns = 32;
2027 -: 1677: return padded_insns * 16;
2028 -: 1678:#endif
2029 -: 1679:}
2030 -: 1680:
2031function legacy_omega_blackwell_kernel_encode_into called 130 returned 100% blocks executed 81%
2032 130: 1681:int omega_blackwell_kernel_encode_into(const BlackwellIRProgram *prog, uint8_t *code_buf, size_t code_cap,
2033 -: 1682: OmegaBlackwellKernel *kernel) {
2034 130*: 1683: if (!kernel) return -1;
2035branch 0 taken 0 (fallthrough)
2036branch 1 taken 130
2037 130: 1684: memset(kernel, 0, sizeof *kernel);
2038 130*: 1685: if (!prog || !code_buf) return -1;
2039branch 0 taken 130 (fallthrough)
2040branch 1 taken 0
2041branch 2 taken 0 (fallthrough)
2042branch 3 taken 130
2043 -: 1686:#ifndef BW_BIND_C_PRIMARY
2044 130: 1687: uint8_t w[256] = {0};
2045 -: 1688: /* refused before any byte is written */
2046 130: 1689: if (omega_bw_bind(6, (uint64_t)prog->count, code_cap, w) == -2) return OMEGA_BW_CODE_BUFFER_TOO_SMALL;
2047call 0 returned 130
2048branch 1 taken 65 (fallthrough)
2049branch 2 taken 65
2050 65: 1690: size_t emitted_size = 0;
2051 65*: 1691: if (omega_bw_encode_program(prog, code_buf, code_cap, &emitted_size) != 0) return -1;
2052call 0 returned 65
2053branch 1 taken 0 (fallthrough)
2054branch 2 taken 65
2055 65: 1692: kernel->code = code_buf;
2056 65: 1693: kernel->code_size = emitted_size;
2057 65: 1694: kernel->insn_count = (size_t)omega_bw_bind(8, emitted_size, 0, w);
2058call 0 returned 65
2059 -: 1695:#else
2060 -: 1696: size_t need = omega_bw_program_code_bytes(prog);
2061 -: 1697: if (code_cap < need) return OMEGA_BW_CODE_BUFFER_TOO_SMALL; /* refused before any byte is written */
2062 -: 1698: size_t emitted_size = 0;
2063 -: 1699: if (omega_bw_encode_program(prog, code_buf, code_cap, &emitted_size) != 0) return -1;
2064 -: 1700: kernel->code = code_buf;
2065 -: 1701: kernel->code_size = emitted_size;
2066 -: 1702: kernel->insn_count = emitted_size / 16;
2067 -: 1703:#endif
2068 65: 1704: kernel->gpr_count = prog->regalloc.peak_gpr_usage;
2069 65: 1705: kernel->uniform_gpr_count = prog->regalloc.peak_ugpr_usage;
2070 65: 1706: sha256_hash(kernel->code, kernel->code_size, kernel->code_digest);
2071call 0 returned 65
2072 65: 1707: return 0;
2073 -: 1708:}
2074 -: 1709:
2075 -: 1710:#ifndef OMEGA_GPU_NO_POSIX
2076 -: 1711:/* Hosted only: the allocating generators keep their names, caps and behavior. Each builds the program,
2077 -: 1712: * mallocs max_bytes (the cap each generator always had) and encodes through omega_blackwell_kernel_encode_into;
2078 -: 1713: * omega_blackwell_kernel_free releases the buffer. */
2079function bw_kernel_alloc_encode called 0 returned 0% blocks executed 0%
2080 #####: 1714:static int bw_kernel_alloc_encode(const BlackwellIRProgram *prog, size_t max_bytes, OmegaBlackwellKernel *kernel) {
2081 #####: 1715: uint8_t *buf = (uint8_t *)malloc(max_bytes);
2082 #####: 1716: if (!buf) { kernel->code = NULL; return -1; }
2083branch 0 never executed (fallthrough)
2084branch 1 never executed
2085 #####: 1717: if (omega_blackwell_kernel_encode_into(prog, buf, max_bytes, kernel) != 0) {
2086call 0 never executed
2087branch 1 never executed (fallthrough)
2088branch 2 never executed
2089 #####: 1718: free(buf);
2090 #####: 1719: kernel->code = NULL;
2091 #####: 1720: return -1;
2092 -: 1721: }
2093 #####: 1722: return 0;
2094 -: 1723:}
2095 -: 1724:
2096function legacy_omega_blackwell_codegen_matmul_i32 called 0 returned 0% blocks executed 0%
2097 #####: 1725:int omega_blackwell_codegen_matmul_i32(const OmegaMatMulSpec *spec, OmegaBlackwellKernel *kernel) {
2098 #####: 1726: if (!spec || !kernel) return -1;
2099branch 0 never executed (fallthrough)
2100branch 1 never executed
2101branch 2 never executed (fallthrough)
2102branch 3 never executed
2103 -: 1727: BlackwellIRProgram prog;
2104 #####: 1728: if (omega_blackwell_codegen_matmul_i32_prog(spec, &prog) != 0) return -1;
2105call 0 never executed
2106branch 1 never executed (fallthrough)
2107branch 2 never executed
2108 -: 1729: /* 13. the code buffer is exactly the padded program (the i32 generator never had a fixed cap) */
2109 #####: 1730: return bw_kernel_alloc_encode(&prog, omega_bw_program_code_bytes(&prog), kernel);
2110call 0 never executed
2111call 1 never executed
2112 -: 1731:}
2113 -: 1732:#endif
2114 -: 1733:
2115 -: 1734:#ifdef BW_MATMUL_C_PRIMARY
2116 -: 1735:int omega_blackwell_codegen_matmul_tensor_prog(const OmegaMatMulSpec *spec, BlackwellIRProgram *prog) {
2117 -: 1736: if (!spec || !prog) return -1;
2118 -: 1737: if (spec->m == 0 || spec->k == 0 || spec->n == 0) return -1;
2119 -: 1738: if (spec->precision != OMEGA_MATMUL_PRECISION_FP16 && spec->precision != OMEGA_MATMUL_PRECISION_BF16) return -1;
2120 -: 1739: if (spec->m % 16 != 0 || spec->n % 8 != 0 || spec->k != 16) {
2121 -: 1740: BW_DIAG("ERROR: MatMul tensor codegen requires M multiple of 16, N multiple of 8, K=16 (got %ux%ux%u)\n",
2122 -: 1741: spec->m, spec->k, spec->n);
2123 -: 1742: return -1;
2124 -: 1743: }
2125 -: 1744:
2126 -: 1745: omega_bw_ir_init(prog);
2127 -: 1746:
2128 -: 1747: /* 1. Allocate virtual registers */
2129 -: 1748: /* 64-bit base pointers */
2130 -: 1749: int v_ptr_a = omega_bw_ir_alloc_vreg64(prog);
2131 -: 1750: int v_ptr_b = omega_bw_ir_alloc_vreg64(prog);
2132 -: 1751: int v_ptr_c = omega_bw_ir_alloc_vreg64(prog);
2133 -: 1752: int uv_desc = omega_bw_ir_alloc_uvreg64(prog);
2134 -: 1753:
2135 -: 1754: /* 32-bit CTA / Thread indexing */
2136 -: 1755: int v_tid = omega_bw_ir_alloc_vreg(prog);
2137 -: 1756: int v_ctaid_x = omega_bw_ir_alloc_vreg(prog);
2138 -: 1757: int v_ctaid_y = omega_bw_ir_alloc_vreg(prog);
2139 -: 1758:
2140 -: 1759: /* Tile and thread coordinates */
2141 -: 1760: int v_group_id = omega_bw_ir_alloc_vreg(prog);
2142 -: 1761: int v_tid_in_grp = omega_bw_ir_alloc_vreg(prog);
2143 -: 1762: int v_row_base = omega_bw_ir_alloc_vreg(prog);
2144 -: 1763: int v_col_base = omega_bw_ir_alloc_vreg(prog);
2145 -: 1764: int v_r0 = omega_bw_ir_alloc_vreg(prog);
2146 -: 1765: int v_r1 = omega_bw_ir_alloc_vreg(prog);
2147 -: 1766: int v_col_b = omega_bw_ir_alloc_vreg(prog);
2148 -: 1767: int v_tid_col2 = omega_bw_ir_alloc_vreg(prog);
2149 -: 1768: int v_const_1 = omega_bw_ir_alloc_vreg(prog);
2150 -: 1769:
2151 -: 1770: /* Bundles for HMMA */
2152 -: 1771: int v_ra = omega_bw_ir_alloc_vreg128(prog); /* Quad: Ra[0]..Ra[3] */
2153 -: 1772: int v_rb = omega_bw_ir_alloc_vreg64(prog); /* Pair: Rb[0]..Rb[1] */
2154 -: 1773: int v_rd = omega_bw_ir_alloc_vreg128(prog); /* Quad: Rd[0]..Rd[3] */
2155 -: 1774:
2156 -: 1775: /* Scratch registers for indexing and loads */
2157 -: 1776: int v_idx = omega_bw_ir_alloc_vreg(prog);
2158 -: 1777: int v_off = omega_bw_ir_alloc_vreg64(prog);
2159 -: 1778: int v_b_tmp0 = omega_bw_ir_alloc_vreg(prog);
2160 -: 1779: int v_b_tmp1 = omega_bw_ir_alloc_vreg(prog);
2161 -: 1780:
2162 -: 1781: if (v_b_tmp1 < 0) return -1;
2163 -: 1782:
2164 -: 1783: /* 2. Load 64-bit global memory descriptor into uniform register pair */
2165 -: 1784: /* LDCU.64 uv_desc, c[0x0][0x358] */
2166 -: 1785: BlackwellIRInsn insn_desc = { .op = BW_IR_LDCU64, .dst_vreg = uv_desc, .imm = 0x358, .is_uniform = true };
2167 -: 1786: omega_bw_ir_append(prog, &insn_desc);
2168 -: 1787:
2169 -: 1788: /* 3. Load 64-bit base pointers from Constant Bank 0 */
2170 -: 1789: /* LDC.64 v_ptr_a, c[0x0][0x380] */
2171 -: 1790: BlackwellIRInsn insn_ptra = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_a, .imm = 0x380 };
2172 -: 1791: omega_bw_ir_append(prog, &insn_ptra);
2173 -: 1792:
2174 -: 1793: /* LDC.64 v_ptr_b, c[0x0][0x388] */
2175 -: 1794: BlackwellIRInsn insn_ptrb = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_b, .imm = 0x388 };
2176 -: 1795: omega_bw_ir_append(prog, &insn_ptrb);
2177 -: 1796:
2178 -: 1797: /* LDC.64 v_ptr_c, c[0x0][0x390] */
2179 -: 1798: BlackwellIRInsn insn_ptrc = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_c, .imm = 0x390 };
2180 -: 1799: omega_bw_ir_append(prog, &insn_ptrc);
2181 -: 1800:
2182 -: 1801: /* 4. Query Special Registers */
2183 -: 1802: /* S2R v_tid, SR_TID.X */
2184 -: 1803: BlackwellIRInsn insn_tidx = { .op = BW_IR_S2R, .dst_vreg = v_tid, .imm = BW_SR_TID_X };
2185 -: 1804: omega_bw_ir_append(prog, &insn_tidx);
2186 -: 1805:
2187 -: 1806: /* S2R v_ctaid_x, SR_CTAID.X */
2188 -: 1807: BlackwellIRInsn insn_cta_x = { .op = BW_IR_S2R, .dst_vreg = v_ctaid_x, .imm = BW_SR_CTAID_X };
2189 -: 1808: omega_bw_ir_append(prog, &insn_cta_x);
2190 -: 1809:
2191 -: 1810: /* S2R v_ctaid_y, SR_CTAID.Y */
2192 -: 1811: BlackwellIRInsn insn_cta_y = { .op = BW_IR_S2R, .dst_vreg = v_ctaid_y, .imm = BW_SR_CTAID_Y };
2193 -: 1812: omega_bw_ir_append(prog, &insn_cta_y);
2194 -: 1813:
2195 -: 1814: /* 5. Set up constant 1 */
2196 -: 1815: BlackwellIRInsn insn_c1 = { .op = BW_IR_MOV_IMM, .dst_vreg = v_const_1, .imm = 1 };
2197 -: 1816: omega_bw_ir_append(prog, &insn_c1);
2198 -: 1817:
2199 -: 1818: /* 6. Extract warp-level tile and thread coordinates */
2200 -: 1819: /* group_id = tid >> 2 */
2201 -: 1820: BlackwellIRInsn insn_grp = { .op = BW_IR_SHF_R, .dst_vreg = v_group_id, .src1_vreg = v_tid, .imm = 2 };
2202 -: 1821: omega_bw_ir_append(prog, &insn_grp);
2203 -: 1822:
2204 -: 1823: /* tid_in_grp = tid & 3 */
2205 -: 1824: BlackwellIRInsn insn_tig = { .op = BW_IR_LOP3_AND, .dst_vreg = v_tid_in_grp, .src1_vreg = v_tid, .imm = 3 };
2206 -: 1825: omega_bw_ir_append(prog, &insn_tig);
2207 -: 1826:
2208 -: 1827: /* row_base = ctaid_y * 16 */
2209 -: 1828: BlackwellIRInsn insn_rbase = { .op = BW_IR_IMAD, .dst_vreg = v_row_base, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = 16, .src3_vreg = -1 };
2210 -: 1829: omega_bw_ir_append(prog, &insn_rbase);
2211 -: 1830:
2212 -: 1831: /* col_base = ctaid_x * 8 */
2213 -: 1832: BlackwellIRInsn insn_cbase = { .op = BW_IR_IMAD, .dst_vreg = v_col_base, .src1_vreg = v_ctaid_x, .src2_vreg = -1, .imm = 8, .src3_vreg = -1 };
2214 -: 1833: omega_bw_ir_append(prog, &insn_cbase);
2215 -: 1834:
2216 -: 1835: /* r0 = row_base + group_id */
2217 -: 1836: BlackwellIRInsn insn_r0 = { .op = BW_IR_IADD3, .dst_vreg = v_r0, .src1_vreg = v_row_base, .src2_vreg = v_group_id, .src3_vreg = -1 };
2218 -: 1837: omega_bw_ir_append(prog, &insn_r0);
2219 -: 1838:
2220 -: 1839: /* r1 = r0 + 8 */
2221 -: 1840: BlackwellIRInsn insn_r1 = { .op = BW_IR_IMAD, .dst_vreg = v_r1, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 8, .src3_vreg = v_r0 };
2222 -: 1841: omega_bw_ir_append(prog, &insn_r1);
2223 -: 1842:
2224 -: 1843: /* col_b = col_base + group_id */
2225 -: 1844: BlackwellIRInsn insn_colb = { .op = BW_IR_IADD3, .dst_vreg = v_col_b, .src1_vreg = v_col_base, .src2_vreg = v_group_id, .src3_vreg = -1 };
2226 -: 1845: omega_bw_ir_append(prog, &insn_colb);
2227 -: 1846:
2228 -: 1847: /* tid_col2 = tid_in_grp * 2 */
2229 -: 1848: BlackwellIRInsn insn_tcol2 = { .op = BW_IR_IMAD, .dst_vreg = v_tid_col2, .src1_vreg = v_tid_in_grp, .src2_vreg = -1, .imm = 2, .src3_vreg = -1 };
2230 -: 1849: omega_bw_ir_append(prog, &insn_tcol2);
2231 -: 1850:
2232 -: 1851: /* 7. Load A fragments (16x16 row-major, 2 bytes/element, row stride 32 bytes) */
2233 -: 1852: /* Pair 0: a0, a1 at r0 * 32 + tid_col2 * 2 */
2234 -: 1853: BlackwellIRInsn insn_a0_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = 32, .src3_vreg = -1 };
2235 -: 1854: omega_bw_ir_append(prog, &insn_a0_idx1);
2236 -: 1855: BlackwellIRInsn insn_a0_idx2 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = 2, .src3_vreg = v_idx };
2237 -: 1856: omega_bw_ir_append(prog, &insn_a0_idx2);
2238 -: 1857: BlackwellIRInsn insn_a0_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 1, .src3_vreg = v_ptr_a };
2239 -: 1858: omega_bw_ir_append(prog, &insn_a0_off);
2240 -: 1859: BlackwellIRInsn insn_lda0 = { .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 0, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x001ea800 };
2241 -: 1860: omega_bw_ir_append(prog, &insn_lda0);
2242 -: 1861:
2243 -: 1862: /* Pair 1: a2, a3 at r1 * 32 + tid_col2 * 2 */
2244 -: 1863: BlackwellIRInsn insn_a1_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = 32, .src3_vreg = -1 };
2245 -: 1864: omega_bw_ir_append(prog, &insn_a1_idx1);
2246 -: 1865: BlackwellIRInsn insn_a1_idx2 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = 2, .src3_vreg = v_idx };
2247 -: 1866: omega_bw_ir_append(prog, &insn_a1_idx2);
2248 -: 1867: BlackwellIRInsn insn_a1_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 1, .src3_vreg = v_ptr_a };
2249 -: 1868: omega_bw_ir_append(prog, &insn_a1_off);
2250 -: 1869: BlackwellIRInsn insn_lda1 = { .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 1, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x001ea800 };
2251 -: 1870: omega_bw_ir_append(prog, &insn_lda1);
2252 -: 1871:
2253 -: 1872: /* Pair 2: a4, a5 at r0 * 32 + tid_col2 * 2 + 16 */
2254 -: 1873: BlackwellIRInsn insn_a2_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = 32, .src3_vreg = -1 };
2255 -: 1874: omega_bw_ir_append(prog, &insn_a2_idx1);
2256 -: 1875: BlackwellIRInsn insn_a2_idx2 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = 2, .src3_vreg = v_idx };
2257 -: 1876: omega_bw_ir_append(prog, &insn_a2_idx2);
2258 -: 1877: BlackwellIRInsn insn_a2_idx3 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 16, .src3_vreg = v_idx };
2259 -: 1878: omega_bw_ir_append(prog, &insn_a2_idx3);
2260 -: 1879: BlackwellIRInsn insn_a2_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 1, .src3_vreg = v_ptr_a };
2261 -: 1880: omega_bw_ir_append(prog, &insn_a2_off);
2262 -: 1881: BlackwellIRInsn insn_lda2 = { .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 2, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x001ea800 };
2263 -: 1882: omega_bw_ir_append(prog, &insn_lda2);
2264 -: 1883:
2265 -: 1884: /* Pair 3: a6, a7 at r1 * 32 + tid_col2 * 2 + 16 */
2266 -: 1885: BlackwellIRInsn insn_a3_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = 32, .src3_vreg = -1 };
2267 -: 1886: omega_bw_ir_append(prog, &insn_a3_idx1);
2268 -: 1887: BlackwellIRInsn insn_a3_idx2 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = 2, .src3_vreg = v_idx };
2269 -: 1888: omega_bw_ir_append(prog, &insn_a3_idx2);
2270 -: 1889: BlackwellIRInsn insn_a3_idx3 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 16, .src3_vreg = v_idx };
2271 -: 1890: omega_bw_ir_append(prog, &insn_a3_idx3);
2272 -: 1891: BlackwellIRInsn insn_a3_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 1, .src3_vreg = v_ptr_a };
2273 -: 1892: omega_bw_ir_append(prog, &insn_a3_off);
2274 -: 1893: BlackwellIRInsn insn_lda3 = { .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 3, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x001ea800 };
2275 -: 1894: omega_bw_ir_append(prog, &insn_lda3);
2276 -: 1895:
2277 -: 1896: /* 8. Load and pack B fragments (16xN row-major, 2 bytes/element) */
2278 -: 1897: /* b0 at tid_col2 * N + col_b */
2279 -: 1898: BlackwellIRInsn insn_b0_idx = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_col_b };
2280 -: 1899: omega_bw_ir_append(prog, &insn_b0_idx);
2281 -: 1900: BlackwellIRInsn insn_b0_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_b };
2282 -: 1901: omega_bw_ir_append(prog, &insn_b0_off);
2283 -: 1902: BlackwellIRInsn insn_ldb0 = { .op = BW_IR_LDG_E_U16, .dst_vreg = v_b_tmp0, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x002ea800 };
2284 -: 1903: omega_bw_ir_append(prog, &insn_ldb0);
2285 -: 1904:
2286 -: 1905: /* b1 at (tid_col2 + 1) * N + col_b = b0_idx + N */
2287 -: 1906: BlackwellIRInsn insn_b1_idx = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_idx };
2288 -: 1907: omega_bw_ir_append(prog, &insn_b1_idx);
2289 -: 1908: BlackwellIRInsn insn_b1_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_b };
2290 -: 1909: omega_bw_ir_append(prog, &insn_b1_off);
2291 -: 1910: BlackwellIRInsn insn_ldb1 = { .op = BW_IR_LDG_E_U16, .dst_vreg = v_b_tmp1, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x002ea800 };
2292 -: 1911: omega_bw_ir_append(prog, &insn_ldb1);
2293 -: 1912:
2294 -: 1913: /* Pack Rb[0] = (b1 << 16) | b0 (wait on barrier 2) */
2295 -: 1914: BlackwellIRInsn insn_pack_b0 = { .op = BW_IR_IMAD, .dst_vreg = v_rb, .dst_subreg = 0, .src1_vreg = v_b_tmp1, .src2_vreg = -1, .imm = 0x10000, .src3_vreg = v_b_tmp0, .control = 0x004fca00 };
2296 -: 1915: omega_bw_ir_append(prog, &insn_pack_b0);
2297 -: 1916:
2298 -: 1917: /* b2 at (tid_col2 + 8) * N + col_b */
2299 -: 1918: BlackwellIRInsn insn_b2_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_col_b };
2300 -: 1919: omega_bw_ir_append(prog, &insn_b2_idx1);
2301 -: 1920: BlackwellIRInsn insn_b2_idx2 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 8 * spec->n, .src3_vreg = v_idx };
2302 -: 1921: omega_bw_ir_append(prog, &insn_b2_idx2);
2303 -: 1922: BlackwellIRInsn insn_b2_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_b };
2304 -: 1923: omega_bw_ir_append(prog, &insn_b2_off);
2305 -: 1924: BlackwellIRInsn insn_ldb2 = { .op = BW_IR_LDG_E_U16, .dst_vreg = v_b_tmp0, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x002ea800 };
2306 -: 1925: omega_bw_ir_append(prog, &insn_ldb2);
2307 -: 1926:
2308 -: 1927: /* b3 at (tid_col2 + 9) * N + col_b = b2_idx + N */
2309 -: 1928: BlackwellIRInsn insn_b3_idx = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_idx };
2310 -: 1929: omega_bw_ir_append(prog, &insn_b3_idx);
2311 -: 1930: BlackwellIRInsn insn_b3_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_b };
2312 -: 1931: omega_bw_ir_append(prog, &insn_b3_off);
2313 -: 1932: BlackwellIRInsn insn_ldb3 = { .op = BW_IR_LDG_E_U16, .dst_vreg = v_b_tmp1, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x002ea800 };
2314 -: 1933: omega_bw_ir_append(prog, &insn_ldb3);
2315 -: 1934:
2316 -: 1935: /* Pack Rb[1] = (b3 << 16) | b2 (wait on barrier 2) */
2317 -: 1936: BlackwellIRInsn insn_pack_b1 = { .op = BW_IR_IMAD, .dst_vreg = v_rb, .dst_subreg = 1, .src1_vreg = v_b_tmp1, .src2_vreg = -1, .imm = 0x10000, .src3_vreg = v_b_tmp0, .control = 0x004fca00 };
2318 -: 1937: omega_bw_ir_append(prog, &insn_pack_b1);
2319 -: 1938:
2320 -: 1939: /* 9. Execute HMMA Tensor Core instruction (wait on barrier 1 for A loads) */
2321 -: 1940: BlackwellIROpcode mma_op = (spec->precision == OMEGA_MATMUL_PRECISION_BF16) ? BW_IR_HMMA_BF16 : BW_IR_HMMA_F16;
2322 -: 1941: BlackwellIRInsn insn_hmma = {
2323 -: 1942: .op = mma_op,
2324 -: 1943: .dst_vreg = v_rd,
2325 -: 1944: .dst_subreg = 0,
2326 -: 1945: .src1_vreg = v_ra,
2327 -: 1946: .src1_subreg = 0,
2328 -: 1947: .src2_vreg = v_rb,
2329 -: 1948: .src2_subreg = 0,
2330 -: 1949: .src3_vreg = -1, /* RZ accumulator input */
2331 -: 1950: .control = 0x002fca00 /* Wait on barrier 1 */
2332 -: 1951: };
2333 -: 1952: omega_bw_ir_append(prog, &insn_hmma);
2334 -: 1953:
2335 -: 1954: /* 10. Store C output fragments (16xN row-major, 4 bytes/float element) */
2336 -: 1955: /* d0: row r0, col col_base + tid_col2 + 0 */
2337 -: 1956: BlackwellIRInsn insn_d0_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_col_base };
2338 -: 1957: omega_bw_ir_append(prog, &insn_d0_idx1);
2339 -: 1958: BlackwellIRInsn insn_d0_idx2 = { .op = BW_IR_IADD3, .dst_vreg = v_idx, .src1_vreg = v_idx, .src2_vreg = v_tid_col2, .src3_vreg = -1 };
2340 -: 1959: omega_bw_ir_append(prog, &insn_d0_idx2);
2341 -: 1960: BlackwellIRInsn insn_d0_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c };
2342 -: 1961: omega_bw_ir_append(prog, &insn_d0_off);
2343 -: 1962: BlackwellIRInsn insn_std0 = { .op = BW_IR_STG_E, .src1_vreg = v_off, .src2_vreg = v_rd, .src2_subreg = 0, .ureg = uv_desc, .control = 0x000fe200 };
2344 -: 1963: omega_bw_ir_append(prog, &insn_std0);
2345 -: 1964:
2346 -: 1965: /* d1: row r0, col col_base + tid_col2 + 1 */
2347 -: 1966: BlackwellIRInsn insn_d1_idx = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 1, .src3_vreg = v_idx };
2348 -: 1967: omega_bw_ir_append(prog, &insn_d1_idx);
2349 -: 1968: BlackwellIRInsn insn_d1_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c };
2350 -: 1969: omega_bw_ir_append(prog, &insn_d1_off);
2351 -: 1970: BlackwellIRInsn insn_std1 = { .op = BW_IR_STG_E, .src1_vreg = v_off, .src2_vreg = v_rd, .src2_subreg = 1, .ureg = uv_desc, .control = 0x000fe200 };
2352 -: 1971: omega_bw_ir_append(prog, &insn_std1);
2353 -: 1972:
2354 -: 1973: /* d2: row r1, col col_base + tid_col2 + 0 */
2355 -: 1974: BlackwellIRInsn insn_d2_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_col_base };
2356 -: 1975: omega_bw_ir_append(prog, &insn_d2_idx1);
2357 -: 1976: BlackwellIRInsn insn_d2_idx2 = { .op = BW_IR_IADD3, .dst_vreg = v_idx, .src1_vreg = v_idx, .src2_vreg = v_tid_col2, .src3_vreg = -1 };
2358 -: 1977: omega_bw_ir_append(prog, &insn_d2_idx2);
2359 -: 1978: BlackwellIRInsn insn_d2_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c };
2360 -: 1979: omega_bw_ir_append(prog, &insn_d2_off);
2361 -: 1980: BlackwellIRInsn insn_std2 = { .op = BW_IR_STG_E, .src1_vreg = v_off, .src2_vreg = v_rd, .src2_subreg = 2, .ureg = uv_desc, .control = 0x000fe200 };
2362 -: 1981: omega_bw_ir_append(prog, &insn_std2);
2363 -: 1982:
2364 -: 1983: /* d3: row r1, col col_base + tid_col2 + 1 */
2365 -: 1984: BlackwellIRInsn insn_d3_idx = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 1, .src3_vreg = v_idx };
2366 -: 1985: omega_bw_ir_append(prog, &insn_d3_idx);
2367 -: 1986: BlackwellIRInsn insn_d3_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c };
2368 -: 1987: omega_bw_ir_append(prog, &insn_d3_off);
2369 -: 1988: BlackwellIRInsn insn_std3 = { .op = BW_IR_STG_E, .src1_vreg = v_off, .src2_vreg = v_rd, .src2_subreg = 3, .ureg = uv_desc, .control = 0x000fe200 };
2370 -: 1989: omega_bw_ir_append(prog, &insn_std3);
2371 -: 1990:
2372 -: 1991: /* 11. Program Exit */
2373 -: 1992: BlackwellIRInsn insn_exit = { .op = BW_IR_EXIT };
2374 -: 1993: omega_bw_ir_append(prog, &insn_exit);
2375 -: 1994: BlackwellIRInsn insn_bra = { .op = BW_IR_BRA };
2376 -: 1995: omega_bw_ir_append(prog, &insn_bra);
2377 -: 1996:
2378 -: 1997: /* 12. Run bounded register allocation */
2379 -: 1998: if (omega_bw_regalloc_solve(prog) != 0) {
2380 -: 1999: return -1;
2381 -: 2000: }
2382 -: 2001: return 0;
2383 -: 2002:}
2384 -: 2003:#else
2385function legacy_omega_blackwell_codegen_matmul_tensor_prog called 0 returned 0% blocks executed 0%
2386 #####: 2004:int omega_blackwell_codegen_matmul_tensor_prog(const OmegaMatMulSpec *s, BlackwellIRProgram *p) {
2387 #####: 2005: return bw_om_matprog(omega_cg_tens, s, 0, 0, 0, 0, 0, p);
2388call 0 never executed
2389 -: 2006:}
2390 -: 2007:#endif
2391 -: 2008:
2392 -: 2009:#ifndef OMEGA_GPU_NO_POSIX
2393function legacy_omega_blackwell_codegen_matmul_tensor called 0 returned 0% blocks executed 0%
2394 #####: 2010:int omega_blackwell_codegen_matmul_tensor(const OmegaMatMulSpec *spec, OmegaBlackwellKernel *kernel) {
2395 #####: 2011: if (!spec || !kernel) return -1;
2396branch 0 never executed (fallthrough)
2397branch 1 never executed
2398branch 2 never executed (fallthrough)
2399branch 3 never executed
2400 -: 2012: BlackwellIRProgram prog;
2401 #####: 2013: if (omega_blackwell_codegen_matmul_tensor_prog(spec, &prog) != 0) {
2402call 0 never executed
2403branch 1 never executed (fallthrough)
2404branch 2 never executed
2405 #####: 2014: return -1;
2406 -: 2015: }
2407 -: 2016:
2408 #####: 2017: return bw_kernel_alloc_encode(&prog, OMEGA_BW_CODE_CAP_SMALL, kernel);
2409call 0 never executed
2410 -: 2018:}
2411 -: 2019:#endif
2412 -: 2020:
2413 -: 2021:/* ---- FB-1 cut 1b: looped tensor matmul ------------------------------------------
2414 -: 2022: *
2415 -: 2023: * Control words (bundle bits 105..125, decoded from the chip-proven kernel and from
2416 -: 2024: * the vendor compiler's SASS for an equivalent HMMA loop on this chip, 2026-10-04):
2417 -: 2025: * stall = bits 9..12 of w[3], yield = 13, write barrier = 14..16, read barrier =
2418 -: 2026: * 17..19, wait mask = 20..25. 7 in a barrier field means "none".
2419 -: 2027: * LDG (A) 0x001ea800 stall 4, yield, sets SB2
2420 -: 2028: * LDG.U16 (B) 0x002ea800 stall 4, yield, sets SB2
2421 -: 2029: * pack IMAD 0x004fca00 stall 5, waits SB2 (every outstanding load has landed)
2422 -: 2030: * HMMA 0x002fca00 stall 5 (fixed latency: the vendor compiler sets no
2423 -: 2031: * write barrier on HMMA either; consumers wait by stall count)
2424 -: 2032: * STG 0x0007e200 stall 1, yield, read barrier SB3 (the store may read its
2425 -: 2033: * data/address registers late; the next writer waits SB3)
2426 -: 2034: * wait SB3 mask bit 23 (0x00800000) on the first instruction that overwrites a
2427 -: 2035: * register a store reads: the C pointer advance.
2428 -: 2036: * Loop-carried registers are kept live to the end of their loop (keep_alive) because
2429 -: 2037: * the allocator is a straight-line linear scan and knows nothing about back edges.
2430 -: 2038: */
2431 -: 2039:#ifdef BW_MATMUL_C_PRIMARY
2432 -: 2040:static void bw_keep_alive(BlackwellIRProgram *prog, int from_idx, int to_idx, int last_idx) {
2433 -: 2041: /* every vreg first defined in [from_idx, to_idx) stays live until last_idx */
2434 -: 2042: for (int v = 0; v < prog->regalloc.num_vregs; v++) {
2435 -: 2043: OmegaLiveInterval *iv = &prog->regalloc.intervals[v];
2436 -: 2044: if (iv->first_def >= from_idx && iv->first_def < to_idx && iv->last_use < last_idx)
2437 -: 2045: iv->last_use = last_idx;
2438 -: 2046: }
2439 -: 2047:}
2440 -: 2048:
2441 -: 2049:#define BW_APPEND(prog, ...) do { BlackwellIRInsn _i = { __VA_ARGS__ }; if (omega_bw_ir_append((prog), &_i) < 0) return -1; } while (0)
2442 -: 2050:
2443 -: 2051:int omega_blackwell_codegen_matmul_tensor_loop_prog(const OmegaMatMulSpec *spec, uint32_t grid_x,
2444 -: 2052: int mutant, BlackwellIRProgram *prog) {
2445 -: 2053: if (!spec || !prog) return -1;
2446 -: 2054: if (spec->m == 0 || spec->k == 0 || spec->n == 0) return -1;
2447 -: 2055: if (spec->precision != OMEGA_MATMUL_PRECISION_FP16 && spec->precision != OMEGA_MATMUL_PRECISION_BF16) return -1;
2448 -: 2056: if (spec->m % 16 != 0 || spec->n % 8 != 0 || spec->k % 16 != 0) {
2449 -: 2057: BW_DIAG("ERROR: looped MatMul tensor codegen requires M%%16, N%%8, K%%16 (got %ux%ux%u)\n",
2450 -: 2058: spec->m, spec->k, spec->n);
2451 -: 2059: return -1;
2452 -: 2060: }
2453 -: 2061: const uint32_t K = spec->k, N = spec->n, NT = N / 8, KSTEPS = K / 16;
2454 -: 2062: if (grid_x == 0 || grid_x > NT) return -1;
2455 -: 2063: /* every immediate below must fit 32 bits: 32 * N (B row-block stride in bytes) is the largest */
2456 -: 2064: if ((uint64_t)N * 32u > 0xffffffffull || (uint64_t)grid_x * 32u > 0xffffffffull) return -1;
2457 -: 2065: if (mutant && KSTEPS < 2) return -1;
2458 -: 2066:
2459 -: 2067: omega_bw_ir_init(prog);
2460 -: 2068:
2461 -: 2069: int v_ptr_a = omega_bw_ir_alloc_vreg64(prog), v_ptr_b = omega_bw_ir_alloc_vreg64(prog), v_ptr_c = omega_bw_ir_alloc_vreg64(prog);
2462 -: 2070: int uv_desc = omega_bw_ir_alloc_uvreg64(prog);
2463 -: 2071: int v_tid = omega_bw_ir_alloc_vreg(prog), v_ctaid_x = omega_bw_ir_alloc_vreg(prog), v_ctaid_y = omega_bw_ir_alloc_vreg(prog);
2464 -: 2072: int v_group = omega_bw_ir_alloc_vreg(prog), v_tig = omega_bw_ir_alloc_vreg(prog), v_tcol2 = omega_bw_ir_alloc_vreg(prog);
2465 -: 2073: int v_r0 = omega_bw_ir_alloc_vreg(prog), v_r1 = omega_bw_ir_alloc_vreg(prog), v_c1 = omega_bw_ir_alloc_vreg(prog);
2466 -: 2074: int v_idx = omega_bw_ir_alloc_vreg(prog), v_col = omega_bw_ir_alloc_vreg(prog), v_cnt = omega_bw_ir_alloc_vreg(prog);
2467 -: 2075: int v_pa0 = omega_bw_ir_alloc_vreg64(prog), v_pa1 = omega_bw_ir_alloc_vreg64(prog), v_pbcol = omega_bw_ir_alloc_vreg64(prog);
2468 -: 2076: int v_pc0 = omega_bw_ir_alloc_vreg64(prog), v_pc1 = omega_bw_ir_alloc_vreg64(prog);
2469 -: 2077: int v_pa0c = omega_bw_ir_alloc_vreg64(prog), v_pa1c = omega_bw_ir_alloc_vreg64(prog), v_pbc = omega_bw_ir_alloc_vreg64(prog);
2470 -: 2078: int v_ta2 = omega_bw_ir_alloc_vreg64(prog), v_ta3 = omega_bw_ir_alloc_vreg64(prog);
2471 -: 2079: int v_tb1 = omega_bw_ir_alloc_vreg64(prog), v_tb2 = omega_bw_ir_alloc_vreg64(prog), v_tb3 = omega_bw_ir_alloc_vreg64(prog);
2472 -: 2080: int v_tc1 = omega_bw_ir_alloc_vreg64(prog), v_tc3 = omega_bw_ir_alloc_vreg64(prog);
2473 -: 2081: int v_ra = omega_bw_ir_alloc_vreg128(prog), v_rb = omega_bw_ir_alloc_vreg64(prog), v_rd = omega_bw_ir_alloc_vreg128(prog);
2474 -: 2082: int v_b0 = omega_bw_ir_alloc_vreg(prog), v_b1 = omega_bw_ir_alloc_vreg(prog);
2475 -: 2083: if (v_b1 < 0 || uv_desc < 0) return -1;
2476 -: 2084:
2477 -: 2085: const uint32_t CTRL_LDA = 0x001ea800u, CTRL_LDB = 0x002ea800u, CTRL_PACK = 0x004fca00u;
2478 -: 2086: const uint32_t CTRL_HMMA = 0x002fca00u, CTRL_STG_RDBAR3 = 0x0007e200u, CTRL_IMADW_WAIT3 = 0x009fcc00u;
2479 -: 2087: const uint32_t CTRL_MOVRZ_WAIT3 = 0x008fe200u;
2480 -: 2088:
2481 -: 2089: /* prologue: descriptor, pointers, ids */
2482 -: 2090: BW_APPEND(prog, .op = BW_IR_LDCU64, .dst_vreg = uv_desc, .imm = 0x358, .is_uniform = true);
2483 -: 2091: BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_a, .imm = 0x380);
2484 -: 2092: BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_b, .imm = 0x388);
2485 -: 2093: BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_c, .imm = 0x390);
2486 -: 2094: BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_tid, .imm = BW_SR_TID_X);
2487 -: 2095: BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_ctaid_x, .imm = BW_SR_CTAID_X);
2488 -: 2096: BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_ctaid_y, .imm = BW_SR_CTAID_Y);
2489 -: 2097: BW_APPEND(prog, .op = BW_IR_MOV_IMM, .dst_vreg = v_c1, .imm = 1);
2490 -: 2098: BW_APPEND(prog, .op = BW_IR_SHF_R, .dst_vreg = v_group, .src1_vreg = v_tid, .imm = 2);
2491 -: 2099: BW_APPEND(prog, .op = BW_IR_LOP3_AND, .dst_vreg = v_tig, .src1_vreg = v_tid, .imm = 3);
2492 -: 2100: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_tcol2, .src1_vreg = v_tig, .src2_vreg = -1, .imm = 2, .src3_vreg = -1);
2493 -: 2101: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_r0, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = 16, .src3_vreg = v_group);
2494 -: 2102: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_r1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 8, .src3_vreg = v_r0);
2495 -: 2103: /* pa0 = A + (r0*K + tcol2)*2 ; pa1 likewise with r1 (A row-major, K bf16 per row) */
2496 -: 2104: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = K, .src3_vreg = v_tcol2);
2497 -: 2105: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa0, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_a);
2498 -: 2106: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = K, .src3_vreg = v_tcol2);
2499 -: 2107: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa1, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_a);
2500 -: 2108: /* col = ctaid_x (first column tile of this CTA) */
2501 -: 2109: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_ctaid_x, .src2_vreg = -1, .imm = 1, .src3_vreg = -1);
2502 -: 2110: /* pbcol = B + (tcol2*N + col*8 + group)*2 */
2503 -: 2111: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tcol2, .src2_vreg = -1, .imm = N, .src3_vreg = v_group);
2504 -: 2112: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx);
2505 -: 2113: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbcol, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_b);
2506 -: 2114: /* pc0 = C + (r0*N + col*8 + tcol2)*4 ; pc1 with r1 */
2507 -: 2115: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = N, .src3_vreg = v_tcol2);
2508 -: 2116: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx);
2509 -: 2117: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc0, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c);
2510 -: 2118: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = N, .src3_vreg = v_tcol2);
2511 -: 2119: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx);
2512 -: 2120: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc1, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c);
2513 -: 2121:
2514 -: 2122: /* ---- column-tile loop ---- */
2515 -: 2123: const int L_col = (int)prog->count;
2516 -: 2124: /* accumulator = 0 (the first write waits SB3: the previous tile's stores may still read it) */
2517 -: 2125: BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 0, .control = CTRL_MOVRZ_WAIT3);
2518 -: 2126: BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 1);
2519 -: 2127: BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 2);
2520 -: 2128: BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 3);
2521 -: 2129: /* K cursors start at the row/column bases (IMAD.WIDE with imm 0 is a 64-bit copy) */
2522 -: 2130: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa0c, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pa0);
2523 -: 2131: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa1c, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pa1);
2524 -: 2132: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbc, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pbcol);
2525 -: 2133: BW_APPEND(prog, .op = BW_IR_MOV_IMM, .dst_vreg = v_cnt, .imm = mutant ? KSTEPS - 1 : KSTEPS);
2526 -: 2134:
2527 -: 2135: /* ---- K loop: one 16x16 A fragment and one 16x8 B fragment per step ---- */
2528 -: 2136: const int L_k = (int)prog->count;
2529 -: 2137: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_ta2, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 16, .src3_vreg = v_pa0c);
2530 -: 2138: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_ta3, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 16, .src3_vreg = v_pa1c);
2531 -: 2139: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tb1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 2u * N, .src3_vreg = v_pbc);
2532 -: 2140: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tb2, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 16u * N, .src3_vreg = v_pbc);
2533 -: 2141: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tb3, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 18u * N, .src3_vreg = v_pbc);
2534 -: 2142: /* A: a0,a1 at (r0, kk+tcol2) ; a2,a3 at (r1, ...) ; a4,a5 at (r0, +8) ; a6,a7 at (r1, +8) */
2535 -: 2143: BW_APPEND(prog, .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 0, .src1_vreg = v_pa0c, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDA);
2536 -: 2144: BW_APPEND(prog, .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 1, .src1_vreg = v_pa1c, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDA);
2537 -: 2145: BW_APPEND(prog, .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 2, .src1_vreg = v_ta2, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDA);
2538 -: 2146: BW_APPEND(prog, .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 3, .src1_vreg = v_ta3, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDA);
2539 -: 2147: /* B: rows kk+tcol2, +1, +8, +9 at column col*8+group */
2540 -: 2148: BW_APPEND(prog, .op = BW_IR_LDG_E_U16, .dst_vreg = v_b0, .src1_vreg = v_pbc, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDB);
2541 -: 2149: BW_APPEND(prog, .op = BW_IR_LDG_E_U16, .dst_vreg = v_b1, .src1_vreg = v_tb1, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDB);
2542 -: 2150: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_rb, .dst_subreg = 0, .src1_vreg = v_b1, .src2_vreg = -1, .imm = 0x10000, .src3_vreg = v_b0, .control = CTRL_PACK);
2543 -: 2151: BW_APPEND(prog, .op = BW_IR_LDG_E_U16, .dst_vreg = v_b0, .src1_vreg = v_tb2, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDB);
2544 -: 2152: BW_APPEND(prog, .op = BW_IR_LDG_E_U16, .dst_vreg = v_b1, .src1_vreg = v_tb3, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDB);
2545 -: 2153: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_rb, .dst_subreg = 1, .src1_vreg = v_b1, .src2_vreg = -1, .imm = 0x10000, .src3_vreg = v_b0, .control = CTRL_PACK);
2546 -: 2154: /* rd += ra * rb (accumulate in place) */
2547 -: 2155: BW_APPEND(prog, .op = (spec->precision == OMEGA_MATMUL_PRECISION_BF16) ? BW_IR_HMMA_BF16 : BW_IR_HMMA_F16,
2548 -: 2156: .dst_vreg = v_rd, .dst_subreg = 0, .src1_vreg = v_ra, .src1_subreg = 0, .src2_vreg = v_rb, .src2_subreg = 0,
2549 -: 2157: .src3_vreg = v_rd, .src3_subreg = 0, .control = CTRL_HMMA);
2550 -: 2158: /* advance K: A by 16 bf16 (32 bytes), B by 16 rows (32 N bytes); every load above has landed (packs waited SB2) */
2551 -: 2159: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa0c, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 32, .src3_vreg = v_pa0c);
2552 -: 2160: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa1c, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 32, .src3_vreg = v_pa1c);
2553 -: 2161: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbc, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 32u * N, .src3_vreg = v_pbc);
2554 -: 2162: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_cnt, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0xffffffffu, .src3_vreg = v_cnt);
2555 -: 2163: BW_APPEND(prog, .op = BW_IR_ISETP_GE, .dst_vreg = -1, .src1_vreg = v_cnt, .src2_vreg = -1, .imm = 1, .src3_vreg = -1);
2556 -: 2164: {
2557 -: 2165: int here = (int)prog->count;
2558 -: 2166: BW_APPEND(prog, .op = BW_IR_BRA, .imm = (uint32_t)(int32_t)(L_k - here), .predicate_p0 = true);
2559 -: 2167: }
2560 -: 2168: const int L_k_end = (int)prog->count - 1;
2561 -: 2169:
2562 -: 2170: /* ---- store the 16x8 tile: d0 (r0, c), d1 (r0, c+1), d2 (r1, c), d3 (r1, c+1) ---- */
2563 -: 2171: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tc1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 4, .src3_vreg = v_pc0);
2564 -: 2172: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tc3, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 4, .src3_vreg = v_pc1);
2565 -: 2173: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc0, .src2_vreg = v_rd, .src2_subreg = 0, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3);
2566 -: 2174: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_tc1, .src2_vreg = v_rd, .src2_subreg = 1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3);
2567 -: 2175: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc1, .src2_vreg = v_rd, .src2_subreg = 2, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3);
2568 -: 2176: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_tc3, .src2_vreg = v_rd, .src2_subreg = 3, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3);
2569 -: 2177: /* next column tile of this CTA: col += grid_x ; B by grid_x*8 bf16 ; C by grid_x*8 f32 (waits SB3 first) */
2570 -: 2178: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x, .src3_vreg = v_col);
2571 -: 2179: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc0, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * 32u, .src3_vreg = v_pc0, .control = CTRL_IMADW_WAIT3);
2572 -: 2180: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * 32u, .src3_vreg = v_pc1);
2573 -: 2181: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbcol, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * 16u, .src3_vreg = v_pbcol);
2574 -: 2182: BW_APPEND(prog, .op = BW_IR_ISETP_GE, .dst_vreg = -1, .src1_vreg = v_col, .src2_vreg = -1, .imm = NT, .src3_vreg = -1);
2575 -: 2183: {
2576 -: 2184: int here = (int)prog->count;
2577 -: 2185: BW_APPEND(prog, .op = BW_IR_BRA, .imm = (uint32_t)(int32_t)(L_col - here), .predicate_p0 = true, .predicate_not = true);
2578 -: 2186: }
2579 -: 2187: const int L_col_end = (int)prog->count - 1;
2580 -: 2188: BW_APPEND(prog, .op = BW_IR_EXIT);
2581 -: 2189: BW_APPEND(prog, .op = BW_IR_BRA);
2582 -: 2190:
2583 -: 2191: /* loop-carried values live to the end of their loop */
2584 -: 2192: bw_keep_alive(prog, 0, L_col, L_col_end);
2585 -: 2193: bw_keep_alive(prog, L_col, L_k, L_k_end);
2586 -: 2194: /* K-loop temporaries too: a load's address pair must never be recycled by a
2587 -: 2195: * later instruction of the same iteration (the load may read it late). */
2588 -: 2196: bw_keep_alive(prog, L_k, L_k_end, L_k_end);
2589 -: 2197: /* the accumulator is read by the stores after the K loop */
2590 -: 2198: if (prog->regalloc.intervals[v_rd].last_use < L_col_end) prog->regalloc.intervals[v_rd].last_use = L_col_end;
2591 -: 2199:
2592 -: 2200: return omega_bw_regalloc_solve(prog);
2593 -: 2201:}
2594 -: 2202:#else
2595function legacy_omega_blackwell_codegen_matmul_tensor_loop_prog called 0 returned 0% blocks executed 0%
2596 #####: 2203:int omega_blackwell_codegen_matmul_tensor_loop_prog(const OmegaMatMulSpec *s, uint32_t grid,
2597 -: 2204: int mutant, BlackwellIRProgram *p) {
2598 #####: 2205: return bw_om_matprog(omega_cg_loop, s, grid, 0, 0, 0, mutant, p);
2599call 0 never executed
2600 -: 2206:}
2601 -: 2207:#endif
2602 -: 2208:
2603 -: 2209:#ifndef OMEGA_GPU_NO_POSIX
2604function legacy_omega_blackwell_codegen_matmul_tensor_loop called 0 returned 0% blocks executed 0%
2605 #####: 2210:int omega_blackwell_codegen_matmul_tensor_loop(const OmegaMatMulSpec *spec, uint32_t grid_x,
2606 -: 2211: int mutant, OmegaBlackwellKernel *kernel) {
2607 #####: 2212: if (!spec || !kernel) return -1;
2608branch 0 never executed (fallthrough)
2609branch 1 never executed
2610branch 2 never executed (fallthrough)
2611branch 3 never executed
2612 -: 2213: BlackwellIRProgram prog;
2613 #####: 2214: if (omega_blackwell_codegen_matmul_tensor_loop_prog(spec, grid_x, mutant, &prog) != 0) return -1;
2614call 0 never executed
2615branch 1 never executed (fallthrough)
2616branch 2 never executed
2617 #####: 2215: return bw_kernel_alloc_encode(&prog, OMEGA_BW_CODE_CAP_SMALL, kernel);
2618call 0 never executed
2619 -: 2216:}
2620 -: 2217:#endif
2621 -: 2218:
2622 -: 2219:/* ---- omega #328: fragment-major tensor matmul ----------------------------------------
2623 -: 2220: *
2624 -: 2221: * The looped kernel above reads B as four scattered 2-byte loads per K step and waits for
2625 -: 2222: * them before the next step (pack waits SB2), so each warp has one 256-byte step in flight;
2626 -: 2223: * at m = 1 on GB10 that streams the weights at about 28 GB/s (omega #328 measurement).
2627 -: 2224: * Here A and B arrive in the order HMMA.16816 consumes them (omega_matmul_frag_pack_a / _b):
2628 -: 2225: * A block (mt, ks): 512 bytes, lane L at L*16: a0..a7, one LDG.E.128 per step;
2629 -: 2226: * B block (nt, ks): 256 bytes, lane L at L*8: b0..b3, one LDG.E.64 per step;
2630 -: 2227: * consecutive K steps of one tile are adjacent, so a warp streams its column tile. Each loop
2631 -: 2228: * pass issues `unroll` steps of loads at immediate offsets (A on SB2, B on SB4), then runs the HMMA
2632 -: 2229: * chain: every HMMA waits SB2 and SB4 (stall 15) and a NOP (stall 14) follows it, the 29 cycles nvcc
2633 -: 2230: * puts between dependent HMMA.16816 (omega_blackwell_verify_codegen_fixtures_fragmm).
2634 -: 2231: * The cursors advance only after the chain, when every load has landed (the HMMAs waited
2635 -: 2232: * SB2 and SB4), as in the looped kernel. Stores, the column-tile loop and the C layout (row-major
2636 -: 2233: * f32) are the looped kernel's. */
2637 -: 2234:/* A loads set SB2 and B loads SB4 (nvcc spreads loads over several scoreboards too); at the
2638 -: 2235: * product unroll of 4 that is 4 loads per scoreboard per pass. The scoreboard depth is not
2639 -: 2236: * documented to us; splitting did not make unroll 8 complete (omega_matmul_frag_unroll). */
2640 -: 2237:#define BW_FRAG_CTRL_LDG_A 0x000ea800u /* stall 4, yield, sets SB2 (nvcc word) */
2641 -: 2238:#define BW_FRAG_CTRL_LDG_B 0x000f2800u /* stall 4, yield, sets SB4 (nvcc word) */
2642 -: 2239:#define BW_FRAG_CTRL_HMMA 0x014fde00u /* stall 15, waits SB2 and SB4 (nvcc: dependent HMMA chain) */
2643 -: 2240:#define BW_FRAG_CTRL_NOP 0x000fdc00u /* stall 14 (nvcc, between dependent HMMAs) */
2644 -: 2241:
2645 -: 2242:#ifdef BW_MATMUL_C_PRIMARY
2646 -: 2243:static void bw_live_until(BlackwellIRProgram *prog, int vreg, int last_idx) {
2647 -: 2244: if (prog->regalloc.intervals[vreg].last_use < last_idx) prog->regalloc.intervals[vreg].last_use = last_idx;
2648 -: 2245:}
2649 -: 2246:
2650 -: 2247:int omega_blackwell_codegen_matmul_frag_prog(const OmegaMatMulSpec *spec, uint32_t grid_x, uint32_t unroll,
2651 -: 2248: int mutant, BlackwellIRProgram *prog) {
2652 -: 2249: if (!spec || !prog) return -1;
2653 -: 2250: if (spec->m == 0 || spec->k == 0 || spec->n == 0) return -1;
2654 -: 2251: if (spec->precision != OMEGA_MATMUL_PRECISION_FP16 && spec->precision != OMEGA_MATMUL_PRECISION_BF16) return -1;
2655 -: 2252: if (spec->m % 16 != 0 || spec->n % 8 != 0 || spec->k % 16 != 0) return -1;
2656 -: 2253: if (unroll != 1 && unroll != 2 && unroll != 4 && unroll != 8) return -1;
2657 -: 2254: const uint32_t K = spec->k, N = spec->n, NT = N / 8, KS = K / 16;
2658 -: 2255: if (KS % unroll != 0) return -1;
2659 -: 2256: const uint32_t ITERS = KS / unroll;
2660 -: 2257: if (grid_x == 0 || grid_x > NT) return -1;
2661 -: 2258: if (mutant && ITERS < 2) return -1;
2662 -: 2259: /* every index and immediate below must fit 32 bits (rows up to OMEGA_BW_MATMUL_MAX_M) */
2663 -: 2260: if ((uint64_t)NT * KS * 32u > 0xffffffffull || (uint64_t)(OMEGA_BW_MATMUL_MAX_M / 16u) * KS * 32u > 0xffffffffull ||
2664 -: 2261: (uint64_t)grid_x * KS * 256u > 0xffffffffull || (uint64_t)N * 32u > 0xffffffffull ||
2665 -: 2262: (uint64_t)OMEGA_BW_MATMUL_MAX_M * N > 0xffffffffull)
2666 -: 2263: return -1;
2667 -: 2264:
2668 -: 2265: omega_bw_ir_init(prog);
2669 -: 2266: int v_ptr_a = omega_bw_ir_alloc_vreg64(prog), v_ptr_b = omega_bw_ir_alloc_vreg64(prog), v_ptr_c = omega_bw_ir_alloc_vreg64(prog);
2670 -: 2267: int uv_desc = omega_bw_ir_alloc_uvreg64(prog);
2671 -: 2268: int v_tid = omega_bw_ir_alloc_vreg(prog), v_ctaid_x = omega_bw_ir_alloc_vreg(prog), v_ctaid_y = omega_bw_ir_alloc_vreg(prog);
2672 -: 2269: int v_group = omega_bw_ir_alloc_vreg(prog), v_tig = omega_bw_ir_alloc_vreg(prog), v_tcol2 = omega_bw_ir_alloc_vreg(prog);
2673 -: 2270: int v_r0 = omega_bw_ir_alloc_vreg(prog), v_r1 = omega_bw_ir_alloc_vreg(prog), v_c1 = omega_bw_ir_alloc_vreg(prog);
2674 -: 2271: int v_idx = omega_bw_ir_alloc_vreg(prog), v_col = omega_bw_ir_alloc_vreg(prog), v_cnt = omega_bw_ir_alloc_vreg(prog);
2675 -: 2272: int v_pa = omega_bw_ir_alloc_vreg64(prog), v_pbcol = omega_bw_ir_alloc_vreg64(prog);
2676 -: 2273: int v_pc0 = omega_bw_ir_alloc_vreg64(prog), v_pc1 = omega_bw_ir_alloc_vreg64(prog);
2677 -: 2274: int v_pac = omega_bw_ir_alloc_vreg64(prog), v_pbc = omega_bw_ir_alloc_vreg64(prog);
2678 -: 2275: int v_tc1 = omega_bw_ir_alloc_vreg64(prog), v_tc3 = omega_bw_ir_alloc_vreg64(prog);
2679 -: 2276: int v_rd = omega_bw_ir_alloc_vreg128(prog);
2680 -: 2277: int v_ra[8], v_rb[8];
2681 -: 2278: for (uint32_t u = 0; u < unroll; u++) { v_ra[u] = omega_bw_ir_alloc_vreg128(prog); v_rb[u] = omega_bw_ir_alloc_vreg64(prog); }
2682 -: 2279: if (v_rb[unroll - 1] < 0 || v_ra[unroll - 1] < 0 || uv_desc < 0) return -1;
2683 -: 2280:
2684 -: 2281: const uint32_t CTRL_STG_RDBAR3 = 0x0007e200u, CTRL_IMADW_WAIT3 = 0x009fcc00u, CTRL_MOVRZ_WAIT3 = 0x008fe200u;
2685 -: 2282:
2686 -: 2283: /* prologue: descriptor, pointers, ids (as the looped kernel) */
2687 -: 2284: BW_APPEND(prog, .op = BW_IR_LDCU64, .dst_vreg = uv_desc, .imm = 0x358, .is_uniform = true);
2688 -: 2285: BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_a, .imm = 0x380);
2689 -: 2286: BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_b, .imm = 0x388);
2690 -: 2287: BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_c, .imm = 0x390);
2691 -: 2288: BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_tid, .imm = BW_SR_TID_X);
2692 -: 2289: BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_ctaid_x, .imm = BW_SR_CTAID_X);
2693 -: 2290: BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_ctaid_y, .imm = BW_SR_CTAID_Y);
2694 -: 2291: BW_APPEND(prog, .op = BW_IR_MOV_IMM, .dst_vreg = v_c1, .imm = 1);
2695 -: 2292: BW_APPEND(prog, .op = BW_IR_SHF_R, .dst_vreg = v_group, .src1_vreg = v_tid, .imm = 2);
2696 -: 2293: BW_APPEND(prog, .op = BW_IR_LOP3_AND, .dst_vreg = v_tig, .src1_vreg = v_tid, .imm = 3);
2697 -: 2294: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_tcol2, .src1_vreg = v_tig, .src2_vreg = -1, .imm = 2, .src3_vreg = -1);
2698 -: 2295: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_r0, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = 16, .src3_vreg = v_group);
2699 -: 2296: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_r1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 8, .src3_vreg = v_r0);
2700 -: 2297: /* pa = A + (ctaid_y * KS * 32 + tid) * 16: this CTA's row tile, this lane's 16 bytes of step 0 */
2701 -: 2298: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = KS * 32u, .src3_vreg = v_tid);
2702 -: 2299: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 16, .src3_vreg = v_ptr_a);
2703 -: 2300: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_ctaid_x, .src2_vreg = -1, .imm = 1, .src3_vreg = -1);
2704 -: 2301: /* pbcol = B + (col * KS * 32 + tid) * 8: column tile col, this lane's 8 bytes of step 0 */
2705 -: 2302: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = KS * 32u, .src3_vreg = v_tid);
2706 -: 2303: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbcol, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 8, .src3_vreg = v_ptr_b);
2707 -: 2304: /* pc0 = C + (r0*N + col*8 + tcol2)*4 ; pc1 with r1 */
2708 -: 2305: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = N, .src3_vreg = v_tcol2);
2709 -: 2306: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx);
2710 -: 2307: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc0, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c);
2711 -: 2308: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = N, .src3_vreg = v_tcol2);
2712 -: 2309: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx);
2713 -: 2310: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc1, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c);
2714 -: 2311:
2715 -: 2312: /* ---- column-tile loop ---- */
2716 -: 2313: const int L_col = (int)prog->count;
2717 -: 2314: BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 0, .control = CTRL_MOVRZ_WAIT3);
2718 -: 2315: BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 1);
2719 -: 2316: BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 2);
2720 -: 2317: BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 3);
2721 -: 2318: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pac, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pa);
2722 -: 2319: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbc, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pbcol);
2723 -: 2320: BW_APPEND(prog, .op = BW_IR_MOV_IMM, .dst_vreg = v_cnt, .imm = mutant ? ITERS - 1 : ITERS);
2724 -: 2321:
2725 -: 2322: /* ---- K loop: `unroll` steps of loads, then the HMMA chain ---- */
2726 -: 2323: const int L_k = (int)prog->count;
2727 -: 2324: for (uint32_t u = 0; u < unroll; u++) {
2728 -: 2325: BW_APPEND(prog, .op = BW_IR_LDG_E_128, .dst_vreg = v_ra[u], .src1_vreg = v_pac, .src2_vreg = -1, .src3_vreg = -1,
2729 -: 2326: .ureg = uv_desc, .imm = u * 512u, .control = BW_FRAG_CTRL_LDG_A);
2730 -: 2327: BW_APPEND(prog, .op = BW_IR_LDG_E_64, .dst_vreg = v_rb[u], .src1_vreg = v_pbc, .src2_vreg = -1, .src3_vreg = -1,
2731 -: 2328: .ureg = uv_desc, .imm = u * 256u, .control = BW_FRAG_CTRL_LDG_B);
2732 -: 2329: }
2733 -: 2330: const BlackwellIROpcode hmma = (spec->precision == OMEGA_MATMUL_PRECISION_BF16) ? BW_IR_HMMA_BF16 : BW_IR_HMMA_F16;
2734 -: 2331: for (uint32_t u = 0; u < unroll; u++) {
2735 -: 2332: BW_APPEND(prog, .op = hmma, .dst_vreg = v_rd, .src1_vreg = v_ra[u], .src2_vreg = v_rb[u], .src3_vreg = v_rd,
2736 -: 2333: .control = BW_FRAG_CTRL_HMMA);
2737 -: 2334: BW_APPEND(prog, .op = BW_IR_NOP, .dst_vreg = -1, .src1_vreg = -1, .src2_vreg = -1, .src3_vreg = -1, .ureg = -1,
2738 -: 2335: .control = BW_FRAG_CTRL_NOP);
2739 -: 2336: }
2740 -: 2337: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pac, .src1_vreg = v_c1, .src2_vreg = -1, .imm = unroll * 512u, .src3_vreg = v_pac);
2741 -: 2338: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbc, .src1_vreg = v_c1, .src2_vreg = -1, .imm = unroll * 256u, .src3_vreg = v_pbc);
2742 -: 2339: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_cnt, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0xffffffffu, .src3_vreg = v_cnt);
2743 -: 2340: BW_APPEND(prog, .op = BW_IR_ISETP_GE, .dst_vreg = -1, .src1_vreg = v_cnt, .src2_vreg = -1, .imm = 1, .src3_vreg = -1);
2744 -: 2341: {
2745 -: 2342: int here = (int)prog->count;
2746 -: 2343: BW_APPEND(prog, .op = BW_IR_BRA, .imm = (uint32_t)(int32_t)(L_k - here), .predicate_p0 = true);
2747 -: 2344: }
2748 -: 2345: const int L_k_end = (int)prog->count - 1;
2749 -: 2346:
2750 -: 2347: /* ---- store the 16x8 tile (as the looped kernel) ---- */
2751 -: 2348: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tc1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 4, .src3_vreg = v_pc0);
2752 -: 2349: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tc3, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 4, .src3_vreg = v_pc1);
2753 -: 2350: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc0, .src2_vreg = v_rd, .src2_subreg = 0, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3);
2754 -: 2351: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_tc1, .src2_vreg = v_rd, .src2_subreg = 1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3);
2755 -: 2352: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc1, .src2_vreg = v_rd, .src2_subreg = 2, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3);
2756 -: 2353: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_tc3, .src2_vreg = v_rd, .src2_subreg = 3, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3);
2757 -: 2354: /* next column tile: col += grid_x ; C by grid_x*8 f32 (waits SB3 first) ; B by grid_x tiles of KS*256 bytes */
2758 -: 2355: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x, .src3_vreg = v_col);
2759 -: 2356: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc0, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * 32u, .src3_vreg = v_pc0, .control = CTRL_IMADW_WAIT3);
2760 -: 2357: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * 32u, .src3_vreg = v_pc1);
2761 -: 2358: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbcol, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * KS * 256u, .src3_vreg = v_pbcol);
2762 -: 2359: BW_APPEND(prog, .op = BW_IR_ISETP_GE, .dst_vreg = -1, .src1_vreg = v_col, .src2_vreg = -1, .imm = NT, .src3_vreg = -1);
2763 -: 2360: {
2764 -: 2361: int here = (int)prog->count;
2765 -: 2362: BW_APPEND(prog, .op = BW_IR_BRA, .imm = (uint32_t)(int32_t)(L_col - here), .predicate_p0 = true, .predicate_not = true);
2766 -: 2363: }
2767 -: 2364: const int L_col_end = (int)prog->count - 1;
2768 -: 2365: BW_APPEND(prog, .op = BW_IR_EXIT);
2769 -: 2366: BW_APPEND(prog, .op = BW_IR_BRA);
2770 -: 2367:
2771 -: 2368: /* Loop-carried values live to the end of their loop (the allocator knows no back edges).
2772 -: 2369: * Only these are read in a later pass than the one that wrote them; prologue temporaries
2773 -: 2370: * are dead before the first loop and may be reused. K-loop temporaries (fragments) are
2774 -: 2371: * kept to the end of the pass, as in the looped kernel. */
2775 -: 2372: const int col_carried[] = { v_c1, v_col, v_pa, v_pbcol, v_pc0, v_pc1, v_rd };
2776 -: 2373: for (size_t i = 0; i < sizeof col_carried / sizeof col_carried[0]; i++) bw_live_until(prog, col_carried[i], L_col_end);
2777 -: 2374: const int k_carried[] = { v_pac, v_pbc, v_cnt };
2778 -: 2375: for (size_t i = 0; i < sizeof k_carried / sizeof k_carried[0]; i++) bw_live_until(prog, k_carried[i], L_k_end);
2779 -: 2376: bw_keep_alive(prog, L_k, L_k_end, L_k_end);
2780 -: 2377: return omega_bw_regalloc_solve(prog);
2781 -: 2378:}
2782 -: 2379:#else
2783function legacy_omega_blackwell_codegen_matmul_frag_prog called 0 returned 0% blocks executed 0%
2784 #####: 2380:int omega_blackwell_codegen_matmul_frag_prog(const OmegaMatMulSpec *s, uint32_t grid, uint32_t u,
2785 -: 2381: int mutant, BlackwellIRProgram *p) {
2786 #####: 2382: return bw_om_matprog(omega_cg_frag, s, grid, u, 0, 0, mutant, p);
2787call 0 never executed
2788 -: 2383:}
2789 -: 2384:#endif
2790 -: 2385:
2791 -: 2386:#ifndef OMEGA_GPU_NO_POSIX
2792function legacy_omega_blackwell_codegen_matmul_frag called 0 returned 0% blocks executed 0%
2793 #####: 2387:int omega_blackwell_codegen_matmul_frag(const OmegaMatMulSpec *spec, uint32_t grid_x, uint32_t unroll,
2794 -: 2388: int mutant, OmegaBlackwellKernel *kernel) {
2795 #####: 2389: if (!spec || !kernel) return -1;
2796branch 0 never executed (fallthrough)
2797branch 1 never executed
2798branch 2 never executed (fallthrough)
2799branch 3 never executed
2800 -: 2390: BlackwellIRProgram prog;
2801 #####: 2391: if (omega_blackwell_codegen_matmul_frag_prog(spec, grid_x, unroll, mutant, &prog) != 0) return -1;
2802call 0 never executed
2803branch 1 never executed (fallthrough)
2804branch 2 never executed
2805 #####: 2392: return bw_kernel_alloc_encode(&prog, OMEGA_BW_CODE_CAP_SMALL, kernel);
2806call 0 never executed
2807 -: 2393:}
2808 -: 2394:#endif
2809 -: 2395:
2810 -: 2396:/* Capped at 4: unroll 8 (72 registers, 16 loads per pass) never completed on the GB10, with all
2811 -: 2397: * loads on SB2 and again with A on SB2 and B on SB4 (2026-10-07 07:50Z and 07:54Z, omega #328),
2812 -: 2398: * while unroll 4 (48 registers) ran every Qwen3 decode shape correctly. Cause UNKNOWN; the next
2813 -: 2399: * experiment is the unroll-4 kernel launched with 72 declared registers (one variable). */
2814 -: 2400:/* ---- 2026-10-12: row/column-blocked fragment kernel (prefill rows) ------------------------
2815 -: 2401: *
2816 -: 2402: * The kernel above gives one warp one 16x8 output tile: every B fragment is streamed once per row
2817 -: 2403: * tile and every A fragment once per column tile, so at m = 128 on GB10 the three Qwen3-8B prefill
2818 -: 2404: * shapes move about 4.7 GB per call at the DRAM rate (128x4096x24576: 20.9 ms, 2026-10-12 baseline).
2819 -: 2405: * Here one warp owns RT row tiles x CT column tiles (RT*CT accumulators) over all of K: per K step
2820 -: 2406: * it loads RT A fragments and CT B fragments and runs RT*CT HMMAs, so each loaded fragment feeds
2821 -: 2407: * RT (B) or CT (A) tensor ops. Same packing, grid rules and C layout as the kernel above: the A
2822 -: 2408: * fragments of row tile i sit at +i*KS*512 bytes, the B fragments of column tile j at +j*KS*256,
2823 -: 2409: * both immediate offsets of the same cursors; the C tile (i, j) is at +i*16*N*4 + j*32 bytes from
2824 -: 2410: * the two row pointers (STG.E immediate offsets, fixtures in omega_blackwell_verify_codegen_fixtures_fragmm).
2825 -: 2411: * Loads per pass stay at or under 8 (unroll*(RT+CT)), the count the proven unroll-4 kernel issues;
2826 -: 2412: * unroll 8 of that kernel (16 loads per pass) never completed on the GB10 and the cause is UNKNOWN,
2827 -: 2413: * so this kernel does not go past that envelope. The HMMA chain keeps the dependent-chain control
2828 -: 2414: * words (stall 15 then NOP stall 14) although the RT*CT accumulators are independent: a longer stall
2829 -: 2415: * is never wrong, and the loads dominate the pass. CTA = one warp, as above; a grid of
2830 -: 2416: * (grid_x, row blocks); column blocks advance by grid_x per pass of the column loop. */
2831 -: 2417:/* The C store offset of the last tile (rt-1, ct-1) is a signed 24-bit STG immediate; for wide N (lm_head,
2832 -: 2418: * 151936 columns) rt > 1 does not fit. Shared by the generator below and omega_matmul_frag_block_shape. */
2833 -: 2419:#ifdef BW_MATMUL_C_PRIMARY
2834 -: 2420:static int frag_block_store_fits(uint32_t rt, uint32_t ct, uint32_t n) {
2835 -: 2421: return (uint64_t)(rt - 1) * 16u * n * 4u + (uint64_t)(ct - 1) * 32u + 4u < (1ull << 23);
2836 -: 2422:}
2837 -: 2423:
2838 -: 2424:int omega_blackwell_codegen_matmul_frag_block_prog(const OmegaMatMulSpec *spec, uint32_t grid_x, uint32_t unroll,
2839 -: 2425: uint32_t rt, uint32_t ct, int mutant, BlackwellIRProgram *prog) {
2840 -: 2426: if (!spec || !prog) return -1;
2841 -: 2427: if (spec->m == 0 || spec->k == 0 || spec->n == 0) return -1;
2842 -: 2428: if (spec->precision != OMEGA_MATMUL_PRECISION_FP16 && spec->precision != OMEGA_MATMUL_PRECISION_BF16) return -1;
2843 -: 2429: if (spec->m % 16 != 0 || spec->n % 8 != 0 || spec->k % 16 != 0) return -1;
2844 -: 2430: if (rt != 1 && rt != 2 && rt != 4 && rt != 8) return -1;
2845 -: 2431: if (ct != 1 && ct != 2 && ct != 4) return -1;
2846 -: 2432: if (rt * ct > 16 || rt * ct < 2) return -1; /* 1x1 is the kernel above */
2847 -: 2433: if (unroll != 1 && unroll != 2) return -1;
2848 -: 2434: if (unroll * (rt + ct) > 8) return -1;
2849 -: 2435: const uint32_t K = spec->k, N = spec->n, NT = N / 8, KS = K / 16;
2850 -: 2436: if (KS % unroll != 0 || NT % ct != 0) return -1;
2851 -: 2437: const uint32_t ITERS = KS / unroll, NB = NT / ct;
2852 -: 2438: if (grid_x == 0 || grid_x > NB) return -1;
2853 -: 2439: if (mutant && ITERS < 2) return -1;
2854 -: 2440: /* every index and immediate below must fit: 32 bits for the index arithmetic, signed 24 bits for
2855 -: 2441: * the load/store offsets (rows up to OMEGA_BW_MATMUL_MAX_M) */
2856 -: 2442: if ((uint64_t)NT * KS * 32u > 0xffffffffull || (uint64_t)(OMEGA_BW_MATMUL_MAX_M / 16u) * KS * 32u > 0xffffffffull ||
2857 -: 2443: (uint64_t)grid_x * ct * KS * 256u > 0xffffffffull || (uint64_t)N * 32u > 0xffffffffull ||
2858 -: 2444: (uint64_t)OMEGA_BW_MATMUL_MAX_M * N > 0xffffffffull)
2859 -: 2445: return -1;
2860 -: 2446: if ((uint64_t)(rt - 1) * KS * 512u + (unroll - 1) * 512u >= (1ull << 23) ||
2861 -: 2447: (uint64_t)(ct - 1) * KS * 256u + (unroll - 1) * 256u >= (1ull << 23) ||
2862 -: 2448: !frag_block_store_fits(rt, ct, N))
2863 -: 2449: return -1;
2864 -: 2450:
2865 -: 2451: omega_bw_ir_init(prog);
2866 -: 2452: int v_ptr_a = omega_bw_ir_alloc_vreg64(prog), v_ptr_b = omega_bw_ir_alloc_vreg64(prog), v_ptr_c = omega_bw_ir_alloc_vreg64(prog);
2867 -: 2453: int uv_desc = omega_bw_ir_alloc_uvreg64(prog);
2868 -: 2454: int v_tid = omega_bw_ir_alloc_vreg(prog), v_ctaid_x = omega_bw_ir_alloc_vreg(prog), v_ctaid_y = omega_bw_ir_alloc_vreg(prog);
2869 -: 2455: int v_group = omega_bw_ir_alloc_vreg(prog), v_tig = omega_bw_ir_alloc_vreg(prog), v_tcol2 = omega_bw_ir_alloc_vreg(prog);
2870 -: 2456: int v_r0 = omega_bw_ir_alloc_vreg(prog), v_r1 = omega_bw_ir_alloc_vreg(prog), v_c1 = omega_bw_ir_alloc_vreg(prog);
2871 -: 2457: int v_idx = omega_bw_ir_alloc_vreg(prog), v_col = omega_bw_ir_alloc_vreg(prog), v_cnt = omega_bw_ir_alloc_vreg(prog);
2872 -: 2458: int v_pa = omega_bw_ir_alloc_vreg64(prog), v_pbcol = omega_bw_ir_alloc_vreg64(prog);
2873 -: 2459: int v_pc0 = omega_bw_ir_alloc_vreg64(prog), v_pc1 = omega_bw_ir_alloc_vreg64(prog);
2874 -: 2460: int v_pac = omega_bw_ir_alloc_vreg64(prog), v_pbc = omega_bw_ir_alloc_vreg64(prog);
2875 -: 2461: int v_rd[16], v_ra[2][8], v_rb[2][4];
2876 -: 2462: for (uint32_t t = 0; t < rt * ct; t++) v_rd[t] = omega_bw_ir_alloc_vreg128(prog);
2877 -: 2463: for (uint32_t u = 0; u < unroll; u++) {
2878 -: 2464: for (uint32_t i = 0; i < rt; i++) v_ra[u][i] = omega_bw_ir_alloc_vreg128(prog);
2879 -: 2465: for (uint32_t j = 0; j < ct; j++) v_rb[u][j] = omega_bw_ir_alloc_vreg64(prog);
2880 -: 2466: }
2881 -: 2467: if (v_rb[unroll - 1][ct - 1] < 0 || v_ra[unroll - 1][rt - 1] < 0 || v_rd[rt * ct - 1] < 0 || uv_desc < 0) return -1;
2882 -: 2468:
2883 -: 2469: const uint32_t CTRL_STG_RDBAR3 = 0x0007e200u, CTRL_IMADW_WAIT3 = 0x009fcc00u, CTRL_MOVRZ_WAIT3 = 0x008fe200u;
2884 -: 2470:
2885 -: 2471: /* prologue: descriptor, pointers, ids (as the kernel above; a CTA's row block is rt row tiles) */
2886 -: 2472: BW_APPEND(prog, .op = BW_IR_LDCU64, .dst_vreg = uv_desc, .imm = 0x358, .is_uniform = true);
2887 -: 2473: BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_a, .imm = 0x380);
2888 -: 2474: BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_b, .imm = 0x388);
2889 -: 2475: BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_c, .imm = 0x390);
2890 -: 2476: BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_tid, .imm = BW_SR_TID_X);
2891 -: 2477: BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_ctaid_x, .imm = BW_SR_CTAID_X);
2892 -: 2478: BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_ctaid_y, .imm = BW_SR_CTAID_Y);
2893 -: 2479: BW_APPEND(prog, .op = BW_IR_MOV_IMM, .dst_vreg = v_c1, .imm = 1);
2894 -: 2480: BW_APPEND(prog, .op = BW_IR_SHF_R, .dst_vreg = v_group, .src1_vreg = v_tid, .imm = 2);
2895 -: 2481: BW_APPEND(prog, .op = BW_IR_LOP3_AND, .dst_vreg = v_tig, .src1_vreg = v_tid, .imm = 3);
2896 -: 2482: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_tcol2, .src1_vreg = v_tig, .src2_vreg = -1, .imm = 2, .src3_vreg = -1);
2897 -: 2483: /* r0 = ctaid_y * 16 * rt + group: row of this lane in row tile 0 of the block; r1 = r0 + 8 */
2898 -: 2484: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_r0, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = 16u * rt, .src3_vreg = v_group);
2899 -: 2485: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_r1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 8, .src3_vreg = v_r0);
2900 -: 2486: /* pa = A + (ctaid_y * rt * KS * 32 + tid) * 16: row tile 0 of this block, this lane's 16 bytes of step 0 */
2901 -: 2487: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = rt * KS * 32u, .src3_vreg = v_tid);
2902 -: 2488: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 16, .src3_vreg = v_ptr_a);
2903 -: 2489: /* col = ctaid_x * ct: first column tile of this CTA's first column block */
2904 -: 2490: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_ctaid_x, .src2_vreg = -1, .imm = ct, .src3_vreg = -1);
2905 -: 2491: /* pbcol = B + (col * KS * 32 + tid) * 8: column tile col, this lane's 8 bytes of step 0 */
2906 -: 2492: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = KS * 32u, .src3_vreg = v_tid);
2907 -: 2493: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbcol, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 8, .src3_vreg = v_ptr_b);
2908 -: 2494: /* pc0 = C + (r0*N + col*8 + tcol2)*4 ; pc1 with r1 */
2909 -: 2495: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = N, .src3_vreg = v_tcol2);
2910 -: 2496: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx);
2911 -: 2497: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc0, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c);
2912 -: 2498: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = N, .src3_vreg = v_tcol2);
2913 -: 2499: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx);
2914 -: 2500: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc1, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c);
2915 -: 2501:
2916 -: 2502: /* ---- column-block loop: zero the rt*ct accumulators (the first MOV waits SB3: the previous
2917 -: 2503: * block's stores have read them), rewind the K cursors ---- */
2918 -: 2504: const int L_col = (int)prog->count;
2919 -: 2505: for (uint32_t t = 0; t < rt * ct; t++)
2920 -: 2506: for (uint32_t s = 0; s < 4; s++)
2921 -: 2507: BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd[t], .dst_subreg = (int)s,
2922 -: 2508: .control = (t == 0 && s == 0) ? CTRL_MOVRZ_WAIT3 : 0);
2923 -: 2509: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pac, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pa);
2924 -: 2510: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbc, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pbcol);
2925 -: 2511: BW_APPEND(prog, .op = BW_IR_MOV_IMM, .dst_vreg = v_cnt, .imm = mutant ? ITERS - 1 : ITERS);
2926 -: 2512:
2927 -: 2513: /* ---- K loop: `unroll` steps of (rt A + ct B) loads, then the rt*ct*unroll HMMAs ---- */
2928 -: 2514: const int L_k = (int)prog->count;
2929 -: 2515: for (uint32_t u = 0; u < unroll; u++) {
2930 -: 2516: for (uint32_t i = 0; i < rt; i++)
2931 -: 2517: BW_APPEND(prog, .op = BW_IR_LDG_E_128, .dst_vreg = v_ra[u][i], .src1_vreg = v_pac, .src2_vreg = -1, .src3_vreg = -1,
2932 -: 2518: .ureg = uv_desc, .imm = u * 512u + i * KS * 512u, .control = BW_FRAG_CTRL_LDG_A);
2933 -: 2519: for (uint32_t j = 0; j < ct; j++)
2934 -: 2520: BW_APPEND(prog, .op = BW_IR_LDG_E_64, .dst_vreg = v_rb[u][j], .src1_vreg = v_pbc, .src2_vreg = -1, .src3_vreg = -1,
2935 -: 2521: .ureg = uv_desc, .imm = u * 256u + j * KS * 256u, .control = BW_FRAG_CTRL_LDG_B);
2936 -: 2522: }
2937 -: 2523: const BlackwellIROpcode hmma = (spec->precision == OMEGA_MATMUL_PRECISION_BF16) ? BW_IR_HMMA_BF16 : BW_IR_HMMA_F16;
2938 -: 2524: for (uint32_t u = 0; u < unroll; u++)
2939 -: 2525: for (uint32_t i = 0; i < rt; i++)
2940 -: 2526: for (uint32_t j = 0; j < ct; j++) {
2941 -: 2527: const int rd = v_rd[i * ct + j];
2942 -: 2528: BW_APPEND(prog, .op = hmma, .dst_vreg = rd, .src1_vreg = v_ra[u][i], .src2_vreg = v_rb[u][j], .src3_vreg = rd,
2943 -: 2529: .control = BW_FRAG_CTRL_HMMA);
2944 -: 2530: BW_APPEND(prog, .op = BW_IR_NOP, .dst_vreg = -1, .src1_vreg = -1, .src2_vreg = -1, .src3_vreg = -1, .ureg = -1,
2945 -: 2531: .control = BW_FRAG_CTRL_NOP);
2946 -: 2532: }
2947 -: 2533: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pac, .src1_vreg = v_c1, .src2_vreg = -1, .imm = unroll * 512u, .src3_vreg = v_pac);
2948 -: 2534: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbc, .src1_vreg = v_c1, .src2_vreg = -1, .imm = unroll * 256u, .src3_vreg = v_pbc);
2949 -: 2535: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_cnt, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0xffffffffu, .src3_vreg = v_cnt);
2950 -: 2536: BW_APPEND(prog, .op = BW_IR_ISETP_GE, .dst_vreg = -1, .src1_vreg = v_cnt, .src2_vreg = -1, .imm = 1, .src3_vreg = -1);
2951 -: 2537: {
2952 -: 2538: int here = (int)prog->count;
2953 -: 2539: BW_APPEND(prog, .op = BW_IR_BRA, .imm = (uint32_t)(int32_t)(L_k - here), .predicate_p0 = true);
2954 -: 2540: }
2955 -: 2541: const int L_k_end = (int)prog->count - 1;
2956 -: 2542:
2957 -: 2543: /* ---- store the rt*ct tiles: tile (i, j) at +i*16*N*4 + j*32 bytes from pc0 (rows r0) and pc1 (rows r1) ---- */
2958 -: 2544: for (uint32_t i = 0; i < rt; i++)
2959 -: 2545: for (uint32_t j = 0; j < ct; j++) {
2960 -: 2546: const int rd = v_rd[i * ct + j];
2961 -: 2547: const uint32_t off = i * 16u * N * 4u + j * 32u;
2962 -: 2548: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc0, .src2_vreg = rd, .src2_subreg = 0, .src3_vreg = -1, .ureg = uv_desc, .imm = off, .control = CTRL_STG_RDBAR3);
2963 -: 2549: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc0, .src2_vreg = rd, .src2_subreg = 1, .src3_vreg = -1, .ureg = uv_desc, .imm = off + 4u, .control = CTRL_STG_RDBAR3);
2964 -: 2550: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc1, .src2_vreg = rd, .src2_subreg = 2, .src3_vreg = -1, .ureg = uv_desc, .imm = off, .control = CTRL_STG_RDBAR3);
2965 -: 2551: BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc1, .src2_vreg = rd, .src2_subreg = 3, .src3_vreg = -1, .ureg = uv_desc, .imm = off + 4u, .control = CTRL_STG_RDBAR3);
2966 -: 2552: }
2967 -: 2553: /* next column block: col += grid_x*ct ; C by grid_x*ct*8 f32 (waits SB3 first) ; B by grid_x*ct tiles of KS*256 bytes */
2968 -: 2554: BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * ct, .src3_vreg = v_col);
2969 -: 2555: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc0, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * ct * 32u, .src3_vreg = v_pc0, .control = CTRL_IMADW_WAIT3);
2970 -: 2556: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * ct * 32u, .src3_vreg = v_pc1);
2971 -: 2557: BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbcol, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * ct * KS * 256u, .src3_vreg = v_pbcol);
2972 -: 2558: BW_APPEND(prog, .op = BW_IR_ISETP_GE, .dst_vreg = -1, .src1_vreg = v_col, .src2_vreg = -1, .imm = NT, .src3_vreg = -1);
2973 -: 2559: {
2974 -: 2560: int here = (int)prog->count;
2975 -: 2561: BW_APPEND(prog, .op = BW_IR_BRA, .imm = (uint32_t)(int32_t)(L_col - here), .predicate_p0 = true, .predicate_not = true);
2976 -: 2562: }
2977 -: 2563: const int L_col_end = (int)prog->count - 1;
2978 -: 2564: BW_APPEND(prog, .op = BW_IR_EXIT);
2979 -: 2565: BW_APPEND(prog, .op = BW_IR_BRA);
2980 -: 2566:
2981 -: 2567: /* loop-carried values live to the end of their loop (as the kernel above) */
2982 -: 2568: const int col_carried[] = { v_c1, v_col, v_pa, v_pbcol, v_pc0, v_pc1 };
2983 -: 2569: for (size_t i = 0; i < sizeof col_carried / sizeof col_carried[0]; i++) bw_live_until(prog, col_carried[i], L_col_end);
2984 -: 2570: for (uint32_t t = 0; t < rt * ct; t++) bw_live_until(prog, v_rd[t], L_col_end);
2985 -: 2571: const int k_carried[] = { v_pac, v_pbc, v_cnt };
2986 -: 2572: for (size_t i = 0; i < sizeof k_carried / sizeof k_carried[0]; i++) bw_live_until(prog, k_carried[i], L_k_end);
2987 -: 2573: bw_keep_alive(prog, L_k, L_k_end, L_k_end);
2988 -: 2574: return omega_bw_regalloc_solve(prog);
2989 -: 2575:}
2990 -: 2576:#else
2991function legacy_omega_blackwell_codegen_matmul_frag_block_prog called 0 returned 0% blocks executed 0%
2992 #####: 2577:int omega_blackwell_codegen_matmul_frag_block_prog(const OmegaMatMulSpec *s, uint32_t grid, uint32_t u,
2993 -: 2578: uint32_t rt, uint32_t ct, int mutant, BlackwellIRProgram *p) {
2994 #####: 2579: return bw_om_matprog(omega_cg_block, s, grid, u, rt, ct, mutant, p);
2995call 0 never executed
2996 -: 2580:}
2997 -: 2581:#endif
2998 -: 2582:
2999 -: 2583:#ifndef OMEGA_GPU_NO_POSIX
3000function legacy_omega_blackwell_codegen_matmul_frag_block called 0 returned 0% blocks executed 0%
3001 #####: 2584:int omega_blackwell_codegen_matmul_frag_block(const OmegaMatMulSpec *spec, uint32_t grid_x, uint32_t unroll,
3002 -: 2585: uint32_t rt, uint32_t ct, int mutant, OmegaBlackwellKernel *kernel) {
3003 #####: 2586: if (!spec || !kernel) return -1;
3004branch 0 never executed (fallthrough)
3005branch 1 never executed
3006branch 2 never executed (fallthrough)
3007branch 3 never executed
3008 -: 2587: BlackwellIRProgram prog;
3009 #####: 2588: if (omega_blackwell_codegen_matmul_frag_block_prog(spec, grid_x, unroll, rt, ct, mutant, &prog) != 0) return -1;
3010call 0 never executed
3011branch 1 never executed (fallthrough)
3012branch 2 never executed
3013 #####: 2589: return bw_kernel_alloc_encode(&prog, OMEGA_BW_CODE_CAP_MAX, kernel);
3014call 0 never executed
3015 -: 2590:}
3016 -: 2591:#endif
3017 -: 2592:
3018 -: 2593:/* The row and column tiles one warp owns in the blocked kernel: the largest of 4, 2, 1 dividing the
3019 -: 2594: * row tiles (rt), and for rt > 1 the largest of 4, 2, 1 dividing the column tiles (ct); rt = ct = 1
3020 -: 2595: * is the single-tile kernel (decode rows). An rt whose last C tile's store offset does not fit the
3021 -: 2596: * 24-bit immediate (frag_block_store_fits: wide N such as lm_head) steps down, to 1 at the end. */
3022 -: 2597:#ifdef BW_MATMUL_C_PRIMARY
3023 -: 2598:void omega_matmul_frag_block_shape(uint32_t mt, uint32_t nt, uint32_t *rt, uint32_t *ct) {
3024 -: 2599: uint32_t r = mt % 4u == 0 ? 4u : mt % 2u == 0 ? 2u : 1u, c = 1u;
3025 -: 2600: for (; r > 1; r /= 2u) {
3026 -: 2601: c = nt % 4u == 0 ? 4u : nt % 2u == 0 ? 2u : 1u;
3027 -: 2602: if (frag_block_store_fits(r, c, nt * 8u)) break;
3028 -: 2603: }
3029 -: 2604: *rt = r;
3030 -: 2605: *ct = r > 1 ? c : 1u;
3031 -: 2606:}
3032 -: 2607:
3033 -: 2608:/* loads per pass at or under 8 (see the kernel comment): unroll 2 only when 2*(rt+ct) fits and KS is even */
3034 -: 2609:uint32_t omega_matmul_frag_block_unroll(uint32_t kp, uint32_t rt, uint32_t ct) {
3035 -: 2610: const uint32_t ks = kp / 16u;
3036 -: 2611: return (ks % 2u == 0 && 2u * (rt + ct) <= 8u) ? 2u : 1u;
3037 -: 2612:}
3038 -: 2613:
3039 -: 2614:uint32_t omega_matmul_frag_unroll(uint32_t kp) {
3040 -: 2615: const uint32_t ks = kp / 16u;
3041 -: 2616: return ks % 4u == 0 ? 4u : ks % 2u == 0 ? 2u : 1u;
3042 -: 2617:}
3043 -: 2618:#else
3044function bw_mat_decide called 0 returned 0% blocks executed 0%
3045 #####: 2619:static uint32_t bw_mat_decide(uint64_t kind, uint64_t a, uint64_t b, uint64_t c) {
3046 #####: 2620: uint64_t result = 0;
3047 #####: 2621: if (omega_cg_matmul(&result, kind, a, b, c) != 0) __builtin_trap();
3048call 0 never executed
3049branch 1 never executed (fallthrough)
3050branch 2 never executed
3051call 3 never executed
3052 #####: 2622: return (uint32_t)result;
3053 -: 2623:}
3054function legacy_omega_matmul_frag_block_shape called 0 returned 0% blocks executed 0%
3055 #####: 2624:void omega_matmul_frag_block_shape(uint32_t mt, uint32_t nt, uint32_t *rt, uint32_t *ct) {
3056 #####: 2625: uint32_t shape = bw_mat_decide(0, mt, nt, 0);
3057call 0 never executed
3058 #####: 2626: *rt = shape & 255u;
3059 #####: 2627: *ct = shape >> 8;
3060 #####: 2628:}
3061function legacy_omega_matmul_frag_block_unroll called 0 returned 0% blocks executed 0%
3062 #####: 2629:uint32_t omega_matmul_frag_block_unroll(uint32_t kp, uint32_t rt, uint32_t ct) {
3063 #####: 2630: return bw_mat_decide(1, kp, rt, ct);
3064call 0 never executed
3065 -: 2631:}
3066function legacy_omega_matmul_frag_unroll called 0 returned 0% blocks executed 0%
3067 #####: 2632:uint32_t omega_matmul_frag_unroll(uint32_t kp) {
3068 #####: 2633: return bw_mat_decide(2, kp, 0, 0);
3069call 0 never executed
3070 -: 2634:}
3071 -: 2635:#endif
3072 -: 2636:
3073 -: 2637:/* A block (mt, ks) holds rows 16mt..16mt+15 and columns 16ks..16ks+15 as 256 bf16 at element
3074 -: 2638: * (mt*KS + ks)*256; inside the block, element (rr, cc) sits at lane*8 + e with lane = (rr%8)*4 + (cc%8)/2
3075 -: 2639: * and e = (cc/8)*4 + (rr/8)*2 + cc%2 (the HMMA.16816 A fragment order, header comment). The 256-entry
3076 -: 2640: * table makes the pack a tile loop with no per-element division (2026-10-12: the per-element form with
3077 -: 2641: * six divisions and a conversion call per element was ~2.5 ms per MB of activations at m = 128). */
3078 -: 2642:static uint16_t g_frag_a_tab[256];
3079function frag_a_tab_init called 0 returned 0% blocks executed 0%
3080 #####: 2643:static void frag_a_tab_init(void) {
3081 #####: 2644: if (g_frag_a_tab[255]) return;
3082branch 0 never executed (fallthrough)
3083branch 1 never executed
3084 #####: 2645: for (uint32_t rr = 0; rr < 16; rr++)
3085branch 0 never executed
3086branch 1 never executed (fallthrough)
3087 #####: 2646: for (uint32_t cc = 0; cc < 16; cc++)
3088branch 0 never executed
3089branch 1 never executed (fallthrough)
3090 #####: 2647: g_frag_a_tab[rr * 16 + cc] = (uint16_t)((((rr & 7u) * 4u + ((cc & 7u) >> 1)) * 8u) + (cc >> 3) * 4u + (rr >> 3) * 2u + (cc & 1u));
3091 -: 2648:}
3092 -: 2649:/* bit for bit what the compiler's (__bf16)f cast gives (gpu_matmul_api_test checks it against
3093 -: 2650: * omega_fp32_to_bf16 on ties, denormals, inf and NaN payloads): round to nearest even, a NaN keeps
3094 -: 2651: * its top payload bits and is made quiet. gcc 13 on aarch64 emits the cast as a call to the
3095 -: 2652: * soft-float routine __truncsfbf2 per element, which was most of the packing cost. */
3096function frag_f32_to_bf16 called 0 returned 0% blocks executed 0%
3097 #####: 2653:static inline uint16_t frag_f32_to_bf16(float f) {
3098 -: 2654: uint32_t u;
3099 #####: 2655: memcpy(&u, &f, 4);
3100 #####: 2656: if ((u & 0x7f800000u) == 0x7f800000u) return (uint16_t)((u >> 16) | ((u & 0x007fffffu) ? 0x0040u : 0u));
3101branch 0 never executed (fallthrough)
3102branch 1 never executed
3103branch 2 never executed (fallthrough)
3104branch 3 never executed
3105 #####: 2657: return (uint16_t)((u + 0x7fffu + ((u >> 16) & 1u)) >> 16);
3106 -: 2658:}
3107 -: 2659:#define FRAG_PACK_A_BODY(LOAD) \
3108 -: 2660: do { \
3109 -: 2661: const uint32_t KS = kp / 16u; \
3110 -: 2662: frag_a_tab_init(); \
3111 -: 2663: memset(dst, 0, (size_t)mp * kp * sizeof *dst); \
3112 -: 2664: for (uint32_t mt = 0; mt < (m + 15u) / 16u; mt++) { \
3113 -: 2665: const uint32_t r1 = m - mt * 16u < 16u ? m - mt * 16u : 16u; \
3114 -: 2666: for (uint32_t ks = 0; ks < (k + 15u) / 16u; ks++) { \
3115 -: 2667: const uint32_t c1 = k - ks * 16u < 16u ? k - ks * 16u : 16u; \
3116 -: 2668: uint16_t *blk = dst + ((size_t)mt * KS + ks) * 256u; \
3117 -: 2669: for (uint32_t rr = 0; rr < r1; rr++) { \
3118 -: 2670: const uint16_t *tab = g_frag_a_tab + rr * 16u; \
3119 -: 2671: const size_t src = (size_t)(mt * 16u + rr) * k + ks * 16u; \
3120 -: 2672: for (uint32_t cc = 0; cc < c1; cc++) blk[tab[cc]] = LOAD(a[src + cc]); \
3121 -: 2673: } \
3122 -: 2674: } \
3123 -: 2675: } \
3124 -: 2676: } while (0)
3125 -: 2677:#define FRAG_ID(x) (x)
3126function legacy_omega_matmul_frag_pack_a called 0 returned 0% blocks executed 0%
3127 #####: 2678:void omega_matmul_frag_pack_a(const uint16_t *a, uint32_t m, uint32_t k, uint32_t mp, uint32_t kp, uint16_t *dst) {
3128 #####: 2679: FRAG_PACK_A_BODY(FRAG_ID);
3129call 0 never executed
3130branch 1 never executed
3131branch 2 never executed (fallthrough)
3132branch 3 never executed
3133branch 4 never executed (fallthrough)
3134branch 5 never executed
3135branch 6 never executed (fallthrough)
3136branch 7 never executed
3137branch 8 never executed (fallthrough)
3138 #####: 2680:}
3139function legacy_omega_matmul_frag_pack_a_f32 called 0 returned 0% blocks executed 0%
3140 #####: 2681:void omega_matmul_frag_pack_a_f32(const float *a, uint32_t m, uint32_t k, uint32_t mp, uint32_t kp, uint16_t *dst) {
3141 #####: 2682: FRAG_PACK_A_BODY(frag_f32_to_bf16);
3142call 0 never executed
3143call 1 never executed
3144branch 2 never executed
3145branch 3 never executed (fallthrough)
3146branch 4 never executed
3147branch 5 never executed (fallthrough)
3148branch 6 never executed
3149branch 7 never executed (fallthrough)
3150branch 8 never executed
3151branch 9 never executed (fallthrough)
3152 #####: 2683:}
3153 -: 2684:
3154 -: 2685:/* Row 0 only, every column of every K block (zeros past k): for a one-row call whose buffer already
3155 -: 2686: * holds zeros in rows 1..15 of every block from an earlier full pack of the same width. */
3156 -: 2687:#define FRAG_PACK_A_ROW0_BODY(LOAD) \
3157 -: 2688: do { \
3158 -: 2689: const uint32_t KS = kp / 16u; \
3159 -: 2690: frag_a_tab_init(); \
3160 -: 2691: const uint16_t *tab = g_frag_a_tab; \
3161 -: 2692: for (uint32_t ks = 0; ks < KS; ks++) { \
3162 -: 2693: uint16_t *blk = dst + (size_t)ks * 256u; \
3163 -: 2694: const uint32_t c0 = ks * 16u, c1 = k - c0 < 16u ? k - c0 : 16u; \
3164 -: 2695: for (uint32_t cc = 0; cc < c1; cc++) blk[tab[cc]] = LOAD(a[c0 + cc]); \
3165 -: 2696: for (uint32_t cc = c1; cc < 16u; cc++) blk[tab[cc]] = 0; \
3166 -: 2697: } \
3167 -: 2698: } while (0)
3168function legacy_omega_matmul_frag_pack_a_row0 called 0 returned 0% blocks executed 0%
3169 #####: 2699:void omega_matmul_frag_pack_a_row0(const uint16_t *a, uint32_t k, uint32_t kp, uint16_t *dst) {
3170 #####: 2700: FRAG_PACK_A_ROW0_BODY(FRAG_ID);
3171call 0 never executed
3172branch 1 never executed
3173branch 2 never executed (fallthrough)
3174branch 3 never executed
3175branch 4 never executed (fallthrough)
3176branch 5 never executed
3177branch 6 never executed (fallthrough)
3178 #####: 2701:}
3179function legacy_omega_matmul_result_sentinels called 0 returned 0% blocks executed 0%
3180 #####: 2702:size_t omega_matmul_result_sentinels(float *cd, uint32_t m, uint32_t n, uint32_t np, float poison, int set) {
3181 -: 2703: /* one word per 16 x 8 fragment tile that holds a real output word: the tile's last real row and column */
3182 #####: 2704: size_t count = 0;
3183 #####: 2705: if (m == 0 || n == 0) return 0;
3184branch 0 never executed (fallthrough)
3185branch 1 never executed
3186branch 2 never executed (fallthrough)
3187branch 3 never executed
3188 #####: 2706: const uint32_t mt = (m + 15u) / 16u, nt = (n + 7u) / 8u;
3189 #####: 2707: for (uint32_t ti = 0; ti < mt; ti++) {
3190branch 0 never executed
3191branch 1 never executed (fallthrough)
3192 #####: 2708: uint32_t r = ti * 16u + 15u; if (r >= m) r = m - 1u;
3193branch 0 never executed (fallthrough)
3194branch 1 never executed
3195 #####: 2709: float *row = cd + (size_t)r * np;
3196 #####: 2710: for (uint32_t tj = 0; tj < nt; tj++) {
3197branch 0 never executed
3198branch 1 never executed (fallthrough)
3199 #####: 2711: uint32_t c = tj * 8u + 7u; if (c >= n) c = n - 1u;
3200branch 0 never executed (fallthrough)
3201branch 1 never executed
3202 #####: 2712: if (set) { row[c] = poison; count++; }
3203branch 0 never executed (fallthrough)
3204branch 1 never executed
3205 #####: 2713: else if (row[c] == poison) count++;
3206branch 0 never executed (fallthrough)
3207branch 1 never executed
3208 -: 2714: }
3209 -: 2715: }
3210 #####: 2716: return count;
3211 -: 2717:}
3212 -: 2718:
3213function legacy_omega_matmul_frag_pack_a_row0_f32 called 0 returned 0% blocks executed 0%
3214 #####: 2719:void omega_matmul_frag_pack_a_row0_f32(const float *a, uint32_t k, uint32_t kp, uint16_t *dst) {
3215 #####: 2720: FRAG_PACK_A_ROW0_BODY(frag_f32_to_bf16);
3216call 0 never executed
3217call 1 never executed
3218branch 2 never executed
3219branch 3 never executed (fallthrough)
3220branch 4 never executed
3221branch 5 never executed (fallthrough)
3222branch 6 never executed
3223branch 7 never executed (fallthrough)
3224 #####: 2721:}
3225 -: 2722:
3226function legacy_omega_matmul_frag_pack_b called 0 returned 0% blocks executed 0%
3227 #####: 2723:void omega_matmul_frag_pack_b(const uint16_t *b, uint32_t k, uint32_t n, uint32_t kp,
3228 -: 2724: uint32_t nt0, uint32_t nt1, uint16_t *dst) {
3229 #####: 2725: const uint32_t KS = kp / 16u;
3230 #####: 2726: memset(dst, 0, (size_t)(nt1 - nt0) * KS * 128u * sizeof *dst);
3231 #####: 2727: for (uint32_t row = 0; row < k; row++) {
3232branch 0 never executed
3233branch 1 never executed (fallthrough)
3234 #####: 2728: const uint32_t ks = row / 16u, rr = row % 16u, khi = rr / 8u, tig = (rr % 8u) / 2u, lo = rr % 2u;
3235 #####: 2729: const uint16_t *src = &b[(size_t)row * n];
3236 #####: 2730: for (uint32_t nt = nt0; nt < nt1; nt++) {
3237branch 0 never executed
3238branch 1 never executed (fallthrough)
3239 #####: 2731: const uint32_t c0 = nt * 8u;
3240 #####: 2732: for (uint32_t group = 0; group < 8u && c0 + group < n; group++) {
3241branch 0 never executed (fallthrough)
3242branch 1 never executed
3243branch 2 never executed
3244branch 3 never executed (fallthrough)
3245 #####: 2733: const size_t lane = group * 4u + tig;
3246 #####: 2734: dst[(((size_t)(nt - nt0) * KS + ks) * 32u + lane) * 4u + khi * 2u + lo] = src[c0 + group];
3247 -: 2735: }
3248 -: 2736: }
3249 -: 2737: }
3250 #####: 2738:}
3251 -: 2739:
3252function legacy_omega_blackwell_verify_codegen_fixtures called 0 returned 0% blocks executed 0%
3253 #####: 2740:int omega_blackwell_verify_codegen_fixtures(void) {
3254 -: 2741: OmegaRegAlloc ra;
3255 #####: 2742: memset(&ra, 0, sizeof(ra));
3256 #####: 2743: ra.vreg_to_phys[0] = 2;
3257 #####: 2744: ra.vreg_to_phys[1] = 4;
3258 #####: 2745: ra.vreg_to_phys[2] = 6;
3259 #####: 2746: ra.vreg_to_phys[3] = 7;
3260 #####: 2747: ra.uvreg_to_phys[0] = 4;
3261 -: 2748:
3262 -: 2749: uint32_t w[4];
3263 -: 2750:
3264 -: 2751: /* 1. MOV R7, RZ */
3265 #####: 2752: BlackwellIRInsn insn_mov_rz = { .op = BW_IR_MOV_RZ, .dst_vreg = 3 };
3266 #####: 2753: if (encode_single_insn(&insn_mov_rz, &ra, w) != 0) return -1;
3267call 0 never executed
3268branch 1 never executed (fallthrough)
3269branch 2 never executed
3270 #####: 2754: if (w[0] != (0x7202 | (7 << 16)) || w[1] != 0xff || w[2] != 0x00000f00) return -2;
3271branch 0 never executed (fallthrough)
3272branch 1 never executed
3273branch 2 never executed (fallthrough)
3274branch 3 never executed
3275branch 4 never executed (fallthrough)
3276branch 5 never executed
3277 -: 2755:
3278 -: 2756: /* 2. MOV R2, 1 */
3279 #####: 2757: BlackwellIRInsn insn_mov_imm = { .op = BW_IR_MOV_IMM, .dst_vreg = 0, .imm = 1 };
3280 #####: 2758: if (encode_single_insn(&insn_mov_imm, &ra, w) != 0) return -3;
3281call 0 never executed
3282branch 1 never executed (fallthrough)
3283branch 2 never executed
3284 #####: 2759: if (w[0] != (0x7802 | (2 << 16)) || w[1] != 1 || w[2] != 0x00000f00) return -4;
3285branch 0 never executed (fallthrough)
3286branch 1 never executed
3287branch 2 never executed (fallthrough)
3288branch 3 never executed
3289branch 4 never executed (fallthrough)
3290branch 5 never executed
3291 -: 2760:
3292 -: 2761: /* 3. Register-Register IMAD: IMAD R7, R2, R6, R7 */
3293 #####: 2762: BlackwellIRInsn insn_imad_rr = { .op = BW_IR_IMAD, .dst_vreg = 3, .src1_vreg = 0, .src2_vreg = 2, .src3_vreg = 3 };
3294 #####: 2763: if (encode_single_insn(&insn_imad_rr, &ra, w) != 0) return -5;
3295call 0 never executed
3296branch 1 never executed (fallthrough)
3297branch 2 never executed
3298 #####: 2764: if (w[0] != (0x7224 | (7 << 16) | (2 << 24)) || w[1] != 6 || w[2] != (0x078e0200 | 7)) return -6;
3299branch 0 never executed (fallthrough)
3300branch 1 never executed
3301branch 2 never executed (fallthrough)
3302branch 3 never executed
3303branch 4 never executed (fallthrough)
3304branch 5 never executed
3305 -: 2765:
3306 -: 2766: /* 4. Immediate IMAD: IMAD R6, R2, 16, RZ */
3307 #####: 2767: BlackwellIRInsn insn_imad_imm = { .op = BW_IR_IMAD, .dst_vreg = 2, .src1_vreg = 0, .src2_vreg = -1, .imm = 16, .src3_vreg = -1 };
3308 #####: 2768: if (encode_single_insn(&insn_imad_imm, &ra, w) != 0) return -7;
3309call 0 never executed
3310branch 1 never executed (fallthrough)
3311branch 2 never executed
3312 #####: 2769: if (w[0] != (0x7824 | (6 << 16) | (2 << 24)) || w[1] != 16 || w[2] != 0x078e02ff) return -8;
3313branch 0 never executed (fallthrough)
3314branch 1 never executed
3315branch 2 never executed (fallthrough)
3316branch 3 never executed
3317branch 4 never executed (fallthrough)
3318branch 5 never executed
3319 -: 2770:
3320 -: 2771: /* 5. IMAD.WIDE: IMAD.WIDE R4, R2, 4, R4 */
3321 #####: 2772: BlackwellIRInsn insn_imad_wide = { .op = BW_IR_IMAD_WIDE, .dst_vreg = 1, .src1_vreg = 0, .imm = 4, .src3_vreg = 1 };
3322 #####: 2773: if (encode_single_insn(&insn_imad_wide, &ra, w) != 0) return -9;
3323call 0 never executed
3324branch 1 never executed (fallthrough)
3325branch 2 never executed
3326 #####: 2774: if (w[0] != (0x7825 | (4 << 16) | (2 << 24)) || w[1] != 4 || w[2] != (0x078e0000 | 4)) return -10;
3327branch 0 never executed (fallthrough)
3328branch 1 never executed
3329branch 2 never executed (fallthrough)
3330branch 3 never executed
3331branch 4 never executed (fallthrough)
3332branch 5 never executed
3333 -: 2775:
3334 -: 2776: /* 6. LDC.64 R4, c[0x0][0x380] */
3335 #####: 2777: BlackwellIRInsn insn_ldc64 = { .op = BW_IR_LDC64, .dst_vreg = 1, .imm = 0x380 };
3336 #####: 2778: if (encode_single_insn(&insn_ldc64, &ra, w) != 0) return -11;
3337call 0 never executed
3338branch 1 never executed (fallthrough)
3339branch 2 never executed
3340 #####: 2779: if (w[0] != (0xff007b82 | (4 << 16)) || w[1] != ((0x380 << 6) & 0x00ffff00) || w[2] != 0x00000a00) return -12;
3341branch 0 never executed (fallthrough)
3342branch 1 never executed
3343branch 2 never executed (fallthrough)
3344branch 3 never executed
3345branch 4 never executed (fallthrough)
3346branch 5 never executed
3347 -: 2780:
3348 -: 2781: /* 7. LDCU.64 UR4, c[0x0][0x358] */
3349 #####: 2782: BlackwellIRInsn insn_ldcu64 = { .op = BW_IR_LDCU64, .dst_vreg = 0, .imm = 0x358, .is_uniform = true };
3350 #####: 2783: if (encode_single_insn(&insn_ldcu64, &ra, w) != 0) return -13;
3351call 0 never executed
3352branch 1 never executed (fallthrough)
3353branch 2 never executed
3354 #####: 2784: if (w[0] != (0xff0077ac | (4 << 16)) || w[1] != ((0x358 << 5) & 0x00ffff00) || w[2] != 0x08000a00) return -14;
3355branch 0 never executed (fallthrough)
3356branch 1 never executed
3357branch 2 never executed (fallthrough)
3358branch 3 never executed
3359branch 4 never executed (fallthrough)
3360branch 5 never executed
3361 -: 2785:
3362 -: 2786: /* 8. LDG.E R2, desc[UR4][R4.64] */
3363 #####: 2787: BlackwellIRInsn insn_ldg = { .op = BW_IR_LDG_E, .dst_vreg = 0, .src1_vreg = 1, .ureg = 0 };
3364 #####: 2788: if (encode_single_insn(&insn_ldg, &ra, w) != 0) return -15;
3365call 0 never executed
3366branch 1 never executed (fallthrough)
3367branch 2 never executed
3368 #####: 2789: if (w[0] != (0x7981 | (2 << 16) | (4 << 24)) || w[1] != 4 || w[2] != 0x0c1e1900) return -16;
3369branch 0 never executed (fallthrough)
3370branch 1 never executed
3371branch 2 never executed (fallthrough)
3372branch 3 never executed
3373branch 4 never executed (fallthrough)
3374branch 5 never executed
3375 -: 2790:
3376 -: 2791: /* 9. STG.E desc[UR4][R4.64], R7 */
3377 #####: 2792: BlackwellIRInsn insn_stg = { .op = BW_IR_STG_E, .src1_vreg = 1, .src2_vreg = 3, .ureg = 0 };
3378 #####: 2793: if (encode_single_insn(&insn_stg, &ra, w) != 0) return -17;
3379call 0 never executed
3380branch 1 never executed (fallthrough)
3381branch 2 never executed
3382 #####: 2794: if (w[0] != (0x7986 | (4 << 24)) || w[1] != 7 || w[2] != (0x0c101900 | 4)) return -18;
3383branch 0 never executed (fallthrough)
3384branch 1 never executed
3385branch 2 never executed (fallthrough)
3386branch 3 never executed
3387branch 4 never executed (fallthrough)
3388branch 5 never executed
3389 -: 2795:
3390 -: 2796: /* 10. S2R R2, SR_CTAID.X */
3391 #####: 2797: BlackwellIRInsn insn_s2r = { .op = BW_IR_S2R, .dst_vreg = 0, .imm = BW_SR_CTAID_X };
3392 #####: 2798: if (encode_single_insn(&insn_s2r, &ra, w) != 0) return -19;
3393call 0 never executed
3394branch 1 never executed (fallthrough)
3395branch 2 never executed
3396 #####: 2799: if (w[0] != (0x7919 | (2 << 16)) || w[2] != (BW_SR_CTAID_X << 8)) return -20;
3397branch 0 never executed (fallthrough)
3398branch 1 never executed
3399branch 2 never executed (fallthrough)
3400branch 3 never executed
3401 -: 2800:
3402 -: 2801: /* 11. HMMA.16816.F32 R4, R4, R2, RZ */
3403 #####: 2802: BlackwellIRInsn insn_hmma_f16 = { .op = BW_IR_HMMA_F16, .dst_vreg = 1, .src1_vreg = 1, .src2_vreg = 0, .src3_vreg = -1 };
3404 #####: 2803: if (encode_single_insn(&insn_hmma_f16, &ra, w) != 0) return -21;
3405call 0 never executed
3406branch 1 never executed (fallthrough)
3407branch 2 never executed
3408 #####: 2804: if (w[0] != 0x0404723c || w[1] != 0x00000002 || w[2] != 0x000018ff || w[3] != 0x000fe200) return -22;
3409branch 0 never executed (fallthrough)
3410branch 1 never executed
3411branch 2 never executed (fallthrough)
3412branch 3 never executed
3413branch 4 never executed (fallthrough)
3414branch 5 never executed
3415branch 6 never executed (fallthrough)
3416branch 7 never executed
3417 -: 2805:
3418 -: 2806: /* 12. HMMA.16816.F32.BF16 R4, R4, R2, RZ */
3419 #####: 2807: BlackwellIRInsn insn_hmma_bf16 = { .op = BW_IR_HMMA_BF16, .dst_vreg = 1, .src1_vreg = 1, .src2_vreg = 0, .src3_vreg = -1 };
3420 -: 2808: uint32_t w_bf16[4];
3421 #####: 2809: if (encode_single_insn(&insn_hmma_bf16, &ra, w_bf16) != 0) return -23;
3422call 0 never executed
3423branch 1 never executed (fallthrough)
3424branch 2 never executed
3425 #####: 2810: if (w_bf16[0] != 0x0404723c || w_bf16[1] != 0x00000002 || w_bf16[2] != 0x000418ff || w_bf16[3] != 0x000fe200) return -24;
3426branch 0 never executed (fallthrough)
3427branch 1 never executed
3428branch 2 never executed (fallthrough)
3429branch 3 never executed
3430branch 4 never executed (fallthrough)
3431branch 5 never executed
3432branch 6 never executed (fallthrough)
3433branch 7 never executed
3434 -: 2811:
3435 -: 2812: /* 13. Differential Invariant: w[2] bit 18 toggles strictly between FP16 and BF16 */
3436 #####: 2813: if ((w[2] ^ w_bf16[2]) != 0x00040000) return -25;
3437branch 0 never executed (fallthrough)
3438branch 1 never executed
3439 #####: 2814: if (w[0] != w_bf16[0] || w[1] != w_bf16[1] || w[3] != w_bf16[3]) return -26;
3440branch 0 never executed (fallthrough)
3441branch 1 never executed
3442branch 2 never executed (fallthrough)
3443branch 3 never executed
3444branch 4 never executed (fallthrough)
3445branch 5 never executed
3446 -: 2815:
3447 -: 2816: /* 14. SHF.R.U32.HI R4, RZ, 2, R2 */
3448 #####: 2817: BlackwellIRInsn insn_shf = { .op = BW_IR_SHF_R, .dst_vreg = 1, .src1_vreg = 0, .imm = 2 };
3449 #####: 2818: if (encode_single_insn(&insn_shf, &ra, w) != 0) return -27;
3450call 0 never executed
3451branch 1 never executed (fallthrough)
3452branch 2 never executed
3453 #####: 2819: if (w[0] != 0xff047819 || w[1] != 2 || w[2] != 0x00011602 || w[3] != 0x001fca00) return -28;
3454branch 0 never executed (fallthrough)
3455branch 1 never executed
3456branch 2 never executed (fallthrough)
3457branch 3 never executed
3458branch 4 never executed (fallthrough)
3459branch 5 never executed
3460branch 6 never executed (fallthrough)
3461branch 7 never executed
3462 -: 2820:
3463 -: 2821: /* 15. LOP3.LUT R4, R2, 3, RZ, 0xc0, !PT */
3464 #####: 2822: BlackwellIRInsn insn_lop3 = { .op = BW_IR_LOP3_AND, .dst_vreg = 1, .src1_vreg = 0, .imm = 3 };
3465 #####: 2823: if (encode_single_insn(&insn_lop3, &ra, w) != 0) return -29;
3466call 0 never executed
3467branch 1 never executed (fallthrough)
3468branch 2 never executed
3469 #####: 2824: if (w[0] != 0x02047812 || w[1] != 3 || w[2] != 0x078ec0ff || w[3] != 0x001fca00) return -30;
3470branch 0 never executed (fallthrough)
3471branch 1 never executed
3472branch 2 never executed (fallthrough)
3473branch 3 never executed
3474branch 4 never executed (fallthrough)
3475branch 5 never executed
3476branch 6 never executed (fallthrough)
3477branch 7 never executed
3478 -: 2825:
3479 -: 2826: /* 16. LDG.E.U16 R2, desc[UR4][R4.64] */
3480 #####: 2827: BlackwellIRInsn insn_ldg16 = { .op = BW_IR_LDG_E_U16, .dst_vreg = 0, .src1_vreg = 1, .ureg = 0 };
3481 #####: 2828: if (encode_single_insn(&insn_ldg16, &ra, w) != 0) return -31;
3482call 0 never executed
3483branch 1 never executed (fallthrough)
3484branch 2 never executed
3485 #####: 2829: if (w[0] != 0x04027981 || w[1] != 4 || w[2] != 0x0c1e1500 || w[3] != 0x000f2200) return -32;
3486branch 0 never executed (fallthrough)
3487branch 1 never executed
3488branch 2 never executed (fallthrough)
3489branch 3 never executed
3490branch 4 never executed (fallthrough)
3491branch 5 never executed
3492branch 6 never executed (fallthrough)
3493branch 7 never executed
3494 -: 2830:
3495 -: 2831: /* A zero-delta branch stays the self-branch the matmul kernels already emit. */
3496 #####: 2832: BlackwellIRInsn insn_bra0 = { .op = BW_IR_BRA };
3497 #####: 2833: if (encode_single_insn(&insn_bra0, &ra, w) != 0) return -33;
3498call 0 never executed
3499branch 1 never executed (fallthrough)
3500branch 2 never executed
3501 #####: 2834: if (w[0] != 0x00fc7947 || w[1] != 0xfffffffc || w[2] != 0x0383ffff || w[3] != 0x000fc000) return -34;
3502branch 0 never executed (fallthrough)
3503branch 1 never executed
3504branch 2 never executed (fallthrough)
3505branch 3 never executed
3506branch 4 never executed (fallthrough)
3507branch 5 never executed
3508branch 6 never executed (fallthrough)
3509branch 7 never executed
3510 -: 2835:
3511 #####: 2836: BlackwellIRInsn insn_ge = { .op = BW_IR_ISETP_GE_U32, .src1_vreg = 1, .src2_vreg = 2 };
3512 #####: 2837: if (encode_single_insn(&insn_ge, &ra, w) != 0) return -35;
3513call 0 never executed
3514branch 1 never executed (fallthrough)
3515branch 2 never executed
3516 #####: 2838: if (w[0] != (0x720c | (4 << 24)) || w[1] != 6 || w[2] != 0x03f06070) return -36;
3517branch 0 never executed (fallthrough)
3518branch 1 never executed
3519branch 2 never executed (fallthrough)
3520branch 3 never executed
3521branch 4 never executed (fallthrough)
3522branch 5 never executed
3523 -: 2839:
3524 #####: 2840: BlackwellIRInsn insn_xor = { .op = BW_IR_LOP3_XOR, .dst_vreg = 1, .src1_vreg = 0, .src2_vreg = 2 };
3525 #####: 2841: if (encode_single_insn(&insn_xor, &ra, w) != 0) return -37;
3526call 0 never executed
3527branch 1 never executed (fallthrough)
3528branch 2 never executed
3529 #####: 2842: if (w[0] != (0x7212 | (4 << 16) | (2 << 24)) || w[1] != 6 || w[2] != 0x078e3cff) return -38;
3530branch 0 never executed (fallthrough)
3531branch 1 never executed
3532branch 2 never executed (fallthrough)
3533branch 3 never executed
3534branch 4 never executed (fallthrough)
3535branch 5 never executed
3536 -: 2843:
3537 #####: 2844: BlackwellIRInsn insn_ldg_ss = { .op = BW_IR_LDG_STRONG_SYS, .dst_vreg = 0, .src1_vreg = 1, .ureg = 0 };
3538 #####: 2845: if (encode_single_insn(&insn_ldg_ss, &ra, w) != 0) return -39;
3539call 0 never executed
3540branch 1 never executed (fallthrough)
3541branch 2 never executed
3542 #####: 2846: if (w[0] != (0x7981 | (2 << 16) | (4 << 24)) || w[1] != 4 || w[2] != 0x0c1f5900) return -40;
3543branch 0 never executed (fallthrough)
3544branch 1 never executed
3545branch 2 never executed (fallthrough)
3546branch 3 never executed
3547branch 4 never executed (fallthrough)
3548branch 5 never executed
3549 -: 2847: /* 17. FADD R7, R2, R4 */
3550 #####: 2848: BlackwellIRInsn insn_fadd = { .op = BW_IR_FADD, .dst_vreg = 3, .src1_vreg = 0, .src2_vreg = 1 };
3551 #####: 2849: if (encode_single_insn(&insn_fadd, &ra, w) != 0) return -133;
3552call 0 never executed
3553branch 1 never executed (fallthrough)
3554branch 2 never executed
3555 #####: 2850: if (w[0] != 0x02077221 || w[1] != 4 || w[2] != 0 || w[3] != 0x004fc400) return -134;
3556branch 0 never executed (fallthrough)
3557branch 1 never executed
3558branch 2 never executed (fallthrough)
3559branch 3 never executed
3560branch 4 never executed (fallthrough)
3561branch 5 never executed
3562branch 6 never executed (fallthrough)
3563branch 7 never executed
3564 -: 2851:
3565 -: 2852: /* 18. FSUB R7, R2, R4 (negated src2) */
3566 #####: 2853: BlackwellIRInsn insn_fsub = { .op = BW_IR_FSUB, .dst_vreg = 3, .src1_vreg = 0, .src2_vreg = 1 };
3567 #####: 2854: if (encode_single_insn(&insn_fsub, &ra, w) != 0) return -135;
3568call 0 never executed
3569branch 1 never executed (fallthrough)
3570branch 2 never executed
3571 #####: 2855: if (w[0] != 0x02077221 || w[1] != 0x80000004 || w[2] != 0 || w[3] != 0x004fc400) return -136;
3572branch 0 never executed (fallthrough)
3573branch 1 never executed
3574branch 2 never executed (fallthrough)
3575branch 3 never executed
3576branch 4 never executed (fallthrough)
3577branch 5 never executed
3578branch 6 never executed (fallthrough)
3579branch 7 never executed
3580 -: 2856:
3581 -: 2857: /* 19. FMUL R7, R2, R4 */
3582 #####: 2858: BlackwellIRInsn insn_fmul = { .op = BW_IR_FMUL, .dst_vreg = 3, .src1_vreg = 0, .src2_vreg = 1 };
3583 #####: 2859: if (encode_single_insn(&insn_fmul, &ra, w) != 0) return -137;
3584call 0 never executed
3585branch 1 never executed (fallthrough)
3586branch 2 never executed
3587 #####: 2860: if (w[0] != 0x02077220 || w[1] != 4 || w[2] != 0x00400000 || w[3] != 0x004fc400) return -138;
3588branch 0 never executed (fallthrough)
3589branch 1 never executed
3590branch 2 never executed (fallthrough)
3591branch 3 never executed
3592branch 4 never executed (fallthrough)
3593branch 5 never executed
3594branch 6 never executed (fallthrough)
3595branch 7 never executed
3596 -: 2861:
3597 -: 2862: /* 20. FFMA R7, R2, R4, R6 */
3598 #####: 2863: BlackwellIRInsn insn_ffma = { .op = BW_IR_FFMA, .dst_vreg = 3, .src1_vreg = 0, .src2_vreg = 1, .src3_vreg = 2 };
3599 #####: 2864: if (encode_single_insn(&insn_ffma, &ra, w) != 0) return -139;
3600call 0 never executed
3601branch 1 never executed (fallthrough)
3602branch 2 never executed
3603 #####: 2865: if (w[0] != 0x02077223 || w[1] != 4 || w[2] != 6 || w[3] != 0x004fc400) return -140;
3604branch 0 never executed (fallthrough)
3605branch 1 never executed
3606branch 2 never executed (fallthrough)
3607branch 3 never executed
3608branch 4 never executed (fallthrough)
3609branch 5 never executed
3610branch 6 never executed (fallthrough)
3611branch 7 never executed
3612 -: 2866:
3613 -: 2867: /* 21. FMNMX_MIN R7, R2, R4 */
3614 #####: 2868: BlackwellIRInsn insn_min = { .op = BW_IR_FMNMX_MIN, .dst_vreg = 3, .src1_vreg = 0, .src2_vreg = 1 };
3615 #####: 2869: if (encode_single_insn(&insn_min, &ra, w) != 0) return -141;
3616call 0 never executed
3617branch 1 never executed (fallthrough)
3618branch 2 never executed
3619 #####: 2870: if (w[0] != 0x02077209 || w[1] != 4 || w[2] != 0x03800000 || w[3] != 0x004fc400) return -142;
3620branch 0 never executed (fallthrough)
3621branch 1 never executed
3622branch 2 never executed (fallthrough)
3623branch 3 never executed
3624branch 4 never executed (fallthrough)
3625branch 5 never executed
3626branch 6 never executed (fallthrough)
3627branch 7 never executed
3628 -: 2871:
3629 -: 2872: /* 22. FMNMX_MAX R7, R2, R4 */
3630 #####: 2873: BlackwellIRInsn insn_max = { .op = BW_IR_FMNMX_MAX, .dst_vreg = 3, .src1_vreg = 0, .src2_vreg = 1 };
3631 #####: 2874: if (encode_single_insn(&insn_max, &ra, w) != 0) return -143;
3632call 0 never executed
3633branch 1 never executed (fallthrough)
3634branch 2 never executed
3635 #####: 2875: if (w[0] != 0x02077209 || w[1] != 4 || w[2] != 0x07800000 || w[3] != 0x004fc400) return -144;
3636branch 0 never executed (fallthrough)
3637branch 1 never executed
3638branch 2 never executed (fallthrough)
3639branch 3 never executed
3640branch 4 never executed (fallthrough)
3641branch 5 never executed
3642branch 6 never executed (fallthrough)
3643branch 7 never executed
3644 -: 2876:
3645 -: 2877: /* 23. I2FP R7, R2 */
3646 #####: 2878: BlackwellIRInsn insn_i2f = { .op = BW_IR_I2FP, .dst_vreg = 3, .src1_vreg = 0 };
3647 #####: 2879: if (encode_single_insn(&insn_i2f, &ra, w) != 0) return -145;
3648call 0 never executed
3649branch 1 never executed (fallthrough)
3650branch 2 never executed
3651 #####: 2880: if (w[0] != 0x00077245 || w[1] != 2 || w[2] != 0x00201400 || w[3] != 0x004fe200) return -146;
3652branch 0 never executed (fallthrough)
3653branch 1 never executed
3654branch 2 never executed (fallthrough)
3655branch 3 never executed
3656branch 4 never executed (fallthrough)
3657branch 5 never executed
3658branch 6 never executed (fallthrough)
3659branch 7 never executed
3660 -: 2881:
3661 -: 2882: /* 24. F2I R7, R2 */
3662 #####: 2883: BlackwellIRInsn insn_f2i = { .op = BW_IR_F2I, .dst_vreg = 3, .src1_vreg = 0 };
3663 #####: 2884: if (encode_single_insn(&insn_f2i, &ra, w) != 0) return -147;
3664call 0 never executed
3665branch 1 never executed (fallthrough)
3666branch 2 never executed
3667 #####: 2885: if (w[0] != 0x00077305 || w[1] != 2 || w[2] != 0x0020f100 || w[3] != 0x004e2200) return -148;
3668branch 0 never executed (fallthrough)
3669branch 1 never executed
3670branch 2 never executed (fallthrough)
3671branch 3 never executed
3672branch 4 never executed (fallthrough)
3673branch 5 never executed
3674branch 6 never executed (fallthrough)
3675branch 7 never executed
3676 -: 2886:
3677 -: 2887: /* 25. MUFU_RCP R7, R2 */
3678 #####: 2888: BlackwellIRInsn insn_mufu_rcp = { .op = BW_IR_MUFU_RCP, .dst_vreg = 3, .src1_vreg = 0 };
3679 #####: 2889: if (encode_single_insn(&insn_mufu_rcp, &ra, w) != 0) return -149;
3680call 0 never executed
3681branch 1 never executed (fallthrough)
3682branch 2 never executed
3683 #####: 2890: if (w[0] != 0x00077308 || w[1] != 2 || w[2] != 0x00001000 || w[3] != 0x000e2400) return -150;
3684branch 0 never executed (fallthrough)
3685branch 1 never executed
3686branch 2 never executed (fallthrough)
3687branch 3 never executed
3688branch 4 never executed (fallthrough)
3689branch 5 never executed
3690branch 6 never executed (fallthrough)
3691branch 7 never executed
3692 -: 2891:
3693 -: 2892: /* 26. MUFU_RSQ R7, R2 */
3694 #####: 2893: BlackwellIRInsn insn_mufu_rsq = { .op = BW_IR_MUFU_RSQ, .dst_vreg = 3, .src1_vreg = 0 };
3695 #####: 2894: if (encode_single_insn(&insn_mufu_rsq, &ra, w) != 0) return -151;
3696call 0 never executed
3697branch 1 never executed (fallthrough)
3698branch 2 never executed
3699 #####: 2895: if (w[0] != 0x00077308 || w[1] != 2 || w[2] != 0x00001400 || w[3] != 0x000e2400) return -152;
3700branch 0 never executed (fallthrough)
3701branch 1 never executed
3702branch 2 never executed (fallthrough)
3703branch 3 never executed
3704branch 4 never executed (fallthrough)
3705branch 5 never executed
3706branch 6 never executed (fallthrough)
3707branch 7 never executed
3708 -: 2896:
3709 -: 2897: /* 27. SHFL_DOWN R7, R2, 16 */
3710 #####: 2898: BlackwellIRInsn insn_shfl = { .op = BW_IR_SHFL_DOWN, .dst_vreg = 3, .src1_vreg = 0, .imm = 16 };
3711 #####: 2899: if (encode_single_insn(&insn_shfl, &ra, w) != 0) return -153;
3712call 0 never executed
3713branch 1 never executed (fallthrough)
3714branch 2 never executed
3715 #####: 2900: if (w[0] != 0x02077f89 || w[1] != 0x0a001f00 || w[2] != 0x000e0000 || w[3] != 0x000e2400) return -154;
3716branch 0 never executed (fallthrough)
3717branch 1 never executed
3718branch 2 never executed (fallthrough)
3719branch 3 never executed
3720branch 4 never executed (fallthrough)
3721branch 5 never executed
3722branch 6 never executed (fallthrough)
3723branch 7 never executed
3724 -: 2901:
3725 -: 2902: /* 28. LDS R7, [R2] */
3726 #####: 2903: BlackwellIRInsn insn_lds = { .op = BW_IR_LDS, .dst_vreg = 3, .src1_vreg = 0, .imm = 0 };
3727 #####: 2904: if (encode_single_insn(&insn_lds, &ra, w) != 0) return -155;
3728call 0 never executed
3729branch 1 never executed (fallthrough)
3730branch 2 never executed
3731 #####: 2905: if (w[0] != 0x02077984 || w[1] != 0 || w[2] != 0 || w[3] != 0x000fe200) return -156;
3732branch 0 never executed (fallthrough)
3733branch 1 never executed
3734branch 2 never executed (fallthrough)
3735branch 3 never executed
3736branch 4 never executed (fallthrough)
3737branch 5 never executed
3738branch 6 never executed (fallthrough)
3739branch 7 never executed
3740 -: 2906:
3741 -: 2907: /* 29. STS [R2], R4 */
3742 #####: 2908: BlackwellIRInsn insn_sts = { .op = BW_IR_STS, .src1_vreg = 0, .src2_vreg = 1, .imm = 0 };
3743 #####: 2909: if (encode_single_insn(&insn_sts, &ra, w) != 0) return -157;
3744call 0 never executed
3745branch 1 never executed (fallthrough)
3746branch 2 never executed
3747 #####: 2910: if (w[0] != 0x02007388 || w[1] != 4 || w[2] != 0 || w[3] != 0x000fe200) return -158;
3748branch 0 never executed (fallthrough)
3749branch 1 never executed
3750branch 2 never executed (fallthrough)
3751branch 3 never executed
3752branch 4 never executed (fallthrough)
3753branch 5 never executed
3754branch 6 never executed (fallthrough)
3755branch 7 never executed
3756 -: 2911:
3757 #####: 2912: return 0;
3758 -: 2913:}
3759 -: 2914:
3760function legacy_omega_blackwell_test_regalloc_bounds called 0 returned 0% blocks executed 0%
3761 #####: 2915:int omega_blackwell_test_regalloc_bounds(void) {
3762 -: 2916: BlackwellIRProgram prog;
3763 #####: 2917: omega_bw_ir_init(&prog);
3764call 0 never executed
3765 -: 2918:
3766 #####: 2919: int v0 = omega_bw_ir_alloc_vreg64(&prog);
3767call 0 never executed
3768 #####: 2920: int v1 = omega_bw_ir_alloc_vreg(&prog);
3769call 0 never executed
3770 #####: 2921: int v2 = omega_bw_ir_alloc_vreg64(&prog);
3771call 0 never executed
3772 #####: 2922: int v3 = omega_bw_ir_alloc_vreg128(&prog); /* Test 128-bit quad allocation */
3773call 0 never executed
3774 -: 2923:
3775 #####: 2924: BlackwellIRInsn i0 = { .op = BW_IR_LDC64, .dst_vreg = v0, .imm = 0x380 };
3776 #####: 2925: omega_bw_ir_append(&prog, &i0);
3777call 0 never executed
3778 #####: 2926: BlackwellIRInsn i1 = { .op = BW_IR_MOV_IMM, .dst_vreg = v1, .imm = 10 };
3779 #####: 2927: omega_bw_ir_append(&prog, &i1);
3780call 0 never executed
3781 #####: 2928: BlackwellIRInsn i2 = { .op = BW_IR_LDC64, .dst_vreg = v2, .imm = 0x388 };
3782 #####: 2929: omega_bw_ir_append(&prog, &i2);
3783call 0 never executed
3784 #####: 2930: BlackwellIRInsn i3 = { .op = BW_IR_HMMA_F16, .dst_vreg = v3, .src1_vreg = v3, .src2_vreg = v0, .src3_vreg = -1 };
3785 #####: 2931: omega_bw_ir_append(&prog, &i3);
3786call 0 never executed
3787 -: 2932: /* i4 uses v1, v2, v3 simultaneously so all intervals are concurrently active */
3788 #####: 2933: int v_sink = omega_bw_ir_alloc_vreg(&prog);
3789call 0 never executed
3790 #####: 2934: BlackwellIRInsn i4 = { .op = BW_IR_IADD3, .dst_vreg = v_sink, .src1_vreg = v1, .src2_vreg = v2, .src3_vreg = v3 };
3791 #####: 2935: omega_bw_ir_append(&prog, &i4);
3792call 0 never executed
3793 -: 2936:
3794 #####: 2937: if (omega_bw_regalloc_solve(&prog) != 0) return -1;
3795call 0 never executed
3796branch 1 never executed (fallthrough)
3797branch 2 never executed
3798 -: 2938:
3799 #####: 2939: int phys_v0 = prog.regalloc.vreg_to_phys[v0];
3800 #####: 2940: int phys_v1 = prog.regalloc.vreg_to_phys[v1];
3801 #####: 2941: int phys_v2 = prog.regalloc.vreg_to_phys[v2];
3802 #####: 2942: int phys_v3 = prog.regalloc.vreg_to_phys[v3];
3803 -: 2943:
3804 #####: 2944: if (phys_v0 % 2 != 0) return -2;
3805branch 0 never executed (fallthrough)
3806branch 1 never executed
3807 #####: 2945: if (phys_v2 % 2 != 0) return -3;
3808branch 0 never executed (fallthrough)
3809branch 1 never executed
3810 #####: 2946: if (phys_v3 % 4 != 0) return -4; /* 4-alignment for 128-bit quad */
3811branch 0 never executed (fallthrough)
3812branch 1 never executed
3813 #####: 2947: if (phys_v1 == phys_v0 || phys_v1 == phys_v0 + 1) return -5;
3814branch 0 never executed (fallthrough)
3815branch 1 never executed
3816branch 2 never executed (fallthrough)
3817branch 3 never executed
3818 #####: 2948: if (phys_v2 == phys_v0 || phys_v2 == phys_v0 + 1) return -6;
3819branch 0 never executed (fallthrough)
3820branch 1 never executed
3821branch 2 never executed (fallthrough)
3822branch 3 never executed
3823 #####: 2949: for (int k = 0; k < 4; k++) {
3824branch 0 never executed
3825branch 1 never executed (fallthrough)
3826 #####: 2950: if (phys_v3 + k == phys_v0 || phys_v3 + k == phys_v0 + 1) return -7;
3827branch 0 never executed (fallthrough)
3828branch 1 never executed
3829branch 2 never executed (fallthrough)
3830branch 3 never executed
3831 #####: 2951: if (phys_v3 + k == phys_v2 || phys_v3 + k == phys_v2 + 1) return -8;
3832branch 0 never executed (fallthrough)
3833branch 1 never executed
3834branch 2 never executed (fallthrough)
3835branch 3 never executed
3836 #####: 2952: if (phys_v3 + k == phys_v1) return -9;
3837branch 0 never executed (fallthrough)
3838branch 1 never executed
3839 -: 2953: }
3840 -: 2954:
3841 -: 2955: /* Test bounds refusal: intentionally attempt to allocate more registers than hardware capacity */
3842 -: 2956: BlackwellIRProgram overflow_prog;
3843 #####: 2957: omega_bw_ir_init(&overflow_prog);
3844call 0 never executed
3845 #####: 2958: for (int i = 0; i < BW_PHYS_GPR_MAX + 5; i++) {
3846branch 0 never executed
3847branch 1 never executed (fallthrough)
3848 #####: 2959: int v = omega_bw_ir_alloc_vreg(&overflow_prog);
3849call 0 never executed
3850 #####: 2960: if (v < 0) break;
3851branch 0 never executed (fallthrough)
3852branch 1 never executed
3853 #####: 2961: BlackwellIRInsn insn = { .op = BW_IR_MOV_IMM, .dst_vreg = v, .imm = (uint32_t)i };
3854 #####: 2962: omega_bw_ir_append(&overflow_prog, &insn);
3855call 0 never executed
3856 -: 2963: }
3857 #####: 2964: for (size_t i = 0; i < overflow_prog.count; i++) {
3858branch 0 never executed
3859branch 1 never executed (fallthrough)
3860 #####: 2965: for (int v = 0; v < overflow_prog.regalloc.num_vregs; v++) {
3861branch 0 never executed
3862branch 1 never executed (fallthrough)
3863 #####: 2966: overflow_prog.regalloc.intervals[v].last_use = (int)overflow_prog.count - 1;
3864 -: 2967: }
3865 -: 2968: }
3866 #####: 2969: if (omega_bw_regalloc_solve(&overflow_prog) == 0) {
3867call 0 never executed
3868branch 1 never executed (fallthrough)
3869branch 2 never executed
3870 #####: 2970: return -6;
3871 -: 2971: }
3872 -: 2972:
3873 #####: 2973: return 0;
3874 -: 2974:}
3875 -: 2975:
3876 -: 2976:#ifndef OMEGA_GPU_NO_POSIX /* prints: hosted only (the freestanding build has no stdio) */
3877function legacy_omega_blackwell_test_codegen_variation called 0 returned 0% blocks executed 0%
3878 #####: 2977:int omega_blackwell_test_codegen_variation(void) {
3879 -: 2978: OmegaMatMulSpec spec1, spec2;
3880 #####: 2979: if (omega_matmul_spec_init(&spec1, 16, 16, 16, OMEGA_MATMUL_PRECISION_INT32) != 0) {
3881call 0 never executed
3882branch 1 never executed (fallthrough)
3883branch 2 never executed
3884 #####: 2980: printf("FAIL: spec1 init failed\n");
3885call 0 never executed
3886 #####: 2981: return -1;
3887 -: 2982: }
3888 #####: 2983: if (omega_matmul_spec_init(&spec2, 32, 16, 64, OMEGA_MATMUL_PRECISION_INT32) != 0) {
3889call 0 never executed
3890branch 1 never executed (fallthrough)
3891branch 2 never executed
3892 #####: 2984: printf("FAIL: spec2 init failed\n");
3893call 0 never executed
3894 #####: 2985: return -1;
3895 -: 2986: }
3896 -: 2987:
3897 -: 2988: OmegaBlackwellKernel k1, k2;
3898 #####: 2989: memset(&k1, 0, sizeof(k1));
3899 #####: 2990: memset(&k2, 0, sizeof(k2));
3900 -: 2991:
3901 #####: 2992: if (omega_blackwell_codegen_matmul(&spec1, &k1) != 0) {
3902call 0 never executed
3903branch 1 never executed (fallthrough)
3904branch 2 never executed
3905 #####: 2993: printf("FAIL: k1 codegen failed\n");
3906call 0 never executed
3907 #####: 2994: return -1;
3908 -: 2995: }
3909 #####: 2996: if (omega_blackwell_codegen_matmul(&spec2, &k2) != 0) {
3910call 0 never executed
3911branch 1 never executed (fallthrough)
3912branch 2 never executed
3913 #####: 2997: printf("FAIL: k2 codegen failed\n");
3914call 0 never executed
3915 #####: 2998: omega_blackwell_kernel_free(&k1);
3916call 0 never executed
3917 #####: 2999: return -1;
3918 -: 3000: }
3919 -: 3001:
3920 -: 3002: OmegaBlackwellRealizationIdentity id1, id2;
3921 #####: 3003: omega_blackwell_bind_matmul_realization(&spec1, &k1, &id1);
3922call 0 never executed
3923 #####: 3004: omega_blackwell_bind_matmul_realization(&spec2, &k2, &id2);
3924call 0 never executed
3925 -: 3005:
3926 #####: 3006: printf("================================================================================\n");
3927call 0 never executed
3928 #####: 3007: printf(" OMEGA BLACKWELL CODEGEN VARIATION DEMONSTRATION (GATE 7 STAGE-1)\n");
3929call 0 never executed
3930 #####: 3008: printf("================================================================================\n");
3931call 0 never executed
3932 #####: 3009: printf("Config 1: 16x16x16 INT32\n");
3933call 0 never executed
3934 #####: 3010: printf(" Instructions: %zu (%zu bytes, %u GPRs, %u UGPRs)\n", k1.insn_count, k1.code_size, k1.gpr_count, k1.uniform_gpr_count);
3935call 0 never executed
3936 #####: 3011: printf(" Spec ID: ");
3937call 0 never executed
3938 #####: 3012: for (int i = 0; i < 16; i++) printf("%02x", spec1.spec_id[i]);
3939call 0 never executed
3940branch 1 never executed
3941branch 2 never executed (fallthrough)
3942 #####: 3013: printf("...\n");
3943call 0 never executed
3944 #####: 3014: printf(" Code Digest: ");
3945call 0 never executed
3946 #####: 3015: for (int i = 0; i < 16; i++) printf("%02x", k1.code_digest[i]);
3947call 0 never executed
3948branch 1 never executed
3949branch 2 never executed (fallthrough)
3950 #####: 3016: printf("...\n");
3951call 0 never executed
3952 #####: 3017: printf(" Realization: ");
3953call 0 never executed
3954 #####: 3018: for (int i = 0; i < 16; i++) printf("%02x", id1.realization_id[i]);
3955call 0 never executed
3956branch 1 never executed
3957branch 2 never executed (fallthrough)
3958 #####: 3019: printf("...\n\n");
3959call 0 never executed
3960 -: 3020:
3961 #####: 3021: printf("Config 2: 32x16x64 INT32\n");
3962call 0 never executed
3963 #####: 3022: printf(" Instructions: %zu (%zu bytes, %u GPRs, %u UGPRs)\n", k2.insn_count, k2.code_size, k2.gpr_count, k2.uniform_gpr_count);
3964call 0 never executed
3965 #####: 3023: printf(" Spec ID: ");
3966call 0 never executed
3967 #####: 3024: for (int i = 0; i < 16; i++) printf("%02x", spec2.spec_id[i]);
3968call 0 never executed
3969branch 1 never executed
3970branch 2 never executed (fallthrough)
3971 #####: 3025: printf("...\n");
3972call 0 never executed
3973 #####: 3026: printf(" Code Digest: ");
3974call 0 never executed
3975 #####: 3027: for (int i = 0; i < 16; i++) printf("%02x", k2.code_digest[i]);
3976call 0 never executed
3977branch 1 never executed
3978branch 2 never executed (fallthrough)
3979 #####: 3028: printf("...\n");
3980call 0 never executed
3981 #####: 3029: printf(" Realization: ");
3982call 0 never executed
3983 #####: 3030: for (int i = 0; i < 16; i++) printf("%02x", id2.realization_id[i]);
3984call 0 never executed
3985branch 1 never executed
3986branch 2 never executed (fallthrough)
3987 #####: 3031: printf("...\n");
3988call 0 never executed
3989 #####: 3032: printf("================================================================================\n");
3990call 0 never executed
3991 -: 3033:
3992 -: 3034: /* Validation checks */
3993 #####: 3035: if (memcmp(spec1.spec_id, spec2.spec_id, 32) == 0) {
3994branch 0 never executed (fallthrough)
3995branch 1 never executed
3996 #####: 3036: printf("FAIL: spec IDs match (expected distinct)\n");
3997call 0 never executed
3998 #####: 3037: return -2;
3999 -: 3038: }
4000 #####: 3039: if (memcmp(k1.code_digest, k2.code_digest, 32) == 0) {
4001branch 0 never executed (fallthrough)
4002branch 1 never executed
4003 #####: 3040: printf("FAIL: code digests match (expected distinct)\n");
4004call 0 never executed
4005 #####: 3041: return -3;
4006 -: 3042: }
4007 #####: 3043: if (memcmp(id1.realization_id, id2.realization_id, 32) == 0) {
4008branch 0 never executed (fallthrough)
4009branch 1 never executed
4010 #####: 3044: printf("FAIL: realization IDs match (expected distinct)\n");
4011call 0 never executed
4012 #####: 3045: return -4;
4013 -: 3046: }
4014 -: 3047:
4015 #####: 3048: printf("PASS: Dynamic codegen variation verified (distinct specifications, code digests, and realization IDs).\n");
4016call 0 never executed
4017 -: 3049:
4018 #####: 3050: omega_blackwell_kernel_free(&k1);
4019call 0 never executed
4020 #####: 3051: omega_blackwell_kernel_free(&k2);
4021call 0 never executed
4022 #####: 3052: return 0;
4023 -: 3053:}
4024 -: 3054:#endif
4025 -: 3055:
4026 -: 3056:/* Declared registers: peak + 2 rounded up to 8 (see omega_blackwell_codegen.h for the chip evidence). */
4027 -: 3057:#ifdef BW_RA_C_PRIMARY
4028 -: 3058:uint32_t omega_bw_gpr_declared(uint32_t peak) { return ((peak + 2u + 7u) / 8u) * 8u; }
4029 -: 3059:int omega_bw_gpr_declared_ok(uint32_t declared, uint32_t peak) { return declared % 8u == 0u && declared >= peak + 2u; }
4030 -: 3060:
4031 -: 3061:int omega_bw_ir_set_gpr_limit(BlackwellIRProgram *prog, uint32_t limit) {
4032 -: 3062: if (!prog || limit <= BW_PHYS_GPR_MAX || limit > BW_PHYS_GPR_HW_LIMIT) return -1;
4033 -: 3063: prog->regalloc.gpr_limit = limit;
4034 -: 3064: return 0;
4035 -: 3065:}
4036 -: 3066:#else
4037function legacy_omega_bw_gpr_declared called 182 returned 100% blocks executed 100%
4038 182: 3067:uint32_t omega_bw_gpr_declared(uint32_t peak) {
4039 182: 3068: return (uint32_t)bw_ra_decide(6, peak, 0);
4040call 0 returned 182
4041 -: 3069:}
4042function legacy_omega_bw_gpr_declared_ok called 182 returned 100% blocks executed 100%
4043 182: 3070:int omega_bw_gpr_declared_ok(uint32_t declared, uint32_t peak) {
4044 182: 3071: return bw_ra_decide(7, declared, peak);
4045call 0 returned 182
4046 -: 3072:}
4047function legacy_omega_bw_ir_set_gpr_limit called 3 returned 100% blocks executed 83%
4048 3: 3073:int omega_bw_ir_set_gpr_limit(BlackwellIRProgram *prog, uint32_t limit) {
4049 3*: 3074: if (!prog || bw_ra_decide(8, limit, 0) != 1) return -1;
4050branch 0 taken 3 (fallthrough)
4051branch 1 taken 0
4052call 2 returned 3
4053branch 3 taken 0 (fallthrough)
4054branch 4 taken 3
4055 3: 3075: prog->regalloc.gpr_limit = limit;
4056 3: 3076: return 0;
4057 -: 3077:}
4058 -: 3078:#endif