Skip to main content

Crate slate_simd

Crate slate_simd 

Source
Expand description

§slate-simd

SIMD distance kernels for Slate-ANN with runtime CPU-feature dispatch.

Provides L2², inner-product, and cosine distance over f32, plus asymmetric f32-query vs narrow-stored kernels (distance_f16, distance_i8) that widen the on-disk representation inside the SIMD reduction so narrow stores skip a decode-to-f32 pass. Four implementation tiers are selected at runtime — AVX-512, AVX2+FMA, ARM NEON, and a portable scalar fallback (also the correctness oracle for the vectorized paths).

§Ranking convention

Mirrors slate_core::Metric: all distances rank by ascending score (smaller = closer).

  • l2_sq — squared Euclidean (no sqrt; preserves ordering).
  • inner_productnegated dot product (−⟨a,b⟩).
  • cosine1 − cos(a,b) over raw inputs; cosine_normalized is the cheaper 1 − ⟨a,b⟩ for pre-normalized inputs.

§Safety model

Vectorized kernels use #[target_feature] intrinsics (unsafe). They are only ever invoked behind the runtime dispatcher in [dispatch], which confirms CPU support before selecting a tier. The public API below is entirely safe and validates that input slices have equal length.

Populated in Phase 1 (f32 kernels + dispatch); narrow-store kernels added in the Phase-9.5 deferred clean-ups.

Modules§

scalar
Scalar reference kernels.

Enums§

Tier
Which implementation tier the dispatcher selected for this CPU.

Functions§

active_tier
The cached active tier for this process.
cosine
Cosine distance 1 − cos(a,b) over raw (un-normalized) inputs.
cosine_normalized
Cosine distance for pre-normalized inputs: 1 − ⟨a,b⟩.
detect_tier
Detect the best tier supported by the current CPU.
distance
Dispatch a distance computation by slate_core::Metric.
distance_f16
Distance between an f32 query and an f16-stored vector, by Metric.
distance_i8
Distance between an f32 query and an i8-stored vector, by Metric.
dot
Raw inner product ⟨a,b⟩ (not negated), dispatched to the best tier.
inner_product
Inner-product distance −⟨a,b⟩, dispatched to the best available tier.
l2_sq
Squared Euclidean (L2²) distance, dispatched to the best available tier.