diff --git a/.crumb b/.crumb index ae1b60858..fffb274db 100644 --- a/.crumb +++ b/.crumb @@ -87,14 +87,14 @@ "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "f6799f3fc7c7ad7be6bd1612c0d129e729e809dbd92daad7acfe5df02d95920c", - "last_commit": "400d6b0", + "digest": "fc811240fb8c5840adf9f00fcae85a1a8cf4832232e0b01af273dce5bfdd94de", + "last_commit": "8fa3768", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "4a13eb3a1f0aeaf6da2f1a4e4d6faee018304dc7db3a270950fc1809e123e1bc", - "last_commit": "400d6b0", + "digest": "0dc1710b156c18dc1ad2ec7c311476c66184878ab9dd9dd250c879748cd0c5b4", + "last_commit": "8fa3768", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, @@ -105,15 +105,15 @@ "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:7fbdc01ee1802c13ee21e4568b8ab66ae3f5fad7b6eeb669a2c2bfd63bc7ab33", - "compiled_at": "2026-10-07T04:09:45Z", + "children_root": "sha256:b03bc004d9ac6c42471db83334b1ebf67c7d57eff23f968006369ef1dc08d263", + "compiled_at": "2026-10-07T07:22:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:754512262646d1d563a682858ae5afeb9859d2f1d31f52229137a8e7c69e6f6a", + "digest": "sha256:ba844abceb616ab797b178857a06b32416eb5ff1e66a682c397461b3182f1c74", "evidence_files": 4818, "evidence_root": "sha256:07642731585ad396c5d9b566a4b8df7807018f494d322dffce41bd04fb51e553", "files": 6658, - "generated_at_commit": "400d6b0caabb1d5e623ecce935bb0bacacc76a48", - "source_tree": "sha256:70217b27f7cbcb9b2da56f7f4daf503eadc16de01a5459b545678d47cc57aced" + "generated_at_commit": "8fa37681cc28fdd7a8fb235c53c2ce746615be4b", + "source_tree": "sha256:095235834cb8e8c52a65875a40a626c245a9de8d0de3766f0a0ab79e6f27a232" }, "owner_lane": "", "provenance": { diff --git a/src/.crumb b/src/.crumb index f8ac130ec..63c450a14 100644 --- a/src/.crumb +++ b/src/.crumb @@ -170,14 +170,14 @@ } ], "children_root": "sha256:564cf410317a627d546c0c234bd632ba414ca943ecca4fd4c8eccc45d863bb48", - "compiled_at": "2026-10-07T04:09:45Z", + "compiled_at": "2026-10-07T07:22:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:f6799f3fc7c7ad7be6bd1612c0d129e729e809dbd92daad7acfe5df02d95920c", + "digest": "sha256:fc811240fb8c5840adf9f00fcae85a1a8cf4832232e0b01af273dce5bfdd94de", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 412, - "generated_at_commit": "400d6b0caabb1d5e623ecce935bb0bacacc76a48", - "source_tree": "sha256:70a50f992e0055f0c1609802a88fd270d7cb5870437fd6b7d190f74d3d75f60f" + "generated_at_commit": "8fa37681cc28fdd7a8fb235c53c2ce746615be4b", + "source_tree": "sha256:5deac563c306d5903469c05986691c14729a09144f2a8263e39e0eda890ce731" }, "owner_lane": "", "provenance": { diff --git a/src/omega_gpu_session.c b/src/omega_gpu_session.c index 2ecb66d20..6d3fa421d 100644 --- a/src/omega_gpu_session.c +++ b/src/omega_gpu_session.c @@ -28,6 +28,7 @@ static const uint32_t SETUP_WORDS[18] = { static pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; static OmegaGpuSession g_s; static bool g_open, g_blocked; +static uint32_t g_spin_us; /* omega_gpu_session_set_spin_us; 0 = sleep-poll only */ static char g_err[320] = ""; static void (*g_hooks[8])(void); static unsigned g_nhooks; @@ -67,6 +68,12 @@ void omega_gpu_session_lock(void) { pthread_mutex_lock(&g_mu); } void omega_gpu_session_unlock(void) { pthread_mutex_unlock(&g_mu); } bool omega_gpu_session_is_open(void) { return g_open; } int omega_gpu_session_is_blocked(void) { return g_blocked ? 1 : 0; } +int omega_gpu_session_set_spin_us(uint32_t us) { + if (us > OMEGA_GPU_SESSION_MAX_SPIN_US) return -1; + __atomic_store_n(&g_spin_us, us, __ATOMIC_RELAXED); + return 0; +} +uint32_t omega_gpu_session_spin_us(void) { return __atomic_load_n(&g_spin_us, __ATOMIC_RELAXED); } int omega_gpu_session_alloc(size_t bytes, NvrmMem *out) { if (!g_open || g_blocked) { omega_gpu_session_set_error("alloc without open device"); return -1; } @@ -230,10 +237,11 @@ int omega_gpu_session_launch(const OmegaGpuLaunch *L, uint64_t *elapsed_ns, uint pb[n++] = (uint32_t)(g_s.marker.va + 0x10); pb[n++] = (uint32_t)((g_s.marker.va + 0x10) >> 32); pb[n++] = OMEGA_BW_MARKER2_PAYLOAD; pb[n++] = 0; pb[n++] = 0x1 | (1u << 20); + const uint32_t spin_us = L->spin_us ? L->spin_us : omega_gpu_session_spin_us(); uint64_t t0 = now_ns(); if (m16_native_submit_methods(&g_s.ctx, pb, n) != 0) { fail_rm("submit_methods", &g_s.ctx.rm); return -1; } - if (session_wait(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, L->timeout_ms, L->spin_us) != 0 || - session_wait(hmarker2, OMEGA_BW_MARKER2_PAYLOAD, L->timeout_ms, L->spin_us) != 0) { + if (session_wait(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, L->timeout_ms, spin_us) != 0 || + session_wait(hmarker2, OMEGA_BW_MARKER2_PAYLOAD, L->timeout_ms, spin_us) != 0) { g_blocked = true; /* uncertain completion: keep everything, refuse every later call */ omega_gpu_session_set_error("marker wait timed out (latched)"); return -1; diff --git a/src/omega_gpu_session.h b/src/omega_gpu_session.h index 949fe1ff0..e7953b757 100644 --- a/src/omega_gpu_session.h +++ b/src/omega_gpu_session.h @@ -90,6 +90,13 @@ bool omega_gpu_session_is_open(void); /* 1 once an uncertain completion has latched this process. */ int omega_gpu_session_is_blocked(void); +/* Process-wide marker-wait spin window, used by every launch whose own spin_us is 0 + * (the matmul, elementwise and attention APIs leave it 0). 0 (the default) keeps the + * 50 us sleep-poll, which Linux timer slack rounds to about 102 us per launch on GB10 + * (omega#328). 0 on success, -1 above OMEGA_GPU_SESSION_MAX_SPIN_US (setting unchanged). */ +int omega_gpu_session_set_spin_us(uint32_t us); +uint32_t omega_gpu_session_spin_us(void); + /* Caller holds the lock, device open. GPU-uncached allocation, page rounded. */ int omega_gpu_session_alloc(size_t bytes, NvrmMem *out); /* Caller holds the lock, device open. A GPU code buffer for code_size bytes with the 2 KB instruction diff --git a/tests/.crumb b/tests/.crumb index 0328516cb..34cac3133 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -284,14 +284,14 @@ } ], "children_root": "sha256:c630c07cfd744174cf35b42b04d96bbb15dfedb76557947943c412d3219586c5", - "compiled_at": "2026-10-07T04:09:45Z", + "compiled_at": "2026-10-07T07:22:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:4a13eb3a1f0aeaf6da2f1a4e4d6faee018304dc7db3a270950fc1809e123e1bc", + "digest": "sha256:0dc1710b156c18dc1ad2ec7c311476c66184878ab9dd9dd250c879748cd0c5b4", "evidence_files": 11, "evidence_root": "sha256:d5c1bceb4d57ef0eb42797c58801b5926509711614c3e38bb7105b6efa3942f2", "files": 818, - "generated_at_commit": "400d6b0caabb1d5e623ecce935bb0bacacc76a48", - "source_tree": "sha256:0a18b2fd43e90ae52b5aebb67ebbdc6486a2fd9092619ed4b57d180f066d3473" + "generated_at_commit": "8fa37681cc28fdd7a8fb235c53c2ce746615be4b", + "source_tree": "sha256:aeaaa2b1fd17afee7fde13b6d5b297e3a07375a1e64f4023228678d1997c4727" }, "owner_lane": "", "provenance": { diff --git a/tests/gpu_matmul_api_test.c b/tests/gpu_matmul_api_test.c index 17297dac3..aea419e98 100644 --- a/tests/gpu_matmul_api_test.c +++ b/tests/gpu_matmul_api_test.c @@ -6,6 +6,7 @@ * ./gpu_matmul_api_test --mutant --out r.json wrong kernel (last K step dropped) must FAIL parity; * exit 0 when every shape caught it ("mutant killed") * ./gpu_matmul_api_test --cta-budget N ... run with a different CTA budget (I42 experiment) + * ./gpu_matmul_api_test --spin-us N ... marker-wait spin window for every launch (omega#328) * * Shapes come from OMEGA_GPU_MATMUL_SHAPES ("m,k,n;m,k,n;..."), default below. * Pass rule per shape: rc OK, parity verified by the API oracle, end-to-end error < 1e-5 relative to @@ -13,6 +14,7 @@ * chip's f32 accumulator differ), second call hits the kernel cache and agrees bit for bit. */ #include "omega_gpu_matmul_api.h" +#include "omega_gpu_session.h" #include "omega_blackwell_codegen.h" #include "omega_blackwell_matmul.h" #include @@ -64,6 +66,13 @@ static void host_only(void) { CHECK(omega_gpu_matmul_f32(16, 16, 16, NULL, b, c, &info) == OMEGA_GPU_MATMUL_BAD_ARGS, "NULL a refused"); CHECK(omega_gpu_matmul_f32(OMEGA_BW_MATMUL_MAX_M + 1, 16, 16, a, b, c, &info) == OMEGA_GPU_MATMUL_TOO_LARGE, "m over limit refused"); CHECK(omega_gpu_matmul_bf16(16, OMEGA_BW_MATMUL_MAX_K + 1, 16, (uint16_t *)a, (uint16_t *)b, c, NULL) == OMEGA_GPU_MATMUL_TOO_LARGE, "k over limit refused (NULL info ok)"); + /* session spin window (omega#328): in-range value kept, out-of-range refused unchanged, 0 restores */ + const uint32_t spin0 = omega_gpu_session_spin_us(); + CHECK(omega_gpu_session_set_spin_us(2000) == 0 && omega_gpu_session_spin_us() == 2000, "spin window 2000 us set"); + CHECK(omega_gpu_session_set_spin_us(OMEGA_GPU_SESSION_MAX_SPIN_US + 1) == -1 && omega_gpu_session_spin_us() == 2000, + "spin window over the maximum refused, setting unchanged"); + CHECK(omega_gpu_session_set_spin_us(0) == 0 && omega_gpu_session_spin_us() == 0, "spin window 0 restores the sleep-poll"); + omega_gpu_session_set_spin_us(spin0); CHECK(omega_gpu_matmul_bf16(16, 16, OMEGA_BW_MATMUL_MAX_N + 1, (uint16_t *)a, (uint16_t *)b, c, NULL) == OMEGA_GPU_MATMUL_TOO_LARGE, "n over limit refused"); CHECK(OMEGA_BW_MATMUL_MAX_N >= 128256 && OMEGA_BW_MATMUL_MAX_K >= 8192 && OMEGA_BW_MATMUL_MAX_M >= 2048, "limits cover Llama shapes (vocab 128256, ffn 8192)"); OmegaGpuTensor *t = NULL; @@ -172,7 +181,7 @@ static int cmp_double(const void *x, const void *y) { double a = *(const double static int timing(const char *shapes, const char *out_path) { FILE *out = out_path ? fopen(out_path, "w") : NULL; if (out_path && !out) { printf("cannot open %s\n", out_path); return 2; } - if (out) fprintf(out, "{\"schema\":\"OMEGA_GPU_MATMUL_API_TIMING_V1\",\"cta_budget\":%u,\"calls\":100,\"shapes\":[", omega_gpu_matmul_cta_budget()); + if (out) fprintf(out, "{\"schema\":\"OMEGA_GPU_MATMUL_API_TIMING_V1\",\"cta_budget\":%u,\"spin_us\":%u,\"calls\":100,\"shapes\":[", omega_gpu_matmul_cta_budget(), omega_gpu_session_spin_us()); char *copy = strdup(shapes); char *save = NULL; int first = 1; for (char *tok = strtok_r(copy, ";", &save); tok; tok = strtok_r(NULL, ";", &save)) { unsigned m, k, n; @@ -242,6 +251,9 @@ int main(int argc, char **argv) { else if (strcmp(argv[i], "--mutant") == 0) mutant = 1; else if (strcmp(argv[i], "--timing") == 0) do_timing = 1; else if (strcmp(argv[i], "--cta-budget") == 0 && i + 1 < argc) omega_gpu_matmul_set_cta_budget((uint32_t)strtoul(argv[++i], NULL, 10)); + else if (strcmp(argv[i], "--spin-us") == 0 && i + 1 < argc) { + if (omega_gpu_session_set_spin_us((uint32_t)strtoul(argv[++i], NULL, 10)) != 0) { fprintf(stderr, "--spin-us out of range\n"); return 2; } + } else if (strcmp(argv[i], "--out") == 0 && i + 1 < argc) out_path = argv[++i]; } const char *shapes = getenv("OMEGA_GPU_MATMUL_SHAPES");