diff --git a/architecture.json b/architecture.json index f5da92d3..7fa41e06 100644 --- a/architecture.json +++ b/architecture.json @@ -227,9 +227,6 @@ {"crate": "leleka-cuda-driver", "file": "src/vram_ledger.rs", "ratchet": "process-global", "reason": "the process-wide VRAM ledger (LELEKA_VRAM_LEDGER): a diagnostic singleton fed by every allocation site"}, {"crate": "leleka-cuda-driver", "file": "src/marker_files.rs", "ratchet": "process-global", "reason": "the marker files of the A/B controls: the paths named by the operator are read once and the time of the first look is kept (OnceLock), so a hot path looks at the disk at most every 250 ms; one type serves the three controls"}, {"crate": "leleka-native-cpu-expert", "file": "src/rust_bench_frontend.rs", "ratchet": "process-global", "reason": "FFI: `static mut stdout` is libc's C stream, declared in an extern block"}, - {"crate": "leleka-native-cpu-expert", "file": "src/rust_expert_layout.rs", "ratchet": "process-global", "reason": "the process-wide expert layout the pool threads read; it is set at load time by the engine"}, - {"crate": "leleka-native-cpu-expert", "file": "src/rust_general_pool/job_default.rs", "ratchet": "process-global", "reason": "the origin instant of the pool's job timestamps"}, - {"crate": "leleka-native-cpu-expert", "file": "src/rust_general_pool.rs", "ratchet": "process-global", "reason": "the hook that releases the GPU waits, installed once by the engine (a function pointer)"}, {"crate": "leleka-native-cpu-expert", "file": "src/settings.rs", "ratchet": "process-global", "reason": "the cell of a Setting: the operator's switches and the CPU probes the kernels dispatch on are computed on the first read and kept for the process life (immutable; a hot path pays one atomic load, and kernel code carries no context to pass a settings value through)"} ], "source_patterns": [ diff --git a/crates/native-cpu-expert/src/rust_expert_layout.rs b/crates/native-cpu-expert/src/rust_expert_layout.rs index 1620ae3c..e8b57b67 100644 --- a/crates/native-cpu-expert/src/rust_expert_layout.rs +++ b/crates/native-cpu-expert/src/rust_expert_layout.rs @@ -2,10 +2,7 @@ //! is numerical layout only; actual ModelBinding/source admission stays outside. use super::rust_ggml::{Kind, NativeFormat}; use super::{Error, FF, H, Result}; -use std::{ - path::Path, - sync::{OnceLock, RwLock}, -}; +use std::path::Path; #[derive(Clone)] pub struct ExpertLayout { pub native: bool, @@ -199,18 +196,6 @@ fn atoll(value: &str) -> i64 { } out.wrapping_mul(sign) } -static LAYOUT: OnceLock> = OnceLock::new(); -pub fn install_layout(layout: ExpertLayout) { - *LAYOUT.get_or_init(|| RwLock::new(ExpertLayout::canonical(0, 512))).write().unwrap_or_else(|p| p.into_inner()) = - layout; -} -pub fn expert_layout() -> ExpertLayout { - LAYOUT - .get_or_init(|| RwLock::new(ExpertLayout::canonical(0, 512))) - .read() - .unwrap_or_else(|p| p.into_inner()) - .clone() -} pub fn cpu_name() -> String { // SAFETY: CPUID is architectural on x86_64; leaves 0x80000002..=4 are queried only after leaf 0x80000000 reported // them. diff --git a/crates/native-cpu-expert/src/rust_general_pool.rs b/crates/native-cpu-expert/src/rust_general_pool.rs index 46513a5e..83a1a33f 100644 --- a/crates/native-cpu-expert/src/rust_general_pool.rs +++ b/crates/native-cpu-expert/src/rust_general_pool.rs @@ -9,7 +9,7 @@ use super::{Error, FF, H, Result}; use std::{ cell::UnsafeCell, sync::{ - Arc, Condvar, Mutex, OnceLock, + Arc, Condvar, Mutex, atomic::{AtomicBool, AtomicI32, AtomicI64, AtomicU32, AtomicU64, Ordering}, }, thread, @@ -79,9 +79,16 @@ struct Shared { single: Vec>, states: Vec, host: AtomicI32, + /// The instant `host_ms` and `now_ms` count from: the creation of this pool. + origin: Instant, host_ms: AtomicI64, } -static RELEASE_GPU_WAITS: OnceLock = OnceLock::new(); +impl Shared { + /// Milliseconds since this pool was created (diagnostic timestamps of the host thread). + fn now_ms(&self) -> i64 { + self.origin.elapsed().as_millis().min(i64::MAX as u128) as i64 + } +} #[derive(Clone, Debug)] pub struct Diagnostic { pub epoch: u32, @@ -113,8 +120,6 @@ mod exec; mod job_default; use job_default::alloc_with; use job_default::cells; -pub use job_default::install_release_gpu_waits; -use job_default::now_ms; mod epoch_scheduling; mod expert_pool; mod expert_pool_split_multi_run; diff --git a/crates/native-cpu-expert/src/rust_general_pool/epoch_scheduling.rs b/crates/native-cpu-expert/src/rust_general_pool/epoch_scheduling.rs index da5358dd..48c16f6d 100644 --- a/crates/native-cpu-expert/src/rust_general_pool/epoch_scheduling.rs +++ b/crates/native-cpu-expert/src/rust_general_pool/epoch_scheduling.rs @@ -1,7 +1,7 @@ //! `Shared` of the general pool: publishing a job epoch, claiming work, draining, the worker loop and the waits. //! Apart from `exec`, which runs one job. -use super::{Duration, Instant, Ordering, RELEASE_GPU_WAITS, Shared, now_ms}; +use super::{Duration, Instant, Ordering, Shared}; impl Shared { pub(super) fn publish(&self) { @@ -31,7 +31,7 @@ impl Shared { self.states[id].store(s, Ordering::Relaxed); } else { self.host.store(s, Ordering::Relaxed); - self.host_ms.store(now_ms(), Ordering::Relaxed); + self.host_ms.store(self.now_ms(), Ordering::Relaxed); } } pub(super) fn drain(&self, e: u32, id: usize) { @@ -91,9 +91,6 @@ impl Shared { } pub(super) fn stall(&self, what: &str) -> ! { eprintln!("strata: the CPU expert pool stalled {what}"); - if let Some(f) = RELEASE_GPU_WAITS.get() { - f(); - } std::process::abort() } pub(super) fn wait_parked(&self) { diff --git a/crates/native-cpu-expert/src/rust_general_pool/expert_pool.rs b/crates/native-cpu-expert/src/rust_general_pool/expert_pool.rs index f027a654..34b62c95 100644 --- a/crates/native-cpu-expert/src/rust_general_pool/expert_pool.rs +++ b/crates/native-cpu-expert/src/rust_general_pool/expert_pool.rs @@ -4,7 +4,7 @@ use super::{ Arc, AtomicBool, AtomicI32, AtomicI64, AtomicU32, AtomicU64, Batch, Condvar, CpuTopology, Diagnostic, Duration, Error, ExpertPool, H, Instant, Job, Line, Mutex, NativeFormat, Ordering, PlanarJob, PoolAffinity, Result, Shared, - SingleScratch, SingleSplit, Split, UnsafeCell, alloc_with, cells, now_ms, thread, + SingleScratch, SingleSplit, Split, UnsafeCell, alloc_with, cells, thread, }; impl ExpertPool { @@ -74,7 +74,8 @@ impl ExpertPool { single: cells::(16)?, states: alloc_with(n, || AtomicI32::new(-1))?, host: AtomicI32::new(-10), - host_ms: AtomicI64::new(now_ms()), + origin: Instant::now(), + host_ms: AtomicI64::new(0), })) } fn spawn_worker(s: Arc, i: usize, core: i32) -> Result> { @@ -131,7 +132,7 @@ impl ExpertPool { mode, workers: s.states.iter().map(|s| s.load(Ordering::SeqCst)).collect(), host: s.host.load(Ordering::SeqCst), - host_for_ms: now_ms() - s.host_ms.load(Ordering::SeqCst), + host_for_ms: s.now_ms() - s.host_ms.load(Ordering::SeqCst), } } pub(super) fn phase(&mut self, mode: u32, tasks: usize, rows: usize, parts: usize) { diff --git a/crates/native-cpu-expert/src/rust_general_pool/job_default.rs b/crates/native-cpu-expert/src/rust_general_pool/job_default.rs index afa731eb..af1af7f5 100644 --- a/crates/native-cpu-expert/src/rust_general_pool/job_default.rs +++ b/crates/native-cpu-expert/src/rust_general_pool/job_default.rs @@ -1,10 +1,7 @@ //! Defaults of the pool's raw job and scratch types, the Send/Sync claim for Shared with its safety argument, -//! and small helpers: fallible zeroed allocation, the GPU-wait release hook and a process-relative millisecond clock. +//! and small helpers: fallible zeroed allocation. -use super::{ - Error, FF, Instant, Job, OnceLock, PlanarActivation, RELEASE_GPU_WAITS, Result, Shared, SingleSplit, Split, - UnsafeCell, -}; +use super::{Error, FF, Job, PlanarActivation, Result, Shared, SingleSplit, Split, UnsafeCell}; impl Default for Job { fn default() -> Self { @@ -45,10 +42,3 @@ pub(super) fn alloc_with(n: usize, make: impl FnMut() -> T) -> Result> pub(super) fn cells(n: usize) -> Result>> { alloc_with(n, || UnsafeCell::new(T::default())) } -pub fn install_release_gpu_waits(callback: fn()) -> Result<()> { - RELEASE_GPU_WAITS.set(callback).map_err(|_| Error::Shape) -} -pub(super) fn now_ms() -> i64 { - static START: OnceLock = OnceLock::new(); - START.get_or_init(Instant::now).elapsed().as_millis().min(i64::MAX as u128) as i64 -}