Skip to content

Commit feffdcf

Browse files
committed
cnn: Enable for Unix/external build (fp32 only for now)
1 parent 02fd180 commit feffdcf

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# emlearn_cnn_fp32 - wrapper for frozen unix build
2+
# Imports the native C module compiled with fp32 configuration
3+
try:
4+
from tinymaix_cnn_fp32_native import *
5+
except ImportError:
6+
pass
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# emlearn_cnn_fp32 wrapper for Unix port
2+
# Compiles mod_cnn.c with fp32 configuration
3+
4+
CNN_SRC := $(USERMOD_DIR)/../tinymaix_cnn
5+
6+
# Add C source file from tinymaix_cnn
7+
SRC_USERMOD_C += $(CNN_SRC)/mod_cnn.c
8+
9+
# Include paths
10+
CFLAGS_USERMOD += -I$(CNN_SRC)/fp32
11+
CFLAGS_USERMOD += -I$(CNN_SRC)/../../dependencies/TinyMaix/include
12+
CFLAGS_USERMOD += -I$(CNN_SRC)/../../dependencies/TinyMaix/src
13+
14+
# Compile flags
15+
CFLAGS_USERMOD += -Wno-error=unused-variable -Wno-error=multichar -Wdouble-promotion
16+
17+
# Define CONFIG_FP32 for the C code
18+
CFLAGS_USERMOD += -DCONFIG_FP32

src/manifest_unix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Ref https://docs.micropython.org/en/latest/reference/manifest.html
55
module("emlearn_trees.py", base_path='./emlearn_trees')
66
module("emlearn_kmeans.py", base_path='./emlearn_kmeans')
7+
module("emlearn_cnn_fp32.py", base_path='./emlearn_cnn_fp32')
78
module("emlearn_fft.py", base_path='./emlearn_fft')
89
module("emlearn_linreg.py", base_path='./emlearn_linreg')
910
module("emlearn_logreg.py", base_path='./emlearn_logreg')

src/tinymaix_cnn/mod_cnn.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
301301
// Define a class
302302
static const mp_rom_map_elem_t mod_cnn_locals_dict_table[] = {
303303
{ MP_ROM_QSTR(MP_QSTR_run), MP_ROM_PTR(&mod_cnn_run_obj) },
304-
{ MP_ROM_QSTR(MP_QSTR_output_dimensions), MP_ROM_PTR(&mod_cnn_del_obj) },
305-
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_cnn_output_dimensions_obj) }
304+
{ MP_ROM_QSTR(MP_QSTR_output_dimensions), MP_ROM_PTR(&mod_cnn_output_dimensions_obj) },
305+
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mod_cnn_del_obj) }
306306
};
307307
static MP_DEFINE_CONST_DICT(mod_cnn_locals_dict, mod_cnn_locals_dict_table);
308308

@@ -325,8 +325,12 @@ const mp_obj_module_t mod_cnn_cmodule = {
325325
.globals = (mp_obj_dict_t *)&mod_cnn_globals,
326326
};
327327

328-
// FIXME: unhardcode config part of module name
328+
// Module name depends on CONFIG
329+
#ifdef CONFIG_FP32
330+
MP_REGISTER_MODULE(MP_QSTR_tinymaix_cnn_fp32_native, mod_cnn_cmodule);
331+
#else
329332
MP_REGISTER_MODULE(MP_QSTR_emlearn_cnn_int8, mod_cnn_cmodule);
330333
#endif
334+
#endif
331335

332336

0 commit comments

Comments
 (0)