Generating .elf file to run on ARM Cortex M7

I am currently trying to understand how I can generate an .elf file for an ARM Cortex M7. This page Setting Up ExecuTorch — ExecuTorch 0.2 documentation (pytorch.org) doesn’t really talk about how I can do that. Also, if I take a look at GitHub executorch/examples/arm there only is one ARM example for a Cortex-M55. I am sorry but can anyone give me further tutorial material?

What I understood is that I need to export my trained model using to_executorch and then convert the .pte file to a header file via executorch/examples/arm/executor_runner/pte_to_header.py at main · pytorch/executorch · GitHub
What I don’t know is how I can create a minimal C++ example which loads the model from the header file and calls the forward function for a given input vector?

executorch/examples/portable/executor_runner/executor_runner.cpp at main · pytorch/executorch · GitHub may be a good example to start with. It’s portable C++ that can build for Cortex M7. If you’re not creating a standalone executable, you could modify main() to be more like a library call that takes the PTE data as a parameter (maybe as a DataLoader or as a raw buffer).

Since it sounds like you’re embedding the PTE data in your image, you’ll need to wrap it in a BufferDataLoader (executorch/extension/data_loader/buffer_data_loader.h at main · pytorch/executorch · GitHub) instead of a FileDataLoader. But once you have that, you should be able to load the Program and Method in the same way that executor_runner.cpp does.

Apart from that code, which should let you execute the model, you’ll need to make sure that your .elf links in the kernels that are necessary to run the model. Overview of ExecuTorch’s Kernel Libraries — ExecuTorch main documentation and the documents that follow it talk about kernel libraries and registration.

Same goes for backends, if you’re delegating your model to the ARM backend. The docs under executorch/examples/arm at main · pytorch/executorch · GitHub or executorch/backends/arm at main · pytorch/executorch · GitHub might have more details on that.