From 6eb1fb00779ab9a2c076972cc8e17479950383a6 Mon Sep 17 00:00:00 2001 From: Filip Date: Wed, 12 Jul 2023 22:23:33 +0000 Subject: [PATCH] Threadpool based HNSW insert Signed-off-by: Filip --- .gitignore | 1 + src/index/hnsw/hnsw.cc | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5b5a5e347..256d07b2a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ .vscode docker-compose-devcontainer.yml docker-compose-devcontainer.yml.tmp +.devcontainer/ *.code-workspace diff --git a/src/index/hnsw/hnsw.cc b/src/index/hnsw/hnsw.cc index d5704ca54..ea9ebdcec 100644 --- a/src/index/hnsw/hnsw.cc +++ b/src/index/hnsw/hnsw.cc @@ -83,10 +83,19 @@ class HnswIndexNode : public IndexNode { auto hnsw_cfg = static_cast(cfg); index_->addPoint(tensor, 0); -#pragma omp parallel for + std::vector> 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_