Skip to content

v15.2 — int8 on Cortex-M4: SMLAD backend and a faster requantize path

Choose a tag to compare

@danmcleran danmcleran released this 12 Oct 11:41
· 114 commits to master since this release
9186e8d

v15.2 — int8 on Cortex-M4: SMLAD backend and a faster requantize path

On a NUCLEO-F411RE (Cortex-M4F, 100 MHz), the keyword-spotting int8 pipeline drops from 826,857 to 580,305 warm cycles, all bit-exact: the activation checksum is unchanged. Float on the same board is 490,262 cycles, so int8 goes from 1.69x the float cost to 1.18x. Most of that gain needs no flag at all.

Performance

  • Requantization is cheaper on every target, with no gate required. saturatingRoundingDoublingHighMul is now one add and one arithmetic shift. gemmlowp's sign-dependent nudge followed by a truncating divide equals floor((a*b + 2^30) / 2^31) for both signs, so the negative-product branch and its second 64-bit add go away; on Cortex-M4 the body is a single SMLAL seeded with 2^30. A new unit test locks it to the gemmlowp form on exact ties, the int32 extremes and a 2M-case sweep.
  • Quantized layers stop reloading their own fields. QConv2D, QConv2DPerChannel, QDepthwiseConv2D, QPointwiseConv2D(PerChannel) and QDense copy their fields and requantizer into locals at the top of forward(). Every output is an int8_t store, which may alias *this, so the compiler was reloading weights, biases and zero point, and re-decoding the requantizer shift, once per output.
  • Together these take the pipeline from 826,857 to 596,988 cycles.

New SIMD backend: TINYMIND_ENABLE_SIMD_ARM_DSP

  • A Phase 14 backend for the AArch32 DSP extension (Cortex-M4 / M7 / M33 / M35P). Four int8 values load per word, widen with SXTB16, have the input zero point subtracted in int16 lanes with SSUB16, and accumulate two products per SMLAD. Bit-exact with the scalar reference.
  • The header #errors unless the target defines __ARM_FEATURE_DSP, so enabling it on a Cortex-M0+ or an AArch64 build fails at compile time rather than miscompiling. Dispatch precedence on Arm is now NEON_DOTPROD > NEON > SVE > HELIUM_MVE_I > ARM_DSP > scalar.
  • QPointwiseConv2D and QPointwiseConv2DPerChannel now reduce through simd::dotProductWithZeroPoint, so they pick up any enabled backend. Output is byte-identical with every gate off.
  • On the KWS pipeline it takes the pointwise layer from 89,449 to 67,784 cycles and the whole pipeline to 580,305. The end-to-end gain is modest because the first convolution, which carries most of the MACs, has a single input channel and never reaches a vector reduction.
  • With Clang on bare metal, pass -munaligned-access; Clang's strict-alignment default is correct but falls back to byte loads.

Fixes

  • KLDivergenceObserver now picks a real clip threshold (user-facing). The sweep in both the C++ observer and the PyTorch importer built the int8 view from the reference histogram after the clipped tail had been folded in, so the first candidate always scored zero divergence and the sweep returned absmax / 16 — clipping 45% of 100k Laplace samples. Empty bins were also skipped instead of penalized, producing negative "divergences". Both are fixed, and the C++ and Python sweeps return the same threshold on the same data. If you calibrated with the KL observer, re-run calibration: your scales will change.
  • examples/predictive_maintenance holds up on the real AI4I 2020 dataset. Its published F1 of 0.84 came from the synthetic fallback only; on the real CSV it scored F1 0.43. It now trains on the failure modes the sensor readings actually determine, with a realistic class balance, and scores precision 0.66, recall 0.80, F1 0.72 on the real data (10-seed mean). The synthetic generator is now fitted to the real CSV, and the README reports only measured figures, labelled by data source.

CI

  • New required gate: "SMLAD backend on emulated Cortex-M4". No CI host can execute these instructions, so make -C unit_test/embedded arm_dsp_qemu builds bare-metal images with GCC, Clang -munaligned-access and Clang at its strict-alignment default, and runs a bit-exactness sweep on QEMU's mps2-an386 Cortex-M4 under semihosting: every length 0..80, every byte misalignment, the int8 extremes, plus QPointwiseConv2D and QDense end to end. Each image must also contain an SMLAD, so a silent scalar fallback fails. The gate was proven able to fail: a wrong lane unpack, a dropped tail, a missing zero-point subtraction and a disabled dispatch branch were each planted and each reported.
  • arm_crosscompile and arm_crosscompile_clang gain Cortex-M4/M33 ARM_DSP corners and a Cortex-M0+ refusal check.
  • Branch protection went from 17 to 18 required contexts.

No existing API changed. Every new gate defaults to off, and every performance change is bit-exact.

Documentation, architecture guides, and example gallery: https://danmcleran.github.io/tinymind/

Full changelog: v15.1...v15.2