Generating .elf file to run on ARM Cortex M7

shallowLearning: <p>I am currently trying to understand how I can generate an .elf file for an ARM Cortex M7. This page <a href="https://pytorch.org/executorch/stable/getting-started-setup.html#quick-setup-colab-jupyter-notebook-prototype" rel="noopener nofollow ugc">Setting Up ExecuTorch — ExecuTorch 0.2 documentation (pytorch.org)</a> doesn’t really talk about how I can do that. Also, if I take a look at GitHub <code>executorch/examples/arm</code> there only is one ARM example for a Cortex-M55. I am sorry but can anyone give me further tutorial material?</p>
<p>What I understood is that I need to export my trained model using <code>to_executorch</code> and then convert the <code>.pte</code> file to a header file via <a href="https://github.com/pytorch/executorch/blob/main/examples/arm/executor_runner/pte_to_header.py" rel="noopener nofollow ugc">executorch/examples/arm/executor_runner/pte_to_header.py at main · pytorch/executorch · GitHub</a><br>
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?</p>

dbort: <p><a href="https://github.com/pytorch/executorch/blob/main/examples/portable/executor_runner/executor_runner.cpp" class="inline-onebox" rel="noopener nofollow ugc">executorch/examples/portable/executor_runner/executor_runner.cpp at main · pytorch/executorch · GitHub</a> 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).</p>
<p>Since it sounds like you’re embedding the PTE data in your image, you’ll need to wrap it in a BufferDataLoader (<a href="https://github.com/pytorch/executorch/blob/main/extension/data_loader/buffer_data_loader.h" class="inline-onebox" rel="noopener nofollow ugc">executorch/extension/data_loader/buffer_data_loader.h at main · pytorch/executorch · GitHub</a>) 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.</p>
<p>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. <a href="https://pytorch.org/executorch/main/kernel-library-overview.html" class="inline-onebox" rel="noopener nofollow ugc">Overview of ExecuTorch’s Kernel Libraries — ExecuTorch main documentation</a> and the documents that follow it talk about kernel libraries and registration.</p>
<p>Same goes for backends, if you’re delegating your model to the ARM backend. The docs under <a href="https://github.com/pytorch/executorch/tree/main/examples/arm" class="inline-onebox" rel="noopener nofollow ugc">executorch/examples/arm at main · pytorch/executorch · GitHub</a> or <a href="https://github.com/pytorch/executorch/tree/main/backends/arm" class="inline-onebox" rel="noopener nofollow ugc">executorch/backends/arm at main · pytorch/executorch · GitHub</a> might have more details on that.</p>