Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/gpu_gpr_boundary_test.c # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / gpu_gpr_boundary_test.c` 86 lines · 7410 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* gpu_gpr_boundary_test: host-only audit of the declared-register rule (OWN-30B, 2026-10-13). 3 * Rule (omega_blackwell_codegen.h): declared = peak + 2 rounded up to a multiple of 8. A fp8 grouped GEMM kernel with 4 * peak 103 declared 104 (the old peak + 1 rule) hung the chip; the same program declared 112 ran. 5 * Checks: the helper for every peak; every launcher's own `declared` for every live kernel spec; the matmul family 6 * (declared by the session from the raw peak) is listed and must not be reachable at a boundary from a Qwen3-30B-A3B shape. */ 7 #include "omega_blackwell_codegen.h" 8 #include "omega_blackwell_codegen_moe.h" 9 #include "omega_blackwell_codegen_bf16.h" 10 #include "omega_blackwell_codegen_router.h" 11 #include "omega_blackwell_codegen_attn.h" 12 #include "omega_blackwell_codegen_gemm.h" 13 #include "omega_gpu_fp8_api.h" 14 #include "omega_gpu_bf16_gemv_api.h" 15 #include "omega_gpu_router_api.h" 16 #include "omega_gpu_decode_attn_api.h" 17 #include "omega_gpu_fp8gemm_api.h" 18 #include 19 #include 20 21 static int g_checks, g_failed; 22 #define CHECK(c, ...) do { g_checks++; if (!(c)) { g_failed++; printf("FAIL: "); printf(__VA_ARGS__); printf("\n"); } } while (0) 23 static BlackwellIRProgram g_prog; 24 25 int main(void) { 26 for (uint32_t peak = 0; peak <= 126; peak++) { 27 uint32_t d = omega_bw_gpr_declared(peak); 28 CHECK(d >= peak + 2 && d % 8 == 0 && d - (peak + 2) < 8 && omega_bw_gpr_declared_ok(d, peak), "helper at peak %u gives %u", peak, d); 29 CHECK(!omega_bw_gpr_declared_ok(((peak + 1u + 7u) / 8u) * 8u, peak) || peak % 8 != 7, "old rule at peak %u must be refused", peak); 30 } 31 CHECK(!omega_bw_gpr_declared_ok(104, 103) && omega_bw_gpr_declared_ok(112, 103), "the 103 / 104 hang case is refused, 112 accepted"); 32 CHECK(!omega_bw_gpr_declared_ok(64, 64) && !omega_bw_gpr_declared_ok(72, 72) && omega_bw_gpr_declared_ok(72, 64), "peak 64 and 72 need 72 and 80 / 72"); 33 34 /* fp8 GEMV: live shapes through the API's own shape / depth rules */ 35 struct { unsigned n, k, groups; } fs[] = { {4096,2048,1},{512,2048,1},{5120,2048,1},{2048,4096,1},{1536,2048,8},{2048,768,8},{1536,2048,1},{2048,768,1},{1u<<20,2048,1},{1u<<20,4096,1},{1u<<20,768,1} }; 36 for (unsigned i = 0; i < sizeof fs / sizeof *fs; i++) { 37 OmegaFp8GemvSpec s; memset(&s, 0, sizeof s); s.k = fs[i].k; 38 omega_gpu_fp8_shape_for(s.k, fs[i].n, &s.lane_bytes, &s.rows, &s.warps); 39 if (fs[i].groups > 1) s.warps = 32; 40 s.depth = omega_gpu_fp8_depth_for(&s, fs[i].n, fs[i].groups); 41 uint32_t peak = 0, decl = 0; 42 CHECK(omega_fp8_gemv_prog_stats(&s, NULL, &peak) == 0, "fp8 gemv %ux%u x%u builds", fs[i].n, fs[i].k, fs[i].groups); 43 (void)omega_gpu_fp8_kernel_fits(&s, &decl); 44 CHECK(omega_bw_gpr_declared_ok(decl, peak), "fp8 gemv %ux%u x%u: peak %u declared %u", fs[i].n, fs[i].k, fs[i].groups, peak, decl); 45 } 46 /* every buildable fp8 GEMV variant */ 47 { unsigned bad = 0, n = 0; 48 for (unsigned k = 256; k <= 8192; k += 256) for (unsigned lb = 8; lb <= 16; lb += 8) for (unsigned rows = 1; rows <= 8; rows *= 2) for (unsigned w = 1; w <= 32; w *= 2) for (unsigned dp = 0; dp <= 8; dp += dp ? dp : 1) { 49 OmegaFp8GemvSpec s = { .k = k, .lane_bytes = lb, .rows = rows, .warps = w, .depth = dp, .mutant = 0 }; uint32_t peak = 0, decl = 0; 50 if (omega_fp8_gemv_prog_stats(&s, NULL, &peak) != 0) continue; 51 n++; (void)omega_gpu_fp8_kernel_fits(&s, &decl); 52 if (!omega_bw_gpr_declared_ok(decl, peak) && decl != 0) bad++; 53 } 54 CHECK(bad == 0, "fp8 gemv sweep: %u of %u variants declared below peak + 2", bad, n); printf("fp8 gemv sweep: %u variants, %u below peak + 2\n", n, bad); } 55 /* bf16 GEMV */ 56 { 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); 57 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); 58 CHECK(omega_bw_gpr_declared_ok(decl, peak), "bf16 gemv k%u: peak %u declared %u", ks[i], peak, decl); } } 59 /* fp8 grouped GEMM (all shapes we launch) */ 60 { unsigned ks[] = { 2048, 768, 4096 }, mts[] = { 4, 8 }; for (unsigned i = 0; i < 3; i++) for (unsigned j = 0; j < 2; j++) { 61 OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, mts[j], 16, 0, 0 }; uint32_t peak = 0, decl = 0; 62 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); 63 CHECK(omega_bw_gpr_declared_ok(decl, peak), "gemm k%u mt%u: peak %u declared %u", ks[i], mts[j], peak, decl); } } 64 /* router and decode attention: the launcher uses omega_bw_gpr_declared(peak) (static), so check the helper on the real peak */ 65 { OmegaRouterSpec s = { .warps = OMEGA_GPU_ROUTER_WARPS, .depth = OMEGA_GPU_ROUTER_DEPTH }; uint32_t peak = 0; 66 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)); } 67 { OmegaDecodeAttnSpec s = { OMEGA_GPU_DATTN_DEPTH, 0 }; uint32_t peak = 0; 68 CHECK(omega_decode_attn_prog_stats(&s, NULL, &peak) == 0 && omega_bw_gpr_declared_ok(omega_bw_gpr_declared(peak), peak), "decode attn peak %u", peak); printf("decode attn peak %u -> declared %u\n", peak, omega_bw_gpr_declared(peak)); } 69 /* matmul / moe-window fragment kernels: declared by the session from the raw peak (max(64, peak rounded up to 8)). 70 * Boundary combinations are reported; the shapes of Qwen3-30B-A3B (n a multiple of 32) never select them. */ 71 { unsigned kps[] = { 768, 2048, 4096 }, nps[] = { 8, 128, 1536, 2048, 4096, 5120, 151936 }; unsigned built = 0, boundary = 0, model_boundary = 0; 72 for (unsigned a = 0; a < 3; a++) for (unsigned b = 0; b < 7; b++) for (unsigned rt = 1; rt <= 4; rt *= 2) for (unsigned ct = 1; ct <= 4; ct *= 2) { 73 OmegaMatMulSpec s; if (omega_matmul_spec_init(&s, 16, kps[a], nps[b], OMEGA_MATMUL_PRECISION_BF16) != 0) continue; 74 unsigned un = (rt > 1 || ct > 1) ? omega_matmul_frag_block_unroll(kps[a], rt, ct) : omega_matmul_frag_unroll(kps[a]); 75 memset(&g_prog, 0, sizeof g_prog); 76 int rc = (rt > 1 || ct > 1) ? omega_blackwell_codegen_matmul_frag_block_prog(&s, 48, un, rt, ct, 0, &g_prog) : omega_blackwell_codegen_matmul_frag_prog(&s, 48, un, 0, &g_prog); 77 if (rc) continue; 78 built++; 79 uint32_t pk = g_prog.regalloc.peak_gpr_usage, decl = pk > 64 ? ((pk + 7) / 8) * 8 : 64; 80 if (decl < pk + 2) { boundary++; unsigned mt = 4, nt = nps[b] / 8; uint32_t r, c; omega_matmul_frag_block_shape(mt, nt, &r, &c); if (r == rt && c == ct) model_boundary++; } 81 } 82 printf("matmul fragment kernels: %u built, %u at a boundary (session declares the raw peak), %u of those selected for a model shape\n", built, boundary, model_boundary); 83 CHECK(model_boundary == 0, "a Qwen3-30B shape reaches a matmul kernel declared below peak + 2"); } 84 printf("gpu_gpr_boundary_test: %d checks, %d failed: %s\n", g_checks, g_failed, g_failed ? "FAIL" : "PASS"); 85 return g_failed ? 1 : 0; 86 }