From 248bdbf08d7d453c45f11781f181a0a5152729d5 Mon Sep 17 00:00:00 2001 From: Heisenberg Date: Fri, 6 Sep 2019 21:34:25 +0800 Subject: [PATCH 1/2] MS-496 Change the top_k limitation from 1024 to 2048 Former-commit-id: d63d6d69432888324424ed1daf0b1236a5243f4e --- cpp/CHANGELOG.md | 1 + cpp/src/utils/ValidationUtil.cpp | 2 +- cpp/src/wrapper/knowhere/vec_index.cpp | 54 +++++++++++++++++++++++++- cpp/src/wrapper/knowhere/vec_index.h | 14 +++---- 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 8d61f970b3..7f8aba8543 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -92,6 +92,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-487 - Define metric type in CreateTable - MS-488 - Improve code format in scheduler - MS-495 - cmake: integrated knowhere +- MS-496 - Change the top_k limitation from 1024 to 2048 ## New Feature - MS-343 - Implement ResourceMgr diff --git a/cpp/src/utils/ValidationUtil.cpp b/cpp/src/utils/ValidationUtil.cpp index 2245496903..bcd8eda260 100644 --- a/cpp/src/utils/ValidationUtil.cpp +++ b/cpp/src/utils/ValidationUtil.cpp @@ -94,7 +94,7 @@ ValidationUtil::ValidateTableIndexMetricType(int32_t metric_type) { ServerError ValidationUtil::ValidateSearchTopk(int64_t top_k, const engine::meta::TableSchema& table_schema) { - if (top_k <= 0 || top_k > 1024) { + if (top_k <= 0) { return SERVER_INVALID_TOPK; } diff --git a/cpp/src/wrapper/knowhere/vec_index.cpp b/cpp/src/wrapper/knowhere/vec_index.cpp index 95ca7edb90..33b41991cb 100644 --- a/cpp/src/wrapper/knowhere/vec_index.cpp +++ b/cpp/src/wrapper/knowhere/vec_index.cpp @@ -14,6 +14,8 @@ #include "vec_impl.h" #include "wrapper_log.h" +#include + namespace zilliz { namespace milvus { @@ -241,19 +243,67 @@ void AutoGenParams(const IndexType &type, const long &size, zilliz::knowhere::Co #define GPU_MAX_NRPOBE 1024 #endif +#define GPU_MAX_TOP_K GPU_MAX_NRPOBE +// TODO(yzb): may be changed latter +#define CPU_MAX_TOP_K GPU_MAX_TOP_K +#define DEFAULT_MAX_TOP_K GPU_MAX_TOP_K + void ParameterValidation(const IndexType &type, Config &cfg) { switch (type) { + case IndexType::FAISS_IVFFLAT_CPU: + case IndexType::FAISS_IVFPQ_CPU: + case IndexType::FAISS_IVFSQ8_CPU: { + //search on CPU + if (cfg.get_with_default("k", 0) != 0) { + auto k = cfg["k"].as(); + if (k > CPU_MAX_TOP_K) { + WRAPPER_LOG_WARNING << "When search with CPU, top_k shoud be no more than " << CPU_MAX_TOP_K + << ", but you passed " << k + << ". Search with " << CPU_MAX_TOP_K << " instead"; + cfg.insert_or_assign("k", CPU_MAX_TOP_K); + } + } + break; + } case IndexType::FAISS_IVFSQ8_GPU: case IndexType::FAISS_IVFFLAT_GPU: case IndexType::FAISS_IVFPQ_GPU: { + //search on GPU if (cfg.get_with_default("nprobe", 0) != 0) { auto nprobe = cfg["nprobe"].as(); if (nprobe > GPU_MAX_NRPOBE) { - 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"; + 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); } } + if (cfg.get_with_default("k", 0) != 0) { + auto k = cfg["k"].as(); + if (k > GPU_MAX_TOP_K) { + WRAPPER_LOG_WARNING << "When search with GPU, top_k shoud be no more than " << GPU_MAX_TOP_K + << ", but you passed " << k + << ". Search with " << GPU_MAX_TOP_K << " instead"; + cfg.insert_or_assign("k", GPU_MAX_TOP_K); + } + } + break; + } + case IndexType::FAISS_IDMAP: + case IndexType::FAISS_IVFFLAT_MIX: + case IndexType::SPTAG_KDT_RNT_CPU: + case IndexType::FAISS_IVFSQ8_MIX: + case IndexType::NSG_MIX: { + // TODO(yzb): need to figure out where it search + if (cfg.get_with_default("k", 0) != 0) { + auto k = cfg["k"].as(); + if (k > DEFAULT_MAX_TOP_K) { + WRAPPER_LOG_WARNING << "top_k shoud be no more than " << DEFAULT_MAX_TOP_K << ", but you passed " + << k + << ". Search with " << DEFAULT_MAX_TOP_K << " instead"; + cfg.insert_or_assign("k", DEFAULT_MAX_TOP_K); + } + } break; } default:break; diff --git a/cpp/src/wrapper/knowhere/vec_index.h b/cpp/src/wrapper/knowhere/vec_index.h index c2b7d9e890..8dc60e9638 100644 --- a/cpp/src/wrapper/knowhere/vec_index.h +++ b/cpp/src/wrapper/knowhere/vec_index.h @@ -14,8 +14,6 @@ #include "knowhere/common/config.h" #include "knowhere/common/binary_set.h" -#include "cuda.h" - namespace zilliz { namespace milvus { @@ -62,7 +60,7 @@ class VecIndex { long *ids, const Config &cfg = Config()) = 0; - virtual VecIndexPtr CopyToGpu(const int64_t& device_id, + virtual VecIndexPtr CopyToGpu(const int64_t &device_id, const Config &cfg = Config()) = 0; virtual VecIndexPtr CopyToCpu(const Config &cfg = Config()) = 0; @@ -86,16 +84,16 @@ extern server::KnowhereError write_index(VecIndexPtr index, const std::string &l extern VecIndexPtr read_index(const std::string &location); -extern VecIndexPtr GetVecIndexFactory(const IndexType &type, const Config& cfg = Config()); +extern VecIndexPtr GetVecIndexFactory(const IndexType &type, const Config &cfg = Config()); extern VecIndexPtr LoadVecIndex(const IndexType &index_type, const zilliz::knowhere::BinarySet &index_binary); -extern void AutoGenParams(const IndexType& type, const long& size, Config& cfg); +extern void AutoGenParams(const IndexType &type, const long &size, Config &cfg); -extern void ParameterValidation(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); +extern IndexType ConvertToCpuIndexType(const IndexType &type); +extern IndexType ConvertToGpuIndexType(const IndexType &type); } } From b167b004c78f0b374f3768f803b72a21d671bda2 Mon Sep 17 00:00:00 2001 From: Heisenberg Date: Sat, 7 Sep 2019 14:48:15 +0800 Subject: [PATCH 2/2] MS-496 Change the top_k limitation from 1024 to 2048 Former-commit-id: fc04ff846d7d4d8b1fb2b16e9dba4f5ddfbe9c9d --- cpp/src/utils/ValidationUtil.cpp | 2 +- cpp/src/wrapper/knowhere/vec_index.cpp | 46 -------------------------- 2 files changed, 1 insertion(+), 47 deletions(-) diff --git a/cpp/src/utils/ValidationUtil.cpp b/cpp/src/utils/ValidationUtil.cpp index 77fd25ae35..bce8143c1a 100644 --- a/cpp/src/utils/ValidationUtil.cpp +++ b/cpp/src/utils/ValidationUtil.cpp @@ -94,7 +94,7 @@ ValidationUtil::ValidateTableIndexMetricType(int32_t metric_type) { ErrorCode ValidationUtil::ValidateSearchTopk(int64_t top_k, const engine::meta::TableSchema& table_schema) { - if (top_k <= 0) { + if (top_k <= 0 || top_k > 2048) { return SERVER_INVALID_TOPK; } diff --git a/cpp/src/wrapper/knowhere/vec_index.cpp b/cpp/src/wrapper/knowhere/vec_index.cpp index 6cb081e8da..1ee8697d64 100644 --- a/cpp/src/wrapper/knowhere/vec_index.cpp +++ b/cpp/src/wrapper/knowhere/vec_index.cpp @@ -243,28 +243,8 @@ void AutoGenParams(const IndexType &type, const long &size, zilliz::knowhere::Co #define GPU_MAX_NRPOBE 1024 #endif -#define GPU_MAX_TOP_K GPU_MAX_NRPOBE -// TODO(yzb): may be changed latter -#define CPU_MAX_TOP_K GPU_MAX_TOP_K -#define DEFAULT_MAX_TOP_K GPU_MAX_TOP_K - void ParameterValidation(const IndexType &type, Config &cfg) { switch (type) { - case IndexType::FAISS_IVFFLAT_CPU: - case IndexType::FAISS_IVFPQ_CPU: - case IndexType::FAISS_IVFSQ8_CPU: { - //search on CPU - if (cfg.get_with_default("k", 0) != 0) { - auto k = cfg["k"].as(); - if (k > CPU_MAX_TOP_K) { - WRAPPER_LOG_WARNING << "When search with CPU, top_k shoud be no more than " << CPU_MAX_TOP_K - << ", but you passed " << k - << ". Search with " << CPU_MAX_TOP_K << " instead"; - cfg.insert_or_assign("k", CPU_MAX_TOP_K); - } - } - break; - } case IndexType::FAISS_IVFSQ8_GPU: case IndexType::FAISS_IVFFLAT_GPU: case IndexType::FAISS_IVFPQ_GPU: { @@ -278,32 +258,6 @@ void ParameterValidation(const IndexType &type, Config &cfg) { cfg.insert_or_assign("nprobe", GPU_MAX_NRPOBE); } } - if (cfg.get_with_default("k", 0) != 0) { - auto k = cfg["k"].as(); - if (k > GPU_MAX_TOP_K) { - WRAPPER_LOG_WARNING << "When search with GPU, top_k shoud be no more than " << GPU_MAX_TOP_K - << ", but you passed " << k - << ". Search with " << GPU_MAX_TOP_K << " instead"; - cfg.insert_or_assign("k", GPU_MAX_TOP_K); - } - } - break; - } - case IndexType::FAISS_IDMAP: - case IndexType::FAISS_IVFFLAT_MIX: - case IndexType::SPTAG_KDT_RNT_CPU: - case IndexType::FAISS_IVFSQ8_MIX: - case IndexType::NSG_MIX: { - // TODO(yzb): need to figure out where it search - if (cfg.get_with_default("k", 0) != 0) { - auto k = cfg["k"].as(); - if (k > DEFAULT_MAX_TOP_K) { - WRAPPER_LOG_WARNING << "top_k shoud be no more than " << DEFAULT_MAX_TOP_K << ", but you passed " - << k - << ". Search with " << DEFAULT_MAX_TOP_K << " instead"; - cfg.insert_or_assign("k", DEFAULT_MAX_TOP_K); - } - } break; } default:break;