Repository navigation
v16.5 — Cortex-M0+ int8 dense speed restored
v16.5 — Cortex-M0+ int8 dense speed restored
Fix: Cortex-M0+ int8 dense layers were about a third slower in v16.3 and v16.4 (#235)
- Re-running the on-target bench on a NUCLEO-L031K6 (Cortex-M0+, 32 MHz) showed the int8 MLP at 48,282 cycles, up from 35,963 in v16.2 (+34%). Bisecting on the board pinned it to the
Requantizerundefined-behaviour fix in v16.3 (#230). - That fix clamps the saturating path's result to the exact
[qmin - zp, qmax - zp]window, in int64, before the zero point is added. The MLP never takes that path. Butapply()is inlined into the dense output loop, and on Cortex-M0+, with eight low registers, keeping those bounds live cost the loop its registers: the dot product reloaded its index from the stack on every multiply-accumulate. - For storage narrower than int32, the path now clamps to a constant ±2^30. The zero point,
qminandqmaxare all below 2^16 in magnitude, so the sum cannot overflow and the final clamp gives the same result. 32-bit storage keeps the exact int64 window. No undefined behaviour returns, and outputs are bit-exact with v16.4. multiplyByQuantizedMultipliernow saturates its left shift with an int32 range test instead of an int64 multiply, which Cortex-M0+ performs in a library call. The result is unchanged. It does not move these benchmarks, but every caller that left-shifts (QAdd, QGRU, QSSM, QCfC and others) skips the 64-bit work.
On-target results (O3, v16.4 → v16.5, every model hash unchanged)
| Image | v16.4 | v16.5 |
|---|---|---|
| L031 int8 MLP | 48,282 cycles | 36,006 cycles (−25.4%), flash −5.7%, stack −18% |
| L031 int8 KWS | 747,881 cycles | 740,864 cycles (−0.9%), flash −11% |
| F411 int8 MLP, SMLAD | 10,047 cycles | 10,227 cycles (+1.8%) |
| F411 int8 KWS, SMLAD | 178,514 cycles | 181,853 cycles (+1.9%) |
The F411 SMLAD builds return to the figures published on the benchmarks page (10,241 and 181,568 cycles); v16.3 had moved them through register allocation alone. Random forest, TFLM and emlearn images are unchanged.
Verification
- Bit-exact against v16.4's
Requantizerover 85 million random cases (int8, uint8, int16, uint16 and int32 storage), and the new shift saturation over 11.7 million, both under UBSan. - New unit test
requantizer_saturating_path_at_int32_railschecks accumulators at the int32 rails against the exact int64 result. It was shown to fail on a planted defect. - The full gate set passes:
make check,check-cxx14,check-clang, cppcheck,header-selfcheck, ASan/UBSan, MemorySanitizer, the fuzz agreement and coverage gates, the Arm cross-compiles, and the SMLAD bit-exactness check on QEMU Cortex-M4.
Documentation, architecture guides, and example gallery: https://danmcleran.github.io/tinymind/
Full changelog: v16.4...v16.5