Skip to content

Commit 9d5491a

Browse files
Michael Norrismeta-codesync[bot]
authored andcommitted
Templatize SIMDResultHandler on SL, mark handle() final (#5223)
Summary: Pull Request resolved: #5223 Follow-up to D104552827 per Matthijs's review feedback. The non-template `SIMDResultHandler` base class had a virtual `handle()` using `simd16uint16_tpl<NONE>` in DD mode, while derived handlers used SL-specific types. This meant derived `handle()` methods HIDED rather than OVERRODE the base, preventing use of `override`/`final`. This restructures the hierarchy: metadata fields from the old `SIMDResultHandler` are merged into `SIMDResultHandlerToFloat` (stays non-template for the polymorphic `FastScanCodeScanner::handler()` interface), and a new template `SIMDResultHandler<SL>` is inserted between them with a virtual `handle()` whose `simd16uint16` type matches the SL parameter. Concrete handlers now genuinely override this virtual and are marked `final`, signaling devirtualization/inlining intent. Also removes dead code: `with_SIMDResultHandler()` (zero callers), `simd_result_handlers_accept_virtual` (only used by that function), and the file-scope `simd16uint16` alias (only used by the old base class). Reviewed By: alibeklfc Differential Revision: D105611944 fbshipit-source-id: 2faaed448692e38459a9c6253039cfa366512a7e
1 parent b63f236 commit 9d5491a

5 files changed

Lines changed: 71 additions & 162 deletions

File tree

faiss/IndexIVFRaBitQFastScan.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ IVFRaBitQHeapHandler<C, SL>::IVFRaBitQHeapHandler(
225225
}
226226
}
227227

228-
// Explicit alias — must match SIMDResultHandler::handle() signature.
229-
using simd16uint16 = simd16uint16_tpl<SINGLE_SIMD_LEVEL_256>;
230-
231228
template <class C, SIMDLevel SL>
232229
void IVFRaBitQHeapHandler<C, SL>::handle(
233230
size_t q,

faiss/IndexRaBitQFastScan.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ template <
134134
struct RaBitQHeapHandler
135135
: simd_result_handlers::ResultHandlerCompare<C, with_id_map, SL> {
136136
using RHC = simd_result_handlers::ResultHandlerCompare<C, with_id_map, SL>;
137-
using RHC::handle;
138137
using RHC::normalizers;
139138
static constexpr SIMDLevel SL256 = simd256_level_selector<SL>::value;
140139
using simd16uint16 = simd16uint16_tpl<SL256>;
@@ -188,7 +187,7 @@ struct RaBitQHeapHandler
188187
}
189188
}
190189

191-
void handle(size_t q, size_t b, simd16uint16 d0, simd16uint16 d1) {
190+
void handle(size_t q, size_t b, simd16uint16 d0, simd16uint16 d1) final {
192191
ALIGNED(32) uint16_t d32tab[32];
193192
d0.store(d32tab);
194193
d1.store(d32tab + 16);

faiss/impl/fast_scan/fast_scan.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,6 @@ int pq4_pack_LUT_qbs_q_map(
353353
return i0;
354354
}
355355

356-
// declared in simd_result_handlers.h
357-
bool simd_result_handlers_accept_virtual = true;
358-
359356
int pq4_qbs_to_nq(int qbs) {
360357
int i0 = 0;
361358
int qi = qbs;

faiss/impl/fast_scan/rabitq_result_handler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ using rabitq_utils::SignBitFactorsWithError;
3838
template <class C, SIMDLevel SL = SINGLE_SIMD_LEVEL_256>
3939
struct IVFRaBitQHeapHandler : ResultHandlerCompare<C, true, SL> {
4040
using RHC = ResultHandlerCompare<C, true, SL>;
41-
using RHC::handle;
4241
using typename RHC::simd16uint16;
4342

4443
const IndexIVFRaBitQFastScan* index;
@@ -83,7 +82,7 @@ struct IVFRaBitQHeapHandler : ResultHandlerCompare<C, true, SL> {
8382
const FastScanDistancePostProcessing* ctx = nullptr,
8483
bool multibit = false);
8584

86-
void handle(size_t q, size_t b, simd16uint16 d0, simd16uint16 d1);
85+
void handle(size_t q, size_t b, simd16uint16 d0, simd16uint16 d1) final;
8786

8887
void set_list_context(size_t list_no, const std::vector<int>& probe_map)
8988
override;

0 commit comments

Comments
 (0)