A keyword spotter needs 1.49 million multiply-adds per answer. In our model of one chip family, a Cortex-M4 takes 7.8 ms, a Cortex-M55 1.9 ms, and an NPU 0.2 ms, if every operator fits.
Learn what the DSP extension, Helium vectors and a small NPU each add to a Cortex-M, how the compiler splits a network between them, and why SRAM, DMA and one odd operator decide the real speed.
Pick a chip, then flip the custom gate switch. Watch which operators move, how long the whole network takes, and how many bytes of SRAM the busiest moment needs. Then we build, piece by piece, each engine, the compiler, the memory path and the partition game.
You need a rough idea of a neural network layer (a grid of multiply-adds) and a little C. We build the rest from zero.
Part of Firmware from Zero to Expertise, Edge ML track. Built from primary sources: the Arm Hot Chips 2020 talk on Cortex-M55 and Ethos-U55, Arm’s Helium design article, the CMSIS-NN docs and paper, and the Vela compiler docs. Sources are listed in the Field Guide. The chip, the cycle counts and the timings in the devices are a labelled model, not a measurement.
Illustrative model, not a measurement: a 9-operator keyword spotter (1,488,768 multiply-adds, 14,000 bytes of int8 weights and biases), all engines at 200 MHz, half of peak throughput used. Peak rates come from Arm: Cortex-M55 8 int8 MACs per clock (Hot Chips 2020), an Ethos-U55 with 128 MACs. The M4 figure of 2 MACs per instruction is the SMLAD instruction.
Chapter 0
See why a small network can run on a coin cell only when the right engine, the right memory and the right split all line up
You wear a pair of earbuds. They sit quiet for hours. When you say a wake word, they light up within a quarter of a second. Between those moments, a tiny network listens to the microphone, many times each second, forever, on a battery the size of a button.
That network is a pile of arithmetic. The chip must finish the pile before the next slice of sound arrives, and it must spend almost no energy doing so. If it is slow, the earbuds miss your word. If it is hungry, the battery dies by Tuesday.
A microcontroller (MCU) is a small computer on one chip: a processor core, a little fast memory called SRAM (it forgets everything when power drops, like a whiteboard), and a larger slow memory called flash (it keeps its contents, like a printed book). A Cortex-M is a family of processor cores from Arm that sit inside most MCUs. The embedded intro and bits, types and the memory map build all of this from zero.
A neural network layer is mostly one move repeated: take a number, multiply it by a weight, and add the result to a running total. That move is a multiply-accumulate, or MAC. A small keyword network does about a million and a half of them per answer. We count them properly in Chapter 1.
An operator is one named step of a network, such as a convolution, a pooling step or a softmax. A network is a list of operators. The runtime, the program that executes the list, visits them one by one. The first lesson of this track shows that runtime and its tensor arena, the block of SRAM where the intermediate results live.
A plain core does one MAC after another, like one cashier serving a long queue. That works, but it is slow and it keeps the core awake. Arm gives a Cortex-M three ways to open more tills.
First, the DSP extension (Cortex-M4 and later) packs two small numbers into one register and multiplies both with one instruction. Second, Helium (Cortex-M55 and M85) adds 128-bit vector registers, so one instruction touches sixteen int8 numbers. Third, a microNPU such as the Arm Ethos-U55 is a separate block next to the core. It holds its own array of multiplier units and runs a whole stretch of the network by itself.
The hero at the top of this page runs one invented keyword network on all three. In our model the Cortex-M4 needs 7.8 ms, the Cortex-M55 with Helium needs 1.9 ms, and the M55 with an NPU needs 0.2 ms. The jump from Helium to the NPU is large. But look at the hero again with the custom gate switch on and off. One odd operator changes the story.
A vendor sheet quotes peak speed for the engine. Your product lives with something else: the speed of the slowest part of the whole path. That path includes the operators the NPU cannot run, the time to start the NPU, the time to bring weights in from slow flash, and the SRAM that all of it needs at once.
So this lesson is about partitioning: deciding which operator runs on which engine, and what that decision does to time and memory. You will meet three failure stories on the way. A network that runs slower on the NPU than on the core. A chip that stalls waiting for weights. A buffer that the NPU reads while it still holds old data. Each one has a symptom, a measurement and a fix.
Chapter 1
Count the MACs and the weight bytes of each layer, and see why one number sets the time and the other sets the memory trouble
You are asked: “Will this network fit our deadline?” You cannot answer by looking at the model file size. You answer by counting. Two counts matter most: how many MACs the layer needs, and how many bytes of weights it must read.
Take the first layer of our keyword network. The input is a small picture of the sound: 49 time steps by 10 features, one value each, stored as int8 (one signed byte). The layer slides a window of 10 by 4 cells over it. At each stop it multiplies the 40 cells by 40 weights and adds them up. That is one output number, and it costs 40 MACs.
A convolution repeats that window for every output position and every filter (a separate set of weights that looks for one pattern). Count the stops, count the filters, multiply by the window size. Here the output grid is 25 by 5 cells and there are 64 filters.
MACs = output cells × filters × window cells = 25 × 5 × 64 × 40 = 320,000
Now count the bytes. Each filter holds 40 int8 weights, so 64 filters hold 2,560 bytes. Each filter also has one bias, a number added at the end, stored as a 4-byte int32 for accuracy. That adds 256 bytes. The layer carries 2,816 bytes of weights and its output holds 25 × 5 × 64 = 8,000 bytes of activations.
Two cheaper layer shapes appear in almost every small network. A depthwise convolution gives each channel its own 3 by 3 window and never mixes channels: 25 × 5 × 64 × 9 = 72,000 MACs. A pointwise convolution is a 1 by 1 window that mixes all 64 input channels into each output channel: 25 × 5 × 64 × 64 = 512,000 MACs. Pair them and you get most of the accuracy of a full 3 by 3 convolution at a fraction of the cost.
Try the counter. Pick a layer shape, then move the two sliders and read the three engines’ compute time.
Choose a layer kind. The warm, purple and teal bars show compute time only, with no memory waits. Drag the filters and the output size and watch which count grows.
Illustrative timings: 200 MHz, half of peak throughput used, peak rates of 2 MACs per clock (Cortex-M4 SMLAD), 8 (Cortex-M55, Arm Hot Chips 2020) and 128 (an Ethos-U55 with 128 MACs). Pointwise assumes as many input channels as filters. Dense takes 64 inputs and ignores the output-cell slider.
Time is the MAC count divided by how many MACs the engine finishes per clock, divided by the clock rate, and divided again by how busy you keep the engine. We call that last factor utilisation. A real engine never reaches 100%, because it waits for data and loops have overhead.
time = MACs ÷ (MACs per clock × utilisation) ÷ clock rate
Work one case with every step. The pointwise layer has 512,000 MACs. A Cortex-M4 does at best 2 per clock; at 50% that is 1 per clock, so 512,000 clocks. At 200 MHz that is 512,000 ÷ 200,000,000 = 2.56 ms. A Cortex-M55 does 8 per clock; at 50% that is 4, so 128,000 clocks, or 0.64 ms. An NPU with 128 MACs at 50% does 64 per clock, so 8,000 clocks, or 40 µs.
Divide MACs by weight bytes and you get reuse: how many times each fetched weight byte is used. Our first layer scores 320,000 ÷ 2,816 ≈ 114. Our pointwise layer scores 512,000 ÷ 4,352 ≈ 118. The final dense layer scores 768 MACs over 816 bytes: under 1. With one input vector, every weight is used once and thrown away.
High reuse means the engine can stay busy. Low reuse means the engine waits for weights. Chapter 5 turns that into numbers for the slow flash path: a dense layer is exactly where a big NPU idles.
The failure mode. Picture a team that halves the MACs of a network by switching to depthwise layers. The symptom: the inference gets only a little faster, far less than half. The measurement: cycles per MAC for each layer from a cycle counter. Depthwise layers show far more cycles per MAC than pointwise ones, because each weight is reused less. The fix: compare layers by measured time, not by MAC count, and let the layer with the worst cycles per MAC lead your redesign.
On real hardware. Take an STM32 Nucleo with a Cortex-M4 part such as the STM32F411. Enable the cycle counter in the debug unit (DWT->CYCCNT) and read it before and after each layer of a TFLM model. Divide by the layer’s MAC count. Repeat with CMSIS-NN kernels on and off to see the gap that Chapter 2 explains.
Chapter 2
Pack two small numbers into one 32-bit register and multiply both at once, then see what the widening step costs
Picture a plain Cortex-M core as a cashier who can scan one item at a time. Each register holds one 32-bit number. But our weights and activations are int8: only 8 bits. Put one int8 number in a 32-bit register and 24 bits sit empty. That is a lot of idle space.
The cheapest fix is to use the empty space. Put two 16-bit numbers in one 32-bit register, side by side. Then one instruction can act on both halves. This idea is called SIMD, short for single instruction, multiple data. Arm calls the Cortex-M version the DSP extension. It arrived with the Cortex-M4 and also sits in the M7 and M33.
SMLAD takes three registers. Call them Rn, Rm and Ra. It treats Rn and Rm as two 16-bit signed lanes each, multiplies lane against lane, and adds both products to the 32-bit total in Ra. One instruction, two MACs. The CMSIS-NN paper describes this as a dual 16-bit multiply feeding a single 32-bit accumulator.
Rd = Ra + (Rn[15:0] × Rm[15:0]) + (Rn[31:16] × Rm[31:16])
Why a 32-bit total? Two int8 numbers multiply into at most 16 bits, and a sum of thousands of products needs room to grow. The wide accumulator avoids overflow, which the int8 lesson examines closely.
Weights and inputs arrive as int8. Four of them fit in one 32-bit load, which is efficient. But SMLAD wants 16-bit lanes. So the code must widen the bytes first: copy each int8 into a 16-bit lane and keep its sign. The instruction for that is SXTB16. It takes bytes 0 and 2 of a register, sign-extends each to 16 bits, and puts them in the two lanes of the result. To reach bytes 1 and 3, rotate the word right by 8 bits first (the instruction has a rotate option, and CMSIS offers __ROR).
So four int8 MACs need two widenings of each operand, two SMLAD instructions, and two word loads. Step through it below with random numbers. Count the instructions at the end.
Each word holds four signed bytes. Press Next instruction to widen the even bytes, multiply-add two lanes, then do the odd bytes. Press New numbers for a fresh draw.
The lane layout follows the Arm definition of SXTB16 and SMLAD (bytes 0 and 2 go to lanes 0 and 1; a rotate by 8 reaches bytes 1 and 3). The numbers are random draws in your browser. The instruction count excludes the loads and the loop.
Count the work: 4 SXTB16 plus 2 SMLAD gives 6 instructions for 4 MACs, plus 2 loads. That is 1.5 instructions per MAC before any loop overhead, so the pair trick alone does not give a clean 2 times gain. This is why careful kernels widen the weights once and reuse them, or arrange the data so one widening serves many MACs. CMSIS-NN, Arm’s library of neural network kernels, does exactly this. Its docs say it picks one of three code paths by feature: no SIMD (for example a Cortex-M0), the DSP extension (for example a Cortex-M4) or Helium (a Cortex-M55). The CMSIS-NN paper (arXiv 1801.06601) reports a 4.6 times gain in runtime and throughput and a 4.9 times gain in energy efficiency from these kernels.
Here is the inner loop in C. The intrinsics come from CMSIS (cmsis_compiler.h and the core header for your part).
/* dot product of n int8 pairs, n a multiple of 4; Cortex-M4 and later with the DSP extension */ int32_t dot_s8(const int8_t *a, const int8_t *b, int n) { int32_t acc = 0; for (int i = 0; i < n; i += 4) { uint32_t wa, wb; memcpy(&wa, a + i, 4); /* one 32-bit load = four int8 */ memcpy(&wb, b + i, 4); acc = __SMLAD(__SXTB16(wa), __SXTB16(wb), acc); /* bytes 0 and 2 */ acc = __SMLAD(__SXTB16(__ROR(wa, 8)), __SXTB16(__ROR(wb, 8)), acc); /* bytes 1 and 3 */ } return acc; }
The code is short, and every line has a reason. The memcpy keeps the load legal when the pointer is not word aligned; the compiler turns it into one load. The accumulator stays in a register for the whole loop, so memory sees only the inputs. If you replace int8_t with the wrong signedness the answer changes, so test against a plain loop first.
The failure mode. Symptom: you compile for a Cortex-M4 but the network runs no faster than before. Measurement: read the cycle counter around one convolution, then look at the build flags. If the compiler was told -mcpu=cortex-m3, or the CMSIS-NN feature macros were not set, the library silently used the no-SIMD path. Fix: set -mcpu=cortex-m4 (or your real part), rebuild, and confirm the DSP path with a cycle count. Never trust a speed-up you have not measured.
On real hardware. On an STM32 Nucleo with a Cortex-M4, run the loop above and a plain C loop over the same 1,024 bytes. Read DWT->CYCCNT around each. Report cycles per MAC for both, with the optimiser on.
Chapter 3
Follow one 128-bit instruction through a narrow datapath, and see how overlap turns four small steps into eight MACs per clock
The DSP extension gave us two lanes. A vector unit gives us many. Think of a bakery that bakes one loaf at a time, then buys a long oven that bakes sixteen at once. The long oven costs more floor space, and on a small chip floor space is money and battery.
Arm’s answer for the Cortex-M is Helium, the name for the M-Profile Vector Extension (MVE) of the Armv8.1-M architecture. The Cortex-M55 has it, and so does the Cortex-M85. The Arm Hot Chips talk from 2020 lists the basics: 8 vector registers, each 128 bits wide, which reuse the floating point registers, and over 150 new instructions. A 128-bit register holds sixteen int8 numbers, eight int16 numbers or four 32-bit numbers. Each of those is a lane.
Arm’s research article on the design explains why Helium did not just copy the Neon unit from bigger Cortex-A chips. A Cortex-M must fit a range of price points in a tiny area. Widening the memory path to 128 bits and adding four 32-bit multipliers was too much for a small core. So the team built something new, with one rule: every instruction describes 128 bits of work, no more and no less.
Here is the trick. The hardware does not need to process all 128 bits in one clock. It cuts each instruction into four chunks of 32 bits and calls them beats, named A to D. A single beat can run one 32-bit MAC or four 8-bit MACs. A small core might do one beat per clock, a bigger one two, a full-width one four. The software is identical in all three cases. Only the speed changes.
The Cortex-M55 is a dual-beat design: it processes 64 bits per clock, so one 128-bit instruction takes 2 clocks. Arm lists its rate per clock as 2 int32, 4 int16 or 8 int8 multiply-accumulates.
A vector multiply needs data from a vector load. The load unit and the multiply unit are separate hardware. Beat A of the multiply needs only beat A of the load. So the multiply can begin as soon as the first beat of its load has finished, while the load unit goes on to fetch the next vector. Arm says it plainly: since the load and MAC hardware are separate, the beats can be overlapped.
Play with it. Each coloured block is one 128-bit instruction, cut into its four beats. Turn overlap off and every instruction must finish before the next one starts.
Top row: the load unit. Bottom row: the multiply unit. Choose how many beats the datapath does per clock, switch overlap on and off, and drag the number of vector instructions.
A scheduling sketch, not a pipeline trace. Each instruction is a 16-lane int8 load followed by a 16-lane int8 multiply-accumulate (16 MACs). Overlapped, a multiply starts one clock after its load starts and loads run back to back. Not overlapped, each load and each multiply finishes before the next starts. The 2-beat, 8 MACs per clock figure is Arm’s for the Cortex-M55.
With two beats per clock and overlap on, a run of N vector instructions finishes in 2N + 1 clocks. For N = 4 that is 9 clocks for 64 MACs, or about 7.1 per clock. As N grows the rate approaches 16 MACs in 2 clocks: 8 per clock. Turn overlap off and the same four instructions need 16 clocks, because each load and each multiply must finish before the next one starts.
A Cortex-M4 does 2 MACs per SMLAD, and needs extra widening. A Cortex-M55 does 8 per clock with no widening, because Helium multiplies int8 lanes directly and accumulates into 32 bits. The Cortex-M55 page from Arm claims up to 15 times the machine learning performance and up to 5 times the signal processing performance of existing Cortex-M chips. Treat those as the vendor’s best case, because they depend on the kernel and the memory.
Two more details matter to firmware. First, the vector load can be predicated: a small mask switches off lanes, so the tail of a loop whose length is not a multiple of 16 needs no separate scalar code. Second, loops can run with little branch overhead. Here is a dot product in C with the Arm MVE intrinsics from arm_mve.h (confirm exact names against your toolchain’s header).
/* int8 dot product on Helium: 16 lanes per step, the tail handled by a lane mask */ #include <arm_mve.h> int32_t dot_s8_mve(const int8_t *a, const int8_t *b, uint32_t n) { int32_t acc = 0; while (n > 0) { mve_pred16_t p = vctp8q(n); /* first min(n,16) lanes on */ int8x16_t va = vldrbq_z_s8(a, p); /* predicated load */ int8x16_t vb = vldrbq_z_s8(b, p); acc = vmladavaq_p_s8(acc, va, vb, p); /* multiply, add across lanes, accumulate */ a += 16; b += 16; n = (n > 16) ? n - 16 : 0; } return acc; }
Compare it with Chapter 2. There is no widening step, no rotate, no tail loop. The compiler and the library, CMSIS-DSP for signal work and CMSIS-NN for networks, hide this from you. But the speed-up exists only if your build selects the Helium path.
The failure mode. Symptom: a Cortex-M55 build runs a layer at only twice the speed of the M4 build, not near 4 times or more. Measurement: look at the library path and disassemble the hot loop. If you see smlad and sxtb16 instead of vmlada and vldrb, the build never used Helium. Fix: select the Armv8.1-M target with MVE enabled (for example -mcpu=cortex-m55), make sure the MVE feature macro is set for CMSIS-NN, and re-measure.
On real hardware. Use a Cortex-M55 board such as an Alif Ensemble devkit, or the Arm Corstone-300 Fixed Virtual Platform when no board is at hand. Time the 1,024-byte dot product from Chapter 2 and from this chapter with the cycle counter, and compare cycles per MAC.
Chapter 4
Meet the Ethos-U55 as a bus master with its own memory ports, and follow one inference through its five-step data flow
Helium makes the core faster at multiplying. A neural processing unit (NPU) takes the multiplying away from the core completely. Think of the core as a chef who has hired a pastry team in the next room. The chef writes down a recipe, hands it over, and goes back to resting. The team works through the whole recipe alone and rings a bell when the cake is done.
Arm’s small NPU is the Ethos-U55, a microNPU that works alongside a Cortex-M55, M7, M33 or M4. Its parts, from the Hot Chips 2020 talk by Arm’s engineers: a MAC engine, a weight decoder, a shared buffer, an elementwise engine for pooling and adds, a central control block and a DMA. It accelerates convolutional and recurrent operators, uses 8-bit or 16-bit activations, and compresses its weights. You pick a size at chip design time: 32, 64, 128 or 256 MACs per clock.
A MAC is two operations, one multiply and one add. So the peak rate in operations per second is 2 × MACs per clock × clock rate. A 128-MAC U55 at 500 MHz peaks at 2 × 128 × 500,000,000 = 128 GOPS (giga-operations per second). At 1 GHz, the 32-MAC version gives 64 GOPS and the 256-MAC version 512 GOPS, the range that Arm’s launch coverage quotes. A shipping chip often runs below that: Alif’s Ensemble E1C uses one U55 with 128 MACs and quotes up to 46 GOPS. ST’s STM32N6 uses its own design, the Neural-ART accelerator, with nearly 300 MAC units and 600 GOPS at about 1 GHz. 2 × 300 × 1 GHz gives the same 600.
A bus master is a block that can read and write memory by itself, without asking the core. The U55 has two such ports, both AXI5: M0, read and write, to SRAM, and M1, read only, to flash. It also has a small register interface (APB) through which the core configures it, and an interrupt line (a wire the NPU uses to tap the core on the shoulder when it is done). That layout explains a great deal later: weights come from flash through the read-only port, while everything the NPU must write (activations, scratch) must sit in SRAM.
The Arm talk walks through one inference in five steps. Step through it below.
Press Next step to move through the five steps. The coloured arrows show which memory port or wire is busy. Pick a MAC count and a clock to see the peak.
The five steps, the two AXI5 masters (M0 read and write to SRAM, M1 read only to flash), the register and interrupt wires, and the 32 to 256 MAC options are from Arm’s Hot Chips 2020 talk on the Cortex-M55 and Ethos-U55. Peak GOPS is 2 × MACs × clock. A real chip rarely sustains the peak.
The NPU supports a fixed set of operators. A network made only of those operators runs entirely on it. Any other operator falls back to the core, where CMSIS-NN kernels run it. In 2020, Arm said that for many popular networks, Softmax was the only operator that fell back. The set grows with each release of the compiler, so do not copy that list. Ask the tool, as Chapter 5 shows.
At run time the TensorFlow Lite for Microcontrollers (TFLM) interpreter sees a model in which the compiler has replaced the supported stretches with one custom operator for the NPU. You register that operator, plus the few fallback operators, and the rest is routine.
/* TFLM host code for a model compiled by Vela; one NPU custom op plus Softmax on the core */ static tflite::MicroMutableOpResolver<2> resolver; resolver.AddEthosU(); /* the "ethos-u" custom operator Vela inserted */ resolver.AddSoftmax(); /* a fallback operator, runs on the Cortex-M */ alignas(16) static uint8_t tensor_arena[kArenaBytes]; /* must live in NPU-reachable SRAM */ static tflite::MicroInterpreter interp(model, resolver, tensor_arena, kArenaBytes); interp.AllocateTensors(); /* fill interp.input(0)->data.int8, then: */ interp.Invoke(); /* the driver starts the NPU, waits for its interrupt */
Read the comment on the arena. The U55 reads and writes activations through its SRAM port, so the arena cannot sit in flash and must be in memory the NPU’s bus can reach. Chapter 6 returns to that rule.
The failure mode. Symptom: you have an NPU, yet the model runs at the same speed as on the core. Measurement: open the compiled model, or run the compiler with its report options, and count the NPU custom operators. If there are none, every operator stayed on the CPU. The usual cause: the Vela compiler needs a quantised network: one whose 32-bit floating point numbers were squeezed into 8-bit or 16-bit signed integers. A floating point model, or one quantised in an unsupported way, is left alone. Fix: quantise the model (see int8 in firmware and quantisation), recompile, and check the operator count again.
On real hardware. Use a board with an Ethos-U55, for example an Alif Ensemble devkit or a Corstone-300 virtual platform. Run one model compiled for the NPU and one for the core only, with the same input. Time both with a hardware timer and write the ratio down. Name the NPU size in your note, because 32 and 256 MAC parts differ by 8 times at the same clock.
Chapter 5
Run the model through the compiler, choose where weights and activations live, and find out when more MACs buy you nothing
The NPU cannot read a .tflite file. It follows a precompiled list of commands. Someone must turn the network into that list, decide which tensor lives where, and split the work into pieces that fit the NPU’s small internal buffer. For the Ethos-U family that someone is Vela, Arm’s open-source Python tool.
Vela reads a quantised model and writes a new one. In the new file, each stretch the NPU can run is replaced by one TensorFlow Lite custom operator that holds the command stream and the compressed weights. Everything else stays untouched and runs on the core. The Vela docs say it plainly: parts of the model that cannot be accelerated are left unchanged and run on the CPU with an appropriate kernel.
The Zephyr project’s Ethos-U sample shows the whole call. Each flag is a decision.
# from the Zephyr tflm_ethosu sample, assuming an Ethos-U55 with 128 MACs vela model_int8.tflite --output-dir out \ --accelerator-config ethos-u55-128 \ --system-config Ethos_U55_High_End_Embedded \ --memory-mode Shared_Sram \ --optimise Performance # which operators stayed on the CPU, and what the compiler supports: vela model_int8.tflite --accelerator-config ethos-u55-128 --show-cpu-operations vela --supported-ops-report
Accelerator config names the hardware you really have: ethos-u55-32, -64, -128 or -256. Pick the wrong one and the command stream is wrong for your silicon. System config describes how fast the memories are. Memory mode says where things live. Optimise chooses between small memory (Size) and fast inference (Performance, the default).
The Vela docs define the memory modes. Sram_Only: the NPU sees only SRAM, so the model’s constant data and the tensor arena both sit in SRAM, shared with the core. Shared_Sram, the default for the U55: the arena is in SRAM, and the constants (weights, command stream) are read from flash or other memory. A third mode, Dedicated_Sram, reserves an SRAM for the NPU alone as a cache. It is the default for the larger U65 and U85. The U55 does not normally use it, because its flash port is read only, as Chapter 4 showed.
The trade is plain. Sram_Only is fast but costs SRAM for every weight byte. Shared_Sram saves SRAM but makes the NPU wait on flash.
The Vela blog lists system configurations by bandwidth. For the U55, “Deep Embedded” has SRAM at 1.6 GB/s and flash at 0.1 GB/s. “High End Embedded” has SRAM at 4 GB/s and flash at 0.5 GB/s. (These come from Vela 3.2.0; check your version.) Turn bandwidth into bytes per clock: at 200 MHz, 0.5 GB/s is 2.5 bytes per clock, and 0.1 GB/s is 0.5 bytes per clock.
Work the pointwise layer, which has 4,352 bytes of weights and 512,000 MACs. At 128 MACs and 50% use, the NPU computes 64 MACs per clock: 8,000 clocks. Fetching 4,352 bytes at 2.5 bytes per clock takes 1,741 clocks. Compute wins, so the layer is compute bound. At 0.5 bytes per clock the fetch takes 8,704 clocks. Now the fetch wins and the layer is memory bound. A bigger MAC array does not help, because the multipliers already wait for weights. Try it.
For each operator that runs on the NPU, the teal bar is compute clocks and the yellow bar is weight-fetch clocks. The longer one sets the time. Change the flash speed, the memory mode and the MAC count.
The two flash speeds and the SRAM speed (4 GB/s) are the Vela 3.2.0 system configurations for the U55. The network is our 9-operator model with the custom gate swapped for ReLU; 200 MHz and 50% use are illustrative, and weight fetch overlaps compute, so each operator costs the larger of the two. Vela prints its own estimates, which Arm warns are only a guide.
The dense layer at the end shows the other face of the story. It has 816 weight bytes and 768 MACs, so compute takes 12 clocks but the fetch takes 326. No setting makes it fast. It is tiny, so you accept it.
The failure mode. Symptom: you move from an NPU with 128 MACs to one with 256 and the inference time barely changes. Measurement: for each layer, compare the compute estimate with the weight bytes divided by the memory bandwidth. In the device, set 0.1 GB/s and step from 128 to 256 MACs: the time stays the same. Fix, in order: use Sram_Only if the weights fit in SRAM, shrink the weights (fewer filters, pruning), and re-check the system config describes the real memory.
For real numbers, Arm’s own advice is to profile on an FPGA, or approximate on a Fixed Virtual Platform (FVP) model. The compiler’s printed estimates only guide its optimisation and are not accurate enough to compare across configurations.
On real hardware. Compile the same model for Shared_Sram and for Sram_Only. On an Ethos-U55 board or the Corstone-300 FVP, time both with a hardware timer and note the SRAM each build uses (the size of your arena plus the constants). Write both numbers side by side.
Chapter 6
Fill audio buffers without the core, place every buffer where the engine can reach it, and keep the cache from lying
A fast engine is useless if it starves. Think of the NPU as a printing press and the audio as paper. The press can print a page in a blink, but someone must keep feeding paper, take the pages out, and never hand it a half-dried sheet. That someone is not the core. The core is asleep.
The DMA controller (direct memory access) is a small helper that copies data between a peripheral and memory with no core involvement. For a microphone, the standard pattern is the ping-pong buffer: two equal buffers, A and B. DMA fills A while the core or NPU reads B. When A is full, an interrupt fires and the roles swap. Interrupts and DMA and DMA ping-pong for audio build this from zero.
Arm’s keyword spotting example in the Hot Chips talk uses 16 kHz audio and a 40 ms frame. Work out one frame. 16,000 samples per second × 0.040 s = 640 samples. At 16 bits each that is 1,280 bytes. DMA delivers one buffer every 40 ms. Between those events the core can sleep, if the inference finishes fast enough.
Two clocks matter. The frame clock is fixed by the microphone: a new frame every 40 ms, no matter what. The inference clock is yours: you decide how often to run the network, and each run must finish before the next one is due. If a run takes longer than the gap, the buffers overrun and audio is lost.
Try it. Pick the engine, set how often inference runs, and scale up the network to see what breaks first.
Top row: DMA fills buffer A or B every 40 ms. Next rows: when the core and the NPU are busy. Choose an engine, drag the run interval and the network size.
Illustrative: the 16 kHz, 40 ms frame is from Arm’s keyword spotting slide. Run times scale our 9-operator model (custom gate swapped for ReLU, 200 MHz, half of peak use) linearly with network size. The core counts as busy while it runs its own operators and while it starts the NPU; it can sleep while the NPU works.
Memory on a modern MCU is not one flat pool. The Cortex-M55 has tightly coupled memories (TCM): small, fast RAMs wired straight to the core for real-time access, up to 16 MB for instructions and 16 MB for data according to Arm. It also has caches for general memory. The Arm talk adds that a DMA controller can reach the TCM through a 64-bit AHB slave port. The NPU is another bus master, and which memories it reaches depends on how your chip designer wired it. For the U55 the reference design gives M0 a path to SRAM and M1 a read-only path to flash. Check your chip’s memory map before you place anything.
A safe plan for a Cortex-M55 with a U55, as a toy rule set: the tensor arena in SRAM that M0 reaches; the model constants in flash (or SRAM in Sram_Only mode); the DMA buffers in SRAM that both the DMA and the core reach; and hot core-only code or data in TCM.
A data cache is a small fast copy of recent memory that sits between the core and RAM. It makes the core fast, but it also creates a danger: the cache can hold an old copy of a buffer that DMA or the NPU just rewrote. The core then reads stale bytes. In the other direction, the core may have written new input only into the cache, so the NPU reads the old RAM contents. Neither mistake raises an error. The network simply gives wrong answers.
/* CMSIS cache maintenance; align and size buffers to your part's cache line */ /* 1. DMA just wrote 'frame' to RAM: drop any stale cached copy before the core reads it */ SCB_InvalidateDCache_by_Addr((uint32_t *)frame, sizeof frame); compute_features(frame, input_tensor); /* the core writes the NPU's input */ /* 2. push the core's writes out to RAM so the NPU sees them */ SCB_CleanDCache_by_Addr((uint32_t *)input_tensor, input_bytes); interp.Invoke(); /* the NPU reads RAM, writes its result to RAM */ SCB_InvalidateDCache_by_Addr((uint32_t *)output_tensor, output_bytes);
Clean pushes the core’s writes down to RAM. Invalidate throws the cached copy away so the next read goes to RAM. A buffer placed in non-cacheable memory (set by the MPU) avoids both calls. Many vendor drivers do the work for you. You still need to know the rule, because a buffer you add later will not be covered.
The failure mode. Symptom: the keyword spotter works on the bench with a test file but gives random answers from the live microphone, and the error changes with the build. Measurement: copy the input tensor to a second buffer with the cache cleaned and compare bytes with what the core believes it wrote; or turn the data cache off and see if the problem vanishes. Fix: add the invalidate and clean calls at each hand-off, or move the buffers into a non-cacheable region.
On real hardware. On an Alif Ensemble or any Cortex-M55 board with a data cache, capture audio with DMA into a buffer and run the model. Toggle the cache maintenance calls off and on. Count wrong answers over 1,000 frames each way.
Chapter 7
Assign nine operators to the core or the NPU and watch the run time, the number of NPU starts and the SRAM peak move together
You now have three engines and a compiler. The last question is the one that decides the product: for each operator, which engine runs it? Think of a relay race. Every time the baton passes from the core to the NPU or back, a few seconds are lost, and both runners need space on the track at the hand-over.
Here are the rules of our model. They follow how the Ethos-U flow works, with toy numbers where noted.
Rule 4 is a simplification, so treat the SRAM numbers as the shape of the effect and not a prediction. The real figure appears in the compiler’s output for your model.
Put every operator on the core with Helium and the time is 1,913 µs. Now send every supported operator to the NPU. The gate stays on the core, so there are two NPU runs: operator 1 alone, then operators 3 to 8. The clocks add up as 5,000 + 3,000 for run one, 8,000 for the gate on the core, 19,576 + 3,000 for run two, and 480 for Softmax: 39,056 clocks, which is 195 µs at 200 MHz. That is almost ten times faster than the core.
Look at the memory, though. The gate on the core needs its 8,000-byte input and 8,000-byte output at once: 16,000 bytes. That is the peak. The operators on the NPU need much less. If you can replace the custom gate with a plain ReLU that the NPU supports, the whole stretch from operator 1 to operator 8 becomes one run. It needs 490 bytes of input, 12 bytes of output and 2,048 of scratch: 2,550 bytes. The time drops to 145 µs because one hand-off disappears and the gate costs less. The 16,000-byte peak was caused by one operator.
Now you play. The goals: finish in under 150 µs and keep the SRAM peak under 12 KB. Tap an operator to move it between the core and the NPU. There is a trap, and the Show the best button reveals the answer.
Tap an operator to switch it between the core (purple) and the NPU (teal). The top bar is time. The columns show the SRAM needed at each stage, against a 12 KB goal line.
The model of this lesson: 200 MHz, an Ethos-U55 with 128 MACs at half use, flash at 0.5 GB/s, a Cortex-M55 with Helium as the core. The 3,000 clock hand-off and the 2,048 byte scratch tile are toy values. The best partition is found by trying all 512 assignments.
The best the model finds is 195 µs with a 16,000 byte peak if the gate stays, or 145 µs with a 2,602 byte peak if you swap it. So the 12 KB goal cannot be met without changing the network. One more surprise: the best partition keeps the dense layer on the core. Its weights are used once (Chapter 1), so the NPU would wait 326 clocks for them, while the core needs only 192 clocks for its 768 MACs. This is the lesson of partitioning: sometimes the right move is not to assign, but to edit the model so that the awkward operator disappears.
The failure mode. Symptom: a team offloads every operator it can, and one small network runs slower than before. Measurement: time each operator on both engines, then add the hand-off to the NPU side. In our model, the average pool takes 2,000 clocks on the core and 1,000 on the NPU, but 4,000 with the hand-off. Offloading that one operator alone makes it twice as slow. Fix: only send a stretch to the NPU when its saving is bigger than the hand-off, join neighbours into one run, and move or rewrite the operator that splits a run.
On real hardware. On an Ethos-U55 board or the Corstone-300 FVP, compile the model, list the CPU operators with the compiler’s --show-cpu-operations option, and count the NPU custom operators in the output. Then time each part with a hardware timer and write down the hand-off cost on your board. Replace the one unsupported operator and repeat.
Chapter 8
Turn speed into energy, and see why the sleeping chip, not the busy one, sets the limit on battery life
A button cell holds a fixed amount of energy. Think of it as a jar of water and the chip as a leaky tap. Two things drain the jar: the burst of work each time the network runs, and the slow drip while the chip waits. Making the burst shorter helps, but only until the drip becomes the bigger leak.
Energy is power multiplied by time. A chip that draws more power for a shorter time may use less energy overall. An engine is efficient when it spends little energy per inference. The best way to save is the habit called race to sleep: finish the work fast, then drop into a deep sleep mode until the next frame. The fraction of time the chip is awake is its duty cycle.
Arm’s 2020 Hot Chips talk compares three setups on one voice assistant workload: a Cortex-M7, a Cortex-M55 with Helium, and a Cortex-M55 with an Ethos-U55. The workload bundles voice activity detection, noise cancellation, two-microphone beamforming, echo cancellation, equalising, mixing, keyword spotting, Opus decoding and speech recognition. Taking the M7 as 1, the slide shows speed to inference at about 6 times for the M55 and 50 times with the U55, and energy efficiency at 7 times and 25 times.
Notice that the energy gain with the NPU (25 times) is smaller than its speed gain (50 times). The NPU draws more power while it runs, so the saving is less than the time saved. Also remember what this is: a vendor figure from simulation, for one mixed workload, not the keyword spotter in this lesson. Use it to learn the shape, then measure your own.
Add the drip. While the chip waits, it still draws a small sleep current for the RAM that holds your data, the clock that wakes it and the microphone path. Call the sleep draw the floor. Let one inference on the M7 cost 1 unit of energy. Run N inferences per second. On an engine with efficiency factor η (1 for the M7, 7 or 25 for the others), the average power is N ÷ η plus the floor F.
average power = N ÷ η + F, battery life gain = (N + F) ÷ (N ÷ η + F)
Work two cases with N = 2 runs per second. With a floor of F = 0.1 units per second, the M7 draws 2.1; the M55 with the U55 draws 2 ÷ 25 + 0.1 = 0.18. The battery lasts 2.1 ÷ 0.18 ≈ 11.7 times longer. Now raise the floor to F = 2: the M7 draws 4; the NPU setup draws 0.08 + 2 = 2.08. The gain is only 1.9 times. The same fast engine, but a leaky sleep state wastes it. Try your own numbers.
Bars show average power in units where one M7 inference costs 1. Teal, purple and warm are the active part; the yellow block is the sleep floor. Drag the rate and the floor.
Energy gains of 1 (Cortex-M7), 7 (Cortex-M55) and 25 (M55 with Ethos-U55) are read from Arm’s Hot Chips 2020 slide for a mixed voice assistant workload, from simulation, so a vendor claim. The inference rate and the sleep floor are your choices and carry no real units.
The lesson for design: first measure the floor. If it is above the active power, no accelerator will save the battery. Cut the floor (turn off unused peripherals, use the deepest sleep mode that keeps RAM, gate clocks) before buying silicon. Our sleep and battery budget lesson covers that side.
The failure mode. Symptom: you moved the network to the NPU and the inference is 10 times faster, but the battery lasts the same time. Measurement: record the average current over a full minute, not during one inference, using a power profiler. Plot current against time. If the baseline between bursts is higher than the bursts averaged, the floor dominates. Fix: reduce the floor first, then reduce how often the network runs (for example, run a tiny always-on detector, and wake the big network only when it fires).
On real hardware. Use a Nordic nRF52840 DK with the Power Profiler Kit II, or the IDD current-measurement jumper on many STM32 Nucleo boards (check the board manual). Record one minute of current with the model running at two rates, 1 per second and 4 per second. Report average current, burst length and the sleep floor, and calculate energy per inference as (average current minus floor) × supply voltage ÷ rate. The next lesson, profile, budget and ship, builds this into a method.
Chapter 9
Keep the numbers, the checklist, the core code and the sources in one place, and carry the idea to the next lesson
A network is a list of operators, each a count of multiply-adds and a count of weight bytes. A Cortex-M4 with the DSP extension multiplies two 16-bit lanes per instruction and pays to widen int8 data. A Cortex-M55 with Helium cuts every 128-bit instruction into 32-bit beats, overlaps loads with multiplies, and reaches 8 int8 MACs per clock. A microNPU such as the Ethos-U55 runs whole stretches of the network from a command stream, reading weights through a read-only flash port and activations through an SRAM port. The Vela compiler splits the network: supported neighbours become one NPU run, everything else stays on the core. The speed you get depends on the weight feed, the start-up cost of each run, the one operator that splits a run, and the SRAM peak. DMA and cache maintenance keep the engine fed with fresh bytes, and the sleep floor sets the limit on battery gain.
| What | Number | Source or model |
|---|---|---|
| SMLAD | 2 signed 16-bit MACs into one 32-bit accumulator | Arm instruction definition; CMSIS-NN paper |
| Helium registers | 8 vector registers of 128 bits, over 150 new instructions | Arm Hot Chips 2020 |
| One beat | 32 bits: one 32-bit MAC or four 8-bit MACs | Arm, “Making Helium” |
| Cortex-M55 rate | 2 clocks per 128-bit vector; 8 int8 MACs per clock | Arm Hot Chips 2020 |
| Cortex-M55 claim | up to 15 times ML and up to 5 times signal processing vs existing Cortex-M | Arm product page (vendor claim) |
| Ethos-U55 sizes | 32, 64, 128 or 256 MACs per clock; 8 or 16-bit activations | Arm Hot Chips 2020; Vela docs |
| Ethos-U55 ports | M0 AXI5 read and write to SRAM; M1 AXI5 read only to flash | Arm Hot Chips 2020 |
| Peak GOPS | 2 × MACs × clock; 64 to 512 GOPS at 1 GHz for 32 to 256 MACs | Derived; launch coverage |
| U55 flash and SRAM speed | Deep Embedded 0.1 and 1.6 GB/s; High End Embedded 0.5 and 4 GB/s | Vela 3.2.0 system configs |
| Voice assistant workload | speed 6 and 50 times, energy 7 and 25 times vs a Cortex-M7 | Arm Hot Chips 2020 (vendor, simulation) |
| Keyword spotting frame | 16 kHz, 40 ms: 640 samples, 1,280 bytes at 16 bits | Arm slide; arithmetic |
| This lesson’s network | 1,488,768 MACs; 14,000 weight bytes; 7.8 ms, 1.9 ms, 195 µs | Illustrative model, labelled |
/* the decision rule behind the partition game: a sketch, not a driver */ bool offload_pays(uint32_t core_clk, /* clocks on the core for this run of operators */ uint32_t npu_compute_clk, /* MACs / (MACs per clock x use) */ uint32_t weight_bytes, float bytes_per_clk, /* flash GB/s divided by clock GHz */ uint32_t handoff_clk) /* program the NPU, take the interrupt */ { uint32_t fetch_clk = (uint32_t)(weight_bytes / bytes_per_clk); uint32_t npu_clk = (npu_compute_clk > fetch_clk ? npu_compute_clk : fetch_clk) + handoff_clk; return npu_clk < core_clk; }
This lesson is the hardware half of the Edge ML track. Lesson 1 runs a network on the core, lesson 2 makes the arithmetic exact, lesson 3 builds the windows and features that feed it, and lesson 5 measures and ships. The wider story of neural engines and their runtimes on larger devices belongs to the planned Physical AI lesson on NPU runtimes. The software side of the same ideas is in MCUNet and TinyEngine, and the DSP side in real-time DSP on a Cortex-M. For a full keyword spotter, see wake word on an MCU.
Opened and read for this lesson:
Not verified here: the Cortex-M55 technical reference manual itself (the 8 MACs per clock figure rests on Arm’s Hot Chips slide and Helium article), and the exact operator list of your Vela version. Check the supported-operators report before you commit a design.
Now press Teach and explain from memory why an NPU can be slower than the core on a bad partition, and what you would change. Then go back to the chip at the top, pick the NPU, flip the custom gate switch and say aloud what moved and why.