Skip to content

Refactor thread pool creation to validate thread count against centroids#329

Merged
rfsaliev merged 3 commits into
mainfrom
rfsaliev/fix-ivf
May 12, 2026
Merged

Refactor thread pool creation to validate thread count against centroids#329
rfsaliev merged 3 commits into
mainfrom
rfsaliev/fix-ivf

Conversation

@rfsaliev
Copy link
Copy Markdown
Member

@rfsaliev rfsaliev commented May 11, 2026

This pull request updates the initialization logic for the inter-query thread pool in the IVFIndex class 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:

  • Added a generic static method make_inter_query_threadpool that 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)
  • Added a specialization for size_t thread 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 )
  • Added a specialization for thread pool prototypes that support resizing, which also logs a warning and resizes the thread pool if needed. (include/svs/index/ivf/index.hR577-R629)

Integration with constructor:

  • Updated the IVFIndex constructor to use the new make_inter_query_threadpool method, ensuring thread pool size validation and logging are applied during initialization. (include/svs/index/ivf/index.hL151-R153)

rfsaliev and others added 2 commits May 11, 2026 12:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 IVFIndex construction through a new make_inter_query_threadpool helper.
  • Add overloads to either throw (generic prototypes) or clamp-with-warning (size_t / resizable prototypes) when requested threads exceed centroid count.

Comment thread include/svs/index/ivf/index.h Outdated
Comment thread include/svs/index/ivf/index.h
@rfsaliev rfsaliev merged commit dc52d34 into main May 12, 2026
23 of 24 checks passed
@rfsaliev rfsaliev deleted the rfsaliev/fix-ivf branch May 12, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants