Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit b7fc7a8

Browse files
committed
Threadpool based HNSW insert
Signed-off-by: Filip <[email protected]>
1 parent 470de66 commit b7fc7a8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
.vscode
1313
docker-compose-devcontainer.yml
1414
docker-compose-devcontainer.yml.tmp
15+
.devcontainer/
1516

1617
*.code-workspace
1718

src/index/hnsw/hnsw.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,18 @@ class HnswIndexNode : public IndexNode {
8383
auto hnsw_cfg = static_cast<const HnswConfig&>(cfg);
8484
index_->addPoint(tensor, 0);
8585

86-
#pragma omp parallel for
86+
std::vector<std::future<void>> futures;
87+
futures.reserve(rows);
88+
8789
for (int i = 1; i < rows; ++i) {
88-
index_->addPoint(((const char*)tensor + index_->data_size_ * i), i);
90+
futures.push_back(pool_->push(
91+
[&, idx = i]() { index_->addPoint(((const char*)tensor + index_->data_size_ * idx), idx); }));
8992
}
93+
94+
for (auto& future : futures) {
95+
future.get();
96+
}
97+
9098
build_time.RecordSection("");
9199
LOG_KNOWHERE_INFO_ << "HNSW built with #points num:" << index_->max_elements_ << " #M:" << index_->M_
92100
<< " #max level:" << index_->maxlevel_ << " #ef_construction:" << index_->ef_construction_

0 commit comments

Comments
 (0)