Skip to content

Commit 5734ebe

Browse files
authored
share the pool externally to ensure that other tasks can be scheduled (#1192)
Signed-off-by: xianliang.li <xianliang.li@zilliz.com>
1 parent 0445e68 commit 5734ebe

5 files changed

Lines changed: 29 additions & 4 deletions

File tree

cmake/libs/libcardinal.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use short SHA1 as version
2-
set(CARDINAL_VERSION v2.5.7 )
2+
set(CARDINAL_VERSION v2.5.8)
33
set(CARDINAL_REPO_URL "https://github.com/zilliztech/cardinal.git")
44

55
set(CARDINAL_REPO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cardinal")

include/knowhere/comp/task.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <functional>
1313
#include <memory>
1414
#include <vector>
15+
16+
#include "folly/executors/CPUThreadPoolExecutor.h"
17+
1518
namespace knowhere {
1619

1720
void
@@ -26,6 +29,13 @@ size_t
2629
GetSearchThreadPoolSize();
2730
size_t
2831
GetBuildThreadPoolSize();
32+
33+
folly::CPUThreadPoolExecutor&
34+
GetSearchThreadPool();
35+
36+
folly::CPUThreadPoolExecutor&
37+
GetBuildThreadPool();
38+
2939
class ThreadPool {
3040
public:
3141
class ScopedOmpSetter {

include/knowhere/comp/thread_pool.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ class ThreadPool {
141141
return pool_.getPendingTaskCount();
142142
}
143143

144+
folly::CPUThreadPoolExecutor&
145+
GetPool() {
146+
return pool_;
147+
}
148+
144149
void
145150
SetNumThreads(uint32_t num_threads) {
146151
if (num_threads == 0) {

python/knowhere/knowhere.i

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ typedef uint64_t size_t;
3737
#include <knowhere/comp/brute_force.h>
3838
#include <knowhere/comp/knowhere_config.h>
3939
#include <knowhere/comp/local_file_manager.h>
40-
#include <knowhere/comp/task.h>
4140
#include <knowhere/comp/index_param.h>
4241
#include <fstream>
4342
#include <string>
@@ -691,12 +690,12 @@ SetSimdType(const std::string type) {
691690

692691
void
693692
SetBuildThreadPool(uint32_t num_threads) {
694-
knowhere::InitBuildThreadPool(num_threads);
693+
knowhere::KnowhereConfig::SetBuildThreadPoolSize(num_threads);
695694
}
696695

697696
void
698697
SetSearchThreadPool(uint32_t num_threads) {
699-
knowhere::InitSearchThreadPool(num_threads);
698+
knowhere::KnowhereConfig::SetSearchThreadPoolSize(num_threads);
700699
}
701700

702701
%}

src/common/thread/thread.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <thread>
1919
#include <utility>
2020

21+
#include "folly/executors/CPUThreadPoolExecutor.h"
2122
#include "knowhere/comp/thread_pool.h"
2223

2324
namespace knowhere {
@@ -57,6 +58,16 @@ InitBuildThreadPool(uint32_t num_threads) {
5758
ThreadPool::InitGlobalBuildThreadPool(num_threads);
5859
}
5960

61+
folly::CPUThreadPoolExecutor&
62+
GetBuildThreadPool() {
63+
return ThreadPool::GetGlobalBuildThreadPool()->GetPool();
64+
}
65+
66+
folly::CPUThreadPoolExecutor&
67+
GetSearchThreadPool() {
68+
return ThreadPool::GetGlobalSearchThreadPool()->GetPool();
69+
}
70+
6071
void
6172
InitSearchThreadPool(uint32_t num_threads) {
6273
ThreadPool::InitGlobalSearchThreadPool(num_threads);

0 commit comments

Comments
 (0)