Add CUDA-accelerated indexing and search#1
Merged
Conversation
raphaelsty
force-pushed
the
feat/cuda-indexing
branch
from
March 18, 2026 22:41
c07c059 to
3c28429
Compare
Feature-gated `cuda` support for GPU-accelerated BM25 indexing and search.
Zero quality loss — identical NDCG@10 to CPU on all BEIR datasets.
## Indexing (MS MARCO 8.8M docs, H100 + 144 cores)
Pipeline: parallel tokenization (rayon) → parallel vocab building
(thread-local HashSets) → stable counting sort → posting lists.
Key optimizations:
- Zero-alloc ASCII tokenizer with stack-allocated token buffer
- FxHashMap stem cache: each unique token stemmed once per thread
- Unsafe FFI PyO3 extraction (44x faster) + GIL release
- Parallel drop of intermediate data (44M strings)
Result: 63.6s → 10.5s (6x faster, 845K d/s)
## Search (MS MARCO 8.8M docs, 6,980 queries, H100)
Upload index to GPU once (~2GB resident), then query via CUDA kernels:
- Fused multi-term BM25 scoring kernel (single launch for all terms)
- Per-thread top-k heaps in registers → block merge in shared memory
- Downloads only k results per query (~80 bytes) instead of full scores
Result: 12.8ms → 0.34ms per query (38x faster, 2,970 q/s)
vs bm25s: 214x faster search on MS MARCO
## API
Rust:
cargo add bm25x --features cuda
let gpu = index.to_gpu_search_index()?;
let results = index.search_gpu(&mut gpu, query, k);
Python:
pip install bm25x # build with: maturin develop --features cuda
index.upload_to_gpu()
index.search(query, k) # auto-dispatches to GPU
## Benchmarks (all BEIR datasets, H100)
Dataset | Index (d/s) | Search (q/s) | NDCG@10
NFCorpus | 32,551 | 6,940 | 0.3287
SciFact | 57,570 | 5,682 | 0.6904
SciDocs | 68,360 | 6,197 | 0.1600
FiQA | 205,115 | 5,935 | 0.2514
MS MARCO | 295,458 | 3,430 | 0.2240
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
raphaelsty
force-pushed
the
feat/cuda-indexing
branch
from
March 18, 2026 22:45
3c28429 to
8e6b175
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cudasupport for GPU-accelerated BM25 indexing and searchIndexing optimizations
Search optimizations
Benchmarks (H100, all BEIR datasets)
API
Rust:
Python:
Test plan
--features cuda🤖 Generated with Claude Code