Skip to content

initizl api to change global number of threads #715

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/VecSim/vec_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ extern "C" void VecSim_SetLogCallbackFunction(logCallbackFunction callback) {

extern "C" void VecSim_SetWriteMode(VecSimWriteMode mode) { VecSimIndex::setWriteMode(mode); }

extern "C" void VecSim_SetNumThreads(size_t new_num_threads) {
VecSimIndex::setNumThreads(new_num_threads);
}

static VecSimResolveCode _ResolveParams_EFRuntime(VecSimAlgo index_type, VecSimRawParam rparam,
VecSimQueryParams *qparams,
VecsimQueryType query_type) {
Expand Down
6 changes: 6 additions & 0 deletions src/VecSim/vec_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ void VecSim_SetTestLogContext(const char *test_name, const char *test_type);
*/
void VecSim_SetWriteMode(VecSimWriteMode mode);

/**
* num_threads: new threads
* TODO: is 0 allowed
*/
void VecSim_SetNumThreads(size_t new_num_threads);

#ifdef __cplusplus
}
#endif
6 changes: 6 additions & 0 deletions src/VecSim/vec_sim_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ struct VecSimIndexInterface : public VecsimBaseObject {
inline static void setWriteMode(VecSimWriteMode mode) {
VecSimIndexInterface::asyncWriteMode = mode;
}

inline static void setNumThreads(size_t new_num_threads) {

// iterate all registered thpools and update their num_threads
VecSimThreadPool::setNumThreads(new_num_threads);
}
#ifdef BUILD_TESTS
virtual void fitMemory() = 0;
#endif
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_svs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,30 @@ TYPED_TEST(SVSTest, svs_vector_add_test) {

VecSimIndex_Free(index);
}
TYPED_TEST(SVSTest, svs_miltiple_indexes) {

size_t dim = 4;

SVSParams params = {
.dim = dim,
.metric = VecSimMetric_IP,
/* SVS-Vamana specifics */
.alpha = 1.2,
.graph_max_degree = 64,
.construction_window_size = 20,
.max_candidate_pool_size = 1024,
.prune_to = 60,
.use_search_history = VecSimOption_ENABLE,
};

VecSimIndex *index = this->CreateNewIndex(params);
ASSERT_INDEX(index);
VecSimIndex *index2 = this->CreateNewIndex(params);
ASSERT_INDEX(index2);

VecSimIndex_Free(index);
VecSimIndex_Free(index2);
}

TYPED_TEST(SVSTest, svs_vector_update_test) {
size_t dim = 4;
Expand Down
Loading