README.md
1# Standalone dynamic backend developer guide
2
3Arm NN allows adding new dynamic backends. Dynamic Backends can be compiled as standalone against Arm NN
4and can be loaded by Arm NN dynamically at runtime.
5
6To be properly loaded and used, the backend instances must comply to the standard interface for dynamic backends
7and to the versioning rules that enforce ABI compatibility.
8The 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
12The easiest way to build a standalone sample dynamic backend is to build using environment configured compiler
13and specify the Arm NN path to the CMake command:
14
15```shell
16cd ${DYNAMIC_BACKEND_DIR}
17mkdir build
18cd build
19cmake -DARMNN_PATH=${ARMNN_PATH}/libarmnn.so ..
20```
21
22Then run the build
23
24```shell
25make
26```
27
28The library will be created in ${DYNAMIC_BACKEND_DIR}/build.
29
30## Dynamic backend loading paths
31
32During the creation of the Runtime, Arm NN will scan a given set of paths searching for suitable dynamic backend objects to load.
33A 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
40Example 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
46The paths will be processed in the same order as they are indicated in the macro.
47
48## Standalone dynamic backend example
49
50The 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
55The details of how to create backends can be found in [src/backends/README.md](../backends/README.md).
56
57The 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
61To build and test the sample dynamic backend mentioned above, first Arm NN must be built with the
62sample dynamic unit tests turned on (**-DSAMPLE_DYNAMIC_BACKEND**) and the path must be provided to the Arm NN build the
63location of where the sample dynamic backend will be located at (**-DDYNAMIC_BACKEND_PATHS**) at runtime.
64This path should reflect the location on the target device, if this is different that the machine on which Arm NN was built.
65
66Arm 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
71Then the sample dynamic backend can be built standalone using the following commands:
72```shell
73cd armnn/src/dynamic/sample
74mkdir build
75cd build
76cmake -DARMNN_PATH=${ARMNN_BUILD_PATH}/libarmnn.so ..
77make
78```
79
80A shared library file named **libArm_SampleDynamic_backend.so** will now be located in the build directory. Copy this to the location
81defined by -DDYNAMIC_BACKEND_PATHS at compile time:
82```shell
83cp libArm_SampleDynamic_backend.so /tmp/armnn/sample_dynamic_backend
84```
85
86Then 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
91To 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```
102
README.md.license
1#
2# Copyright © 2019-2021 Arm Ltd and Contributors. All rights reserved.
3# SPDX-License-Identifier: MIT
4#
5