Skip to content

Commit 902ea36

Browse files
Upgrade faiss to 1.41.1+, from e5114c23 to ef28c6be (#1558)
Signed-off-by: Alexandr Guzhva <alexanderguzhva@gmail.com>
1 parent 61737c7 commit 902ea36

106 files changed

Lines changed: 7140 additions & 2689 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmake/libs/libfaiss.cmake

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ knowhere_file_glob(
99
thirdparty/faiss/faiss/*.cpp
1010
thirdparty/faiss/faiss/impl/*.cpp
1111
thirdparty/faiss/faiss/impl/fast_scan/*.cpp
12+
thirdparty/faiss/faiss/impl/hnsw/*.cpp
1213
thirdparty/faiss/faiss/impl/pq_code_distance/*.cpp
1314
thirdparty/faiss/faiss/impl/scalar_quantizer/*.cpp
1415
thirdparty/faiss/faiss/invlists/*.cpp
@@ -32,11 +33,12 @@ knowhere_file_glob(
3233
GLOB
3334
FAISS_DD_AVX512_SRCS
3435
thirdparty/faiss/faiss/impl/fast_scan/impl-avx512.cpp
36+
thirdparty/faiss/faiss/impl/hnsw/avx512.cpp
3537
thirdparty/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx512.cpp
3638
thirdparty/faiss/faiss/impl/scalar_quantizer/sq-avx512.cpp
37-
# # temporarily disabled
38-
# thirdparty/faiss/faiss/utils/distances_fused/avx512.cpp
39+
thirdparty/faiss/faiss/utils/distances_fused/avx512.cpp
3940
thirdparty/faiss/faiss/utils/simd_impl/distances_avx512.cpp
41+
thirdparty/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp
4042
)
4143
# combine files
4244
list(APPEND FAISS_AVX512_SRCS ${FAISS_DD_AVX512_SRCS})
@@ -56,9 +58,12 @@ knowhere_file_glob(
5658
FAISS_DD_AVX2_SRCS
5759
thirdparty/faiss/faiss/impl/approx_topk/avx2.cpp
5860
thirdparty/faiss/faiss/impl/fast_scan/impl-avx2.cpp
61+
thirdparty/faiss/faiss/impl/hnsw/avx2.cpp
5962
thirdparty/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx2.cpp
6063
thirdparty/faiss/faiss/impl/scalar_quantizer/sq-avx2.cpp
64+
thirdparty/faiss/faiss/utils/distances_fused/simdlib_based.cpp
6165
thirdparty/faiss/faiss/utils/simd_impl/distances_avx2.cpp
66+
thirdparty/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp
6267
)
6368
# combine files
6469
list(APPEND FAISS_AVX2_SRCS ${FAISS_DD_AVX2_SRCS})
@@ -97,7 +102,9 @@ knowhere_file_glob(
97102
thirdparty/faiss/faiss/impl/approx_topk/neon.cpp
98103
thirdparty/faiss/faiss/impl/fast_scan/impl-neon.cpp
99104
thirdparty/faiss/faiss/impl/scalar_quantizer/sq-neon.cpp
105+
thirdparty/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp
100106
thirdparty/faiss/faiss/utils/simd_impl/distances_aarch64.cpp
107+
thirdparty/faiss/faiss/utils/simd_impl/rabitq_neon.cpp
101108
)
102109
# combine files
103110
list(APPEND FAISS_NEON_SRCS ${FAISS_DD_NEON_SRCS})

thirdparty/faiss/benchs/avx512_result_handlers/bench_avx512_result_handler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#if defined(__x86_64__)
9+
810
#include "faiss_avx512_result_handler.h"
911

1012
#include <faiss/IndexIVF.h>
@@ -125,3 +127,5 @@ int main() {
125127

126128
return 0;
127129
}
130+
131+
#endif // defined(__x86_64__)

thirdparty/faiss/benchs/avx512_result_handlers/faiss_avx512_result_handler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#if defined(__x86_64__)
11+
1012
#include <faiss/impl/FaissAssert.h>
1113
#include <faiss/impl/ResultHandler.h>
1214
#include <immintrin.h>
@@ -145,3 +147,5 @@ struct ReservoirResultHandlerAVX512 : ResultHandler {
145147
};
146148

147149
} // namespace faiss
150+
151+
#endif // defined(__x86_64__)

thirdparty/faiss/benchs/avx512_result_handlers/partition.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#if defined(__x86_64__)
9+
810
#include "partition.h"
911

1012
#include <algorithm>
1113
#include <cassert>
1214
#include <cstdint>
13-
#include <cstdio>
1415
#include <cstring>
1516
#include <limits>
1617
#include <numeric>
@@ -601,3 +602,5 @@ void argsort(size_t n, float* val, int32_t* idx) {
601602
argsort(left_size, val, idx);
602603
argsort(n - left_size, val + left_size, idx + left_size);
603604
}
605+
606+
#endif // defined(__x86_64__)

thirdparty/faiss/benchs/avx512_result_handlers/partition.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#if defined(__x86_64__)
11+
1012
#include <cstddef>
1113
#include <cstdint>
1214

@@ -38,3 +40,5 @@ void argpartition(size_t n, float* val, int32_t* idx, size_t k);
3840
* @param idx Array of indices (modified in place, reordered with values)
3941
*/
4042
void argsort(size_t n, float* val, int32_t* idx);
43+
44+
#endif // defined(__x86_64__)

thirdparty/faiss/benchs/avx512_result_handlers/test_bitonic.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7+
8+
#if defined(__x86_64__)
9+
710
#include <immintrin.h>
811
#include <algorithm>
912
#include <cassert>
@@ -109,3 +112,5 @@ int main() {
109112

110113
return 0;
111114
}
115+
116+
#endif // defined(__x86_64__)

thirdparty/faiss/benchs/avx512_result_handlers/test_partition.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#if defined(__x86_64__)
9+
810
#include <gtest/gtest.h>
911

1012
#include "partition.h"
@@ -170,3 +172,5 @@ TEST(ArgpartitionTest, PartitionsCorrectly) {
170172
}
171173
}
172174
}
175+
176+
#endif // defined(__x86_64__)

