aboutsummaryrefslogtreecommitdiff
path: root/23.11/md_shim__build_guide_shim_support_library.html
blob: 1ed53cd8661520689e17ee740aaccc7aa183d1a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!-- HTML header for doxygen 1.8.17-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Arm NN: How to use the Android NDK to build Arm NN</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <img alt="ArmNN" src="Arm_NN_horizontal_blue.png" style="max-width: 15rem; margin-top: .5rem; margin-left 13px"/>
  <td id="projectalign" style="padding-left: 0.9em;">
   <div id="projectname">
   &#160;<span id="projectnumber">23.11</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('md_shim__build_guide_shim_support_library.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">How to use the Android NDK to build Arm NN </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#download-arm-nn">Download Arm NN</a></li>
<li><a href="#build-arm-compute-library">Build Arm Compute Library</a></li>
<li><a href="#build-arm-nn">Build Arm NN</a></li>
<li><a href="#build-arm-nn-support-library">Build Arm NN Support Library</a></li>
<li><a href="#build-arm-nn-shim">Build Arm NN Shim</a></li>
</ul>
<h1>Introduction</h1>
<p>These are step by step instructions for building the Arm NN shim and support library for NNAPI. This work is currently in an experimental phase.</p>
<h1>Prerequisites</h1>
<p>The following are required to build the Arm NN support library</p><ul>
<li>Android NDK r25<ul>
<li>Detailed setup can be found in ../BuildGuideAndroidNDK.md "BuildGuideAndroidNDK.md"</li>
</ul>
</li>
<li>Flatbuffer version 23.5.26<ul>
<li>Detailed setup can be found in ../BuildGuideCrossCompilation.md "BuildGuideCrossCompilation.md"</li>
</ul>
</li>
</ul>
<p>The following is required to build the Arm NN shim</p><ul>
<li>AOSP Source (Android Open Source Project)<ul>
<li>Download the source from the <a href="https://source.android.com/setup/build/downloading">official website</a></li>
<li>This guide will use release tag <code>android12-s1-release</code></li>
</ul>
</li>
</ul>
<p>Set environment variables </p><div class="fragment"><div class="line">export WORKING_DIR=&lt;path to where the Arm NN source code, clframework and aosp repos will be cloned&gt;</div>
<div class="line">export AOSP_ROOT=&lt;path to the root of Android tree where the shim will be built&gt;</div>
<div class="line">export AOSP_MODULES_ROOT=&lt;path to where AOSP modules will be cloned i.e. $WORKING_DIR/aosp&gt;</div>
<div class="line">export ARMNN_BUILD_DIR=&lt;path to the Arm NN build directory i.e. $WORKING_DIR/build&gt;</div>
<div class="line">export NDK=&lt;path to&gt;android-ndk-r25</div>
<div class="line">export NDK_TOOLCHAIN_ROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64</div>
<div class="line">export PATH=$NDK_TOOLCHAIN_ROOT/bin/:$PATH</div>
<div class="line">export FLATBUFFERS_ANDROID_BUILD=&lt;path to flatbuffers target android build&gt;</div>
<div class="line">export FLATBUFFERS_X86_BUILD=&lt;path to flatbuffers host build-x86_64&gt;</div>
</div><!-- fragment --><h1>Download Arm NN</h1>
<p>If the user only wishes to build the Support Library with the NDK, the Arm NN repo can be cloned into any folder. If the user also wishes to build the Arm NN Shim, for this the Arm NN repo will need to reside within the Android tree in order for armnn/shim/Android.bp to be picked up by the Soong (Android) build system. For example $AOSP_ROOT/vendor/arm/armnn</p>
<ul>
<li>Clone Arm NN: (Requires Git if not previously installed: <code>sudo apt install git</code>)</li>
</ul>
<div class="fragment"><div class="line">cd $WORKING_DIR</div>
<div class="line">git clone https://github.com/ARM-software/armnn.git</div>
</div><!-- fragment --><h1>Build Arm Compute Library</h1>
<p>Arm NN provides a script that downloads the version of Arm Compute Library that Arm NN was tested with: </p><div class="fragment"><div class="line">${WORKING_DIR}/armnn/scripts/get_compute_library.sh</div>
</div><!-- fragment --><ul>
<li>Build the Arm Compute Library: (Requires SCons if not previously installed: <code>sudo apt install scons</code>) <div class="fragment"><div class="line">cd ${WORKING_DIR}/clframework</div>
<div class="line"> </div>
<div class="line">scons arch=arm64-v8a \</div>
<div class="line">toolchain_prefix=aarch64-linux-android- \</div>
<div class="line">compiler_prefix=aarch64-linux-android29- \</div>
<div class="line">neon=1 opencl=1 \</div>
<div class="line">embed_kernels=1 \</div>
<div class="line">build_dir=android-arm64v8a \</div>
<div class="line">extra_cxx_flags=&quot;-Wno-parentheses-equality -Wno-missing-braces -fPIC&quot; \</div>
<div class="line">Werror=0 embed_kernels=1 examples=0 \</div>
<div class="line">validation_tests=0 benchmark_tests=0 benchmark_examples=0 os=android -j16</div>
</div><!-- fragment --></li>
</ul>
<h1>Build Arm NN and Serializer</h1>
<ul>
<li>Build Arm NN: (Requires CMake if not previously installed: <code>sudo apt install cmake</code>) <div class="fragment"><div class="line">cd $ARMNN_BUILD_DIR</div>
<div class="line">CXX=aarch64-linux-android29-clang++ \</div>
<div class="line">CC=aarch64-linux-android29-clang \</div>
<div class="line">CXX_FLAGS=&quot;-fPIE -fPIC&quot; cmake ${WORKING_DIR}/armnn \</div>
<div class="line">-DCMAKE_ANDROID_NDK=$NDK \</div>
<div class="line">-DCMAKE_SYSTEM_NAME=Android \</div>
<div class="line">-DCMAKE_SYSTEM_VERSION=29 \</div>
<div class="line">-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \</div>
<div class="line">-DCMAKE_EXE_LINKER_FLAGS=&quot;-pie -llog -lz&quot; \</div>
<div class="line">-DARMCOMPUTE_ROOT=$WORKING_DIR/clframework/ \</div>
<div class="line">-DARMCOMPUTE_BUILD_DIR=$WORKING_DIR/clframework/build/android-arm64v8a/ \</div>
<div class="line">-DARMCOMPUTENEON=1 -DARMCOMPUTECL=1 -DARMNNREF=1 \</div>
<div class="line">-DFLATBUFFERS_ROOT=$FLATBUFFERS_ANDROID_BUILD \</div>
<div class="line">-DFLATC_DIR=$FLATBUFFERS_X86_BUILD \</div>
<div class="line">-DBUILD_ARMNN_SERIALIZER=1 -DBUILD_GATORD_MOCK=0 -DBUILD_BASE_PIPE_SERVER=0</div>
</div><!-- fragment --><ul>
<li>Run the build <div class="fragment"><div class="line">make -j16</div>
</div><!-- fragment --></li>
</ul>
</li>
</ul>
<h1>Build Arm NN Support Library</h1>
<p>Building the support library requires building some AOSP libraries via the NDK. It should be possible to use $AOSP_ROOT instead of $AOSP_MODULES_ROOT.</p>
<p>However this example will instead clone the necessary AOSP repos outside of the Android tree and apply some minor patches which were required to get it to build with the Android version used in this guide.</p>
<div class="fragment"><div class="line"># Call a script which will clone the necessary AOSP repos (do not clone them into Android tree)</div>
<div class="line">${WORKING_DIR}/armnn/shim/sl/scripts/clone_aosp_libs.sh $AOSP_MODULES_ROOT</div>
<div class="line"> </div>
<div class="line"># Modify the repos by applying patches</div>
<div class="line">${WORKING_DIR}/armnn/shim/sl/scripts/modify_aosp_libs.sh $AOSP_MODULES_ROOT</div>
<div class="line"> </div>
<div class="line"># Build the Support Library</div>
<div class="line">CMARGS=&quot;$CMARGS \</div>
<div class="line">-DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake \</div>
<div class="line">-DANDROID_ABI=arm64-v8a \</div>
<div class="line">-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \</div>
<div class="line">-DCMAKE_ANDROID_NDK=$NDK \</div>
<div class="line">-DANDROID_PLATFORM=android-29 \</div>
<div class="line">-DAOSP_MODULES_ROOT=$AOSP_MODULES_ROOT \</div>
<div class="line">-DARMNN_SOURCE_DIR=$WORKING_DIR/armnn \</div>
<div class="line">-DArmnn_DIR=$ARMNN_BUILD_DIR &quot;</div>
<div class="line"> </div>
<div class="line">mkdir ${WORKING_DIR}/armnn/shim/sl/build</div>
<div class="line">cd ${WORKING_DIR}/armnn/shim/sl/build</div>
<div class="line"> </div>
<div class="line">CXX=aarch64-linux-android29-clang++ \</div>
<div class="line">CC=aarch64-linux-android29-clang \</div>
<div class="line">cmake $CMARGS ../</div>
<div class="line">make</div>
</div><!-- fragment --><h1>Build Arm NN Shim</h1>
<p>By default the Arm NN shim Android.bp.off is not enabled. It is enabled below by renaming it to Android.bp</p>
<div class="fragment"><div class="line">cd ${WORKING_DIR}/armnn/shim</div>
<div class="line">mv Android.bp.off Android.bp</div>
<div class="line"> </div>
<div class="line">cd $AOSP_ROOT</div>
<div class="line">source build/envsetup.sh</div>
<div class="line">lunch &lt;device&gt;-eng</div>
<div class="line">cd vendor/arm/armnn/shim</div>
<div class="line">export ARMNN_ANDROID_MK_ENABLE=0</div>
<div class="line">mm</div>
</div><!-- fragment --><p>The built libraries and manifest file can be found here: $AOSP_ROOT/out/target/product/&lt;device&gt;/vendor/lib64/libarmnn_support_library.so $AOSP_ROOT/out/target/product/&lt;device&gt;/vendor/bin/hw/android.hardware.neuralnetworks-shim-service-armnn $AOSP_ROOT/out/target/product/&lt;device&gt;/vendor/etc/vintf/manifest/android.hardware.neuralnetworks-shim-service-armnn.xml</p>
<p>Currently the Arm NN libraries are shared libraries and therefore will need to be pushed to the device: $ARMNN_BUILD_DIR/libarmnn.so </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Wed Nov 22 2023 10:57:11 for Arm NN by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.17 </li>
  </ul>
</div>
</body>
</html>