Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit 470de66

Browse files
authored
Update diskann benchmark (#984)
Signed-off-by: Yudong Cai <yudong.cai@zilliz.com>
1 parent 4771575 commit 470de66

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ knowhere_file_glob(GLOB_RECURSE KNOWHERE_SRCS src/common/*.cc src/index/*.cc
9797
set(KNOWHERE_LINKER_LIBS "")
9898

9999
if(WITH_DISKANN)
100+
add_definitions(-DKNOWHERE_WITH_DISKANN)
100101
include(cmake/libs/libdiskann.cmake)
101102
else()
102103
knowhere_file_glob(GLOB_RECURSE KNOWHERE_DISKANN_SRCS src/index/diskann/*.cc)

benchmark/hdf5/benchmark_float.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ std::string kIPIndexDir = kDir + "/ip_index";
2727
std::string kL2IndexPrefix = kL2IndexDir + "/l2";
2828
std::string kIPIndexPrefix = kIPIndexDir + "/ip";
2929

30-
constexpr uint32_t kNumRows = 10000;
31-
constexpr uint32_t kNumQueries = 100;
32-
constexpr uint32_t kDim = 128;
33-
constexpr uint32_t kK = 10;
34-
constexpr float kL2KnnRecall = 0.8;
35-
3630
void
3731
WriteRawDataToDisk(const std::string data_path, const float* raw_data, const uint32_t num, const uint32_t dim) {
3832
std::ofstream writer(data_path.c_str(), std::ios::binary);
@@ -119,14 +113,17 @@ class Benchmark_float : public Benchmark_knowhere, public ::testing::Test {
119113
printf("[%.3f s] Test '%s/%s' done\n\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str());
120114
}
121115

116+
#ifdef KNOWHERE_WITH_DISKANN
122117
void
123118
test_diskann(const knowhere::Json& cfg) {
124119
auto conf = cfg;
125120
conf["index_prefix"] = (metric_type_ == knowhere::metric::L2 ? kL2IndexPrefix : kIPIndexPrefix);
126-
conf["num_threads"] = 8;
127121
conf["search_cache_budget_gb"] = 0;
128122
conf["beamwidth"] = 8;
129123

124+
knowhere::BinarySet binset;
125+
index_.Deserialize(binset, conf);
126+
130127
printf("\n[%0.3f s] %s | %s \n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str());
131128
printf("================================================================================\n");
132129
for (auto nq : NQs_) {
@@ -144,6 +141,7 @@ class Benchmark_float : public Benchmark_knowhere, public ::testing::Test {
144141
printf("================================================================================\n");
145142
printf("[%.3f s] Test '%s/%s' done\n\n", get_time_diff(), ann_test_name_.c_str(), index_type_.c_str());
146143
}
144+
#endif
147145

148146
protected:
149147
void
@@ -255,6 +253,7 @@ TEST_F(Benchmark_float, TEST_HNSW) {
255253
}
256254
}
257255

256+
#ifdef KNOWHERE_WITH_DISKANN
258257
TEST_F(Benchmark_float, TEST_DISKANN) {
259258
index_type_ = knowhere::IndexEnum::INDEX_DISKANN;
260259

@@ -264,9 +263,8 @@ TEST_F(Benchmark_float, TEST_DISKANN) {
264263
conf["data_path"] = kRawDataPath;
265264
conf["max_degree"] = 56;
266265
conf["search_list_size"] = 128;
267-
conf["pq_code_budget_gb"] = sizeof(float) * kDim * kNumRows * 0.125 / (1024 * 1024 * 1024);
266+
conf["pq_code_budget_gb"] = sizeof(float) * dim_ * nb_ * 0.125 / (1024 * 1024 * 1024);
268267
conf["build_dram_budget_gb"] = 32.0;
269-
conf["num_threads"] = 8;
270268

271269
fs::create_directory(kDir);
272270
fs::create_directory(kL2IndexDir);
@@ -283,3 +281,4 @@ TEST_F(Benchmark_float, TEST_DISKANN) {
283281
index_.Build(*ds_ptr, conf);
284282
test_diskann(conf);
285283
}
284+
#endif

benchmark/hdf5/ref_logs/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test_binary_range_hnsw:
2222

2323
###################################################################################################
2424
# Test Knowhere float index
25-
test_float: test_float_idmap test_float_ivf_flat test_float_ivf_sq8 test_float_ivf_pq test_float_hnsw
25+
test_float: test_float_idmap test_float_ivf_flat test_float_ivf_sq8 test_float_ivf_pq test_float_hnsw test_float_diskann
2626
test_float_gpu: test_float_ivf_flat test_float_ivf_pq
2727

2828
test_float_idmap:
@@ -35,6 +35,8 @@ test_float_ivf_pq:
3535
./benchmark_float --gtest_filter="Benchmark_float.TEST_IVF_PQ" | tee test_float_ivf_pq.log
3636
test_float_hnsw:
3737
./benchmark_float --gtest_filter="Benchmark_float.TEST_HNSW" | tee test_float_hnsw.log
38+
test_float_diskann:
39+
./benchmark_float --gtest_filter="Benchmark_float.TEST_DISKANN" | tee test_float_diskann.log
3840

3941
###################################################################################################
4042
# Test Knowhere float index bitset

src/common/comp/knowhere_config.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
#include <string>
1515

16+
#ifdef KNOWHERE_WITH_DISKANN
17+
#include "diskann/aio_context_pool.h"
18+
#endif
1619
#include "faiss/Clustering.h"
1720
#include "faiss/utils/distances.h"
18-
#include "faiss/utils/utils.h"
1921
#include "knowhere/log.h"
2022
#ifdef KNOWHERE_WITH_GPU
2123
#include "index/gpu/gpu_res_mgr.h"

tests/ut/test_search.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ TEST_CASE("Test Mem Index With Binary Vector", "[bool metrics]") {
428428
}
429429
}
430430

431+
#if 0
431432
SECTION("Test Range Search") {
432433
using std::make_tuple;
433434
auto [name, gen] = GENERATE_REF(table<std::string, std::function<knowhere::Json()>>({
@@ -449,4 +450,5 @@ TEST_CASE("Test Mem Index With Binary Vector", "[bool metrics]") {
449450
auto results = idx.RangeSearch(*query_ds, json, nullptr);
450451
REQUIRE(results.error() == knowhere::Status::faiss_inner_error);
451452
}
453+
#endif
452454
}

tests/ut/test_simd.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "knowhere/comp/brute_force.h"
1616
#include "knowhere/comp/index_param.h"
1717
#include "knowhere/comp/knowhere_config.h"
18-
#include "knowhere/utils.h"
1918
#include "utils.h"
2019

2120
TEST_CASE("Test BruteForce Search SIMD", "[bf]") {
@@ -54,9 +53,9 @@ TEST_CASE("Test BruteForce Search SIMD", "[bf]") {
5453
}
5554
};
5655

57-
for (auto simd_type : {knowhere::KnowhereConfig::SimdType::AUTO, knowhere::KnowhereConfig::SimdType::AVX512,
58-
knowhere::KnowhereConfig::SimdType::AVX2, knowhere::KnowhereConfig::SimdType::SSE4_2,
59-
knowhere::KnowhereConfig::SimdType::GENERIC}) {
56+
for (auto simd_type : {knowhere::KnowhereConfig::SimdType::AVX512, knowhere::KnowhereConfig::SimdType::AVX2,
57+
knowhere::KnowhereConfig::SimdType::SSE4_2, knowhere::KnowhereConfig::SimdType::GENERIC,
58+
knowhere::KnowhereConfig::SimdType::AUTO}) {
6059
test_search_with_simd(simd_type);
6160
}
6261
}
@@ -105,7 +104,7 @@ TEST_CASE("Test PQ Search SIMD", "[pq]") {
105104
REQUIRE(recall > 0.2);
106105
};
107106

108-
for (auto simd_type : {knowhere::KnowhereConfig::SimdType::SSE4_2, knowhere::KnowhereConfig::SimdType::GENERIC}) {
107+
for (auto simd_type : {knowhere::KnowhereConfig::SimdType::GENERIC, knowhere::KnowhereConfig::SimdType::AUTO}) {
109108
for (int64_t m : {8, 16, 32, 64, 128}) {
110109
test_search_with_simd(m, simd_type);
111110
}

0 commit comments

Comments
 (0)