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

Commit 6eb1fb0

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

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.gitignore

+1
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

+11-2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,19 @@ 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([&, idx = i]() {
91+
index_->addPoint(((const char*)tensor + index_->data_size_ * idx), idx);
92+
}));
8993
}
94+
95+
for (auto& future : futures) {
96+
future.get();
97+
}
98+
9099
build_time.RecordSection("");
91100
LOG_KNOWHERE_INFO_ << "HNSW built with #points num:" << index_->max_elements_ << " #M:" << index_->M_
92101
<< " #max level:" << index_->maxlevel_ << " #ef_construction:" << index_->ef_construction_

0 commit comments

Comments
 (0)