From 759a951e4bb4f86b78d46e2c76744fdef05f759f Mon Sep 17 00:00:00 2001 From: "xiaojun.lin" Date: Mon, 25 Nov 2019 15:23:50 +0800 Subject: [PATCH 1/5] fix --- core/build.sh | 2 +- .../knowhere/index/vector_index/nsg/NSG.cpp | 60 +++++++++++-------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/core/build.sh b/core/build.sh index 3afb5d1b37..badcc5a032 100755 --- a/core/build.sh +++ b/core/build.sh @@ -56,7 +56,7 @@ while getopts "p:d:t:f:ulrcgjhxzme" arg; do USE_JFROG_CACHE="ON" ;; x) - CUSTOMIZATION="OFF" # force use ori faiss + CUSTOMIZATION="ON" ;; g) GPU_VERSION="ON" diff --git a/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp b/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp index bdf538c204..002e160562 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp @@ -718,45 +718,55 @@ NsgIndex::Search(const float* query, const unsigned& nq, const unsigned& dim, co int64_t* ids, SearchParams& params) { std::vector> resset(nq); + params.search_length = k; TimeRecorder rc("search"); - if (nq == 1) { + // TODO(linxj): when to use openmp + if (nq <= 4) { GetNeighbors(query, resset[0], nsg, ¶ms); } else { -//#pragma omp parallel for schedule(dynamic, 50) #pragma omp parallel for for (unsigned int i = 0; i < nq; ++i) { - // TODO(linxj): when to use openmp auto single_query = query + i * dim; GetNeighbors(single_query, resset[i], nsg, ¶ms); } } - rc.ElapseFromBegin("cost"); - + rc.RecordSection("cost"); for (unsigned int i = 0; i < nq; ++i) { - for (unsigned int j = 0; j < k; ++j) { - // ids[i * k + j] = resset[i][j].id; - - // Fix(linxj): bug, reset[i][j] out of range - ids[i * k + j] = ids_[resset[i][j].id]; - dist[i * k + j] = resset[i][j].distance; + int64_t var = resset[i].size() - k; + if (var >= 0) { + for (unsigned int j = 0; j < k; ++j) { + ids[i * k + j] = ids_[resset[i][j].id]; + dist[i * k + j] = resset[i][j].distance; + } + } + else { + for (unsigned int j = 0; j < resset[i].size(); ++j) { + ids[i * k + j] = ids_[resset[i][j].id]; + dist[i * k + j] = resset[i][j].distance; + } + for (unsigned int j = resset[i].size(); j < k; ++j) { + ids[i * k + j] = -1; + dist[i * k + j] = -1; + } } } + rc.RecordSection("merge"); - //>> Debug: test single insert - // int x_0 = resset[0].size(); - // for (int l = 0; l < resset[0].size(); ++l) { - // resset[0].pop_back(); - //} - // resset.clear(); +//>> Debug: test single insert +// int x_0 = resset[0].size(); +// for (int l = 0; l < resset[0].size(); ++l) { +// resset[0].pop_back(); +//} +// resset.clear(); - // ProfilerStart("xx.prof"); - // std::vector resset; - // GetNeighbors(query, resset, nsg, ¶ms); - // for (int i = 0; i < k; ++i) { - // ids[i] = resset[i].id; - // dist[i] = resset[i].distance; - //} - // ProfilerStop(); +// ProfilerStart("xx.prof"); +// std::vector resset; +// GetNeighbors(query, resset, nsg, ¶ms); +// for (int i = 0; i < k; ++i) { +// ids[i] = resset[i].id; +// dist[i] = resset[i].distance; +//} +// ProfilerStop(); } void From 6d0d67ca95a4deec66ffe3add3b2eaa239fd74dd Mon Sep 17 00:00:00 2001 From: "xiaojun.lin" Date: Mon, 25 Nov 2019 15:28:25 +0800 Subject: [PATCH 2/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53e427dcb9..bc2be5edf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Please mark all change in change log and use the ticket from JIRA. - \#440 - Query API in customization still uses old version - \#440 - Server cannot startup with gpu_resource_config.enable=false in GPU version - \#458 - Index data is not compatible between 0.5 and 0.6 +- \#465 - Server hang caused by searching with nsg index - \#486 - gpu no usage during index building ## Feature From 6546bf5af8b97986ea8a542858f4c659a1f3dfb5 Mon Sep 17 00:00:00 2001 From: "xiaojun.lin" Date: Mon, 25 Nov 2019 15:30:30 +0800 Subject: [PATCH 3/5] format code --- .../knowhere/index/vector_index/nsg/NSG.cpp | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp b/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp index 002e160562..5872178e96 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp @@ -738,8 +738,7 @@ NsgIndex::Search(const float* query, const unsigned& nq, const unsigned& dim, co ids[i * k + j] = ids_[resset[i][j].id]; dist[i * k + j] = resset[i][j].distance; } - } - else { + } else { for (unsigned int j = 0; j < resset[i].size(); ++j) { ids[i * k + j] = ids_[resset[i][j].id]; dist[i * k + j] = resset[i][j].distance; @@ -752,21 +751,21 @@ NsgIndex::Search(const float* query, const unsigned& nq, const unsigned& dim, co } rc.RecordSection("merge"); -//>> Debug: test single insert -// int x_0 = resset[0].size(); -// for (int l = 0; l < resset[0].size(); ++l) { -// resset[0].pop_back(); -//} -// resset.clear(); + //>> Debug: test single insert + // int x_0 = resset[0].size(); + // for (int l = 0; l < resset[0].size(); ++l) { + // resset[0].pop_back(); + //} + // resset.clear(); -// ProfilerStart("xx.prof"); -// std::vector resset; -// GetNeighbors(query, resset, nsg, ¶ms); -// for (int i = 0; i < k; ++i) { -// ids[i] = resset[i].id; -// dist[i] = resset[i].distance; -//} -// ProfilerStop(); + // ProfilerStart("xx.prof"); + // std::vector resset; + // GetNeighbors(query, resset, nsg, ¶ms); + // for (int i = 0; i < k; ++i) { + // ids[i] = resset[i].id; + // dist[i] = resset[i].distance; + //} + // ProfilerStop(); } void From 651b05a06d6471da7fe551acac894fd9cecefbf9 Mon Sep 17 00:00:00 2001 From: "xiaojun.lin" Date: Mon, 25 Nov 2019 16:44:00 +0800 Subject: [PATCH 4/5] review change --- .../index/knowhere/knowhere/common/Timer.cpp | 37 +++++++------------ .../knowhere/index/vector_index/nsg/NSG.cpp | 4 +- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/core/src/index/knowhere/knowhere/common/Timer.cpp b/core/src/index/knowhere/knowhere/common/Timer.cpp index fefe1e1705..169b55b56f 100644 --- a/core/src/index/knowhere/knowhere/common/Timer.cpp +++ b/core/src/index/knowhere/knowhere/common/Timer.cpp @@ -18,6 +18,7 @@ #include // TODO(linxj): using Log instead #include "knowhere/common/Timer.h" +#include "knowhere/common/Log.h" namespace knowhere { @@ -51,30 +52,18 @@ TimeRecorder::PrintTimeRecord(const std::string& msg, double span) { std::cout << str_log << std::endl; break; } - // case 1: { - // SERVER_LOG_DEBUG << str_log; - // break; - //} - // case 2: { - // SERVER_LOG_INFO << str_log; - // break; - //} - // case 3: { - // SERVER_LOG_WARNING << str_log; - // break; - //} - // case 4: { - // SERVER_LOG_ERROR << str_log; - // break; - //} - // case 5: { - // SERVER_LOG_FATAL << str_log; - // break; - //} - // default: { - // SERVER_LOG_INFO << str_log; - // break; - //} + case 1: { + KNOWHERE_LOG_DEBUG << str_log; + break; + } + // case 2: { + // KNOWHERE_LOG_TRACE << str_log; + // break; + // } + // case 3: { + // KNOWHERE_LOG_WARNING << str_log; + // break; + // } } } diff --git a/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp b/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp index 5872178e96..b4e00e57b7 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/nsg/NSG.cpp @@ -719,7 +719,7 @@ NsgIndex::Search(const float* query, const unsigned& nq, const unsigned& dim, co std::vector> resset(nq); params.search_length = k; - TimeRecorder rc("search"); + TimeRecorder rc("NsgIndex::search", 1); // TODO(linxj): when to use openmp if (nq <= 4) { GetNeighbors(query, resset[0], nsg, ¶ms); @@ -730,7 +730,7 @@ NsgIndex::Search(const float* query, const unsigned& nq, const unsigned& dim, co GetNeighbors(single_query, resset[i], nsg, ¶ms); } } - rc.RecordSection("cost"); + rc.RecordSection("search"); for (unsigned int i = 0; i < nq; ++i) { int64_t var = resset[i].size() - k; if (var >= 0) { From 60c59d309953ca49e4683d09b6ec07f2d9b07477 Mon Sep 17 00:00:00 2001 From: "xiaojun.lin" Date: Mon, 25 Nov 2019 18:41:23 +0800 Subject: [PATCH 5/5] format code --- .../index/knowhere/knowhere/common/Timer.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/index/knowhere/knowhere/common/Timer.cpp b/core/src/index/knowhere/knowhere/common/Timer.cpp index 169b55b56f..141e1ceed6 100644 --- a/core/src/index/knowhere/knowhere/common/Timer.cpp +++ b/core/src/index/knowhere/knowhere/common/Timer.cpp @@ -17,8 +17,8 @@ #include // TODO(linxj): using Log instead -#include "knowhere/common/Timer.h" #include "knowhere/common/Log.h" +#include "knowhere/common/Timer.h" namespace knowhere { @@ -56,14 +56,14 @@ TimeRecorder::PrintTimeRecord(const std::string& msg, double span) { KNOWHERE_LOG_DEBUG << str_log; break; } - // case 2: { - // KNOWHERE_LOG_TRACE << str_log; - // break; - // } - // case 3: { - // KNOWHERE_LOG_WARNING << str_log; - // break; - // } + // case 2: { + // KNOWHERE_LOG_TRACE << str_log; + // break; + // } + // case 3: { + // KNOWHERE_LOG_WARNING << str_log; + // break; + // } } }