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
omega-mv / evidence / DECODE-LAUNCH-COLLAPSE-20261013 / graph-r5-cached / worktree.diff
| 1 | diff --git a/Makefile b/Makefile |
| 2 | index b7b853c3..c0c41699 100644 |
| 3 | --- a/Makefile |
| 4 | +++ b/Makefile |
| 5 | @@ -36,6 +36,7 @@ SRCS += src/omega_gpu_hostmath.c |
| 6 | SRCS += src/omega_blackwell_codegen_router.c src/omega_gpu_router_api.c |
| 7 | # OWN-30B W-L2 (2026-10-13): decode launch collapse, new files only: command list (N launches, one submit) + glue kernels |
| 8 | SRCS += src/omega_gpu_cmdlist.c src/omega_blackwell_codegen_dec.c |
| 9 | +SRCS += src/omega_gpu_mem_cached.c |
| 10 | SRCS += src/omega_gpu_decode_graph.c |
| 11 | # OWN-30B (2026-10-13): bf16 streaming GEMV for the lm_head (omega_gpu_bf16_gemv_api.h), new files only |
| 12 | SRCS += src/omega_blackwell_codegen_bf16.c src/omega_gpu_bf16_gemv_api.c |
| 13 | diff --git a/src/omega_gpu_fp8_api.c b/src/omega_gpu_fp8_api.c |
| 14 | index 934cc583..501ad1b6 100644 |
| 15 | --- a/src/omega_gpu_fp8_api.c |
| 16 | +++ b/src/omega_gpu_fp8_api.c |
| 17 | @@ -4,6 +4,7 @@ |
| 18 | * coherent with direct CPU mappings"), one launch = omega_gpu_session_launch (shader-cache |
| 19 | * invalidate, constant bank, QMD0/QMD1, marker, L2_FLUSH_DIRTY, second marker on uncached memory). */ |
| 20 | #include "omega_gpu_fp8_api.h" |
| 21 | +#include "omega_gpu_mem_cached.h" |
| 22 | #include "omega_blackwell_codegen_moe.h" |
| 23 | #include "omega_gpu_session.h" |
| 24 | #include "omega_gpu_fmt.h" |
| 25 | @@ -35,6 +36,7 @@ static struct { |
| 26 | int depth_set; uint32_t depth; /* depth override (depth_set: 0 = automatic) */ |
| 27 | uint32_t gpr_pad; /* registers declared beyond the kernel's peak (diagnosis knob) */ |
| 28 | int mutant, no_fold, sealed; |
| 29 | + int weights_cached; /* omega_gpu_fp8_set_weight_cache: uploads after it allocate GPU-cached (read-only weights) */ |
| 30 | bool hooked; |
| 31 | Slot cache[CACHE_SLOTS]; |
| 32 | unsigned next; |
| 33 | @@ -224,7 +226,8 @@ int omega_gpu_fp8_tensor_upload(uint32_t experts, uint32_t n, uint32_t k, const |
| 34 | t->experts = experts; t->n = n; t->k = k; |
| 35 | int rc = OMEGA_GPU_FP8_OK; |
| 36 | omega_gpu_session_lock(); |
| 37 | - if (!dev_open_locked() || omega_gpu_session_alloc(wbytes, &t->w) != 0 || omega_gpu_session_alloc(scount * 4u, &t->s) != 0) rc = OMEGA_GPU_FP8_CHIP_FAIL; |
| 38 | + int (*const alloc)(size_t, OmegaGpuMem *) = g.weights_cached ? omega_gpu_session_alloc_cached : omega_gpu_session_alloc; |
| 39 | + if (!dev_open_locked() || alloc(wbytes, &t->w) != 0 || alloc(scount * 4u, &t->s) != 0) rc = OMEGA_GPU_FP8_CHIP_FAIL; |
| 40 | omega_gpu_session_unlock(); |
| 41 | if (rc == OMEGA_GPU_FP8_OK) { |
| 42 | memcpy(t->w.cpu, w, wbytes); |
| 43 | @@ -367,3 +370,7 @@ int omega_gpu_fp8_gemv_grouped_record(OmegaGpuCmdList *cl, const OmegaGpuFp8Tens |
| 44 | if (!cl) return OMEGA_GPU_FP8_BAD_ARGS; |
| 45 | return gemv_core(t, groups, NULL, NULL, NULL, x_rows, NULL, NULL, tab_va, x_va, cl, y_va); |
| 46 | } |
| 47 | + |
| 48 | +/* ---- weight cache policy (OWN-30B L2 kernel-time cut) ---- */ |
| 49 | +void omega_gpu_fp8_set_weight_cache(int on) { omega_gpu_session_lock(); g.weights_cached = on ? 1 : 0; omega_gpu_session_unlock(); } |
| 50 | +int omega_gpu_fp8_weight_cache(void) { return g.weights_cached; } |
| 51 | diff --git a/src/omega_gpu_fp8_api.h b/src/omega_gpu_fp8_api.h |
| 52 | index 7e43cc3e..43e97650 100644 |
| 53 | --- a/src/omega_gpu_fp8_api.h |
| 54 | +++ b/src/omega_gpu_fp8_api.h |
| 55 | @@ -135,6 +135,10 @@ uint32_t omega_gpu_fp8_depth_for(const OmegaFp8GemvSpec *spec, uint32_t n, uint3 |
| 56 | int omega_gpu_fp8_kernel_fits(const OmegaFp8GemvSpec *spec, uint32_t *declared); |
| 57 | /* CTAs per group per launch (0 restores the automatic choice: MAX_CTAS single, GROUPED_CTAS grouped). */ |
| 58 | void omega_gpu_fp8_set_cta_budget(uint32_t ctas); |
| 59 | +/* 1: tensors uploaded from now on live in GPU-cached memory (read-only weights; omega_gpu_mem_cached.h). Default 0: |
| 60 | + * GPU-uncached like every session buffer. Tensors already uploaded keep their policy. */ |
| 61 | +void omega_gpu_fp8_set_weight_cache(int on); |
| 62 | +int omega_gpu_fp8_weight_cache(void); |
| 63 | /* Diagnosis: declare `pad` registers beyond the kernel's peak in the QMD (0 = exact peak). */ |
| 64 | void omega_gpu_fp8_set_gpr_pad(uint32_t pad); |
| 65 | /* TEST ONLY: deliberately wrong kernels (1 scale dropped, 2 scale block never advances, 3 group table entry |
| 66 | diff --git a/src/omega_gpu_platform_linux.c b/src/omega_gpu_platform_linux.c |
| 67 | index 0aaae738..12736760 100644 |
| 68 | --- a/src/omega_gpu_platform_linux.c |
| 69 | +++ b/src/omega_gpu_platform_linux.c |
| 70 | @@ -177,14 +177,22 @@ static int ref_dma_alloc(void *ctx, OmegaGpuDeviceHandle dev, const OmegaGpuBuff |
| 71 | ref_lock(r); |
| 72 | int rc = dev_ok(r, dev); |
| 73 | if (rc == OMEGA_GPU_PLAT_OK) rc = omega_gpu_platform_check_buffer(desc, &g_caps); |
| 74 | - /* everything here is GPU-uncached; a cached buffer would need flushes nobody issues */ |
| 75 | - if (rc == OMEGA_GPU_PLAT_OK && desc->gpu_cache != OMEGA_GPU_CACHE_GPU_UNCACHED) rc = OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY; |
| 76 | + /* GPU-uncached by default. GPU-cached only for DEVICE-PRIVATE data buffers (OWN-30B T3b, 2026-10-13): no CPU_READ, no |
| 77 | + * HOST_POLLED, so the CPU never reads a line the GPU may still hold in L2 (nvos.h:1116 "For system memory this will not be |
| 78 | + * coherent with direct CPU mappings"). omega_gpu_mem_cached.c (OWN-30B L2) writes such a buffer from the CPU exactly once, |
| 79 | + * before any GPU read, then syncs; omega_gpu_devmem.h (T3b) fills them with GPU writes only. Either way no stale L2 line exists. */ |
| 80 | + /* (original T3b note:) nvos.h:1116 "For system memory this will not be |
| 81 | + * coherent with direct CPU mappings"); omega_gpu_devmem.h fills them with GPU writes only, so no stale L2 line exists. */ |
| 82 | + const int cached = desc->gpu_cache == OMEGA_GPU_CACHE_GPU_CACHED; |
| 83 | + if (rc == OMEGA_GPU_PLAT_OK && cached && |
| 84 | + (desc->kind != OMEGA_GPU_HANDLE_BUF_DATA || (desc->rights & (OMEGA_GPU_RIGHT_CPU_READ | OMEGA_GPU_RIGHT_HOST_POLLED)))) |
| 85 | + rc = OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY; |
| 86 | if (rc != OMEGA_GPU_PLAT_OK) { rc = refuse(r, rc, "dma_alloc"); ref_unlock(r); return rc; } |
| 87 | uint32_t idx = 0, gen = 0; |
| 88 | rc = omega_gpu_handles_open(&r->t, desc->kind, desc->bytes, LINUX_REF_BUFFERS, g_caps.max_total_bytes, &idx, &gen); |
| 89 | if (rc != OMEGA_GPU_PLAT_OK) { rc = refuse(r, rc, "dma_alloc"); ref_unlock(r); return rc; } |
| 90 | NvrmMem m; |
| 91 | - if (nvrm_alloc_gpu_uncached(&r->m16.rm, desc->bytes, &m) != 0) { |
| 92 | + if ((cached ? nvrm_alloc(&r->m16.rm, desc->bytes, &m) : nvrm_alloc_gpu_uncached(&r->m16.rm, desc->bytes, &m)) != 0) { |
| 93 | (void)omega_gpu_handles_close(&r->t, idx, gen, desc->kind); /* this slot never got memory: its generation moves on */ |
| 94 | rc = refuse(r, OMEGA_GPU_PLAT_REFUSED_DEVICE, "nvrm_alloc_gpu_uncached"); |
| 95 | ref_unlock(r); |
| 96 | diff --git a/tests/gpu_decode_graph_test.c b/tests/gpu_decode_graph_test.c |
| 97 | index 620c8bae..7abf27fd 100644 |
| 98 | --- a/tests/gpu_decode_graph_test.c |
| 99 | +++ b/tests/gpu_decode_graph_test.c |
| 100 | @@ -199,9 +199,10 @@ static int host_only(void) { |
| 101 | return g_failed ? 1 : 0; |
| 102 | } |
| 103 | |
| 104 | -static int chip_run(uint32_t layers, uint32_t vocab, uint32_t reps, int red, const char *out_path) { |
| 105 | +static int chip_run(uint32_t layers, uint32_t vocab, uint32_t reps, int red, int cached, const char *out_path) { |
| 106 | FILE *out = out_path ? fopen(out_path, "w") : NULL; |
| 107 | - if (out) fprintf(out, "{\"layers\":%u,\"vocab\":%u,\"pos\":%u,\"reps\":%u,\"red\":%d,", layers, vocab, POS, reps, red); |
| 108 | + if (out) fprintf(out, "{\"layers\":%u,\"vocab\":%u,\"pos\":%u,\"reps\":%u,\"red\":%d,\"cached_weights\":%d,", layers, vocab, POS, reps, red, cached); |
| 109 | + omega_gpu_fp8_set_weight_cache(cached); /* one variable: the FP8 tensors uploaded below live GPU-cached or not */ |
| 110 | Model m; |
| 111 | uint64_t t0 = omega_gpu_session_now_ns(); |
| 112 | if (model_build(&m, layers, vocab) != 0) { CHECK(0, "synthetic model build"); return 1; } |
| 113 | @@ -283,6 +284,8 @@ static int chip_run(uint32_t layers, uint32_t vocab, uint32_t reps, int red, con |
| 114 | int prc = run_graph(gr, &m, &C, &st); |
| 115 | CHECK(prc == 0 && C.tok == C0.tok && !memcmp(C.logits, C0.logits, (size_t)vocab * 4), "C after the mutants bit-identical to the first C"); |
| 116 | |
| 117 | + if (out) { uint64_t h = 1469598103934665603ull; const unsigned char *b = (const unsigned char *)C0.logits; for (size_t i = 0; i < (size_t)vocab * 4; i++) { h ^= b[i]; h *= 1099511628211ull; } |
| 118 | + fprintf(out, "\"C0_token\":%u,\"C0_logits_fnv\":\"%016" PRIx64 "\",", C0.tok, h); } |
| 119 | /* timeline instrument: stamps on -> one timestamp per launch, monotonic, span within the chip time; token unchanged; off -> refuses */ |
| 120 | { |
| 121 | static uint64_t sts[OMEGA_GPU_CMDLIST_MAX_LAUNCHES + 1]; static uint8_t kinds[OMEGA_GPU_CMDLIST_MAX_LAUNCHES]; |
| 122 | @@ -319,10 +322,11 @@ static int chip_run(uint32_t layers, uint32_t vocab, uint32_t reps, int red, con |
| 123 | } |
| 124 | |
| 125 | int main(int argc, char **argv) { |
| 126 | - int host = 0, red = 0; uint32_t reps = 20, layers = 2, vocab = 151936; const char *out = NULL; |
| 127 | + int host = 0, red = 0, cached = 0; uint32_t reps = 20, layers = 2, vocab = 151936; const char *out = NULL; |
| 128 | for (int i = 1; i < argc; i++) { |
| 129 | if (strcmp(argv[i], "--host-only") == 0) host = 1; |
| 130 | else if (strcmp(argv[i], "--red") == 0) red = 1; |
| 131 | + else if (strcmp(argv[i], "--cached-weights") == 0) cached = 1; |
| 132 | else if (strcmp(argv[i], "--reps") == 0 && i + 1 < argc) reps = (uint32_t)atoi(argv[++i]); |
| 133 | else if (strcmp(argv[i], "--layers") == 0 && i + 1 < argc) layers = (uint32_t)atoi(argv[++i]); |
| 134 | else if (strcmp(argv[i], "--vocab") == 0 && i + 1 < argc) vocab = (uint32_t)atoi(argv[++i]); |
| 135 | @@ -331,7 +335,7 @@ int main(int argc, char **argv) { |
| 136 | } |
| 137 | if (reps == 0) reps = 1; |
| 138 | if (layers == 0 || layers > 8) layers = 2; |
| 139 | - int rc = host ? host_only() : chip_run(layers, vocab, reps, red, out); |
| 140 | + int rc = host ? host_only() : chip_run(layers, vocab, reps, red, cached, out); |
| 141 | printf("%s: %d checks, %d failed: %s\n", host ? "host-only" : red ? "chip-red" : "chip", g_checks, g_failed, rc ? "FAIL" : "PASS"); |
| 142 | return rc; |
| 143 | } |
| 144 | diff --git a/tools/run_gpu_decode_graph_chip.sh b/tools/run_gpu_decode_graph_chip.sh |
| 145 | index 0fd229cf..6b7955bf 100755 |
| 146 | --- a/tools/run_gpu_decode_graph_chip.sh |
| 147 | +++ b/tools/run_gpu_decode_graph_chip.sh |
| 148 | @@ -1,5 +1,6 @@ |
| 149 | #!/bin/bash |
| 150 | -# run_gpu_decode_graph_chip.sh EVIDENCE_DIR [red] [PHYSICS_DIR] |
| 151 | +# run_gpu_decode_graph_chip.sh EVIDENCE_DIR [main|red|cached] [PHYSICS_DIR] |
| 152 | +# cached: main with --cached-weights (FP8 tensors in GPU-cached memory); verdict "GPU_DECODE_GRAPH_CHIP_CACHED: PASS|FAIL" |
| 153 | # OWN-30B W-L2a chip gate for omega_gpu_decode_graph (one Qwen3-30B-A3B decode token as one command list). |
| 154 | # Caller holds the GB10 lock: flock /tmp/aien-gb10.lock tools/run_gpu_decode_graph_chip.sh EVID |
| 155 | # 0. host proofs first (never hardware results): --host-only |
| 156 | @@ -23,6 +24,12 @@ T=./build/gpu_decode_graph_test |
| 157 | sha256sum "$T" build/libomega_gpu.a > "$EVID/binaries.sha256" |
| 158 | fail=0 |
| 159 | $T --host-only 2>&1 | tee "$EVID/host-only.log"; [ "${PIPESTATUS[0]}" = 0 ] || fail=1 |
| 160 | +if [ "$MODE" = cached ]; then |
| 161 | + $T --cached-weights --reps "${REPS:-20}" --out "$EVID/receipt-cached.json" 2>&1 | tee "$EVID/cached.log"; rc=${PIPESTATUS[0]} |
| 162 | + echo "end $(date -u +%FT%TZ) cached_exit=$rc" >> "$EVID/device.txt" |
| 163 | + (cd "$EVID" && sha256sum *.json *.log *.txt *.diff *.sha256 > SHA256SUMS) |
| 164 | + if [ "$rc" = 0 ] && [ $fail = 0 ]; then echo "GPU_DECODE_GRAPH_CHIP_CACHED: PASS"; exit 0; else echo "GPU_DECODE_GRAPH_CHIP_CACHED: FAIL"; exit 1; fi |
| 165 | +fi |
| 166 | if [ "$MODE" = red ]; then |
| 167 | $T --red --reps "${REPS:-3}" --out "$EVID/receipt-red.json" 2>&1 | tee "$EVID/red.log"; rc=${PIPESTATUS[0]} |
| 168 | echo "end $(date -u +%FT%TZ) red_exit=$rc" >> "$EVID/device.txt" |