ulab, or what you will - numpy on bare metal

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: ulab, or what you will - numpy on bare metal

Post by rcolistete » Mon Aug 03, 2020 6:39 am

rcolistete wrote:
Mon Jul 27, 2020 1:54 pm
25 new MicroPython firmwares with ulab v0.54.0 (released in July 24 2020) were published :
- 11 with combinations of sp, dp, sp & _thread, dp & _thread, sp & network, dp & network for Pyboard v1.1/Lite v1.0;
- 12 with combinations of sp, dp, sp & _thread, dp & _thread for Pyboard D SF2/SF3/SF6;
- 2 for ESP8266 >= 2 MB and 1 MB of flash (with reduced filesystem), using only sp, without threads, due to limitations of MicroPython on ESP8266.
16 new MicroPython firmwares for ESP32 with ulab v0.54.0 were published :
* 16 with combinations of sp, dp, ESP-IDF v3.3, ESP-IDF v4.0 for 4 types of ESP32 boards.
* also announced in topic "ESP32 firmwares with single/double precision and ulab module".
Last edited by rcolistete on Mon Aug 03, 2020 2:51 pm, edited 1 time in total.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: ulab, or what you will - numpy on bare metal

Post by rcolistete » Mon Aug 03, 2020 6:54 am

ulab v0.54.1 has one important fix (vectors with lenght > 65535) when using MicroPython boards with lot of RAM (like ESP32 PSRAM). I'll publish MicroPython firmwares with ulab v0.54.1 during this week.

With the ulab v0.54.0 included in MicroPython firmwares for Pyboard's, ESP8266 and ESP32, it is now possible to benchmark these boards, so that an ulab benchmark will also be published in this week.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

v923z
Posts: 168
Joined: Mon Dec 28, 2015 6:19 pm

Re: ulab, or what you will - numpy on bare metal

Post by v923z » Mon Aug 03, 2020 5:30 pm

rcolistete wrote:
Mon Aug 03, 2020 6:54 am
ulab v0.54.1 has one important fix (vectors with lenght > 65535) when using MicroPython boards with lot of RAM (like ESP32 PSRAM). I'll publish MicroPython firmwares with ulab v0.54.1 during this week.
There is actually one issue with this. I haven't though about this before, but here it is: argsort returns an array with the positions in the array. As soon as you have length > 65535, the array must be able to hold this, which means that the array must support the size_t type. That opens up a whole can of worms.

The thing is, with computers you don't have this problem, because it doesn't matter, whether a computer has 200 MB of RAM, or 200 GB, size_t will fit in both. But on microcontrollers, it makes a huge difference, whether you have 100 kB, or 2 MB, and adding new types significantly increases the required flash and RAM space. See e.g. here: https://github.com/v923z/micropython-ul ... ay.c#L1074

I am not sure what the proper course of action would be, but I am actually leaning towards imposing 65535 for the length of the array. Another option (I have to look into that) could be to have a pre-compiler switch to decide how many types you want to support. That could become a bit messy, though, while you also have to stipulate your upcasting rules somewhere. If you can come up with a reasonable table for the various cases, I could try to incorporate it: https://micropython-ulab.readthedocs.io ... #upcasting.

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: ulab, or what you will - numpy on bare metal

Post by rcolistete » Mon Aug 03, 2020 5:45 pm

I think it is better (less limitation) to document 'argsort' explaining that it deals with arrays with size up to 65535, due to the internal number types of ulab (uint16 is the maximum integer).

