From 5f318406f0a1189fdd43bfdb0f052553c6ed19ea Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Mon, 5 Oct 2026 13:27:32 -0500 Subject: [PATCH 1/7] feat(prime-drag-race): suite runner, reference, validator, receipts, contract v1 Standalone crate (the parent crate needs a sibling checkout to build). Independent Miller-Rabin reference, strict validation, negative tests, trial protocol with receipts, and CONTRACT.md. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 + prime-drag-race/CONTRACT.md | 121 ++++++ prime-drag-race/Cargo.lock | 601 ++++++++++++++++++++++++++++++ prime-drag-race/Cargo.toml | 25 ++ prime-drag-race/src/exec.rs | 69 ++++ prime-drag-race/src/lib.rs | 15 + prime-drag-race/src/main.rs | 136 +++++++ prime-drag-race/src/receipt.rs | 199 ++++++++++ prime-drag-race/src/reference.rs | 200 ++++++++++ prime-drag-race/src/runner.rs | 253 +++++++++++++ prime-drag-race/src/sweep.rs | 79 ++++ prime-drag-race/src/validate.rs | 382 +++++++++++++++++++ prime-drag-race/tests/negative.rs | 320 ++++++++++++++++ 13 files changed, 2404 insertions(+) create mode 100644 prime-drag-race/CONTRACT.md create mode 100644 prime-drag-race/Cargo.lock create mode 100644 prime-drag-race/Cargo.toml create mode 100644 prime-drag-race/src/exec.rs create mode 100644 prime-drag-race/src/lib.rs create mode 100644 prime-drag-race/src/main.rs create mode 100644 prime-drag-race/src/receipt.rs create mode 100644 prime-drag-race/src/reference.rs create mode 100644 prime-drag-race/src/runner.rs create mode 100644 prime-drag-race/src/sweep.rs create mode 100644 prime-drag-race/src/validate.rs create mode 100644 prime-drag-race/tests/negative.rs diff --git a/README.md b/README.md index aef07f7..2864e53 100644 --- a/README.md +++ b/README.md @@ -221,3 +221,7 @@ Copyright (c) 2026 Drake Stapleton and AIEN Contributors. See [NOTICE](NOTICE) f - **Benchmark Code & Harness**: Standard [GNU AGPL-3.0-or-later](LICENSE) for universal execution, replication, and integration. - **Benchmark Data & Metrics**: Raw telemetry JSON, hardware timing records, and SVG comparison charts are dedicated to the public domain under [CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/). - **Upstream Development Charter**: [CONSTITUTION.md](CONSTITUTION.md) defines the internal architectural doctrine and stewardship standards for upstream development and does not bind downstream users. + +## Prime Drag Race + +The frozen contract and suite runner for the AIEN Prime Drag Race live in [prime-drag-race/](prime-drag-race/CONTRACT.md). The runner is a standalone Rust crate (`cargo build` inside that directory). diff --git a/prime-drag-race/CONTRACT.md b/prime-drag-race/CONTRACT.md new file mode 100644 index 0000000..82c0287 --- /dev/null +++ b/prime-drag-race/CONTRACT.md @@ -0,0 +1,121 @@ +# AIEN Prime Drag Race: benchmark contract (version 1) + +This contract is frozen. Any change to a rule below is a new contract version. +The runner in this directory enforces it. Contract version string: `1`. + +## What is measured + +Sieve all primes up to a limit (default 1,000,000), over and over, for at least a minimum time +(default 5 seconds), and count how many complete passes finish. The score is passes per second. +Higher is faster. + +## The canonical result + +For limit L, only odd numbers are stored. Bit k (word k/64, bit k%64, little-endian 64-bit words, +which is the same bytes as little-endian 32-bit words) is set exactly when 2k+1 is prime, for +0 <= k < (L+1)/2. All bits past that range are zero. The prime 2 is implicit when L >= 2. The count +of primes is the number of set bits plus 1 when L >= 2. For L = 1,000,000 the count is 78,498. + +The runner builds this result itself with an independent reference: deterministic Miller-Rabin on +every odd number up to L (bases 2, 3, 5, 7 below 3,215,031,751, otherwise the first 12 primes, with +128-bit multiplication). The reference is checked against trial division and the known prime counts +(10:4, 100:25, 1,000:168, 10,000:1,229, 100,000:9,592, 1,000,000:78,498, 10,000,000:664,579). + +## What one pass includes + +Everything needed to go from nothing to a complete result that the host can read: reset or allocate +the sieve state, compute the base primes up to sqrt(L) (for GPUs, on the host, written into a +device-visible buffer), launch the work, wait for confirmed completion, and have the result sitting +in host-readable memory. Excluded: process start, one-time setup (opening a GPU session, uploading +kernel code, allocating persistent buffers), and the final export and checking of the answer. +A CPU pass allocates a fresh zeroed sieve each time (faithful). A GPU pass that keeps persistent +buffers is marked not faithful. + +## Implementation interface + +` [--limit N] [--min-seconds S] [--bitmap-out PATH] [--report-out PATH] [--audit-passes K]` + +- Timed mode: loop passes against a monotonic clock until S seconds have passed. Elapsed is the + actual time spent. After the loop, outside the timing, export the last pass's canonical bitmap and + write the report. Print exactly one line on stdout, and only on success: + `