tum-ei-eda / utvm_staticrt_codegen

This project contains a code generator that produces static C NN inference deployment code targeting tiny micro-controllers (TinyML) as replacement for other µTVM runtimes. This tools generates a runtime, which statically executes the compiled model. This reduces the overhead in terms of code size and execution time compared to having a dynamic on-device runtime.
Apache License 2.0
27 stars 9 forks source link

Cross compile to ARM 32 bits #12

Closed wuruoyu closed 2 years ago

wuruoyu commented 2 years ago

Hi, I am wondering if this tool support cross-compilation (to ARM 32 bits). IMHO, micro-TVM is for embedded systems, and naturally, the AOT compilation should support ARM.

I see the commented code here: https://github.com/tum-ei-eda/utvm_staticrt_codegen/blob/6d4c8d98e8826da9c525a7b3f5d8b8ea4e4e1a00/examples/utvm_gen_graph_and_params.py#L118-L128

But I am not sure if it works well and how to make it work.

Very appreciate your help!

PhilippvK commented 2 years ago

We currently do not use microTVM at all to compile the generated kernel sources as we are just interested in the artifacts of the codegen which can essentially be supplied as C-files to any MCU toolchain similar to the CMake configuration for x86 which can be found here.

AFAIK is the Compiler/Flasher interface mentioned in https://github.com/tum-ei-eda/utvm_staticrt_codegen/blob/1b296f1efcc28671ee21ccbe86a81b968db8b1e5/examples/utvm_gen_graph_and_params.py#L118 being replaced by the microTVM Project API

PhilippvK commented 2 years ago

Also keep in mind that current neither the Graph Executor nor the AoT executor ist currently used in the target_src as it is just there to demonstrate and test the utvm_staticrt_codegen which is similar to the AoT compiler but implemented in a different way.

I might be able to update the examples in the repository to optionally use the Graph Executor or AoT compiler in the near future so stay tuned.

wuruoyu commented 2 years ago

Thank you for sharing! Please forgive me that I am very new to TVM.

By any chance, do you know any working AoT compiler examples in microTVM? I want to do an experiment with the microTVM AoT compiler. I know it is still undergoing heavy development but I only need several demo cases of AoT. If you happen to know one, please drop me a pointer. Really appreciate your help!

PhilippvK commented 2 years ago

@wuruoyu The best reference I know are actually the pytest files used in TVM to test the full AoT flow.

They can be found in tvm/tests/python/relay/aot and invoked via:

cd tvm # or whereever you have cloned and build tvm before
export PYTHONPATH=$(pwd)/python
python3 -m pytest tests/python/relay/aot/test_crt_aot.py

However as this takes quite long and does not actually show whats going on under the hood, you are probably better of looking at the pytest tests/python/relay/aot/aot_test_utils.py helper script used by the scripts to generate AoT projects as well as the used Makefile: pytest tests/python/relay/aot/default.mk

wuruoyu commented 2 years ago

Thanks a lot! They do look promising!

wuruoyu commented 2 years ago

Sorry I found out that my TVM installation does not work well, so I deleted

PhilippvK commented 2 years ago

@wuruoyu I think it had something to do with you TVM files being newer as the ones used to build TVM via CMake as the feature which was resulting in the error was justadded about 8 hours ago.

wuruoyu commented 2 years ago

@PhilippvK Exactly, thank you~

By the way, are you able to just run pytest tests/python/relay/aot/default.mk? Or it is just suggesting to me to look at that makefile?

I tried to run pytest tests/python/relay/aot/aot_test_utils.py but it shows no tests ran. And when I tried to run pytest tests/python/relay/aot/default.mk, it is complaining that the file is not found.

PhilippvK commented 2 years ago

@wuruoyu You should only run python3 -m pytest tests/python/relay/aot/test_crt_aot.py. The other files are used by that script but not actually pytests.

wuruoyu commented 2 years ago

Thanks a lot!

With the script in pytests, I am able to compile a mobilenet model binary in X86. Do you know how to use those scripts to cross-compile a binary in Arm? I tried adding some flags but fail... Very appreciate your help!

wuruoyu commented 2 years ago

Thanks for all the guidance you gave! I finally am able to do cross-compiling by looking into tests/micro/zephyr/test_zephyr_aot.py. Really appreciate your help!