compiling native modules (ulab)
Posted: Thu Jul 30, 2020 4:27 pm
Hi all,
I have recently seen that it is possible to turn .c code into .mpy files, so that the output can be loaded as a standard module without having to re-compile the firmware. This sounds fantastic, except that there are limitations, and even worse, I am not sure I could decipher all the limitations properly.
In particular, I would consider turning ulab into a native module, but I am not sure that is even possible. E.g., does the sentence from
"So, if your C code has writable data, make sure the data is defined globally, without an initialiser, and only written to within functions." from the micropython manual mean that user-defined structures containing writable data, like an ndarray, would not qualify? (An ndarray, since it supports the buffer protocol, could be written to by a number of things, not only by the user.)
Another question concerns performance: does the native code run at, well, native speed, or should one expect slow-down, or RAM penalties?
Can one load sub-modules of a native module, or will everything be loaded as a single chunk? ulab is split into 8 sub-modules, which can be imported separately. Would something like this be possible?
If compiling a complex library, like ulab, into a native module is feasible at all, I would definitely like to further explore the question.
Thanks,
Zoltán
I have recently seen that it is possible to turn .c code into .mpy files, so that the output can be loaded as a standard module without having to re-compile the firmware. This sounds fantastic, except that there are limitations, and even worse, I am not sure I could decipher all the limitations properly.
In particular, I would consider turning ulab into a native module, but I am not sure that is even possible. E.g., does the sentence from
"So, if your C code has writable data, make sure the data is defined globally, without an initialiser, and only written to within functions." from the micropython manual mean that user-defined structures containing writable data, like an ndarray, would not qualify? (An ndarray, since it supports the buffer protocol, could be written to by a number of things, not only by the user.)
Another question concerns performance: does the native code run at, well, native speed, or should one expect slow-down, or RAM penalties?
Can one load sub-modules of a native module, or will everything be loaded as a single chunk? ulab is split into 8 sub-modules, which can be imported separately. Would something like this be possible?
If compiling a complex library, like ulab, into a native module is feasible at all, I would definitely like to further explore the question.
Thanks,
Zoltán