Repository navigation
Commit 292cf6f
authored
perf(fastlanes): enable runtime dispatch for the bit transposes (#10102)
## Summary
`fastlanes` picks its `transpose_bits` / `untranspose_bits`
implementation at
compile time unless the crate is built with its `runtime` feature, and
nothing
in the workspace enables it. A build without `-C target-feature=+bmi2`
(or
VBMI) therefore always takes the scalar transpose, on any CPU. That
covers the
Python wheels, which maturin builds for plain x86-64, and the main
CodSpeed
leg, whose `+avx2` implies neither BMI2 nor VBMI.
The fused compare from #8239 transposes once per 1024-row block, so the
scalar path shows up there first. `bitpack_compare_sweep`, median µs, 64
blocks, `Lt` against a constant, width 4 (width 8 looks the same):
| build | u8 | u16 | u32 | u64 | i64 |
|---|---|---|---|---|---|
| x86-64 | 4.76 | 6.20 | 9.19 | 26.0 | 25.9 |
| x86-64, `runtime` | 2.43 | 3.65 | 6.38 | 22.2 | 22.2 |
| `+avx2` | 3.56 | 4.53 | 6.74 | 10.1 | 9.01 |
| `+avx2`, `runtime` | 1.90 | 2.44 | 3.94 | 6.98 | 5.89 |
That is 1.2x to 1.95x, largest for narrow types, where the transpose is
most
of the work: timing the fastlanes calls alone, u8 at width 4 spends 1.3
µs of
4.1 in `unpack_cmp` and the rest in the transpose. Measured on a Ryzen
AI 5 340
(Zen 5, AVX-512 with VBMI), one run per build; I have not measured a CPU
with
BMI2 but without VBMI.
Detection is `cpufeatures`, already a locked dependency, cached in an
atomic
after the first call. aarch64 is unaffected: NEON is baseline there and
was
already selected at compile time. The rest of the workspace already
detects at
runtime (`take` via AVX2, the AVX-512 VBMI2 filter compress), so this
only
brings fastlanes in line.
## Changes
One line in the workspace `Cargo.toml`, plus the matching `cpufeatures`
edge
under `fastlanes` in `Cargo.lock` (the package itself is already
locked):
```toml
fastlanes = { version = "0.7.0", features = ["runtime"] }
```
One thing to check on your side: with runtime detection the transpose
path
depends on the runner's CPU rather than on `RUSTFLAGS`, so if the
CodSpeed
simulation runners differ in BMI2 / VBMI support, the fastlanes benches
may
move between runs.
Reproduce:
```
cargo bench -p vortex-fastlanes --bench bitpack_compare_sweep
cargo bench -p vortex-fastlanes --bench bitpack_compare_sweep --features fastlanes/runtime
```
Signed-off-by: mightsleep <[email protected]>1 parent 5ff5969 commit 292cf6f
2 files changed
Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
0 commit comments