From 7c52f426df834aae56b37476de879eba46333d1f Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 3 Oct 2026 07:56:09 -0500 Subject: [PATCH] physics: nvrm: GB10 CPU-rewritten GPU-read memory must be GPU-uncached (GPFIFO/USERD, pushbuffer) Symptom: on the GB10, a second submission to a channel never completed (completion marker stuck at the first value), and reused pushbuffer slots re-executed their OLD commands (marker went 3 -> 1). Tests that reuse a pushbuffer or wrap the ring hung or reported stale results. Root cause: memory the CPU rewrites and the GPU reads was allocated GPU-cacheable. NVIDIA's own header says GPU_CACHEABLE_YES on system memory "will not be coherent with direct CPU mappings" (nvos.h:1117-1118), and the UVM driver documents sticky L2 lines on GB10B and refuses to GPU-cache system memory (uvm_gpu.h:1135-1138, nvidia-uvm 580.173.02). CPU dsb barriers do not invalidate the GPU's cached copy, so the GPU replays stale contents. Fix (physics): allocate with nvrm_alloc_gpu_uncached at - nvrm/nvrm.c nvrm_channel: GPFIFO ring + USERD (one allocation, 0x10000) - m16/m16_native.c m16_native_create_channel: reusable pushbuffer (pb_mem) Adds nvrm/submission_visibility_gates.c (distinct commands; reuse + ring wrap over 2051 submissions on a 1024-entry ring) and tests/run_submission_visibility_gates.sh (builds anywhere, prints SKIP and exits 0 when /dev/nvidia0 is absent). Listed as a SKIP job in host-gates.yml and the README, like the other GB10-only runners. Evidence (read-only, ~/workspace/evidence-out): - CHIPWAIT-DIAG-20261003 run-026: visibility gate FAIL before the fix (expected=2 observed=1); run-027: PASS after; run-028: world_lifecycle 11/11. - CHIPWAIT-FIX-20261003 run-001: [PASS] SUBMISSION_VISIBILITY_DISTINCT_COMMANDS and [PASS] SUBMISSION_VISIBILITY_REUSE_AND_RING_WRAP; run-002: targeted M19 gates 2,3,6,7,8 PASS (failed=0); run-003: world_lifecycle 11/11 PASS. Limits: omega-side runs were built with PHYSICS_LOCK_CHECK=0 (not a clean-clone qualification); each result is a single passing run, not a repeated campaign. Other cacheable allocations (world scratch arena, completion marker, registered buffers, resident jobs) are not changed here and are tracked as follow-up. Co-Authored-By: GPT-6 Astra Co-Authored-By: Drake Stapleton Co-Authored-By: Claude Fable 5.1 --- .github/workflows/host-gates.yml | 9 ++- README.md | 2 +- m16/m16_native.c | 5 +- nvrm/nvrm.c | 5 +- nvrm/submission_visibility_gates.c | 77 ++++++++++++++++++++++++ tests/run_submission_visibility_gates.sh | 34 +++++++++++ 6 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 nvrm/submission_visibility_gates.c create mode 100755 tests/run_submission_visibility_gates.sh diff --git a/.github/workflows/host-gates.yml b/.github/workflows/host-gates.yml index 4b099ad..d98be2c 100644 --- a/.github/workflows/host-gates.yml +++ b/.github/workflows/host-gates.yml @@ -19,7 +19,8 @@ name: Host gates # SKIP jobs (shown grey, never green): GB10-only runners # tests/run_forge_gates.sh (Gate 3/4 on the GB10), tests/run_m15_gates.sh # (reads the real GPU's sysfs), tests/run_m16_requalification.sh (native -# GB10 submission), tests/run_nvrm_lifecycle_gates.sh (NVRM on the GB10). +# GB10 submission), tests/run_nvrm_lifecycle_gates.sh (NVRM on the GB10), +# tests/run_submission_visibility_gates.sh (GB10 queue/pushbuffer visibility). on: push: @@ -100,3 +101,9 @@ jobs: runs-on: ubuntu-24.04-arm steps: - run: exit 1 + gb10-submission-visibility: + name: "submission visibility gates (SKIP: needs GB10 + NVRM)" + if: ${{ false }} + runs-on: ubuntu-24.04-arm + steps: + - run: exit 1 diff --git a/README.md b/README.md index f9de9bc..8413a7e 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ tests/run_forge_analog_sim_gates.sh # simulated analog provider vs digital orac m3/tests/run_m3_gates.sh # M3 PHYSICS_EFFECTS, 19 gates in QEMU ``` -`./run_m2_gates.sh` leaves the committed receipt untouched unless `--write-receipt` is passed, which is only for a recorded requalification decision. Gates that need the real GB10 (`tests/run_forge_gates.sh`, `tests/run_m15_gates.sh`, `tests/run_m16_requalification.sh`, `tests/run_nvrm_lifecycle_gates.sh`) run on the DGX Spark one at a time and are never killed mid-run; CI declares them SKIP, never PASS. +`./run_m2_gates.sh` leaves the committed receipt untouched unless `--write-receipt` is passed, which is only for a recorded requalification decision. Gates that need the real GB10 (`tests/run_forge_gates.sh`, `tests/run_m15_gates.sh`, `tests/run_m16_requalification.sh`, `tests/run_nvrm_lifecycle_gates.sh`, `tests/run_submission_visibility_gates.sh`) run on the DGX Spark one at a time and are never killed mid-run; CI declares them SKIP, never PASS. ## Contributing diff --git a/m16/m16_native.c b/m16/m16_native.c index c97b42f..a964f3a 100644 --- a/m16/m16_native.c +++ b/m16/m16_native.c @@ -44,8 +44,9 @@ int m16_native_free_memory(M16NativeContext *ctx, void *cpu_addr) { int m16_native_create_channel(M16NativeContext *ctx) { if (!ctx) return -1; if (nvrm_channel(&ctx->rm) != 0) return -1; - /* Preallocate pushbuffer memory (4 KiB) */ - if (nvrm_alloc(&ctx->rm, 0x1000, &ctx->pb_mem) != 0) return -1; + /* The CPU rewrites this command buffer between retired submissions. + * Bypass the GPU cache so the next submission reads the new commands. */ + if (nvrm_alloc_gpu_uncached(&ctx->rm, 0x1000, &ctx->pb_mem) != 0) return -1; return 0; } diff --git a/nvrm/nvrm.c b/nvrm/nvrm.c index abab24f..a7cea38 100644 --- a/nvrm/nvrm.c +++ b/nvrm/nvrm.c @@ -625,7 +625,10 @@ int nvrm_channel(Nvrm *rm) { if (rm_alloc(rm, rm->chgroup, FERMI_CONTEXT_SHARE_A, &cs, sizeof cs, &rm->ctxshare)) return -1; rm->entries = 1024; - if (nvrm_alloc(rm, 0x10000, &rm->fifo)) return -1; + /* CPU publishes new queue entries and USERD GPPut after each completion. + * A GPU-cached allocation can retain their previous contents on GB10; + * CPU store barriers alone do not invalidate that cached copy. */ + if (nvrm_alloc_gpu_uncached(rm, 0x10000, &rm->fifo)) return -1; if (nvrm_alloc(rm, 0x100000, &rm->notifier)) return -1; NV_CHANNEL_ALLOC_PARAMS gp; diff --git a/nvrm/submission_visibility_gates.c b/nvrm/submission_visibility_gates.c new file mode 100644 index 0000000..44e18a9 --- /dev/null +++ b/nvrm/submission_visibility_gates.c @@ -0,0 +1,77 @@ +/* Real-device regression for CPU-published queue entries and rewritten + * command buffers. No CUDA runtime; run under the shared chip queue. + * The unfixed allocator stalls on the second submission on GB10. + */ +#include "m16_native.h" + +#include +#include +#include + +static int run_sequence(int reuse) { + M16NativeContext ctx; + if (m16_native_open(&ctx) != 0) { + fprintf(stderr, "visibility: open failed\n"); + return 0; + } + int ok = 0; + NvrmMem completion; + if (m16_native_create_channel(&ctx) != 0 || + nvrm_alloc_gpu_uncached(&ctx.rm, 4096, &completion) != 0) + goto finish; + volatile uint32_t *marker = completion.cpu; + *marker = 0; + __asm__ volatile("dsb sy" ::: "memory"); + uint32_t count = reuse ? ctx.rm.entries * 2 + 3 : 2; + for (uint32_t payload = 1; payload <= count; ++payload) { + uint32_t methods[32]; + int words = m16_native_build_release(methods, completion.va, + payload, ctx.rm.compute_class); + if (words <= 0) goto finish; + if (reuse) { + /* Previous use is retired before the next call overwrites slot 0. */ + if (ctx.rm.put != ctx.rm.retired || + m16_native_enqueue_methods(&ctx, methods, (size_t)words) != 0) + goto finish; + } else { + uint32_t offset = (payload - 1) * 128; + memcpy((unsigned char *)ctx.pb_mem.cpu + offset, methods, + (size_t)words * sizeof(uint32_t)); + __asm__ volatile("dsb sy" ::: "memory"); + if (nvrm_enqueue(&ctx.rm, &ctx.pb_mem, offset, (uint32_t)words) != 0) + goto finish; + } + if (payload == 1) { + /* Negative control: no notification, no completed work. */ + if (m16_native_wait_marker_ge(marker, payload, 5) == 0 || *marker != 0) { + fprintf(stderr, "visibility: pre-notification control failed\n"); + goto finish; + } + } + m16_native_ring_doorbell(&ctx); + if (m16_native_wait_marker_ge(marker, payload, 5000) != 0 || + *marker != payload) { + fprintf(stderr, "VISIBILITY_FAIL reuse=%d expected=%" PRIu32 + " observed=%" PRIu32 " put=%" PRIu32 " retired=%" PRIu32 "\n", + reuse, payload, *marker, ctx.rm.put, ctx.rm.retired); + goto finish; + } + nvrm_retire(&ctx.rm, ctx.rm.put); + } + printf("visibility: reuse=%d submissions=%" PRIu32 + " ring_capacity=%" PRIu32 " final_marker=%" PRIu32 "\n", + reuse, count, ctx.rm.entries, *marker); + ok = 1; +finish: + /* Tear down the channel before freeing memory, including failure paths. */ + if (m16_native_close(&ctx) != 0) ok = 0; + return ok; +} + +int main(void) { + int distinct = run_sequence(0); + printf("[%s] SUBMISSION_VISIBILITY_DISTINCT_COMMANDS\n", distinct ? "PASS" : "FAIL"); + int reuse = run_sequence(1); + printf("[%s] SUBMISSION_VISIBILITY_REUSE_AND_RING_WRAP\n", reuse ? "PASS" : "FAIL"); + return distinct && reuse ? 0 : 1; +} diff --git a/tests/run_submission_visibility_gates.sh b/tests/run_submission_visibility_gates.sh new file mode 100755 index 0000000..6a0b8b4 --- /dev/null +++ b/tests/run_submission_visibility_gates.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# tests/run_submission_visibility_gates.sh -- GB10 CPU-published queue entries and rewritten command buffers. +set -euo pipefail + +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) +REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd -P) +LOCK_FILE=/tmp/aien-gb10.lock + +cd "$REPO_ROOT" + +echo "=== GB10 Submission Visibility Gates ===" +echo "Timestamp: $(date -u +"%Y-%m-%dT%H:%M:%SZ")" +echo "Host: $(uname -n) ($(uname -m))" + +echo -e "\n[*] Building submission_visibility_gates..." +gcc -O2 -Wall -Wextra -Werror \ + -I./nvrm -I./m16 \ + -I./third_party/nvidia-open-580.173.02/src/common/sdk/nvidia/inc \ + -I./third_party/nvidia-open-580.173.02/kernel-open/common/inc \ + -I./third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm \ + -I./third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include \ + nvrm/nvrm.c m16/m16_native.c nvrm/submission_visibility_gates.c -o nvrm/submission_visibility_gates + +echo " submission_visibility_gates built cleanly." + +if [ ! -e /dev/nvidia0 ]; then + echo "SKIP: /dev/nvidia0 not present; submission visibility gates need the GB10 (build above succeeded)." + exit 0 +fi + +echo -e "\n[*] Running submission_visibility_gates under GPU lock ($LOCK_FILE)..." +flock "$LOCK_FILE" ./nvrm/submission_visibility_gates + +echo -e "\n=== GB10 Submission Visibility Gates: done ==="