Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize hgraph #281

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/algorithm/hgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ HGraph::KnnSearch(const DatasetPtr& query,
int64_t k,
const std::string& parameters,
const std::function<bool(int64_t)>& filter) const {
BitsetOrCallbackFilter ft(filter);
std::unique_ptr<BitsetOrCallbackFilter> ft = nullptr;
if (filter != nullptr) {
ft = std::make_unique<BitsetOrCallbackFilter>(filter);
}
try {
int64_t query_dim = query->GetDim();
CHECK_ARGUMENT(
Expand Down Expand Up @@ -183,7 +186,7 @@ HGraph::KnnSearch(const DatasetPtr& query,
auto params = HGraphSearchParameters::FromJson(parameters);

search_param.ef_ = params.ef_search;
search_param.is_id_allowed_ = &ft;
search_param.is_id_allowed_ = ft.get();
auto search_result = this->search_one_graph(query->GetFloat32Vectors(),
this->bottom_graph_,
this->basic_flatten_codes_,
Expand Down
8 changes: 4 additions & 4 deletions src/index/hgraph_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class HGraphIndex : public Index {
int64_t k,
const std::string& parameters,
BitsetPtr invalid = nullptr) const override {
auto func = [&invalid](int64_t id) -> bool {
if (invalid == nullptr) {
return false;
}
std::function<bool(int64_t)> func = [&invalid](int64_t id) -> bool {
int64_t bit_index = id & ROW_ID_MASK;
return invalid->Test(bit_index);
};
if (invalid == nullptr) {
func = nullptr;
}
SAFE_CALL(return this->hgraph_->KnnSearch(query, k, parameters, func));
}

Expand Down
7 changes: 1 addition & 6 deletions src/simd/avx512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@ SQ8UniformComputeCodesIP(const uint8_t* codes1, const uint8_t* codes2, uint64_t
return 0.0f;
}

alignas(64) int32_t temp[16];
int32_t result = 0;
uint64_t d = 0;
__m512i sum = _mm512_setzero_si512();
__m512i mask = _mm512_set1_epi16(0xff);
Expand All @@ -370,10 +368,7 @@ SQ8UniformComputeCodesIP(const uint8_t* codes1, const uint8_t* codes2, uint64_t
sum = _mm512_add_epi32(sum, _mm512_madd_epi16(xx1, yy1));
sum = _mm512_add_epi32(sum, _mm512_madd_epi16(xx2, yy2));
}
_mm512_store_si512(reinterpret_cast<__m512i*>(temp), sum);
for (int i = 0; i < 16; ++i) {
result += temp[i];
}
int32_t result = _mm512_reduce_add_epi32(sum);
result += static_cast<int32_t>(avx2::SQ8UniformComputeCodesIP(codes1 + d, codes2 + d, dim - d));
return static_cast<float>(result);
#else
Expand Down
Loading