Commit ec28cc9
perf(kpm): box-filter Pyramid downsample — criterion benchmark + SIMD (#211)
* perf(kpm): add criterion benchmark for Pyramid downsample (#131)
Establish the scalar baseline for the pyramid downsample trilogy so the
SIMD path (#132) and any chunked-layout work (#133) can prove speedups
against stable numbers.
- Promote the private `downsample` to `pub fn downsample_scalar` and add
a `pub fn downsample` dispatcher (scalar-only for now; #132 wires in
the SIMD paths). Both are `pub` so the criterion bench (a separate
crate) can measure them directly; `Pyramid::build` is the stable API.
- Add `crates/core/benches/pyramid_bench.rs` benchmarking
`downsample_scalar` and `Pyramid::build` (num_levels=4) at 640x480,
1280x720 and 1920x1080 with a fixed-seed PRNG input.
- Wire `[[bench]] name = "pyramid_bench"` into Cargo.toml.
Baseline (median, this machine):
downsample 640x480 ~116 us | 1280x720 ~341 us | 1920x1080 ~884 us
pyramid_build 640x480 ~159 us | 1280x720 ~597 us | 1920x1080 ~1.87 ms
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* perf(kpm): SIMD path for Pyramid downsample (AVX2/SSE4.1/wasm32) (#132)
Add runtime-dispatched SIMD implementations of the pyramid downsample,
each byte-identical to the scalar baseline established in #131.
- `downsample_avx2`: 32 output cols/iter via 256-bit lanes
(`maddubs` horizontal pairwise add + `packus` + `permute4x64` to undo
the per-lane interleave).
- `downsample_sse41`: 16 output cols/iter via 128-bit lanes.
- `downsample_wasm`: 16 output cols/iter via `simd128`
(`extadd_pairwise_u8x16` + `narrow`).
- `downsample` dispatches AVX2 -> SSE4.1 -> scalar on x86_64 (runtime
`is_x86_feature_detected!`) and simd128 on wasm32; scalar remains the
fallback. Each `unsafe` site carries a `// SAFETY:` comment.
- Shared `downsample_dims` + `downsample_row_tail_scalar` helpers define
the rounding in one place; the SIMD main loops handle full blocks and
defer the per-row remainder to the scalar tail.
- Block counts are sized so loads/stores stay in bounds for any
dimension (incl. odd / sub-block widths).
Correctness: property tests compare each SIMD path against scalar over 16
sizes (odd dims, tiny images, block boundaries) plus a dispatcher-parity
test. `cargo clippy --all-targets --all-features -- -D warnings` clean.
Speedup (downsample, median ns -> us, this machine):
640x480 scalar 85.8 | sse41 7.4 (11.6x) | avx2 5.8 (14.7x)
1280x720 scalar 251 | sse41 25.0 (10.0x) | avx2 18.6 (13.5x)
1920x1080 scalar 773 | sse41 96.1 (8.0x) | avx2 75.9 (10.2x)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* test(kpm): exhaustive width-sweep parity for SIMD downsample (#132)
Add a 2..=160 column sweep (x4 row counts) comparing both the AVX2 and
SSE4.1 paths against scalar, covering every remainder case of the 16- and
32-wide main loops. Strengthens confidence beyond the hand-picked sizes
that each SIMD path is byte-identical to scalar for all dimensions.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent db70e09 commit ec28cc9
3 files changed
Lines changed: 578 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
157 | 161 | | |
158 | 162 | | |
159 | 163 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 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 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
0 commit comments