Awesome
ulab Samples
Links, examples, benchmarks, etc, about ulab module, a NumPy-like array manipulation library for MicroPython and CircuitPython
Authors : Eduardo Destefani Stefanato, Pedro Henrique Robadel da Silva Camâra, Roberto Colistete Jr, Thiago Ferreira Santos
Last update : August 12th 2020
Links about ulab
- official repository 'v923z/micropython-ulab';
- official documentation 'micropython-ulab’s documentation';
- Jupyter Notebook 'ulab Manual, with technical details of the implementation';
- Adafruit tutorial, 'ulab: Crunch Numbers fast in CircuitPython. Use numpy-like commands to process data quickly';
- MicroPython Forum topic, 'ulab, or what you will - numpy on bare metal';
- news and articles about ulab :
- vídeo It's FFT Tuesday! Testing out mic FFT on CircuitPython - Adafruit Industries YouTube channel, 02/2020;
- NUMPY COMES TO MICRO PYTHON - Hackaday, 29/10/2019;
- HackSpace Magazine Issue 30 – CircuitPython ulab - Adafruit Blog, 24/04/2020;
- Zoltán Vörös' ulab Brings NumPy-Style Fast Math to MicroPython in Just 25kB of Compiled Code" - Hackster, 11/2019.
Firmwares and MicroPython boards adopting ulab
- CircuitPython firmware >= v5.1.0 (02/04/2020), ulab in CircuitPython isn't included on boards with small flash memory.
CircuitPython 5.1.0 Released! - Adafruit Blog, 02/04/2020.
Official CircuitPython documentação about ulab; - OpenMV Cam firmware >= v3.5.0 (20191104);
- MicroPython for K210 Lobo firmware >= v202002;
- MaixPy >= v0.5.0 (28/12/2019).
Firmwares with ulab included, built by the community
- "Firmwares for MicroPython on Pyboard v1.1/Lite v1.0/D SF2/D SF3/D SF6 - rcolistete GitLab", with single precision (SP/FP32) and double precision (DP/FP64), without and with threads;
- "Firmwares for MicroPython on ESP8266 - rcolistete GitLab", with single precision (SP/FP32), without threads;
- "Firmwares for MicroPython on ESP32 - rcolistete GitLab", with single precision (SP/FP32) and double precision (DP/FP64), with threads;
- "Firmwares for MicroPython on Pycom boards", without and with PyBytes, with single precision (SP/FP32) and double precision (DP/FP64), with threads.
Benchmark of FFT with 1024 points
ulab.fft.fft()
calculation time (of a, b = fft.fft(y)
so it includes the time to transfer the result) for 1024 points with single precision (FP32) and double precision (FP64) for float point numbers, using ulab v0.54.0 & MicroPython v1.12 (if not cited) :
Board | Clock (MHz) | Time (ms) in FP32 | Time (ms) in FP64 |
---|---|---|---|
Pyboard Lite v1.0 | 96 (default) | 3.572 | 53.39 |
Pyboard v1.1 | 168 (default) | 2.0382 | 32.076 |
Pyboard v1.1 CPy 6.0.0a2 | 168 (default) | 2.253 | - |
Pyboard D SF2 | 216 (maximum) | 1.039 | 17.660 |
Pyboard D SF6 | 216 (maximum) | 1.001 | 2.041 |
ESP8266 EX (WeMos D1 Mini) | 160 (maximum) | 28.874 | - |
ESP32-PICO-D4 rev1 (M5StickC) | 240 (maximum) | 1.635 | 20.97 |
ESP32 D0WDQ6 rev0 (LoLin32) | 240 (maximum) | 1.53 | 20.95 |
ESP32 PSRAM D0WDQ6 rev1 (LoLin32 Pro) | 240 (maximum) | 2.30 | 23.18 |
ESP32 D0WDQ6 rev0 (LoPy v1) | 160 (default) | 2.38 | 32.877 |
ESP32 PSRAM D0WDQ6 rev1 (LoPy4) | 160 (default) | 3.00 | 34.5 |
MAixBiT - Lobo fw v202002 | 400 (default) | - | 1.030 |
MAixBiT - MaixPy v0.5.0 | 600 (maximum) | 1.45 | - |
OpenMV M7 - fw v3.6.7 | 216 (default) | 0.780 | - |
OpenMV H7 - fw v3.6.7 | 480 (default) | 0.397 | - |
OpenMV H7 CPy 6.0.0a2 | 480 (default) | 1.99 | - |
ItsyBitsy M4 CPy 6.0.0a2 | 120 (default) | 3.1 | - |
Adafruit CLUE CPy 6.0.0a2 | 64 (default) | 7.19 | - |
Teensy 4.0 CPy 6.0.0a2 | 600 (default) | 1.84 | - |
Observations
- firmwares with ulab included on Pyboard's, ESP8266, ESP32 and Pycom boards, from "MicroPython Firmwares - rcolistete GitLab";
- CircuitPython (CPy) 6.0.0a2 using ulab v0.51.1, only with single precision (FP32);
- MAixBiT - Lobo fw v202002 using ulab v0.37.0, only with double precision (FP64);
- MAixBiT - MaixPy v0.5.0 using ulab v0.26.2, only with single precision (FP32);
- OpenMV fw v3.6.7 using ulab v0.50.2, only with single precision (FP32).
Analyses
- OpenMV H7 with ARM Cortex-M7 STM32H743VI has double precision (FP64) hardware support, but the OpenMV firmware only supports single precision (FP32), is the winner in single precision (FP32) FFT. Notice that CircuitPython on OpenMV H7 is not well optimised;
- Sipeed MAix BiT with RISC-V 64bit Kendryte K210 has double precision (FP64) hardware support and is the winner in double precision (FP64) FFT when using the MicroPython for K210 Lobo firmware (supporting only FP64). While MaixPy firmware is for single precision (FP32), even with overclocking it is slower, so not well optimised;
- OpenMV M7 is old as it was released in January 2017, but with ARM Cortex-M7 STM32F765VI it has FP64 hardware support, while OpenMV firmware only supporting single precision (FP32), it is in the 2nd place in FP32 FFT;
- Pyboard D SF6 with ARM Cortex-M7 STM32F767VIT has double precision (FP64) hardware support, it is in 2nd place in FP64 FFT and 3rd place in FP32 FFT;
- Pyboard D SF2 with ARM Cortex-M7 STM32F722IEK, is a lot cheaper than Pyboard D SF6 but has only FP32 hardware support, in the 4th place and almost the same performance of Pyboard D SF6 in FP32 FFT, and in 3rd place in FP64 FFT;
- ESP32 boards with higher (240 MHz) clock and without PSRAM have good performance in FP32 FFT and good price (>= US$2), but not in FP64 FFT because ESP32 microcontrollers don't have FP64 hardware support. Notice that PSRAM performance is about 50% worse;
- Teensy 4.0 with ARM Cortex-M7 NXP iMX RT1062 has double precision (FP64) hardware support, higher possible clocks (up to 1008 MHz with heatsink), but CircuitPython only supports FP32 and it is currently not well optimised. But Teensy 4.0 has great performance potential if the CircuitPython/MicroPython firmwares improve;
- Pyboard v1.1, while it is the oldest and 1st MicroPython board, announced in 2013 and released in 2014, its ARM Cortex-M4F STM32F405RG with only FP32 hardware support still has good performance in FP32 FFT. Its CircuitPython firmware is also well optimised;
- CircuitPython on Adafruit ItsyBitsy M4 Express and Adafruit CLUE nRF52840 Express seems well optimised, supporting FP32 FFT;
- ESP8266 is the last in FP32 FFT performance but is the cheapest microcontroller supporting ulab (FP32 FFT), as an ESP8266 ESP-01S costs about US$1.
It would be very useful to have more MicroPython/CircuitPython firmwares supporting both single precision (FP32) and double precision (FP64), including for all the 5 boards above with double precision (FP64) hardware support.