Skip to content

Commit 56f1392

Browse files
yuhaijun999ketor
authored andcommitted
[feat][index] Add diskann hook to speed up building and querying.
1 parent f0da846 commit 56f1392

File tree

3 files changed

+709
-0
lines changed

3 files changed

+709
-0
lines changed

src/diskann/diskann_item_manager.cc

+29
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
#include "proto/common.pb.h"
3333
#include "proto/error.pb.h"
3434

35+
#ifndef ENABLE_DISKANN_SIMD_HOOK
36+
#define ENABLE_DISKANN_SIMD_HOOK
37+
#endif
38+
39+
// #undef ENABLE_DISKANN_SIMD_HOOK
40+
41+
#if defined(ENABLE_DISKANN_SIMD_HOOK)
42+
#include "diskann_hook.h"
43+
#include "simd/hook.h"
44+
#endif
3545
namespace dingodb {
3646

3747
DiskANNItemManager::DiskANNItemManager()
@@ -112,6 +122,8 @@ bool DiskANNItemManager::Init(std::shared_ptr<Config> config) {
112122
DiskANNItem::SetImportTimeout(import_timeout_s_);
113123
DiskANNItem::SetBaseDir(path_);
114124

125+
DiskANNItemManager::SetSimdHookForDiskANN();
126+
115127
return true;
116128
}
117129

@@ -162,4 +174,21 @@ std::vector<std::shared_ptr<DiskANNItem>> DiskANNItemManager::FindAll() {
162174
return items;
163175
}
164176

177+
void DiskANNItemManager::SetSimdHookForDiskANN() {
178+
#if defined(ENABLE_DISKANN_SIMD_HOOK)
179+
std::string simd_type;
180+
fvec_hook_info(simd_type);
181+
182+
#if defined(__x86_64__)
183+
DINGO_LOG(INFO) << fmt::format("cpu_support_avx512 : {} cpu_support_avx2 : {} cpu_support_sse4_2 : {}",
184+
cpu_support_avx512() ? "true" : "false", cpu_support_avx2() ? "true" : "false",
185+
cpu_support_sse4_2() ? "true" : "false");
186+
#endif
187+
DINGO_LOG(INFO) << fmt::format("cpu simd_type : {}", simd_type);
188+
diskann::set_fvec_L2sqr_hook(fvec_L2sqr);
189+
diskann::set_fvec_inner_product_hook(fvec_inner_product);
190+
DINGO_LOG(INFO) << fmt::format("set diskann hook : {} {}", "fvec_L2sqr", "fvec_inner_product");
191+
#endif
192+
}
193+
165194
} // namespace dingodb

src/diskann/diskann_item_manager.h

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class DiskANNItemManager : public DiskANNItemManagerSingleton<DiskANNItemManager
6464

6565
std::vector<std::shared_ptr<DiskANNItem>> FindAll();
6666

67+
static void SetSimdHookForDiskANN();
68+
6769
protected:
6870
private:
6971
std::string path_;

0 commit comments

Comments
 (0)