Wth many MicroPython boards with RAM >= 256 kB, it is useful to have ulab able to define a float vector of, e. g., 70,000 values, taking 280 kB of RAM in FP32, and apply operators and functions. MicroPython boards with more RAM :
- Pyboard D SF6, aprox. 389 kB of free RAM in MicroPython;
- ESP32 PSRAM (it became cheaper and very common in the form of generic boards, TinyPICO board, in Pycom boards, etc), 4,000 kB of free RAM in MicroPython v1.12;
- MAix Bit and other boards with K210 MCU, 2-8 MB of free RAM in MicroPython, depending on the firmware;
- Teensy 4.0/4.1, 729 kB of free RAM in CircuitPython.
Last edited by rcolistete on Mon Aug 03, 2020 5:47 pm, edited 1 time in total.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: ulab, or what you will - numpy on bare metal

Post by rcolistete » Mon Aug 03, 2020 5:46 pm

v923z wrote:
Mon Jul 27, 2020 5:44 pm
Roberto, thanks for the hard work, it is really exciting! I have added a link to your repository in the readme: https://github.com/v923z/micropython-ul ... /README.md
Thanks for citing the links of my GitLab repository in ulab GitHub. Now there is a new link, for ESP32 firmwares with ulab.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: ulab, or what you will - numpy on bare metal

Post by rcolistete » Mon Aug 03, 2020 5:50 pm

Motivation to keep ulab powerful/not limited : some initial benchmarks (I'll publish after finishing) show that ulab on some MCU boards is competitive with NumPy on Raspberry Pi. Raspberry Pi Zero (W) is even slower 8-)
Last edited by rcolistete on Mon Aug 03, 2020 5:54 pm, edited 1 time in total.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

v923z
Posts: 168
Joined: Mon Dec 28, 2015 6:19 pm

Re: ulab, or what you will - numpy on bare metal

Post by v923z » Mon Aug 03, 2020 5:51 pm

rcolistete wrote:
Mon Aug 03, 2020 5:45 pm
I think it is better (less limitation) to document 'argsort' explaining that it deals with arrays with size up to 65535, due to the internal number types of ulab (uint16 is the maximum integer).
OK, so if the length > 65535, we simply bail out with a ValueError? Could be done.

v923z
Posts: 168
Joined: Mon Dec 28, 2015 6:19 pm

Re: ulab, or what you will - numpy on bare metal

Post by v923z » Mon Aug 03, 2020 5:52 pm

rcolistete wrote:
Mon Aug 03, 2020 5:50 pm
Motivation to keep ulab powerful/not limited : some initial benchmarks show that ulab on some MCU boards is competitive with NumPy on Raspberry Pi. Raspberry Pi Zero (W) is even slower.
Well, that is surprising. But it could be related to the fact that ulab has absolutely no python facade. In numpy, a lot of things actually happen in python, and that definitely doesn't help speed.

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: ulab, or what you will - numpy on bare metal

Post by rcolistete » Mon Aug 03, 2020 5:57 pm

v923z wrote:
Mon Aug 03, 2020 5:52 pm
rcolistete wrote:
Mon Aug 03, 2020 5:50 pm
Motivation to keep ulab powerful/not limited : some initial benchmarks show that ulab on some MCU boards is competitive with NumPy on Raspberry Pi. Raspberry Pi Zero (W) is even slower.
Well, that is surprising. But it could be related to the fact that ulab has absolutely no python facade. In numpy, a lot of things actually happen in python, and that definitely doesn't help speed.
+ :
- there are 'super-microcontrollers' since 2019, like the K210 (MAix BIT, etc), OpenMV Cam H7 (Plus), Teensy 4.x, Pyboard D SF6, etc.
- some MCU boards have FPU with FP64 support.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: ulab, or what you will - numpy on bare metal

Post by rcolistete » Mon Aug 03, 2020 5:59 pm

v923z wrote:
Mon Aug 03, 2020 5:51 pm
rcolistete wrote:
Mon Aug 03, 2020 5:45 pm
I think it is better (less limitation) to document 'argsort' explaining that it deals with arrays with size up to 65535, due to the internal number types of ulab (uint16 is the maximum integer).
OK, so if the length > 65535, we simply bail out with a ValueError? Could be done.
Yeah, error message and warning in the docs.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

Post Reply