Commit a3d59f0
faiss DD: use 256-bit fast-scan QBS kernel on AMD Zen 4 (split AVX-512) (#5488)
Summary:
Pull Request resolved: #5488
## TLDR make PQFS faster on AMD Bergamo specifically, without regressing for RaBitQFS, by changing AVX512 --> AVX2 for the FastScan part. The RaBitQ avx512 popcount is still avx512, it is just the FastScan part that stays on AVX2.
Under dynamic dispatch (`faiss.dynamic_dispatch=true`) the fast-scan QBS search
path picks the 512-bit accumulate kernel whenever the runtime SIMD level is
AVX-512. On AMD Zen 4 / Zen 4c ("Bergamo", family 0x19) that is the wrong
choice: Zen 4 splits 512-bit ops over two separate 256-bit parts.
- This can execute operations in 2 separate operations, so 2 cycles compared to a single cycle in avx2. It can sometimes be slower or faster depending on the operation, because more new instructions are supported in avx512 like vpopcnt which are completely missing in AVX2.
- Why split at all? because older CPUs had to downclock for avx512 instructions, while this approach does not, so it can be faster for certain workloads, and it allows support for avx512 instructions for free.
Captured from benchmark infra, matched
AVX2-static vs AVX-512-DD operating points):
- Bergamo `PQ8x4fs`: median AVX-512/AVX2 = 0.861 (nq=1) / 0.860 (batched)
across 15 datasets, spread [0.857, 0.867], 14/15 datasets below 0.95
(worst `sift-1M` = 0.60).
- Bergamo `PQ16x4fs`: 0.870 (nq=1) / 0.878 (batched) across 14 datasets.
The magnitude is tight and reproduces on ~every dataset in both the single-query
and batched regimes, well below the Bergamo benchmark noise floor (SVS-Vamana
negative control median ~1.05), so it is real signal. It is isolated to the
bbs=32 QBS path: `PQ*x4fs_64` (bbs=64) and `IVF*,PQ*x4fs` are unaffected, and on
Intel Skylake / Cooper Lake the same factories are FASTER under AVX-512
(1.01-1.71x), so the fix must be keyed to Zen 4 only.
Fix (3 files):
- `simd_levels.{h,cpp}`: add `SIMDConfig::avx512_split`, set by raw-CPUID
detection (vendor == AuthenticAMD && display_family == 0x19), run once at load
time from `auto_detect_simd_level()` in both DD and static builds.
- `dispatching.h` `ScannerMixIn::accumulate_loop_qbs`: this is the live QBS
search dispatch for BOTH PQ fast-scan and RaBitQ fast-scan. When the CPU splits avx512, route to the 256-bit (AVX2) QBS kernel
(`pq4_accumulate_loop_qbs_fixed_scaler_256<AVX2>`, the same one the existing
unknown-qbs fallback already uses) instead of the 512-bit kernel. Process-
constant runtime branch, hoisted out of the inner accumulate loop. Intel
AVX-512 keeps the 512-bit kernel unchanged.
Note: the fix is placed in `dispatching.h` (the path IndexFastScan /
IndexIVFFastScan search actually take, via `ScannerMixIn`), NOT in
`decompose_qbs.h` -- the QBS block kernel there is only reached by the
`accumulate_to_mem` test utility, not by any search path, so routing it there
would be inert for search.
Scope: RaBitQ fast-scan shares this same PQ4 QBS accumulate, so it is also routed
to 256-bit on Zen 4. That is not expected to regress it -- the 256-bit kernel is
>= the 512-bit one on Zen 4 (the whole premise), and RaBitQ's AVX-512 popcount
(folded into the query LUT) and multibit FP-refine kernels are untouched. An
earlier version of this diff also added a Cooper Lake RaBitQ-popcount cap and a
native `vpopcntq` path; the Cooper Lake regression that motivated them did not
survive additional benchmark runs, so both were
dropped to keep this a single-purpose, evidence-backed fix.
Validated on Bergamo (see Test Plan)
Reviewed By: junjieqi
Differential Revision: D113617130
fbshipit-source-id: c59b522134f40cc7a7daf6abaa3c3f6d5b139fe11 parent 4d74915 commit a3d59f0
3 files changed
Lines changed: 85 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
117 | | - | |
118 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
119 | 152 | | |
120 | 153 | | |
121 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| |||
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
56 | 97 | | |
57 | 98 | | |
58 | 99 | | |
| |||
101 | 142 | | |
102 | 143 | | |
103 | 144 | | |
| 145 | + | |
| 146 | + | |
104 | 147 | | |
105 | 148 | | |
106 | 149 | | |
| |||
264 | 307 | | |
265 | 308 | | |
266 | 309 | | |
| 310 | + | |
267 | 311 | | |
268 | 312 | | |
269 | 313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
164 | 170 | | |
165 | 171 | | |
166 | 172 | | |
| |||
0 commit comments