-
-
Notifications
You must be signed in to change notification settings - Fork 15
Support usage as external C modules #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There was a proof of concept of this done here, #2 Right now there are some natmod hacks in the module code. So that should be fixed first, to reduce the amount of #ifdefs we need to support both ways of building. Via something like #15 |
This might also enable to include in ports that only/primarily support external C modules, like "embed" and "webassembly". |
This might help with #3 also |
I tried to integrate emlearn .mpy frozen code to the build of MicroPython but failed. I hope the project would support build as user C modules. Also, it could utilize ESP-DSP, ESP-NN for specific ESP32 case. |
The .mpy files are intended to be installed into the filesystem using mip. Typically at runtime. But for including in a firmware image, I think there are some tools to pre-fill a filesystem. The ROMFS that just landed in MicroPython 1.25 might be one option. |
Initial test was merged in #36 . There are some code difference needed between native modules and external C modules, but that looks manageable. Things that need to be figured out:
Then we need to do a bit of testing, and also set everything up in CI. And of course add documentation once everything is working. |
I managed to solve the above. The fact that everything needs to be done twice, for cmake and makefile-based ports, is super annoying and quite time-consuming. |
@jonnor, thank u so much. I will try to build it as USER_C_MODULES as soon as possible. I'd like cmake-based because ESP-IDF 5.x switching to CMake. |
@jonnor, it's great that I can build it successfully on ESP32-C3, ESP32-C6. During the build, it needs to include some files from emlearn project, https://github.com/emlearn/emlearn/tree/master/emlearn, such as Then I must git clone it inside the folder dependencies, At some point during build process, it reports like below. Anyway, it is successful.
Then I run the example code here, https://github.com/emlearn/emlearn-micropython/tree/master/examples/xor_trees. It got successful result. I dont know whether it is expect result or not.
My custom build on ESP32-C3 now has emlearn, but
|
I found |
Yes, the _c modules are the underlying C modules. And then the modules without _c is a Python module, which also includes the stuff from the C module. This is what one needs to do with external modules to merge Python and C code into one module :) (dynamic native modules have built in support for this concept at runtime). |
Thanks a lot for testing. Glad you got it to work :) The XOR output is correct. Regarding Note that esp-idf can be a bit annoying here, as it has its own virtual environment for Python packages - so one needs to install the pages inside that virtual env. |
PS: I have not tested yet myself on RISC-V ESP32 chips. I will test that soon I hope, and comment in #35 how it goes |
If lacking of this, as in my case, is the library still working properly? |
If possible, please add support c modules for emlearn_iir_q15, emlearn_kmeans, emlearn_neighbors. |
Right now emlearn is distributed as dynamic native modules. This is excellent for getting started, as one can just drop in a .mpy file on a standard MicroPython build and have things working. However, native modules always execute out of RAM, which tends to be more limited than FLASH space. In addition, for dynamic modules, some library code like for softfloat etc must be duplicated.
Additionally, the tooling for including .mpy files automatically in a firmware image is a bit missing right now.
For these reasons, it would be nice to optionally be able to include the modules, as "external C modules" during a MicroPython build.
The text was updated successfully, but these errors were encountered: