emlearn / emlearn-micropython

Efficient Machine Learning engine for MicroPython
83 stars 13 forks source link

Most modules do not work on Cortex M0 / RP2040 - size limitation #14

Closed jonnor closed 1 month ago

jonnor commented 4 months ago

RP2040 and other Cortex M0/M0+ devices (ARCH=armv6m) only support ARM Thumb (not Thumb 2) instruction set. As of MicroPython 1.23, the linker for .mpy files only supports jumps that are under 11 bits. This limits module sizes to around 2kB maximum.

Most of the emlearn-micropython modules are slightly larger than 2kB on armv6m. The module sizes are a bit larger than some other architectures, since this architecture does not have floating point hardware, and we need to include some soft-float support.

At the moment, this is blocking most practical uses on Cortex M0.

jonnor commented 4 months ago

I tried implementing support for larger jumps in https://github.com/micropython/micropython/pull/12241/files However the first iteration was not correct.

jonnor commented 1 month ago

Has now been fixed upstream in https://github.com/micropython/micropython/pull/15812 - scheduled for release with MicroPython 1.24

jonnor commented 1 month ago

I have backported this fix to https://github.com/jonnor/micropython/tree/emlearn-micropython-v1.23-2 which is now used in master. I was able to run the xor_trees example (above 2kB) on an RP2040, so this appears to be fixed now.