benchmarks-mv
Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS.
Brought by drakestapleton
benchmarks-mv / prime-drag-race / src / sweep.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! Correctness sweep limits (DESIGN "Limits sweep"). |
| 17 | use std::collections::BTreeSet; |
| 18 | |
| 19 | fn small_primes(max: u64) -> Vec<u64> { |
| 20 | (2..=max).filter(|&n| super::reference::is_prime(n)).collect() |
| 21 | } |
| 22 | |
| 23 | pub fn default_sweep() -> Vec<u64> { |
| 24 | let mut s: BTreeSet<u64> = BTreeSet::new(); |
| 25 | for v in [0, 1, 2, 3, 4, 5, 8, 9, 15, 25, 121, 169, 289, 361, 961, 1_000_000] { |
| 26 | s.insert(v); |
| 27 | } |
| 28 | for (a, b) in [ |
| 29 | (31, 34), |
| 30 | (63, 66), |
| 31 | (95, 97), |
| 32 | (127, 130), |
| 33 | (255, 258), |
| 34 | (1023, 1025), |
| 35 | (1999, 2001), |
| 36 | (4095, 4097), |
| 37 | (999_983, 1_000_003), |
| 38 | ] { |
| 39 | s.extend(a..=b); |
| 40 | } |
| 41 | // 64 odd numbers per word means 128 per word; 64*32 words per thread block means 2048 numbers per |
| 42 | // block of one bit each. Cover multiples +-1 of both. |
| 43 | for k in 1..=16u64 { |
| 44 | for base in [128 * k, 2048 * k] { |
| 45 | s.extend([base - 1, base, base + 1]); |
| 46 | } |
| 47 | } |
| 48 | for p in small_primes(997) { |
| 49 | let q = p * p; |
| 50 | s.extend([q - 1, q, q + 1]); |
| 51 | } |
| 52 | s.into_iter().collect() |
| 53 | } |
| 54 | |
| 55 | /// Parse "1,2,5..9,100". Ranges are inclusive. |
| 56 | pub fn parse_limits(text: &str) -> Result<Vec<u64>, String> { |
| 57 | let mut out = BTreeSet::new(); |
| 58 | for part in text.split(',').map(str::trim).filter(|p| !p.is_empty()) { |
| 59 | if let Some((a, b)) = part.split_once("..") { |
| 60 | let a: u64 = a.parse().map_err(|_| format!("bad limit {part}"))?; |
| 61 | let b: u64 = b.parse().map_err(|_| format!("bad limit {part}"))?; |
| 62 | if a > b { |
| 63 | return Err(format!("bad range {part}")); |
| 64 | } |
| 65 | out.extend(a..=b); |
| 66 | } else { |
| 67 | out.insert(part.parse::<u64>().map_err(|_| format!("bad limit {part}"))?); |
| 68 | } |
| 69 | } |
| 70 | if out.is_empty() { |
| 71 | return Err("no limits given".into()); |
| 72 | } |
| 73 | Ok(out.into_iter().collect()) |
| 74 | } |
| 75 | |
| 76 | #[cfg(test)] |
| 77 | mod tests { |
| 78 | use super::*; |
| 79 | |
| 80 | #[test] |
| 81 | fn sweep_has_required_points() { |
| 82 | let s = default_sweep(); |
| 83 | for v in [0, 1, 2, 9, 997 * 997, 997 * 997 + 1, 1_000_003, 2047, 2049] { |
| 84 | assert!(s.contains(&v), "missing {v}"); |
| 85 | } |
| 86 | assert!(!s.contains(&10_000_000)); |
| 87 | } |
| 88 | |
| 89 | #[test] |
| 90 | fn parse() { |
| 91 | assert_eq!(parse_limits("1,3..5").unwrap(), vec![1, 3, 4, 5]); |
| 92 | assert!(parse_limits("x").is_err()); |
| 93 | } |
| 94 | } |