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

Commit

Permalink
Threadpool based HNSW insert
Browse files Browse the repository at this point in the history
Signed-off-by: Filip <[email protected]>
  • Loading branch information
filip-halt committed Jul 13, 2023
1 parent 470de66 commit b7fc7a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
.vscode
docker-compose-devcontainer.yml
docker-compose-devcontainer.yml.tmp
.devcontainer/

*.code-workspace

Expand Down
12 changes: 10 additions & 2 deletions src/index/hnsw/hnsw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ class HnswIndexNode : public IndexNode {
auto hnsw_cfg = static_cast<const HnswConfig&>(cfg);
index_->addPoint(tensor, 0);

#pragma omp parallel for
std::vector<std::future<void>> futures;
futures.reserve(rows);

for (int i = 1; i < rows; ++i) {
index_->addPoint(((const char*)tensor + index_->data_size_ * i), i);
futures.push_back(pool_->push(
[&, idx = i]() { index_->addPoint(((const char*)tensor + index_->data_size_ * idx), idx); }));
}

for (auto& future : futures) {
future.get();
}

build_time.RecordSection("");
LOG_KNOWHERE_INFO_ << "HNSW built with #points num:" << index_->max_elements_ << " #M:" << index_->M_
<< " #max level:" << index_->maxlevel_ << " #ef_construction:" << index_->ef_construction_
Expand Down

0 comments on commit b7fc7a8

Please sign in to comment.