Skip to content

Commit b897b19

Browse files
authored
Fix the KeywordSpotting arena and reconcile it with the README (pytorch#21788)
Fix the KeywordSpotting arena and reconcile it with the README The sketch shipped a 28 KB arena, which fails on hardware at load_method: ET| E [ET:memory_allocator.h:105] Memory allocation failed: 180B requested (adjusted for alignment), 4B available FAIL: method 0x21 The README already documented that 28 KB fails, and its measured table (46,068 bytes of RAM, 10/10 keywords) corresponds to a 40 KB arena. The sketch and the documentation were out of sync; the documentation was the correct one. Set the arena to 40 KB. Verified on an Arduino UNO Q: RAM comes out at 46,068 bytes (35%), exactly reproducing the README's figure, and mfcc_yes.h scores "yes" at 8.95 against -10.80 to -0.46 for the other eleven classes. Not simply raising it further, which was my first instinct and was wrong. Zephyr reserves a 32 KB stack and a 32 KB heap out of the board's 128 KB, so a 64 KB arena pushes globals to 70,644 bytes and overlaps that reservation. It ran and printed the right answer when I tried it, which is exactly the problem: arduino-cli reports RAM against the full 131,072 bytes, knows nothing about Zephyr's reservations, and calls that build a comfortable 53%. The arena is bounded on both sides, so the README section now gives the band as a table rather than describing a floor. Authored with assistance from Claude Code.
1 parent d92a619 commit b897b19

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎examples/arduino/README.md‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,15 @@ RAM is the binding constraint, not flash. Zephyr reserves 32 KB of main stack
497497
and a 32 KB heap out of 128 KB before the sketch gets any, and the arena the
498498
sketch hands to `MemoryManager` comes out of what remains. KeywordSpotting's
499499
DS-CNN plans 16 KB of buffers but needs considerably more for the method's own
500-
structures: a 28 KB arena fails `load_method` with `MemoryAllocationFailed`
501-
(0x21), and a 64 KB one loads but then fails `execute` with `InvalidProgram`
502-
(0x23), which is memory being overrun rather than a malformed program.
500+
structures, which leaves a usable band rather than a floor to clear:
501+
502+
| Arena | Result |
503+
|-------|--------|
504+
| 28 KB | `load_method` fails, `MemoryAllocationFailed` (0x21), 180 B short |
505+
| 40 KB | Works. 46,068 bytes of globals (35%) — what the table above measures |
506+
| 64 KB | Pushes globals to 70,644 and past Zephyr's reservation; may appear to run, but it is overrunning memory |
507+
508+
The sketch ships 40 KB for that reason. Growing it is not automatically safer:
509+
`arduino-cli` reports RAM against the full 131,072 bytes and knows nothing about
510+
Zephyr's stack and heap, so a 64 KB arena still reports a comfortable 53% while
511+
already overlapping reserved memory. Read the arena as bounded on both sides.

‎examples/arduino/examples/KeywordSpotting/KeywordSpotting.ino‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ static const char* kLabels[] = {
5454
"silence", "unknown", "yes", "no", "up", "down",
5555
"left", "right", "on", "off", "stop", "go"};
5656

57-
alignas(16) static uint8_t method_pool[28 * 1024];
57+
// 28 KB fails load_method with MemoryAllocationFailed (0x21), and going the
58+
// other way is not free: Zephyr takes a 32 KB stack and a 32 KB heap out of the
59+
// board's 128 KB before the sketch sees any, so an arena large enough to push
60+
// globals past ~64 KB overruns that reservation. arduino-cli's RAM figure does
61+
// not account for it and will look comfortable either way. See "Memory" in
62+
// ../../README.md.
63+
alignas(16) static uint8_t method_pool[40 * 1024];
5864

5965
// ExecuTorch logs go to a weak hook so the library does not depend on Serial.
6066
// Without this the runtime's own diagnostics -- allocation failures, operator

0 commit comments

Comments
 (0)