Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IVF-FLAT support k > 256 #2169

Merged
merged 20 commits into from
Mar 4, 2024

Conversation

mfoerste4
Copy link
Collaborator

@mfoerste4 mfoerste4 commented Feb 9, 2024

Add support for topk > 256 for ivf_flat (Issue #1555)

The PR adds a non-fused version of topk that is utilized if k > 256.

FYI, @tfeher

@github-actions github-actions bot added the cpp label Feb 9, 2024
@cjnolet cjnolet added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Feb 11, 2024
@mfoerste4 mfoerste4 marked this pull request as ready for review February 19, 2024 10:50
@mfoerste4 mfoerste4 requested review from a team as code owners February 19, 2024 10:50
@mfoerste4 mfoerste4 changed the title [Draft] Ivfflat max k gt 256 IVF-FLAT support k > 256 Feb 20, 2024
Copy link
Contributor

@tfeher tfeher left a comment

Choose a reason for hiding this comment

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

Thanks Malte for the PR! It looks great overall, here are my comments

cpp/include/raft/neighbors/detail/ivf_common.cuh Outdated Show resolved Hide resolved
cpp/include/raft/neighbors/detail/ivf_flat_build.cuh Outdated Show resolved Hide resolved
cpp/include/raft/neighbors/detail/ivf_flat_search-inl.cuh Outdated Show resolved Hide resolved
@mfoerste4
Copy link
Collaborator Author

@tfeher thanks for the review. I have added your suggestions.

Copy link
Contributor

@tfeher tfeher left a comment

Choose a reason for hiding this comment

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

Thanks Malte for the updates, it is great to see the increasing code reuse between IVF methods! The PR looks good to me.

As discussed offline, the perf of the non-fused top-k search is currently less then ideal due to large number of dummy values (as a result from cluster size imbalance). We discussed how to improve that in a follow up PR for radix top-k.

@cjnolet
Copy link
Member

cjnolet commented Mar 4, 2024

/merge

@rapids-bot rapids-bot bot merged commit 515ac62 into rapidsai:branch-24.04 Mar 4, 2024
61 checks passed
rapids-bot bot pushed a commit that referenced this pull request Mar 20, 2024
This PR is a followup to #2169. To enable IVF-flat with k>256 we need an additional select_k invocation which was unexpectedly slow. There are two reasons for that:

First problem is the data handed to select_k: The valid data length per row is much smaller than the conservative maximum that could be achieved by probing the N largest probes. Therefore each query row contains roughly ~50% dummy values. This is also the case for IVF-PQ, but did not show up as prominent due to the second reason.

The second problem, and also a difference to the IVF-PQ algorithm - is that a 64bit payload data type is used for selectK. The performance of selectK with 64bit index type is significantly slower than with 32bit, especially when many elements are in the same range:
```
Benchmark                                                           Time             CPU   Iterations
-----------------------------------------------------------------------------------------------------
SelectK/float/uint32_t/kRadix11bitsExtraPass/1/manual_time       1.68 ms         1.74 ms          413 1357#200000#512
SelectK/float/uint32_t/kRadix11bitsExtraPass/3/manual_time       2.31 ms         2.37 ms          302 1357#200000#512#same-leading-bits
SelectK/float/int64_t/kRadix11bitsExtraPass/1/manual_time        5.92 ms         5.98 ms          116 1357#200000#512
SelectK/float/int64_t/kRadix11bitsExtraPass/3/manual_time        83.7 ms         83.8 ms            8 1357#200000#512#same-leading-bits
-----------------------------------------------------------------------------------------------------
```
The data distribution within a IVF-flat benchmark resulted in a select_k time of ~24ms. 

### scope:
* additional parameter added to select_k to optionally pass individual row lengths for every batch entry. This parameter is utilized by both IVF-Flat and IVF-PQ and results in a ~2x speedup (50 nodes out of 5000) of the final `select_k`. 
* refactor ivf-flat search to work with 32bit indices by storing positions instead of actual indices. This allows to utilize 32bit index type select_k for ~10x speedup in the final `select_k`.

FYI @tfeher @achirkin 

### not in scope:
* General optimization of select_k: In the current implementation there is no difference in the type of the payload and the actual index type. Especially the type of the histogram has a large effect on performance (due to the atomics).

Authors:
  - Malte Förster (https://github.com/mfoerste4)

Approvers:
  - Tamas Bela Feher (https://github.com/tfeher)

URL: #2221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpp improvement Improvement / enhancement to an existing function non-breaking Non-breaking change python
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants