Commit db70e09
perf(kpm): Gaussian scale-space pyramid — benchmark + rayon parallelization (#209)
* perf(kpm): criterion benchmark for Gaussian scale-space pyramid (#200)
Establish the scalar baseline for the Gaussian pyramid SIMD series
(#200 -> #201 -> #202). Unlike the BoxFilterPyramid8u trilogy (#131-133,
dead code per #203), GaussianScaleSpacePyramid is the pyramid the
KPM/FREAK detector actually uses via DoGScaleInvariantDetector.
- Promote the three hot helpers to `pub` with scalar-only dispatchers,
following the `pyramid::downsample` precedent from #131:
binomial_4th_order_u8_to_f32{,_scalar}
binomial_4th_order_f32_to_f32{,_scalar}
downsample_bilinear_f32{,_scalar}
`build` calls the dispatchers, so #201/#202 only fill in SIMD variants
and wire dispatch. Behavior unchanged (dual-mode C++ parity test still
green).
- Add crates/core/benches/gaussian_pyramid_bench.rs benchmarking each
scalar helper plus end-to-end `build` (num_octaves from
num_octaves_for(w, h, 8), matching rust_backend) at 640x480, 1280x720
and 1920x1080 with fixed-seed PRNG input.
- Wire `[[bench]] name = "gaussian_pyramid_bench"` into Cargo.toml.
Baseline (median, this machine):
binomial_f32 640x480 710 us | 1280x720 2.04 ms | 1920x1080 5.26 ms
binomial_u8 640x480 546 us | 1280x720 1.60 ms | 1920x1080 3.38 ms
bilinear 640x480 138 us | 1280x720 381 us | 1920x1080 1.16 ms
build (e2e) 640x480 3.11 ms | 1280x720 9.95 ms | 1920x1080 26.0 ms
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* perf(kpm): parallelize Gaussian pyramid filter passes with rayon (#207) (#208)
The binomial filter and bilinear downsample of GaussianScaleSpacePyramid
are memory-bandwidth bound, so the SIMD attempt (#201/#206) gave ~1.0× —
a single core can't saturate DRAM bandwidth. Multiple cores can, so
parallelize over rows with rayon (native; wasm stays single-threaded).
- Per-row helpers (binomial_{h,v}_row_{f32,u8}, bilinear_row_f32) are the
single source of truth for the arithmetic; serial and rayon paths both
call them, so output is bit-for-bit identical regardless of threading
(rows are independent). Validated by serial-vs-rayon parity tests + the
existing dual-mode C++ parity test (scalar == C++, rayon == scalar).
- Added *_rayon variants (par_chunks_mut over rows) for both binomial
variants and the bilinear downsample, cfg(not(wasm32)).
- Dispatchers pick rayon above PARALLEL_MIN_PIXELS (600k px), else serial;
wasm always serial. The threshold keeps <=480p serial (where thread
overhead regressed the binomial filter) and parallelizes 720p+.
- Bench extended with a `rayon` arm per group.
Speedup (scalar -> rayon, same-run medians, this machine):
binomial_f32 720p 2.75->1.71 ms (1.61x) | 1080p 4.33->2.84 ms (1.52x)
binomial_u8 720p 1.69->1.42 ms (1.19x) | 1080p 3.55->2.36 ms (1.50x)
bilinear 720p 0.40->0.17 ms (2.36x) | 1080p 1.01->0.57 ms (1.77x)
(<=480p stays serial by design.)
Closes #207.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
* test(kpm): skip large rayon-parity tests under Miri; drop redundant h alias
The #207 rayon parity tests build pyramids at up to 800×800 — astronomically
slow under Miri's interpreter (the run was stuck for 2h). #207 adds no
unsafe (rayon is safe), so Miri has nothing to validate there. Annotate the
four large-image tests with #[cfg_attr(miri, ignore)], matching the existing
#194 idiom; they still run natively.
Also replace the redundant `let h = height;` alias in binomial_v_row_{f32,u8}
with `height` directly — the elided binding showed as 2 uncovered lines in the
tarpaulin/codecov patch report.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 97d6bfb commit db70e09
3 files changed
Lines changed: 627 additions & 147 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 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 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
0 commit comments