Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.ipynb -diff
11 changes: 6 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
repository: jonnor/micropython
path: micropython
ref: v1.25.0-armv6m-abs-relocations
ref: v1.26.1-emlearn
- name: Install Python dependencies
run: pip install -r requirements.txt
- name: Setup MicroPython X86
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
with:
repository: jonnor/micropython
path: micropython
ref: v1.25.0-armv6m-abs-relocations
ref: v1.26.1-emlearn
- name: Install Python dependencies
run: pip install -r requirements.txt
- name: Setup MicroPython ARM
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
with:
repository: jonnor/micropython
path: micropython
ref: v1.25.0-armv6m-abs-relocations
ref: v1.26.1-emlearn
- name: Install Python dependencies
run: pip install -r requirements.txt

Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
with:
repository: jonnor/micropython
path: micropython
ref: v1.25.0-armv6m-abs-relocations
ref: v1.26.1-emlearn
- name: Install Python dependencies
run: pip install -r requirements.txt

Expand Down Expand Up @@ -195,7 +195,7 @@ jobs:
with:
repository: jonnor/micropython
path: micropython
ref: v1.25.0-armv6m-abs-relocations
ref: v1.26.1-emlearn
- name: Install Python dependencies
run: pip install -r requirements.txt
- name: Setup MicroPython X86
Expand All @@ -210,6 +210,7 @@ jobs:
mv ./dist/ports/unix/micropython ./dist/ports/macos/micropython
- name: Build .mpy modules and run tests Unix/x64
# natmod build with linking seems broken on Mac OS, exception in mpy_ld.py, ELFError, magic number does not match
# https://github.com/micropython/micropython/issues/5500
run: echo SKIP make check ARCH=x64 V=1

- name: Archive dist artifacts
Expand Down
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@ PORT_DIST_DIR=./dist/ports/$(PORT)/$(BOARD)
UNIX_MICROPYTHON = ./dist/ports/unix/micropython

$(MODULES_PATH)/emlearn_trees.mpy:
make -C src/emlearn_trees/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
make -C src/emlearn_trees/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) CFLAGS_EXTRA=${CFLAGS_EXTRA} V=1 clean dist

$(MODULES_PATH)/emlearn_neighbors.mpy:
make -C src/emlearn_neighbors/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
make -C src/emlearn_neighbors/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) CFLAGS_EXTRA=${CFLAGS_EXTRA} V=1 clean dist

$(MODULES_PATH)/emlearn_iir.mpy:
make -C src/emlearn_iir/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
make -C src/emlearn_iir/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) CFLAGS_EXTRA=${CFLAGS_EXTRA} V=1 clean dist

$(MODULES_PATH)/emlearn_fft.mpy:
make -C src/emlearn_fft/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
make -C src/emlearn_fft/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) CFLAGS_EXTRA=${CFLAGS_EXTRA} V=1 clean dist

$(MODULES_PATH)/emlearn_cnn_int8.mpy:
make -C src/tinymaix_cnn/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 CONFIG=int8 clean dist
make -C src/tinymaix_cnn/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) CFLAGS_EXTRA=${CFLAGS_EXTRA} V=1 CONFIG=int8 clean dist

$(MODULES_PATH)/emlearn_cnn_fp32.mpy:
make -C src/tinymaix_cnn/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 CONFIG=fp32 clean dist
make -C src/tinymaix_cnn/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) CFLAGS_EXTRA=${CFLAGS_EXTRA} V=1 CONFIG=fp32 clean dist

$(MODULES_PATH)/emlearn_kmeans.mpy:
make -C src/emlearn_kmeans/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
make -C src/emlearn_kmeans/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) CFLAGS_EXTRA=${CFLAGS_EXTRA} V=1 clean dist

$(MODULES_PATH)/emlearn_iir_q15.mpy:
make -C src/emlearn_iir_q15/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
make -C src/emlearn_iir_q15/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) CFLAGS_EXTRA=${CFLAGS_EXTRA} V=1 clean dist

$(MODULES_PATH)/emlearn_arrayutils.mpy:
make -C src/emlearn_arrayutils/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
make -C src/emlearn_arrayutils/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) CFLAGS_EXTRA=${CFLAGS_EXTRA} V=1 clean dist

$(MODULES_PATH)/emlearn_linreg.mpy:
make -C src/emlearn_linreg/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
make -C src/emlearn_linreg/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) CFLAGS_EXTRA=${CFLAGS_EXTRA} V=1 clean dist

emlearn_trees.results: $(MODULES_PATH)/emlearn_trees.mpy
MICROPYPATH=$(MODULES_PATH) $(MICROPYTHON_BIN) tests/test_trees.py
Expand Down
21 changes: 18 additions & 3 deletions docs/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You will need to have **Python 3.10+ or later** already installed.
We assume that **micropython** git repository available.
It is assumed to be at the same level as this repository in the file system.
If using another location, adjust `MPY_DIR` accordingly.
You should be using MicroPython 1.25 (or newer).
You should be using MicroPython 1.26 (or newer).

