1*89c4ff92SAndroid Build Coastguard Worker# Standalone dynamic backend developer guide 2*89c4ff92SAndroid Build Coastguard Worker 3*89c4ff92SAndroid Build Coastguard WorkerArm NN allows adding new dynamic backends. Dynamic Backends can be compiled as standalone against Arm NN 4*89c4ff92SAndroid Build Coastguard Workerand can be loaded by Arm NN dynamically at runtime. 5*89c4ff92SAndroid Build Coastguard Worker 6*89c4ff92SAndroid Build Coastguard WorkerTo be properly loaded and used, the backend instances must comply to the standard interface for dynamic backends 7*89c4ff92SAndroid Build Coastguard Workerand to the versioning rules that enforce ABI compatibility. 8*89c4ff92SAndroid Build Coastguard WorkerThe details of how to add dynamic backends can be found in [src/backends/README.md](../backends/README.md). 9*89c4ff92SAndroid Build Coastguard Worker 10*89c4ff92SAndroid Build Coastguard Worker### Standalone dynamic backend build 11*89c4ff92SAndroid Build Coastguard Worker 12*89c4ff92SAndroid Build Coastguard WorkerThe easiest way to build a standalone sample dynamic backend is to build using environment configured compiler 13*89c4ff92SAndroid Build Coastguard Workerand specify the Arm NN path to the CMake command: 14*89c4ff92SAndroid Build Coastguard Worker 15*89c4ff92SAndroid Build Coastguard Worker```shell 16*89c4ff92SAndroid Build Coastguard Workercd ${DYNAMIC_BACKEND_DIR} 17*89c4ff92SAndroid Build Coastguard Workermkdir build 18*89c4ff92SAndroid Build Coastguard Workercd build 19*89c4ff92SAndroid Build Coastguard Workercmake -DARMNN_PATH=${ARMNN_PATH}/libarmnn.so .. 20*89c4ff92SAndroid Build Coastguard Worker``` 21*89c4ff92SAndroid Build Coastguard Worker 22*89c4ff92SAndroid Build Coastguard WorkerThen run the build 23*89c4ff92SAndroid Build Coastguard Worker 24*89c4ff92SAndroid Build Coastguard Worker```shell 25*89c4ff92SAndroid Build Coastguard Workermake 26*89c4ff92SAndroid Build Coastguard Worker``` 27*89c4ff92SAndroid Build Coastguard Worker 28*89c4ff92SAndroid Build Coastguard WorkerThe library will be created in ${DYNAMIC_BACKEND_DIR}/build. 29*89c4ff92SAndroid Build Coastguard Worker 30*89c4ff92SAndroid Build Coastguard Worker## Dynamic backend loading paths 31*89c4ff92SAndroid Build Coastguard Worker 32*89c4ff92SAndroid Build Coastguard WorkerDuring the creation of the Runtime, Arm NN will scan a given set of paths searching for suitable dynamic backend objects to load. 33*89c4ff92SAndroid Build Coastguard WorkerA list of (absolute) paths can be specified at compile-time by setting a define named ```DYNAMIC_BACKEND_PATHS``` 34*89c4ff92SAndroid Build Coastguard Worker in the form of a colon-separated list of strings. 35*89c4ff92SAndroid Build Coastguard Worker 36*89c4ff92SAndroid Build Coastguard Worker```shell 37*89c4ff92SAndroid Build Coastguard Worker-DDYNAMIC_BACKEND_PATHS="PATH_1:PATH_2...:PATH_N" 38*89c4ff92SAndroid Build Coastguard Worker``` 39*89c4ff92SAndroid Build Coastguard Worker 40*89c4ff92SAndroid Build Coastguard WorkerExample for setting the path to the sample standalone dynamic backend built from the previous step: 41*89c4ff92SAndroid Build Coastguard Worker 42*89c4ff92SAndroid Build Coastguard Worker```shell 43*89c4ff92SAndroid Build Coastguard Worker-DDYNAMIC_BACKEND_PATHS=${DYNAMIC_BACKEND_DIR}/build 44*89c4ff92SAndroid Build Coastguard Worker``` 45*89c4ff92SAndroid Build Coastguard Worker 46*89c4ff92SAndroid Build Coastguard WorkerThe paths will be processed in the same order as they are indicated in the macro. 47*89c4ff92SAndroid Build Coastguard Worker 48*89c4ff92SAndroid Build Coastguard Worker## Standalone dynamic backend example 49*89c4ff92SAndroid Build Coastguard Worker 50*89c4ff92SAndroid Build Coastguard WorkerThe source code includes an example that is used to generate a simple dynamic backend and is provided at 51*89c4ff92SAndroid Build Coastguard Worker 52*89c4ff92SAndroid Build Coastguard Worker[SampleDynamicBackend.hpp](./sample/SampleDynamicBackend.hpp) 53*89c4ff92SAndroid Build Coastguard Worker[SampleDynamicBackend.cpp](./sample/SampleDynamicBackend.cpp) 54*89c4ff92SAndroid Build Coastguard Worker 55*89c4ff92SAndroid Build Coastguard WorkerThe details of how to create backends can be found in [src/backends/README.md](../backends/README.md). 56*89c4ff92SAndroid Build Coastguard Worker 57*89c4ff92SAndroid Build Coastguard WorkerThe makefile used for building the standalone reference dynamic backend is also provided: 58*89c4ff92SAndroid Build Coastguard Worker[CMakeLists.txt](./sample/CMakeLists.txt) 59*89c4ff92SAndroid Build Coastguard Worker 60*89c4ff92SAndroid Build Coastguard Worker### End-To-End steps to build and test the sample dynamic backend 61*89c4ff92SAndroid Build Coastguard WorkerTo build and test the sample dynamic backend mentioned above, first Arm NN must be built with the 62*89c4ff92SAndroid Build Coastguard Workersample dynamic unit tests turned on (**-DSAMPLE_DYNAMIC_BACKEND**) and the path must be provided to the Arm NN build the 63*89c4ff92SAndroid Build Coastguard Workerlocation of where the sample dynamic backend will be located at (**-DDYNAMIC_BACKEND_PATHS**) at runtime. 64*89c4ff92SAndroid Build Coastguard WorkerThis path should reflect the location on the target device, if this is different that the machine on which Arm NN was built. 65*89c4ff92SAndroid Build Coastguard Worker 66*89c4ff92SAndroid Build Coastguard WorkerArm NN can be built using the [Build Tool](../../build-tool/README.md) with the following additional comma-separated **--armnn-cmake-args** in the **BUILD_ARGS**: 67*89c4ff92SAndroid Build Coastguard Worker```shell 68*89c4ff92SAndroid Build Coastguard Worker--armnn-cmake-args='-DSAMPLE_DYNAMIC_BACKEND=1,-DDYNAMIC_BACKEND_PATHS=/tmp/armnn/sample_dynamic_backend' 69*89c4ff92SAndroid Build Coastguard Worker``` 70*89c4ff92SAndroid Build Coastguard Worker 71*89c4ff92SAndroid Build Coastguard WorkerThen the sample dynamic backend can be built standalone using the following commands: 72*89c4ff92SAndroid Build Coastguard Worker```shell 73*89c4ff92SAndroid Build Coastguard Workercd armnn/src/dynamic/sample 74*89c4ff92SAndroid Build Coastguard Workermkdir build 75*89c4ff92SAndroid Build Coastguard Workercd build 76*89c4ff92SAndroid Build Coastguard Workercmake -DARMNN_PATH=${ARMNN_BUILD_PATH}/libarmnn.so .. 77*89c4ff92SAndroid Build Coastguard Workermake 78*89c4ff92SAndroid Build Coastguard Worker``` 79*89c4ff92SAndroid Build Coastguard Worker 80*89c4ff92SAndroid Build Coastguard WorkerA shared library file named **libArm_SampleDynamic_backend.so** will now be located in the build directory. Copy this to the location 81*89c4ff92SAndroid Build Coastguard Workerdefined by -DDYNAMIC_BACKEND_PATHS at compile time: 82*89c4ff92SAndroid Build Coastguard Worker```shell 83*89c4ff92SAndroid Build Coastguard Workercp libArm_SampleDynamic_backend.so /tmp/armnn/sample_dynamic_backend 84*89c4ff92SAndroid Build Coastguard Worker``` 85*89c4ff92SAndroid Build Coastguard Worker 86*89c4ff92SAndroid Build Coastguard WorkerThen run the Arm NN unit tests which will be located inside the build directory created by the Arm NN build-tool: 87*89c4ff92SAndroid Build Coastguard Worker```shell 88*89c4ff92SAndroid Build Coastguard Worker./UnitTests 89*89c4ff92SAndroid Build Coastguard Worker``` 90*89c4ff92SAndroid Build Coastguard Worker 91*89c4ff92SAndroid Build Coastguard WorkerTo be confident that the standalone dynamic backend tests are running, run the unit tests with the following filter: 92*89c4ff92SAndroid Build Coastguard Worker```shell 93*89c4ff92SAndroid Build Coastguard Worker./UnitTests -tc=CreateSampleDynamicBackend,SampleDynamicBackendEndToEnd 94*89c4ff92SAndroid Build Coastguard Worker[doctest] doctest version is "2.4.6" 95*89c4ff92SAndroid Build Coastguard Worker[doctest] run with "--help" for options 96*89c4ff92SAndroid Build Coastguard Worker=============================================================================== 97*89c4ff92SAndroid Build Coastguard Worker[doctest] test cases: 2 | 2 passed | 0 failed | 2796 skipped 98*89c4ff92SAndroid Build Coastguard Worker[doctest] assertions: 11 | 11 passed | 0 failed | 99*89c4ff92SAndroid Build Coastguard Worker[doctest] Status: SUCCESS! 100*89c4ff92SAndroid Build Coastguard Worker 101*89c4ff92SAndroid Build Coastguard Worker``` 102