55#include "py/runtime.h"
66#endif
77
8+ // Define unique symbol names based on CONFIG
9+ #ifdef CONFIG_FP32
10+ #define CNN_TYPE mod_cnn_fp32_type
11+ #define CNN_CMODULE mod_cnn_fp32_cmodule
12+ #define CNN_FREE mod_cnn_fp32_free
13+ #elif defined(CONFIG_INT8 )
14+ #define CNN_TYPE mod_cnn_int8_type
15+ #define CNN_CMODULE mod_cnn_int8_cmodule
16+ #define CNN_FREE mod_cnn_int8_free
17+ #else
18+ #define CNN_TYPE mod_cnn_int8_type
19+ #define CNN_CMODULE mod_cnn_int8_cmodule
20+ #define CNN_FREE mod_cnn_int8_free
21+ #endif
822
9- void mod_cnn_free (void * ptr );
23+ // Forward declaration for tm_port.h
24+ void CNN_FREE (void * ptr );
1025
1126// TinyMaix config
1227#include "./tm_port.h"
@@ -81,18 +96,18 @@ typedef struct _mp_obj_mod_cnn_t {
8196} mp_obj_mod_cnn_t ;
8297
8398#if MICROPY_ENABLE_DYNRUNTIME
84- mp_obj_full_type_t mod_cnn_type ;
99+ mp_obj_full_type_t CNN_TYPE ;
85100#else
86- static const mp_obj_type_t mod_cnn_type ;
101+ static const mp_obj_type_t CNN_TYPE ;
87102#endif
88103
89104
90- void mod_cnn_free (void * ptr )
105+ void CNN_FREE (void * ptr )
91106{
92107#if MICROPY_ENABLE_DYNRUNTIME
93108 return m_free (ptr );
94109#else
95- return m_del (void * , ptr , 0 ); // XXX: not sure if safe
110+ return m_del (void * , ptr , 0 );
96111#endif
97112}
98113
@@ -116,7 +131,7 @@ static mp_obj_t mod_cnn_new(mp_obj_t model_data_obj) {
116131 const int model_data_length = bufinfo .len / sizeof (* model_data_buffer );
117132
118133 // Construct object
119- mp_obj_mod_cnn_t * o = mp_obj_malloc (mp_obj_mod_cnn_t , (mp_obj_type_t * )& mod_cnn_type );
134+ mp_obj_mod_cnn_t * o = mp_obj_malloc (mp_obj_mod_cnn_t , (mp_obj_type_t * )& CNN_TYPE );
120135 tm_mdl_t * model = & o -> model ;
121136
122137 // Copy the model data
@@ -283,15 +298,15 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
283298
284299 mp_store_global (MP_QSTR_new , MP_OBJ_FROM_PTR (& mod_cnn_new_obj ));
285300
286- mod_cnn_type .base .type = (void * )& mp_fun_table .type_type ;
287- mod_cnn_type .flags = MP_TYPE_FLAG_ITER_IS_CUSTOM ;
288- mod_cnn_type .name = MP_QSTR_tinymaixcnn ;
301+ CNN_TYPE .base .type = (void * )& mp_fun_table .type_type ;
302+ CNN_TYPE .flags = MP_TYPE_FLAG_ITER_IS_CUSTOM ;
303+ CNN_TYPE .name = MP_QSTR_tinymaixcnn ;
289304 // methods
290305 mod_locals_dict_table [0 ] = (mp_map_elem_t ){ MP_OBJ_NEW_QSTR (MP_QSTR_run ), MP_OBJ_FROM_PTR (& mod_cnn_run_obj ) };
291306 mod_locals_dict_table [1 ] = (mp_map_elem_t ){ MP_OBJ_NEW_QSTR (MP_QSTR___del__ ), MP_OBJ_FROM_PTR (& mod_cnn_del_obj ) };
292307 mod_locals_dict_table [2 ] = (mp_map_elem_t ){ MP_OBJ_NEW_QSTR (MP_QSTR_output_dimensions ), MP_OBJ_FROM_PTR (& mod_cnn_output_dimensions_obj ) };
293308
294- MP_OBJ_TYPE_SET_SLOT (& mod_cnn_type , locals_dict , (void * )& mod_locals_dict , 2 );
309+ MP_OBJ_TYPE_SET_SLOT (& CNN_TYPE , locals_dict , (void * )& mod_locals_dict , 2 );
295310
296311 // This must be last, it restores the globals dict
297312 MP_DYNRUNTIME_INIT_EXIT
@@ -308,7 +323,7 @@ static MP_DEFINE_CONST_DICT(mod_cnn_locals_dict, mod_cnn_locals_dict_table);
308323
309324
310325static MP_DEFINE_CONST_OBJ_TYPE (
311- mod_cnn_type ,
326+ CNN_TYPE ,
312327 MP_QSTR_tinymaix_cnn ,
313328 MP_TYPE_FLAG_NONE ,
314329 locals_dict , & mod_cnn_locals_dict
@@ -320,17 +335,17 @@ static const mp_rom_map_elem_t mod_cnn_globals_table[] = {
320335};
321336static MP_DEFINE_CONST_DICT (mod_cnn_globals , mod_cnn_globals_table ) ;
322337
323- const mp_obj_module_t mod_cnn_cmodule = {
338+ const mp_obj_module_t CNN_CMODULE = {
324339 .base = { & mp_type_module },
325340 .globals = (mp_obj_dict_t * )& mod_cnn_globals ,
326341};
327342
328343// Module name depends on CONFIG
329344#ifdef CONFIG_FP32
330- MP_REGISTER_MODULE (MP_QSTR_tinymaix_cnn_fp32_native , mod_cnn_cmodule );
345+ MP_REGISTER_MODULE (MP_QSTR_emlearn_cnn_fp32_native , CNN_CMODULE );
346+ #elif defined(CONFIG_INT8 )
347+ MP_REGISTER_MODULE (MP_QSTR_emlearn_cnn_int8_native , CNN_CMODULE );
331348#else
332- MP_REGISTER_MODULE (MP_QSTR_emlearn_cnn_int8 , mod_cnn_cmodule );
349+ MP_REGISTER_MODULE (MP_QSTR_emlearn_cnn_int8_native , CNN_CMODULE );
333350#endif
334351#endif
335-
336-
0 commit comments