Skip to content

[FEA] Binary IVF Flat Index - #1099

Merged
rapids-bot[bot] merged 200 commits into
NVIDIA:mainfrom
tarang-jain:binary-kmeans
Oct 22, 2026
Merged

rapids-bot[bot] merged 200 commits into
NVIDIA:mainfrom
tarang-jain:binary-kmeans

Conversation

@tarang-jain

@tarang-jain tarang-jain commented Jul 9, 2025 •

Copy link
Copy Markdown
Contributor

Depends on NVIDIA/raft#2770

Implementation of binary ivf flat index (bitwise hamming metric for the IVF Flat index)

Key Features

1. Binary Index Structure

  • Added binary_centers_ field to store cluster centers as packed uint8_t arrays for binary data
  • Index automatically detects BitwiseHamming metric and configures itself for binary operation
  • Only support uint8_t inputs with BitwiseHamming and add only single instantiations of newly added kernels

2. K-means Clustering for Binary Data

The clustering approach for binary data required special handling:

  • Expanded Space Clustering: Binary data (uint8_t) is expanded to signed representation (int8_t) where each bit becomes ±1

    • 0 → -1, 1 → +1 transformation enables meaningful centroid computation
    • Clustering performed using L2 distance in the expanded dimensional space
  • Centroid Quantization: After computing float centroids in expanded space, they are converted back to binary format:

    • Centroids are stored as packed uint8_t arrays
    • KMeans (coarse) prediction is done on these quantized centroids with the BitwiseHamming distance.

3. Distance Kernels

Coarse Search (Cluster Selection)

  • Implemented specialized bitwise_hamming_distance_op for query-to-centroid distances in order to compute PairwiseDistances

Fine-Grained Search (Within Clusters)

Extended the interleaved scan kernel (ivf_flat_interleaved_scan.cuh) with specialized templates for BitwiseHamming:

  • Veclen-based optimization: Different code paths based on vectorization width

    • Veclen=16,8,4: Load data as uint32_t, use __popc(x ^ y) for 4-byte Hamming distance
    • Veclen=1,2: Byte-wise XOR and population count
  • Efficient memory access patterns:

    • Maintains interleaved data layout for coalesced memory access
    • Specialized loadAndComputeDist templates for uint8_t that leverage vectorized loads

cuvs-bench Benchmarks (latency):
image
image
image
image

@copy-pr-bot

copy-pr-bot Bot commented Jul 9, 2025

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cjnolet cjnolet moved this from Todo to In Progress in Unstructured Data Processing Jul 11, 2025
@tarang-jain

Copy link
Copy Markdown
Contributor Author

/ok to test 5e6db22

@copy-pr-bot

copy-pr-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

/ok to test 5e6db22

@tarang-jain, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@tarang-jain

Copy link
Copy Markdown
Contributor Author

/ok to test 5e6db22

@tfeher tfeher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Tarang for addressing my questions. The PR looks good to me.

@KyleFromNVIDIA KyleFromNVIDIA left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

JIT+LTO changes look reasonable to me

@tarang-jain
tarang-jain removed request for a team and AyodeAwe October 20, 2026 17:35
@tarang-jain

Copy link
Copy Markdown
Contributor Author

Notes: after a lot of discussion offline, we have brought back design 2:

Implement a new quantized dataset type binary_dataset, similar to SQ/VPQ datasets. It's backed by the uint8_t mdarray/mdspan plus the binary dictionary. This means the index is not flat anymore, rather IVF-Binary. See my refactoring suggestion tarang-jain#1 . See how this will look merged onto main #2864

@tarang-jain

Copy link
Copy Markdown
Contributor Author

/ok to test ad67e8b

@copy-pr-bot

copy-pr-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

/ok to test ad67e8b

@tarang-jain, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@tarang-jain

Copy link
Copy Markdown
Contributor Author

/ok to test ad67e8b

@tarang-jain

Copy link
Copy Markdown
Contributor Author

/ok to test 6c393a7

@tarang-jain

Copy link
Copy Markdown
Contributor Author

/ok to test 8dae48a

@tarang-jain
tarang-jain requested a review from achirkin October 22, 2026 06:34
tarang-jain added a commit to tarang-jain/cuvs that referenced this pull request Oct 22, 2026
@achirkin
achirkin dismissed their stale review October 22, 2026 15:17

Co-authored parts of PR

@achirkin
achirkin removed their request for review October 22, 2026 15:17
@tarang-jain

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit 2757e7d into NVIDIA:main Oct 22, 2026
119 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Unstructured Data Processing Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpp feature request New feature or request non-breaking Introduces a non-breaking change stale-active

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants