Refactor thread pool creation to validate thread count against centroids#329
Merged
Conversation
Co-Authored-By: mnorris11 <mnorris@meta.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors svs::index::ivf::IVFIndex inter-query thread pool initialization to validate (and in some cases clamp) the thread count so it cannot exceed the number of centroids, preventing invalid centroid partitioning during search initialization.
Changes:
- Route
IVFIndexconstruction through a newmake_inter_query_threadpoolhelper. - Add overloads to either throw (generic prototypes) or clamp-with-warning (size_t / resizable prototypes) when requested threads exceed centroid count.
ibhati
approved these changes
May 11, 2026
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.
This pull request updates the initialization logic for the inter-query thread pool in the
IVFIndexclass to better handle cases where the number of threads may exceed the number of centroids, and to provide improved validation and logging. The changes introduce a new static factory method,make_inter_query_threadpool, with multiple overloads to handle different types of thread pool prototypes and to ensure the thread pool size does not exceed the number of centroids.Note: Change in PR is inspired by #324 made by @mnorris11
Thread pool initialization improvements:
make_inter_query_threadpoolthat validates the requested thread pool size against the number of centroids, throwing an exception if there are too many threads. (include/svs/index/ivf/index.hR577-R629)size_tthread pool prototypes, which automatically reduces the thread pool size to match the number of centroids and logs a warning if resizing is necessary. ( include/svs/index/ivf/index.hR577-R629 )Integration with constructor:
IVFIndexconstructor to use the newmake_inter_query_threadpoolmethod, ensuring thread pool size validation and logging are applied during initialization. (include/svs/index/ivf/index.hL151-R153)