Skip to content

v18.2 — int8 residual adds at a third of CMSIS-NN's cycles, and the Cortex-M0+ dense speed restored

Choose a tag to compare

@danmcleran danmcleran released this 12 Nov 19:39
· 26 commits to master since this release
4cccbcd

v18.2 — int8 residual adds at a third of CMSIS-NN's cycles, and the Cortex-M0+ dense speed restored

Performance

  • QAdd rescales each input in one rounding (#273). TFLite ADD rescales both inputs with a two-step rounding and a branch on the shift's sign. When the parameters allow it, which covers every int8 input at TFLite's left_shift of 20, QAdd now composes the two roundings into one 64-bit multiply-add and a shift, and requantizes the sum with the single-rounding requantizer the convolutions already use. Other parameters take the reference loop, kept out of line with a new TINYMIND_NOINLINE macro so that forward() stays small enough to inline and a const layer keeps its parameters folded as constants. On the NUCLEO-F411RE the three residual adds of the MLPerf Tiny ResNet-8 take 21%, 37% and 42% fewer cycles, a third of CMSIS-NN's, and the whole model 1.2% fewer, bit-exact. A QAdd whose parameters sit in RAM runs in about half the cycles, and on the Cortex-M0+ QAdd is 10% faster.
  • Cortex-M0+ dense layers get their speed back (#275). The L031 MLP benchmark had been running 36% slower at -O2 since #230 (35,637 to 48,619 cycles). The dense layers call the requantizer once per output, and its rarely taken saturating path, though never executed, kept GCC from giving the dot product the registers it needed on Thumb-1. Under the new TINYMIND_SPLIT_REQUANTIZER_FORMS, on by default for GCC on Thumb-1 only, QDense and the single-pixel pointwise layers check once per layer whether every requantizer takes the one-rounding path (Requantizer::oneRounding()) and then run a copy of the loop that calls applyOneRounding(). The MLP now takes 33,010 cycles at -O2 and 32,644 at -O3, faster than before #230 at both levels, bit-exact. Other compilers and cores measured slower with the split and compile to the same code as before.
  • Member reads hoisted out of store loops (#272). An int8_t store may alias the layer object itself, so a member read inside such a loop is reloaded on every element. QAdd, QPad2D and QEmbedding now copy their fields into locals first, as the convolutions already did: with the layer in RAM, QPad2D is 10% faster and QEmbedding 20% faster. The same change was measured and dropped where it gained nothing, and for QAvgPool2D, where it made the layer 7% slower.

Verification

  • The CBMC requantizer proof gains 32 jobs proving QAdd's one-rounding input step free of undefined behaviour and equal to the gemmlowp reference for every input, zero point, left shift and multiplier in its domain, with two new planted defects that must be caught (#273).
  • The quantization suite compares QAdd with the reference arithmetic over all 65,536 input pairs for 480 parameter sets, and builds with the split dense loops on, so every dense test runs them; new tests check applyOneRounding() against apply() for four storage types (#273, #275).

Benchmarks

  • Every table on the benchmarks page is re-measured on both boards. With the SMLAD backend, tinymind takes 16.4% fewer cycles than TFLM with CMSIS-NN on the MLPerf Tiny keyword-spotting model and 29.4% fewer on image classification (#274).
  • make TOOLCHAIN=clang builds the tinymind images with Clang through a new clang-arm-cxx wrapper, which adds -munaligned-access (without it the SMLAD backend's word loads become byte loads) and -fshort-enums. Every Clang image is bit-exact with the GCC build; GCC is 3–45% faster, and the page says so (#274).
  • The bench harness's idle loops were undefined behaviour in C++ (an empty infinite loop), which Clang deleted; they now hold an empty asm volatile, and the GCC images compile to identical code (#274).

Docs and CI

  • The agent instructions are split into one AGENTS.md per area, with CLAUDE.md importing them (#270), and the har_activity seed statistic is corrected (#269).
  • The CI apt installer falls back to mirrors outside Canonical's network when the default archive is unreachable (#271).
  • README, the Pages site and the architecture notes describe QAdd's one-rounding inputs and the Thumb-1 dense split (#276).

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

Full changelog: v18.1...v18.2