You should build and install the [MicroPython Unix port](https://github.com/micropython/micropython/blob/master/ports/unix/README.md) to run/test on PC (`micropython` executable).

Expand Down Expand Up @@ -50,12 +50,27 @@ Install Python packages
pip install -r requirements.txt
```

#### Run tests on PC using external modules build

#### Run tests on PC
This runs tests by building the modules as external C modules,
which bakes them into the firmware image/executable.

NOTE: Tested on Linux and Mac OS. Not tested on Windows Subsystem for Linux (WSL).

```
make check_unix
```

#### Run tests on PC using dynamic native modules

This runs tests by building as dynamic native modules (.mpy files),
and the .mpy files are then loaded at runtime.

NOTE: This does not work on Mac OS. Due to https://github.com/micropython/micropython/issues/5500

NOTE: Requires `micropython` program to installed (MicroPython Unix port).

To build and run tests on host
To build and run tests of dynamic native modules on host
```
make check
```
Expand Down
2 changes: 2 additions & 0 deletions docs/native_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ The following is an overview of .mpy ABI version for MicroPython releases.
+---------------------+---------------+
| MicroPython version | .mpy version |
+=====================+===============+
| 1.26.x | 6.3 |
+---------------------+---------------+
| 1.25.x | 6.3 |
+---------------------+---------------+
| 1.24.x | 6.3 |
Expand Down
3 changes: 2 additions & 1 deletion docs/support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ There are no long-term-support or bugfix versions of emlearn-micropython, at thi
================== ======================
MicroPython emlearn-micropython
================== ======================
1.25.x master
1.26.x master
1.26.x 0.9.x
1.25.x 0.8.x
1.24.x 0.7.0
1.23.x 0.6.0
Expand Down
30 changes: 30 additions & 0 deletions src/dynmodule.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

## Common parts used for each module

# Location of top-level MicroPython directory
MPY_DIR = ../../micropython

# Architecture to build for (x86, x64, armv6m, armv7m, xtensa, xtensawin)
ARCH = x64

# The ABI version for .mpy files
MPY_ABI_VERSION := 6.3

# enable linking of libm etc
LINK_RUNTIME=1


DIST_DIR := ../../dist/$(ARCH)_$(MPY_ABI_VERSION)

# Releases
DIST_FILE = $(DIST_DIR)/$(MOD).mpy
$(DIST_DIR):
mkdir -p $@

$(DIST_FILE): $(MOD).mpy $(DIST_DIR)
cp $< $@

# Include to get the rules for compiling and linking the module
include $(MPY_DIR)/py/dynruntime.mk

dist: $(DIST_FILE)
28 changes: 1 addition & 27 deletions src/emlearn_arrayutils/Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
# Location of top-level MicroPython directory
MPY_DIR = ../../micropython

# Architecture to build for (x86, x64, armv6m, armv7m, xtensa, xtensawin)
ARCH = x64

# The ABI version for .mpy files
MPY_ABI_VERSION := 6.3

DIST_DIR := ../../dist/$(ARCH)_$(MPY_ABI_VERSION)

# enable linking of libm etc
LINK_RUNTIME=1

# Name of module
MOD = emlearn_arrayutils

# Source files (.c or .py)
SRC = modarrayutils.c

# Releases
DIST_FILE = $(DIST_DIR)/$(MOD).mpy
$(DIST_DIR):
mkdir -p $@

$(DIST_FILE): $(MOD).mpy $(DIST_DIR)
cp $< $@

# Include to get the rules for compiling and linking the module
include $(MPY_DIR)/py/dynruntime.mk

CFLAGS += -I$(CMSIS_DSP_DIR)/Include

dist: $(DIST_FILE)
include ../dynmodule.mk
26 changes: 2 additions & 24 deletions src/emlearn_trees/Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
# Location of top-level MicroPython directory
MPY_DIR = ../../micropython

# Architecture to build for (x86, x64, armv6m, armv7m, xtensa, xtensawin)
ARCH = x64

# The ABI version for .mpy files
MPY_ABI_VERSION := 6.3

# Location of emlearn library
EMLEARN_DIR := $(shell python3 -c "import emlearn; print(emlearn.includedir)")

# enable linking of libm etc
LINK_RUNTIME=1

DIST_DIR := ../../dist/$(ARCH)_$(MPY_ABI_VERSION)

# Name of module
MOD = emlearn_trees

# Source files (.c or .py)
SRC = trees.c emlearn_trees.py

# Releases
DIST_FILE = $(DIST_DIR)/$(MOD).mpy
$(DIST_DIR):
mkdir -p $@

$(DIST_FILE): $(MOD).mpy $(DIST_DIR)
cp $< $@

# Include to get the rules for compiling and linking the module
include $(MPY_DIR)/py/dynruntime.mk
include ../dynmodule.mk

# Must come after dynmodule include
CFLAGS += -I$(EMLEARN_DIR) -Wno-unused-function

dist: $(DIST_FILE)
Loading