Skip to content

v1.6.0

Latest

Choose a tag to compare

@vikramdattu vikramdattu released this 01 Dec 07:22
v1.6.0

Faster kernels on every chip, and fixes for ESP32-P4 before rev v3.

Before you update: convolution and depthwise convolution ask for more scratch on ESP32, ESP32-S3, ESP32-P4 and ESP32-S31. Size the arena from the scratch getters again, or AllocateTensors() can fail. Details are under Changed.

Cycle counts per chip are in docs/performance.md.

Added

  • ESP32: MAC16 kernels for convolution and depthwise convolution, selected by CONFIG_NN_ESP32_MAC16 (default on).
  • ESP32-S3 and ESP32-P4: opt-in dual-core execution for the plain fully connected APIs (#60).
  • ESP32-P4 and ESP32-S31: weight-stationary batched fully connected kernel (#63).

Performance

  • ESP32-S3:
    • convolution: s8 MAC path, faster requant, im2col through the batched 1x1 kernel, and the remaining paths split across both cores;
    • depthwise convolution: int8 kernel for KxK filters with a channel multiplier of 1;
    • fully connected: one-pass s8 kernel with the input offset in the MAC;
    • max pooling: fast paths for 2x2 and 3x3 windows, and row bands.
  • ESP32-P4 and ESP32-S31:
    • convolution and depthwise convolution: faster int8 kernels;
    • 1x1 convolution: the 16-pixel batch is transposed with PIE;
    • max pooling: fast paths for 2x2 and 3x3 windows, and row bands;
    • elementwise add and multiply: vector requant.

Changed

  • ESP32-S3: convolution and depthwise convolution ask for more scratch.
    • Convolution grows with the filter: a 3x3 convolution from 64 to 128 channels on 28x28 needs 57,616 B instead of 39,520 B, and a 1x1 from 960 to 1280 channels on 7x7 needs 55,872 B instead of 39,488 B. The largest scratch of MobileNet grows from 47 KB to 63 KB.
    • Depthwise convolution needs 24 B more per channel: 7x7x2048 3x3 needs 123,136 B instead of 73,760 B. Large maps with few channels need less.
    • Size the arena from the scratch getters again after updating.
  • ESP32-P4 and ESP32-S31: convolution scratch on the im2col path grows by 12 B per output channel.
    • For example, a 3x3 convolution from 8 to 256 channels needs 5,368 B instead of 2,296 B.
    • Layers on the new lanes-as-channels kernel also hold a copy of the filter and about 2 KB more. These are layers with a window row of 2 to 31 bytes, 16 to 48 output channels and at least 256 output pixels, such as a first 3x3 layer on RGB input.
    • Size the arena from esp_nn_get_conv_scratch_size() again after updating.
  • ESP32: convolution and depthwise convolution ask for up to about 16 KB of scratch per layer.
    • person_detection needs 98,780 B of arena instead of 82,308 B.
    • Turn off CONFIG_NN_ESP32_MAC16 to keep the generic kernels and the scratch of 1.5.0.
  • ESP32-P4 and ESP32-S31: depthwise convolution scratch grows by up to about 19 KB per layer, plus about 16 to 20 B per channel.
    • Layers of 8 to 15 channels, for example 48x48x8 with SAME padding: 32 B to 19,344 B.
    • Wide padded maps, for example 1920x1080x32: 128 B to 19,872 B.
    • Many channels, for example 7x7x2048 3x3 SAME: 8,192 B to 41,216 B, and 14x14x1152: 4,608 B to 27,888 B.
    • With the dual-core worker enabled, the worker allocates the same scratch again.
    • Size the arena from esp_nn_get_depthwise_conv_scratch_size() again after updating.
  • The task that runs inference needs more stack: about 1 KB more on ESP32-S3 and 0.5 KB more on ESP32-P4.
  • ESP32-S3: CONFIG_NN_DUAL_CORE_WORKER_STACK_SIZE is at least 3072, as the worker peaks at about 2.3 KB. Values of 2048 to 3071 in an sdkconfig no longer apply.
  • ESP32-P4 and ESP32-S31: batched fully connected takes the 1x1 convolution path from a batch of 16. With the dual-core worker active, it takes it from a batch of 4 when there are at least 32 outputs.

Fixed

  • ESP32-P4 before rev v3 keeps only the low 12 bits of a hardware loop count. These ops returned wrong results since 1.3.0:

    • mean over 4096 or more positions;
    • softmax on rows of 65552 or more;
    • average pooling with a filter width of 4096 or more;
    • max pooling with a filter width of 4096 or more on 16 or more channels.

    This affects ESP32-P4 chips before rev v3: builds on ESP-IDF v5.3 and v5.4, and builds on v5.5 or later with CONFIG_ESP32P4_SELECTS_REV_LESS_V3.

  • Activation limits outside int8 now give the reference results, for callers that pass them directly (TensorFlow Lite Micro never does):

    • ESP32-S3: elementwise multiply;
    • ESP32-P4 and ESP32-S31: max pooling.
  • Softmax: no signed shifts into the sign bit (#55).

  • ESP32-S3: elementwise add with aligned inputs and an output that is not 8-byte aligned wrote the output up to 7 bytes early, over the bytes before it (#73).

CI

  • The emulator tests run on the latest esp-emu, and cover ESP32-S3.

Thanks to James Lavrenz (@jameslavrenz), Alix Anneraud (@AlixANNERAUD), and Léa Guechoum (@Learistocats), whose multiply sweep test is from #64 and who fixed the ESP32-S3 add in #73.