From 123ee1a2eeb260dce2313bc4ad82ca85794c423b Mon Sep 17 00:00:00 2001 From: igneum-labs <337424239+igneum-labs@users.noreply.github.com> Date: Sun, 4 Oct 2026 19:18:04 +0000 Subject: [PATCH] Variant race: a 150 ms pause between timed windows so the job loop gets the card (the mutex is not fair; a queued job waited the whole race, 36 s, in the first serve check) Co-Authored-By: Claude Fable 5.1 --- proto-cuda/nvrtc/worker.cpp | 3 +++ proto-metal/main.swift | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/proto-cuda/nvrtc/worker.cpp b/proto-cuda/nvrtc/worker.cpp index aee50baf0..e8cd73b1c 100644 --- a/proto-cuda/nvrtc/worker.cpp +++ b/proto-cuda/nvrtc/worker.cpp @@ -687,6 +687,9 @@ static void racePair(Ctx& c, Pair* p, const PfPack& pk, const std::string& bound if (i > 0 && round == 0 && wallMs() > deadline) { e.ok = false; e.note = "not timed: the race budget ran out"; continue; } if (pinnedOnly && i == 0) continue; if (!raceTime(c, p, pk, e, dOut, batch, pinnedOnly ? 0 : benchMs, s, round == 0)) e.ok = false; + // the mutex is not fair: give the job loop the card between windows (measured on the Mac, 4 October + // 2026: without this a queued job waited the whole race, 36 s) + std::this_thread::sleep_for(std::chrono::milliseconds(150)); } } if (dOut) c.drv.memFree(dOut); diff --git a/proto-metal/main.swift b/proto-metal/main.swift index 508b77328..5073f00f3 100644 --- a/proto-metal/main.swift +++ b/proto-metal/main.swift @@ -2899,7 +2899,9 @@ func raceProgram(_ gpu: GPU, _ program: ServeProgram, dataset: MTLBuffer, datase if pinnedOnly && i == 0 { continue } if round == 0 && i > 0 && nowNs() > deadline { entries[i].note = "not timed: the race budget ran out"; continue } gpuLock.lock() - defer { gpuLock.unlock() } + // NSLock is not fair: after the window the job loop gets the card (measured 4 October 2026: without the + // pause a queued job waited the whole race, 36 s) + defer { gpuLock.unlock(); Thread.sleep(forTimeInterval: 0.15) } if round == 0 && i > 0 { if !run(k, base: 0x1000_0000, count: checkN, into: outBuf) { entries[i].note = "did not run"; continue } var bad = -1