Edge AI & TinyML Architecture
While datacenter inference operates in a world of high-bandwidth memory (HBM3), 80-gigabyte VRAM pools, and kilowatt power supplies, the physical frontier of AI lives at the opposite extreme: Edge AI and TinyML.
TinyML is the technical discipline of running machine learning inference on ultra-low-power microcontrollers (MCUs)—such as ARM Cortex-M0+, Cortex-M4, Cortex-M7, ESP32, and RISC-V:
- Compute Power: 40 MHz to 200 MHz single-core clocks.
- Memory Envelope: 64 KB to 256 KB of SRAM (working memory) and 512 KB to 2 MB of Flash ROM.
- Power Budget: Milliwatts or microwatts (operating on coin-cell batteries or solar energy for years without human intervention).
- Zero Operating System: Bare-metal C++ execution without virtual memory, paging, or swap files.
This chapter details the systems architecture of microcontroller inference engines, zero-copy Flash execution, and memory planning algorithms.
Imagine trying to park an 18-wheel cargo truck inside a tiny one-car residential garage. That is what running deep learning on a microcontroller feels like.
If you bring the whole truck in, it simply won't fit. You have to disassemble the truck: take off the heavy steel parts, shrink the engine, and remove anything that isn't essential.
In TinyML, the 18-wheel truck is a convolutional neural network, and the one-car garage is a 128 KB microcontroller chip. We fit the model by converting all numbers to 8-bit integers (INT8), storing the blueprint on a chip that uses zero electricity (Flash ROM), and reusing a single piece of scratchpad paper for every calculation (the Static Tensor Arena).
1. The Microcontroller Memory Architecture
Explore the division between non-volatile Flash memory (ROM) and volatile SRAM:
The Embedded Memory Split
In an embedded system, memory is divided into two physically distinct semiconductor technologies:
- Flash Memory (ROM, Non-Volatile):
- Size: Typically 512 KB to 2 MB.
- Speed: Moderate read speed (~30-50ns), zero standby power.
- Purpose: Stores compiled firmware instructions, quantized INT8 weights, bias vectors, and graph topology.
- XIP (eXecute In Place): The microcontroller reads weights directly from Flash via memory-mapped buses (SPI / AHB). Weights never enter SRAM!
- SRAM (Static RAM, Volatile):
- Size: 64 KB to 256 KB total.
- Speed: High-speed single-cycle access (~5ns), high static leakage current.
- Purpose: Reserved strictly for mutable state: input sensor buffers (microphones, accelerometers, camera pixels) and intermediate layer activations.
2. The Static Tensor Arena: Zero Dynamic Allocation
To eliminate heap fragmentation, TensorFlow Lite for Microcontrollers (TFLite Micro) allocates a single static byte buffer at initialization:
Offline Activation Lifetime Planning
Because the layer execution order of a neural network is deterministic, an offline memory planner computes the exact lifetime intervals for every intermediate activation tensor:
Tensors whose lifetimes do not overlap are assigned the exact same byte offset inside tensor_arena. This buffer reuse reduces peak SRAM consumption by up to 75%, allowing models with 180 KB of total activations to execute inside a 48 KB arena!
3. System-Algorithm Co-Design: MCUNet & Depthwise Convolutions
Standard convolutional layers are computationally prohibitive on microcontrollers.
For a standard convolution with input channels , output channels , and kernel size :
In Depthwise-Separable Convolutions (MobileNet / MCUNet):
- Depthwise Step: Applies a single spatial filter per input channel independently.
- Pointwise Step: Applies a linear projection across channels.
4. Python Simulation: Microcontroller Memory Arena Planner
Run this live in-browser Python implementation to simulate how an offline activation memory planner assigns buffer offsets to minimize peak SRAM:
- Never allocate heap dynamically (
malloc): Use static byte arrays in the BSS segment. - Quantize to INT8 symmetrically: Eliminates cross-term corrections and allows single-cycle ARM Cortex-M DSP instructions (
SMLAD). - Keep Model Weights in Flash (XIP): Never copy weights into SRAM.
Learn how modern accelerators fuse operators and eliminate memory roundtrips in Hardware Acceleration & Custom Kernels.