faiss 0.1.7 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +7 -7
- data/ext/faiss/ext.cpp +1 -1
- data/ext/faiss/extconf.rb +8 -2
- data/ext/faiss/index.cpp +102 -69
- data/ext/faiss/index_binary.cpp +24 -30
- data/ext/faiss/kmeans.cpp +20 -16
- data/ext/faiss/numo.hpp +867 -0
- data/ext/faiss/pca_matrix.cpp +13 -14
- data/ext/faiss/product_quantizer.cpp +23 -24
- data/ext/faiss/utils.cpp +10 -37
- data/ext/faiss/utils.h +2 -13
- data/lib/faiss/version.rb +1 -1
- data/lib/faiss.rb +0 -5
- data/vendor/faiss/faiss/AutoTune.cpp +292 -291
- data/vendor/faiss/faiss/AutoTune.h +55 -56
- data/vendor/faiss/faiss/Clustering.cpp +334 -195
- data/vendor/faiss/faiss/Clustering.h +88 -35
- data/vendor/faiss/faiss/IVFlib.cpp +171 -195
- data/vendor/faiss/faiss/IVFlib.h +48 -51
- data/vendor/faiss/faiss/Index.cpp +85 -103
- data/vendor/faiss/faiss/Index.h +54 -48
- data/vendor/faiss/faiss/Index2Layer.cpp +139 -164
- data/vendor/faiss/faiss/Index2Layer.h +22 -22
- data/vendor/faiss/faiss/IndexBinary.cpp +45 -37
- data/vendor/faiss/faiss/IndexBinary.h +140 -132
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +73 -53
- data/vendor/faiss/faiss/IndexBinaryFlat.h +29 -24
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +46 -43
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +16 -15
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +215 -232
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +25 -24
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +182 -177
- data/vendor/faiss/faiss/IndexBinaryHash.h +41 -34
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +489 -461
- data/vendor/faiss/faiss/IndexBinaryIVF.h +97 -68
- data/vendor/faiss/faiss/IndexFlat.cpp +116 -147
- data/vendor/faiss/faiss/IndexFlat.h +35 -46
- data/vendor/faiss/faiss/IndexHNSW.cpp +372 -348
- data/vendor/faiss/faiss/IndexHNSW.h +57 -41
- data/vendor/faiss/faiss/IndexIVF.cpp +474 -454
- data/vendor/faiss/faiss/IndexIVF.h +146 -113
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +248 -250
- data/vendor/faiss/faiss/IndexIVFFlat.h +48 -51
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +457 -516
- data/vendor/faiss/faiss/IndexIVFPQ.h +74 -66
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +406 -372
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +82 -57
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +104 -102
- data/vendor/faiss/faiss/IndexIVFPQR.h +33 -28
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +125 -133
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +19 -21
- data/vendor/faiss/faiss/IndexLSH.cpp +75 -96
- data/vendor/faiss/faiss/IndexLSH.h +21 -26
- data/vendor/faiss/faiss/IndexLattice.cpp +42 -56
- data/vendor/faiss/faiss/IndexLattice.h +11 -16
- data/vendor/faiss/faiss/IndexNNDescent.cpp +231 -0
- data/vendor/faiss/faiss/IndexNNDescent.h +72 -0
- data/vendor/faiss/faiss/IndexNSG.cpp +303 -0
- data/vendor/faiss/faiss/IndexNSG.h +85 -0
- data/vendor/faiss/faiss/IndexPQ.cpp +405 -464
- data/vendor/faiss/faiss/IndexPQ.h +64 -67
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +143 -170
- data/vendor/faiss/faiss/IndexPQFastScan.h +46 -32
- data/vendor/faiss/faiss/IndexPreTransform.cpp +120 -150
- data/vendor/faiss/faiss/IndexPreTransform.h +33 -36
- data/vendor/faiss/faiss/IndexRefine.cpp +115 -131
- data/vendor/faiss/faiss/IndexRefine.h +22 -23
- data/vendor/faiss/faiss/IndexReplicas.cpp +147 -153
- data/vendor/faiss/faiss/IndexReplicas.h +62 -56
- data/vendor/faiss/faiss/IndexResidual.cpp +291 -0
- data/vendor/faiss/faiss/IndexResidual.h +152 -0
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +120 -155
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +41 -45
- data/vendor/faiss/faiss/IndexShards.cpp +256 -240
- data/vendor/faiss/faiss/IndexShards.h +85 -73
- data/vendor/faiss/faiss/MatrixStats.cpp +112 -97
- data/vendor/faiss/faiss/MatrixStats.h +7 -10
- data/vendor/faiss/faiss/MetaIndexes.cpp +135 -157
- data/vendor/faiss/faiss/MetaIndexes.h +40 -34
- data/vendor/faiss/faiss/MetricType.h +7 -7
- data/vendor/faiss/faiss/VectorTransform.cpp +652 -474
- data/vendor/faiss/faiss/VectorTransform.h +61 -89
- data/vendor/faiss/faiss/clone_index.cpp +77 -73
- data/vendor/faiss/faiss/clone_index.h +4 -9
- data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +33 -38
- data/vendor/faiss/faiss/gpu/GpuAutoTune.h +11 -9
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +197 -170
- data/vendor/faiss/faiss/gpu/GpuCloner.h +53 -35
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.cpp +12 -14
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +27 -25
- data/vendor/faiss/faiss/gpu/GpuDistance.h +116 -112
- data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +1 -2
- data/vendor/faiss/faiss/gpu/GpuIndex.h +134 -137
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +76 -73
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +173 -162
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +67 -64
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +89 -86
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +150 -141
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +101 -103
- data/vendor/faiss/faiss/gpu/GpuIndicesOptions.h +17 -16
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +116 -128
- data/vendor/faiss/faiss/gpu/GpuResources.h +182 -186
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +433 -422
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +131 -130
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +468 -456
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +25 -19
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +22 -20
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +9 -8
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +39 -44
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +16 -14
- data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +77 -71
- data/vendor/faiss/faiss/gpu/perf/PerfIVFPQAdd.cpp +109 -88
- data/vendor/faiss/faiss/gpu/perf/WriteIndex.cpp +75 -64
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +230 -215
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +80 -86
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +284 -277
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +416 -416
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +611 -517
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +166 -164
- data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +61 -53
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +274 -238
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +73 -57
- data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +47 -50
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +79 -72
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +140 -146
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.h +69 -71
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +21 -16
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +25 -29
- data/vendor/faiss/faiss/gpu/utils/Timer.h +30 -29
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +270 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +115 -0
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +90 -120
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +81 -65
- data/vendor/faiss/faiss/impl/FaissAssert.h +73 -58
- data/vendor/faiss/faiss/impl/FaissException.cpp +56 -48
- data/vendor/faiss/faiss/impl/FaissException.h +41 -29
- data/vendor/faiss/faiss/impl/HNSW.cpp +595 -611
- data/vendor/faiss/faiss/impl/HNSW.h +179 -200
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +672 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +172 -0
- data/vendor/faiss/faiss/impl/NNDescent.cpp +487 -0
- data/vendor/faiss/faiss/impl/NNDescent.h +154 -0
- data/vendor/faiss/faiss/impl/NSG.cpp +682 -0
- data/vendor/faiss/faiss/impl/NSG.h +199 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +484 -454
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +52 -55
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +26 -47
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +469 -459
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +76 -87
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +448 -0
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +130 -0
- data/vendor/faiss/faiss/impl/ResultHandler.h +96 -132
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +648 -701
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +48 -46
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +129 -131
- data/vendor/faiss/faiss/impl/ThreadedIndex.h +61 -55
- data/vendor/faiss/faiss/impl/index_read.cpp +547 -479
- data/vendor/faiss/faiss/impl/index_write.cpp +497 -407
- data/vendor/faiss/faiss/impl/io.cpp +75 -94
- data/vendor/faiss/faiss/impl/io.h +31 -41
- data/vendor/faiss/faiss/impl/io_macros.h +40 -29
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +137 -186
- data/vendor/faiss/faiss/impl/lattice_Zn.h +40 -51
- data/vendor/faiss/faiss/impl/platform_macros.h +29 -8
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +77 -124
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +39 -48
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +41 -52
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +80 -117
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +109 -137
- data/vendor/faiss/faiss/index_factory.cpp +269 -218
- data/vendor/faiss/faiss/index_factory.h +6 -7
- data/vendor/faiss/faiss/index_io.h +23 -26
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +67 -75
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +22 -24
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +96 -112
- data/vendor/faiss/faiss/invlists/DirectMap.h +29 -33
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +307 -364
- data/vendor/faiss/faiss/invlists/InvertedLists.h +151 -151
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +29 -34
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +17 -18
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +257 -293
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +50 -45
- data/vendor/faiss/faiss/python/python_callbacks.cpp +23 -26
- data/vendor/faiss/faiss/python/python_callbacks.h +9 -16
- data/vendor/faiss/faiss/utils/AlignedTable.h +79 -44
- data/vendor/faiss/faiss/utils/Heap.cpp +40 -48
- data/vendor/faiss/faiss/utils/Heap.h +186 -209
- data/vendor/faiss/faiss/utils/WorkerThread.cpp +67 -76
- data/vendor/faiss/faiss/utils/WorkerThread.h +32 -33
- data/vendor/faiss/faiss/utils/distances.cpp +301 -310
- data/vendor/faiss/faiss/utils/distances.h +133 -118
- data/vendor/faiss/faiss/utils/distances_simd.cpp +456 -516
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +117 -0
- data/vendor/faiss/faiss/utils/extra_distances.cpp +113 -232
- data/vendor/faiss/faiss/utils/extra_distances.h +30 -29
- data/vendor/faiss/faiss/utils/hamming-inl.h +260 -209
- data/vendor/faiss/faiss/utils/hamming.cpp +375 -469
- data/vendor/faiss/faiss/utils/hamming.h +62 -85
- data/vendor/faiss/faiss/utils/ordered_key_value.h +16 -18
- data/vendor/faiss/faiss/utils/partitioning.cpp +393 -318
- data/vendor/faiss/faiss/utils/partitioning.h +26 -21
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +78 -66
- data/vendor/faiss/faiss/utils/quantize_lut.h +22 -20
- data/vendor/faiss/faiss/utils/random.cpp +39 -63
- data/vendor/faiss/faiss/utils/random.h +13 -16
- data/vendor/faiss/faiss/utils/simdlib.h +4 -2
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +88 -85
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +226 -165
- data/vendor/faiss/faiss/utils/simdlib_neon.h +832 -0
- data/vendor/faiss/faiss/utils/utils.cpp +304 -287
- data/vendor/faiss/faiss/utils/utils.h +53 -48
- metadata +26 -12
- data/lib/faiss/index.rb +0 -20
- data/lib/faiss/index_binary.rb +0 -20
- data/lib/faiss/kmeans.rb +0 -15
- data/lib/faiss/pca_matrix.rb +0 -15
- data/lib/faiss/product_quantizer.rb +0 -22
@@ -20,10 +20,8 @@
|
|
20
20
|
* parallel compile times. Templates are instanciated explicitly.
|
21
21
|
*/
|
22
22
|
|
23
|
-
|
24
23
|
namespace faiss {
|
25
24
|
|
26
|
-
|
27
25
|
/** Pack codes for consumption by the SIMD kernels.
|
28
26
|
* The unused bytes are set to 0.
|
29
27
|
*
|
@@ -36,11 +34,13 @@ namespace faiss {
|
|
36
34
|
* @param blocks output array, size nb * nsq / 2.
|
37
35
|
*/
|
38
36
|
void pq4_pack_codes(
|
39
|
-
const uint8_t
|
40
|
-
size_t ntotal,
|
41
|
-
size_t
|
42
|
-
|
43
|
-
|
37
|
+
const uint8_t* codes,
|
38
|
+
size_t ntotal,
|
39
|
+
size_t M,
|
40
|
+
size_t nb,
|
41
|
+
size_t bbs,
|
42
|
+
size_t M2,
|
43
|
+
uint8_t* blocks);
|
44
44
|
|
45
45
|
/** Same as pack_codes but write in a given range of the output,
|
46
46
|
* leaving the rest untouched. Assumes allocated entries are 0 on input.
|
@@ -51,12 +51,13 @@ void pq4_pack_codes(
|
|
51
51
|
* @param blocks output array, size at least ceil(i1 / bbs) * bbs * nsq / 2
|
52
52
|
*/
|
53
53
|
void pq4_pack_codes_range(
|
54
|
-
const uint8_t
|
54
|
+
const uint8_t* codes,
|
55
55
|
size_t M,
|
56
|
-
size_t i0,
|
57
|
-
size_t
|
58
|
-
|
59
|
-
|
56
|
+
size_t i0,
|
57
|
+
size_t i1,
|
58
|
+
size_t bbs,
|
59
|
+
size_t M2,
|
60
|
+
uint8_t* blocks);
|
60
61
|
|
61
62
|
/** get a single element from a packed codes table
|
62
63
|
*
|
@@ -64,9 +65,11 @@ void pq4_pack_codes_range(
|
|
64
65
|
* @param sq subquantizer (< nsq)
|
65
66
|
*/
|
66
67
|
uint8_t pq4_get_packed_element(
|
67
|
-
const uint8_t
|
68
|
-
size_t
|
69
|
-
|
68
|
+
const uint8_t* data,
|
69
|
+
size_t bbs,
|
70
|
+
size_t nsq,
|
71
|
+
size_t i,
|
72
|
+
size_t sq);
|
70
73
|
|
71
74
|
/** Pack Look-up table for consumption by the kernel.
|
72
75
|
*
|
@@ -75,13 +78,7 @@ uint8_t pq4_get_packed_element(
|
|
75
78
|
* @param src input array, size (nq, 16)
|
76
79
|
* @param dest output array, size (nq, 16)
|
77
80
|
*/
|
78
|
-
void pq4_pack_LUT(
|
79
|
-
int nq, int nsq,
|
80
|
-
const uint8_t *src,
|
81
|
-
uint8_t *dest
|
82
|
-
);
|
83
|
-
|
84
|
-
|
81
|
+
void pq4_pack_LUT(int nq, int nsq, const uint8_t* src, uint8_t* dest);
|
85
82
|
|
86
83
|
/** Loop over database elements and accumulate results into result handler
|
87
84
|
*
|
@@ -92,16 +89,15 @@ void pq4_pack_LUT(
|
|
92
89
|
* @param codes packed codes array
|
93
90
|
* @param LUT packed look-up table
|
94
91
|
*/
|
95
|
-
template<class ResultHandler>
|
92
|
+
template <class ResultHandler>
|
96
93
|
void pq4_accumulate_loop(
|
97
94
|
int nq,
|
98
|
-
size_t nb,
|
95
|
+
size_t nb,
|
96
|
+
int bbs,
|
99
97
|
int nsq,
|
100
|
-
const uint8_t
|
101
|
-
const uint8_t
|
102
|
-
ResultHandler
|
103
|
-
|
104
|
-
|
98
|
+
const uint8_t* codes,
|
99
|
+
const uint8_t* LUT,
|
100
|
+
ResultHandler& res);
|
105
101
|
|
106
102
|
/* qbs versions, supported only for bbs=32.
|
107
103
|
*
|
@@ -115,8 +111,7 @@ void pq4_accumulate_loop(
|
|
115
111
|
* nq = 3 + 2 + 2 + 1 = 6 queries. For a given total block size, the optimal
|
116
112
|
* decomposition into sub-blocks (measured empirically) is given by
|
117
113
|
* preferred_qbs().
|
118
|
-
*/
|
119
|
-
|
114
|
+
*/
|
120
115
|
|
121
116
|
/* compute the number of queries from a base-16 decomposition */
|
122
117
|
int pq4_qbs_to_nq(int qbs);
|
@@ -133,18 +128,16 @@ int pq4_preferred_qbs(int nq);
|
|
133
128
|
* @param dest output array, size (nq, 16)
|
134
129
|
* @return nq
|
135
130
|
*/
|
136
|
-
int pq4_pack_LUT_qbs(
|
137
|
-
int fqbs, int nsq,
|
138
|
-
const uint8_t *src,
|
139
|
-
uint8_t *dest
|
140
|
-
);
|
131
|
+
int pq4_pack_LUT_qbs(int fqbs, int nsq, const uint8_t* src, uint8_t* dest);
|
141
132
|
|
142
|
-
/** Same as pq4_pack_LUT_qbs, except the source vectors are remapped with q_map
|
133
|
+
/** Same as pq4_pack_LUT_qbs, except the source vectors are remapped with q_map
|
134
|
+
*/
|
143
135
|
int pq4_pack_LUT_qbs_q_map(
|
144
|
-
int qbs,
|
145
|
-
|
146
|
-
const
|
147
|
-
|
136
|
+
int qbs,
|
137
|
+
int nsq,
|
138
|
+
const uint8_t* src,
|
139
|
+
const int* q_map,
|
140
|
+
uint8_t* dest);
|
148
141
|
|
149
142
|
/** Run accumulation loop.
|
150
143
|
*
|
@@ -155,15 +148,13 @@ int pq4_pack_LUT_qbs_q_map(
|
|
155
148
|
* @param LUT look-up table (packed)
|
156
149
|
* @param res call-back for the resutls
|
157
150
|
*/
|
158
|
-
template<class ResultHandler>
|
151
|
+
template <class ResultHandler>
|
159
152
|
void pq4_accumulate_loop_qbs(
|
160
153
|
int qbs,
|
161
154
|
size_t nb,
|
162
155
|
int nsq,
|
163
|
-
const uint8_t
|
164
|
-
const uint8_t
|
165
|
-
ResultHandler
|
166
|
-
|
167
|
-
|
156
|
+
const uint8_t* codes,
|
157
|
+
const uint8_t* LUT,
|
158
|
+
ResultHandler& res);
|
168
159
|
|
169
|
-
} // namespace faiss
|
160
|
+
} // namespace faiss
|
@@ -5,16 +5,13 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
7
|
|
8
|
-
|
9
8
|
#include <faiss/impl/pq4_fast_scan.h>
|
10
9
|
|
11
10
|
#include <faiss/impl/FaissAssert.h>
|
12
11
|
#include <faiss/impl/simd_result_handlers.h>
|
13
12
|
|
14
|
-
|
15
13
|
namespace faiss {
|
16
14
|
|
17
|
-
|
18
15
|
using namespace simd_result_handlers;
|
19
16
|
|
20
17
|
/***************************************************************
|
@@ -29,18 +26,17 @@ namespace {
|
|
29
26
|
* writes results in a ResultHandler
|
30
27
|
*/
|
31
28
|
|
32
|
-
template<int NQ, int BB, class ResultHandler>
|
29
|
+
template <int NQ, int BB, class ResultHandler>
|
33
30
|
void kernel_accumulate_block(
|
34
31
|
int nsq,
|
35
|
-
const uint8_t
|
36
|
-
const uint8_t
|
37
|
-
ResultHandler
|
38
|
-
{
|
32
|
+
const uint8_t* codes,
|
33
|
+
const uint8_t* LUT,
|
34
|
+
ResultHandler& res) {
|
39
35
|
// distance accumulators
|
40
36
|
simd16uint16 accu[NQ][BB][4];
|
41
37
|
|
42
|
-
for(int q = 0; q < NQ; q++) {
|
43
|
-
for(int b = 0; b < BB; b++) {
|
38
|
+
for (int q = 0; q < NQ; q++) {
|
39
|
+
for (int b = 0; b < BB; b++) {
|
44
40
|
accu[q][b][0].clear();
|
45
41
|
accu[q][b][1].clear();
|
46
42
|
accu[q][b][2].clear();
|
@@ -48,9 +44,9 @@ void kernel_accumulate_block(
|
|
48
44
|
}
|
49
45
|
}
|
50
46
|
|
51
|
-
for(int sq = 0; sq < nsq; sq += 2) {
|
47
|
+
for (int sq = 0; sq < nsq; sq += 2) {
|
52
48
|
simd32uint8 lut_cache[NQ];
|
53
|
-
for(int q = 0; q < NQ; q++) {
|
49
|
+
for (int q = 0; q < NQ; q++) {
|
54
50
|
lut_cache[q] = simd32uint8(LUT);
|
55
51
|
LUT += 32;
|
56
52
|
}
|
@@ -62,7 +58,7 @@ void kernel_accumulate_block(
|
|
62
58
|
simd32uint8 chi = simd32uint8(simd16uint16(c) >> 4) & mask;
|
63
59
|
simd32uint8 clo = c & mask;
|
64
60
|
|
65
|
-
for(int q = 0; q < NQ; q++) {
|
61
|
+
for (int q = 0; q < NQ; q++) {
|
66
62
|
simd32uint8 lut = lut_cache[q];
|
67
63
|
simd32uint8 res0 = lut.lookup_2_lanes(clo);
|
68
64
|
simd32uint8 res1 = lut.lookup_2_lanes(chi);
|
@@ -76,9 +72,8 @@ void kernel_accumulate_block(
|
|
76
72
|
}
|
77
73
|
}
|
78
74
|
|
79
|
-
for(int q = 0; q < NQ; q++) {
|
75
|
+
for (int q = 0; q < NQ; q++) {
|
80
76
|
for (int b = 0; b < BB; b++) {
|
81
|
-
|
82
77
|
accu[q][b][0] -= accu[q][b][1] << 8;
|
83
78
|
simd16uint16 dis0 = combine2x2(accu[q][b][0], accu[q][b][1]);
|
84
79
|
|
@@ -88,19 +83,15 @@ void kernel_accumulate_block(
|
|
88
83
|
res.handle(q, b, dis0, dis1);
|
89
84
|
}
|
90
85
|
}
|
91
|
-
|
92
|
-
|
93
86
|
}
|
94
87
|
|
95
|
-
|
96
|
-
template<int NQ, int BB, class ResultHandler>
|
88
|
+
template <int NQ, int BB, class ResultHandler>
|
97
89
|
void accumulate_fixed_blocks(
|
98
90
|
size_t nb,
|
99
91
|
int nsq,
|
100
|
-
const uint8_t
|
101
|
-
const uint8_t
|
102
|
-
ResultHandler
|
103
|
-
{
|
92
|
+
const uint8_t* codes,
|
93
|
+
const uint8_t* LUT,
|
94
|
+
ResultHandler& res) {
|
104
95
|
constexpr int bbs = 32 * BB;
|
105
96
|
for (int64_t j0 = 0; j0 < nb; j0 += bbs) {
|
106
97
|
FixedStorageHandler<NQ, 2 * BB> res2;
|
@@ -111,29 +102,28 @@ void accumulate_fixed_blocks(
|
|
111
102
|
}
|
112
103
|
}
|
113
104
|
|
114
|
-
|
115
105
|
} // anonymous namespace
|
116
106
|
|
117
|
-
template<class ResultHandler>
|
107
|
+
template <class ResultHandler>
|
118
108
|
void pq4_accumulate_loop(
|
119
109
|
int nq,
|
120
|
-
size_t nb,
|
110
|
+
size_t nb,
|
111
|
+
int bbs,
|
121
112
|
int nsq,
|
122
|
-
const uint8_t
|
123
|
-
const uint8_t
|
124
|
-
ResultHandler
|
125
|
-
{
|
113
|
+
const uint8_t* codes,
|
114
|
+
const uint8_t* LUT,
|
115
|
+
ResultHandler& res) {
|
126
116
|
FAISS_THROW_IF_NOT(is_aligned_pointer(codes));
|
127
117
|
FAISS_THROW_IF_NOT(is_aligned_pointer(LUT));
|
128
118
|
FAISS_THROW_IF_NOT(bbs % 32 == 0);
|
129
119
|
FAISS_THROW_IF_NOT(nb % bbs == 0);
|
130
120
|
|
131
|
-
#define DISPATCH(NQ, BB)
|
132
|
-
|
133
|
-
|
134
|
-
|
121
|
+
#define DISPATCH(NQ, BB) \
|
122
|
+
case NQ * 1000 + BB: \
|
123
|
+
accumulate_fixed_blocks<NQ, BB>(nb, nsq, codes, LUT, res); \
|
124
|
+
break
|
135
125
|
|
136
|
-
switch(nq * 1000 + bbs / 32) {
|
126
|
+
switch (nq * 1000 + bbs / 32) {
|
137
127
|
DISPATCH(1, 1);
|
138
128
|
DISPATCH(1, 2);
|
139
129
|
DISPATCH(1, 3);
|
@@ -143,26 +133,28 @@ void pq4_accumulate_loop(
|
|
143
133
|
DISPATCH(2, 2);
|
144
134
|
DISPATCH(3, 1);
|
145
135
|
DISPATCH(4, 1);
|
146
|
-
|
147
|
-
|
136
|
+
default:
|
137
|
+
FAISS_THROW_FMT("nq=%d bbs=%d not instantiated", nq, bbs);
|
148
138
|
}
|
149
139
|
#undef DISPATCH
|
150
|
-
|
151
140
|
}
|
152
141
|
|
153
142
|
// explicit template instantiations
|
154
143
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
144
|
+
#define INSTANTIATE_ACCUMULATE(TH, C, with_id_map) \
|
145
|
+
template void pq4_accumulate_loop<TH<C, with_id_map>>( \
|
146
|
+
int, \
|
147
|
+
size_t, \
|
148
|
+
int, \
|
149
|
+
int, \
|
150
|
+
const uint8_t*, \
|
151
|
+
const uint8_t*, \
|
152
|
+
TH<C, with_id_map>&);
|
153
|
+
|
154
|
+
#define INSTANTIATE_3(C, with_id_map) \
|
155
|
+
INSTANTIATE_ACCUMULATE(SingleResultHandler, C, with_id_map) \
|
156
|
+
INSTANTIATE_ACCUMULATE(HeapHandler, C, with_id_map) \
|
157
|
+
INSTANTIATE_ACCUMULATE(ReservoirHandler, C, with_id_map)
|
166
158
|
|
167
159
|
using Csi = CMax<uint16_t, int>;
|
168
160
|
INSTANTIATE_3(Csi, false);
|
@@ -174,7 +166,4 @@ INSTANTIATE_3(Csl, true);
|
|
174
166
|
using CslMin = CMin<uint16_t, int64_t>;
|
175
167
|
INSTANTIATE_3(CslMin, true);
|
176
168
|
|
177
|
-
|
178
|
-
|
179
169
|
} // namespace faiss
|
180
|
-
|