Update ACL pin to 8abbabd6ad946441c8ef1a03896fa98f7801af1f
[platform/upstream/armnn.git] / Documentation / index.xhtml
1 <!-- Copyright (c) 2020 ARM Limited. -->
2 <!--                                 -->
3 <!-- SPDX-License-Identifier: MIT    -->
4 <!--                                 -->
5 <!-- HTML header for doxygen 1.8.13-->
6 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
7 <html xmlns="http://www.w3.org/1999/xhtml">
8 <head>
9 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
10 <meta http-equiv="X-UA-Compatible" content="IE=9"/>
11 <meta name="generator" content="Doxygen 1.8.13"/>
12 <meta name="robots" content="NOINDEX, NOFOLLOW" />
13 <meta name="viewport" content="width=device-width, initial-scale=1"/>
14 <title>ArmNN: Introduction</title>
15 <link href="tabs.css" rel="stylesheet" type="text/css"/>
16 <script type="text/javascript" src="jquery.js"></script>
17 <script type="text/javascript" src="dynsections.js"></script>
18 <link href="navtree.css" rel="stylesheet" type="text/css"/>
19 <script type="text/javascript" src="resize.js"></script>
20 <script type="text/javascript" src="navtreedata.js"></script>
21 <script type="text/javascript" src="navtree.js"></script>
22 <script type="text/javascript">
23   $(document).ready(initResizable);
24 </script>
25 <link href="search/search.css" rel="stylesheet" type="text/css"/>
26 <script type="text/javascript" src="search/searchdata.js"></script>
27 <script type="text/javascript" src="search/search.js"></script>
28 <script type="text/x-mathjax-config">
29   MathJax.Hub.Config({
30     extensions: ["tex2jax.js"],
31     jax: ["input/TeX","output/HTML-CSS"],
32 });
33 </script><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
34 <link href="doxygen.css" rel="stylesheet" type="text/css" />
35 <link href="stylesheet.css" rel="stylesheet" type="text/css"/>
36 </head>
37 <body>
38 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
39 <div id="titlearea">
40 <table cellspacing="0" cellpadding="0">
41  <tbody>
42  <tr style="height: 56px;">
43   <img alt="ArmNN" src="Arm_NN_horizontal_blue.png" style="max-width: 10rem; margin-top: .5rem; margin-left 10px"/>
44   <td style="padding-left: 0.5em;">
45    <div id="projectname">
46    &#160;<span id="projectnumber">20.02</span>
47    </div>
48   </td>
49  </tr>
50  </tbody>
51 </table>
52 </div>
53 <!-- end header part -->
54 <!-- Generated by Doxygen 1.8.13 -->
55 <script type="text/javascript">
56 var searchBox = new SearchBox("searchBox", "search",false,'Search');
57 </script>
58 <script type="text/javascript" src="menudata.js"></script>
59 <script type="text/javascript" src="menu.js"></script>
60 <script type="text/javascript">
61 $(function() {
62   initMenu('',true,false,'search.php','Search');
63   $(document).ready(function() { init_search(); });
64 });
65 </script>
66 <div id="main-nav"></div>
67 </div><!-- top -->
68 <div id="side-nav" class="ui-resizable side-nav-resizable">
69   <div id="nav-tree">
70     <div id="nav-tree-contents">
71       <div id="nav-sync" class="sync"></div>
72     </div>
73   </div>
74   <div id="splitbar" style="-moz-user-select:none;" 
75        class="ui-resizable-handle">
76   </div>
77 </div>
78 <script type="text/javascript">
79 $(document).ready(function(){initNavTree('index.xhtml','');});
80 </script>
81 <div id="doc-content">
82 <!-- window showing the filter options -->
83 <div id="MSearchSelectWindow"
84      onmouseover="return searchBox.OnSearchSelectShow()"
85      onmouseout="return searchBox.OnSearchSelectHide()"
86      onkeydown="return searchBox.OnSearchSelectKey(event)">
87 </div>
88
89 <!-- iframe showing the search results (closed by default) -->
90 <div id="MSearchResultsWindow">
91 <iframe src="javascript:void(0)" frameborder="0" 
92         name="MSearchResults" id="MSearchResults">
93 </iframe>
94 </div>
95
96 <div class="header">
97   <div class="headertitle">
98 <div class="title">Introduction </div>  </div>
99 </div><!--header-->
100 <div class="contents">
101 <div class="toc"><h3>Table of Contents</h3>
102 <ul><li class="level1"><a href="#S0_1_armnn">ArmNN</a></li>
103 <li class="level1"><a href="#S1_license">License</a></li>
104 <li class="level1"><a href="#S2_1_contributions">Contributor Guide</a><ul><li class="level2"><a href="#S2_1_dco">Developer Certificate of Origin (DCO)</a></li>
105 <li class="level2"><a href="#S2_2_releases">Releases</a></li>
106 <li class="level2"><a href="#S2_3_development_repository">Developer Repository</a></li>
107 <li class="level2"><a href="#S2_4_code_review">Code Review</a></li>
108 <li class="level2"><a href="#S2_5_continuous_integration">Continuous Integration</a></li>
109 <li class="level2"><a href="#S2_6_communications">Communications</a></li>
110 </ul>
111 </li>
112 <li class="level1"><a href="#S3_build_instructions">Build Instructions</a><ul><li class="level2"><a href="#S3_1_android_ndk_build_guide">How to use the Android NDK to build ArmNN</a></li>
113 <li class="level2"><a href="#S3_2_cross_compilations_build_guide">Cross Compilation Build Guide</a></li>
114 </ul>
115 </li>
116 </ul>
117 </div>
118 <div class="textblock"><h1><a class="anchor" id="S0_1_armnn"></a>
119 ArmNN</h1>
120 <p>Arm NN is a key component of the <a href="https://mlplatform.org/">machine learning platform</a>, which is part of the <a href="https://www.linaro.org/news/linaro-announces-launch-of-machine-intelligence-initiative/">Linaro Machine Intelligence Initiative</a>. For more information on the machine learning platform and Arm NN, see: <a href="https://mlplatform.org/">https://mlplatform.org/</a>, also there is further Arm NN information available from <a href="https://developer.arm.com/products/processors/machine-learning/arm-nn">https://developer.arm.com/products/processors/machine-learning/arm-nn</a></p>
121 <p>There is a getting started guide here using TensorFlow: <a href="https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-tensorflow">https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-tensorflow</a></p>
122 <p>There is a getting started guide here using TensorFlow Lite: <a href="https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-tensorflow-lite">https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-tensorflow-lite</a></p>
123 <p>There is a getting started guide here using Caffe: <a href="https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-caffe">https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-caffe</a></p>
124 <p>There is a getting started guide here using ONNX: <a href="https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-onnx">https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-onnx</a></p>
125 <p>There is a guide for backend development <a href="backends.xhtml">here</a>. <br />
126 <br />
127 <br />
128 <br />
129 </p>
130 <h1><a class="anchor" id="S1_license"></a>
131 License</h1>
132 <p>Arm NN is provided under the <a href="https://spdx.org/licenses/MIT.html">MIT</a> license.</p>
133 <p><b><b>MIT License</b></b></p>
134 <p>Copyright (c) 2017-2020 ARM Limited.</p>
135 <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
136 <p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
137 <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
138 <p>Individual files contain the following tag instead of the full license text. </p><pre class="fragment">SPDX-License-Identifier: MIT
139 </pre><p>This enables machine processing of license information based on the SPDX License Identifiers that are available <a href="http://spdx.org/licenses/">here</a> <br />
140 <br />
141 <br />
142 <br />
143 </p>
144 <h1><a class="anchor" id="S2_1_contributions"></a>
145 Contributor Guide</h1>
146 <p>The Arm NN project is open for external contributors and welcomes contributions. Arm NN is licensed under the <a href="https://spdx.org/licenses/MIT.html">MIT license</a> and all accepted contributions must have the same license. For more details on contributing to Arm NN see the <a href="https://mlplatform.org/contributing/">Contributing page</a> on the <a href="https://mlplatform.org/">MLPlatform.org</a> website.</p>
147 <h2><a class="anchor" id="S2_1_dco"></a>
148 Developer Certificate of Origin (DCO)</h2>
149 <p>Before the Arm NN project accepts your contribution, you need to certify its origin and give us your permission. To manage this process we use Developer Certificate of Origin (DCO) V1.1 (<a href="https://developercertificate.org/">https://developercertificate.org/</a>).</p>
150 <p>To indicate that you agree to the the terms of the DCO, you "sign off" your contribution by adding a line with your name and e-mail address to every git commit message:</p>
151 <p>Signed-off-by: John Doe <a href="#" onclick="location.href='mai'+'lto:'+'joh'+'n.'+'doe'+'@e'+'xam'+'pl'+'e.o'+'rg'; return false;">john.<span style="display: none;">.nosp@m.</span>doe@<span style="display: none;">.nosp@m.</span>examp<span style="display: none;">.nosp@m.</span>le.o<span style="display: none;">.nosp@m.</span>rg</a></p>
152 <p>You must use your real name, no pseudonyms or anonymous contributions are accepted.</p>
153 <h2><a class="anchor" id="S2_2_releases"></a>
154 Releases</h2>
155 <p>Official Arm NN releases are published through the official <a href="https://github.com/ARM-software/armnn">Arm NN Github repository</a>.</p>
156 <h2><a class="anchor" id="S2_3_development_repository"></a>
157 Developer Repository</h2>
158 <p>The Arm NN development repository is hosted on the <a href="https://git.mlplatform.org/ml/armnn.git/">mlplatform.org git repository</a> hosted by <a href="https://www.linaro.org/">Linaro</a>.</p>
159 <h2><a class="anchor" id="S2_4_code_review"></a>
160 Code Review</h2>
161 <p>Contributions must go through code review. Code reviews are performed through the <a href="https://review.mlplatform.org">mlplatform.org Gerrit server</a>. Contributors need to signup to this Gerrit server with their GitHub account credentials.</p>
162 <p>Only reviewed contributions can go to the master branch of Arm NN.</p>
163 <h2><a class="anchor" id="S2_5_continuous_integration"></a>
164 Continuous Integration</h2>
165 <p>Contributions to Arm NN go through testing at the Arm CI system. All unit, integration and regression tests must pass before a contribution gets merged to the Arm NN master branch.</p>
166 <h2><a class="anchor" id="S2_6_communications"></a>
167 Communications</h2>
168 <p>We encourage all Arm NN developers to subscribe to the <a href="https://lists.linaro.org/mailman/listinfo/armnn-dev">Arm NN developer mailing list</a>. <br />
169 <br />
170 <br />
171 <br />
172 </p>
173 <h1><a class="anchor" id="S3_build_instructions"></a>
174 Build Instructions</h1>
175 <p>Arm tests the build system of Arm NN with the following build environments:</p>
176 <p>Android NDK Cross compilation from x86_64 Ubuntu to arm64 Linux Native compilation under aarch64 Debian 9</p>
177 <p>Arm NN is written using portable C++14 and the build system uses <a href="https://cmake.org/">CMake</a>, therefore it is possible to build for a wide variety of target platforms, from a wide variety of host environments.</p>
178 <p>The armnn/tests directory contains tests used during Arm NN development. Many of them depend on third-party IP, model protobufs and image files not distributed with Arm NN. The dependencies of some of the tests are available freely on the Internet, for those who wish to experiment.</p>
179 <p>The 'armnn/samples' directory contains SimpleSample.cpp, a very basic example of the ArmNN SDK API in use.</p>
180 <p>The 'ExecuteNetwork' program, in armnn/tests/ExecuteNetwork, has no additional dependencies beyond those required by Arm NN and the model parsers. It takes any model and any input tensor, and simply prints out the output tensor. Run it with no arguments to see command-line help.</p>
181 <p>The 'ArmnnConverter' program, in armnn/src/armnnConverter, has no additional dependencies beyond those required by Arm NN and the model parsers. It takes a model in TensorFlow format and produces a serialized model in Arm NN format. Run it with no arguments to see command-line help. Note that this program can only convert models for which all operations are supported by the serialization tool src/armnnSerializer.</p>
182 <p>The 'ArmnnQuantizer' program, in armnn/src/armnnQuantizer, has no additional dependencies beyond those required by Arm NN and the model parsers. It takes a 32-bit float network and converts it into a quantized asymmetric 8-bit or quantized symmetric 16-bit network. Static quantization is supported by default but dynamic quantization can be enabled if CSV file of raw input tensors is specified. Run it with no arguments to see command-line help.</p>
183 <p>note that Arm NN needs to be built against a particular version of <a href="https://github.com/ARM-software/ComputeLibrary">ARM's Compute Library</a>. The get_compute_library.sh in the scripts subdirectory will clone the compute library from the review.mlplatform.org github repository into a directory alongside armnn named 'clframework' and checks out the correct revision. <br />
184 <br />
185 <br />
186 <br />
187 </p>
188 <h2><a class="anchor" id="S3_1_android_ndk_build_guide"></a>
189 How to use the Android NDK to build ArmNN</h2>
190 <ul>
191 <li>
192 <a href="#introduction">Introduction</a>  </li>
193 <li>
194 <a href="#downloadNDK">Download the Android NDK and make a standalone toolchain</a>  </li>
195 <li>
196 <a href="#buildBoost">Build the Boost C++ libraries</a>  </li>
197 <li>
198 <a href="#buildCL">Build the Compute Library</a>  </li>
199 <li>
200 <a href="#buildProtobuf">Build Google's Protobuf library</a>  </li>
201 <li>
202 <a href="#downloadTF">Download TensorFlow</a>  </li>
203 <li>
204 <a href="#buildArmNN">Build ArmNN</a>  </li>
205 <li>
206 <a href="#runArmNNUnitTests">Run ArmNN UnitTests on an Android device</a>  </li>
207 </ul>
208 <h2><a class="anchor" id="introduction"></a>Introduction</h2>
209 <p>These are step by step instructions for using the Android NDK to build ArmNN. They have been tested on a clean install of Ubuntu 18.04, and should also work with other OS versions. The instructions show how to build the ArmNN core library and the optional TensorFlow parser. All downloaded or generated files will be saved inside the <code>~/armnn-devenv</code> directory.</p>
210 <h2><a class="anchor" id="downloadNDK"></a>Download the Android NDK and make a standalone toolchain</h2>
211 <h3>Download the Android NDK from <a href="https://developer.android.com/ndk/downloads/index.html">the official website</a>:</h3>
212 <div class="fragment"><div class="line">mkdir -p ~/armnn-devenv/toolchains</div><div class="line">cd ~/armnn-devenv/toolchains</div><div class="line"></div><div class="line">#For Mac OS, change the NDK download link accordingly.</div><div class="line">wget https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip</div><div class="line">unzip android-ndk-r17b-linux-x86_64.zip</div><div class="line">export NDK=~/armnn-devenv/toolchains/android-ndk-r17b</div></div><!-- fragment --> <pre class="fragment"> You may want to append `export NDK=~/armnn-devenv/toolchains/android-ndk-r17b` to your `~/.bashrc` (or `~/.bash_profile` in Mac OS).
213 </pre><h3>Make a standalone toolchain:</h3>
214 <pre class="fragment"> (Requires python if not previously installed: `sudo apt install python`)
215 </pre><div class="fragment"><div class="line"># Create an arm64 API 26 libc++ toolchain.</div><div class="line">$NDK/build/tools/make_standalone_toolchain.py \</div><div class="line">    --arch arm64 \</div><div class="line">    --api 26 \</div><div class="line">    --stl=libc++ \</div><div class="line">    --install-dir=$HOME/armnn-devenv/toolchains/aarch64-android-r17b</div><div class="line">export PATH=$HOME/armnn-devenv/toolchains/aarch64-android-r17b/bin:$PATH</div></div><!-- fragment --> <pre class="fragment"> You may want to append `export PATH=$HOME/armnn-devenv/toolchains/aarch64-android-r17b/bin:$PATH` to your `~/.bashrc` (or `~/.bash_profile` in Mac OS).
216 </pre><h2><a class="anchor" id="buildBoost"></a>Build the Boost C++ libraries</h2>
217 <h3>Download Boost version 1.64:</h3>
218 <div class="fragment"><div class="line">mkdir ~/armnn-devenv/boost</div><div class="line">cd ~/armnn-devenv/boost</div><div class="line">wget https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.bz2</div><div class="line">tar xvf boost_1_64_0.tar.bz2</div></div><!-- fragment --><h3>Build:</h3>
219 <pre class="fragment">(Requires gcc if not previously installed: `sudo apt install gcc`)
220 </pre> <div class="fragment"><div class="line">echo &quot;using gcc : arm : aarch64-linux-android-clang++ ;&quot; &gt; $HOME/armnn-devenv/boost/user-config.jam</div><div class="line">cd ~/armnn-devenv/boost/boost_1_64_0</div><div class="line">./bootstrap.sh --prefix=$HOME/armnn-devenv/boost/install</div><div class="line">./b2 install --user-config=$HOME/armnn-devenv/boost/user-config.jam \</div><div class="line"> toolset=gcc-arm link=static cxxflags=-fPIC --with-filesystem \</div><div class="line"> --with-test --with-log --with-program_options -j16</div></div><!-- fragment --><h2><a class="anchor" id="buildCL"></a>Build the Compute Library</h2>
221 <h3>Clone the Compute Library:</h3>
222 <pre class="fragment">(Requires Git if not previously installed: `sudo apt install git`)
223 </pre><div class="fragment"><div class="line">cd ~/armnn-devenv</div><div class="line">git clone https://github.com/ARM-software/ComputeLibrary.git</div></div><!-- fragment --><h3>Build:</h3>
224 <pre class="fragment">(Requires SCons if not previously installed: `sudo apt install scons`)
225 </pre> <div class="fragment"><div class="line">cd ComputeLibrary</div><div class="line">scons arch=arm64-v8a neon=1 opencl=1 embed_kernels=1 extra_cxx_flags=&quot;-fPIC&quot; \</div><div class="line"> benchmark_tests=0 validation_tests=0 os=android -j16</div></div><!-- fragment --><h2><a class="anchor" id="buildProtobuf"></a>Build Google's Protobuf library</h2>
226 <h3>Clone protobuf:</h3>
227 <div class="fragment"><div class="line">mkdir ~/armnn-devenv/google</div><div class="line">cd ~/armnn-devenv/google</div><div class="line">git clone https://github.com/google/protobuf.git</div><div class="line">cd protobuf</div><div class="line">git checkout -b v3.5.2 v3.5.2</div></div><!-- fragment --><h3>Build a native (x86) version of the protobuf libraries and compiler (protoc):</h3>
228 <pre class="fragment">(Requires cUrl, autoconf, llibtool, and other build dependencies if not previously installed: `sudo apt install curl autoconf libtool build-essential g++`)
229 </pre><div class="fragment"><div class="line">./autogen.sh</div><div class="line">mkdir x86_build</div><div class="line">cd x86_build</div><div class="line">../configure --prefix=$HOME/armnn-devenv/google/x86_pb_install</div><div class="line">make install -j16</div><div class="line">cd ..</div></div><!-- fragment --><h3>Build the arm64 version of the protobuf libraries:</h3>
230 <div class="fragment"><div class="line">mkdir arm64_build</div><div class="line">cd arm64_build</div><div class="line">CC=aarch64-linux-android-clang \</div><div class="line">  CXX=aarch64-linux-android-clang++ \</div><div class="line">  CFLAGS=&quot;-fPIE -fPIC&quot; LDFLAGS=&quot;-pie -llog&quot; \</div><div class="line">   ../configure --host=aarch64-linux-android \</div><div class="line">   --prefix=$HOME/armnn-devenv/google/arm64_pb_install \</div><div class="line">   --with-protoc=$HOME/armnn-devenv/google/x86_pb_install/bin/protoc</div><div class="line">make install -j16</div><div class="line">cd ..</div></div><!-- fragment --><h2><a class="anchor" id="downloadTF"></a>Download TensorFlow</h2>
231 <h3>Clone TensorFlow source code:</h3>
232 <div class="fragment"><div class="line">cd ~/armnn-devenv/google/</div><div class="line">git clone https://github.com/tensorflow/tensorflow.git</div><div class="line">cd tensorflow/</div><div class="line">git checkout a0043f9262dc1b0e7dc4bdf3a7f0ef0bebc4891e</div></div><!-- fragment --> <pre class="fragment">You need tensorflow/contrib/makefile/tf_proto_files.txt from TensorFlow to generate TensorFlow protobuf definitions. This file is not available in TensorFlow master branch.
233 </pre><h2><a class="anchor" id="buildArmNN"></a>Build ArmNN</h2>
234 <h3>Clone ArmNN source code:</h3>
235 <div class="fragment"><div class="line">cd ~/armnn-devenv/</div><div class="line">git clone https://github.com/ARM-software/armnn.git</div></div><!-- fragment --><h3>Generate TensorFlow protobuf definitions:</h3>
236 <div class="fragment"><div class="line">cd ~/armnn-devenv/google/tensorflow</div><div class="line">~/armnn-devenv/armnn/scripts/generate_tensorflow_protobuf.sh \</div><div class="line"> $HOME/armnn-devenv/google/tf_pb $HOME/armnn-devenv/google/x86_pb_install</div></div><!-- fragment --><h3>Build ArmNN:</h3>
237 <pre class="fragment">(Requires CMake if not previously installed: `sudo apt install cmake`)
238 </pre><div class="fragment"><div class="line">mkdir ~/armnn-devenv/armnn/build</div><div class="line">cd ~/armnn-devenv/armnn/build</div><div class="line">CXX=aarch64-linux-android-clang++ \</div><div class="line">CC=aarch64-linux-android-clang \</div><div class="line">CXX_FLAGS=&quot;-fPIE -fPIC&quot; \</div><div class="line">cmake .. \</div><div class="line">-DCMAKE_SYSTEM_NAME=Android \</div><div class="line">-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \</div><div class="line">-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=$HOME/armnn-devenv/toolchains/aarch64-android-r17b/ \</div><div class="line">-DCMAKE_EXE_LINKER_FLAGS=&quot;-pie -llog&quot; \</div><div class="line">-DARMCOMPUTE_ROOT=$HOME/armnn-devenv/ComputeLibrary/ \</div><div class="line">-DARMCOMPUTE_BUILD_DIR=$HOME/armnn-devenv/ComputeLibrary/build \</div><div class="line">-DBOOST_ROOT=$HOME/armnn-devenv/boost/install/ \</div><div class="line">-DARMCOMPUTENEON=1 -DARMCOMPUTECL=1 -DARMNNREF=1 \</div><div class="line">-DTF_GENERATED_SOURCES=$HOME/armnn-devenv/google/tf_pb/ -DBUILD_TF_PARSER=1 \</div><div class="line">-DPROTOBUF_ROOT=$HOME/armnn-devenv/google/arm64_pb_install/</div><div class="line">make -j16</div></div><!-- fragment --><h2><a class="anchor" id="runArmNNUnitTests"></a>Run the ArmNN unit tests on an Android device</h2>
239 <h3>Push the build results to an Android device and make symbolic links for shared libraries:</h3>
240 <p>Currently adb version we have used for testing is 1.0.41.</p>
241 <div class="fragment"><div class="line">adb push libarmnnTfParser.so /data/local/tmp/</div><div class="line">adb push libarmnn.so /data/local/tmp/</div><div class="line">adb push UnitTests /data/local/tmp/</div><div class="line">adb push $NDK/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so /data/local/tmp/</div><div class="line">adb push $HOME/armnn-devenv/google/arm64_pb_install/lib/libprotobuf.so /data/local/tmp/libprotobuf.so.15.0.1</div><div class="line">adb shell &#39;ln -s libprotobuf.so.15.0.1 /data/local/tmp/libprotobuf.so.15&#39;</div><div class="line">adb shell &#39;ln -s libprotobuf.so.15.0.1 /data/local/tmp/libprotobuf.so&#39;</div></div><!-- fragment --><h3>Push the files needed for the unit tests (they are a mix of files, directories and symbolic links):</h3>
242 <div class="fragment"><div class="line">adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/testSharedObject</div><div class="line">adb push -p ~/armnn-devenv/armnn/build/src/backends/backendsCommon/test/testSharedObject/* /data/local/tmp/src/backends/backendsCommon/test/testSharedObject/</div><div class="line"></div><div class="line">adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/testDynamicBackend</div><div class="line">adb push -p ~/armnn-devenv/armnn/build/src/backends/backendsCommon/test/testDynamicBackend/* /data/local/tmp/src/backends/backendsCommon/test/testDynamicBackend/</div><div class="line"></div><div class="line">adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath1</div><div class="line">adb push -p ~/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath1/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath1/</div><div class="line"></div><div class="line">adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2</div><div class="line">adb push -p ~/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/</div><div class="line">adb shell ln -s Arm_CpuAcc_backend.so /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1</div><div class="line">adb shell ln -s Arm_CpuAcc_backend.so.1 /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1.2</div><div class="line">adb shell ln -s Arm_CpuAcc_backend.so.1.2 /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1.2.3</div><div class="line">adb push -p ~/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath2/Arm_GpuAcc_backend.so /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/</div><div class="line">adb shell ln -s nothing /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_no_backend.so</div><div class="line"></div><div class="line">adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath3</div><div class="line"></div><div class="line">adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath5</div><div class="line">adb push -p ~/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath5/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath5/</div><div class="line"></div><div class="line">adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath6</div><div class="line">adb push -p ~/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath6/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath6/</div><div class="line"></div><div class="line">adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath7</div><div class="line"></div><div class="line">adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath9</div><div class="line">adb push -p ~/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath9/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath9/</div><div class="line"></div><div class="line">adb shell mkdir -p /data/local/tmp/src/backends/dynamic/reference</div><div class="line">adb push -p ~/armnn-devenv/armnn/build/src/backends/dynamic/reference/Arm_CpuRef_backend.so /data/local/tmp/src/backends/dynamic/reference/</div></div><!-- fragment --><h3>Run ArmNN unit tests:</h3>
243 <div class="fragment"><div class="line">adb shell &#39;LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/UnitTests&#39;</div></div><!-- fragment --> <pre class="fragment">If libarmnnUtils.a is present in `~/armnn-devenv/armnn/build/` and the unit tests run without failure then the build was successful.
244 </pre><p> <br />
245 <br />
246 <br />
247 <br />
248 </p>
249 <h2><a class="anchor" id="S3_2_cross_compilations_build_guide"></a>
250 Cross Compilation Build Guide</h2>
251 <ul>
252 <li>
253 <a href="#introduction">Introduction</a>  </li>
254 <li>
255 <a href="#installCCT">Cross-compiling ToolChain</a>  </li>
256 <li>
257 <a href="#buildProtobuf">Build and install Google's Protobuf library</a>  </li>
258 <li>
259 <a href="#buildCaffe">Build Caffe for x86_64</a>  </li>
260 <li>
261 <a href="#installBaarch">Build Boost library for arm64</a>  </li>
262 <li>
263 <a href="#buildCL">Build Compute Library</a>  </li>
264 <li>
265 <a href="#buildANN">Build ArmNN</a>  </li>
266 <li>
267 <a href="#unittests">Run Unit Tests</a>  </li>
268 <li>
269 <a href="#troubleshooting">Troubleshooting and Errors</a>  </li>
270 </ul>
271 <h2><a class="anchor" id="introduction"></a>Introduction</h2>
272 <p>These are the step by step instructions on Cross-Compiling ArmNN under an x86_64 system to target an Arm64 system. This build flow has been tested with Ubuntu 16.04. The instructions show how to build the ArmNN core library and the Boost, Protobuf, Caffe and Compute Libraries necessary for compilation.</p>
273 <h2><a class="anchor" id="installCCT"></a>Cross-compiling ToolChain</h2>
274 <h3>Install the standard cross-compilation libraries for arm64:</h3>
275 <div class="fragment"><div class="line">sudo apt install crossbuild-essential-arm64</div></div><!-- fragment --><h2><a class="anchor" id="buildProtobuf"></a>Build and install Google's Protobuf library</h2>
276 <h3>Get protobuf-all-3.5.1.tar.gz from <a href="https://github.com/protocolbuffers/protobuf/releases/tag/v3.5.1">here</a>.</h3>
277 <h3>Extract:</h3>
278 <div class="fragment"><div class="line">tar -zxvf protobuf-all-3.5.1.tar.gz</div><div class="line">cd protobuf-3.5.1</div></div><!-- fragment --><h3>Build a native (x86_64) version of the protobuf libraries and compiler (protoc):</h3>
279 <p>(Requires cUrl, autoconf, llibtool, and other build dependencies if not previously installed: sudo apt install curl autoconf libtool build-essential g++)</p>
280 <div class="fragment"><div class="line">mkdir x86_64_build</div><div class="line">cd x86_64_build</div><div class="line">../configure --prefix=$HOME/armnn-devenv/google/x86_64_pb_install</div><div class="line">make install -j16</div><div class="line">cd ..</div></div><!-- fragment --><h3>Build the arm64 version of the protobuf libraries:</h3>
281 <div class="fragment"><div class="line">mkdir arm64_build</div><div class="line">cd arm64_build</div><div class="line">CC=aarch64-linux-gnu-gcc \</div><div class="line">CXX=aarch64-linux-gnu-g++ \</div><div class="line">../configure --host=aarch64-linux \</div><div class="line">--prefix=$HOME/armnn-devenv/google/arm64_pb_install \</div><div class="line">--with-protoc=$HOME/armnn-devenv/google/x86_64_pb_install/bin/protoc</div><div class="line">make install -j16</div><div class="line">cd ..</div></div><!-- fragment --><h2><a class="anchor" id="buildCaffe"></a>Build Caffe for x86_64</h2>
282 <h3>Ubuntu 16.04 installation. These steps are taken from the full Caffe installation documentation <a href="http://caffe.berkeleyvision.org/install_apt.html">here</a></h3>
283 <h3>Install dependencies:</h3>
284 <div class="fragment"><div class="line">sudo apt-get install libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev</div><div class="line">sudo apt-get install --no-install-recommends libboost-all-dev</div><div class="line">sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev</div><div class="line">sudo apt-get install libopenblas-dev</div><div class="line">sudo apt-get install libatlas-base-dev</div></div><!-- fragment --><h3>Download Caffe-Master from <a href="https://github.com/BVLC/caffe">here</a>.</h3>
285 <div class="fragment"><div class="line">git clone https://github.com/BVLC/caffe.git</div><div class="line">cd caffe</div><div class="line">cp Makefile.config.example Makefile.config</div></div><!-- fragment --><h3>Adjust Makefile.config as necessary for your environment, for example:</h3>
286 <div class="fragment"><div class="line">#CPU only version:</div><div class="line">CPU_ONLY := 1</div><div class="line"></div><div class="line">#Add hdf5 and protobuf include and library directories (Replace $HOME with explicit /home/username dir):</div><div class="line">INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/ $HOME/armnn-devenv/google/x86_64_pb_install/include/</div><div class="line">LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/ $HOME/armnn-devenv/google/x86_64_pb_install/lib/</div></div><!-- fragment --><h3>Setup environment:</h3>
287 <div class="fragment"><div class="line">export PATH=$HOME/armnn-devenv/google/x86_64_pb_install/bin/:$PATH</div><div class="line">export LD_LIBRARY_PATH=$HOME/armnn-devenv/google/x86_64_pb_install/lib/:$LD_LIBRARY_PATH</div></div><!-- fragment --><h3>Compilation with Make:</h3>
288 <div class="fragment"><div class="line">make all</div><div class="line">make test</div><div class="line">make runtest</div></div><!-- fragment --> <pre class="fragment">These should all run without errors
289 </pre> <h3>caffe.pb.h and caffe.pb.cc will be needed when building ArmNN's Caffe Parser</h3>
290 <h2><a class="anchor" id="installBaarch"></a>Build Boost library for arm64</h2>
291 <h3>Build Boost library for arm64</h3>
292 <p>Download Boost version 1.64 from <a href="http://www.boost.org/doc/libs/1_64_0/more/getting_started/unix-variants.html">here</a>. Using any version of Boost greater than 1.64 will fail to build ArmNN, due to different dependency issues.</p>
293 <div class="fragment"><div class="line">tar -zxvf boost_1_64_0.tar.gz</div><div class="line">cd boost_1_64_0</div><div class="line">echo &quot;using gcc : arm : aarch64-linux-gnu-g++ ;&quot; &gt; user_config.jam</div><div class="line">./bootstrap.sh --prefix=$HOME/armnn-devenv/boost_arm64_install</div><div class="line">./b2 install toolset=gcc-arm link=static cxxflags=-fPIC --with-filesystem --with-test --with-log --with-program_options -j32 --user-config=user_config.jam</div></div><!-- fragment --><h2><a class="anchor" id="buildCL"></a>Build Compute Library</h2>
294 <h3>Building the Arm Compute Library:</h3>
295 <div class="fragment"><div class="line">git clone https://github.com/ARM-software/ComputeLibrary.git</div><div class="line">cd ComputeLibrary/</div><div class="line">scons arch=arm64-v8a neon=1 opencl=1 embed_kernels=1 extra_cxx_flags=&quot;-fPIC&quot; -j8 internal_only=0</div></div><!-- fragment --><h2><a class="anchor" id="buildANN"></a>Build ArmNN</h2>
296 <h3>Compile ArmNN for arm64:</h3>
297 <div class="fragment"><div class="line">git clone https://github.com/ARM-software/armnn.git</div><div class="line">cd armnn</div><div class="line">mkdir build</div><div class="line">cd build</div></div><!-- fragment --><h3>Use CMake to configure your build environment, update the following script and run it from the armnn/build directory to set up the armNN build:</h3>
298 <div class="fragment"><div class="line">#!/bin/bash</div><div class="line">CXX=aarch64-linux-gnu-g++ \</div><div class="line">CC=aarch64-linux-gnu-gcc \</div><div class="line">cmake .. \</div><div class="line">-DARMCOMPUTE_ROOT=$HOME/armnn-devenv/ComputeLibrary \</div><div class="line">-DARMCOMPUTE_BUILD_DIR=$HOME/armnn-devenv/ComputeLibrary/build/ \</div><div class="line">-DBOOST_ROOT=$HOME/armnn-devenv/boost_arm64_install/ \</div><div class="line">-DARMCOMPUTENEON=1 -DARMCOMPUTECL=1 -DARMNNREF=1 \</div><div class="line">-DCAFFE_GENERATED_SOURCES=$HOME/armnn-devenv/caffe/build/src \</div><div class="line">-DBUILD_CAFFE_PARSER=1 \</div><div class="line">-DPROTOBUF_ROOT=$HOME/armnn-devenv/google/x86_64_pb_install/ \</div><div class="line">-DPROTOBUF_LIBRARY_DEBUG=$HOME/armnn-devenv/google/arm64_pb_install/lib/libprotobuf.so.15.0.1 \</div><div class="line">-DPROTOBUF_LIBRARY_RELEASE=$HOME/armnn-devenv/google/arm64_pb_install/lib/libprotobuf.so.15.0.1</div></div><!-- fragment --><h3>Run the build</h3>
299 <div class="fragment"><div class="line">make -j32</div></div><!-- fragment --><h2><a class="anchor" id="unittests"></a>Run Unit Tests</h2>
300 <h3>Copy the build folder to an arm64 linux machine</h3>
301 <h3>Copy the libprotobuf.so.15.0.1 library file to the build folder</h3>
302 <h3>cd to the build folder on your arm64 machine and set your LD_LIBRARY_PATH to its current location:</h3>
303 <div class="fragment"><div class="line">cd build/</div><div class="line">export LD_LIBRARY_PATH=`pwd`</div></div><!-- fragment --><h3>Create a symbolic link to libprotobuf.so.15.0.1:</h3>
304 <div class="fragment"><div class="line">ln -s libprotobuf.so.15.0.1 ./libprotobuf.so.15</div></div><!-- fragment --><h3>Run the UnitTests:</h3>
305 <div class="fragment"><div class="line">./UnitTests</div><div class="line">Running 567 test cases...</div><div class="line"></div><div class="line">    No errors detected</div></div><!-- fragment --><h2><a class="anchor" id="troubleshooting"></a>Troubleshooting and Errors:</h2>
306 <h2>Error adding symbols: File in wrong format</h2>
307 <h3>When building armNN:</h3>
308 <div class="fragment"><div class="line">/usr/local/lib/libboost_log.a: error adding symbols: File in wrong format</div><div class="line">collect2: error: ld returned 1 exit status</div><div class="line">CMakeFiles/armnn.dir/build.make:4028: recipe for target &#39;libarmnn.so&#39; failed</div><div class="line">make[2]: *** [libarmnn.so] Error 1</div><div class="line">CMakeFiles/Makefile2:105: recipe for target &#39;CMakeFiles/armnn.dir/all&#39; failed</div><div class="line">make[1]: *** [CMakeFiles/armnn.dir/all] Error 2</div><div class="line">Makefile:127: recipe for target &#39;all&#39; failed</div><div class="line">make: *** [all] Error 2</div></div><!-- fragment --><h3>Boost libraries are not compiled for the correct architecture, try recompiling for arm64</h3>
309 <h2>Virtual memory exhausted</h2>
310 <h3>When compiling the boost libraries:</h3>
311 <div class="fragment"><div class="line">virtual memory exhausted: Cannot allocate memory</div></div><!-- fragment --><h3>Not enough memory available to compile. Increase the amount of RAM or swap space available.</h3>
312 <h2>Unrecognized command line option '-m64'</h2>
313 <h3>When compiling the boost libraries:</h3>
314 <div class="fragment"><div class="line">aarch64-linux-gnu-g++: error: unrecognized command line option ‘-m64’</div></div><!-- fragment --><h3>Clean the boost library directory before trying to build with a different architecture:</h3>
315 <div class="fragment"><div class="line">sudo ./b2 clean</div></div><!-- fragment --><h3>It should show the following for arm64:</h3>
316 <div class="fragment"><div class="line">- 32-bit                   : no</div><div class="line">- 64-bit                   : yes</div><div class="line">- arm                      : yes</div></div><!-- fragment --><h2>Missing libz.so.1</h2>
317 <h3>When compiling armNN:</h3>
318 <div class="fragment"><div class="line">/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: libz.so.1, needed by /home/&lt;username&gt;/armNN/usr/lib64/libprotobuf.so.15.0.0, not found (try using -rpath or -rpath-link)</div></div><!-- fragment --><h3>Missing arm64 libraries for libz.so.1, these can be added by adding a second architecture to dpkg and explicitly installing them:</h3>
319 <div class="fragment"><div class="line">sudo dpkg --add-architecture arm64</div><div class="line">sudo apt-get install zlib1g:arm64</div><div class="line">sudo apt-get update</div><div class="line">sudo ldconfig</div></div><!-- fragment --><h3>If apt-get update returns 404 errors for arm64 repos refer to section 5 below.</h3>
320 <h3>Alternatively the missing arm64 version of libz.so.1 can be downloaded and installed from a .deb package <a href="https://launchpad.net/ubuntu/wily/arm64/zlib1g/1:1.2.8.dfsg-2ubuntu4">here</a></h3>
321 <div class="fragment"><div class="line">sudo dpkg -i zlib1g_1.2.8.dfsg-2ubuntu4_arm64.deb</div></div><!-- fragment --><h2>Unable to install arm64 packages after adding arm64 architecture</h2>
322 <h3>Using sudo apt-get update should add all of the required repos for arm64 but if it does not or you are getting 404 errors the following instructions can be used to add the repos manually:</h3>
323 <h3>From stackoverflow <a href="https://askubuntu.com/questions/430705/how-to-use-apt-get-to-download-multi-arch-library/430718">here</a>.</h3>
324 <h3>Open /etc/apt/sources.list with your preferred text editor.</h3>
325 <h3>Mark all the current (default) repos as [arch=], e.g.</h3>
326 <div class="fragment"><div class="line">deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ xenial main restricted</div></div><!-- fragment --><h3>Then add the following:</h3>
327 <div class="fragment"><div class="line">deb [arch=arm64] http://ports.ubuntu.com/ xenial main restricted</div><div class="line">deb [arch=arm64] http://ports.ubuntu.com/ xenial-updates main restricted</div><div class="line">deb [arch=arm64] http://ports.ubuntu.com/ xenial universe</div><div class="line">deb [arch=arm64] http://ports.ubuntu.com/ xenial-updates universe</div><div class="line">deb [arch=arm64] http://ports.ubuntu.com/ xenial multiverse</div><div class="line">deb [arch=arm64] http://ports.ubuntu.com/ xenial-updates multiverse</div><div class="line">deb [arch=arm64] http://ports.ubuntu.com/ xenial-backports main restricted universe multiverse</div></div><!-- fragment --><h3>Update and install again:</h3>
328 <div class="fragment"><div class="line">sudo apt-get install zlib1g:arm64</div><div class="line">sudo apt-get update</div><div class="line">sudo ldconfig</div></div><!-- fragment --><h2>Undefined references to google::protobuf:: functions</h2>
329 <h3>When compiling armNN there are multiple errors of the following type:</h3>
330 <p>``<code> libarmnnCaffeParser.so: undefined reference to</code>google::protobuf:* ``` </p><h3>Missing or out of date protobuf compilation libraries.</h3>
331 <p>Use the command 'protoc &ndash;version' to check which version of protobuf is available (version 3.5.1 is required). Follow the instructions above to install protobuf 3.5.1 Note this will require you to recompile Caffe for x86_64</p>
332 <h2>Errors on strict-aliasing rules when compiling the Compute Library</h2>
333 <h3>When compiling the Compute Library there are multiple errors on strict-aliasing rules:</h3>
334 <div class="fragment"><div class="line">cc1plus: error: unrecognized command line option ‘-Wno-implicit-fallthrough’ [-Werror]</div></div><!-- fragment --><h3>Add Werror=0 to the scons command:</h3>
335 <div class="fragment"><div class="line">scons arch=arm64-v8a neon=1 opencl=1 embed_kernels=1 extra_cxx_flags=&quot;-fPIC&quot; -j8 internal_only=0 Werror=0</div></div><!-- fragment --> </div></div><!-- contents -->
336 </div><!-- doc-content -->
337 <!-- start footer part -->
338 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
339   <ul>
340     <li class="footer">Generated on Fri Mar 13 2020 16:09:21 for ArmNN by
341     <a href="http://www.doxygen.org/index.html">
342     <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
343   </ul>
344 </div>
345 </body>
346 </html>