blob: 282ec45936ed6cf5dd28bd8d656ebd030450fac4 [file] [log] [blame]
<!-- 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">24.05</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="#deprecation-notice">Deprecation Notice</a></li>
<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>Deprecation Notice</h1>
<p>Arm NN will be dropping support for support library in 24.08.</p>
<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 r26b<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-r26b</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-android${ANDROID_API}- \</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>
<p>Note: ANDROID_API is the Android API version you want to build.</p>
<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-android${ANDROID_API}-clang++ \</div>
<div class="line">CC=aarch64-linux-android${ANDROID_API}-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=$ANDROID_API \</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-$ANDROID_API \</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-android$ANDROID_API-clang++ \</div>
<div class="line">CC=aarch64-linux-android$ANDROID_API-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 Thu May 16 2024 09:31:54 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>