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

Unify use of OpenMP for HNSW threading models #724

Open
wants to merge 6 commits into
base: branch-25.04
Choose a base branch
from

Conversation

divyegala
Copy link
Member

@divyegala divyegala commented Feb 25, 2025

cuvs_bench hnswlib wrapper was using a custom threading pool while cuvs hnsw wrapper was using OpenMP for parallelism. This was causing unexpected deviations in measured timings.

Furthermore, the default for # of threads in cuvs_bench hnswlib wrapper search params was 1, which is incorrect.

@divyegala divyegala added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Feb 25, 2025
@divyegala divyegala self-assigned this Feb 25, 2025
@divyegala divyegala requested review from a team as code owners February 25, 2025 20:43
Copy link
Contributor

@achirkin achirkin left a comment

Choose a reason for hiding this comment

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

Thanks, very welcome change, but I have a few questions to make sure it works as intended.

  • I don't see any changes to CMakeLists. Is the benchmark executable already linked with openmp?
  • Can we now remove cpp/bench/ann/src/common/thread_pool.hpp completely?

@@ -66,13 +66,13 @@ class hnsw_lib : public algo<T> {
struct build_param {
int m;
int ef_construction;
int num_threads = omp_get_num_procs();
int num_threads = omp_get_max_threads();
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the consequences of switching from omp_get_num_procs() to omp_get_max_threads() with respect to the SMT/hyperthreading?
Does hyperthreading make HNSW slower or faster?
Also, does OpenMP take into account whether the number of cores is limited by numactl?

Copy link
Member Author

@divyegala divyegala Feb 26, 2025

Choose a reason for hiding this comment

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

Answering your questions one by one:

I don't see any changes to CMakeLists. Is the benchmark executable already linked with openmp?

All benchmark executables link to OpenMP already.

Can we now remove cpp/bench/ann/src/common/thread_pool.hpp completely?

No, unfortunately the FAISS wrappers still use it.

What are the consequences of switching from omp_get_num_procs() to omp_get_max_threads() with respect to the SMT/hyperthreading?

omp_get_num_procs() only returns number of physical cores. The difference in search times are very visibly apparent when accounting for thread usage to be all available hyperthreads vs just using physical cores. It makes HNSW faster.

Also, does OpenMP take into account whether the number of cores is limited by numactl?

No, it does not. We would either have to write a custom implementation or use some thread-pool library that can account for this. I think it would fall out of the scope of this PR and would be a general design philosophy discussion that we would have to undertake with the team, as we use OpenMP in quite a lot of places outside of HNSW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpp improvement Improves an existing functionality non-breaking Introduces a non-breaking change Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants