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
GitHub aien-dev/CUDApp#237 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/CUDApp/patches/b0fff876c2bddbaa.bundle -o b0fff876c2bddbaa.bundle git fetch b0fff876c2bddbaa.bundle refs/pull/237/head
Provenance
github-import 1
aien-dev/CUDApp
237
6ac940d87506fb6e778ff2dacb9ea35cf011caba
{"kind":"github-import","owner":"aien-dev","repo":"CUDApp","number":237,"url":"https://github.com/aien-dev/CUDApp/pull/237","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:57Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/Makefile b/Makefile index 0a8a8b80..25a1230c 100644 --- a/Makefile +++ b/Makefile @@ -330,11 +330,59 @@ $(OUT_DIR)/gpu_lmhead_fp8_study: tests/gpu_lmhead_fp8_study.c src/omega_gpu_bf16 # permutation, budgets) plus the warp simulator (512 threads); the chip gate is tools/run_gpu_fp8gemm_chip.sh under the GB10 lock. .PHONY: test-gpu-fp8gemm GPU_FP8GEMM_TEST = $(OUT_DIR)/gpu_fp8gemm_test -$(GPU_FP8GEMM_TEST): tests/gpu_fp8gemm_test.c tests/bw_warp_sim_k.h src/omega_gpu_fp8gemm_api.h src/omega_blackwell_codegen_gemm.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a +$(GPU_FP8GEMM_TEST): tests/gpu_fp8gemm_test.c tests/bw_warp_sim_k.h src/omega_gpu_fp8gemm_api.h src/omega_gpu_fp8gemm_internal.h src/omega_blackwell_codegen_gemm.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/gpu_fp8gemm_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +# P-DRA-4 DRA-67: the decode levers are env-gated and OFF by default; --spec-of checks the spec the stroke path resolves. +FP8GEMM_STROKE_GU = --spec-of 2048,16,4,1 test-gpu-fp8gemm: $(GPU_FP8GEMM_TEST) $(GPU_FP8GEMM_TEST) --host-only $(GPU_FP8GEMM_TEST) --sim + env -u AIEN_OMEGA_FP8GEMM_X_AHEAD $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "rowmap=1 mt=4 x_ahead=0" + env AIEN_OMEGA_FP8GEMM_X_AHEAD=0 $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "x_ahead=0" + env AIEN_OMEGA_FP8GEMM_X_AHEAD=yes $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "x_ahead=0" + env AIEN_OMEGA_FP8GEMM_X_AHEAD=1 $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "rowmap=1 mt=4 x_ahead=1" + env AIEN_OMEGA_FP8GEMM_X_AHEAD=1 $(GPU_FP8GEMM_TEST) --spec-of 2048,16,8,0 --warps 4 --expect "x_ahead=0" + for v in "" 0 yes 2 " 1" "1 " 11; do \ + env AIEN_OMEGA_FP8GEMM_X_AHEAD="$$v" $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "x_ahead=0" || exit 1; done + @# DRA-78: AIEN_OMEGA_FP8GEMM_CTA_BUDGET; unset = the incumbent rule exactly (segs >= 64: 2, >= 8: 12, else 96) + env -u AIEN_OMEGA_FP8GEMM_CTA_BUDGET $(GPU_FP8GEMM_TEST) --spec-of 512,64,4,1 --expect "ctas=2 x_ahead=0" + env -u AIEN_OMEGA_FP8GEMM_CTA_BUDGET $(GPU_FP8GEMM_TEST) --spec-of 2048,64,4,1 --expect "ctas=2" + env -u AIEN_OMEGA_FP8GEMM_CTA_BUDGET $(GPU_FP8GEMM_TEST) --spec-of 2048,8,4,1 --expect "ctas=12" + env -u AIEN_OMEGA_FP8GEMM_CTA_BUDGET $(GPU_FP8GEMM_TEST) --spec-of 512,7,4,1 --expect "ctas=96" + env -u AIEN_OMEGA_FP8GEMM_CTA_BUDGET $(GPU_FP8GEMM_TEST) --spec-of 2048,1,0,0 --expect "ctas=96" + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET=4 $(GPU_FP8GEMM_TEST) --spec-of 2048,1,0,0 --expect "ctas=4" + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET=512:4 $(GPU_FP8GEMM_TEST) --spec-of 512,64,4,1 --expect "ctas=4" + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET=512:4 $(GPU_FP8GEMM_TEST) --spec-of 2048,64,4,1 --expect "ctas=2" + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET=512:4 $(GPU_FP8GEMM_TEST) --spec-of 512,7,4,1 --expect "ctas=96" + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET=512:4,2048:6 $(GPU_FP8GEMM_TEST) --spec-of 2048,8,4,1 --expect "ctas=6" + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET=512:4,2048:6 $(GPU_FP8GEMM_TEST) --spec-of 2048,1,0,0 --expect "ctas=96" + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET=2048:6,3 $(GPU_FP8GEMM_TEST) --spec-of 512,64,4,1 --expect "ctas=3" + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET=2048:6,3 $(GPU_FP8GEMM_TEST) --spec-of 2048,64,4,1 --expect "ctas=6" + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET=1024 $(GPU_FP8GEMM_TEST) --spec-of 512,64,4,1 --expect "ctas=1024" + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET=512:4 $(GPU_FP8GEMM_TEST) --spec-of 512,64,4,1 --ctas 7 --expect "ctas=7" + @# malformed values are refused whole: the incumbent budget stays (512,64 -> 2) + for v in "" 0 1025 -1 abc 4x " 4" "4," ",4" "512:" ":4" "512:0" "512:4,,3" "512:4,512:5" "3,4" "512:4;3" "16385:4" "512:4:4"; do \ + env AIEN_OMEGA_FP8GEMM_CTA_BUDGET="$$v" $(GPU_FP8GEMM_TEST) --spec-of 512,64,4,1 --expect "ctas=2" || exit 1; done + @# DRA-79: AIEN_OMEGA_FP8GEMM_ROW_AHEAD; only exactly "1" turns it on, and only at one K step per row (k 512 at lane 16, k 256 at lane 8) + env -u AIEN_OMEGA_FP8GEMM_ROW_AHEAD $(GPU_FP8GEMM_TEST) --spec-of 512,64,4,1 --expect "row_ahead=0 ctas=2" + env -u AIEN_OMEGA_FP8GEMM_ROW_AHEAD $(GPU_FP8GEMM_TEST) --spec-of 512,8,4,1 --expect "row_ahead=0" + env AIEN_OMEGA_FP8GEMM_ROW_AHEAD=1 $(GPU_FP8GEMM_TEST) --spec-of 512,64,4,1 --expect "row_ahead=1 rowmap=1 mt=4 ctas=2 x_ahead=0" + env AIEN_OMEGA_FP8GEMM_ROW_AHEAD=1 $(GPU_FP8GEMM_TEST) --spec-of 512,8,4,1 --expect "row_ahead=1 ctas=12" + env AIEN_OMEGA_FP8GEMM_ROW_AHEAD=1 AIEN_OMEGA_FP8GEMM_X_AHEAD=1 AIEN_OMEGA_FP8GEMM_CTA_BUDGET=512:4 $(GPU_FP8GEMM_TEST) --spec-of 512,64,4,1 --expect "row_ahead=1 x_ahead=1 ctas=4" + env AIEN_OMEGA_FP8GEMM_ROW_AHEAD=1 $(GPU_FP8GEMM_TEST) --spec-of 2048,64,4,1 --expect "row_ahead=0" + env AIEN_OMEGA_FP8GEMM_ROW_AHEAD=1 $(GPU_FP8GEMM_TEST) --spec-of 2048,1,0,0 --expect "row_ahead=0" + for v in "" 0 yes 2 " 1" "1 " 11; do \ + env AIEN_OMEGA_FP8GEMM_ROW_AHEAD="$$v" $(GPU_FP8GEMM_TEST) --spec-of 512,64,4,1 --expect "row_ahead=0" || exit 1; done + @# DRA-89: AIEN_OMEGA_FP8GEMM_ROWAWARE; unset or anything but "1" = the incumbent dense mt 8 for every row count; + @# "1" = the live rows rounded up to 1/2/4/8 (MIX k 2048, O k 4096); a set_shape mt (--mt) keeps its pin + for r in 1 2 3 4 5 8; do for k in 2048 4096; do \ + env -u AIEN_OMEGA_FP8GEMM_ROWAWARE $(GPU_FP8GEMM_TEST) --dense-of $$k,$$r --expect "mt=8 warps=16 mutant=0 rowmap=0 x_ahead=0 ctas=96" || exit 1; \ + for v in 0 yes " 1" "1 " 11 2; do env AIEN_OMEGA_FP8GEMM_ROWAWARE="$$v" $(GPU_FP8GEMM_TEST) --dense-of $$k,$$r --expect "mt=8" || exit 1; done; done; done + for rm in 1:1 2:2 3:4 4:4 5:8 6:8 7:8 8:8; do r=$${rm%:*}; m=$${rm#*:}; for k in 2048 4096; do \ + env AIEN_OMEGA_FP8GEMM_ROWAWARE=1 $(GPU_FP8GEMM_TEST) --dense-of $$k,$$r --expect "mt=$$m warps=16 mutant=0 rowmap=0 x_ahead=0 ctas=96" || exit 1; done; done + env AIEN_OMEGA_FP8GEMM_ROWAWARE=1 $(GPU_FP8GEMM_TEST) --dense-of 2048,1 --mt 4 --expect "mt=4" + env -u AIEN_OMEGA_FP8GEMM_ROWAWARE $(GPU_FP8GEMM_TEST) --sim-dense + env AIEN_OMEGA_FP8GEMM_ROWAWARE=1 $(GPU_FP8GEMM_TEST) --sim-dense # OWN-30B (2026-10-13): host-only audit that every launcher declares peak + 2 registers (the chip hung at peak + 1). .PHONY: test-gpu-gpr-boundary diff --git a/src/omega_blackwell_codegen_gemm.c b/src/omega_blackwell_codegen_gemm.c index 10bf71b4..9dffece5 100644 --- a/src/omega_blackwell_codegen_gemm.c +++ b/src/omega_blackwell_codegen_gemm.c @@ -2,7 +2,8 @@ /* omega_blackwell_codegen_gemm.c: FP8 e4m3 block-scaled grouped GEMM for prefill (OWN-30B builder F item 26). See the * header for the contract. The emitter helpers are copies of omega_blackwell_codegen_moe.c's (same chip-learned * scheduling rules) plus one addition: weight and scale prefetch loads use scoreboards 3 (buffer A) and 4 (buffer B) - * and are waited for only by the step that decodes them, so the next step's weights stream while this step computes. */ + * and are waited for only by the step that decodes them, so the next step's weights stream while this step computes; the + * staging words of x' are loaded one step ahead the same way on scoreboard 5 (L312 lever 3, 2026-10-21). */ #include "omega_blackwell_codegen_gemm.h" #ifndef OMEGA_GPU_NO_POSIX #include <stdlib.h> @@ -72,6 +73,7 @@ static void movi(Em *e, int d, uint32_t imm) { BlackwellIRInsn i = I0(BW_IR_MOV_ static void movrz(Em *e, int d) { BlackwellIRInsn i = I0(BW_IR_MOV_RZ); i.dst_vreg = d; emit(e, i, K_FIXED); } /* d = a * imm + c (c NOREG = RZ); a may be a sub-register of a quad */ static void imadi(Em *e, int d, int a, unsigned asub, uint32_t imm, int c) { BlackwellIRInsn i = I0(BW_IR_IMAD); i.dst_vreg = d; i.src1_vreg = a; i.src1_subreg = (uint8_t)asub; i.imm = imm; i.src3_vreg = c; emit(e, i, K_FIXED); } +static void imadi_sub(Em *e, int d, unsigned dsub, int a, unsigned asub, uint32_t imm, int c) { BlackwellIRInsn i = I0(BW_IR_IMAD); i.dst_vreg = d; i.dst_subreg = (uint8_t)dsub; i.src1_vreg = a; i.src1_subreg = (uint8_t)asub; i.imm = imm; i.src3_vreg = c; emit(e, i, K_FIXED); } /* d = a * b + c (registers) */ static void imadr(Em *e, int d, int a, int b, int c) { BlackwellIRInsn i = I0(BW_IR_IMAD); i.dst_vreg = d; i.src1_vreg = a; i.src2_vreg = b; i.src3_vreg = c; emit(e, i, K_FIXED); } /* d64 = a * imm + c64 */ @@ -128,6 +130,22 @@ static void ldw_pf(Em *e, BlackwellIROpcode op, int d, int addr64, uint32_t imm, } static void consume(Em *e, unsigned sb) { e->pending |= e->held & (1u << sb); e->held &= ~(1u << sb); } +/* The staging words of one K step (NJ per thread) into xv[], loaded one step AHEAD on scoreboard 5 (L312 lever 3): the + * STS of the step that reads them waits for them (consume(5)), so the x' latency hides behind the previous step's + * compute instead of sitting between its barriers. Addresses in rounds of 4 so the temporaries stay few; every load + * sets SB_RD and the next waits on it (the address read), as every load batch of this file does. xs (plain) or xso (rowmap) + * already point at the step to load. */ +static void x_prefetch(Em *e, uint32_t NJ, uint32_t T, uint32_t ROWW, uint32_t K, int RM, int one, int xs, int xso, const int *xb, const int *xv, int udesc) { + for (uint32_t j0 = 0; j0 < NJ; j0 += 4) { + const uint32_t nj = NJ - j0 < 4 ? NJ - j0 : 4; + int xa[4]; + for (uint32_t q = 0; q < nj; q++) xa[q] = V64(e); + if (e->err) return; + for (uint32_t q = 0; q < nj; q++) { const uint32_t pos = (j0 + q) * T; if (RM) imadw(e, xa[q], xso, 1u, xb[j0 + q]); else imadw(e, xa[q], one, ((pos / ROWW) * K + pos % ROWW) * 4u, xs); } + for (uint32_t q = 0; q < nj; q++) ldw_pf(e, BW_IR_LDG_E, xv[j0 + q], xa[q], 0, udesc, 5); + } +} + static int log2u(uint32_t v) { int l = 0; while ((1u << l) < v) l++; return (1u << l) == v ? l : -1; } static int spec_ok(const OmegaFp8GemmSpec *s) { @@ -138,8 +156,11 @@ static int spec_ok(const OmegaFp8GemmSpec *s) { if (s->k == 0 || s->k > 16384u || s->k % 128u || s->k % (32u * s->lane_bytes)) return 0; uint32_t ks = s->k / (32u * s->lane_bytes); if (ks % 2u && ks > 3u) return 0; /* odd step counts are fully unrolled: at most 3 */ - if (s->mutant < 0 || s->mutant > 4) return 0; + if (s->mutant < 0 || s->mutant > 6) return 0; if (s->rowmap > 1u || (s->rowmap && s->mt > 4u)) return 0; /* the mapped form keeps NJ row bases and MT y rows in registers: mt 8 needs 135 at 16 warps, past the file */ + if (s->x_ahead > 1u || (s->x_ahead && s->mt * s->lane_bytes / s->warps > 16u)) return 0; /* lever 3 holds NJ staging words in registers: NJ > 16 (under 8 warps at mt * lane_bytes 128) is not a served shape */ + if (s->row_ahead > 1u || (s->row_ahead && ks != 1u)) return 0; /* DRA-79: the next row's weights fill the second register set, which only the one-step K loop leaves free */ + if ((s->mutant == 5 || s->mutant == 6) && !s->row_ahead) return 0; return 1; } uint32_t omega_fp8gemm_steps(const OmegaFp8GemmSpec *spec) { return spec_ok(spec) ? spec->k / (32u * spec->lane_bytes) : 0; } @@ -220,7 +241,30 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell for (int q = 0; q < 4; q++) xq[q] = V128(e); for (int b = 0; b < 2; b++) { wq[b] = LB == 16 ? V128(e) : V64(e); sc[b] = V(e); } for (int i = 0; i < 4; i++) fr[i] = V(e); + /* x_ahead (L312 lever 3): the next K step's staging words, loaded one step ahead (x_prefetch) into NJ registers held + * across the step; x_ahead 0 keeps the incumbent program byte for byte (the staging words loaded inside the step) */ + const int XA = spec->x_ahead != 0; + int xv[16]; + if (XA) for (uint32_t j = 0; j < NJ; j++) xv[j] = V(e); + /* row_ahead (DRA-79, KS 1): wq[1]/sc[1] hold the weights of the row the next pass computes, in flight on scoreboard 4. The + * row-loop head finds the warp's next row (rg + stride, clamped like rg) as a row delta dr and a scale-block delta dsb; the pass + * prologue waits, moves wq[1]/sc[1] into wq[0]/sc[0] and loads the next pass's row: the same row (sel 0) unless this is the + * row's last pass (sel 1). row_ahead 0 keeps the incumbent program byte for byte. */ + const int RA = spec->row_ahead != 0; + int dr = NOREG, dsb = NOREG; + if (RA) { dr = V(e); dsb = V(e); } if (e->err) return -1; + if (RA) { /* the first row of the warp (the row-loop head's arithmetic), loaded before the loop */ + imadi(e, rg, base, 0, 1, warp); + imadi(e, t1, rg, 0, 0xffffffffu, nm1); shr(e, over, t1, 0, 31); + imadi(e, d, nm1, 0, 0xffffffffu, rg); + imadr(e, tmp, over, d, NOREG); imadi(e, rgc, tmp, 0, 0xffffffffu, rg); + imadw(e, pw, rgc, K, wbase); imadw(e, pw, wlane, 1, pw); + shr(e, tmp, rgc, 0, 7); + imadw(e, ps, tmp, KB * 4u, sbase); imadw(e, ps, slane, 1, ps); + ldw_pf(e, ldw, wq[1], pw, 0, udesc, 4); + ldw_pf(e, BW_IR_LDG_E, sc[1], ps, 0, udesc, 4); + } /* ---- weight-row loop (uniform per CTA) ---- */ const int L_rg = here(e); @@ -237,6 +281,15 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell imadw(e, pyrg, rg, 4, py); imadi(e, lo, over, 0, 1, lane); imadi(e, rowp, row0, 0, 1, NOREG); imadi(e, rem, cnt, 0, 1, NOREG); imadi(e, pc, passes, 0, 1, NOREG); + if (RA) { /* the warp's next row: rg + stride (mutant 5: + 1), clamped to n - 1; deltas from rgc (both >= 0) */ + imadi(e, t, stride, 0, 1, rg); + if (spec->mutant == 5) imadi(e, t, one, 0, 1, t); + imadi(e, t1, t, 0, 0xffffffffu, nm1); shr(e, fl, t1, 0, 31); /* (rg2 > n - 1) */ + imadi(e, d, nm1, 0, 0xffffffffu, t); + imadr(e, tq, fl, d, NOREG); imadi(e, t, tq, 0, 0xffffffffu, t); /* rg2 clamped */ + imadi(e, dr, rgc, 0, 0xffffffffu, t); /* dr = rgc2 - rgc */ + shr(e, t, t, 0, 7); shr(e, tq, rgc, 0, 7); imadi(e, dsb, tq, 0, 0xffffffffu, t); /* dsb = rgc2/128 - rgc/128 */ + } /* ---- pass loop: MT rows of x per pass ---- */ const int L_pass = here(e); @@ -257,8 +310,23 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell } imadw(e, pwc, one, 0, pw); imadw(e, psc, one, 0, ps); for (uint32_t m = 0; m < MT; m++) movrz(e, acc[m]); - ldw_pf(e, ldw, wq[0], pwc, 0, udesc, 3); - ldw_pf(e, BW_IR_LDG_E, sc[0], psc, 0, udesc, 3); + if (RA) { + consume(e, 4); + for (uint32_t w = 0; w < (LB == 16 ? 4u : 2u); w++) imadi_sub(e, wq[0], w, wq[1], w, 1, NOREG); + imadi(e, sc[0], sc[1], 0, 1, NOREG); + int pa = V64(e), pb = V64(e), sel = V(e), sd = V(e); + if (e->err) return -1; + if (spec->mutant == 6) movi(e, sel, 1); + else { imadi(e, sel, one, 0, 0xfffffffeu, pc); shr(e, sel, sel, 0, 31); } /* 1 iff pc == 1: this row's last pass */ + imadr(e, sd, sel, dr, NOREG); imadw(e, pa, sd, K, pw); + imadr(e, sd, sel, dsb, NOREG); imadw(e, pb, sd, KB * 4u, ps); + ldw_pf(e, ldw, wq[1], pa, 0, udesc, 4); + ldw_pf(e, BW_IR_LDG_E, sc[1], pb, 0, udesc, 4); + } else { + ldw_pf(e, ldw, wq[0], pwc, 0, udesc, 3); + ldw_pf(e, BW_IR_LDG_E, sc[0], psc, 0, udesc, 3); + } + if (XA) x_prefetch(e, NJ, T, ROWW, K, RM, one, xs, xso, xb, xv, udesc); /* step 0's x' words */ movi(e, cntk, KS / U); /* ---- K loop: U steps per iteration ---- */ @@ -267,17 +335,18 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell for (uint32_t us = 0; us < U; us++) { const int cur = (int)(us & 1u), nxt = 1 - cur; const unsigned sbc = cur ? 4u : 3u, sbn = nxt ? 4u : 3u; - /* addresses first (fixed-latency ops would otherwise wait for the loads below), then loads back to back; the - * staging words go in rounds of 4 so the temporaries stay few */ + /* addresses first (fixed-latency ops would otherwise wait for the loads below), then loads back to back */ const int last = us + 1 == U, prefetch = !last || KS > U; - int pwn = -1, psn = -1; + int pwn = -1, psn = -1, nf = -1; if (prefetch) { pwn = V64(e); psn = V64(e); } int sa = V(e); if (e->err) return -1; if (prefetch && !last) { imadw(e, pwn, one, (us + 1) * 32u * LB, pwc); imadw(e, psn, one, spec->mutant == 2 ? 0u : (us + 1) * BPS * 4u, psc); } else if (prefetch) { /* the next iteration's step 0; the last iteration re-reads its own step (harmless, drained after the loop) */ - int nf = V(e), inc = V(e), inc2 = V(e); + int inc, inc2; + if (XA) { inc = V(e); inc2 = V(e); nf = V(e); } + else { nf = V(e); inc = V(e); inc2 = V(e); } if (e->err) return -1; imadi(e, nf, one, 0, 0xfffffffeu, cntk); /* cntk - 2 */ shr(e, nf, nf, 0, 31); /* 1 iff cntk == 1 (the last iteration) */ @@ -285,18 +354,34 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell imadi(e, inc, nf, 0, U * 32u * LB, NOREG); imadi(e, inc2, nf, 0, spec->mutant == 2 ? 0u : U * BPS * 4u, NOREG); imadw(e, pwn, inc, 1, pwc); imadw(e, psn, inc2, 1, psc); } - for (uint32_t j0 = 0; j0 < NJ; j0 += 4) { - const uint32_t nj = NJ - j0 < 4 ? NJ - j0 : 4; - int xv[4], xa[4]; - for (uint32_t q = 0; q < nj; q++) { xv[q] = V(e); xa[q] = V64(e); } - if (e->err) return -1; - for (uint32_t q = 0; q < nj; q++) { const uint32_t pos = (j0 + q) * T; if (RM) imadw(e, xa[q], xso, 1u, xb[j0 + q]); else imadw(e, xa[q], one, ((pos / ROWW) * K + pos % ROWW) * 4u, xs); } - for (uint32_t q = 0; q < nj; q++) ldg32(e, xv[q], xa[q], udesc, q == 0); - if (prefetch && j0 == 0) { + if (XA) { + /* stage this step's x' words: they were loaded one step ago (the pass prologue for step 0), scoreboard 5 */ + consume(e, 5); + for (uint32_t j = 0; j < NJ; j++) { imadi(e, sa, one, 0, j * T * 4u, sa0); sts32(e, sa, xv[j]); } + if (prefetch) { ldw_pf(e, ldw, wq[nxt], pwn, 0, udesc, sbn); ldw_pf(e, BW_IR_LDG_E, sc[nxt], psn, 0, udesc, sbn); + /* the next step's x' words, into the registers the STS above has read (its SB_RD wait orders the two); the + * last step of the last iteration re-reads its own step (nf 0), never past the rows */ + if (!last) { if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs); } + else { if (RM) imadi(e, xso, nf, 0, ROWW * 4u, xso); else imadw(e, xs, nf, ROWW * 4u, xs); } + x_prefetch(e, NJ, T, ROWW, K, RM, one, xs, xso, xb, xv, udesc); + } + } else { + /* the incumbent: this step's staging words loaded and stored inside the step, in rounds of 4 */ + for (uint32_t j0 = 0; j0 < NJ; j0 += 4) { + const uint32_t nj = NJ - j0 < 4 ? NJ - j0 : 4; + int xw[4], xa[4]; + for (uint32_t q = 0; q < nj; q++) { xw[q] = V(e); xa[q] = V64(e); } + if (e->err) return -1; + for (uint32_t q = 0; q < nj; q++) { const uint32_t pos = (j0 + q) * T; if (RM) imadw(e, xa[q], xso, 1u, xb[j0 + q]); else imadw(e, xa[q], one, ((pos / ROWW) * K + pos % ROWW) * 4u, xs); } + for (uint32_t q = 0; q < nj; q++) ldg32(e, xw[q], xa[q], udesc, q == 0); + if (prefetch && j0 == 0) { + ldw_pf(e, ldw, wq[nxt], pwn, 0, udesc, sbn); + ldw_pf(e, BW_IR_LDG_E, sc[nxt], psn, 0, udesc, sbn); + } + for (uint32_t q = 0; q < nj; q++) { imadi(e, sa, one, 0, (j0 + q) * T * 4u, sa0); sts32(e, sa, xw[q]); } } - for (uint32_t q = 0; q < nj; q++) { imadi(e, sa, one, 0, (j0 + q) * T * 4u, sa0); sts32(e, sa, xv[q]); } } bar_sync(e); consume(e, sbc); @@ -319,7 +404,7 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell else ffma(e, acc[m], dot[m], sc[cur], 0, acc[m]); } bar_sync(e); - if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs); + if (!XA) { if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs); } } imadw(e, pwc, one, U * 32u * LB, pwc); imadw(e, psc, one, spec->mutant == 2 ? 0u : U * BPS * 4u, psc); @@ -327,7 +412,8 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell isetp_ge_u32(e, cntk, one); bra_if_p0(e, L_k); loop_end(e); - consume(e, 3); consume(e, 4); + consume(e, 3); if (!RA) consume(e, 4); /* row_ahead: scoreboard 4 is the next row, waited for at the next pass prologue */ + if (XA) consume(e, 5); /* the last step's re-read x' words land before their registers go out of scope */ /* ---- reduce and store, per row of the pass ---- */ for (uint32_t m = 0; m < MT; m++) @@ -361,6 +447,7 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell const int L_end = here(e); patch_bra(e, bra_end, L_end); if (bra_empty >= 0) patch_bra(e, bra_empty, L_end); + if (RA) consume(e, 4); /* the last prefetched row lands before EXIT */ tail(e); if (e->err) return -1; return omega_bw_regalloc_solve(prog); diff --git a/src/omega_blackwell_codegen_gemm.h b/src/omega_blackwell_codegen_gemm.h index 74abbcfa..cd391839 100644 --- a/src/omega_blackwell_codegen_gemm.h +++ b/src/omega_blackwell_codegen_gemm.h @@ -18,7 +18,8 @@ * stages one K step of MT rows (MT*32*LB*4 <= 16384 bytes: the QMD shared-memory limit of omega_blackwell_qmd.h) in * shared memory, so every lane reads its 4 columns of every row with one conflict-free LDS.128. Per step: stage, * BAR.SYNC, compute, BAR.SYNC. The weights and scales of step s+1 are loaded before step s computes (two register - * sets, scoreboards 3 and 4 held until the step that uses them). + * sets, scoreboards 3 and 4 held until the step that uses them); with x_ahead 1 (L312 lever 3) so are the staging words + * of x' for step s+1 (scoreboard 5, stored at the start of the step that reads them): neither latency sits between the barriers. * * Segment table (device, 32 bytes per segment, ctaid.y = segment): { w_va u64, s_va u64, row0 u32, cnt u32, pad[8] }. * Constant bank 0 argument words (cbank + 0x380): @@ -35,7 +36,9 @@ * * mutant (tests only): 1 drops the block scale (acc += dot), 2 never advances the scale pointer (wrong when KS >= 2), * 3 reads the neighbouring row's x (m ^ 1) for every row, 4 drops the empty-segment guard (a cnt 0 segment then runs 2^32 passes: the - * warp simulator's step budget catches it). Each must be caught. + * warp simulator's step budget catches it), 5 (row_ahead only) prefetches weight row rg + stride + 1 instead of rg + stride, + * 6 (row_ahead only) prefetches the next weight row at every pass instead of the last (wrong when a segment runs >= 2 passes). + * Each must be caught. */ #include <stdint.h> #include "omega_blackwell_codegen.h" @@ -66,6 +69,14 @@ typedef struct { * expert on the chip; the x' buffer holds one permuted row per head, the outputs land in head order). 0: the * prefill form, x' row i and y row i are sorted row i. mt <= 4 (registers); the dense trunk of a stroke (one * segment, the heads' rows in head order) needs no map and runs at mt 8. */ + uint32_t x_ahead; /* 1 (L312 lever 3): the staging words of x' for step s+1 are loaded during step s on scoreboard 5 and + * stored at the start of the step that reads them; NJ = mt * lane_bytes / warps <= 16 (registers). 0: the + * incumbent program, byte for byte (the staging words loaded inside the step that stores them). */ + uint32_t row_ahead; /* 1 (P-DRA-4 DRA-79, KS = 1 only: k == 32 * lane_bytes, the decode down projection): the weights and scale + * of the warp's NEXT weight row (rg + stride, clamped) are loaded during the last pass of the current row on + * scoreboard 4 into the second register set, and moved into the first at the next pass prologue, so the + * one-step K loop no longer waits a full load latency per row. Passes before the last re-load the current + * row. 0: the incumbent program, byte for byte. */ } OmegaFp8GemmSpec; int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, BlackwellIRProgram *prog); diff --git a/src/omega_bw_hazard.c b/src/omega_bw_hazard.c index 026ae76b..7776618e 100644 --- a/src/omega_bw_hazard.c +++ b/src/omega_bw_hazard.c @@ -115,7 +115,7 @@ int omega_bw_decode(const uint8_t b[16], OmegaBwInsn *d) { } const char *omega_bw_hazard_kind(uint8_t kind) { - return kind == OMEGA_BW_HZ_RAW ? "RAW" : kind == OMEGA_BW_HZ_WAR ? "WAR" : kind == OMEGA_BW_HZ_WAW ? "WAW" : "?"; + return kind == OMEGA_BW_HZ_RAW ? "RAW" : kind == OMEGA_BW_HZ_WAR ? "WAR" : kind == OMEGA_BW_HZ_WAW ? "WAW" : kind == OMEGA_BW_HZ_EXIT ? "EXIT" : "?"; } /* ---- the walk --------------------------------------------------------------------------------------------------- @@ -175,6 +175,11 @@ static void step(const OmegaBwInsn *d, uint32_t pc, State *s, OmegaBwHazardRepor int has_w = d->wbar != OMEGA_BW_NOBAR; if (has_w || d->var) { s->w[i] |= 1ull << (has_w ? (1u << d->wbar) : 0u); s->wpc[i] = pc; } } + /* EXIT (unconditional) with a register write still in flight: the program never waited for a load it issued (P-DRA-4 + * DRA-79: a prefetch past the last use). Reported once per register, against the producer. */ + if (d->flow == OMEGA_BW_FLOW_EXIT && d->guard == 7u) + for (unsigned i = 0; i < NREG; i++) + if (s->w[i]) { if (rep) note(rep, pc, s->wpc[i], OMEGA_BW_HZ_EXIT, i, s->w[i]); s->w[i] = 0; } /* late source reads: held until a wait on the read barrier or on the write barrier (completion) */ if (d->late || d->rbar != OMEGA_BW_NOBAR) { unsigned m = (d->rbar != OMEGA_BW_NOBAR ? 1u << d->rbar : 0u) | (d->wbar != OMEGA_BW_NOBAR ? 1u << d->wbar : 0u); diff --git a/src/omega_bw_hazard.h b/src/omega_bw_hazard.h index cd80642c..e2e56d4d 100644 --- a/src/omega_bw_hazard.h +++ b/src/omega_bw_hazard.h @@ -55,7 +55,8 @@ typedef struct { * reported as not checked, never as clean). */ int omega_bw_decode(const uint8_t b[16], OmegaBwInsn *d); -enum { OMEGA_BW_HZ_RAW = 1, OMEGA_BW_HZ_WAR = 2, OMEGA_BW_HZ_WAW = 3 }; +/* OMEGA_BW_HZ_EXIT: an unconditional EXIT reached with a register write (a load) still pending on some path. */ +enum { OMEGA_BW_HZ_RAW = 1, OMEGA_BW_HZ_WAR = 2, OMEGA_BW_HZ_WAW = 3, OMEGA_BW_HZ_EXIT = 4 }; typedef struct { uint32_t pc; /* instruction index of the offending reader / writer */ diff --git a/src/omega_gpu_fp8gemm_api.c b/src/omega_gpu_fp8gemm_api.c index 6487abba..18a268b0 100644 --- a/src/omega_gpu_fp8gemm_api.c +++ b/src/omega_gpu_fp8gemm_api.c @@ -3,15 +3,17 @@ * See the header. Submission path and buffer policy are the FP8 GEMV API's: every buffer both sides touch is * GPU-uncached (nvos.h NVOS32_ATTR2_GPU_CACHEABLE), one launch = omega_gpu_session_launch. */ #include "omega_gpu_fp8gemm_api.h" +#include "omega_gpu_fp8gemm_internal.h" #include "omega_gpu_session.h" #include "omega_gpu_cmdlist.h" #include "omega_gpu_fmt.h" #include "omega_gpu_native_runtime.h" #include "omega_gpu_code_alloc.h" #include <string.h> +#include <stdio.h> #include <stdlib.h> -#define CACHE_SLOTS 8 +#define CACHE_SLOTS 16 /* DRA-89: the row-aware stroke pins 8 dense shapes (mt 1/2/4/8 at k 2048, 4096) + 2 expert shapes; the native cache holds 16 (omega_gpu_fp8_api.c) */ #define MARKER_TIMEOUT_MS 20000ull #define POISON_F32 (-999.0f) @@ -96,6 +98,22 @@ void omega_gpu_fp8gemm_shape_for(uint32_t k, uint32_t *mt, uint32_t *warps, uint if (mt) *mt = g.mt ? g.mt : 4u; if (warps) *warps = g.warps ? g.warps : 16u; } +/* L312 lever 3: x' staging words one K step ahead, OFF unless AIEN_OMEGA_FP8GEMM_X_AHEAD=1 (read once; P-DRA-4 DRA-67: + * decode changes are env-gated, default off, until the stroke gate passes), and only where the NJ = mt * lane_bytes / + * warps staging words fit the registers the program holds for them (NJ <= 16); call after mt is final */ +static void x_ahead_for(OmegaFp8GemmSpec *spec) { + static int on = -1; + if (on < 0) { const char *e = getenv("AIEN_OMEGA_FP8GEMM_X_AHEAD"); on = (e && e[0] == '1' && e[1] == 0) ? 1 : 0; } + spec->x_ahead = on && spec->mt * spec->lane_bytes / spec->warps <= 16u ? 1u : 0u; +} +/* DRA-79 (P-DRA-4): the next weight row's weights and scale loaded during the current row (OmegaFp8GemmSpec.row_ahead), OFF + * unless AIEN_OMEGA_FP8GEMM_ROW_AHEAD=1 (read once), and only at one K step per row (k == 32 * lane_bytes: the 35B's down + * projection, k 512); every call that resolves its spec here (the stroke, prefill) takes it */ +static void row_ahead_for(OmegaFp8GemmSpec *spec) { + static int on = -1; + if (on < 0) { const char *e = getenv("AIEN_OMEGA_FP8GEMM_ROW_AHEAD"); on = (e && e[0] == '1' && e[1] == 0) ? 1 : 0; } + spec->row_ahead = on && spec->k == 32u * spec->lane_bytes ? 1u : 0u; +} /* dense = a few distinct experts with many rows each (qkv, o): 8 rows per pass measured best there */ static void spec_for(uint32_t k, uint32_t segs, OmegaFp8GemmSpec *spec) { memset(spec, 0, sizeof *spec); @@ -103,6 +121,8 @@ static void spec_for(uint32_t k, uint32_t segs, OmegaFp8GemmSpec *spec) { omega_gpu_fp8gemm_shape_for(k, &spec->mt, &spec->warps, &spec->lane_bytes); if (!g.mt && segs < 8u) spec->mt = 8u; spec->mutant = g.mutant; + x_ahead_for(spec); + row_ahead_for(spec); } static int g_rec; /* 1 while a record call runs (lock held): kernel_for must not evict */ @@ -205,11 +225,25 @@ int omega_gpu_fp8gemm_prepare(uint32_t k) { return rc; } +/* DRA-89 (P-DRA-4): the row-aware dense decode shape, OFF unless AIEN_OMEGA_FP8GEMM_ROWAWARE=1 (read once; decode changes are + * env-gated, default off, until the stroke gate passes). The stroke's dense calls (one segment: MIX, O) record with mt = the + * live rows rounded up to 1, 2, 4 or 8 instead of spec_for's dense 8, so a stroke of N < 8 conversations does not stage and + * multiply 8 - N padding rows per pass. 0 = the incumbent choice (knob off, a set_shape mt, or no rows). */ +uint32_t omega_gpu_fp8gemm_dense_mt(uint32_t rows) { + static int on = -1; + if (on < 0) { const char *e = getenv("AIEN_OMEGA_FP8GEMM_ROWAWARE"); on = (e && e[0] == '1' && e[1] == 0) ? 1 : 0; } + if (!on || g.mt || rows == 0) return 0; + return rows <= 1u ? 1u : rows <= 2u ? 2u : rows <= 4u ? 4u : 8u; +} /* ---- the stroke's record path (L312 v2): one launch appended to a command list, every buffer the caller's ---- */ static void spec_for_stroke(uint32_t k, uint32_t segs, uint32_t mt, int rowmap, OmegaFp8GemmSpec *spec) { spec_for(k, segs, spec); if (mt) spec->mt = mt; spec->rowmap = rowmap ? 1u : 0u; + x_ahead_for(spec); +} +void omega_gpu_fp8gemm_stroke_spec(uint32_t k, uint32_t segs, uint32_t mt, int rowmap, OmegaFp8GemmSpec *spec) { + spec_for_stroke(k, segs, mt, rowmap, spec); } int omega_gpu_fp8gemm_prepare_shape(uint32_t k, uint32_t segs, uint32_t mt, int rowmap) { OmegaFp8GemmSpec spec; spec_for_stroke(k, segs, mt, rowmap, &spec); @@ -228,7 +262,62 @@ int omega_gpu_fp8gemm_prepare_shape(uint32_t k, uint32_t segs, uint32_t mt, int omega_gpu_session_unlock(); return rc; } -uint32_t omega_gpu_fp8gemm_cta_budget_for(uint32_t segs) { return g.ctas ? g.ctas : (segs >= 64u ? 2u : segs >= 8u ? 12u : 96u); } +/* DRA-78 (P-DRA-4): AIEN_OMEGA_FP8GEMM_CTA_BUDGET, read once, sets the CTA budget per segment of the calls that take the + * API's choice (record cta_budget 0, the stroke; the prefill call) for a chip sweep. Comma-separated items, each "N" (every + * call) or "K:N" (the grouped calls of tensor width K with >= 8 segments: the stroke's experts, 512 = down, 2048 = gate_up; + * the dense trunk keeps the rule). N 1..1024, K 1..16384, at most one bare N and one item per K. Unset = the incumbent rule + * exactly. A malformed value is refused whole (one stderr line; the rule stays) so a sweep never runs a budget it did not + * name: slices check the resolved budget first with gpu_fp8gemm_test --spec-of K,SEGS,MT,ROWMAP --expect "ctas=N". + * Precedence: the record's cta_budget argument, then omega_gpu_fp8gemm_set_cta_budget, then K:N, then N, then the rule. */ +#define CTA_ENV_ITEMS 8 +static struct { int read; uint32_t all, n, k[CTA_ENV_ITEMS], c[CTA_ENV_ITEMS]; } g_cta_env; +static int parse_dec(const char **p, uint32_t lo, uint32_t hi, uint32_t *v) { + const char *s = *p; uint32_t x = 0; + if (*s < '0' || *s > '9') return -1; + while (*s >= '0' && *s <= '9') { x = x * 10u + (uint32_t)(*s - '0'); if (x > hi) return -1; s++; } + if (x < lo) return -1; + *p = s; *v = x; return 0; +} +/* 0 on success (out filled), -1 malformed; s non-NULL */ +static int cta_env_parse(const char *s, uint32_t *all, uint32_t *n, uint32_t *ks, uint32_t *cs) { + *all = 0; *n = 0; + if (!*s) return -1; + for (;;) { + uint32_t a = 0, b = 0; + if (parse_dec(&s, 1, 16384, &a) != 0) return -1; + if (*s == ':') { + s++; + if (parse_dec(&s, 1, 1024, &b) != 0 || *n == CTA_ENV_ITEMS) return -1; + for (uint32_t i = 0; i < *n; i++) if (ks[i] == a) return -1; + ks[*n] = a; cs[*n] = b; (*n)++; + } else { + if (a > 1024u || *all) return -1; + *all = a; + } + if (!*s) return 0; + if (*s++ != ',') return -1; + } +} +static void cta_env_read(void) { + if (g_cta_env.read) return; + g_cta_env.read = 1; + const char *e = getenv("AIEN_OMEGA_FP8GEMM_CTA_BUDGET"); + if (!e) return; + uint32_t all = 0, n = 0, ks[CTA_ENV_ITEMS], cs[CTA_ENV_ITEMS]; + if (cta_env_parse(e, &all, &n, ks, cs) != 0) { fprintf(stderr, "omega_gpu_fp8gemm: AIEN_OMEGA_FP8GEMM_CTA_BUDGET=\"%s\" refused (want N or K:N items, N 1..1024): the incumbent budget stays\n", e); return; } + g_cta_env.all = all; g_cta_env.n = n; + for (uint32_t i = 0; i < n; i++) { g_cta_env.k[i] = ks[i]; g_cta_env.c[i] = cs[i]; } +} +/* the budget a call of width k (0: no width, the public form) with segs segments gets when its caller passes 0 */ +static uint32_t budget_for(uint32_t k, uint32_t segs) { + if (g.ctas) return g.ctas; + cta_env_read(); + if (segs >= 8u) for (uint32_t i = 0; i < g_cta_env.n; i++) if (g_cta_env.k[i] == k) return g_cta_env.c[i]; + if (g_cta_env.all) return g_cta_env.all; + return segs >= 64u ? 2u : segs >= 8u ? 12u : 96u; +} +uint32_t omega_gpu_fp8gemm_cta_budget_for(uint32_t segs) { return budget_for(0, segs); } +uint32_t omega_gpu_fp8gemm_stroke_cta_budget(uint32_t k, uint32_t segs) { return budget_for(k, segs); } int omega_gpu_fp8gemm_record(OmegaGpuCmdList *cl, const OmegaGpuFp8Tensor *t, uint32_t rows, uint32_t segs, uint64_t seg_va, uint64_t xp_va, uint64_t y_va, uint64_t xmap_va, uint64_t ymap_va, uint32_t mt, uint32_t cta_budget, OmegaGpuFp8GemmInfo *info) { @@ -241,7 +330,7 @@ int omega_gpu_fp8gemm_record(OmegaGpuCmdList *cl, const OmegaGpuFp8Tensor *t, ui if (omega_fp8gemm_shared_bytes(&spec) == 0) { omega_gpu_session_set_error("fp8 gemm record: shape refused (rowmap needs mt <= 4)"); return OMEGA_GPU_FP8GEMM_BAD_ARGS; } const uint32_t W = spec.warps; uint32_t grid_x = (n + W - 1) / W; - const uint32_t budget = cta_budget ? cta_budget : omega_gpu_fp8gemm_cta_budget_for(segs); + const uint32_t budget = cta_budget ? cta_budget : budget_for(k, segs); if (grid_x > budget) grid_x = budget; if (grid_x == 0) grid_x = 1; /* caller holds the session lock */ @@ -337,7 +426,7 @@ static int gemm_core(const OmegaGpuFp8Tensor *t, uint32_t M, const uint32_t *ids if (general_ok && omega_fp8gemm_shared_bytes(&spec) == 0) return general_gemm(t, M, ids, trow, x32, x16, y, n, k, segs, info, OMEGA_GPU_FP8GEMM_CODEGEN_FAIL, t0); const uint32_t MT = spec.mt, W = spec.warps; uint32_t grid_x = (n + W - 1) / W; - uint32_t budget = g.ctas ? g.ctas : (segs >= 64u ? 2u : segs >= 8u ? 12u : 96u); + uint32_t budget = budget_for(k, segs); if (grid_x > budget) grid_x = budget; if (grid_x == 0) grid_x = 1; diff --git a/src/omega_gpu_fp8gemm_api.h b/src/omega_gpu_fp8gemm_api.h index cf896905..83102587 100644 --- a/src/omega_gpu_fp8gemm_api.h +++ b/src/omega_gpu_fp8gemm_api.h @@ -105,6 +105,9 @@ int omega_gpu_fp8gemm_record(struct OmegaGpuCmdList *cl, const OmegaGpuFp8Tensor OmegaGpuFp8GemmInfo *info); int omega_gpu_fp8gemm_prepare_shape(uint32_t k, uint32_t segs, uint32_t mt, int rowmap); uint32_t omega_gpu_fp8gemm_cta_budget_for(uint32_t segs); +/* DRA-89: the mt a one-segment (dense) stroke call of `rows` rows records with: 0 (the incumbent dense 8) unless + * AIEN_OMEGA_FP8GEMM_ROWAWARE=1, then rows rounded up to 1, 2, 4, 8. Prepare every value the stroke can pass. */ +uint32_t omega_gpu_fp8gemm_dense_mt(uint32_t rows); /* host helper: the permuted, 2^64-scaled x' row the kernel reads (k values in, k out) */ void omega_fp8gemm_permute_x(const float *x, uint32_t k, uint32_t lane_bytes, float *out); diff --git a/src/omega_gpu_fp8gemm_internal.h b/src/omega_gpu_fp8gemm_internal.h new file mode 100644 index 00000000..5e708bc4 --- /dev/null +++ b/src/omega_gpu_fp8gemm_internal.h @@ -0,0 +1,12 @@ +#ifndef OMEGA_GPU_FP8GEMM_INTERNAL_H +#define OMEGA_GPU_FP8GEMM_INTERNAL_H +/* Library-internal view of omega_gpu_fp8gemm_api.c for the host tests. Not part of the public ABI (no manifest entry). */ +#include "omega_blackwell_codegen_gemm.h" +#include <stdint.h> +/* The program spec omega_gpu_fp8gemm_prepare_shape / _record would build for (k, segs, mt, rowmap) under the process's + * environment and setters (AIEN_OMEGA_FP8GEMM_X_AHEAD, omega_gpu_fp8gemm_set_shape, ...). Host only: opens no device. */ +void omega_gpu_fp8gemm_stroke_spec(uint32_t k, uint32_t segs, uint32_t mt, int rowmap, OmegaFp8GemmSpec *spec); +/* The CTA budget per segment a call of width k with segs segments gets when it passes cta_budget 0 (the stroke), under + * the process's environment and setters (AIEN_OMEGA_FP8GEMM_CTA_BUDGET, omega_gpu_fp8gemm_set_cta_budget; DRA-78). */ +uint32_t omega_gpu_fp8gemm_stroke_cta_budget(uint32_t k, uint32_t segs); +#endif diff --git a/src/omega_gpu_q36_graph.c b/src/omega_gpu_q36_graph.c index 31736829..e0a0b0fd 100644 --- a/src/omega_gpu_q36_graph.c +++ b/src/omega_gpu_q36_graph.c @@ -605,11 +605,18 @@ _Static_assert(sizeof(Seg32) == OMEGA_GEMM_SEG_BYTES, "segment entry layout"); int omega_gpu_q36_graph_set_batch(OmegaGpuQ36Graph *g, int on) { if (!g || g->in_token) return OMEGA_GPU_DGRAPH_BAD_ARGS; if (!on) { g->batch = 0; return OMEGA_GPU_DGRAPH_OK; } - /* pin the four GEMM shapes the batch records (a kernel cache miss while recording is refused): the dense trunk at 8 rows - * per pass without maps, the expert blocks at 4 rows per pass with the row maps */ + /* pin the GEMM shapes the batch records (a kernel cache miss while recording is refused): the dense trunk at 8 rows + * per pass without maps (or, row-aware, DRA-89, every mt omega_gpu_fp8gemm_dense_mt gives for 1..heads rows), the expert + * blocks at 4 rows per pass with the row maps */ const uint32_t R = g->heads * NG; - int rc = omega_gpu_fp8gemm_prepare_shape(H, 1, 0, 0); - if (rc == 0) rc = omega_gpu_fp8gemm_prepare_shape(OMEGA_GPU_Q36_MIXER_OUT, 1, 0, 0); + int rc = 0; + for (uint32_t r = 1, last = UINT32_MAX; r <= g->heads && rc == 0; r++) { + const uint32_t mt = omega_gpu_fp8gemm_dense_mt(r); + if (mt == last) continue; + last = mt; + rc = omega_gpu_fp8gemm_prepare_shape(H, 1, mt, 0); + if (rc == 0) rc = omega_gpu_fp8gemm_prepare_shape(OMEGA_GPU_Q36_MIXER_OUT, 1, mt, 0); + } if (rc == 0) rc = omega_gpu_fp8gemm_prepare_shape(H, R, 0, 1); if (rc == 0) rc = omega_gpu_fp8gemm_prepare_shape(EI, R, 0, 1); if (rc != 0) return OMEGA_GPU_DGRAPH_CHIP_FAIL; @@ -707,7 +714,7 @@ int omega_gpu_q36_graph_record_layer_heads(OmegaGpuQ36Graph *g, uint32_t l, cons if (rc == OMEGA_GPU_DGRAPH_OK) rc = rec_perm(g, K_PERM_XQ, xq0, pt2048, xp, H, N); if (!g->layer[l].attn) { if (rc == OMEGA_GPU_DGRAPH_OK) rc = after_op(g, OMEGA_GPU_Q36_K_AB, omega_gpu_bf16_gemv_rows_record(g->cl, g->layer[l].ab, N, xq0, abN)); - if (rc == OMEGA_GPU_DGRAPH_OK) rc = native_record_gemm(g, OMEGA_GPU_Q36_K_MIX, g->layer[l].mix, N, 1, segd, xp, mixN, 0, 0, 0); + if (rc == OMEGA_GPU_DGRAPH_OK) rc = native_record_gemm(g, OMEGA_GPU_Q36_K_MIX, g->layer[l].mix, N, 1, segd, xp, mixN, 0, 0, omega_gpu_fp8gemm_dense_mt(N)); for (uint32_t h = 0; h < N && rc == OMEGA_GPU_DGRAPH_OK; h++) { const uint64_t mix_h = mixN + (uint64_t)h * OMEGA_GPU_Q36_GDN_MIX * 4u; uint64_t mo = 0; @@ -716,7 +723,7 @@ int omega_gpu_q36_graph_record_layer_heads(OmegaGpuQ36Graph *g, uint32_t l, cons if (rc == OMEGA_GPU_DGRAPH_OK) rc = rec_perm(g, K_PERM_O, mo, pt4096, op + h * MOS, OMEGA_GPU_Q36_MIXER_OUT, 1); } } else { - if (rc == OMEGA_GPU_DGRAPH_OK) rc = native_record_gemm(g, OMEGA_GPU_Q36_K_MIX, g->layer[l].mix, N, 1, segd, xp, mixN, 0, 0, 0); /* n 9216: the rows are 9216 apart */ + if (rc == OMEGA_GPU_DGRAPH_OK) rc = native_record_gemm(g, OMEGA_GPU_Q36_K_MIX, g->layer[l].mix, N, 1, segd, xp, mixN, 0, 0, omega_gpu_fp8gemm_dense_mt(N)); /* n 9216: the rows are 9216 apart */ uint32_t w[OMEGA_DEC_GA_WORDS]; memset(w, 0, sizeof w); put64(w, OMEGA_DEC_GA_IN, mixN); put64(w, OMEGA_DEC_GA_TAB, va_of(g, L->gtab)); put64(w, OMEGA_DEC_GA_OUT, aggN); if (rc == OMEGA_GPU_DGRAPH_OK) @@ -734,7 +741,7 @@ int omega_gpu_q36_graph_record_layer_heads(OmegaGpuQ36Graph *g, uint32_t l, cons } if (rc == OMEGA_GPU_DGRAPH_OK) rc = rec_perm(g, K_PERM_O, attN, pt4096, op, OMEGA_GPU_Q36_MIXER_OUT, N); } - if (rc == OMEGA_GPU_DGRAPH_OK) rc = native_record_gemm(g, OMEGA_GPU_Q36_K_O, g->layer[l].o, N, 1, segd + OMEGA_GEMM_SEG_BYTES, op, oN, 0, 0, 0); + if (rc == OMEGA_GPU_DGRAPH_OK) rc = native_record_gemm(g, OMEGA_GPU_Q36_K_O, g->layer[l].o, N, 1, segd + OMEGA_GEMM_SEG_BYTES, op, oN, 0, 0, omega_gpu_fp8gemm_dense_mt(N)); if (rc == OMEGA_GPU_DGRAPH_OK) rc = rec_res_rows(g, K_ADD_R, x0, oN, 0, 0, 1.0f, N); /* the sparse block: one router launch for the N heads (lever 2: the gate table read once; head h's buffer at rlb + h * lb_stride), * GROUP sorts their picks into one segment table, two grouped GEMMs */ diff --git a/tests/bw_hazard_test.c b/tests/bw_hazard_test.c index e052b090..b28ffcef 100644 --- a/tests/bw_hazard_test.c +++ b/tests/bw_hazard_test.c @@ -266,7 +266,7 @@ static void test_controls(void) { war[1].dst_vreg = 5; war[1].control = FIX; n = enc(war, 3, c); CHECK(n && omega_bw_hazard_check(c, n, &g_rep) == 0 && g_rep.count == 0, "control: a register the store does not read passes"); /* WAR released by the load's completion: waiting on the write barrier also frees the address */ - BlackwellIRInsn warc[] = { mk(BW_IR_LDG_E, 4, 2, -1, -1, 4, LD), mk(BW_IR_MOV_RZ, 2, -1, -1, -1, -1, CW(6, 7, 7, 0x1)), mk(BW_IR_EXIT, -1, -1, -1, -1, -1, ENDW) }; + BlackwellIRInsn warc[] = { mk(BW_IR_LDG_E, 4, 2, -1, -1, 4, LD), mk(BW_IR_MOV_RZ, 2, -1, -1, -1, -1, CW(6, 7, 7, 0x1)), mk(BW_IR_EXIT, -1, -1, -1, -1, -1, CW(5, 7, 7, 0x1)) }; n = enc(warc, 3, c); CHECK(n && omega_bw_hazard_check(c, n, &g_rep) == 0 && g_rep.count == 0, "control: address overwrite after the load completed passes"); warc[1].control = FIX; n = enc(warc, 3, c); @@ -275,6 +275,12 @@ static void test_controls(void) { BlackwellIRInsn waw[] = { mk(BW_IR_LDG_E, 4, 2, -1, -1, 4, LD), mk(BW_IR_MOV_RZ, 4, -1, -1, -1, -1, CW(6, 7, 7, 0x2)), mk(BW_IR_EXIT, -1, -1, -1, -1, -1, ENDW) }; n = enc(waw, 3, c); CHECK(n && omega_bw_hazard_check(c, n, &g_rep) == 0 && g_rep.count == 1 && finding(&g_rep, 1, OMEGA_BW_HZ_WAW, 4), "control WAW caught"); + /* EXIT with the load still in flight (P-DRA-4 DRA-79 row_ahead L_end wait) / with the wait on the EXIT */ + BlackwellIRInsn ex[] = { mk(BW_IR_LDG_E, 4, 2, -1, -1, 4, LD), mk(BW_IR_EXIT, -1, -1, -1, -1, -1, ENDW) }; + n = enc(ex, 2, c); + CHECK(n && omega_bw_hazard_check(c, n, &g_rep) == 0 && g_rep.count == 1 && finding(&g_rep, 1, OMEGA_BW_HZ_EXIT, 4), "control EXIT with a pending load caught"); + ex[1].control = CW(5, 7, 7, 0x1); n = enc(ex, 2, c); + CHECK(n && omega_bw_hazard_check(c, n, &g_rep) == 0 && g_rep.count == 0, "control EXIT behind the wait passes"); /* a variable-latency result with no write barrier at all: nothing can release it */ BlackwellIRInsn nob[] = { mk(BW_IR_S2R, 4, -1, -1, -1, -1, CW(4, 7, 7, 0)), mk(BW_IR_FADD, 6, 4, 4, -1, -1, CW(6, 7, 7, 0x3f)), mk(BW_IR_EXIT, -1, -1, -1, -1, -1, ENDW) }; nob[0].imm = BW_SR_TID_X; n = enc(nob, 3, c); @@ -366,8 +372,15 @@ static void sweep_bytes(const char *family, const char *variant, const uint8_t * CHECK(0, "%s %s: not checked (instruction %lld, word 0 %08x, decode %d)", family, variant, pc, w0, pc >= 0 ? omega_bw_decode(code + pc * 16, &d) : -9); return; } + size_t exit_open = 0; for (size_t i = 0; i < g_rep.count && i < OMEGA_BW_HAZARD_MAX; i++) { const OmegaBwHazard *f = &g_rep.f[i]; int known = 0; + /* EXIT-pending gates fp8gemm only (DRA-79). Older families (fp8_gemv2 1059, matmul_frag_block 75, matmul_frag 9 at + * 2026-10-31) exit with prefetches in flight; listed as EXITPEND, kept out of the findings total, not gated yet. */ + if (f->kind == OMEGA_BW_HZ_EXIT && strcmp(family, "fp8gemm")) { + printf("EXITPEND %s %s: IR %u R%u (producer IR %u) [not gated]\n", family, variant, f->pc, f->reg, f->src_pc); + exit_open++; continue; + } for (size_t k = 0; g_known[k].family; k++) if (!strcmp(g_known[k].family, family) && (g_known[k].pc == ANY_PC || g_known[k].pc == f->pc) && g_known[k].kind == f->kind && g_known[k].reg == f->reg && g_known[k].uniform == f->uniform) { g_known[k].seen = 1; known = g_known[k].cls; } @@ -375,7 +388,7 @@ static void sweep_bytes(const char *family, const char *variant, const uint8_t * f->uniform ? "U" : "", f->reg, f->release, f->src_pc, known ? "triaged" : "UNTRIAGED", known ? known : '-'); CHECK(known, "%s %s: untriaged %s at IR %u", family, variant, omega_bw_hazard_kind(f->kind), f->pc); } - g_findings_total += g_rep.count; + g_findings_total += g_rep.count - exit_open; if (g_dump_dir && g_rep.count) { char path[512]; snprintf(path, sizeof path, "%s/%s-%zu.bin", g_dump_dir, family, g_nseen - 1); /* 0644, not fopen's 0666 & ~umask: a dump is never world-writable */ @@ -416,11 +429,13 @@ static void sweep(void) { snprintf(v, sizeof v, "k%u rows%u warps%u depth%u", ks[a], rows, w, dp); if (BUILD(omega_blackwell_codegen_bf16_gemv_prog(&s, &g_prog))) sweep_prog("bf16_gemv", v, P_NONE); } } - /* fp8 grouped GEMM */ - { unsigned ks[] = { 768, 2048, 4096 }; - for (unsigned a = 0; a < 3; a++) for (unsigned lb = 8; lb <= 16; lb += 8) for (unsigned mt = 1; mt <= 16; mt *= 2) for (unsigned w = 1; w <= 32; w *= 2) { - OmegaFp8GemmSpec s = { .k = ks[a], .lane_bytes = lb, .mt = mt, .warps = w }; - snprintf(v, sizeof v, "k%u lane%u mt%u warps%u", ks[a], lb, mt, w); + /* fp8 grouped GEMM: the incumbent, rowmap (the stroke's expert form), x_ahead (L312 lever 3, scoreboard 5) and row_ahead + * (DRA-79, scoreboard 4 held across the row loop; one K step only: k 256 at lane 8, k 512 at lane 16) */ + { unsigned ks[] = { 512, 768, 2048, 4096, 256 }; + for (unsigned a = 0; a < 5; a++) for (unsigned lb = 8; lb <= 16; lb += 8) for (unsigned mt = 1; mt <= 16; mt *= 2) for (unsigned w = 1; w <= 32; w *= 2) + for (unsigned rm = 0; rm <= 1; rm++) for (unsigned xa = 0; xa <= 1; xa++) for (unsigned ra = 0; ra <= 1; ra++) { + OmegaFp8GemmSpec s = { .k = ks[a], .lane_bytes = lb, .mt = mt, .warps = w, .rowmap = rm, .x_ahead = xa, .row_ahead = ra }; + snprintf(v, sizeof v, "k%u lane%u mt%u warps%u%s%s%s", ks[a], lb, mt, w, rm ? " rowmap" : "", xa ? " x_ahead" : "", ra ? " row_ahead" : ""); if (BUILD(omega_blackwell_codegen_fp8gemm_prog(&s, &g_prog))) sweep_prog("fp8gemm", v, P_NONE); } } /* ternary GEMV */ diff --git a/tests/gpu_fp8gemm_test.c b/tests/gpu_fp8gemm_test.c index 988d8a24..bada1575 100644 --- a/tests/gpu_fp8gemm_test.c +++ b/tests/gpu_fp8gemm_test.c @@ -12,6 +12,7 @@ * Verdict line last: "gpu_fp8gemm_test: N checks, F failed: PASS|FAIL". */ #include "omega_gpu_fp8gemm_api.h" +#include "omega_gpu_fp8gemm_internal.h" #include "omega_gpu_fp8_api.h" #include "omega_gpu_session.h" #include "bw_warp_sim_k.h" @@ -118,19 +119,50 @@ static void host_only(void) { CHECK(p[(1 * 32 + 5) * 4 + 2] / 18446744073709551616.0f == x[86], "column 86 sits at lane 5 word 1 element 2"); } struct { uint32_t k, lb, mt, w; } shp[] = { { 2048, 16, 8, 16 }, { 4096, 16, 8, 16 }, { 1024, 16, 8, 16 }, { 768, 8, 8, 16 }, { 768, 8, 8, 8 }, { 2048, 8, 8, 16 }, { 2048, 16, 4, 16 }, { 2048, 16, 8, 32 }, { 2048, 16, 8, 8 }, { 2048, 16, 4, 8 }, { 4096, 16, 4, 8 } }; for (unsigned i = 0; i < sizeof shp / sizeof shp[0]; i++) for (int m = 0; m <= 3; m++) { - OmegaFp8GemmSpec s = { shp[i].k, shp[i].lb, shp[i].mt, shp[i].w, m, 0 }; uint32_t n = 0, gp = 0; + OmegaFp8GemmSpec s = { shp[i].k, shp[i].lb, shp[i].mt, shp[i].w, m, 0, 0, 0 }; uint32_t n = 0, gp = 0; int rc = omega_fp8gemm_prog_stats(&s, &n, &gp); uint32_t decl = ((gp + 1 + 7) / 8) * 8; CHECK(rc == 0 && n <= 1024, "codegen k %u lb %u mt %u warps %u mutant %d: rc %d insns %u gprs %u", s.k, s.lane_bytes, s.mt, s.warps, m, rc, n, gp); if (m == 0 && rc == 0) printf("codegen k %4u lane %2u mt %2u warps %2u: %u instructions, %u registers (declared %u, register file %u of 65536)%s, shared %u B\n", s.k, s.lane_bytes, s.mt, s.warps, n, gp, decl, 32u * s.warps * decl, 32u * s.warps * decl <= 65536u ? "" : " DOES NOT FIT", omega_fp8gemm_shared_bytes(&s)); } - { OmegaFp8GemmSpec s = { 2048, 16, 16, 16, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 16 at lane 16 refused (32 KB of shared memory)"); } - { OmegaFp8GemmSpec s = { 2048, 16, 6, 16, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 6 refused"); } - { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 5, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mutant 5 refused"); } - { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 2 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap 2 refused"); } - { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 1 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap at mt 8 refused (registers)"); } + { OmegaFp8GemmSpec s = { 2048, 16, 16, 16, 0, 0, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 16 at lane 16 refused (32 KB of shared memory)"); } + { OmegaFp8GemmSpec s = { 2048, 16, 6, 16, 0, 0, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 6 refused"); } + { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 7, 0, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mutant 7 refused"); } + /* DRA-79 row_ahead: KS 1 only (k == 32 * lane_bytes), 0/1 only; mutants 5 and 6 only with it */ + { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 0, 0, 1 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "row_ahead at KS 4 refused"); } + { OmegaFp8GemmSpec s = { 1024, 16, 8, 16, 0, 0, 0, 1 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "row_ahead at KS 2 refused"); } + { OmegaFp8GemmSpec s = { 512, 16, 4, 16, 0, 0, 0, 2 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "row_ahead 2 refused"); } + for (int m = 5; m <= 6; m++) { OmegaFp8GemmSpec s = { 512, 16, 4, 16, m, 0, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mutant %d without row_ahead refused", m); + s.row_ahead = 1; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) == 0, "mutant %d with row_ahead accepted", m); } + { struct { uint32_t k, lb, mt, w, rm, xa; } ra[] = { { 512, 16, 4, 16, 0, 0 }, { 512, 16, 8, 16, 0, 0 }, { 512, 16, 4, 8, 0, 0 }, { 512, 16, 4, 16, 1, 0 }, + { 512, 16, 4, 16, 1, 1 }, { 512, 16, 8, 16, 0, 1 }, { 256, 8, 4, 8, 0, 0 }, { 256, 8, 4, 8, 1, 1 } }; + for (unsigned i = 0; i < sizeof ra / sizeof ra[0]; i++) { + OmegaFp8GemmSpec s = { ra[i].k, ra[i].lb, ra[i].mt, ra[i].w, 0, ra[i].rm, ra[i].xa, 1 }; uint32_t n = 0, gp = 0; + int rc = omega_fp8gemm_prog_stats(&s, &n, &gp); + uint32_t decl = ((gp + 1 + 7) / 8) * 8; + CHECK(rc == 0 && n <= 1024 && 32u * s.warps * decl <= 65536u, "row_ahead codegen k %u lb %u mt %u warps %u rowmap %u x_ahead %u: rc %d insns %u gprs %u", s.k, s.lane_bytes, s.mt, s.warps, s.rowmap, s.x_ahead, rc, n, gp); + printf("row_ahead codegen k %4u lane %2u mt %2u warps %2u%s%s: %u instructions, %u registers (declared %u, register file %u of 65536)\n", s.k, s.lane_bytes, s.mt, s.warps, s.rowmap ? " rowmap" : "", s.x_ahead ? " x_ahead" : "", n, gp, decl, 32u * s.warps * decl); + } } + { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 2, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap 2 refused"); } + { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 1, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap at mt 8 refused (registers)"); } + /* L312 lever 3 (x_ahead): every shape above and the rowmap form at mt 4 build with the NJ prefetch registers (fit is + * printed as above: warps 32 does not fit either way); NJ > 16 and x_ahead 2 are refused */ + for (unsigned i = 0; i < sizeof shp / sizeof shp[0]; i++) { + OmegaFp8GemmSpec s = { shp[i].k, shp[i].lb, shp[i].mt, shp[i].w, 0, 0, 1, 0 }; uint32_t n = 0, gp = 0; + int rc = omega_fp8gemm_prog_stats(&s, &n, &gp); + uint32_t decl = ((gp + 1 + 7) / 8) * 8; + CHECK(rc == 0 && n <= 1024, "x_ahead codegen k %u lb %u mt %u warps %u: rc %d insns %u gprs %u", s.k, s.lane_bytes, s.mt, s.warps, rc, n, gp); + if (rc == 0) printf("x_ahead codegen k %4u lane %2u mt %2u warps %2u: %u instructions, %u registers (declared %u)%s\n", s.k, s.lane_bytes, s.mt, s.warps, n, gp, decl, 32u * s.warps * decl <= 65536u ? "" : " DOES NOT FIT"); + } + { OmegaFp8GemmSpec s = { 2048, 16, 4, 16, 0, 1, 1, 0 }; uint32_t n = 0, gp = 0; int rc = omega_fp8gemm_prog_stats(&s, &n, &gp); + uint32_t decl = ((gp + 1 + 7) / 8) * 8; + CHECK(rc == 0 && 32u * s.warps * decl <= 65536u, "x_ahead rowmap mt 4: rc %d gprs %u", rc, gp); + printf("x_ahead codegen k 2048 lane 16 mt 4 warps 16 rowmap: %u instructions, %u registers (declared %u)\n", n, gp, decl); } + { OmegaFp8GemmSpec s = { 2048, 16, 8, 4, 0, 0, 1, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "x_ahead at NJ 32 refused (registers)"); + s.x_ahead = 0; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) == 0, "the same shape without x_ahead is accepted"); } + { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 0, 2, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "x_ahead 2 refused"); } { uint32_t ks[] = { 2048, 4096, 512, 768 }; for (unsigned i = 0; i < 4; i++) { - OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, 4, 16, 0, 1 }; uint32_t n = 0, gp = 0; + OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, 4, 16, 0, 1, 0, 0 }; uint32_t n = 0, gp = 0; int rc = omega_fp8gemm_prog_stats(&s, &n, &gp); uint32_t decl = ((gp + 1 + 7) / 8) * 8; CHECK(rc == 0 && n <= 1024 && 32u * s.warps * decl <= 65536u, "codegen k %u mt 4 rowmap: rc %d insns %u gprs %u", ks[i], rc, n, gp); @@ -143,10 +175,12 @@ static void host_only(void) { /* ------------------------------------------------------------- simulator */ static uint64_t g_sim_issues; +static uint32_t g_xa; /* the battery runs once with x_ahead 0 (the incumbent) and once with x_ahead 1 (L312 lever 3) */ +static uint32_t g_ra; /* 1: the row_ahead battery (DRA-79, KS 1 shapes only) */ typedef struct { uint32_t k, n, lb, mt, w, grid; uint32_t counts[4]; uint32_t nseg; } SimPt; static int sim_point(const SimPt *p, int mutant, uint32_t seed, char *msg, size_t msgn, size_t *bad) { static BlackwellIRProgram prog; - OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, 0 }; + OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, 0, g_xa, g_ra }; if (omega_blackwell_codegen_fp8gemm_prog(&spec, &prog) != 0) { snprintf(msg, msgn, "codegen refused"); return -1; } uint32_t M = 0; for (uint32_t g = 0; g < p->nseg; g++) M += p->counts[g]; Weights W; weights_make(&W, p->nseg, p->n, p->k, seed); @@ -198,7 +232,7 @@ static int sim_point(const SimPt *p, int mutant, uint32_t seed, char *msg, size_ * result must equal the emulation moved through YMAP and differ from the unmoved one. budget: the simulator's step budget. */ static int sim_point2(const SimPt *p, int mutant, uint32_t seed, int rowmap, int empty_at, uint64_t budget, char *msg, size_t msgn, size_t *bad, int *moved) { static BlackwellIRProgram prog; - OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, (uint32_t)rowmap }; + OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, (uint32_t)rowmap, g_xa, g_ra }; if (omega_blackwell_codegen_fp8gemm_prog(&spec, &prog) != 0) { snprintf(msg, msgn, "codegen refused"); return -1; } uint32_t M = 0; for (uint32_t g = 0; g < p->nseg; g++) M += p->counts[g]; Weights W; weights_make(&W, p->nseg, p->n, p->k, seed); @@ -268,7 +302,8 @@ static int sim_point2(const SimPt *p, int mutant, uint32_t seed, int rowmap, int return err; } -static void sim_battery(void) { +static void sim_battery_one(void) { + printf("sim battery, x_ahead %u\n", g_xa); SimPt pts[] = { { 2048, 40, 16, 8, 16, 2, { 1, 5, 9 }, 3 }, /* lane 16, KS 4 (2 iterations), 2 passes in segment 3, row clamping (n 40 < 2 x 32 x 1) */ { 4096, 20, 16, 8, 16, 1, { 3, 8 }, 2 }, /* KS 8: 4 iterations */ @@ -325,6 +360,66 @@ static void sim_battery(void) { } printf("sim: %" PRIu64 " warp issues in total\n", g_sim_issues); } +/* DRA-79 row_ahead: KS 1 shapes only (the decode down projection). Many rows per warp (the next-row prefetch crosses the row loop + * several times), more than one pass per row (passes before the last re-load the current row), clamped rows past n, more than one + * 128-row scale block, an empty segment, the row-mapped form; mutants 1, 3 (the incumbent's), 5 (wrong next row) and 6 (next row + * at every pass) must be caught, mutant 4 (guard dropped) must run out of steps */ +static void sim_battery_ra(void) { + printf("sim battery, row_ahead 1, x_ahead %u\n", g_xa); + const SimPt pts[] = { + { 512, 200, 16, 4, 16, 1, { 1, 5, 9 }, 3 }, /* 13 rows per warp, up to 3 passes, rows past n clamped, 2 scale blocks */ + { 512, 300, 16, 4, 16, 2, { 3, 2 }, 2 }, /* 2 CTAs: stride 32, 3 scale blocks (2 segments, so the mapped form moves rows) */ + { 512, 40, 16, 8, 16, 2, { 1, 5, 9 }, 3 }, /* mt 8: 2 rows per warp, clamping */ + { 512, 150, 16, 4, 8, 1, { 2, 7 }, 2 }, /* 8 warps */ + { 256, 150, 8, 4, 8, 1, { 2, 7 }, 2 }, /* lane 8: k 256 is one step */ + }; + char msg[300]; size_t bad = 1; int moved = 0, err; + for (size_t i = 0; i < sizeof pts / sizeof pts[0]; i++) { + err = sim_point(&pts[i], 0, 131 + (uint32_t)i, msg, sizeof msg, &bad); + CHECK(!err && bad == 0, "sim row_ahead k %u n %u lane %u mt %u warps %u grid %u: %s", pts[i].k, pts[i].n, pts[i].lb, pts[i].mt, pts[i].w, pts[i].grid, msg); + printf("sim row_ahead k %u n %u lane %u mt %u warps %u grid %u: %s %s\n", pts[i].k, pts[i].n, pts[i].lb, pts[i].mt, pts[i].w, pts[i].grid, err ? "ERROR" : bad ? "MISMATCH" : "ok", msg); + bad = 1; SimPt q = pts[i]; if (q.mt > 4u) q.mt = 4u; /* the mapped form runs at mt <= 4 */ + err = sim_point2(&q, 0, 151 + (uint32_t)i, 1, (int)(i % 3), 0, msg, sizeof msg, &bad, &moved); + CHECK(!err && bad == 0 && moved, "sim row_ahead rowmap k %u n %u mt %u + empty segment at %zu: %s", q.k, q.n, q.mt, i % 3, msg); + printf("sim row_ahead rowmap k %u n %u mt %u warps %u + empty segment at %zu: %s %s\n", q.k, q.n, q.mt, q.w, i % 3, err ? "ERROR" : bad ? "MISMATCH" : "ok", msg); + } + const int ms[] = { 1, 3, 5, 6 }; + for (unsigned j = 0; j < 4; j++) { + bad = 0; err = sim_point(&pts[0], ms[j], 77, msg, sizeof msg, &bad); + CHECK(!err && bad != 0, "sim row_ahead mutant %d must be caught: %s", ms[j], msg); + printf("sim row_ahead mutant %d: %s %s\n", ms[j], err ? "ERROR" : bad ? "caught" : "NOT CAUGHT", msg); + bad = 0; err = sim_point2(&pts[0], ms[j], 78, 1, -1, 0, msg, sizeof msg, &bad, NULL); + CHECK(!err && bad != 0, "sim row_ahead rowmap mutant %d must be caught: %s", ms[j], msg); + printf("sim row_ahead rowmap mutant %d: %s %s\n", ms[j], err ? "ERROR" : bad ? "caught" : "NOT CAUGHT", msg); + } + err = sim_point2(&pts[0], 4, 99, 0, 1, 2000000ull, msg, sizeof msg, &bad, NULL); + CHECK(err != 0 && (strstr(msg, "step budget") || strstr(msg, "outside the declared buffers")), "sim row_ahead mutant 4 (no empty-segment guard) must be caught: %s", msg); + printf("sim row_ahead empty segment, mutant 4 (guard dropped): %s %s\n", err ? "caught" : "NOT CAUGHT", msg); + printf("sim: %" PRIu64 " warp issues in total\n", g_sim_issues); +} +static void sim_battery(void) { + for (g_xa = 0; g_xa <= 1; g_xa++) sim_battery_one(); + for (g_ra = 1, g_xa = 0; g_xa <= 1; g_xa++) sim_battery_ra(); + g_ra = 0; +} +/* DRA-89: the dense stroke calls as the stroke resolves them under this process's environment (AIEN_OMEGA_FP8GEMM_ROWAWARE, + * AIEN_OMEGA_FP8GEMM_X_AHEAD): MIX (n 12288 GDN, 9216 attention; k 2048) and O (n 2048, k 4096), one segment of 1..8 rows, + * mt = omega_gpu_fp8gemm_dense_mt(rows) (0: the incumbent dense 8); every output bit-identical to the emulation. */ +static void sim_dense(void) { + static const uint32_t nk[3][2] = { { 12288, 2048 }, { 9216, 2048 }, { 2048, 4096 } }; + for (unsigned i = 0; i < 3; i++) + for (uint32_t rows = 1; rows <= 8; rows++) { + OmegaFp8GemmSpec s; omega_gpu_fp8gemm_stroke_spec(nk[i][1], 1, omega_gpu_fp8gemm_dense_mt(rows), 0, &s); + const SimPt p = { s.k, nk[i][0], s.lane_bytes, s.mt, s.warps, 2, { rows }, 1 }; + char msg[300]; size_t bad = 1; + g_xa = s.x_ahead; g_ra = s.row_ahead; + int err = sim_point(&p, 0, 500 + 16 * i + rows, msg, sizeof msg, &bad); + CHECK(!err && bad == 0, "sim dense k %u n %u rows %u mt %u x_ahead %u: %s", p.k, p.n, rows, p.mt, g_xa, msg); + printf("sim dense k %u n %u rows %u mt %u warps %u x_ahead %u: %s %s\n", p.k, p.n, rows, p.mt, p.w, g_xa, err ? "ERROR" : bad ? "MISMATCH" : "ok", msg); + } + g_xa = 0; g_ra = 0; + printf("sim dense: %" PRIu64 " warp issues in total\n", g_sim_issues); +} /* ------------------------------------------------------------- chip */ static int g_evict = 1; @@ -353,8 +448,9 @@ static void run_shape(const Shape *S, uint32_t reps, uint32_t seed) { uint32_t *ids = malloc(M * 4), *trow = malloc(M * 4); uint32_t *picks = malloc((size_t)M * 4); make_table(S->tokens, S->topk, S->experts, seed + 7, ids, trow, picks); - uint32_t xrows = S->experts > 1 ? (S->k == 768 ? M : S->tokens) : S->tokens; - if (S->experts > 1 && S->k == 768) for (uint32_t i = 0; i < M; i++) trow[i] = i; /* down: one activation row per routed row */ + const int per_row_x = S->experts > 1 && (S->k == 768 || S->k == 512); /* down: one activation row per routed row (k 768 the 30B's, k 512 the 35B's) */ + uint32_t xrows = S->experts > 1 ? (per_row_x ? M : S->tokens) : S->tokens; + if (per_row_x) for (uint32_t i = 0; i < M; i++) trow[i] = i; float *x = make_x(xrows, S->k, seed + 3); float *y = malloc((size_t)M * S->n * 4), *yref = malloc((size_t)M * S->n * 4), *y2 = malloc((size_t)M * S->n * 4); OmegaGpuFp8GemmInfo info; @@ -387,13 +483,17 @@ static void run_shape(const Shape *S, uint32_t reps, uint32_t seed) { CHECK(rc == 0 && memcmp(y, y2, (size_t)M * S->n * 4) == 0, "%s: second call bit-identical", S->name); printf("second call: %s\n", rc == 0 && memcmp(y, y2, (size_t)M * S->n * 4) == 0 ? "bit-identical" : "DIFFERS"); /* mutants */ - for (int m = 1; m <= 3; m++) { + OmegaFp8GemmSpec rs; omega_gpu_fp8gemm_stroke_spec(S->k, 64, 0, 0, &rs); /* row_ahead (DRA-79) adds mutants 5 and 6 */ + for (int m = 1; m <= (rs.row_ahead ? 6 : 3); m++) { + if (m == 4) continue; /* the empty-segment guard: no empty segment on this path (the simulator catches it) */ omega_gpu_fp8gemm_test_set_mutant(m); rc = omega_gpu_fp8gemm_f32(t, M, ids, trow, x, xrows, y2, NULL); size_t b = 0; if (rc == 0) for (size_t i = 0; i < (size_t)M * S->n; i++) if (memcmp(&y[i], &y2[i], 4) != 0) b++; if (rc != 0) printf("chip mutant %d: call returned %s: %s\n", m, omega_gpu_fp8gemm_rc_name(rc), omega_gpu_fp8gemm_last_error()); int caught = rc == 0 && b != 0; if (m == 2 && info.k / (32u * info.lane_bytes) < 2) caught = 1; /* single-step k: mutant 2 has no effect by construction */ + if (m == 3 && info.mt < 2) caught = 1; /* one row per pass (--mt 1): mutant 3 has no neighbour row */ + if (m == 6 && info.passes_max < 2) caught = 1; /* one pass per row: every pass is the last */ CHECK(caught, "%s: chip mutant %d must be caught", S->name, m); printf("chip mutant %d: %s (%zu of %zu outputs differ)\n", m, caught ? "caught" : "NOT CAUGHT", b, (size_t)M * S->n); if (g_out) fprintf(g_out, "%s{\"point\":\"%s mutant %d\",\"caught\":%d}", g_first ? "" : ",", S->name, m, caught), g_first = 0; @@ -418,7 +518,7 @@ static void run_shape(const Shape *S, uint32_t reps, uint32_t seed) { for (uint32_t tk = 0; tk < S->tokens && ok; tk++) { OmegaGpuFp8Info fi; int r2; if (S->experts == 1) r2 = omega_gpu_fp8_gemv_f32(t, 0, x + (size_t)tk * S->k, yref, &fi); - else if (S->k == 768) r2 = omega_gpu_fp8_gemv_grouped_f32(t, S->topk, picks + (size_t)tk * S->topk, x + (size_t)tk * S->topk * S->k, S->topk, yref, &fi); + else if (per_row_x) r2 = omega_gpu_fp8_gemv_grouped_f32(t, S->topk, picks + (size_t)tk * S->topk, x + (size_t)tk * S->topk * S->k, S->topk, yref, &fi); else r2 = omega_gpu_fp8_gemv_grouped_f32(t, S->topk, picks + (size_t)tk * S->topk, x + (size_t)tk * S->k, 1, yref, &fi); if (r2) ok = 0; else { sum_e += fi.elapsed_ns; sum_c += fi.call_ns; } } @@ -436,11 +536,34 @@ static void run_shape(const Shape *S, uint32_t reps, uint32_t seed) { free(ids); free(trow); free(picks); free(x); free(y); free(yref); free(y2); weights_free(&W); } +/* --spec-of K,SEGS,MT,ROWMAP: the spec the stroke path resolves under this process's environment, printed as one line with + * ctas = the CTA budget per segment it records with (DRA-78); with --expect "f=v ...", every listed field must hold (the + * env-gate checks of the decode levers: default off; the knob checks a chip slice runs before it measures). */ +static int spec_of(const char *arg, const char *expect) { + unsigned k = 0, segs = 0, mt = 0, rowmap = 0; + if (sscanf(arg, "%u,%u,%u,%u", &k, &segs, &mt, &rowmap) != 4) { printf("spec-of: bad argument %s\n", arg); return 2; } + OmegaFp8GemmSpec s; omega_gpu_fp8gemm_stroke_spec(k, segs, mt, (int)rowmap, &s); + char line[256]; + snprintf(line, sizeof line, " k=%u lane_bytes=%u mt=%u warps=%u mutant=%d rowmap=%u x_ahead=%u ctas=%u row_ahead=%u ", s.k, s.lane_bytes, s.mt, s.warps, s.mutant, s.rowmap, s.x_ahead, + omega_gpu_fp8gemm_stroke_cta_budget(k, segs), s.row_ahead); + printf("spec-of %s:%s\n", arg, line); + if (!expect) return 0; + char want[64]; const char *p = expect; int n = 0, bad = 0; + while (sscanf(p, " %62s%n", want + 1, &n) == 1) { + want[0] = ' '; size_t w = strlen(want); want[w] = ' '; want[w + 1] = 0; + g_checks++; if (!strstr(line, want)) { g_failed++; bad = 1; printf("spec-of %s: FAIL expected%s\n", arg, want); } + p += n; + } + return bad; +} + int main(int argc, char **argv) { - int host = 0, sim = 0; const char *out_path = NULL, *shape = "all"; uint32_t reps = 0, mt = 0, warps = 0, ctas = 0, spin = 2000, tokens = 64; + int host = 0, sim = 0, simd = 0; const char *out_path = NULL, *shape = "all", *spec_arg = NULL, *expect = NULL, *dense_arg = NULL; uint32_t reps = 0, mt = 0, warps = 0, ctas = 0, spin = 2000, tokens = 64; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--host-only") == 0) host = 1; else if (strcmp(argv[i], "--sim") == 0) sim = 1; + else if (strcmp(argv[i], "--sim-dense") == 0) simd = 1; + else if (strcmp(argv[i], "--dense-of") == 0 && i + 1 < argc) dense_arg = argv[++i]; else if (strcmp(argv[i], "--out") == 0 && i + 1 < argc) out_path = argv[++i]; else if (strcmp(argv[i], "--shape") == 0 && i + 1 < argc) shape = argv[++i]; else if (strcmp(argv[i], "--reps") == 0 && i + 1 < argc) reps = (uint32_t)atoi(argv[++i]); @@ -450,20 +573,41 @@ int main(int argc, char **argv) { else if (strcmp(argv[i], "--tokens") == 0 && i + 1 < argc) tokens = (uint32_t)atoi(argv[++i]); else if (strcmp(argv[i], "--spin-us") == 0 && i + 1 < argc) spin = (uint32_t)atoi(argv[++i]); else if (strcmp(argv[i], "--no-evict") == 0) g_evict = 0; + else if (strcmp(argv[i], "--spec-of") == 0 && i + 1 < argc) spec_arg = argv[++i]; + else if (strcmp(argv[i], "--expect") == 0 && i + 1 < argc) expect = argv[++i]; else { printf("unknown argument %s\n", argv[i]); return 2; } } - Shape shapes[] = { { "gateup", 128, 1536, 2048, tokens, 8 }, { "down", 128, 2048, 768, tokens, 8 }, { "qkv", 1, 5120, 2048, tokens, 1 }, { "o", 1, 2048, 4096, tokens, 1 }, { "d768", 1, 2048, 768, tokens, 1 } }; + if (dense_arg) { /* --dense-of K,ROWS: the spec a dense stroke call of ROWS rows records with (--spec-of K,1,dense_mt(ROWS),0) */ + unsigned k = 0, rows = 0; static char sa[64]; + if (sscanf(dense_arg, "%u,%u", &k, &rows) != 2) { printf("dense-of: bad argument %s\n", dense_arg); return 2; } + if (mt || warps) omega_gpu_fp8gemm_set_shape(mt, warps); + snprintf(sa, sizeof sa, "%u,1,%u,0", k, omega_gpu_fp8gemm_dense_mt(rows)); + printf("dense-of %s: rows %u -> mt arg %u\n", dense_arg, rows, omega_gpu_fp8gemm_dense_mt(rows)); + spec_arg = sa; + } + if (spec_arg) { + if (mt || warps) omega_gpu_fp8gemm_set_shape(mt, warps); + if (ctas) omega_gpu_fp8gemm_set_cta_budget(ctas); + int rc = spec_of(spec_arg, expect); + if (rc == 2 || !expect) return rc; + printf("gpu_fp8gemm_test: %d checks, %d failed: %s\n", g_checks, g_failed, g_failed ? "FAIL" : "PASS"); + return g_failed ? 1 : 0; + } + Shape shapes[] = { { "gateup", 128, 1536, 2048, tokens, 8 }, { "down", 128, 2048, 768, tokens, 8 }, { "qkv", 1, 5120, 2048, tokens, 1 }, { "o", 1, 2048, 4096, tokens, 1 }, { "d768", 1, 2048, 768, tokens, 1 }, { "mix", 1, 12288, 2048, tokens, 1 }, + { "d512", 128, 2048, 512, tokens, 8 } }; /* d512: the 35B's down projection (k 512: one K step, DRA-79 row_ahead) */ + const unsigned nshapes = sizeof shapes / sizeof shapes[0]; unsigned selected = 0; - for (unsigned i = 0; i < 5; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) selected++; + for (unsigned i = 0; i < nshapes; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) selected++; if (!selected) { fprintf(stderr, "gpu_fp8gemm_test: INVALID shape '%s'\n", shape); return 2; } if (host) host_only(); if (sim) sim_battery(); - if (!host && !sim) { + if (simd) sim_dense(); + if (!host && !sim && !simd) { if (mt || warps) omega_gpu_fp8gemm_set_shape(mt, warps); if (ctas) omega_gpu_fp8gemm_set_cta_budget(ctas); (void)omega_gpu_session_set_spin_us(spin); if (out_path) { g_out = test_out_open(out_path); if (g_out) fprintf(g_out, "{\"receipt\":\"OMEGA_GPU_FP8GEMM_V1\",\"reps\":%u,\"evict\":%d,\"tokens\":%u,\"spin_us\":%u,\"points\":[", reps ? reps : 1, g_evict, tokens, omega_gpu_session_spin_us()); } - for (unsigned i = 0; i < 5; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) run_shape(&shapes[i], reps ? reps : 1, 1000 + i); + for (unsigned i = 0; i < nshapes; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) run_shape(&shapes[i], reps ? reps : 1, 1000 + i); if (g_out) { fprintf(g_out, "],\"checks\":%d,\"failed\":%d,\"verdict\":\"%s\"}\n", g_checks, g_failed, !g_checks ? "NOT_RUN" : g_failed ? "FAIL" : "PASS"); fclose(g_out); } omega_gpu_session_close(); } diff --git a/tests/gpu_gpr_boundary_test.c b/tests/gpu_gpr_boundary_test.c index 21046454..5d671104 100644 --- a/tests/gpu_gpr_boundary_test.c +++ b/tests/gpu_gpr_boundary_test.c @@ -56,11 +56,18 @@ int main(void) { { unsigned ks[] = { 2048, 4096 }; for (unsigned i = 0; i < 2; i++) { OmegaBf16GemvSpec s; memset(&s, 0, sizeof s); s.k = ks[i]; uint32_t c; omega_gpu_bf16_shape_for(s.k, &s.rows, &s.warps, &s.depth, &c); uint32_t peak = 0, decl = 0; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, &peak) == 0, "bf16 k%u builds", ks[i]); (void)omega_gpu_bf16_kernel_fits(&s, &decl); CHECK(omega_bw_gpr_declared_ok(decl, peak), "bf16 gemv k%u: peak %u declared %u", ks[i], peak, decl); } } - /* fp8 grouped GEMM (all shapes we launch) */ - { unsigned ks[] = { 2048, 768, 4096 }, mts[] = { 4, 8 }; for (unsigned i = 0; i < 3; i++) for (unsigned j = 0; j < 2; j++) { - OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, mts[j], 16, 0, 0 }; uint32_t peak = 0, decl = 0; - CHECK(omega_fp8gemm_prog_stats(&s, NULL, &peak) == 0, "gemm k%u mt%u builds", ks[i], mts[j]); (void)omega_gpu_fp8gemm_kernel_fits(&s, &decl); - CHECK(omega_bw_gpr_declared_ok(decl, peak), "gemm k%u mt%u: peak %u declared %u", ks[i], mts[j], peak, decl); } } + /* fp8 grouped GEMM (all shapes we launch, with and without the L312 lever 3 x' prefetch; mt 1 and 2: the DRA-89 row-aware dense stroke) */ + { unsigned ks[] = { 2048, 768, 4096 }, mts[] = { 1, 2, 4, 8 }; for (unsigned xa = 0; xa < 2; xa++) for (unsigned i = 0; i < 3; i++) for (unsigned j = 0; j < 4; j++) { + OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, mts[j], 16, 0, 0, xa, 0 }; uint32_t peak = 0, decl = 0; + if ((s.mt * s.lane_bytes) % s.warps) continue; /* k 768 (lane 8) at mt 1 is no launched shape (spec_ok refuses it) */ + CHECK(omega_fp8gemm_prog_stats(&s, NULL, &peak) == 0, "gemm k%u mt%u x_ahead %u builds", ks[i], mts[j], xa); (void)omega_gpu_fp8gemm_kernel_fits(&s, &decl); + CHECK(omega_bw_gpr_declared_ok(decl, peak), "gemm k%u mt%u x_ahead %u: peak %u declared %u", ks[i], mts[j], xa, peak, decl); } } + /* DRA-79 row_ahead: the decode down projection (k 512, one K step), mapped and plain, with and without x_ahead */ + { unsigned mts[] = { 4, 8 }; for (unsigned xa = 0; xa < 2; xa++) for (unsigned rm = 0; rm < 2; rm++) for (unsigned j = 0; j < 2; j++) { + if (rm && mts[j] > 4) continue; + OmegaFp8GemmSpec s = { 512, 16, mts[j], 16, 0, rm, xa, 1 }; uint32_t peak = 0, decl = 0; + CHECK(omega_fp8gemm_prog_stats(&s, NULL, &peak) == 0, "gemm k512 mt%u rowmap %u x_ahead %u row_ahead builds", mts[j], rm, xa); (void)omega_gpu_fp8gemm_kernel_fits(&s, &decl); + CHECK(omega_bw_gpr_declared_ok(decl, peak), "gemm k512 mt%u rowmap %u x_ahead %u row_ahead: peak %u declared %u", mts[j], rm, xa, peak, decl); } } /* router and decode attention: the launcher uses omega_bw_gpr_declared(peak) (static), so check the helper on the real peak */ { OmegaRouterSpec s = { .warps = OMEGA_GPU_ROUTER_WARPS, .depth = OMEGA_GPU_ROUTER_DEPTH }; uint32_t peak = 0; CHECK(omega_router_prog_stats(&s, NULL, &peak) == 0 && omega_bw_gpr_declared_ok(omega_bw_gpr_declared(peak), peak), "router peak %u", peak); printf("router peak %u -> declared %u\n", peak, omega_bw_gpr_declared(peak)); }