thirdparty/faiss/benchs/bench_cppcontrib_sa_decode.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <iostream>
1313
#include <memory>
1414
#include <random>
15-
#include <thread>
1615
#include <tuple>
1716
#include <vector>
1817

@@ -32,7 +31,7 @@ std::tuple<std::shared_ptr<faiss::Index>, std::vector<uint8_t>> trainDataset(
3231
const uint64_t d,
3332
const std::string& description) {
3433
//
35-
omp_set_num_threads(std::thread::hardware_concurrency());
34+
omp_set_num_threads(omp_get_max_threads());
3635

3736
// train an index
3837
auto index = std::shared_ptr<faiss::Index>(

thirdparty/faiss/benchs/bench_hnsw_flat_panorama.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,22 @@
2626

2727
def eval_recall(index, efSearch_val, xq, gt, k):
2828
"""Evaluate recall and QPS for a given efSearch value."""
29+
nq = len(xq)
30+
faiss.cvar.indexPanorama_stats.reset()
2931
t0 = time.time()
3032
_, I = index.search(xq, k=k)
3133
t = time.time() - t0
32-
speed = t * 1000 / len(xq)
34+
speed = t * 1000 / nq
3335
qps = 1000 / speed
3436

35-
corrects = (gt == I).sum()
36-
recall = corrects / (len(xq) * k)
37+
recall = np.mean(
38+
[len(set(gt[i]) & set(I[i])) / k for i in range(nq)],
39+
)
40+
ratio_dims_scanned = faiss.cvar.indexPanorama_stats.ratio_dims_scanned
3741
print(
3842
f"\tefSearch {efSearch_val:3d}, Recall@{k}: "
39-
f"{recall:.6f}, speed: {speed:.6f} ms/query, QPS: {qps:.2f}"
43+
f"{recall:.6f}, speed: {speed:.6f} ms/query, QPS: {qps:.2f}, "
44+
f"dims scanned: {ratio_dims_scanned * 100:.1f}%"
4045
)
4146

4247
return recall, qps

thirdparty/faiss/c_api/utils/distances_c.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ void faiss_fvec_norms_L2sqr(float* norms, const float* x, size_t d, size_t nx);
7474
/// L2-renormalize a set of vector. Nothing done if the vector is 0-normed
7575
void faiss_fvec_renorm_L2(size_t d, size_t nx, float* x);
7676

77-
/// Setter of threshold value on nx above which we switch to BLAS to compute
77+
/// Setter of threshold value on nx * d above which we switch to BLAS to compute
7878
/// distances
7979
void faiss_set_distance_compute_blas_threshold(int value);
8080

81-
/// Getter of threshold value on nx above which we switch to BLAS to compute
81+
/// Getter of threshold value on nx * d above which we switch to BLAS to compute
8282
/// distances
8383
int faiss_get_distance_compute_blas_threshold();
8484

0 commit comments

Comments
 (0)