contrib/faiss/faiss/utils/hamming_distance/hamdis-inl.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | // This file contains low level inline facilities for computing |
9 | | // Hamming distances, such as HammingComputerXX and GenHammingComputerXX. |
10 | | |
11 | | #ifndef FAISS_hamming_inl_h |
12 | | #define FAISS_hamming_inl_h |
13 | | |
14 | | #include <faiss/utils/hamming_distance/common.h> |
15 | | |
16 | | #ifdef __aarch64__ |
17 | | // ARM compilers may produce inoptimal code for Hamming distance somewhy. |
18 | | #include <faiss/utils/hamming_distance/neon-inl.h> |
19 | | #elif __AVX512F__ |
20 | | // offers better performance where __AVX512VPOPCNTDQ__ is supported |
21 | | #include <faiss/utils/hamming_distance/avx512-inl.h> |
22 | | #elif __AVX2__ |
23 | | // better versions for GenHammingComputer |
24 | | #include <faiss/utils/hamming_distance/avx2-inl.h> |
25 | | #else |
26 | | #include <faiss/utils/hamming_distance/generic-inl.h> |
27 | | #endif |
28 | | |
29 | | namespace faiss { |
30 | | |
31 | | /*************************************************************************** |
32 | | * Equivalence with a template class when code size is known at compile time |
33 | | **************************************************************************/ |
34 | | |
35 | | // default template |
36 | | template <int CODE_SIZE> |
37 | | struct HammingComputer : HammingComputerDefault { |
38 | | HammingComputer(const uint8_t* a, int code_size) |
39 | | : HammingComputerDefault(a, code_size) {} |
40 | | }; |
41 | | |
42 | | #define SPECIALIZED_HC(CODE_SIZE) \ |
43 | | template <> \ |
44 | | struct HammingComputer<CODE_SIZE> : HammingComputer##CODE_SIZE { \ |
45 | | HammingComputer(const uint8_t* a) \ |
46 | 0 | : HammingComputer##CODE_SIZE(a, CODE_SIZE) {} \Unexecuted instantiation: _ZN5faiss15HammingComputerILi4EEC2EPKh Unexecuted instantiation: _ZN5faiss15HammingComputerILi8EEC2EPKh Unexecuted instantiation: _ZN5faiss15HammingComputerILi16EEC2EPKh Unexecuted instantiation: _ZN5faiss15HammingComputerILi20EEC2EPKh Unexecuted instantiation: _ZN5faiss15HammingComputerILi32EEC2EPKh Unexecuted instantiation: _ZN5faiss15HammingComputerILi64EEC2EPKh |
47 | | } |
48 | | |
49 | | SPECIALIZED_HC(4); |
50 | | SPECIALIZED_HC(8); |
51 | | SPECIALIZED_HC(16); |
52 | | SPECIALIZED_HC(20); |
53 | | SPECIALIZED_HC(32); |
54 | | SPECIALIZED_HC(64); |
55 | | |
56 | | #undef SPECIALIZED_HC |
57 | | |
58 | | /*************************************************************************** |
59 | | * Dispatching function that takes a code size and a consumer object |
60 | | * the consumer object should contain a retun type t and a operation template |
61 | | * function f() that must be called to perform the operation. |
62 | | **************************************************************************/ |
63 | | |
64 | | template <class Consumer, class... Types> |
65 | | typename Consumer::T dispatch_HammingComputer( |
66 | | int code_size, |
67 | | Consumer& consumer, |
68 | 0 | Types... args) { |
69 | 0 | switch (code_size) { |
70 | 0 | #define DISPATCH_HC(CODE_SIZE) \ |
71 | 0 | case CODE_SIZE: \ |
72 | 0 | return consumer.template f<HammingComputer##CODE_SIZE>(args...); |
73 | 0 | DISPATCH_HC(4); |
74 | 0 | DISPATCH_HC(8); |
75 | 0 | DISPATCH_HC(16); |
76 | 0 | DISPATCH_HC(20); |
77 | 0 | DISPATCH_HC(32); |
78 | 0 | DISPATCH_HC(64); |
79 | 0 | default: |
80 | 0 | return consumer.template f<HammingComputerDefault>(args...); |
81 | 0 | } |
82 | 0 | #undef DISPATCH_HC |
83 | 0 | } Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_10PQDecoder8EE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMinIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_10PQDecoder8EE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMinIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_10PQDecoder8EE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMaxIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_10PQDecoder8EE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMaxIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_11PQDecoder16EE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMinIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_11PQDecoder16EE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMinIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_11PQDecoder16EE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMaxIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_11PQDecoder16EE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMaxIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_16PQDecoderGenericEE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMinIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_16PQDecoderGenericEE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMinIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_16PQDecoderGenericEE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMaxIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_16PQDecoderGenericEE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMaxIflEELb1EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_10PQDecoder8EE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMinIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_10PQDecoder8EE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMinIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_10PQDecoder8EE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMaxIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_10PQDecoder8EE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMaxIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_11PQDecoder16EE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMinIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_11PQDecoder16EE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMinIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_11PQDecoder16EE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMaxIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_11PQDecoder16EE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMaxIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_16PQDecoderGenericEE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMinIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE0ENS_16PQDecoderGenericEE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMinIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_16PQDecoderGenericEE27Run_scan_list_polysemous_hcINS1_16KnnSearchResultsINS_4CMaxIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexIVFPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_113IVFPQScannerTIlLNS_10MetricTypeE1ENS_16PQDecoderGenericEE27Run_scan_list_polysemous_hcINS1_18RangeSearchResultsINS_4CMaxIflEELb0EEEEEJPKS5_mPKhSA_EEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexPQ.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_125Run_polysemous_inner_loopEJPKNS_7IndexPQEPKfPKhlPfPliEEENT_1TEiRSC_DpT0_ Unexecuted instantiation: IndexIVFSpectralHash.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_112BuildScannerEJPKNS_20IndexIVFSpectralHashEbEEENT_1TEiRS6_DpT0_ Unexecuted instantiation: IndexBinaryIVF.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_112BuildScannerEJibEEENT_1TEiRS3_DpT0_ Unexecuted instantiation: IndexBinaryIVF.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_134Run_search_knn_hamming_per_invlistEJPKNS_14IndexBinaryIVFElPKhlPKlPKiPiPlbPKNS_19SearchParametersIVFEEEENT_1TEiRSH_DpT0_ Unexecuted instantiation: IndexBinaryIVF.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_128Run_search_knn_hamming_countILb1EEEJPKNS_14IndexBinaryIVFElPKhPKllPiPlPKNS_19SearchParametersIVFEEEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexBinaryIVF.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_128Run_search_knn_hamming_countILb0EEEJPKNS_14IndexBinaryIVFElPKhPKllPiPlPKNS_19SearchParametersIVFEEEENT_1TEiRSG_DpT0_ Unexecuted instantiation: IndexBinaryHNSW.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_121BuildDistanceComputerEJPNS_15IndexBinaryFlatEEEENT_1TEiRS5_DpT0_ Unexecuted instantiation: IndexBinaryHash.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_123Run_search_single_queryEJNS_15IndexBinaryHashEPKhNS1_18RangeSearchResultsEmmmEEENT_1TEiRS7_DpT0_ Unexecuted instantiation: IndexBinaryHash.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_123Run_search_single_queryEJNS_15IndexBinaryHashEPKhNS1_16KnnSearchResultsEmmmEEENT_1TEiRS7_DpT0_ Unexecuted instantiation: IndexBinaryHash.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_120Run_verify_shortlistEJPNS_15IndexBinaryFlatEPKhSt13unordered_setIlSt4hashIlESt8equal_toIlESaIlEENS1_18RangeSearchResultsEEEENT_1TEiRSF_DpT0_ Unexecuted instantiation: IndexBinaryHash.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_120Run_verify_shortlistEJPNS_15IndexBinaryFlatEPKhSt13unordered_setIlSt4hashIlESt8equal_toIlESaIlEENS1_16KnnSearchResultsEEEENT_1TEiRSF_DpT0_ Unexecuted instantiation: hamming.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_119Run_hammings_knn_hcEJmPNS_9HeapArrayINS_4CMaxIilEEEEPKhS9_mib17ApproxTopK_mode_tPKNS_10IDSelectorEEEENT_1TEiRSE_DpT0_ Unexecuted instantiation: hamming.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_119Run_hammings_knn_mcEJmPKhS4_mmmPiPlPKNS_10IDSelectorEEEENT_1TEiRSA_DpT0_ Unexecuted instantiation: hamming.cpp:_ZN5faiss24dispatch_HammingComputerINS_12_GLOBAL__N_124Run_hamming_range_searchEJPKhS4_mmimPNS_17RangeSearchResultEPKNS_10IDSelectorEEEENT_1TEiRSA_DpT0_ |
84 | | |
85 | | } // namespace faiss |
86 | | |
87 | | #endif |