From bb7a0511da41576ee1b26137465b3c8fc5189d4b Mon Sep 17 00:00:00 2001 From: Heisenberg Date: Fri, 6 Sep 2019 16:13:44 +0800 Subject: [PATCH 1/2] MS-453 GPU search error when nprobe set more than 1024 Former-commit-id: 455e79a2aa392610634a402b7c55a077a7c5eaca --- cpp/CHANGELOG.md | 1 + cpp/src/wrapper/knowhere/vec_impl.cpp | 7 +++++-- cpp/src/wrapper/knowhere/vec_index.cpp | 27 +++++++++++++++++++++++++- cpp/src/wrapper/knowhere/vec_index.h | 4 ++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index d599b5256c..7225e4369d 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -26,6 +26,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-467 - mysql db test failed - MS-470 - Drop index success, which table not created - MS-471 - code coverage run failed +- MS-453 - GPU search error when nprobe set more than 1024 ## Improvement - MS-327 - Clean code for milvus diff --git a/cpp/src/wrapper/knowhere/vec_impl.cpp b/cpp/src/wrapper/knowhere/vec_impl.cpp index 0989178783..edb20cf8a3 100644 --- a/cpp/src/wrapper/knowhere/vec_impl.cpp +++ b/cpp/src/wrapper/knowhere/vec_impl.cpp @@ -72,8 +72,11 @@ server::KnowhereError VecIndexImpl::Search(const long &nq, const float *xq, floa auto k = cfg["k"].as(); auto dataset = GenDataset(nq, dim, xq); - Config search_cfg; - auto res = index_->Search(dataset, cfg); + Config search_cfg = cfg; + + AutoTurnParams(type, search_cfg); + + auto res = index_->Search(dataset, search_cfg); auto ids_array = res->array()[0]; auto dis_array = res->array()[1]; diff --git a/cpp/src/wrapper/knowhere/vec_index.cpp b/cpp/src/wrapper/knowhere/vec_index.cpp index 0665ffc166..2e4be3f254 100644 --- a/cpp/src/wrapper/knowhere/vec_index.cpp +++ b/cpp/src/wrapper/knowhere/vec_index.cpp @@ -71,7 +71,7 @@ size_t FileIOWriter::operator()(void *ptr, size_t size) { } -VecIndexPtr GetVecIndexFactory(const IndexType &type, const Config& cfg) { +VecIndexPtr GetVecIndexFactory(const IndexType &type, const Config &cfg) { std::shared_ptr index; auto gpu_device = cfg.get_with_default("gpu_id", 0); switch (type) { @@ -235,6 +235,31 @@ void AutoGenParams(const IndexType &type, const long &size, zilliz::knowhere::Co } } +#if CUDA_VERSION > 9000 +#define GPU_MAX_NRPOBE 2048 +#else +#define GPU_MAX_NRPOBE 1024 +#endif + +void AutoTurnParams(const IndexType &type, Config &cfg) { + switch (type) { + case IndexType::FAISS_IVFSQ8_GPU: + case IndexType::FAISS_IVFFLAT_GPU: + case IndexType::FAISS_IVFPQ_GPU: { + if (cfg.get_with_default("nprobe", 0) != 0) { + auto nprobe = cfg["nprobe"].as(); + if (nprobe > GPU_MAX_NRPOBE) { + WRAPPER_LOG_ERROR << "When search with GPU, nprobe shoud be no more than " << GPU_MAX_NRPOBE << ", but you passed " << nprobe + << ". Search with " << GPU_MAX_NRPOBE << " instead"; + cfg.insert_or_assign("nprobe", GPU_MAX_NRPOBE); + } + } + break; + } + default:break; + } +} + IndexType ConvertToCpuIndexType(const IndexType &type) { // TODO(linxj): add IDMAP switch (type) { diff --git a/cpp/src/wrapper/knowhere/vec_index.h b/cpp/src/wrapper/knowhere/vec_index.h index c69106159a..b5170acb72 100644 --- a/cpp/src/wrapper/knowhere/vec_index.h +++ b/cpp/src/wrapper/knowhere/vec_index.h @@ -14,6 +14,8 @@ #include "knowhere/common/config.h" #include "knowhere/common/binary_set.h" +#include "cuda.h" + namespace zilliz { namespace milvus { @@ -90,6 +92,8 @@ extern VecIndexPtr LoadVecIndex(const IndexType &index_type, const zilliz::knowh extern void AutoGenParams(const IndexType& type, const long& size, Config& cfg); +extern void AutoTurnParams(const IndexType& type, Config& cfg); + extern IndexType ConvertToCpuIndexType(const IndexType& type); extern IndexType ConvertToGpuIndexType(const IndexType& type); From ae8c5f8b777fe70a4adad24c35aca355911199a4 Mon Sep 17 00:00:00 2001 From: Heisenberg Date: Fri, 6 Sep 2019 16:38:44 +0800 Subject: [PATCH 2/2] MS-453 GPU search error when nprobe set more than 1024 Former-commit-id: cd871f4c238febe90a02a81c0b0d311d88729839 --- cpp/src/wrapper/knowhere/vec_impl.cpp | 2 +- cpp/src/wrapper/knowhere/vec_index.cpp | 4 ++-- cpp/src/wrapper/knowhere/vec_index.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/src/wrapper/knowhere/vec_impl.cpp b/cpp/src/wrapper/knowhere/vec_impl.cpp index edb20cf8a3..cecf9dc8ce 100644 --- a/cpp/src/wrapper/knowhere/vec_impl.cpp +++ b/cpp/src/wrapper/knowhere/vec_impl.cpp @@ -74,7 +74,7 @@ server::KnowhereError VecIndexImpl::Search(const long &nq, const float *xq, floa Config search_cfg = cfg; - AutoTurnParams(type, search_cfg); + ParameterValidation(type, search_cfg); auto res = index_->Search(dataset, search_cfg); auto ids_array = res->array()[0]; diff --git a/cpp/src/wrapper/knowhere/vec_index.cpp b/cpp/src/wrapper/knowhere/vec_index.cpp index 2e4be3f254..95ca7edb90 100644 --- a/cpp/src/wrapper/knowhere/vec_index.cpp +++ b/cpp/src/wrapper/knowhere/vec_index.cpp @@ -241,7 +241,7 @@ void AutoGenParams(const IndexType &type, const long &size, zilliz::knowhere::Co #define GPU_MAX_NRPOBE 1024 #endif -void AutoTurnParams(const IndexType &type, Config &cfg) { +void ParameterValidation(const IndexType &type, Config &cfg) { switch (type) { case IndexType::FAISS_IVFSQ8_GPU: case IndexType::FAISS_IVFFLAT_GPU: @@ -249,7 +249,7 @@ void AutoTurnParams(const IndexType &type, Config &cfg) { if (cfg.get_with_default("nprobe", 0) != 0) { auto nprobe = cfg["nprobe"].as(); if (nprobe > GPU_MAX_NRPOBE) { - WRAPPER_LOG_ERROR << "When search with GPU, nprobe shoud be no more than " << GPU_MAX_NRPOBE << ", but you passed " << nprobe + WRAPPER_LOG_WARNING << "When search with GPU, nprobe shoud be no more than " << GPU_MAX_NRPOBE << ", but you passed " << nprobe << ". Search with " << GPU_MAX_NRPOBE << " instead"; cfg.insert_or_assign("nprobe", GPU_MAX_NRPOBE); } diff --git a/cpp/src/wrapper/knowhere/vec_index.h b/cpp/src/wrapper/knowhere/vec_index.h index b5170acb72..c2b7d9e890 100644 --- a/cpp/src/wrapper/knowhere/vec_index.h +++ b/cpp/src/wrapper/knowhere/vec_index.h @@ -92,7 +92,7 @@ extern VecIndexPtr LoadVecIndex(const IndexType &index_type, const zilliz::knowh extern void AutoGenParams(const IndexType& type, const long& size, Config& cfg); -extern void AutoTurnParams(const IndexType& type, Config& cfg); +extern void ParameterValidation(const IndexType& type, Config& cfg); extern IndexType ConvertToCpuIndexType(const IndexType& type); extern IndexType ConvertToGpuIndexType(const IndexType& type);