From f4a860bbfbc0ac9608e90a07d52c8db8b5185551 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 3 Oct 2026 05:56:29 -0500 Subject: [PATCH 1/2] CHIPWAIT-2: vector + accelerator-world waits on shared primitive, uncached completion memory omega_blackwell_submit.c (3 launchers): fixed wait on marker+marker2 and the QMD semaphore, uncached marker page, L2 flush + second marker after the WFI marker, tagged BW_WAIT_FAIL line on failure. omega_accelerator_world.c: sequence (wrap-safe) waits, uncached completion page, flush + marker2 for synchronous dispatches, WORLD_WAIT_FAIL line before the unchanged world->faulted handling. Host tests prove wait logic only. Co-Authored-By: Claude Sonnet 5.5 --- src/omega_accelerator_world.c | 56 +++++++++++++++++++++++++++++++---- src/omega_blackwell_submit.c | 35 ++++++++++++++++++---- 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/src/omega_accelerator_world.c b/src/omega_accelerator_world.c index 2445fd17a..e91416338 100644 --- a/src/omega_accelerator_world.c +++ b/src/omega_accelerator_world.c @@ -3,6 +3,7 @@ #include "omega_blackwell_encoder.h" #include "omega_blackwell_codegen.h" #include "omega_blackwell_submit.h" +#include "omega_gpu_wait.h" #include "sha256.h" #include #include @@ -39,6 +40,46 @@ static bool payload_reached(uint32_t payload, uint32_t upto) { return (int32_t)(payload - upto) <= 0; } +/* CHIPWAIT-2: completion memory and waits for the world's completion page. + * The page is GPU-uncached. Each synchronous dispatch (execute and the matmul + * variant) releases its payload at +0 and, after an L2_FLUSH_DIRTY mem-op + * (NVC96F_MEM_OP_A..D = 0x28..0x34, D bits 31:27 OPERATION = 0x10, as in + * omega_numeric_gb10.c), the same payload at +0x10; the host waits for both with + * the wrap-safe sequence wait. The same payload sequence is used so the check is + * "reached or passed", never exact equality. */ +#define WORLD_MARKER2_OFFSET 0x10 + +static volatile uint32_t *world_marker2(const OmegaAcceleratorWorld *world) { + return (volatile uint32_t *)((uint8_t *)world->completion.cpu_marker + WORLD_MARKER2_OFFSET); +} + + +/* Wait until word has reached `payload` (sequence wait). Returns 0 on PASS; + * otherwise prints one tagged line with the report and returns -1. The caller + * keeps its own fault handling. */ +static int world_wait_seq(const char *site, const char *what, volatile uint32_t *word, + uint32_t payload, uint32_t progress_ms, uint32_t total_ms) { + omega_gpu_wait_cfg_t cfg; + memset(&cfg, 0, sizeof(cfg)); + cfg.progress_timeout_ms = progress_ms; + cfg.total_timeout_ms = total_ms; + omega_gpu_wait_report_t r; + if (omega_gpu_wait_sequence(word, payload, &r, &cfg)) return 0; + fprintf(stderr, + "WORLD_WAIT_FAIL site=%s wait=%s kind=%s result=%s expected=%u observed=%u " + "elapsed_ns=%llu progress_count=%llu polls=%llu\n", + site, what, omega_gpu_wait_kind_name(r.wait_kind), omega_gpu_wait_result_name(r.result), + r.expected, r.last_observed, (unsigned long long)r.elapsed_ns, + (unsigned long long)r.progress_count, (unsigned long long)r.polls); + return -1; +} + +/* Synchronous dispatch: marker, then marker2 (progress stall 5000 ms, hard total 600000 ms). */ +static int world_wait_dispatch(const OmegaAcceleratorWorld *world, const char *site, uint32_t payload) { + if (world_wait_seq(site, "marker", world->completion.cpu_marker, payload, 5000, 600000) != 0) return -1; + return world_wait_seq(site, "marker2", world_marker2(world), payload, 5000, 600000); +} + static bool buffer_referenced_in_flight(const OmegaAcceleratorWorld *world, uint32_t id) { for (uint32_t i = 0; i < world->in_flight_count; i++) { const OmegaWorldSubmission *s = &world->in_flight[i]; @@ -712,10 +753,13 @@ int omega_world_drain(OmegaAcceleratorWorld *world, if (!world->channel_active) return OMEGA_WORLD_ERR_HARDWARE; if (timeout_ms < 0) return OMEGA_WORLD_ERR_INVALID_ARG; - /* Caller-built pushbuffers carry only the first release, so drain waits on - * marker 1; dispatch_vector/dispatch_matmul build the C3 tail and wait on marker 2. */ - if (m16_native_wait_marker_ge(world->completion.cpu_marker, upto_payload, - (uint64_t)timeout_ms) != 0) { + /* Caller-supplied budget (API contract, gates pass 0..10000 ms): hard total = timeout_ms + * (0 becomes 1 ms because the primitive maps 0 to its 600 s default), stall = min(5000, total). + * Waits on the marker only: pushbuffers built by callers (omega_world_gates.c) release + * the marker without a flush or marker2. */ + uint32_t drain_total = timeout_ms ? (uint32_t)timeout_ms : 1u; + if (world_wait_seq(__func__, "marker", world->completion.cpu_marker, upto_payload, + drain_total < 5000 ? drain_total : 5000, drain_total) != 0) { world->faulted = true; return OMEGA_WORLD_ERR_HARDWARE; } @@ -1004,7 +1048,7 @@ int omega_world_dispatch_vector(OmegaAcceleratorWorld *world, return OMEGA_WORLD_ERR_HARDWARE; } - if (m16_native_wait_marker_ge(world->completion.cpu_marker2, payload, 5000) != 0) { + if (world_wait_dispatch(world, __func__, payload) != 0) { world->faulted = true; omega_world_scratch_reset(world); return OMEGA_WORLD_ERR_HARDWARE; @@ -1240,7 +1284,7 @@ int omega_world_dispatch_matmul(OmegaAcceleratorWorld *world, return OMEGA_WORLD_ERR_HARDWARE; } - if (m16_native_wait_marker_ge(world->completion.cpu_marker2, payload, 5000) != 0) { + if (world_wait_dispatch(world, __func__, payload) != 0) { world->faulted = true; omega_world_scratch_reset(world); return OMEGA_WORLD_ERR_HARDWARE; diff --git a/src/omega_blackwell_submit.c b/src/omega_blackwell_submit.c index 097195615..5ab382629 100644 --- a/src/omega_blackwell_submit.c +++ b/src/omega_blackwell_submit.c @@ -5,6 +5,7 @@ #include "omega_blackwell_engine.h" #include "omega_gpu_engine.h" #include "m16_native.h" +#include "omega_gpu_wait.h" #include #include #include @@ -132,6 +133,30 @@ int omega_blackwell_execute_vector(const OmegaVectorSpec *spec, return parity_res; } +/* CHIPWAIT-2: the two direct launchers wait through the shared primitive + * (src/omega_gpu_wait.c): exact-value wait on the marker with marker2 required + * (marker2 lands only after the L2 flush, so the output is in memory), progress + * stall 5000 ms (the old budget), hard total 600000 ms. One tagged line on failure. + * The engine-routed launcher keeps the engine's own timed waits. */ +static int bw_wait_one(const char *site, const char *what, volatile uint32_t *w, uint32_t want, + volatile uint32_t *m2, uint32_t m2want) { + omega_gpu_wait_cfg_t cfg; + memset(&cfg, 0, sizeof(cfg)); + cfg.progress_timeout_ms = 5000; + cfg.total_timeout_ms = 600000; + cfg.marker2 = m2; + cfg.marker2_want = m2want; + omega_gpu_wait_report_t r; + if (omega_gpu_wait_fixed(w, want, &r, &cfg)) return 0; + fprintf(stderr, + "BW_WAIT_FAIL site=%s wait=%s kind=%s result=%s expected=0x%x observed=0x%x " + "marker2_observed=0x%x elapsed_ns=%llu progress_count=%llu polls=%llu\n", + site, what, omega_gpu_wait_kind_name(r.wait_kind), omega_gpu_wait_result_name(r.result), + r.expected, r.last_observed, r.last_marker2, (unsigned long long)r.elapsed_ns, + (unsigned long long)r.progress_count, (unsigned long long)r.polls); + return -1; +} + int omega_blackwell_execute_matmul(const OmegaMatMulSpec *spec, const OmegaBlackwellKernel *kernel, const uint32_t *h_a, @@ -339,9 +364,8 @@ int omega_blackwell_execute_matmul(const OmegaMatMulSpec *spec, if (m16_native_submit_methods(&ctx, pb, pb_len) != 0) { m16_native_close(&ctx); return -1; } /* Wait for hardware completion marker */ - if (m16_native_wait_marker(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, 5000) != 0) { m16_native_close(&ctx); return -1; } - /* C3: the second release lands only after the L2 flush, so the output is in memory. */ - if (m16_native_wait_marker(hmarker2, OMEGA_BW_MARKER2_PAYLOAD, 5000) != 0) { m16_native_close(&ctx); return -1; } + /* CHIPWAIT-2: marker with marker2 required (C3: the second release lands only after the L2 flush). */ + if (bw_wait_one(__func__, "marker", hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, hmarker2, OMEGA_BW_MARKER2_PAYLOAD) != 0) { m16_native_close(&ctx); return -1; } __asm__ volatile("dsb sy" ::: "memory"); uint64_t t_end = current_time_ns(); @@ -580,9 +604,8 @@ int omega_blackwell_execute_matmul_tensor(const OmegaMatMulSpec *spec, uint64_t t_start = current_time_ns(); if (m16_native_submit_methods(&ctx, pb, pb_len) != 0) { m16_native_close(&ctx); return -1; } - if (m16_native_wait_marker(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, 5000) != 0) { m16_native_close(&ctx); return -1; } - /* C3: the second release lands only after the L2 flush, so the output is in memory. */ - if (m16_native_wait_marker(hmarker2, OMEGA_BW_MARKER2_PAYLOAD, 5000) != 0) { m16_native_close(&ctx); return -1; } + /* CHIPWAIT-2: marker with marker2 required (C3: the second release lands only after the L2 flush). */ + if (bw_wait_one(__func__, "marker", hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, hmarker2, OMEGA_BW_MARKER2_PAYLOAD) != 0) { m16_native_close(&ctx); return -1; } __asm__ volatile("dsb sy" ::: "memory"); uint64_t t_end = current_time_ns(); From ef07c91f763096aedf853bfaea7186577ce0099b Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 3 Oct 2026 06:03:38 -0500 Subject: [PATCH 2/2] CHIPWAIT-2: one hard budget per completion; drain keeps its full caller budget Inspector notes on #234: chained waits (marker then marker2/semaphore) each had their own 600 s cap, so a completion could wait 1200 s; they now spend from one shared budget. omega_world_drain stall limit equals the caller's total again instead of min(5000, total). Co-Authored-By: Claude Opus 5.5 --- src/omega_accelerator_world.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/omega_accelerator_world.c b/src/omega_accelerator_world.c index e91416338..2f2188f50 100644 --- a/src/omega_accelerator_world.c +++ b/src/omega_accelerator_world.c @@ -56,15 +56,21 @@ static volatile uint32_t *world_marker2(const OmegaAcceleratorWorld *world) { /* Wait until word has reached `payload` (sequence wait). Returns 0 on PASS; * otherwise prints one tagged line with the report and returns -1. The caller - * keeps its own fault handling. */ + * keeps its own fault handling. The hard total is *budget_ms; time spent is + * deducted so chained waits share one budget. */ static int world_wait_seq(const char *site, const char *what, volatile uint32_t *word, - uint32_t payload, uint32_t progress_ms, uint32_t total_ms) { + uint32_t payload, uint32_t progress_ms, uint32_t *budget_ms) { + uint32_t total_ms = *budget_ms; omega_gpu_wait_cfg_t cfg; memset(&cfg, 0, sizeof(cfg)); cfg.progress_timeout_ms = progress_ms; cfg.total_timeout_ms = total_ms; omega_gpu_wait_report_t r; - if (omega_gpu_wait_sequence(word, payload, &r, &cfg)) return 0; + if (omega_gpu_wait_sequence(word, payload, &r, &cfg)) { + uint64_t spent_ms = r.elapsed_ns / 1000000ull; + *budget_ms = spent_ms < total_ms ? total_ms - (uint32_t)spent_ms : 1u; + return 0; + } fprintf(stderr, "WORLD_WAIT_FAIL site=%s wait=%s kind=%s result=%s expected=%u observed=%u " "elapsed_ns=%llu progress_count=%llu polls=%llu\n", @@ -74,10 +80,12 @@ static int world_wait_seq(const char *site, const char *what, volatile uint32_t return -1; } -/* Synchronous dispatch: marker, then marker2 (progress stall 5000 ms, hard total 600000 ms). */ +/* Synchronous dispatch: marker, then marker2 (progress stall 5000 ms, one hard + * total of 600000 ms shared by both waits). */ static int world_wait_dispatch(const OmegaAcceleratorWorld *world, const char *site, uint32_t payload) { - if (world_wait_seq(site, "marker", world->completion.cpu_marker, payload, 5000, 600000) != 0) return -1; - return world_wait_seq(site, "marker2", world_marker2(world), payload, 5000, 600000); + uint32_t budget_ms = 600000; + if (world_wait_seq(site, "marker", world->completion.cpu_marker, payload, 5000, &budget_ms) != 0) return -1; + return world_wait_seq(site, "marker2", world_marker2(world), payload, 5000, &budget_ms); } static bool buffer_referenced_in_flight(const OmegaAcceleratorWorld *world, uint32_t id) { @@ -754,12 +762,13 @@ int omega_world_drain(OmegaAcceleratorWorld *world, if (timeout_ms < 0) return OMEGA_WORLD_ERR_INVALID_ARG; /* Caller-supplied budget (API contract, gates pass 0..10000 ms): hard total = timeout_ms - * (0 becomes 1 ms because the primitive maps 0 to its 600 s default), stall = min(5000, total). + * (0 becomes 1 ms because the primitive maps 0 to its 600 s default), stall = total, so the + * caller keeps its full budget as before. * Waits on the marker only: pushbuffers built by callers (omega_world_gates.c) release * the marker without a flush or marker2. */ uint32_t drain_total = timeout_ms ? (uint32_t)timeout_ms : 1u; if (world_wait_seq(__func__, "marker", world->completion.cpu_marker, upto_payload, - drain_total < 5000 ? drain_total : 5000, drain_total) != 0) { + drain_total, &drain_total) != 0) { world->faulted = true; return OMEGA_WORLD_ERR_HARDWARE; }