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