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 / q38-decode-speed-chip-20261019T0142Z / worktree.diff
| 1 | diff --git a/src/omega_gpu_q38_graph.c b/src/omega_gpu_q38_graph.c |
| 2 | index 399c80d8..3648be4f 100644 |
| 3 | --- a/src/omega_gpu_q38_graph.c |
| 4 | +++ b/src/omega_gpu_q38_graph.c |
| 5 | @@ -9,6 +9,7 @@ |
| 6 | #include "omega_blackwell_codegen_dec.h" |
| 7 | #include "omega_gpu_session.h" |
| 8 | #include "omega_gpu_fmt.h" |
| 9 | +#include <stdlib.h> |
| 10 | #include <string.h> |
| 11 | |
| 12 | #define TIMEOUT_MS 20000ull |
| 13 | @@ -274,6 +275,13 @@ static int rec_res(OmegaGpuQ38Graph *g, int ki, uint64_t x, uint64_t a, uint64_t |
| 14 | return add_glue(g, ki == K_NORM ? OMEGA_GPU_Q38_K_NORM : OMEGA_GPU_Q38_K_RES, ki, 1, 1, H, w, OMEGA_DEC_RES_WORDS); |
| 15 | } |
| 16 | |
| 17 | +static int g_overlap_ab = -1; |
| 18 | +void omega_gpu_q38_graph_set_overlap_ab(int on) { g_overlap_ab = on ? 1 : 0; } |
| 19 | +static int q38_overlap_ab(void) { |
| 20 | + if (g_overlap_ab < 0) { const char *e = getenv("AIEN_OMEGA_Q38_OVERLAP_AB"); g_overlap_ab = (e && e[0] == '0' && e[1] == 0) ? 0 : 1; } |
| 21 | + return g_overlap_ab; |
| 22 | +} |
| 23 | + |
| 24 | static int rec_fp8(OmegaGpuQ38Graph *g, uint8_t kind, const OmegaGpuFp8Tensor *t, uint64_t tab, uint64_t x, uint64_t y) { |
| 25 | return after_op(g, kind, omega_gpu_fp8_gemv_grouped_record(g->cl, t, 1, tab, x, 1, y)); |
| 26 | } |
| 27 | @@ -305,11 +313,20 @@ int omega_gpu_q38_graph_record_layer(OmegaGpuQ38Graph *g, uint32_t l, uint32_t p |
| 28 | const uint32_t ki = g->layer[l].kind_index; |
| 29 | int rc = OMEGA_GPU_DGRAPH_OK; |
| 30 | if (g->xq_layer != (int)l) rc = rec_res(g, K_NORM, x, 0, in_norm, xq, SCALE_2P64); |
| 31 | - if (rc == OMEGA_GPU_DGRAPH_OK) rc = rec_fp8(g, OMEGA_GPU_Q38_K_MIX, g->layer[l].mix, tab, xq, mix); |
| 32 | + /* GDN layers: the a|b GEMV (latency-bound, ~18 us) is recorded first and the mix GEMV marked independent of it: both only |
| 33 | + * read xq and write their own buffers, so the two grids overlap; the GDN step after them waits for both (normal barrier). |
| 34 | + * AIEN_OMEGA_Q38_OVERLAP_AB=0 or set_overlap_ab(0): the old order, mix then a|b, each behind a barrier. */ |
| 35 | + const int overlap = !g->layer[l].attn && q38_overlap_ab(); |
| 36 | + if (overlap && rc == OMEGA_GPU_DGRAPH_OK) rc = after_op(g, OMEGA_GPU_Q38_K_AB, omega_gpu_bf16_gemv_record(g->cl, g->layer[l].ab, xq, va_of(g, g->lo.ab))); |
| 37 | + if (rc == OMEGA_GPU_DGRAPH_OK) { |
| 38 | + int mrc = omega_gpu_fp8_gemv_grouped_record(g->cl, g->layer[l].mix, 1, tab, xq, 1, mix); |
| 39 | + if (mrc == 0 && overlap && !g->flush_each && omega_gpu_cmdlist_mark_independent(g->cl) != 0) mrc = -1; |
| 40 | + rc = after_op(g, OMEGA_GPU_Q38_K_MIX, mrc); |
| 41 | + } |
| 42 | uint64_t mixer_out = att; |
| 43 | if (!g->layer[l].attn) { |
| 44 | const uint64_t ab = va_of(g, g->lo.ab); |
| 45 | - if (rc == OMEGA_GPU_DGRAPH_OK) rc = after_op(g, OMEGA_GPU_Q38_K_AB, omega_gpu_bf16_gemv_record(g->cl, g->layer[l].ab, xq, ab)); |
| 46 | + if (!overlap && rc == OMEGA_GPU_DGRAPH_OK) rc = after_op(g, OMEGA_GPU_Q38_K_AB, omega_gpu_bf16_gemv_record(g->cl, g->layer[l].ab, xq, ab)); |
| 47 | if (rc == OMEGA_GPU_DGRAPH_OK) |
| 48 | rc = after_op(g, OMEGA_GPU_Q38_K_GDN, omega_gpu_gdn_record(g->cl, g->cfg.gdn, ki, mix, mix + OMEGA_GPU_Q38_GDN_QKV * 4u, ab, |
| 49 | g->cfg.eps_l2, g->cfg.eps, 1.0f, SCALE_2P64, &mixer_out)); |
| 50 | diff --git a/src/omega_gpu_q38_graph.h b/src/omega_gpu_q38_graph.h |
| 51 | index b32c2670..263b1a3a 100644 |
| 52 | --- a/src/omega_gpu_q38_graph.h |
| 53 | +++ b/src/omega_gpu_q38_graph.h |
| 54 | @@ -90,6 +90,9 @@ int omega_gpu_q38_graph_set_final_norm(OmegaGpuQ38Graph *g, const float *final_n |
| 55 | * omega_gpu_q38_graph_read returns the unscaled hidden (exact power-of-two rescale). Logits are those of the quantised head: |
| 56 | * callers own the drift study against the bf16 head. */ |
| 57 | int omega_gpu_q38_graph_set_lm_head_fp8(OmegaGpuQ38Graph *g, const OmegaGpuFp8Tensor *head); |
| 58 | +/* GDN layers record the a|b GEMV first and the mix GEMV beside it (no barrier between the two; both only read xq), process-wide. |
| 59 | + * 1 (default) or 0 (mix then a|b, each behind a barrier); env AIEN_OMEGA_Q38_OVERLAP_AB when never set. Values are identical. */ |
| 60 | +void omega_gpu_q38_graph_set_overlap_ab(int on); |
| 61 | /* One whole token: x_embed (f32 [5120]) -> greedy token; pos: the token's position (attention layers append K/V there, |
| 62 | * GDN layers advance their state). */ |
| 63 | int omega_gpu_q38_graph_token(OmegaGpuQ38Graph *g, const float *x_embed, uint32_t pos, uint32_t *token, OmegaGpuDecodeGraphStats *st); |