Skip to content

Commit be609b0

Browse files
committed
feat(fingerprint): VectorWidth config with LazyLock — 4K/8K/16K switchable
Adds VectorConfig + vector_config() frozen singleton (like simd_caps()). Three widths: W4K (64 words): CAM command address space — one item per slot W8K (128 words): deprecated legacy W16K (256 words): production default Default: 16K. Override: NDARRAY_VECTOR_WIDTH=8192 env var before first access. After first call, width is frozen for the process lifetime. https://claude.ai/code/session_01SbYsmmbPf9YQuYbHZN52Zh
1 parent d02826d commit be609b0

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

src/hpc/fingerprint.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,72 @@ pub type Fingerprint1K = Fingerprint<128>;
265265
/// 64K-bit fingerprint (recognition projections).
266266
pub type Fingerprint64K = Fingerprint<1024>;
267267

268+
// ─── Vector width config (LazyLock, switchable) ─────────────────
269+
270+
use std::sync::LazyLock;
271+
272+
/// Supported vector widths for the BindSpace substrate.
273+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
274+
#[repr(u16)]
275+
pub enum VectorWidth {
276+
/// 4,096 bits = 64 words = 512 bytes. CAM command address space.
277+
/// One item per address — verb/command vocabulary, not holographic memory.
278+
W4K = 64,
279+
/// 8,192 bits = 128 words = 1 KB. Deprecated legacy.
280+
W8K = 128,
281+
/// 16,384 bits = 256 words = 2 KB. Production default.
282+
W16K = 256,
283+
}
284+
285+
/// Runtime vector configuration. Frozen on first access.
286+
///
287+
/// Like `simd_caps()` — detect once, read everywhere.
288+
/// Controls serialization format, network protocol, and storage layout.
289+
/// Does NOT change the Rust type (use the matching Fingerprint\<N\> alias).
290+
#[derive(Clone, Copy, Debug)]
291+
pub struct VectorConfig {
292+
pub width: VectorWidth,
293+
pub words: usize,
294+
pub bits: usize,
295+
pub bytes: usize,
296+
}
297+
298+
impl VectorConfig {
299+
const fn from_width(w: VectorWidth) -> Self {
300+
let words = w as usize;
301+
VectorConfig { width: w, words, bits: words * 64, bytes: words * 8 }
302+
}
303+
}
304+
305+
static VECTOR_WIDTH: LazyLock<VectorConfig> = LazyLock::new(|| {
306+
let w = std::env::var("NDARRAY_VECTOR_WIDTH")
307+
.ok()
308+
.and_then(|s| match s.as_str() {
309+
"4096" | "4k" | "4K" => Some(VectorWidth::W4K),
310+
"8192" | "8k" | "8K" => Some(VectorWidth::W8K),
311+
"16384" | "16k" | "16K" => Some(VectorWidth::W16K),
312+
_ => None,
313+
})
314+
.unwrap_or(VectorWidth::W16K);
315+
VectorConfig::from_width(w)
316+
});
317+
318+
/// Get the frozen vector width configuration.
319+
///
320+
/// Defaults to 16K (production). Override with `NDARRAY_VECTOR_WIDTH=8192`
321+
/// env var before first access. After first call, width is frozen.
322+
///
323+
/// ```
324+
/// use ndarray::hpc::fingerprint::vector_config;
325+
/// let cfg = vector_config();
326+
/// assert_eq!(cfg.bits, 16_384); // default
327+
/// assert_eq!(cfg.words, 256);
328+
/// assert_eq!(cfg.bytes, 2_048);
329+
/// ```
330+
pub fn vector_config() -> &'static VectorConfig {
331+
&VECTOR_WIDTH
332+
}
333+
268334
#[cfg(test)]
269335
mod tests {
270336
use super::*;

0 commit comments

Comments
 (0)