🛠 Inference IA accélérée par les instructions vectorielles

ESP32-S3 · avance · Schéma : IMG-esp32-s3-avance-2-esp32-s3-inference-ia-vectorielle.svg — Puce ESP32-S3 avec son double cœur LX7 et ses extensions vectorielles, un petit réseau de neurones en couches traversant la puce, chronomètre symbolisant le gain ESP-NN face à une puce sans vectoriel.

Objectives

Understand what the LX7 vector instructions (absent in the ESP32 and S2) bring to int8 quantized neural network inference: the ESP-NN (layers) and ESP-DSP (signal) libraries exploit them, enabling the ESP32-S3 to run ESP-WHO (face detection) or ESP-Skainet (offline voice recognition). You will measure the gain yourself with a fully connected layer computed by esp_nn_fully_connected_s8, the flagship primitive of ESP-NN.

Hardware

Full Code

// Couche fully-connected int8 acceleree (ESP-NN, cote Arduino via esp32 core)
// Outils -> Board: "ESP32S3 Dev Module" ; ajouter "esp_nn" aux includes paths
#include "esp_nn.h"

#define ENTREES 64
#define SORTIES 8

// Poids et biases quantifies int8 (ici des valeurs demo)
static int8_t  poids[SORTIES][ENTREES];
static int32_t biais[SORTIES];
static int8_t  entree[ENTREES];
static int8_t  sortie[SORTIES];

void setup {
  Serial.begin(115200);
  for (int i = 0; i < SORTIES; i++) {
    biais[i] = 0;
    for (int j = 0; j < ENTREES; j++)
      poids[i][j] = (int8_t)((i * 7 + j * 13) % 251 - 125);
  }
  for (int j = 0; j < ENTREES; j++) entree[j] = (int8_t)(j % 127);

  setCpuFrequencyMhz(240);
  dl_nn_version;   // version d'ESP-NN liee

  uint32_t t0 = micros;
  for (int k = 0; k < 1000; k++) {
    esp_nn_fully_connected_s8(
      entree, ENTREES, 0,            // activations, taille, zero-point
      poids, SORTIES, 0,             // poids, sortie, zero-point poids
      biais, 1033, 12,               // biais, mult, shift (quantification)
      sortie, -128, 127);            // tampon sortie, plage int8
  }
  uint32_t t1 = micros;
  Serial.printf("1000 FC %dx8 : %lu us (ESP-NN vectoriel)\n",
                ENTREES, (unsigned long)(t1 - t0));
  Serial.printf("sortie[0] = %d\n", sortie[0]);
}

void loop { delay(1000); }

Expected Verification

The console displays the ESP-NN version followed by the time taken for one thousand 64×8 int8 layers — on the order of a few hundred microseconds on a core running at 240 MHz, a throughput that allows audio or sensor models to perform several dozen inferences per second. Comparing this with a hand-written reference loop (without esp_nn), the visible difference demonstrates the effect of the LX7 vector instructions. For a real-world case, use TensorFlow Lite for Microcontrollers with the ESP-NN delegate, or directly ESP-WHO/ESP-Skainet.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials