1# Integrating a Backend Delegate into ExecuTorch 2 3Disclaimer: We are planning to restructure the repository around delegates. 4With that some of these guidelines will change in the future. 5 6This is a high level guideline when integrating a backend delegate with ExecuTorch. 7 8## Directory Structure 9 10Delegate files should be under this directory: 11`executorch/backends/<delegate_name>/`. The delegate name should be unique. 12 13## Python Source Files 14 15Delegate Python files such as those implementing `preprocess()` or `partition()` 16functions for ExecuTorch AOT flow, excluding any external third-party 17dependencies and their files, should be installed and available with 18the top level ExecuTorch package. For third-party dependencies, please refer to 19[this](./backend-delegates-dependencies.md). 20 21## C++ Source Files 22 23At a minimum, a delegate must provide CMake support for building its C++ 24sources. 25 26For the CMake setup, the delegate dir should be included by the 27top level `CMakeLists.txt` file using `add_subdirectory` CMake command, and 28should be built conditionally with an ExecuTorch build flag like 29`EXECUTORCH_BUILD_<DELEGATE_NAME>`, see `EXECUTORCH_BUILD_XNNPACK` for example. 30For third-party dependencies, please refer to 31[this](./backend-delegates-dependencies.md). 32 33<!--- 34TODO: Add more details. Need to insert a CMake layer in `executorch/backends` to 35provide some uniform abstraction across delegates. 36---> 37 38## Tests 39 40Tests should be added under `executorch/backends/<delegate_name>/test`. Tests 41can be either python or C++ tests. For adding more complex end-to-end (e2e) 42tests, please reach out to us. 43 44Common test types: 45* Simple python unit tests that test AOT logic such as `partitioner()` or AOT 46 export flow (generating a `.pte` file from an `nn.Module`) 47* Runtime C++ tests, using gtest, that test delegate `init()` or `execute()` 48 runtime logic. 49 50## Documentation 51 52A delegate must contain a `executorch/backends/<delegate_name>/README.md` 53explaining the basics of the delegate, directory structure, features, and known 54issues if any. 55 56Any extra setup steps beyond the ones listed above should be documented in 57`executorch/backends/<delegate_name>/setup.md` 58