From 835018ff991cea7eebd8729be900fbc239e03808 Mon Sep 17 00:00:00 2001 From: cqy123456 <39671710+cqy123456@users.noreply.github.com> Date: Wed, 5 Jun 2024 07:46:47 -0500 Subject: [PATCH 01/14] check the combination of index type and data type (#634) Signed-off-by: cqy123456 --- include/knowhere/comp/index_param.h | 8 +++++ include/knowhere/comp/knowhere_check.h | 46 ++++++++++++++++++++++++++ include/knowhere/index/index_factory.h | 3 ++ src/index/hnsw/hnsw.cc | 4 +-- src/index/index_factory.cc | 16 +++++++++ tests/ut/test_index_check.cc | 43 ++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 include/knowhere/comp/knowhere_check.h create mode 100644 tests/ut/test_index_check.cc diff --git a/include/knowhere/comp/index_param.h b/include/knowhere/comp/index_param.h index 178b7e6c2..9cda0df76 100644 --- a/include/knowhere/comp/index_param.h +++ b/include/knowhere/comp/index_param.h @@ -155,4 +155,12 @@ constexpr const char* SUBSTRUCTURE = "SUBSTRUCTURE"; constexpr const char* SUPERSTRUCTURE = "SUPERSTRUCTURE"; } // namespace metric +enum VecType { + VECTOR_BINARY = 100, + VECTOR_FLOAT = 101, + VECTOR_FLOAT16 = 102, + VECTOR_BFLOAT16 = 103, + VECTOR_SPARSE_FLOAT = 104, +}; // keep the same value as milvus proto define + } // namespace knowhere diff --git a/include/knowhere/comp/knowhere_check.h b/include/knowhere/comp/knowhere_check.h new file mode 100644 index 000000000..5f2db1764 --- /dev/null +++ b/include/knowhere/comp/knowhere_check.h @@ -0,0 +1,46 @@ +// Copyright (C) 2019-2023 Zilliz. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the License +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions and limitations under the License. + +#ifndef COMP_KNOWHERE_CHECKER_H +#define COMP_KNOWHERE_CHECKER_H + +#include + +#include "knowhere/comp/index_param.h" +#include "knowhere/index/index_factory.h" +namespace knowhere { +namespace KnowhereCheck { +bool +IndexTypeAndDataTypeCheck(const std::string& index_name, VecType data_type) { + auto& index_factory = IndexFactory::Instance(); + switch (data_type) { + case VecType::VECTOR_BINARY: + return index_factory.HasIndex(index_name); + case VecType::VECTOR_FLOAT: + return index_factory.HasIndex(index_name); + case VecType::VECTOR_BFLOAT16: + return index_factory.HasIndex(index_name); + case VecType::VECTOR_FLOAT16: + return index_factory.HasIndex(index_name); + case VecType::VECTOR_SPARSE_FLOAT: + if (index_name != IndexEnum::INDEX_SPARSE_INVERTED_INDEX && index_name != IndexEnum::INDEX_SPARSE_WAND) { + return false; + } else { + return index_factory.HasIndex(index_name); + } + default: + return false; + } +} +} // namespace KnowhereCheck +} // namespace knowhere + +#endif /* COMP_KNOWHERE_CHECKER_H */ diff --git a/include/knowhere/index/index_factory.h b/include/knowhere/index/index_factory.h index f861b27fb..1eca451b5 100644 --- a/include/knowhere/index/index_factory.h +++ b/include/knowhere/index/index_factory.h @@ -28,6 +28,9 @@ class IndexFactory { template const IndexFactory& Register(const std::string& name, std::function(const int32_t&, const Object&)> func); + template + bool + HasIndex(const std::string& name); static IndexFactory& Instance(); diff --git a/src/index/hnsw/hnsw.cc b/src/index/hnsw/hnsw.cc index ae92dddf7..9dde0ba52 100644 --- a/src/index/hnsw/hnsw.cc +++ b/src/index/hnsw/hnsw.cc @@ -595,12 +595,12 @@ class HnswIndexNode : public IndexNode { KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW_DEPRECATED, HnswIndexNode, fp32); KNOWHERE_MOCK_REGISTER_GLOBAL(HNSW_DEPRECATED, HnswIndexNode, fp16); KNOWHERE_MOCK_REGISTER_GLOBAL(HNSW_DEPRECATED, HnswIndexNode, bf16); -KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW_DEPRECATED, HnswIndexNode, bin1); +// KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW_DEPRECATED, HnswIndexNode, bin1); #else KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW, HnswIndexNode, fp32); KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW, HnswIndexNode, fp16); KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW, HnswIndexNode, bf16); -KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW, HnswIndexNode, bin1); +// KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW, HnswIndexNode, bin1); #endif KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW_SQ8, HnswIndexNode, fp32, QuantType::SQ8); diff --git a/src/index/index_factory.cc b/src/index/index_factory.cc index 1134998cb..b090425e9 100644 --- a/src/index/index_factory.cc +++ b/src/index/index_factory.cc @@ -72,6 +72,14 @@ IndexFactory::Register(const std::string& name, std::function(c return *this; } +template +bool +IndexFactory::HasIndex(const std::string& name) { + auto& func_mapping_ = MapInstance(); + auto key = GetKey(name); + return (func_mapping_.find(key) != func_mapping_.end()); +} + IndexFactory& IndexFactory::Instance() { static IndexFactory factory; @@ -108,3 +116,11 @@ knowhere::IndexFactory::Register( template const knowhere::IndexFactory& knowhere::IndexFactory::Register( const std::string&, std::function(const int32_t&, const Object&)>); +template bool +knowhere::IndexFactory::HasIndex(const std::string&); +template bool +knowhere::IndexFactory::HasIndex(const std::string&); +template bool +knowhere::IndexFactory::HasIndex(const std::string&); +template bool +knowhere::IndexFactory::HasIndex(const std::string&); diff --git a/tests/ut/test_index_check.cc b/tests/ut/test_index_check.cc new file mode 100644 index 000000000..4e71a1401 --- /dev/null +++ b/tests/ut/test_index_check.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2019-2023 Zilliz. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the License +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions and limitations under the License. + +#include + +#include "catch2/catch_approx.hpp" +#include "catch2/catch_test_macros.hpp" +#include "catch2/generators/catch_generators.hpp" +#include "knowhere/comp/index_param.h" +#include "knowhere/comp/knowhere_check.h" +#include "knowhere/index/index_factory.h" + +TEST_CASE("Test index and data type check", "[IndexCheckTest]") { + SECTION("Test valid") { + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, + knowhere::VecType::VECTOR_FLOAT) == true); + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, + knowhere::VecType::VECTOR_BFLOAT16) == true); +#ifdef KNOWHERE_WITH_CARDINAL + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, + knowhere::VecType::VECTOR_BINARY) == true); +#else + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, + knowhere::VecType::VECTOR_BINARY) == false); +#endif + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_DISKANN, + knowhere::VecType::VECTOR_FLOAT) == true); + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_DISKANN, + knowhere::VecType::VECTOR_FLOAT16) == true); + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_DISKANN, + knowhere::VecType::VECTOR_BINARY) == false); + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_DISKANN, + knowhere::VecType::VECTOR_SPARSE_FLOAT) == false); + } +} From d204709748a3fe8f64cd342397c6720757f000b1 Mon Sep 17 00:00:00 2001 From: cqy123456 <39671710+cqy123456@users.noreply.github.com> Date: Wed, 5 Jun 2024 08:08:20 -0500 Subject: [PATCH 02/14] add sparse support type (#635) Signed-off-by: cqy123456 --- include/knowhere/comp/knowhere_check.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/knowhere/comp/knowhere_check.h b/include/knowhere/comp/knowhere_check.h index 5f2db1764..1499a7f34 100644 --- a/include/knowhere/comp/knowhere_check.h +++ b/include/knowhere/comp/knowhere_check.h @@ -31,7 +31,8 @@ IndexTypeAndDataTypeCheck(const std::string& index_name, VecType data_type) { case VecType::VECTOR_FLOAT16: return index_factory.HasIndex(index_name); case VecType::VECTOR_SPARSE_FLOAT: - if (index_name != IndexEnum::INDEX_SPARSE_INVERTED_INDEX && index_name != IndexEnum::INDEX_SPARSE_WAND) { + if (index_name != IndexEnum::INDEX_SPARSE_INVERTED_INDEX && index_name != IndexEnum::INDEX_SPARSE_WAND && + index_name != IndexEnum::INDEX_HNSW) { return false; } else { return index_factory.HasIndex(index_name); From e681784daba5b403ed4f3ac014519269aab9d90d Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Thu, 6 Jun 2024 14:31:47 +0800 Subject: [PATCH 03/14] [skip ci] Add diskann benchmark test (#637) Signed-off-by: Cai Yudong --- benchmark/hdf5/benchmark_float.cpp | 53 ++++++--------- benchmark/hdf5/benchmark_float_bitset.cpp | 26 ++----- benchmark/hdf5/benchmark_float_range.cpp | 67 +++++++++++++++++++ .../hdf5/benchmark_float_range_bitset.cpp | 22 ++---- benchmark/hdf5/benchmark_knowhere.h | 17 +++++ benchmark/hdf5/ref_logs/Makefile | 12 +++- 6 files changed, 124 insertions(+), 73 deletions(-) diff --git a/benchmark/hdf5/benchmark_float.cpp b/benchmark/hdf5/benchmark_float.cpp index 53ed80b94..010c5f84c 100644 --- a/benchmark/hdf5/benchmark_float.cpp +++ b/benchmark/hdf5/benchmark_float.cpp @@ -19,23 +19,6 @@ #include "knowhere/comp/local_file_manager.h" #include "knowhere/dataset.h" -namespace fs = std::filesystem; -std::string kDir = fs::current_path().string() + "/diskann_test"; -std::string kRawDataPath = kDir + "/raw_data"; -std::string kL2IndexDir = kDir + "/l2_index"; -std::string kIPIndexDir = kDir + "/ip_index"; -std::string kL2IndexPrefix = kL2IndexDir + "/l2"; -std::string kIPIndexPrefix = kIPIndexDir + "/ip"; - -void -WriteRawDataToDisk(const std::string data_path, const float* raw_data, const uint32_t num, const uint32_t dim) { - std::ofstream writer(data_path.c_str(), std::ios::binary); - writer.write((char*)&num, sizeof(uint32_t)); - writer.write((char*)&dim, sizeof(uint32_t)); - writer.write((char*)raw_data, sizeof(float) * num * dim); - writer.close(); -} - class Benchmark_float : public Benchmark_knowhere, public ::testing::Test { public: void @@ -117,25 +100,25 @@ class Benchmark_float : public Benchmark_knowhere, public ::testing::Test { void test_diskann(const knowhere::Json& cfg) { auto conf = cfg; - conf["index_prefix"] = (metric_type_ == knowhere::metric::L2 ? kL2IndexPrefix : kIPIndexPrefix); - conf["search_cache_budget_gb"] = 0; - conf["beamwidth"] = 8; knowhere::BinarySet binset; - index_.Deserialize(binset, conf); + index_.value().Deserialize(binset, conf); printf("\n[%0.3f s] %s | %s \n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str()); printf("================================================================================\n"); - for (auto nq : NQs_) { - auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_); - for (auto k : TOPKs_) { - conf["search_list_size"] = 2 * k; - conf[knowhere::meta::TOPK] = k; - CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, nullptr)); - auto ids = result.value()->GetIds(); - float recall = CalcRecall(ids, nq, k); - printf(" nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", nq, k, t_diff, recall); - std::fflush(stdout); + for (auto search_list_size : SEARCH_LISTs_) { + conf["search_list_size"] = search_list_size; + for (auto nq : NQs_) { + auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_); + for (auto k : TOPKs_) { + conf[knowhere::meta::TOPK] = k; + CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, nullptr)); + auto ids = result.value()->GetIds(); + float recall = CalcRecall(ids, nq, k); + printf(" search_list_size = %4d, nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", + search_list_size, nq, k, t_diff, recall); + std::fflush(stdout); + } } } printf("================================================================================\n"); @@ -177,6 +160,9 @@ class Benchmark_float : public Benchmark_knowhere, public ::testing::Test { const std::vector HNSW_Ms_ = {16}; const std::vector EFCONs_ = {200}; const std::vector EFs_ = {128, 256, 512}; + + // DISKANN index params + const std::vector SEARCH_LISTs_ = {100, 200, 400}; }; TEST_F(Benchmark_float, TEST_IDMAP) { @@ -260,9 +246,10 @@ TEST_F(Benchmark_float, TEST_DISKANN) { conf["index_prefix"] = (metric_type_ == knowhere::metric::L2 ? kL2IndexPrefix : kIPIndexPrefix); conf["data_path"] = kRawDataPath; conf["max_degree"] = 56; - conf["search_list_size"] = 128; conf["pq_code_budget_gb"] = sizeof(float) * dim_ * nb_ * 0.125 / (1024 * 1024 * 1024); conf["build_dram_budget_gb"] = 32.0; + conf["search_cache_budget_gb"] = 0; + conf["beamwidth"] = 8; fs::create_directory(kDir); fs::create_directory(kL2IndexDir); @@ -277,7 +264,7 @@ TEST_F(Benchmark_float, TEST_DISKANN) { index_type_, knowhere::Version::GetCurrentVersion().VersionNumber(), diskann_index_pack); printf("[%.3f s] Building all on %d vectors\n", get_time_diff(), nb_); knowhere::DataSetPtr ds_ptr = nullptr; - index_.Build(*ds_ptr, conf); + index_.value().Build(*ds_ptr, conf); test_diskann(conf); } #endif diff --git a/benchmark/hdf5/benchmark_float_bitset.cpp b/benchmark/hdf5/benchmark_float_bitset.cpp index 9568dc0c4..af930686b 100644 --- a/benchmark/hdf5/benchmark_float_bitset.cpp +++ b/benchmark/hdf5/benchmark_float_bitset.cpp @@ -21,29 +21,12 @@ const int32_t GPU_DEVICE_ID = 0; -namespace fs = std::filesystem; -std::string kDir = fs::current_path().string() + "/diskann_test"; -std::string kRawDataPath = kDir + "/raw_data"; -std::string kL2IndexDir = kDir + "/l2_index"; -std::string kIPIndexDir = kDir + "/ip_index"; -std::string kL2IndexPrefix = kL2IndexDir + "/l2"; -std::string kIPIndexPrefix = kIPIndexDir + "/ip"; - constexpr uint32_t kNumRows = 10000; constexpr uint32_t kNumQueries = 100; constexpr uint32_t kDim = 128; constexpr uint32_t kK = 10; constexpr float kL2KnnRecall = 0.8; -void -WriteRawDataToDisk(const std::string data_path, const float* raw_data, const uint32_t num, const uint32_t dim) { - std::ofstream writer(data_path.c_str(), std::ios::binary); - writer.write((char*)&num, sizeof(uint32_t)); - writer.write((char*)&dim, sizeof(uint32_t)); - writer.write((char*)raw_data, sizeof(float) * num * dim); - writer.close(); -} - class Benchmark_float_bitset : public Benchmark_knowhere, public ::testing::Test { public: void @@ -104,10 +87,10 @@ class Benchmark_float_bitset : public Benchmark_knowhere, public ::testing::Test printf("[%.3f s] Test '%s/%s' done\n\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str()); } +#ifdef KNOWHERE_WITH_DISKANN void test_diskann(const knowhere::Json& cfg) { auto conf = cfg; - conf["index_prefix"] = (metric_type_ == knowhere::metric::L2 ? kL2IndexPrefix : kIPIndexPrefix); printf("\n[%0.3f s] %s | %s \n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str()); printf("================================================================================\n"); @@ -118,9 +101,11 @@ class Benchmark_float_bitset : public Benchmark_knowhere, public ::testing::Test auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_); for (auto k : TOPKs_) { conf[knowhere::meta::TOPK] = k; + auto g_result = golden_index_.value().Search(*ds_ptr, conf, bitset); + auto g_ids = g_result.value()->GetIds(); CALC_TIME_SPAN(auto result = index_.value().Search(*ds_ptr, conf, bitset)); auto ids = result.value()->GetIds(); - float recall = CalcRecall(ids, nq, k); + float recall = CalcRecall(g_ids, ids, nq, k); printf(" bitset_per = %3d%%, nq = %4d, k = %4d, elapse = %6.3fs, R@ = %.4f\n", per, nq, k, t_diff, recall); std::fflush(stdout); @@ -130,6 +115,7 @@ class Benchmark_float_bitset : public Benchmark_knowhere, public ::testing::Test printf("================================================================================\n"); printf("[%.3f s] Test '%s/%s' done\n\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str()); } +#endif protected: void @@ -214,6 +200,7 @@ TEST_F(Benchmark_float_bitset, TEST_HNSW) { test_hnsw(conf); } +#ifdef KNOWHERE_WITH_DISKANN TEST_F(Benchmark_float_bitset, TEST_DISKANN) { index_type_ = knowhere::IndexEnum::INDEX_DISKANN; @@ -240,3 +227,4 @@ TEST_F(Benchmark_float_bitset, TEST_DISKANN) { index_.value().Build(*ds_ptr, conf); test_diskann(conf); } +#endif diff --git a/benchmark/hdf5/benchmark_float_range.cpp b/benchmark/hdf5/benchmark_float_range.cpp index 6ee424900..9893a5b2e 100644 --- a/benchmark/hdf5/benchmark_float_range.cpp +++ b/benchmark/hdf5/benchmark_float_range.cpp @@ -15,6 +15,7 @@ #include "benchmark_knowhere.h" #include "knowhere/comp/knowhere_config.h" +#include "knowhere/comp/local_file_manager.h" #include "knowhere/dataset.h" class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test { @@ -98,6 +99,37 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test printf("[%.3f s] Test '%s/%s' done\n\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str()); } +#ifdef KNOWHERE_WITH_DISKANN + void + test_diskann(const knowhere::Json& cfg) { + auto conf = cfg; + auto radius = conf.at(knowhere::meta::RADIUS).get(); + + knowhere::BinarySet binset; + index_.value().Deserialize(binset, conf); + + printf("\n[%0.3f s] %s | %s, radius=%.3f\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str(), + radius); + printf("================================================================================\n"); + for (auto search_list_size : SEARCH_LISTs_) { + conf["search_list_size"] = search_list_size; + for (auto nq : NQs_) { + auto ds_ptr = knowhere::GenDataSet(nq, dim_, xq_); + CALC_TIME_SPAN(auto result = index_.value().RangeSearch(*ds_ptr, conf, nullptr)); + auto ids = result.value()->GetIds(); + auto lims = result.value()->GetLims(); + float recall = CalcRecall(ids, lims, nq); + float accuracy = CalcAccuracy(ids, lims, nq); + printf(" search_list_size = %4d, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f\n", search_list_size, + nq, t_diff, recall, accuracy); + std::fflush(stdout); + } + } + printf("================================================================================\n"); + printf("[%.3f s] Test '%s/%s' done\n\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str()); + } +#endif + protected: void SetUp() override { @@ -138,6 +170,9 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test const std::vector HNSW_Ms_ = {16}; const std::vector EFCONs_ = {200}; const std::vector EFs_ = {16, 32, 64, 128, 256, 512}; + + // DISKANN index params + const std::vector SEARCH_LISTs_ = {100, 200, 400}; }; // This testcase can be used to generate HDF5 file @@ -243,3 +278,35 @@ TEST_F(Benchmark_float_range, TEST_HNSW) { } } } + +#ifdef KNOWHERE_WITH_DISKANN +TEST_F(Benchmark_float_range, TEST_DISKANN) { + index_type_ = knowhere::IndexEnum::INDEX_DISKANN; + + knowhere::Json conf = cfg_; + + conf["index_prefix"] = (metric_type_ == knowhere::metric::L2 ? kL2IndexPrefix : kIPIndexPrefix); + conf["data_path"] = kRawDataPath; + conf["max_degree"] = 56; + conf["pq_code_budget_gb"] = sizeof(float) * dim_ * nb_ * 0.125 / (1024 * 1024 * 1024); + conf["build_dram_budget_gb"] = 32.0; + conf["search_cache_budget_gb"] = 0; + conf["beamwidth"] = 8; + + fs::create_directory(kDir); + fs::create_directory(kL2IndexDir); + fs::create_directory(kIPIndexDir); + + WriteRawDataToDisk(kRawDataPath, (const float*)xb_, (const uint32_t)nb_, (const uint32_t)dim_); + + std::shared_ptr file_manager = std::make_shared(); + auto diskann_index_pack = knowhere::Pack(file_manager); + + index_ = knowhere::IndexFactory::Instance().Create( + index_type_, knowhere::Version::GetCurrentVersion().VersionNumber(), diskann_index_pack); + printf("[%.3f s] Building all on %d vectors\n", get_time_diff(), nb_); + knowhere::DataSetPtr ds_ptr = nullptr; + index_.value().Build(*ds_ptr, conf); + test_diskann(conf); +} +#endif diff --git a/benchmark/hdf5/benchmark_float_range_bitset.cpp b/benchmark/hdf5/benchmark_float_range_bitset.cpp index 742e641bd..26585ce54 100644 --- a/benchmark/hdf5/benchmark_float_range_bitset.cpp +++ b/benchmark/hdf5/benchmark_float_range_bitset.cpp @@ -21,29 +21,12 @@ const int32_t GPU_DEVICE_ID = 0; -namespace fs = std::filesystem; -std::string kDir = fs::current_path().string() + "/diskann_test"; -std::string kRawDataPath = kDir + "/raw_data"; -std::string kL2IndexDir = kDir + "/l2_index"; -std::string kIPIndexDir = kDir + "/ip_index"; -std::string kL2IndexPrefix = kL2IndexDir + "/l2"; -std::string kIPIndexPrefix = kIPIndexDir + "/ip"; - constexpr uint32_t kNumRows = 10000; constexpr uint32_t kNumQueries = 100; constexpr uint32_t kDim = 128; constexpr uint32_t kK = 10; constexpr float kL2KnnRecall = 0.8; -void -WriteRawDataToDisk(const std::string data_path, const float* raw_data, const uint32_t num, const uint32_t dim) { - std::ofstream writer(data_path.c_str(), std::ios::binary); - writer.write((char*)&num, sizeof(uint32_t)); - writer.write((char*)&dim, sizeof(uint32_t)); - writer.write((char*)raw_data, sizeof(float) * num * dim); - writer.close(); -} - class Benchmark_float_range_bitset : public Benchmark_knowhere, public ::testing::Test { public: void @@ -108,11 +91,11 @@ class Benchmark_float_range_bitset : public Benchmark_knowhere, public ::testing printf("[%.3f s] Test '%s/%s' done\n\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str()); } +#ifdef KNOWHERE_WITH_DISKANN void test_diskann(const knowhere::Json& cfg) { auto conf = cfg; auto radius = conf[knowhere::meta::RADIUS].get(); - conf["index_prefix"] = (metric_type_ == knowhere::metric::L2 ? kL2IndexPrefix : kIPIndexPrefix); printf("\n[%0.3f s] %s | %s | radius=%.3f\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str(), radius); @@ -138,6 +121,7 @@ class Benchmark_float_range_bitset : public Benchmark_knowhere, public ::testing printf("================================================================================\n"); printf("[%.3f s] Test '%s/%s' done\n\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str()); } +#endif protected: void @@ -215,6 +199,7 @@ TEST_F(Benchmark_float_range_bitset, TEST_HNSW) { test_hnsw(conf); } +#ifdef KNOWHERE_WITH_DISKANN TEST_F(Benchmark_float_range_bitset, TEST_DISKANN) { index_type_ = knowhere::IndexEnum::INDEX_DISKANN; @@ -241,3 +226,4 @@ TEST_F(Benchmark_float_range_bitset, TEST_DISKANN) { index_.value().Build(*ds_ptr, conf); test_diskann(conf); } +#endif diff --git a/benchmark/hdf5/benchmark_knowhere.h b/benchmark/hdf5/benchmark_knowhere.h index c831fb27f..312c940f6 100644 --- a/benchmark/hdf5/benchmark_knowhere.h +++ b/benchmark/hdf5/benchmark_knowhere.h @@ -22,6 +22,14 @@ #include "knowhere/index/index_factory.h" #include "knowhere/version.h" +namespace fs = std::filesystem; +std::string kDir = fs::current_path().string() + "/diskann_test"; +std::string kRawDataPath = kDir + "/raw_data"; +std::string kL2IndexDir = kDir + "/l2_index"; +std::string kIPIndexDir = kDir + "/ip_index"; +std::string kL2IndexPrefix = kL2IndexDir + "/l2"; +std::string kIPIndexPrefix = kIPIndexDir + "/ip"; + class Benchmark_knowhere : public Benchmark_hdf5 { public: void @@ -136,6 +144,15 @@ class Benchmark_knowhere : public Benchmark_hdf5 { return golden_index_.value(); } + void + WriteRawDataToDisk(const std::string data_path, const float* raw_data, const uint32_t num, const uint32_t dim) { + std::ofstream writer(data_path.c_str(), std::ios::binary); + writer.write((char*)&num, sizeof(uint32_t)); + writer.write((char*)&dim, sizeof(uint32_t)); + writer.write((char*)raw_data, sizeof(float) * num * dim); + writer.close(); + } + protected: std::string index_type_; knowhere::Json cfg_; diff --git a/benchmark/hdf5/ref_logs/Makefile b/benchmark/hdf5/ref_logs/Makefile index 8ef33ae98..3258317f2 100644 --- a/benchmark/hdf5/ref_logs/Makefile +++ b/benchmark/hdf5/ref_logs/Makefile @@ -40,7 +40,7 @@ test_float_diskann: ################################################################################################### # Test Knowhere float index bitset -test_float_bitset: test_float_bitset_ivf_flat test_float_bitset_ivf_sq8 test_float_bitset_ivf_pq test_float_bitset_hnsw +test_float_bitset: test_float_bitset_ivf_flat test_float_bitset_ivf_sq8 test_float_bitset_ivf_pq test_float_bitset_hnsw test_float_bitset_diskann test_float_bitset_gpu: test_float_bitset_ivf_flat test_float_bitset_ivf_pq test_float_bitset_ivf_flat: @@ -51,10 +51,12 @@ test_float_bitset_ivf_pq: ./benchmark_float_bitset --gtest_filter="Benchmark_float_bitset.TEST_IVF_PQ" | tee test_float_bitset_ivf_pq.log test_float_bitset_hnsw: ./benchmark_float_bitset --gtest_filter="Benchmark_float_bitset.TEST_HNSW" | tee test_float_bitset_hnsw.log +test_float_bitset_diskann: + ./benchmark_float_bitset --gtest_filter="Benchmark_float_bitset.TEST_DISKANN" | tee test_float_bitset_diskann.log ################################################################################################### # Test Knowhere float index range -test_float_range: test_float_range_idmap test_float_range_ivf_flat test_float_range_ivf_sq8 test_float_range_ivf_pq test_float_range_hnsw +test_float_range: test_float_range_idmap test_float_range_ivf_flat test_float_range_ivf_sq8 test_float_range_ivf_pq test_float_range_hnsw test_float_range_diskann test_float_range_idmap: ./benchmark_float_range --gtest_filter="Benchmark_float_range.TEST_IDMAP" | tee test_float_range_idmap.log @@ -66,10 +68,12 @@ test_float_range_ivf_pq: ./benchmark_float_range --gtest_filter="Benchmark_float_range.TEST_IVF_PQ" | tee test_float_range_ivf_pq.log test_float_range_hnsw: ./benchmark_float_range --gtest_filter="Benchmark_float_range.TEST_HNSW" | tee test_float_range_hnsw.log +test_float_range_diskann: + ./benchmark_float_range --gtest_filter="Benchmark_float_range.TEST_DISKANN" | tee test_float_range_diskann.log ################################################################################################### # Test Knowhere float index range bitset -test_float_range_bitset: test_float_range_bitset_ivf_flat test_float_range_bitset_ivf_sq8 test_float_range_bitset_ivf_pq test_float_range_bitset_hnsw +test_float_range_bitset: test_float_range_bitset_ivf_flat test_float_range_bitset_ivf_sq8 test_float_range_bitset_ivf_pq test_float_range_bitset_hnsw test_float_range_bitset_diskann test_float_range_bitset_ivf_flat: ./benchmark_float_range_bitset --gtest_filter="Benchmark_float_range_bitset.TEST_IVF_FLAT" | tee test_float_range_bitset_ivf_flat.log @@ -79,6 +83,8 @@ test_float_range_bitset_ivf_pq: ./benchmark_float_range_bitset --gtest_filter="Benchmark_float_range_bitset.TEST_IVF_PQ" | tee test_float_range_bitset_ivf_pq.log test_float_range_bitset_hnsw: ./benchmark_float_range_bitset --gtest_filter="Benchmark_float_range_bitset.TEST_HNSW" | tee test_float_range_bitset_hnsw.log +test_float_range_bitset_diskann: + ./benchmark_float_range_bitset --gtest_filter="Benchmark_float_range_bitset.TEST_DISKANN" | tee test_float_range_bitset_diskann.log ################################################################################################### # Test Knowhere float index range multi From 24d074f6aa2df31739738204757b30a9bb59199a Mon Sep 17 00:00:00 2001 From: cqy123456 <39671710+cqy123456@users.noreply.github.com> Date: Thu, 6 Jun 2024 03:15:27 -0500 Subject: [PATCH 04/14] register binary_hnsw in knowhere (#638) Signed-off-by: cqy123456 --- src/index/hnsw/hnsw.cc | 4 ++-- tests/ut/test_index_check.cc | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/index/hnsw/hnsw.cc b/src/index/hnsw/hnsw.cc index 9dde0ba52..ae92dddf7 100644 --- a/src/index/hnsw/hnsw.cc +++ b/src/index/hnsw/hnsw.cc @@ -595,12 +595,12 @@ class HnswIndexNode : public IndexNode { KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW_DEPRECATED, HnswIndexNode, fp32); KNOWHERE_MOCK_REGISTER_GLOBAL(HNSW_DEPRECATED, HnswIndexNode, fp16); KNOWHERE_MOCK_REGISTER_GLOBAL(HNSW_DEPRECATED, HnswIndexNode, bf16); -// KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW_DEPRECATED, HnswIndexNode, bin1); +KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW_DEPRECATED, HnswIndexNode, bin1); #else KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW, HnswIndexNode, fp32); KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW, HnswIndexNode, fp16); KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW, HnswIndexNode, bf16); -// KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW, HnswIndexNode, bin1); +KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW, HnswIndexNode, bin1); #endif KNOWHERE_SIMPLE_REGISTER_GLOBAL(HNSW_SQ8, HnswIndexNode, fp32, QuantType::SQ8); diff --git a/tests/ut/test_index_check.cc b/tests/ut/test_index_check.cc index 4e71a1401..9f14236cc 100644 --- a/tests/ut/test_index_check.cc +++ b/tests/ut/test_index_check.cc @@ -24,13 +24,8 @@ TEST_CASE("Test index and data type check", "[IndexCheckTest]") { knowhere::VecType::VECTOR_FLOAT) == true); REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, knowhere::VecType::VECTOR_BFLOAT16) == true); -#ifdef KNOWHERE_WITH_CARDINAL REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, knowhere::VecType::VECTOR_BINARY) == true); -#else - REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, - knowhere::VecType::VECTOR_BINARY) == false); -#endif REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_DISKANN, knowhere::VecType::VECTOR_FLOAT) == true); REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_DISKANN, From 0198bbe72def5c5820fe64edac692a0bc6e0da74 Mon Sep 17 00:00:00 2001 From: foxspy Date: Thu, 6 Jun 2024 16:16:12 +0800 Subject: [PATCH 05/14] remove iterator/sparse ut limit (#636) Signed-off-by: xianliang.li --- cmake/libs/libcardinal.cmake | 2 +- tests/ut/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/libs/libcardinal.cmake b/cmake/libs/libcardinal.cmake index e6769f0c4..0e33a6a1c 100644 --- a/cmake/libs/libcardinal.cmake +++ b/cmake/libs/libcardinal.cmake @@ -1,5 +1,5 @@ # Use short SHA1 as version -set(CARDINAL_VERSION v2.4.3) +set(CARDINAL_VERSION v2.4.5) set(CARDINAL_REPO_URL "https://github.com/zilliztech/cardinal.git") set(CARDINAL_REPO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cardinal") diff --git a/tests/ut/CMakeLists.txt b/tests/ut/CMakeLists.txt index f9d885291..51309d977 100644 --- a/tests/ut/CMakeLists.txt +++ b/tests/ut/CMakeLists.txt @@ -17,7 +17,7 @@ if(NOT WITH_DISKANN) endif() if (WITH_CARDINAL) - knowhere_file_glob(GLOB_RECURSE CARDINAL_UNSUPPORTED_TESTS test_iterator.cc test_feder.cc test_sparse.cc) + knowhere_file_glob(GLOB_RECURSE CARDINAL_UNSUPPORTED_TESTS test_feder.cc) list(REMOVE_ITEM KNOWHERE_UT_SRCS ${CARDINAL_UNSUPPORTED_TESTS}) else() knowhere_file_glob(GLOB_RECURSE KNOWHERE_CLUSTER_TESTS test_cluster.cc) From 7fd9de4ed16ccd8f90cc3c8f96e70b28ce98df32 Mon Sep 17 00:00:00 2001 From: Min Tian Date: Thu, 6 Jun 2024 19:11:46 +0800 Subject: [PATCH 06/14] params for iterator (#625) Signed-off-by: min.tian --- include/knowhere/config.h | 1 + src/index/diskann/diskann_config.h | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/knowhere/config.h b/include/knowhere/config.h index 041e9f8f0..46ee0c0e9 100644 --- a/include/knowhere/config.h +++ b/include/knowhere/config.h @@ -722,6 +722,7 @@ class BaseConfig : public Config { .description("materialized view search info") .allow_empty_without_default() .for_search() + .for_iterator() .for_range_search(); KNOWHERE_CONFIG_DECLARE_FIELD(opt_fields_path) .description("materialized view optional fields path") diff --git a/src/index/diskann/diskann_config.h b/src/index/diskann/diskann_config.h index 6a8f0de09..51df6a210 100644 --- a/src/index/diskann/diskann_config.h +++ b/src/index/diskann/diskann_config.h @@ -88,7 +88,8 @@ class DiskANNConfig : public BaseConfig { .allow_empty_without_default() .set_range(1, std::numeric_limits::max()) .for_train() - .for_search(); + .for_search() + .for_iterator(); KNOWHERE_CONFIG_DECLARE_FIELD(pq_code_budget_gb) .description("the size of PQ compressed representation in GB.") .set_range(0, std::numeric_limits::max()) @@ -124,7 +125,8 @@ class DiskANNConfig : public BaseConfig { .set_default(8) .set_range(1, 128) .for_search() - .for_range_search(); + .for_range_search() + .for_iterator(); KNOWHERE_CONFIG_DECLARE_FIELD(min_k) .description("the min l_search size used in range search.") .set_default(100) @@ -139,7 +141,8 @@ class DiskANNConfig : public BaseConfig { .description("the threshold of filter ratio to use PQ + Refine.") .set_default(-1.0f) .set_range(-1.0f, 1.0f) - .for_search(); + .for_search() + .for_iterator(); } Status From e7a79d86ffe4abdf6adb7c05f34bf561809f6911 Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Thu, 6 Jun 2024 20:15:22 +0800 Subject: [PATCH 07/14] [skip ci] Fix diskann benchmark fail (#640) Signed-off-by: Cai Yudong --- benchmark/hdf5/benchmark_float.cpp | 8 +++++--- benchmark/hdf5/benchmark_float_bitset.cpp | 5 +++++ benchmark/hdf5/benchmark_float_range.cpp | 8 +++++--- benchmark/hdf5/benchmark_float_range_bitset.cpp | 5 +++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/benchmark/hdf5/benchmark_float.cpp b/benchmark/hdf5/benchmark_float.cpp index 010c5f84c..10a284183 100644 --- a/benchmark/hdf5/benchmark_float.cpp +++ b/benchmark/hdf5/benchmark_float.cpp @@ -101,9 +101,6 @@ class Benchmark_float : public Benchmark_knowhere, public ::testing::Test { test_diskann(const knowhere::Json& cfg) { auto conf = cfg; - knowhere::BinarySet binset; - index_.value().Deserialize(binset, conf); - printf("\n[%0.3f s] %s | %s \n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str()); printf("================================================================================\n"); for (auto search_list_size : SEARCH_LISTs_) { @@ -265,6 +262,11 @@ TEST_F(Benchmark_float, TEST_DISKANN) { printf("[%.3f s] Building all on %d vectors\n", get_time_diff(), nb_); knowhere::DataSetPtr ds_ptr = nullptr; index_.value().Build(*ds_ptr, conf); + + knowhere::BinarySet binset; + index_.value().Serialize(binset); + index_.value().Deserialize(binset, conf); + test_diskann(conf); } #endif diff --git a/benchmark/hdf5/benchmark_float_bitset.cpp b/benchmark/hdf5/benchmark_float_bitset.cpp index af930686b..1942d4faf 100644 --- a/benchmark/hdf5/benchmark_float_bitset.cpp +++ b/benchmark/hdf5/benchmark_float_bitset.cpp @@ -225,6 +225,11 @@ TEST_F(Benchmark_float_bitset, TEST_DISKANN) { printf("[%.3f s] Building all on %d vectors\n", get_time_diff(), nb_); knowhere::DataSetPtr ds_ptr = nullptr; index_.value().Build(*ds_ptr, conf); + + knowhere::BinarySet binset; + index_.value().Serialize(binset); + index_.value().Deserialize(binset, conf); + test_diskann(conf); } #endif diff --git a/benchmark/hdf5/benchmark_float_range.cpp b/benchmark/hdf5/benchmark_float_range.cpp index 9893a5b2e..195ba2e5b 100644 --- a/benchmark/hdf5/benchmark_float_range.cpp +++ b/benchmark/hdf5/benchmark_float_range.cpp @@ -105,9 +105,6 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test auto conf = cfg; auto radius = conf.at(knowhere::meta::RADIUS).get(); - knowhere::BinarySet binset; - index_.value().Deserialize(binset, conf); - printf("\n[%0.3f s] %s | %s, radius=%.3f\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str(), radius); printf("================================================================================\n"); @@ -307,6 +304,11 @@ TEST_F(Benchmark_float_range, TEST_DISKANN) { printf("[%.3f s] Building all on %d vectors\n", get_time_diff(), nb_); knowhere::DataSetPtr ds_ptr = nullptr; index_.value().Build(*ds_ptr, conf); + + knowhere::BinarySet binset; + index_.value().Serialize(binset); + index_.value().Deserialize(binset, conf); + test_diskann(conf); } #endif diff --git a/benchmark/hdf5/benchmark_float_range_bitset.cpp b/benchmark/hdf5/benchmark_float_range_bitset.cpp index 26585ce54..e977b89bd 100644 --- a/benchmark/hdf5/benchmark_float_range_bitset.cpp +++ b/benchmark/hdf5/benchmark_float_range_bitset.cpp @@ -224,6 +224,11 @@ TEST_F(Benchmark_float_range_bitset, TEST_DISKANN) { printf("[%.3f s] Building all on %d vectors\n", get_time_diff(), nb_); knowhere::DataSetPtr ds_ptr = nullptr; index_.value().Build(*ds_ptr, conf); + + knowhere::BinarySet binset; + index_.value().Serialize(binset); + index_.value().Deserialize(binset, conf); + test_diskann(conf); } #endif From 807cd89e2489ada158c15384877e334281c4bf03 Mon Sep 17 00:00:00 2001 From: presburger Date: Wed, 12 Jun 2024 19:37:50 +0800 Subject: [PATCH 08/14] update raft from 23.12 to 24.04 (#628) Signed-off-by: yusheng.ma --- CMakeLists.txt | 6 +- cmake/libs/libcutlass.cmake | 107 --------------------------- cmake/libs/libraft.cmake | 4 +- cmake/libs/librapids.cmake | 2 +- src/common/raft/proto/raft_index.cuh | 4 +- 5 files changed, 9 insertions(+), 114 deletions(-) delete mode 100644 cmake/libs/libcutlass.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 021e4ac80..2bfab184c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,9 @@ include_directories(${folly_INCLUDE_DIRS}) find_package(nlohmann_json REQUIRED) find_package(glog REQUIRED) find_package(prometheus-cpp REQUIRED) -find_package(fmt REQUIRED) +if(NOT WITH_RAFT) + find_package(fmt REQUIRED) +endif() find_package(opentelemetry-cpp REQUIRED) set(CMAKE_CXX_STANDARD 17) @@ -129,7 +131,7 @@ endif() if(WITH_LIGHT) knowhere_file_glob(GLOB_RECURSE KNOWHERE_SRCS src/common/*.cc - src/index/hnsw/hnsw.cc src/io/*.cc) + src/index/hnsw/hnsw.cc src/io/*.cc src/index/index_factory.cc) knowhere_file_glob(GLOB_RECURSE KNOWHERE_TRACER_SRCS src/common/tracer.cc src/common/prometheus_client.cc) list(REMOVE_ITEM KNOWHERE_SRCS ${KNOWHERE_TRACER_SRCS}) diff --git a/cmake/libs/libcutlass.cmake b/cmake/libs/libcutlass.cmake deleted file mode 100644 index 41dae6803..000000000 --- a/cmake/libs/libcutlass.cmake +++ /dev/null @@ -1,107 +0,0 @@ -# ============================================================================= -# Copyright (c) 2021-2022, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. -# ============================================================================= - -function(find_and_configure_cutlass) - set(oneValueArgs VERSION REPOSITORY PINNED_TAG) - cmake_parse_arguments(PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" - ${ARGN}) - - # if(RAFT_ENABLE_DIST_DEPENDENCIES OR RAFT_COMPILE_LIBRARIES) - set(CUTLASS_ENABLE_HEADERS_ONLY - ON - CACHE BOOL "Enable only the header library") - set(CUTLASS_NAMESPACE - "raft_cutlass" - CACHE STRING "Top level namespace of CUTLASS") - set(CUTLASS_ENABLE_CUBLAS - OFF - CACHE BOOL "Disable CUTLASS to build with cuBLAS library.") - - if(CUDA_STATIC_RUNTIME) - set(CUDART_LIBRARY - "${CUDA_cudart_static_LIBRARY}" - CACHE FILEPATH "fixing cutlass cmake code" FORCE) - endif() - - rapids_cpm_find( - NvidiaCutlass - ${PKG_VERSION} - GLOBAL_TARGETS - nvidia::cutlass::cutlass - CPM_ARGS - GIT_REPOSITORY - ${PKG_REPOSITORY} - GIT_TAG - ${PKG_PINNED_TAG} - GIT_SHALLOW - TRUE - OPTIONS - "CUDAToolkit_ROOT ${CUDAToolkit_LIBRARY_DIR}") - - if(TARGET CUTLASS AND NOT TARGET nvidia::cutlass::cutlass) - add_library(nvidia::cutlass::cutlass ALIAS CUTLASS) - endif() - - if(NvidiaCutlass_ADDED) - rapids_export( - BUILD - NvidiaCutlass - EXPORT_SET - NvidiaCutlass - GLOBAL_TARGETS - nvidia::cutlass::cutlass - NAMESPACE - nvidia::cutlass::) - endif() - # endif() - - # We generate the cutlass-config files when we built cutlass locally, so - # always do `find_dependency` - rapids_export_package(BUILD NvidiaCutlass raft-distance-exports - GLOBAL_TARGETS nvidia::cutlass::cutlass) - rapids_export_package(INSTALL NvidiaCutlass raft-distance-exports - GLOBAL_TARGETS nvidia::cutlass::cutlass) - rapids_export_package(BUILD NvidiaCutlass raft-nn-exports GLOBAL_TARGETS - nvidia::cutlass::cutlass) - rapids_export_package(INSTALL NvidiaCutlass raft-nn-exports GLOBAL_TARGETS - nvidia::cutlass::cutlass) - - # Tell cmake where it can find the generated NvidiaCutlass-config.cmake we - # wrote. - include("${rapids-cmake-dir}/export/find_package_root.cmake") - rapids_export_find_package_root( - INSTALL NvidiaCutlass [=[${CMAKE_CURRENT_LIST_DIR}/../]=] - raft-distance-exports) - rapids_export_find_package_root( - BUILD NvidiaCutlass [=[${CMAKE_CURRENT_LIST_DIR}]=] raft-distance-exports) - include("${rapids-cmake-dir}/export/find_package_root.cmake") - rapids_export_find_package_root( - INSTALL NvidiaCutlass [=[${CMAKE_CURRENT_LIST_DIR}/../]=] raft-nn-exports) - rapids_export_find_package_root( - BUILD NvidiaCutlass [=[${CMAKE_CURRENT_LIST_DIR}]=] raft-nn-exports) -endfunction() - -if(NOT RAFT_CUTLASS_GIT_TAG) - set(RAFT_CUTLASS_GIT_TAG v2.9.1) -endif() - -if(NOT RAFT_CUTLASS_GIT_REPOSITORY) - set(RAFT_CUTLASS_GIT_REPOSITORY https://github.com/NVIDIA/cutlass.git) -endif() - -find_and_configure_cutlass( - VERSION 2.9.1 REPOSITORY ${RAFT_CUTLASS_GIT_REPOSITORY} PINNED_TAG - ${RAFT_CUTLASS_GIT_TAG}) diff --git a/cmake/libs/libraft.cmake b/cmake/libs/libraft.cmake index 157ef661b..dd4506f56 100644 --- a/cmake/libs/libraft.cmake +++ b/cmake/libs/libraft.cmake @@ -16,8 +16,8 @@ add_definitions(-DKNOWHERE_WITH_RAFT) add_definitions(-DRAFT_EXPLICIT_INSTANTIATE_ONLY) set(RAFT_VERSION "${RAPIDS_VERSION}") -set(RAFT_FORK "wphicks") -set(RAFT_PINNED_TAG "knowhere-2.4") +set(RAFT_FORK "milvus-io") +set(RAFT_PINNED_TAG "branch-24.04") rapids_find_package(CUDAToolkit REQUIRED BUILD_EXPORT_SET knowhere-exports INSTALL_EXPORT_SET knowhere-exports) diff --git a/cmake/libs/librapids.cmake b/cmake/libs/librapids.cmake index 7b0c4e7c8..a8b4e6c8c 100644 --- a/cmake/libs/librapids.cmake +++ b/cmake/libs/librapids.cmake @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations under # the License. -set(RAPIDS_VERSION 23.12) +set(RAPIDS_VERSION 24.04) if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/RAPIDS.cmake) file( diff --git a/src/common/raft/proto/raft_index.cuh b/src/common/raft/proto/raft_index.cuh index f2f0ceedc..f3f618dd1 100644 --- a/src/common/raft/proto/raft_index.cuh +++ b/src/common/raft/proto/raft_index.cuh @@ -190,7 +190,7 @@ struct raft_index { template auto static build(raft::resources const& res, index_params_type const& index_params, DataMdspanT data) { - if constexpr (std::is_same_v>) { + if constexpr (std::is_same_v>) { if constexpr (vector_index_kind == raft_index_kind::brute_force) { return raft_index{ raft::neighbors::brute_force::build(res, index_params, data)}; @@ -199,7 +199,7 @@ struct raft_index { raft::neighbors::cagra::build(res, index_params, data)}; } else if constexpr (vector_index_kind == raft_index_kind::ivf_pq) { return raft_index{raft::neighbors::ivf_pq::build( - res, index_params, data.handle(), data.extent(0), data.extent(1))}; + res, index_params, data.data_handle(), data.extent(0), data.extent(1))}; } else { RAFT_FAIL("IVF flat does not support construction from host data"); } From 8ad9fca0d5ccd54d3730bc28fe2c471bb9576688 Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Thu, 13 Jun 2024 14:40:58 +0800 Subject: [PATCH 09/14] [skip ci] Update range search benchmark result display (#646) Signed-off-by: Cai Yudong --- benchmark/hdf5/benchmark_float_range.cpp | 15 ++++++++------- benchmark/hdf5/benchmark_float_range_bitset.cpp | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/benchmark/hdf5/benchmark_float_range.cpp b/benchmark/hdf5/benchmark_float_range.cpp index 195ba2e5b..ec37de4df 100644 --- a/benchmark/hdf5/benchmark_float_range.cpp +++ b/benchmark/hdf5/benchmark_float_range.cpp @@ -37,7 +37,8 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test CheckDistance(metric_type_, ids, distances, lims, nq); float recall = CalcRecall(ids, lims, nq); float accuracy = CalcAccuracy(ids, lims, nq); - printf(" nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f\n", nq, t_diff, recall, accuracy); + printf(" nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f, L@ = %.2f\n", nq, t_diff, recall, accuracy, + lims[nq] / (float)nq); std::fflush(stdout); } printf("================================================================================\n"); @@ -62,8 +63,8 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test auto lims = result.value()->GetLims(); float recall = CalcRecall(ids, lims, nq); float accuracy = CalcAccuracy(ids, lims, nq); - printf(" nprobe = %4d, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f\n", nprobe, nq, t_diff, recall, - accuracy); + printf(" nprobe = %4d, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f, L@ = %.2f\n", nprobe, nq, + t_diff, recall, accuracy, lims[nq] / (float)nq); std::fflush(stdout); } } @@ -90,8 +91,8 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test auto lims = result.value()->GetLims(); float recall = CalcRecall(ids, lims, nq); float accuracy = CalcAccuracy(ids, lims, nq); - printf(" ef = %4d, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f\n", ef, nq, t_diff, recall, - accuracy); + printf(" ef = %4d, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f, L@ = %.2f\n", ef, nq, t_diff, + recall, accuracy, lims[nq] / (float)nq); std::fflush(stdout); } } @@ -117,8 +118,8 @@ class Benchmark_float_range : public Benchmark_knowhere, public ::testing::Test auto lims = result.value()->GetLims(); float recall = CalcRecall(ids, lims, nq); float accuracy = CalcAccuracy(ids, lims, nq); - printf(" search_list_size = %4d, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f\n", search_list_size, - nq, t_diff, recall, accuracy); + printf(" search_list_size = %4d, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f, L@ = %.2f\n", + search_list_size, nq, t_diff, recall, accuracy, lims[nq] / (float)nq); std::fflush(stdout); } } diff --git a/benchmark/hdf5/benchmark_float_range_bitset.cpp b/benchmark/hdf5/benchmark_float_range_bitset.cpp index e977b89bd..bd935cf8a 100644 --- a/benchmark/hdf5/benchmark_float_range_bitset.cpp +++ b/benchmark/hdf5/benchmark_float_range_bitset.cpp @@ -51,8 +51,8 @@ class Benchmark_float_range_bitset : public Benchmark_knowhere, public ::testing auto lims = result.value()->GetLims(); float recall = CalcRecall(g_ids, g_lims, ids, lims, nq); float accuracy = CalcAccuracy(g_ids, g_lims, ids, lims, nq); - printf(" bitset_per = %3d%%, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f\n", per, nq, t_diff, - recall, accuracy); + printf(" bitset_per = %3d%%, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f, L@ = %.2f\n", per, nq, + t_diff, recall, accuracy, lims[nq] / (float)nq); std::fflush(stdout); } } @@ -82,8 +82,8 @@ class Benchmark_float_range_bitset : public Benchmark_knowhere, public ::testing auto lims = result.value()->GetLims(); float recall = CalcRecall(g_ids, g_lims, ids, lims, nq); float accuracy = CalcAccuracy(g_ids, g_lims, ids, lims, nq); - printf(" bitset_per = %3d%%, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f\n", per, nq, t_diff, - recall, accuracy); + printf(" bitset_per = %3d%%, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f, L@ = %.2f\n", per, nq, + t_diff, recall, accuracy, lims[nq] / (float)nq); std::fflush(stdout); } } @@ -113,8 +113,8 @@ class Benchmark_float_range_bitset : public Benchmark_knowhere, public ::testing auto lims = result.value()->GetLims(); float recall = CalcRecall(g_ids, g_lims, ids, lims, nq); float accuracy = CalcAccuracy(g_ids, g_lims, ids, lims, nq); - printf(" bitset_per = %3d%%, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f\n", per, nq, t_diff, - recall, accuracy); + printf(" bitset_per = %3d%%, nq = %4d, elapse = %6.3fs, R@ = %.4f, A@ = %.4f, L@ = %.2f\n", per, nq, + t_diff, recall, accuracy, lims[nq] / (float)nq); std::fflush(stdout); } } From 6ee20d3bfc0a9273af2b18fabf60070e37e35991 Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Fri, 14 Jun 2024 11:35:50 +0800 Subject: [PATCH 10/14] [skip ci] Update script prepare_gpu_build.sh for nightly build (#648) Signed-off-by: Cai Yudong --- scripts/prepare_gpu_build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/prepare_gpu_build.sh b/scripts/prepare_gpu_build.sh index b37d0dda4..931938457 100755 --- a/scripts/prepare_gpu_build.sh +++ b/scripts/prepare_gpu_build.sh @@ -3,5 +3,6 @@ # This script is to modify CMakeLists.txt to build knowhere for certain GPU serials # GTX 1060 - sm_61 # GTX 1660 - sm_75 -sed 's/set(CMAKE_CUDA_ARCHITECTURES .*$/set(CMAKE_CUDA_ARCHITECTURES \"61-real;75-real\")/' CMakeLists.txt > tmp +# GTX 2080 SUPER - sm_75 +sed 's/set(CMAKE_CUDA_ARCHITECTURES .*$/set(CMAKE_CUDA_ARCHITECTURES \"75-real\")/' CMakeLists.txt > tmp mv tmp CMakeLists.txt From 5654078319e874915acc24d0822cac003ffc150f Mon Sep 17 00:00:00 2001 From: cqy123456 <39671710+cqy123456@users.noreply.github.com> Date: Fri, 14 Jun 2024 04:44:43 -0500 Subject: [PATCH 11/14] update index and data type check function (#649) Signed-off-by: cqy123456 --- include/knowhere/comp/index_param.h | 5 ++ include/knowhere/comp/knowhere_check.h | 27 +++------ include/knowhere/index/index_factory.h | 13 ++++- include/knowhere/index/index_table.h | 79 ++++++++++++++++++++++++++ include/knowhere/utils.h | 4 +- src/index/index_factory.cc | 23 +++----- tests/ut/test_index_check.cc | 10 ++++ 7 files changed, 120 insertions(+), 41 deletions(-) create mode 100644 include/knowhere/index/index_table.h diff --git a/include/knowhere/comp/index_param.h b/include/knowhere/comp/index_param.h index 9cda0df76..4526534a2 100644 --- a/include/knowhere/comp/index_param.h +++ b/include/knowhere/comp/index_param.h @@ -43,6 +43,11 @@ constexpr const char* INDEX_RAFT_IVFFLAT = "GPU_RAFT_IVF_FLAT"; constexpr const char* INDEX_RAFT_IVFPQ = "GPU_RAFT_IVF_PQ"; constexpr const char* INDEX_RAFT_CAGRA = "GPU_RAFT_CAGRA"; +constexpr const char* INDEX_GPU_BRUTEFORCE = "GPU_BRUTE_FORCE"; +constexpr const char* INDEX_GPU_IVFFLAT = "GPU_IVF_FLAT"; +constexpr const char* INDEX_GPU_IVFPQ = "GPU_IVF_PQ"; +constexpr const char* INDEX_GPU_CAGRA = "GPU_CAGRA"; + constexpr const char* INDEX_HNSW = "HNSW"; constexpr const char* INDEX_HNSW_SQ8 = "HNSW_SQ8"; constexpr const char* INDEX_HNSW_SQ8_REFINE = "HNSW_SQ8_REFINE"; diff --git a/include/knowhere/comp/knowhere_check.h b/include/knowhere/comp/knowhere_check.h index 1499a7f34..15734dda5 100644 --- a/include/knowhere/comp/knowhere_check.h +++ b/include/knowhere/comp/knowhere_check.h @@ -18,27 +18,14 @@ #include "knowhere/index/index_factory.h" namespace knowhere { namespace KnowhereCheck { -bool +static bool IndexTypeAndDataTypeCheck(const std::string& index_name, VecType data_type) { - auto& index_factory = IndexFactory::Instance(); - switch (data_type) { - case VecType::VECTOR_BINARY: - return index_factory.HasIndex(index_name); - case VecType::VECTOR_FLOAT: - return index_factory.HasIndex(index_name); - case VecType::VECTOR_BFLOAT16: - return index_factory.HasIndex(index_name); - case VecType::VECTOR_FLOAT16: - return index_factory.HasIndex(index_name); - case VecType::VECTOR_SPARSE_FLOAT: - if (index_name != IndexEnum::INDEX_SPARSE_INVERTED_INDEX && index_name != IndexEnum::INDEX_SPARSE_WAND && - index_name != IndexEnum::INDEX_HNSW) { - return false; - } else { - return index_factory.HasIndex(index_name); - } - default: - return false; + auto& static_index_table = IndexFactory::StaticIndexTableInstance(); + auto key = std::pair(index_name, data_type); + if (static_index_table.find(key) != static_index_table.end()) { + return true; + } else { + return false; } } } // namespace KnowhereCheck diff --git a/include/knowhere/index/index_factory.h b/include/knowhere/index/index_factory.h index 1eca451b5..f66cfe9a3 100644 --- a/include/knowhere/index/index_factory.h +++ b/include/knowhere/index/index_factory.h @@ -13,6 +13,7 @@ #define INDEX_FACTORY_H #include +#include #include #include @@ -28,11 +29,11 @@ class IndexFactory { template const IndexFactory& Register(const std::string& name, std::function(const int32_t&, const Object&)> func); - template - bool - HasIndex(const std::string& name); static IndexFactory& Instance(); + typedef std::set> GlobalIndexTable; + static GlobalIndexTable& + StaticIndexTableInstance(); private: struct FunMapValueBase { @@ -76,6 +77,12 @@ class IndexFactory { std::make_unique::type>>(version, object), thread_size)); \ }, \ data_type) +#define KNOWHERE_SET_STATIC_GLOBAL_INDEX_TABLE(name, index_table) \ + static int name = []() -> int { \ + auto& static_index_table = IndexFactory::StaticIndexTableInstance(); \ + static_index_table.insert(index_table.begin(), index_table.end()); \ + return 0; \ + }(); } // namespace knowhere #endif /* INDEX_FACTORY_H */ diff --git a/include/knowhere/index/index_table.h b/include/knowhere/index/index_table.h new file mode 100644 index 000000000..275bdaf07 --- /dev/null +++ b/include/knowhere/index/index_table.h @@ -0,0 +1,79 @@ +// Copyright (C) 2019-2023 Zilliz. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the License +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions and limitations under the License. + +#ifndef INDEX_TABLE_H +#define INDEX_TABLE_H +#include +#include + +#include "knowhere/comp/index_param.h" +#include "knowhere/index/index_factory.h" +namespace knowhere { +static std::set> legal_knowhere_index = { + // binary ivf + {IndexEnum::INDEX_FAISS_BIN_IDMAP, VecType::VECTOR_BINARY}, + {IndexEnum::INDEX_FAISS_BIN_IVFFLAT, VecType::VECTOR_BINARY}, + // ivf + {IndexEnum::INDEX_FAISS_IDMAP, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_FAISS_IDMAP, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_FAISS_IDMAP, VecType::VECTOR_BFLOAT16}, + + {IndexEnum::INDEX_FAISS_IVFFLAT, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_FAISS_IVFFLAT, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_FAISS_IVFFLAT, VecType::VECTOR_BFLOAT16}, + + {IndexEnum::INDEX_FAISS_IVFFLAT_CC, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_FAISS_IVFFLAT_CC, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_FAISS_IVFFLAT_CC, VecType::VECTOR_BFLOAT16}, + + {IndexEnum::INDEX_FAISS_IVFPQ, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_FAISS_IVFPQ, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_FAISS_IVFPQ, VecType::VECTOR_BFLOAT16}, + + {IndexEnum::INDEX_FAISS_SCANN, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_FAISS_SCANN, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_FAISS_SCANN, VecType::VECTOR_BFLOAT16}, + + {IndexEnum::INDEX_FAISS_IVFSQ8, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_FAISS_IVFSQ8, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_FAISS_IVFSQ8, VecType::VECTOR_BFLOAT16}, + + {IndexEnum::INDEX_FAISS_IVFSQ_CC, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_FAISS_IVFSQ_CC, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_FAISS_IVFSQ_CC, VecType::VECTOR_BFLOAT16}, + // gpu index + {IndexEnum::INDEX_GPU_BRUTEFORCE, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_GPU_IVFFLAT, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_GPU_IVFPQ, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_GPU_CAGRA, VecType::VECTOR_FLOAT}, + // hnsw + {IndexEnum::INDEX_HNSW, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_HNSW, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_HNSW, VecType::VECTOR_BFLOAT16}, + + {IndexEnum::INDEX_HNSW_SQ8, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_HNSW_SQ8, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_HNSW_SQ8, VecType::VECTOR_BFLOAT16}, + + {IndexEnum::INDEX_HNSW_SQ8_REFINE, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_HNSW_SQ8_REFINE, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_HNSW_SQ8_REFINE, VecType::VECTOR_BFLOAT16}, + // diskann + {IndexEnum::INDEX_DISKANN, VecType::VECTOR_FLOAT}, + {IndexEnum::INDEX_DISKANN, VecType::VECTOR_FLOAT16}, + {IndexEnum::INDEX_DISKANN, VecType::VECTOR_BFLOAT16}, + // sparse index + {IndexEnum::INDEX_SPARSE_INVERTED_INDEX, VecType::VECTOR_SPARSE_FLOAT}, + {IndexEnum::INDEX_SPARSE_WAND, VecType::VECTOR_SPARSE_FLOAT}, +}; +KNOWHERE_SET_STATIC_GLOBAL_INDEX_TABLE(KNOWHERE_STATIC_INDEX, legal_knowhere_index) +} // namespace knowhere +#endif /* INDEX_TABLE_H */ diff --git a/include/knowhere/utils.h b/include/knowhere/utils.h index 1fce95a34..35ae12733 100644 --- a/include/knowhere/utils.h +++ b/include/knowhere/utils.h @@ -31,8 +31,8 @@ IsMetricType(const std::string& str, const knowhere::MetricType& metric_type) { inline bool IsFlatIndex(const knowhere::IndexType& index_type) { - static std::vector flat_index_list = {IndexEnum::INDEX_FAISS_IDMAP, - IndexEnum::INDEX_FAISS_GPU_IDMAP}; + static std::vector flat_index_list = { + IndexEnum::INDEX_FAISS_IDMAP, IndexEnum::INDEX_FAISS_GPU_IDMAP, IndexEnum::INDEX_GPU_BRUTEFORCE}; return std::find(flat_index_list.begin(), flat_index_list.end(), index_type) != flat_index_list.end(); } diff --git a/src/index/index_factory.cc b/src/index/index_factory.cc index b090425e9..8bce34916 100644 --- a/src/index/index_factory.cc +++ b/src/index/index_factory.cc @@ -11,6 +11,8 @@ #include "knowhere/index/index_factory.h" +#include "knowhere/index/index_table.h" + #ifdef KNOWHERE_WITH_RAFT #include #endif @@ -72,14 +74,6 @@ IndexFactory::Register(const std::string& name, std::function(c return *this; } -template -bool -IndexFactory::HasIndex(const std::string& name) { - auto& func_mapping_ = MapInstance(); - auto key = GetKey(name); - return (func_mapping_.find(key) != func_mapping_.end()); -} - IndexFactory& IndexFactory::Instance() { static IndexFactory factory; @@ -93,6 +87,11 @@ IndexFactory::MapInstance() { static FuncMap func_map; return func_map; } +IndexFactory::GlobalIndexTable& +IndexFactory::StaticIndexTableInstance() { + static GlobalIndexTable static_index_table; + return static_index_table; +} } // namespace knowhere // @@ -116,11 +115,3 @@ knowhere::IndexFactory::Register( template const knowhere::IndexFactory& knowhere::IndexFactory::Register( const std::string&, std::function(const int32_t&, const Object&)>); -template bool -knowhere::IndexFactory::HasIndex(const std::string&); -template bool -knowhere::IndexFactory::HasIndex(const std::string&); -template bool -knowhere::IndexFactory::HasIndex(const std::string&); -template bool -knowhere::IndexFactory::HasIndex(const std::string&); diff --git a/tests/ut/test_index_check.cc b/tests/ut/test_index_check.cc index 9f14236cc..fb8dc059c 100644 --- a/tests/ut/test_index_check.cc +++ b/tests/ut/test_index_check.cc @@ -24,8 +24,18 @@ TEST_CASE("Test index and data type check", "[IndexCheckTest]") { knowhere::VecType::VECTOR_FLOAT) == true); REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, knowhere::VecType::VECTOR_BFLOAT16) == true); + +#ifndef KNOWHERE_WITH_CARDINAL + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, + knowhere::VecType::VECTOR_BINARY) == false); + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, + knowhere::VecType::VECTOR_SPARSE_FLOAT) == false); +#else REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, knowhere::VecType::VECTOR_BINARY) == true); + REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_HNSW, + knowhere::VecType::VECTOR_SPARSE_FLOAT) == true); +#endif REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_DISKANN, knowhere::VecType::VECTOR_FLOAT) == true); REQUIRE(knowhere::KnowhereCheck::IndexTypeAndDataTypeCheck(knowhere::IndexEnum::INDEX_DISKANN, From 44b7cbb97bdd46075cb4df51884c941aeed3a1d1 Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Tue, 18 Jun 2024 19:57:53 +0800 Subject: [PATCH 12/14] Add data type conversion test (#653) Signed-off-by: Cai Yudong --- tests/ut/test_type.cc | 28 ++++++++++++++++++++++++++-- tests/ut/utils.h | 15 ++------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/tests/ut/test_type.cc b/tests/ut/test_type.cc index 8484bf616..aebb81bd4 100644 --- a/tests/ut/test_type.cc +++ b/tests/ut/test_type.cc @@ -20,8 +20,8 @@ TEST_CASE("Test bf16 patch", "[bf16 patch]") { const int64_t nb = 1000, nq = 10; const int64_t dim = 128; - const auto train_ds = GenFloatDataSet(nb, dim); - const auto query_ds = GenFloatDataSet(nq, dim); + const auto train_ds = GenDataSet(nb, dim); + const auto query_ds = GenDataSet(nq, dim); auto train_tensor = reinterpret_cast(train_ds->GetTensor()); @@ -99,3 +99,27 @@ TEST_CASE("Test bf16 patch", "[bf16 patch]") { REQUIRE(ip_dist[i] == ip_dist_new[i]); } } + +template +void +check_data_type_accuracy(float accuracy) { + const int64_t nb = 100; + const int64_t dim = 16; + + auto fp32_base_ds = GenDataSet(nb, dim); + + auto type_base_ds = knowhere::data_type_conversion(*fp32_base_ds); + auto fp32_base_ds_2 = knowhere::data_type_conversion(*type_base_ds); + + auto bv1 = static_cast(fp32_base_ds->GetTensor()); + auto bv2 = static_cast(fp32_base_ds_2->GetTensor()); + + for (int64_t i = 0; i < nb * dim; i++) { + REQUIRE(std::abs(bv2[i] / bv1[i] - 1.0) < accuracy); + } +} + +TEST_CASE("Test Float16", "[fp16]") { + check_data_type_accuracy(0.001); + check_data_type_accuracy(0.01); +} diff --git a/tests/ut/utils.h b/tests/ut/utils.h index 3f15fee63..003928279 100644 --- a/tests/ut/utils.h +++ b/tests/ut/utils.h @@ -38,21 +38,10 @@ struct DisPairLess { inline knowhere::DataSetPtr GenDataSet(int rows, int dim, int seed = 42) { - std::mt19937 rng(seed); - std::uniform_int_distribution<> distrib(0.0, 100.0); - float* ts = new float[rows * dim]; - for (int i = 0; i < rows * dim; ++i) ts[i] = (float)distrib(rng); - auto ds = knowhere::GenDataSet(rows, dim, ts); - ds->SetIsOwner(true); - return ds; -} - -inline knowhere::DataSetPtr -GenFloatDataSet(int rows, int dim, int seed = 42) { std::mt19937 rng(seed); std::uniform_real_distribution<> distrib(0.0, 100.0); float* ts = new float[rows * dim]; - for (int i = 0; i < rows * dim; ++i) ts[i] = (float)distrib(rng); + for (int i = 0; i < rows * dim; ++i) ts[i] = distrib(rng); auto ds = knowhere::GenDataSet(rows, dim, ts); ds->SetIsOwner(true); return ds; @@ -149,7 +138,7 @@ GetKNNRecall(const knowhere::DataSet& ground_truth, const std::vector ids_0(gt_ids + i * gt_k, gt_ids + i * gt_k + gt_k); std::vector ids_1 = result[i]; From 389a3f0620332ab0b3f39547ca15b6b5524de99c Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Wed, 19 Jun 2024 14:05:53 +0800 Subject: [PATCH 13/14] Update BruteForce ut for multi data type (#656) Signed-off-by: Cai Yudong --- tests/ut/test_bruteforce.cc | 132 +++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 40 deletions(-) diff --git a/tests/ut/test_bruteforce.cc b/tests/ut/test_bruteforce.cc index 6bb85bccb..72bce0853 100644 --- a/tests/ut/test_bruteforce.cc +++ b/tests/ut/test_bruteforce.cc @@ -17,6 +17,89 @@ #include "knowhere/utils.h" #include "utils.h" +template +void +check_search(const knowhere::DataSetPtr train_ds, const knowhere::DataSetPtr query_ds, const int64_t k, + const knowhere::MetricType metric, const knowhere::Json& conf) { + knowhere::DataSetPtr base(train_ds); + knowhere::DataSetPtr query(query_ds); + if constexpr (!std::is_same_v) { + base = knowhere::data_type_conversion(*train_ds); + query = knowhere::data_type_conversion(*query_ds); + } + + auto res = knowhere::BruteForce::Search(base, query, conf, nullptr); + auto nq = query_ds->GetRows(); + REQUIRE(res.has_value()); + auto ids = res.value()->GetIds(); + auto dist = res.value()->GetDistance(); + for (int64_t i = 0; i < nq; i++) { + REQUIRE(ids[i * k] == i); + if (metric == knowhere::metric::L2) { + REQUIRE(dist[i * k] == 0); + } else { + REQUIRE(std::abs(dist[i * k] - 1.0) < 0.00001); + } + } +} + +template +void +check_search_with_buf(const knowhere::DataSetPtr train_ds, const knowhere::DataSetPtr query_ds, const int64_t k, + const knowhere::MetricType metric, const knowhere::Json& conf) { + auto nq = query_ds->GetRows(); + auto ids = new int64_t[nq * k]; + auto dist = new float[nq * k]; + + knowhere::DataSetPtr base(train_ds); + knowhere::DataSetPtr query(query_ds); + if constexpr (!std::is_same_v) { + base = knowhere::data_type_conversion(*train_ds); + query = knowhere::data_type_conversion(*query_ds); + } + + auto res = knowhere::BruteForce::SearchWithBuf(base, query, ids, dist, conf, nullptr); + REQUIRE(res == knowhere::Status::success); + for (int64_t i = 0; i < nq; i++) { + REQUIRE(ids[i * k] == i); + if (metric == knowhere::metric::L2) { + REQUIRE(dist[i * k] == 0); + } else { + REQUIRE(std::abs(dist[i * k] - 1.0) < 0.00001); + } + } + delete[] ids; + delete[] dist; +} + +template +void +check_range_search(const knowhere::DataSetPtr train_ds, const knowhere::DataSetPtr query_ds, const int64_t k, + const knowhere::MetricType metric, const knowhere::Json& conf) { + knowhere::DataSetPtr base(train_ds); + knowhere::DataSetPtr query(query_ds); + if constexpr (!std::is_same_v) { + base = knowhere::data_type_conversion(*train_ds); + query = knowhere::data_type_conversion(*query_ds); + } + + auto res = knowhere::BruteForce::RangeSearch(base, query, conf, nullptr); + REQUIRE(res.has_value()); + auto ids = res.value()->GetIds(); + auto dist = res.value()->GetDistance(); + auto lims = res.value()->GetLims(); + auto nq = query_ds->GetRows(); + for (int64_t i = 0; i < nq; i++) { + REQUIRE(lims[i] == (size_t)i); + REQUIRE(ids[i] == i); + if (metric == knowhere::metric::L2) { + REQUIRE(dist[i] == 0); + } else { + REQUIRE(std::abs(dist[i] - 1.0) < 0.00001); + } + } +} + TEST_CASE("Test Brute Force", "[float vector]") { using Catch::Approx; @@ -38,52 +121,21 @@ TEST_CASE("Test Brute Force", "[float vector]") { }; SECTION("Test Search") { - auto res = knowhere::BruteForce::Search(train_ds, query_ds, conf, nullptr); - REQUIRE(res.has_value()); - auto ids = res.value()->GetIds(); - auto dist = res.value()->GetDistance(); - for (int64_t i = 0; i < nq; i++) { - REQUIRE(ids[i * k] == i); - if (metric == knowhere::metric::L2) { - REQUIRE(dist[i * k] == 0); - } else { - REQUIRE(std::abs(dist[i * k] - 1.0) < 0.00001); - } - } + check_search(train_ds, query_ds, k, metric, conf); + check_search(train_ds, query_ds, k, metric, conf); + check_search(train_ds, query_ds, k, metric, conf); } SECTION("Test Search With Buf") { - auto ids = new int64_t[nq * k]; - auto dist = new float[nq * k]; - auto res = knowhere::BruteForce::SearchWithBuf(train_ds, query_ds, ids, dist, conf, nullptr); - REQUIRE(res == knowhere::Status::success); - for (int64_t i = 0; i < nq; i++) { - REQUIRE(ids[i * k] == i); - if (metric == knowhere::metric::L2) { - REQUIRE(dist[i * k] == 0); - } else { - REQUIRE(std::abs(dist[i * k] - 1.0) < 0.00001); - } - } - delete[] ids; - delete[] dist; + check_search_with_buf(train_ds, query_ds, k, metric, conf); + check_search_with_buf(train_ds, query_ds, k, metric, conf); + check_search_with_buf(train_ds, query_ds, k, metric, conf); } SECTION("Test Range Search") { - auto res = knowhere::BruteForce::RangeSearch(train_ds, query_ds, conf, nullptr); - REQUIRE(res.has_value()); - auto ids = res.value()->GetIds(); - auto dist = res.value()->GetDistance(); - auto lims = res.value()->GetLims(); - for (int64_t i = 0; i < nq; i++) { - REQUIRE(lims[i] == (size_t)i); - REQUIRE(ids[i] == i); - if (metric == knowhere::metric::L2) { - REQUIRE(dist[i] == 0); - } else { - REQUIRE(std::abs(dist[i] - 1.0) < 0.00001); - } - } + check_range_search(train_ds, query_ds, k, metric, conf); + check_range_search(train_ds, query_ds, k, metric, conf); + check_range_search(train_ds, query_ds, k, metric, conf); } } From 0e043239b6152f90f468dd72df4b76fd7a22957f Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Thu, 20 Jun 2024 14:40:15 +0800 Subject: [PATCH 14/14] Clean build warnings (#657) Signed-off-by: Cai Yudong --- benchmark/hdf5/benchmark_hdf5.h | 4 ++- benchmark/hdf5/gen_hdf5_file.cpp | 2 +- src/index/index.cc | 6 ++-- tests/ut/test_range_util.cc | 2 ++ thirdparty/DiskANN/src/index.cpp | 30 ++++++----------- thirdparty/DiskANN/src/pq_flash_index.cpp | 4 +-- thirdparty/faiss/faiss/IndexIVFFastScan.cpp | 32 +++++++++---------- thirdparty/faiss/faiss/IndexIVFPQFastScan.cpp | 8 ++--- thirdparty/faiss/faiss/impl/index_read.cpp | 2 +- .../faiss/faiss/impl/simd_result_handlers.h | 8 ++--- thirdparty/faiss/faiss/utils/distances_if.h | 2 +- .../faiss/faiss/utils/distances_simd.cpp | 2 +- .../utils/hamming_distance/generic-inl.h | 1 - .../faiss/faiss/utils/partitioning_avx2.cpp | 2 +- thirdparty/hnswlib/hnswlib/hnswalg.h | 2 +- 15 files changed, 50 insertions(+), 57 deletions(-) diff --git a/benchmark/hdf5/benchmark_hdf5.h b/benchmark/hdf5/benchmark_hdf5.h index 8a7f707cd..4964a2625 100644 --- a/benchmark/hdf5/benchmark_hdf5.h +++ b/benchmark/hdf5/benchmark_hdf5.h @@ -355,7 +355,9 @@ class Benchmark_hdf5 : public Benchmark_base { auto dataspace = H5Screate_simple(2, dims, NULL); auto dataset = H5Dcreate2(file, dataset_name, type_id, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); auto err = H5Dwrite(dataset, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); - assert(err == 0); + if (err != 0) { + std::abort(); + } H5Dclose(dataset); H5Sclose(dataspace); } diff --git a/benchmark/hdf5/gen_hdf5_file.cpp b/benchmark/hdf5/gen_hdf5_file.cpp index 2ec4723db..ee02bdf43 100644 --- a/benchmark/hdf5/gen_hdf5_file.cpp +++ b/benchmark/hdf5/gen_hdf5_file.cpp @@ -127,7 +127,7 @@ class Create_HDF5 : public Benchmark_hdf5, public ::testing::Test { // convert golden_ids to int32 auto elem_cnt = result.value()->GetLims()[nq]; std::vector gt_ids_int(elem_cnt); - for (int32_t i = 0; i < elem_cnt; i++) { + for (size_t i = 0; i < elem_cnt; i++) { gt_ids_int[i] = result.value()->GetIds()[i]; } diff --git a/src/index/index.cc b/src/index/index.cc index 6aee5b4af..22d8515dc 100644 --- a/src/index/index.cc +++ b/src/index/index.cc @@ -81,7 +81,7 @@ Index::Search(const DataSet& dataset, const Json& json, const BitsetView& bit // when index is mutable, it could happen that data count larger than bitset size, see // https://github.com/zilliztech/knowhere/issues/70 // so something must be wrong at caller side when passed bitset size larger than data count - if (bitset_.size() > this->Count()) { + if (bitset_.size() > (size_t)this->Count()) { msg = fmt::format("bitset size should be <= data count, but we get bitset size: {}, data count: {}", bitset_.size(), this->Count()); LOG_KNOWHERE_ERROR_ << msg; @@ -132,7 +132,7 @@ Index::AnnIterator(const DataSet& dataset, const Json& json, const BitsetView // when index is mutable, it could happen that data count larger than bitset size, see // https://github.com/zilliztech/knowhere/issues/70 // so something must be wrong at caller side when passed bitset size larger than data count - if (bitset_.size() > this->Count()) { + if (bitset_.size() > (size_t)this->Count()) { msg = fmt::format("bitset size should be <= data count, but we get bitset size: {}, data count: {}", bitset_.size(), this->Count()); LOG_KNOWHERE_ERROR_ << msg; @@ -167,7 +167,7 @@ Index::RangeSearch(const DataSet& dataset, const Json& json, const BitsetView // when index is mutable, it could happen that data count larger than bitset size, see // https://github.com/zilliztech/knowhere/issues/70 // so something must be wrong at caller side when passed bitset size larger than data count - if (bitset_.size() > this->Count()) { + if (bitset_.size() > (size_t)this->Count()) { msg = fmt::format("bitset size should be <= data count, but we get bitset size: {}, data count: {}", bitset_.size(), this->Count()); LOG_KNOWHERE_ERROR_ << msg; diff --git a/tests/ut/test_range_util.cc b/tests/ut/test_range_util.cc index 326f5a466..88bec385c 100644 --- a/tests/ut/test_range_util.cc +++ b/tests/ut/test_range_util.cc @@ -116,6 +116,7 @@ TEST_CASE("Test GetRangeSearchResult for HNSW/DiskANN", "[range search]") { } /////////////////////////////////////////////////////////////////////////////// +#if 0 namespace { void GenRangeSearchResult(faiss::RangeSearchResult& res, const int64_t nq, const int64_t label_min, const int64_t label_max, @@ -157,3 +158,4 @@ CountValidRangeSearchResult(const float* distances, const size_t* lims, const in return valid; } } // namespace +#endif diff --git a/thirdparty/DiskANN/src/index.cpp b/thirdparty/DiskANN/src/index.cpp index e523d96b6..8360f4049 100644 --- a/thirdparty/DiskANN/src/index.cpp +++ b/thirdparty/DiskANN/src/index.cpp @@ -5,45 +5,35 @@ // CHECK FOR BULK AND FRESH // CHECK FOR FLOAT, INT8 and UINT8 -#include -#include -#include -// #include +#include +#include #include #include -#include #include -#include "knowhere/log.h" -#include "knowhere/comp/thread_pool.h" -#include "tsl/robin_set.h" -#include "tsl/robin_map.h" -#include +#include -#include -#include -#include +#include "boost/dynamic_bitset.hpp" +#include "tsl/robin_set.h" +#include "diskann/ann_exception.h" #include "diskann/common_includes.h" +#include "diskann/index.h" #include "diskann/logger.h" -#include "diskann/exceptions.h" -#include "diskann/aligned_file_reader.h" -#include "diskann/math_utils.h" -#include "diskann/memory_mapper.h" #include "diskann/parameters.h" #include "diskann/partition_and_pq.h" #include "diskann/timer.h" #include "diskann/utils.h" -#include "diskann/ann_exception.h" +#include "knowhere/comp/thread_pool.h" +#include "knowhere/log.h" + #if defined(RELEASE_UNUSED_TCMALLOC_MEMORY_AT_CHECKPOINTS) && \ defined(DISKANN_BUILD) #include "gperftools/malloc_extension.h" #endif -#include "boost/dynamic_bitset.hpp" #if !defined(__ARM_NEON) || !defined(__aarch64__) #include #endif -#include "diskann/index.h" #define MAX_POINTS_FOR_USING_BITSET 10000000 diff --git a/thirdparty/DiskANN/src/pq_flash_index.cpp b/thirdparty/DiskANN/src/pq_flash_index.cpp index 4fc5b145a..9886da2fb 100644 --- a/thirdparty/DiskANN/src/pq_flash_index.cpp +++ b/thirdparty/DiskANN/src/pq_flash_index.cpp @@ -194,7 +194,7 @@ namespace diskann { if (coord_cache_buf == nullptr) { diskann::alloc_aligned((void **) &coord_cache_buf, coord_cache_buf_len * sizeof(T), 8 * sizeof(T)); - memset(coord_cache_buf, 0, coord_cache_buf_len * sizeof(T)); + std::fill_n(coord_cache_buf, coord_cache_buf_len, T()); } size_t BLOCK_SIZE = 32; @@ -273,7 +273,7 @@ namespace diskann { if (coord_cache_buf == nullptr) { diskann::alloc_aligned((void **) &coord_cache_buf, coord_cache_buf_len * sizeof(T), 8 * sizeof(T)); - memset(coord_cache_buf, 0, coord_cache_buf_len * sizeof(T)); + std::fill_n(coord_cache_buf, coord_cache_buf_len, T()); } async_pool.push([&, state_controller = this->state_controller, sample_bin, diff --git a/thirdparty/faiss/faiss/IndexIVFFastScan.cpp b/thirdparty/faiss/faiss/IndexIVFFastScan.cpp index d647c703b..e3093e5fa 100644 --- a/thirdparty/faiss/faiss/IndexIVFFastScan.cpp +++ b/thirdparty/faiss/faiss/IndexIVFFastScan.cpp @@ -303,7 +303,7 @@ void IndexIVFFastScan::compute_LUT_uint8( // OMP for MSVC requires i to have signed integral type #pragma omp parallel for if (n > 100) - for (int64_t i = 0; i < n; i++) { + for (size_t i = 0; i < n; i++) { const float* t_in = dis_tables_float.get() + i * dim123; const float* b_in = nullptr; uint8_t* t_out = dis_tables.get() + i * dim123_2; @@ -492,7 +492,7 @@ int compute_search_nslice( size_t n, size_t nprobe) { int nslice; - if (n <= omp_get_max_threads()) { + if (n <= (size_t)omp_get_max_threads()) { nslice = n; } else if (index->lookup_table_is_3d()) { // make sure we don't make too big LUT tables @@ -839,7 +839,7 @@ void IndexIVFFastScan::search_implem_1( if (single_LUT) { LUT = dis_tables.get() + i * dim12; } - for (idx_t j = 0; j < nprobe; j++) { + for (size_t j = 0; j < nprobe; j++) { if (!single_LUT) { LUT = dis_tables.get() + (i * nprobe + j) * dim12; } @@ -916,7 +916,7 @@ void IndexIVFFastScan::search_implem_2( if (single_LUT) { LUT = dis_tables.get() + i * dim12; } - for (idx_t j = 0; j < nprobe; j++) { + for (size_t j = 0; j < nprobe; j++) { if (!single_LUT) { LUT = dis_tables.get() + (i * nprobe + j) * dim12; } @@ -975,10 +975,10 @@ void IndexIVFFastScan::search_implem_10( const NormTableScaler* scaler, const IVFSearchParameters* params) const { // const size_t nprobe = params ? params->nprobe : this->nprobe; - const size_t max_codes = params ? params->max_codes : this->max_codes; + // const size_t max_codes = params ? params->max_codes : this->max_codes; // const IDSelector* sel = params ? params->sel : nullptr; - const SearchParameters* quantizer_params = - params ? params->quantizer_params : nullptr; + // const SearchParameters* quantizer_params = + // params ? params->quantizer_params : nullptr; size_t dim12 = ksub * M2; AlignedTable dis_tables; @@ -1003,7 +1003,7 @@ void IndexIVFFastScan::search_implem_10( if (single_LUT) { LUT = dis_tables.get() + i * dim12; } - for (idx_t j = 0; j < nprobe; j++) { + for (size_t j = 0; j < nprobe; j++) { size_t ij = i * nprobe + j; if (!single_LUT) { LUT = dis_tables.get() + ij * dim12; @@ -1056,10 +1056,10 @@ void IndexIVFFastScan::range_search_implem_10( const NormTableScaler* scaler, const IVFSearchParameters* params) const { // const size_t nprobe = params ? params->nprobe : this->nprobe; - const size_t max_codes = params ? params->max_codes : this->max_codes; + // const size_t max_codes = params ? params->max_codes : this->max_codes; // const IDSelector* sel = params ? params->sel : nullptr; - const SearchParameters* quantizer_params = - params ? params->quantizer_params : nullptr; + // const SearchParameters* quantizer_params = + // params ? params->quantizer_params : nullptr; const size_t max_empty_result_buckets = params ? params->max_empty_result_buckets : 1; @@ -1088,7 +1088,7 @@ void IndexIVFFastScan::range_search_implem_10( if (single_LUT) { LUT = dis_tables.get() + i * dim12; } - for (idx_t j = 0; j < nprobe; j++) { + for (size_t j = 0; j < nprobe; j++) { size_t ij = i * nprobe + j; if (!single_LUT) { LUT = dis_tables.get() + ij * dim12; @@ -1183,7 +1183,7 @@ void IndexIVFFastScan::search_implem_12( { int ij = 0; for (int i = 0; i < n; i++) { - for (int j = 0; j < nprobe; j++) { + for (size_t j = 0; j < nprobe; j++) { if (cq.ids[ij] >= 0) { qcs.push_back(QC{i, int(cq.ids[ij]), int(j)}); } @@ -1321,7 +1321,7 @@ void IndexIVFFastScan::range_search_implem_12( { int ij = 0; for (int i = 0; i < n; i++) { - for (int j = 0; j < nprobe; j++) { + for (size_t j = 0; j < nprobe; j++) { if (cq.ids[ij] >= 0) { qcs.push_back(QC{i, int(cq.ids[ij]), int(j)}); } @@ -1468,7 +1468,7 @@ void IndexIVFFastScan::search_implem_14( { int ij = 0; for (int i = 0; i < n; i++) { - for (int j = 0; j < nprobe; j++) { + for (size_t j = 0; j < nprobe; j++) { if (cq.ids[ij] >= 0) { qcs.push_back(QC{i, int(cq.ids[ij]), int(j)}); } @@ -1564,7 +1564,7 @@ void IndexIVFFastScan::search_implem_14( std::set q_set; #pragma omp for schedule(dynamic) - for (idx_t cluster = 0; cluster < ses.size(); cluster++) { + for (size_t cluster = 0; cluster < ses.size(); cluster++) { size_t i0 = ses[cluster].start; size_t i1 = ses[cluster].end; size_t list_size = ses[cluster].list_size; diff --git a/thirdparty/faiss/faiss/IndexIVFPQFastScan.cpp b/thirdparty/faiss/faiss/IndexIVFPQFastScan.cpp index b45ad6331..4bfae9f8e 100644 --- a/thirdparty/faiss/faiss/IndexIVFPQFastScan.cpp +++ b/thirdparty/faiss/faiss/IndexIVFPQFastScan.cpp @@ -159,7 +159,7 @@ void IndexIVFPQFastScan::encode_vectors( bool include_listnos) const { if (by_residual) { AlignedTable residuals(n * d); - for (size_t i = 0; i < n; i++) { + for (int64_t i = 0; i < n; i++) { if (list_nos[i] < 0) { memset(residuals.data() + i * d, 0, sizeof(residuals[0]) * d); } else { @@ -236,7 +236,7 @@ void IndexIVFPQFastScan::compute_LUT( pq.compute_inner_prod_tables(n, x, ip_table.get()); #pragma omp parallel for if (n * nprobe > 8000) - for (idx_t ij = 0; ij < n * nprobe; ij++) { + for (size_t ij = 0; ij < n * nprobe; ij++) { idx_t i = ij / nprobe; float* tab = dis_tables.get() + ij * dim12; idx_t cij = cq.ids[ij]; @@ -261,7 +261,7 @@ void IndexIVFPQFastScan::compute_LUT( memset(biases.get(), 0, sizeof(float) * n * nprobe); #pragma omp parallel for if (n * nprobe > 8000) - for (idx_t ij = 0; ij < n * nprobe; ij++) { + for (size_t ij = 0; ij < n * nprobe; ij++) { idx_t i = ij / nprobe; float* xij = &xrel[ij * d]; idx_t cij = cq.ids[ij]; @@ -317,7 +317,7 @@ void IndexIVFPQFastScan::sa_decode(idx_t n, const uint8_t* codes, float* x) pq.decode(code + coarse_size, xi); if (by_residual) { quantizer->reconstruct(list_no, residual.data()); - for (size_t j = 0; j < d; j++) { + for (int j = 0; j < d; j++) { xi[j] += residual[j]; } } diff --git a/thirdparty/faiss/faiss/impl/index_read.cpp b/thirdparty/faiss/faiss/impl/index_read.cpp index 5871fe3c2..165683715 100644 --- a/thirdparty/faiss/faiss/impl/index_read.cpp +++ b/thirdparty/faiss/faiss/impl/index_read.cpp @@ -1157,7 +1157,7 @@ Index* read_index(IOReader* f, int io_flags) { idx = idxhnsw; } else if ( h == fourcc("INSf") || h == fourcc("INSp") || h == fourcc("INSs")) { - IndexNSG* idxnsg; + IndexNSG* idxnsg = nullptr; if (h == fourcc("INSf")) idxnsg = new IndexNSGFlat(); if (h == fourcc("INSp")) diff --git a/thirdparty/faiss/faiss/impl/simd_result_handlers.h b/thirdparty/faiss/faiss/impl/simd_result_handlers.h index a278d9212..26ebd88e0 100644 --- a/thirdparty/faiss/faiss/impl/simd_result_handlers.h +++ b/thirdparty/faiss/faiss/impl/simd_result_handlers.h @@ -692,7 +692,7 @@ struct RangeHandler : ResultHandlerCompare { void begin(const float* norms) override { normalizers = norms; - for (int q = 0; q < nq; ++q) { + for (size_t q = 0; q < nq; ++q) { thresholds[q] = normalizers[2 * q] * (radius - normalizers[2 * q + 1]); } @@ -754,7 +754,7 @@ struct RangeHandler : ResultHandlerCompare { memmove(rres.lims + 1, rres.lims, sizeof(*rres.lims) * rres.nq); rres.lims[0] = 0; - for (int q = 0; q < nq; q++) { + for (size_t q = 0; q < nq; q++) { float one_a = 1 / normalizers[2 * q]; float b = normalizers[2 * q + 1]; for (size_t i = rres.lims[q]; i < rres.lims[q + 1]; i++) { @@ -801,7 +801,7 @@ struct PartialRangeHandler : RangeHandler { // commit to partial result instead of full RangeResult void end() override { std::vector sorted_triplets(triplets.size()); - for (int q = 0; q < nq; q++) { + for (size_t q = 0; q < nq; q++) { n_per_query[q + 1] += n_per_query[q]; } shift_n_per_query(); @@ -813,7 +813,7 @@ struct PartialRangeHandler : RangeHandler { size_t* lims = n_per_query.data(); - for (int q = 0; q < nq; q++) { + for (size_t q = 0; q < nq; q++) { float one_a = 1 / normalizers[2 * q]; float b = normalizers[2 * q + 1]; RangeQueryResult& qres = pres.new_result(q + q0); diff --git a/thirdparty/faiss/faiss/utils/distances_if.h b/thirdparty/faiss/faiss/utils/distances_if.h index 3fb8cb685..f42fa5b98 100644 --- a/thirdparty/faiss/faiss/utils/distances_if.h +++ b/thirdparty/faiss/faiss/utils/distances_if.h @@ -70,7 +70,7 @@ void buffered_if( // todo: maybe add a special case "ny < N" right here const size_t ny_buffer_size = (ny / BUFFER_SIZE) * BUFFER_SIZE; - size_t saved_j[2 * BUFFER_SIZE + N]; + size_t saved_j[2 * BUFFER_SIZE + N] = {0}; size_t counter = 0; for (size_t j = 0; j < ny_buffer_size; j += BUFFER_SIZE) { diff --git a/thirdparty/faiss/faiss/utils/distances_simd.cpp b/thirdparty/faiss/faiss/utils/distances_simd.cpp index 75c501570..749e9c3f2 100644 --- a/thirdparty/faiss/faiss/utils/distances_simd.cpp +++ b/thirdparty/faiss/faiss/utils/distances_simd.cpp @@ -98,7 +98,7 @@ void compute_PQ_dis_tables_dsub2( for (int k0 = 0; k0 < ksub; k0 += 8) { simd8float32 centroids[8]; for (int k = 0; k < 8; k++) { - ALIGNED(32) float centroid[8]; + ALIGNED(32) float centroid[8] = {0}; size_t wp = 0; size_t rp = (m0 * ksub + k + k0) * 2; for (int m = m0; m < m1; m++) { diff --git a/thirdparty/faiss/faiss/utils/hamming_distance/generic-inl.h b/thirdparty/faiss/faiss/utils/hamming_distance/generic-inl.h index 75d6554bf..5beb20111 100644 --- a/thirdparty/faiss/faiss/utils/hamming_distance/generic-inl.h +++ b/thirdparty/faiss/faiss/utils/hamming_distance/generic-inl.h @@ -309,7 +309,6 @@ struct HammingComputerDefault { const uint8_t* a = a8 + 8 * quotient8; const uint8_t* b = b8 + 8 * quotient8; switch (remainder8) { - [[fallthrough]]; case 7: accu += hamdis_tab_ham_bytes[a[6] ^ b[6]]; [[fallthrough]]; diff --git a/thirdparty/faiss/faiss/utils/partitioning_avx2.cpp b/thirdparty/faiss/faiss/utils/partitioning_avx2.cpp index 3270e7100..893f469d8 100644 --- a/thirdparty/faiss/faiss/utils/partitioning_avx2.cpp +++ b/thirdparty/faiss/faiss/utils/partitioning_avx2.cpp @@ -286,7 +286,7 @@ uint16_t simd_partition_fuzzy_with_bounds( n_eq_1 = q; IFV printf(" override: thresh=%d n_eq_1=%ld\n", thresh, n_eq_1); } else { - assert(n_eq_1 <= n_eq); + assert((size_t)n_eq_1 <= n_eq); } size_t wp = simd_compress_array(vals, ids, n, thresh, n_eq_1); diff --git a/thirdparty/hnswlib/hnswlib/hnswalg.h b/thirdparty/hnswlib/hnswlib/hnswalg.h index ca84ed4d3..5e347b1fd 100644 --- a/thirdparty/hnswlib/hnswlib/hnswalg.h +++ b/thirdparty/hnswlib/hnswlib/hnswalg.h @@ -1392,7 +1392,7 @@ class HierarchicalNSW : public AlgorithmInterface { } std::unique_ptr query_data_sq; - const data_t* raw_data = (const data_t*)query_data; + [[maybe_unused]] const data_t* raw_data = (const data_t*)query_data; if constexpr (sq_enabled) { query_data_sq = std::make_unique(*(size_t*)dist_func_param_); encodeSQuant((const data_t*)query_data, query_data_sq.get());