embedded-nn
A pure Rust, #![no_std] neural network inference library for microcontrollers and embedded targets, ported from and inspired by ARM's CMSIS-NN and TensorFlow Lite Micro.
Features
#![no_std]Bare-Metal Support: Built for bare-metal targets (ARM Cortex-M, RISC-V, ESP32, etc.) with zero required heap allocations (alloc).- Target SIMD Hooks: Vectorized 4-way and 8-way dot-product abstractions (
vec_dot_s8,vec_dot_s16) optimized for compiler auto-vectorization and hardware SIMD acceleration. - Quantization Support:
int8(s8) andint16(s16) per-tensor and per-channel fixed-point quantization.int4(s4) 4-bit sub-byte quantization (packed nibbles for sub-byte weight compression).
- Recurrent Operators: Unidirectional
LSTMcell (lstm_step_s8_s16) andSVDF(Singular Value Decomposition Filter) layer. - Float Fallback Operations: IEEE-754
f16half-precision conversions (f16_to_f32,f32_to_f16),f32convolution, dense, and softmax layers. - Core Neural Operators:
- Convolution: 2D Conv (
s8,s4,f32), 1x1 Fast Conv, Depthwise Conv. - Dense / Fully Connected: Matrix multiplication (
s8,s16,s4,f32). - Activations: ReLU, ReLU6, LeakyReLU, Sigmoid, Tanh.
- Pooling: Max Pooling 2D, Average Pooling 2D (
s8,s16). - Softmax: Fixed-point exponential Softmax (
s8,s16) & float Softmax (f32). - Utilities: Depthwise concatenation, Padding, Transposition, Reshaping.
- Convolution: 2D Conv (
Quick Example: 4-Bit Sub-Byte (s4) Fully Connected Layer
use ;
Module Overview
| Module | Description |
|---|---|
types |
Tensor dimensions (Dims), kernel shapes (Tile), quantization parameters, layer config structs. |
support |
Requantization math (requantize, doubling_high_mult_no_sat, divide_by_power_of_two). |
simd |
Vectorized 4-way/8-way dot product routines (vec_dot_s8, vec_dot_s16). |
subbyte |
4-bit (s4) sub-byte packing/unpacking and quantized layers (fully_connected_s4, convolve_s4). |
recurrent |
Recurrent neural network layers (lstm_step_s8_s16, svdf_s8). |
float_ops |
IEEE-754 f16 half-precision conversions and f32 fallback operations (convolve_f32, softmax_f32). |
activations |
ReLU, ReLU6, LeakyReLU, Sigmoid, Tanh. |
basic_math |
Elementwise Add, Subtract, Multiply. |
convolution |
2D Convolution, Depthwise Convolution (per-tensor & per-channel). |
fully_connected |
Dense / Linear layer (per-tensor & per-channel). |
pooling |
Max Pool 2D, Average Pool 2D. |
softmax |
Fixed-point exponential Softmax. |
concat |
Tensor depthwise concatenation. |
pad |
Tensor padding. |
transpose |
Matrix and spatial transposition. |
reshape |
Tensor reshaping. |
License
The contents of this repository are dual-licensed under the MIT OR Apache 2.0
License. That means you can choose either the MIT license or the Apache 2.0
license when you re-use this code. See LICENSE-MIT or
LICENSE-APACHE for more information on each specific
license.