Skip to content

Commit

Permalink
Fix some build warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Yudong <[email protected]>
  • Loading branch information
cydrain committed Dec 18, 2024
1 parent cae8d1f commit b9dd6ca
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 23 deletions.
2 changes: 2 additions & 0 deletions benchmark/hdf5/benchmark_float_qps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class Benchmark_float_qps : public Benchmark_knowhere, public ::testing::Test {
}
}

#ifdef KNOWHERE_WITH_DISKANN
template <typename T>
void
test_diskann(const knowhere::Json& cfg) {
Expand Down Expand Up @@ -309,6 +310,7 @@ class Benchmark_float_qps : 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());
}
}
#endif

private:
template <typename T>
Expand Down
14 changes: 8 additions & 6 deletions src/common/comp/brute_force.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ BruteForce::Search(const DataSetPtr base_dataset, const DataSetPtr query_dataset
BitsetViewIDSelector bw_idselector(bitset, xb_id_offset);
faiss::IDSelector* id_selector = (bitset.empty()) ? nullptr : &bw_idselector;

auto cur_query = (const DataType*)xq + dim * index;
switch (faiss_metric_type) {
case faiss::METRIC_L2: {
[[maybe_unused]] auto cur_query = (const DataType*)xq + dim * index;
if constexpr (std::is_same_v<DataType, knowhere::fp32>) {
faiss::float_maxheap_array_t buf{(size_t)1, (size_t)topk, cur_labels, cur_distances};
faiss::knn_L2sqr(cur_query, (const float*)xb, dim, 1, nb, &buf, nullptr, id_selector);
Expand All @@ -178,6 +178,7 @@ BruteForce::Search(const DataSetPtr base_dataset, const DataSetPtr query_dataset
break;
}
case faiss::METRIC_INNER_PRODUCT: {
[[maybe_unused]] auto cur_query = (const DataType*)xq + dim * index;
faiss::float_minheap_array_t buf{(size_t)1, (size_t)topk, cur_labels, cur_distances};
if (is_cosine) {
if constexpr (std::is_same_v<DataType, knowhere::fp32>) {
Expand Down Expand Up @@ -320,9 +321,9 @@ BruteForce::SearchWithBuf(const DataSetPtr base_dataset, const DataSetPtr query_

BitsetViewIDSelector bw_idselector(bitset, xb_id_offset);
faiss::IDSelector* id_selector = (bitset.empty()) ? nullptr : &bw_idselector;
auto cur_query = (const DataType*)xq + dim * index;
switch (faiss_metric_type) {
case faiss::METRIC_L2: {
[[maybe_unused]] auto cur_query = (const DataType*)xq + dim * index;
if constexpr (std::is_same_v<DataType, knowhere::fp32>) {
faiss::float_maxheap_array_t buf{(size_t)1, (size_t)topk, cur_labels, cur_distances};
faiss::knn_L2sqr(cur_query, (const float*)xb, dim, 1, nb, &buf, nullptr, id_selector);
Expand All @@ -336,6 +337,7 @@ BruteForce::SearchWithBuf(const DataSetPtr base_dataset, const DataSetPtr query_
break;
}
case faiss::METRIC_INNER_PRODUCT: {
[[maybe_unused]] auto cur_query = (const DataType*)xq + dim * index;
faiss::float_minheap_array_t buf{(size_t)1, (size_t)topk, cur_labels, cur_distances};
if (is_cosine) {
if constexpr (std::is_same_v<DataType, knowhere::fp32>) {
Expand Down Expand Up @@ -523,9 +525,9 @@ BruteForce::RangeSearch(const DataSetPtr base_dataset, const DataSetPtr query_da

BitsetViewIDSelector bw_idselector(bitset, xb_id_offset);
faiss::IDSelector* id_selector = (bitset.empty()) ? nullptr : &bw_idselector;
auto cur_query = (const DataType*)xq + dim * index;
switch (faiss_metric_type) {
case faiss::METRIC_L2: {
[[maybe_unused]] auto cur_query = (const DataType*)xq + dim * index;
if constexpr (std::is_same_v<DataType, knowhere::fp32>) {
faiss::range_search_L2sqr(cur_query, (const float*)xb, dim, 1, nb, radius, &res,
id_selector);
Expand All @@ -539,6 +541,7 @@ BruteForce::RangeSearch(const DataSetPtr base_dataset, const DataSetPtr query_da
break;
}
case faiss::METRIC_INNER_PRODUCT: {
[[maybe_unused]] auto cur_query = (const DataType*)xq + dim * index;
is_ip = true;
if (is_cosine) {
if constexpr (std::is_same_v<DataType, knowhere::fp32>) {
Expand Down Expand Up @@ -795,14 +798,13 @@ BruteForce::AnnIterator(const DataSetPtr base_dataset, const DataSetPtr query_da
ThreadPool::ScopedSearchOmpSetter setter(1);

BitsetViewIDSelector bw_idselector(bitset, xb_id_offset);
faiss::IDSelector* id_selector = (bitset.empty()) ? nullptr : &bw_idselector;
[[maybe_unused]] faiss::IDSelector* id_selector = (bitset.empty()) ? nullptr : &bw_idselector;
auto larger_is_closer = faiss::is_similarity_metric(faiss_metric_type) || is_cosine;
auto max_dis = larger_is_closer ? std::numeric_limits<float>::lowest() : std::numeric_limits<float>::max();
std::vector<DistId> distances_ids(nb, {-1, max_dis});
auto cur_query = (const DataType*)xq + dim * index;
[[maybe_unused]] auto cur_query = (const DataType*)xq + dim * index;
switch (faiss_metric_type) {
case faiss::METRIC_L2: {
auto cur_query = (const DataType*)xq + dim * index;
if constexpr (std::is_same_v<DataType, knowhere::fp32>) {
faiss::all_L2sqr(cur_query, (const float*)xb, dim, 1, nb, distances_ids, nullptr, id_selector);
} else if constexpr (KnowhereHalfPrecisionFloatPointTypeCheck<DataType>::value) {
Expand Down
10 changes: 5 additions & 5 deletions tests/ut/test_bruteforce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ check_search_with_out_ids(const uint64_t nb, const uint64_t nq, const uint64_t d
std::vector<float> dis(nq * k, std::numeric_limits<float>::quiet_NaN());
std::vector<int64_t> ids(nq * k, -1);
if (metric == knowhere::metric::L2) {
faiss::float_maxheap_array_t heaps{nq, k, ids.data(), dis.data()};
faiss::float_maxheap_array_t heaps{nq, (size_t)k, ids.data(), dis.data()};
heaps.heapify();
for (auto i = 0; i < block_prefix.size() - 1; i++) {
for (size_t i = 0; i < block_prefix.size() - 1; i++) {
auto begin_id = block_prefix[i];
auto end_id = block_prefix[i + 1];
auto blk_rows = end_id - begin_id;
Expand All @@ -120,9 +120,9 @@ check_search_with_out_ids(const uint64_t nb, const uint64_t nq, const uint64_t d
}
heaps.reorder();
} else {
faiss::float_minheap_array_t heaps{nq, k, ids.data(), dis.data()};
faiss::float_minheap_array_t heaps{nq, (size_t)k, ids.data(), dis.data()};
heaps.heapify();
for (auto i = 0; i < block_prefix.size() - 1; i++) {
for (size_t i = 0; i < block_prefix.size() - 1; i++) {
auto begin_id = block_prefix[i];
auto end_id = block_prefix[i + 1];
auto blk_rows = end_id - begin_id;
Expand All @@ -139,7 +139,7 @@ check_search_with_out_ids(const uint64_t nb, const uint64_t nq, const uint64_t d
auto gt = knowhere::BruteForce::Search<T>(total_train_ds, query_ds, conf, bitset);
auto gt_ids = gt.value()->GetIds();
const float* gt_dis = gt.value()->GetDistance();
for (auto i = 0; i < nq * k; i++) {
for (size_t i = 0; i < nq * k; i++) {
REQUIRE(gt_ids[i] == ids[i]);
REQUIRE(GetRelativeLoss(gt_dis[i], dis[i]) < 0.00001);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ut/test_faiss_hnsw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ TEST_CASE("hnswlib to FAISS HNSW for HNSW_FLAT", "Check search fallback") {
const size_t DIM = 16;

const int32_t NB = 256;
const int32_t NQ = 16;
// const int32_t NQ = 16;
const int32_t TOPK = 16;

// create base json config
Expand Down
16 changes: 8 additions & 8 deletions tests/ut/test_feder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ TEST_CASE("Test Feder", "[feder]") {
return json;
};

auto hnsw_gen = [base_gen]() {
knowhere::Json json = base_gen();
json[knowhere::indexparam::HNSW_M] = 8;
json[knowhere::indexparam::EFCONSTRUCTION] = 200;
json[knowhere::indexparam::EF] = 16;
json[knowhere::indexparam::OVERVIEW_LEVELS] = 2;
return json;
};
// auto hnsw_gen = [base_gen]() {
// knowhere::Json json = base_gen();
// json[knowhere::indexparam::HNSW_M] = 8;
// json[knowhere::indexparam::EFCONSTRUCTION] = 200;
// json[knowhere::indexparam::EF] = 16;
// json[knowhere::indexparam::OVERVIEW_LEVELS] = 2;
// return json;
// };

const auto train_ds = GenDataSet(nb, dim, seed);
const auto query_ds = GenDataSet(nq, dim, seed);
Expand Down
2 changes: 2 additions & 0 deletions tests/ut/test_get_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ TEST_CASE("Test Binary Get Vector By Ids", "[Binary GetVectorByIds]") {
return json;
};

#ifdef KNOWHERE_WITH_CARDINAL
auto bin_hnsw_gen = [base_bin_gen]() {
knowhere::Json json = base_bin_gen();
json[knowhere::indexparam::HNSW_M] = 128;
json[knowhere::indexparam::EFCONSTRUCTION] = 100;
json[knowhere::indexparam::EF] = 64;
return json;
};
#endif

auto bin_flat_gen = base_bin_gen;

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/DiskANN/src/pq_flash_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ namespace diskann {

std::vector<Neighbor> full_retset;
full_retset.reserve(4096);
auto vec_hash = knowhere::hash_vec(query_float, data_dim);
// auto vec_hash = knowhere::hash_vec(query_float, data_dim);
_u32 best_medoid = 0;
// for tuning, do not use cache

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/faiss/faiss/cppcontrib/knowhere/impl/Neighbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NeighborSetPopList {

inline bool
insert(const Neighbor nbr, IteratorMinHeap* disqualified = nullptr) {
auto pos = std::upper_bound(&data_[0], &data_[0] + size_, nbr) - &data_[0];
size_t pos = std::upper_bound(&data_[0], &data_[0] + size_, nbr) - &data_[0];
if (pos >= capacity_) {
if (disqualified) {
disqualified->push(nbr);
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/faiss/faiss/impl/ResultHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ struct RangeSearchBlockResultHandler : BlockResultHandler<C> {
// it is a bit tricky to find the poper PartialResult structure
// because the inner loop is on db not on queries.

if (pr < j0s.size() && j0 == j0s[pr]) {
if ((size_t)pr < j0s.size() && j0 == j0s[pr]) {
pres = partial_results[pr];
pr++;
} else if (j0 == 0 && j0s.size() > 0) {
Expand Down

0 comments on commit b9dd6ca

Please sign in to comment.