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 / exec.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 | //! Run one implementation process once and capture everything it produced. |
| 17 | use std::fs; |
| 18 | use std::io; |
| 19 | use std::path::Path; |
| 20 | use std::process::{Command, Stdio}; |
| 21 | use std::sync::atomic::{AtomicU64, Ordering}; |
| 22 | use std::time::{Duration, Instant}; |
| 23 | |
| 24 | pub struct Executed { |
| 25 | pub exit_code: Option<i32>, |
| 26 | pub stdout: Vec<u8>, |
| 27 | pub stderr: Vec<u8>, |
| 28 | pub report: Option<Vec<u8>>, |
| 29 | pub bitmap: Option<Vec<u8>>, |
| 30 | pub wall_s: f64, |
| 31 | } |
| 32 | |
| 33 | static COUNTER: AtomicU64 = AtomicU64::new(0); |
| 34 | |
| 35 | /// Execute `imp` with the implementation CLI of the contract. |
| 36 | /// `audit = Some(k)` runs audit mode with k passes, otherwise timed mode. |
| 37 | pub fn execute(imp: &Path, limit: u64, min_seconds: f64, audit: Option<u32>) -> io::Result<Executed> { |
| 38 | let dir = std::env::temp_dir().join(format!( |
| 39 | "prime-race-{}-{}", |
| 40 | std::process::id(), |
| 41 | COUNTER.fetch_add(1, Ordering::SeqCst) |
| 42 | )); |
| 43 | fs::create_dir_all(&dir)?; |
| 44 | let bm = dir.join("bitmap.bin"); |
| 45 | let rp = dir.join("report.json"); |
| 46 | let mut tries = 0; |
| 47 | let (out, wall_s) = loop { |
| 48 | let mut cmd = Command::new(imp); |
| 49 | cmd.arg("--limit").arg(limit.to_string()); |
| 50 | match audit { |
| 51 | Some(k) => { |
| 52 | cmd.arg("--audit-passes").arg(k.to_string()); |
| 53 | } |
| 54 | None => { |
| 55 | cmd.arg("--min-seconds").arg(min_seconds.to_string()); |
| 56 | } |
| 57 | } |
| 58 | cmd.arg("--bitmap-out").arg(&bm).arg("--report-out").arg(&rp); |
| 59 | cmd.stdin(Stdio::null()); |
| 60 | let t = Instant::now(); |
| 61 | match cmd.output() { |
| 62 | Ok(o) => break (o, t.elapsed().as_secs_f64()), |
| 63 | // A freshly written script can briefly be busy; retry only that case. |
| 64 | Err(e) if e.kind() == io::ErrorKind::ExecutableFileBusy && tries < 20 => { |
| 65 | tries += 1; |
| 66 | std::thread::sleep(Duration::from_millis(25)); |
| 67 | } |
| 68 | Err(e) => { |
| 69 | let _ = fs::remove_dir_all(&dir); |
| 70 | return Err(e); |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | let ex = Executed { |
| 75 | exit_code: out.status.code(), |
| 76 | stdout: out.stdout, |
| 77 | stderr: out.stderr, |
| 78 | report: fs::read(&rp).ok(), |
| 79 | bitmap: fs::read(&bm).ok(), |
| 80 | wall_s, |
| 81 | }; |
| 82 | let _ = fs::remove_dir_all(&dir); |
| 83 | Ok(ex) |
| 84 | } |