You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SVE low-dim nearest fast path + SuperKMeans spherical support
Summary:
Two related optimizations for the SCANN coarse quantizer / PQ encoding
path, both targeting ARM SVE:
1. Low-dimensional L2sqr nearest fast path (d in {2,4,8})
fvec_L2sqr_ny_nearest<ARM_SVE> previously wrote all ny distances to
the scratch buffer then did a separate linear scan. For PQ encoding
(compute_1_code) each call has d = dsub and ny = ksub, making this the
hot path. The new path keeps one SVE lane per centroid via D svld1
loads, tracks the min index in registers, and still fills the buffer
(contract-preserving). ny stays generic.
ProductQuantizer::compute_code switches to AVAILABLE_SIMD_LEVELS_A1 so
the ARM_SVE implementation is reachable from PQ encoding (A0 does not
include ARM_SVE).
2. SuperKMeans spherical (inner-product) support
SuperKMeans previously only supported L2. With cp.spherical=true:
- TrainState::R becomes std::unique_ptr<VectorTransform>; power-of-two
d uses the fast HadamardRotation, L2 keeps RandomRotationMatrix.
- update_centroids_and_split and Forgy init renormalize centroids to
unit length, so minimizing L2 is equivalent to maximizing inner
product.
- HadamardRotation::reverse_transform fills the missing inverse.
- ClusteringParameters::use_super_kmeans (default false) lets
Level1Quantizer::train_q1 route coarse quantizer training through
SuperKMeans when explicitly enabled.
- block_l2<ARM_SVE> completes the SuperKMeans SIMD kernels.
Tests: low-dim nearest across SIMD levels (d in {2,4,8}, varied ny),
spherical objective vs vanilla spherical Clustering, unit-norm centroids,
use_super_kmeans field inheritance. Python stubs updated.
Measured on qwen 4096-dim, IP, nlist=1024, sub_dim=4, 1 thread, 50k rows:
- SCANN_DVR Train 67.73s -> 24.36s, Build 78.59s -> 31.52s (-60%)
- recall@10 unchanged vs Clustering baseline (diff <= 0.0002)
0 commit comments