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

fix openblas thread version ivf build performance degradation #741

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions include/knowhere/comp/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#pragma once

#include <omp.h>

#ifdef __linux__
#include <cblas.h>
#include <sys/resource.h>
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
Expand Down Expand Up @@ -230,7 +230,9 @@ class ThreadPool {

class ScopedOmpSetter {
int omp_before;

#if defined(OPENBLAS_OS_LINUX)
int blas_thread_before;
#endif
public:
explicit ScopedOmpSetter(int num_threads = 0) {
if (build_pool_ == nullptr) { // this should not happen in prod
Expand All @@ -239,10 +241,18 @@ class ThreadPool {
omp_before = build_pool_->size();
}

#if defined(OPENBLAS_OS_LINUX)
blas_thread_before = openblas_get_num_threads();
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we set the blas_thread_before same way as omp_before

openblas_set_num_threads(1);
#endif

omp_set_num_threads(num_threads <= 0 ? omp_before : num_threads);
}
~ScopedOmpSetter() {
omp_set_num_threads(omp_before);
#if defined(OPENBLAS_OS_LINUX)
openblas_set_num_threads(blas_thread_before);
#endif
}
};

Expand Down
Loading