Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/test_omega_gpu_q38_graph_host.c # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / test_omega_gpu_q38_graph_host.c` 136 lines ยท 7349 bytes Raw Blame History 1 /* 2 * test_omega_gpu_q38_graph_host: host-only (no GPU opened) ABI, validation, permutation, and Blackwell codegen proof 3 * for the Qwen3.8-27B multi-head stroke, batched dense FP8 GEMM, and exact two-pass head extensions in omega_gpu_q38_graph. 4 * Verdict line last: "test_omega_gpu_q38_graph_host: N checks, F failed: PASS|FAIL". 5 */ 6 #include "omega_gpu_q38_graph.h" 7 #include "omega_blackwell_codegen_dec.h" 8 #include "omega_blackwell_codegen_gemm.h" 9 #include "omega_gpu_fp8gemm_api.h" 10 #include "omega_gpu_bf16_gemv_api.h" 11 #include 12 #include 13 #include 14 15 static unsigned g_checks, g_failed; 16 #define CHECK(cond, ...) do { g_checks++; if (!(cond)) { g_failed++; printf("FAIL: "); printf(__VA_ARGS__); printf("\n"); } } while (0) 17 18 static void check_perm_width(uint32_t k) { 19 uint32_t *tab = calloc(k, sizeof *tab); 20 float *src = calloc(k, sizeof *src), *ref = calloc(k, sizeof *ref); 21 CHECK(tab && src && ref, "alloc perm width %u", k); 22 if (!tab || !src || !ref) { free(tab); free(src); free(ref); return; } 23 omega_q38_perm_table(tab, k); 24 for (uint32_t i = 0; i < k; i++) src[i] = (float)(i + 1u) * 0.25f; 25 const uint32_t lb = (k % 512u == 0) ? 16u : 8u; 26 omega_fp8gemm_permute_x(src, k, lb, ref); 27 size_t bad = 0; 28 for (uint32_t i = 0; i < k; i++) { 29 if (tab[i] >= k) { bad++; continue; } 30 const float got = src[tab[i]] * 0x1p64f; 31 if (memcmp(&got, &ref[i], 4) != 0) bad++; 32 } 33 CHECK(bad == 0, "omega_q38_perm_table matches omega_fp8gemm_permute_x at k=%u (bad=%zu)", k, bad); 34 free(tab); free(src); free(ref); 35 } 36 37 static void check_dec_codegen(const char *label, const OmegaDecSpec *sp, int expect_ok) { 38 BlackwellIRProgram *p = calloc(1, sizeof *p); 39 CHECK(p != NULL, "alloc IR program for %s", label); 40 if (!p) return; 41 int rc = omega_blackwell_codegen_dec_prog(sp, p); 42 size_t bytes = rc == 0 ? omega_bw_program_code_bytes(p) : 0; 43 if (expect_ok) { 44 CHECK(rc == 0 && bytes > 0, "%s codegen ok (rc=%d, bytes=%zu)", label, rc, bytes); 45 CHECK(omega_bw_gpr_declared(p->regalloc.peak_gpr_usage) <= 128u, "%s GPRs fit (%u peak)", label, p->regalloc.peak_gpr_usage); 46 } else { 47 CHECK(rc != 0, "%s codegen refused invalid spec", label); 48 } 49 free(p); 50 } 51 52 static void check_fp8gemm_27b(uint32_t k) { 53 OmegaFp8GemmSpec sp; memset(&sp, 0, sizeof sp); 54 sp.k = k; 55 omega_gpu_fp8gemm_shape_for(k, &sp.mt, &sp.warps, &sp.lane_bytes); 56 uint32_t decl = 0; 57 int fits = omega_gpu_fp8gemm_kernel_fits(&sp, &decl); 58 CHECK(fits == OMEGA_GPU_FP8GEMM_OK, "fp8gemm k=%u (mt=%u w=%u lb=%u decl=%u) fits register file (rc=%d)", k, sp.mt, sp.warps, sp.lane_bytes, decl, fits); 59 BlackwellIRProgram *p = calloc(1, sizeof *p); 60 if (p) { 61 int rc = omega_blackwell_codegen_fp8gemm_prog(&sp, p); 62 size_t bytes = rc == 0 ? omega_bw_program_code_bytes(p) : 0; 63 CHECK(rc == 0 && bytes > 0, "fp8gemm k=%u codegen ok (rc=%d, bytes=%zu)", k, rc, bytes); 64 free(p); 65 } 66 } 67 68 int main(void) { 69 /* 1. Exact head admission reserve */ 70 const uint64_t extra = omega_gpu_q38_exact_extra_bytes(); 71 CHECK(extra > (1ull << 30), "exact_extra_bytes > 1 GiB (got %llu)", (unsigned long long)extra); 72 73 /* 2. Host-only BAD_ARGS guards (never touch the GPU) */ 74 OmegaGpuQ38Graph *g = (OmegaGpuQ38Graph *)0x1; 75 OmegaGpuQ38GraphConfig cfg; memset(&cfg, 0, sizeof cfg); 76 CHECK(omega_gpu_q38_graph_create_heads(&cfg, 0, &g) == OMEGA_GPU_DGRAPH_BAD_ARGS && !g, "create_heads refuses heads=0"); 77 CHECK(omega_gpu_q38_graph_create_heads(&cfg, OMEGA_GPU_Q38_MAX_HEADS + 1u, &g) == OMEGA_GPU_DGRAPH_BAD_ARGS && !g, "create_heads refuses heads>MAX"); 78 CHECK(omega_gpu_q38_graph_create_heads(NULL, 2, &g) == OMEGA_GPU_DGRAPH_BAD_ARGS && !g, "create_heads refuses NULL cfg"); 79 CHECK(omega_gpu_q38_graph_set_head_state(NULL, 0, NULL, NULL) == OMEGA_GPU_DGRAPH_BAD_ARGS, "set_head_state refuses NULL"); 80 CHECK(omega_gpu_q38_graph_begin_stroke(NULL, NULL, 1) == OMEGA_GPU_DGRAPH_BAD_ARGS, "begin_stroke refuses NULL"); 81 CHECK(omega_gpu_q38_graph_record_head_layer(NULL, 0, 0, 0) == OMEGA_GPU_DGRAPH_BAD_ARGS, "record_head_layer refuses NULL"); 82 CHECK(omega_gpu_q38_graph_record_head_final(NULL, 0) == OMEGA_GPU_DGRAPH_BAD_ARGS, "record_head_final refuses NULL"); 83 CHECK(omega_gpu_q38_graph_end_stroke(NULL, NULL, NULL) == OMEGA_GPU_DGRAPH_BAD_ARGS, "end_stroke refuses NULL"); 84 CHECK(omega_gpu_q38_graph_stroke(NULL, NULL, NULL, 1, NULL, NULL) == OMEGA_GPU_DGRAPH_BAD_ARGS, "stroke refuses NULL"); 85 CHECK(omega_gpu_q38_graph_read_head(NULL, 0, NULL, NULL, NULL) == OMEGA_GPU_DGRAPH_BAD_ARGS, "read_head refuses NULL"); 86 CHECK(omega_gpu_q38_graph_set_batch(NULL, 1) == OMEGA_GPU_DGRAPH_BAD_ARGS, "set_batch refuses NULL"); 87 CHECK(omega_gpu_q38_graph_batch(NULL) == 0, "batch(NULL) == 0"); 88 CHECK(omega_gpu_q38_graph_record_layer_heads(NULL, 0, NULL) == OMEGA_GPU_DGRAPH_BAD_ARGS, "record_layer_heads refuses NULL"); 89 CHECK(omega_gpu_q38_graph_set_exact_head(NULL, NULL, NULL, 0) == OMEGA_GPU_DGRAPH_BAD_ARGS, "set_exact_head refuses NULL"); 90 CHECK(omega_gpu_q38_graph_exact_head_active(NULL) == 0, "exact_head_active(NULL) == 0"); 91 CHECK(omega_gpu_q38_graph_exact_head_active_head(NULL, 0) == 0, "exact_head_active_head(NULL, 0) == 0"); 92 omega_gpu_q38_graph_set_exact_head_on(NULL, 1); 93 omega_gpu_q38_graph_set_head_exact_head_on(NULL, 0, 1); 94 CHECK(strcmp(omega_gpu_q38_graph_kind_name(OMEGA_GPU_Q38_K_PERM), "perm") == 0, "kind_name(K_PERM) == perm"); 95 96 /* 3. Permutation tables for 27B (H=5120, mout=6144, I=17408), 9B (4096, 12288), and lb=8 (256) */ 97 check_perm_width(5120u); 98 check_perm_width(6144u); 99 check_perm_width(17408u); 100 check_perm_width(4096u); 101 check_perm_width(256u); 102 103 /* 4. 27B glue kernel codegen (NORM|ROWS, ADD|NORM|ROWS, XBOUND H=5120, XBOUND invalid width) */ 104 { 105 OmegaDecSpec s; memset(&s, 0, sizeof s); 106 s.kind = OMEGA_DEC_RES; s.mode = OMEGA_DEC_RES_NORM | OMEGA_DEC_RES_ROWS; s.width = 5120u; 107 check_dec_codegen("RES NORM|ROWS H=5120", &s, 1); 108 s.mode = OMEGA_DEC_RES_ADD | OMEGA_DEC_RES_NORM | OMEGA_DEC_RES_ROWS; 109 check_dec_codegen("RES ADD|NORM|ROWS H=5120", &s, 1); 110 memset(&s, 0, sizeof s); 111 s.kind = OMEGA_DEC_XBOUND; s.width = 5120u; 112 check_dec_codegen("XBOUND H=5120", &s, 1); 113 s.width = 4096u; 114 check_dec_codegen("XBOUND H=4096", &s, 1); 115 s.width = 1536u; 116 check_dec_codegen("XBOUND invalid H=1536", &s, 0); 117 } 118 119 /* 5. 27B batched FP8 GEMM codegen (mix/gate_up K=5120, o K=6144, down K=17408) */ 120 check_fp8gemm_27b(5120u); 121 check_fp8gemm_27b(6144u); 122 check_fp8gemm_27b(17408u); 123 124 /* 6. 27B exact-head bf16 MASK kernel register-file check at K=5120 */ 125 { 126 OmegaBf16GemvSpec sp; memset(&sp, 0, sizeof sp); 127 uint32_t ctas = 0, decl = 0; 128 sp.k = 5120u; sp.mask = 1u; 129 omega_gpu_bf16_shape_for(5120u, &sp.rows, &sp.warps, &sp.depth, &ctas); 130 int fits = omega_gpu_bf16_kernel_fits(&sp, &decl); 131 CHECK(fits == OMEGA_GPU_BF16_OK, "bf16 MASK k=5120 fits register file (decl=%u, rc=%d)", decl, fits); 132 } 133 134 printf("test_omega_gpu_q38_graph_host: %u checks, %u failed: %s\n", g_checks, g_failed, g_failed ? "FAIL" : "PASS"); 135 return g_failed ? 1 : 0; 136 }