TactivergeLite

Lite / Independent Engineering Research / Week 23

Fitting a model into memory, time and energy

A smartwatch must recognise a gesture in 20 ms, using under 1 mJ, with 64 KB of RAM. Can your model do it? Work it out before you build it.

About 50 min · 3 goals · Checked by automated tests · Full interactive version

Why should I care?

Embedded ML projects fail most often on budgets, not on accuracy. A few lines of arithmetic, done early, decide whether a design is possible and which knob to turn. This is the habit research engineers bring to any resource-constrained system.

Predict

On a typical small chip, which costs more energy: one 8-bit MAC, or reading one byte from off-chip DRAM?

  1. The MAC, by far
  2. About the same
  3. The DRAM read, by roughly 100× or more
  4. Neither uses energy
Guess first, then reveal

Arithmetic is cheap; moving data is not. Published estimates put an off-chip DRAM access at hundreds of times the energy of a small integer operation (exact figures depend on the technology). Keeping weights and activations on-chip is often the biggest energy win.

Discover

In the Code Lab, write a function that takes a list of layer sizes and returns MACs, weight bytes (at a chosen bit width), peak activation bytes and energy per inference for given pJ/MAC and pJ/byte. Test it on the network from the worked example, then search for the largest hidden layer that fits a 1 mJ, 64 KB RAM budget.

What the interactive shows (text version)

A budget table has four rows: flash (weights and code), RAM (peak activations), latency (MACs ÷ MAC rate) and energy (MACs × energy per MAC + bytes × energy per byte). The worked example needs 0.67 ms and 0.92 µJ, mostly from reading weights.

You can also open the interactive on the full site when you have a faster connection.

Understand

The budget table

Write one row per resource: flash (weights + code), RAM (peak activations + buffers + stack), latency (MACs ÷ MAC rate + overheads) and energy (MAC energy + memory energy + idle energy). Each has a limit from the product requirement. The design is feasible only if every row fits, with a margin.

Energy per inference

E ≈ MACs × e_MAC + bytes moved × e_byte + P_idle × time. Because e_byte can be tens to hundreds of times e_MAC (depending on which memory), a model with fewer weight reads can beat one with fewer MACs. Reusing data already in registers or SRAM is the key trick of efficient accelerators.

Which knob?

Too big for flash: quantise or prune. Too big for RAM: process in smaller tiles, or choose layers with smaller activations. Too slow: fewer MACs, SIMD instructions or an accelerator. Too much energy: reduce data movement, then MACs, then duty-cycle the device. Each change must be re-checked against accuracy on held-out data.

Explain it another way

Intuitive

Packing for a flight with a weight limit, a size limit and a time limit at security. Every item must pass all three, and the heavy boots matter more than the socks.

Technical

Roofline thinking: performance is limited either by compute (MACs per second) or by memory bandwidth (bytes per second × operations per byte). Arithmetic intensity, MACs per byte moved, tells you which.

Mathematical

Example: 2×10⁶ MACs at 1 pJ = 2 µJ; 200 KB of weights read from flash at 20 pJ/byte = 4 µJ; total 6 µJ. Quantising to 4 bits halves the weight bytes: 2 + 2 = 4 µJ, a 33% saving with no change in MACs.

Applied

Always-on audio wake-word detectors often run a tiny first-stage model continuously and wake a larger model (or the main processor) only when it fires: a cascade that keeps average energy low.

Worked example 1

Budget check: 32,128 MACs and 32 KB of int8 weights; 1 MAC/cycle at 48 MHz; 3 pJ/MAC; 25 pJ/byte from flash. Latency and energy?

Latency = 32,128/48×10⁶ ≈ 0.67 ms. Energy = 32,128×3 pJ + 32,768×25 pJ ≈ 0.096 µJ + 0.82 µJ ≈ 0.92 µJ: memory dominates by about 8×.

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

µJ

µJ

MACs

Practice 4. Your model's weights fit in flash, but one layer's input and output activations together exceed RAM. What is the most direct fix?

million

Apply it

Write a one-page feasibility study for an on-device classifier of your choice: requirement, budget table with every assumption and its source, the calculation, and a recommendation. Mark every number you have not measured as an estimate.

Reflect

Which budget row would you have forgotten if you had started by training the model?

Write your answer on paper or in your own notes. Lite never stores what you write.

← Quantisation: fewer bits, smaller modelsPower, performance and area →