Skip to content

Panorama Optimizations#5041

Draft
aknayar wants to merge 22 commits intofacebookresearch:mainfrom
aknayar:optimize-pano
Draft

Panorama Optimizations#5041
aknayar wants to merge 22 commits intofacebookresearch:mainfrom
aknayar:optimize-pano

Conversation

@aknayar
Copy link
Copy Markdown
Contributor

@aknayar aknayar commented Apr 3, 2026

Note: Should be merged before #4970 (IVFPQPanorama).

Changes

Performance

This PR implements various optimizations to Panorama (L2Flat and IVFFlat).

  1. Disaggregate distance computation from pruning decisions to avoid branches in distance computation hotpath.
  2. Early batch processing termination when no points are remaining.
  3. Manually unrolled distance kernel.
  4. Template distance computation on level width for autovectorization.
  5. if constexpr (C::is_max) instead of C::cmp for autovectorized pruning.
  6. Byteset for vectorized compacting of active indices using _pext_u64.
  7. Template distance computation and pruning on first level (no active_indices indirection) to let it autovectorize.
  8. Hoist buffer allocations into IndexFlat/IVFFlatScannerPanorama.

Other

  • Define kDefaultBatchSize once in Panorama.h (previously defined in 5 separate locations).
  • Allow bench_flat_l2_panorama.py and bench_ivf_flat_panorama.py to accept gist1M or sift1M as dataset to bench on.

Results

...

@meta-cla meta-cla bot added the CLA Signed label Apr 3, 2026
@aknayar aknayar marked this pull request as draft April 3, 2026 22:43
}

float lower_bound = exact_distances[idx] - cauchy_schwarz_bound;
if constexpr (C::is_max) {
Copy link
Copy Markdown
Contributor Author

@aknayar aknayar Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately C::cmp() kills autovectorization here so we resort to this workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant