Skip to content

Commit 0097209

Browse files
committed
cnn: Fixup dynamic module build
Needs different config from external C...
1 parent a919097 commit 0097209

7 files changed

Lines changed: 22 additions & 16 deletions

File tree

dependencies/TinyMaix

src/emlearn_cnn_fp32/emlearn_cnn_fp32.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
/* Define CONFIG_FP32 first */
88
#define CONFIG_FP32
99

10+
// for external module we need static
11+
#define TM_STATIC static
12+
1013
/* Include the fp32 tm_port.h directly */
1114
#include "../tinymaix_cnn/fp32/tm_port.h"
1215

src/emlearn_cnn_int8/emlearn_cnn_int8.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
/* Define CONFIG_INT8 first */
88
#define CONFIG_INT8
99

10+
// for external module we need static
11+
#define TM_STATIC static
12+
1013
/* Include the int8 tm_port.h directly */
1114
#include "../tinymaix_cnn/int8/tm_port.h"
1215

src/tinymaix_cnn/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ $(DIST_FILE): $(MOD).mpy $(DIST_DIR)
3535
# Include to get the rules for compiling and linking the module
3636
include $(MPY_DIR)/py/dynruntime.mk
3737

38-
CFLAGS += -I$(CONFIG_DIR) -I$(TINYMAIX_DIR)/include -I$(TINYMAIX_DIR)/src -Wno-error=unused-variable -Wno-error=multichar -Wdouble-promotion
38+
CONFIG_DEFINE = CONFIG_$(shell echo $(CONFIG) | tr '[:lower:]' '[:upper:]')
39+
40+
CFLAGS += -D${CONFIG_DEFINE} -I$(CONFIG_DIR) -I$(TINYMAIX_DIR)/include -I$(TINYMAIX_DIR)/src -Wno-error=unused-variable -Wno-error=multichar -Wdouble-promotion
3941

4042
dist: $(DIST_FILE)

src/tinymaix_cnn/fp32/tm_port.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,20 @@ limitations under the License.
3535
#define TM_MDL_TYPE TM_MDL_FP32
3636
#define TM_FASTSCALE (0) //enable if your chip don't have FPU, may speed up 1/3, but decrease accuracy
3737
#define TM_LOCAL_MATH (1) //use local math func (like exp()) to avoid libm
38-
#define TM_ENABLE_STAT (1) //enable mdl stat functions
38+
#define TM_ENABLE_STAT (0) //enable mdl stat functions
3939
#define TM_MAX_CSIZE (1000) //max channel num //used if INT8 mdl //cost TM_MAX_CSIZE*4 Byte
4040
#define TM_MAX_KSIZE (5*5) //max kernel_size //cost TM_MAX_KSIZE*4 Byte
4141
#define TM_MAX_KCSIZE (3*3*256) //max kernel_size*channels //cost TM_MAX_KSIZE*sizeof(mtype_t) Byte
4242

4343
#define TM_INLINE __attribute__((always_inline)) static inline
44-
#define TM_WEAK static
44+
#ifndef TM_WEAK
45+
#define TM_WEAK __attribute__((weak))
46+
#endif
4547

4648
// Disable "static" (non-const) globals, since they are not supported by MicroPython mpy_ld.py
47-
// But when building multiple variants, we need static to avoid duplicate definitions
48-
#ifdef CONFIG_FP32
49-
#define TM_STATIC static
50-
#else
49+
#ifndef TM_STATIC
5150
#define TM_STATIC
52-
#endif
51+
#endif
5352

5453
// Use MicroPython for dynamic allocation
5554
#define tm_malloc(x) m_malloc(x)

src/tinymaix_cnn/int8/tm_port.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@ limitations under the License.
3535
#define TM_MDL_TYPE TM_MDL_INT8
3636
#define TM_FASTSCALE (0) //enable if your chip don't have FPU, may speed up 1/3, but decrease accuracy
3737
#define TM_LOCAL_MATH (1) //use local math func (like exp()) to avoid libm
38-
#define TM_ENABLE_STAT (1) //enable mdl stat functions
38+
#define TM_ENABLE_STAT (0) //enable mdl stat functions
3939
#define TM_MAX_CSIZE (1000) //max channel num //used if INT8 mdl //cost TM_MAX_CSIZE*4 Byte
4040
#define TM_MAX_KSIZE (5*5) //max kernel_size //cost TM_MAX_KSIZE*4 Byte
4141
#define TM_MAX_KCSIZE (3*3*256) //max kernel_size*channels //cost TM_MAX_KSIZE*sizeof(mtype_t) Byte
4242

4343
#define TM_INLINE __attribute__((always_inline)) static inline
44-
#define TM_WEAK static
44+
#ifndef TM_WEAK
45+
#define TM_WEAK __attribute__((weak))
46+
#endif
4547

4648
// Disable "static" (non-const) globals, since they are not supported by MicroPython mpy_ld.py
47-
// But when building multiple variants, we need static to avoid duplicate definitions
48-
#ifdef CONFIG_INT8
49-
#define TM_STATIC static
50-
#else
49+
#ifndef TM_STATIC
5150
#define TM_STATIC
5251
#endif
5352

src/tinymaix_cnn/mod_cnn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void CNN_FREE(void *ptr);
3636
#elif defined(CONFIG_FP32)
3737
#include "./fp32/tm_port.h"
3838
#else
39-
#include "./int8/tm_port.h" // default
39+
#error "No config defined"
4040
#endif
4141
#endif
4242

0 commit comments

Comments
 (0)