blob: f2f88c9b324464c3532806a94e648543ae9118cf [file] [log] [blame]
Sheri Zhangd813bab2021-04-30 16:53:41 +01001///
Gunes Bayiree905002022-02-25 15:20:00 +00002/// Copyright (c) 2017-2022 Arm Limited.
Sheri Zhangd813bab2021-04-30 16:53:41 +01003///
4/// SPDX-License-Identifier: MIT
5///
6/// Permission is hereby granted, free of charge, to any person obtaining a copy
7/// of this software and associated documentation files (the "Software"), to
8/// deal in the Software without restriction, including without limitation the
9/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10/// sell copies of the Software, and to permit persons to whom the Software is
11/// furnished to do so, subject to the following conditions:
12///
13/// The above copyright notice and this permission notice shall be included in all
14/// copies or substantial portions of the Software.
15///
16/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22/// SOFTWARE.
23///
24namespace arm_compute
25{
26/** @page how_to_build How to Build and Run Examples
27
28@tableofcontents
29
30@section S1_1_build_options Build options
31
32scons 2.3 or above is required to build the library.
33To see the build options available simply run ```scons -h```:
34
35 debug: Debug (yes|no)
36 default: False
37
38 asserts: Enable asserts (this flag is forced to 1 for debug=1) (yes|no)
39 default: False
40
41 logging: Logging (this flag is forced to 1 for debug=1) (yes|no)
42 default: False
43
Gunes Bayiree905002022-02-25 15:20:00 +000044 arch: Target Architecture (armv7a|x86_32|x86_64|armv8a|armv8.2-a|armv8.2-a-sve|armv8.2-a-sve2|armv8.6-a|armv8.6-a-sve|armv8.6-a-sve2|armv8r64|x86)
Sheri Zhangd813bab2021-04-30 16:53:41 +010045 default: armv7a
46
47 estate: Execution State (auto|32|64)
48 default: auto
49
50 os: Target OS (linux|android|macos|tizen|bare_metal)
51 default: linux
52
53 build: Build type (native|cross_compile|embed_only)
54 default: cross_compile
55
56 examples: Build example programs (yes|no)
57 default: True
58
59 gemm_tuner: Build gemm_tuner programs (yes|no)
60 default: True
61
62 Werror: Enable/disable the -Werror compilation flag (yes|no)
63 default: True
64
65 standalone: Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute (yes|no)
66 default: False
67
68 opencl: Enable OpenCL support (yes|no)
69 default: True
70
71 neon: Enable Arm® Neon™ support (yes|no)
72 default: False
73
74 embed_kernels: Embed OpenCL kernels in library binary (yes|no)
75 default: True
76
77 compress_kernels: Compress embedded OpenCL kernels in library binary. Note embed_kernels should be enabled as well (yes|no)
78 default: False
79
80 set_soname: Set the library's soname and shlibversion (requires SCons 2.4 or above) (yes|no)
81 default: False
82
83 openmp: Enable OpenMP backend (yes|no)
84 default: False
85
86 cppthreads: Enable C++11 threads backend (yes|no)
87 default: True
88
89 build_dir: Specify sub-folder for the build ( /path/to/build_dir )
90 default: .
91
92 install_dir: Specify sub-folder for the install ( /path/to/install_dir )
93 default:
94
95 exceptions: Enable/disable C++ exception support (yes|no)
96 default: True
97
98 linker_script: Use an external linker script ( /path/to/linker_script )
99 default:
100
101 custom_options: Custom options that can be used to turn on/off features
102 (all|none|comma-separated list of names)
103 allowed names: disable_mmla_fp
104 default: none
105
106 data_type_support: Enable a list of data types to support
107 (all|none|comma-separated list of names)
108 allowed names: qasymm8 qasymm8_signed qsymm16 fp16 fp32
109 default: all
110
111 toolchain_prefix: Override the toolchain prefix
112 default:
113
114 compiler_prefix: Override the compiler prefix
115 default:
116
117 extra_cxx_flags: Extra CXX flags to be appended to the build command
118 default:
119
120 extra_link_flags: Extra LD flags to be appended to the build command
121 default:
122
123 compiler_cache: Command to prefix to the C and C++ compiler (e.g ccache)
124 default:
125
126 specs_file: Specs file to use
127 default: rdimon.specs
128
129 benchmark_examples: Build benchmark examples programs (yes|no)
130 default: False
131
132 validate_examples: Build validate examples programs (yes|no)
133 default: False
134
135 reference_openmp: Build reference validation with openmp (yes|no)
136 default: True
137
138 validation_tests: Build validation test programs (yes|no)
139 default: False
140
141 benchmark_tests: Build benchmark test programs (yes|no)
142 default: False
143
144 test_filter: Pattern to specify the tests' filenames to be compiled
145 default: *.cpp
146
147 pmu: Enable PMU counters (yes|no)
148 default: False
149
150 mali: Enable Arm® Mali™ hardware counters (yes|no)
151 default: False
152
153 external_tests_dir: Add examples, benchmarks and tests to the tests suite from an external path ( /path/to/external_tests_dir )
154 default:
155
Freddie Liardetf289e572021-08-06 09:12:26 +0100156 high_priority: Generate a library using only the high priority operators
157 default: False
158
159 data_layout_support: Enable a list of data layout to support
160 default: False
161
Sheri Zhangd813bab2021-04-30 16:53:41 +0100162@b debug / @b asserts:
163 - With debug=1 asserts are enabled, and the library is built with symbols and no optimisations enabled.
164 - With debug=0 and asserts=1: Optimisations are enabled and symbols are removed, however all the asserts are still present (This is about 20% slower than the release build)
165 - With debug=0 and asserts=0: All optimisations are enable and no validation is performed, if the application misuses the library it is likely to result in a crash. (Only use this mode once you are sure your application is working as expected).
166
167@b arch: The x86_32 and x86_64 targets can only be used with neon=0 and opencl=1.
168
169@b os: Choose the operating system you are targeting: Linux, Android or bare metal.
Jakub Sujakee301b32021-06-04 09:46:08 +0100170@note bare metal can only be used for Arm® Neon™ (not OpenCL), only static libraries get built and Neon™'s multi-threading support is disabled.
Sheri Zhangd813bab2021-04-30 16:53:41 +0100171
172@b build: you can either build directly on your device (native) or cross compile from your desktop machine (cross-compile). In both cases make sure the compiler is available in your path.
173
174@note If you want to natively compile for 32bit on a 64bit Arm device running a 64bit OS then you will have to use cross-compile too.
175
176There is also an 'embed_only' option which will generate all the .embed files for the OpenCL kernels. This might be useful if using a different build system to compile the library.
177
Jakub Sujakee301b32021-06-04 09:46:08 +0100178In addition the option 'compress_kernels' will compress the embedded OpenCL kernel files using zlib and inject them in the library. This is useful for reducing the binary size. Note, this option is only available for Android when 'embed_kernels' is enabled.
Sheri Zhangd813bab2021-04-30 16:53:41 +0100179
180@b Werror: If you are compiling using the same toolchains as the ones used in this guide then there shouldn't be any warning and therefore you should be able to keep Werror=1. If with a different compiler version the library fails to build because of warnings interpreted as errors then, if you are sure the warnings are not important, you might want to try to build with Werror=0 (But please do report the issue on Github).
181
Jakub Sujakee301b32021-06-04 09:46:08 +0100182@b opencl / @b neon: Choose which SIMD technology you want to target. (Neon™ for Arm® Cortex®-A CPUs or OpenCL for Arm® Mali™ GPUs)
Sheri Zhangd813bab2021-04-30 16:53:41 +0100183
184@b embed_kernels: For OpenCL only: set embed_kernels=1 if you want the OpenCL kernels to be built in the library's binaries instead of being read from separate ".cl" / ".cs" files. If embed_kernels is set to 0 then the application can set the path to the folder containing the OpenCL kernel files by calling CLKernelLibrary::init(). By default the path is set to "./cl_kernels".
185
186@b set_soname: Do you want to build the versioned version of the library ?
187
188If enabled the library will contain a SONAME and SHLIBVERSION and some symlinks will automatically be created between the objects.
189Example:
190 libarm_compute_core.so -> libarm_compute_core.so.1.0.0
191 libarm_compute_core.so.1 -> libarm_compute_core.so.1.0.0
192 libarm_compute_core.so.1.0.0
193
194@note This options is disabled by default as it requires SCons version 2.4 or above.
195
196@b extra_cxx_flags: Custom CXX flags which will be appended to the end of the build command.
197
198@b build_dir: Build the library in a subfolder of the "build" folder. (Allows to build several configurations in parallel).
199
200@b examples: Build or not the examples
201
202@b validation_tests: Enable the build of the validation suite.
203
204@b benchmark_tests: Enable the build of the benchmark tests
205
206@b pmu: Enable the PMU cycle counter to measure execution time in benchmark tests. (Your device needs to support it)
207
208@b mali: Enable the collection of Arm® Mali™ hardware counters to measure execution time in benchmark tests. (Your device needs to have a Arm® Mali™ driver that supports it)
209
Freddie Liardetf289e572021-08-06 09:12:26 +0100210@b openmp: Build in the OpenMP scheduler for Neon™.
Sheri Zhangd813bab2021-04-30 16:53:41 +0100211
212@note Only works when building with g++ not clang++
213
Freddie Liardetf289e572021-08-06 09:12:26 +0100214@b cppthreads: Build in the C++11 scheduler for Neon™.
Sheri Zhangd813bab2021-04-30 16:53:41 +0100215
216@sa Scheduler::set
217
Freddie Liardetf289e572021-08-06 09:12:26 +0100218@b external_tests_dir: Add examples, benchmarks and tests to the tests suite from an external path ( /path/to/external_tests_dir )
Sheri Zhangd813bab2021-04-30 16:53:41 +0100219
220In order to use this option, the external tests directory must have the following structure:
221
222 EXTERNAL_TESTS_DIR:
223 └── tests
224 ├── benchmark
225 │   ├── CL
226 │   ├── datasets
227 │   ├── fixtures
228 │   └── Neon
229 └── validation
230    ├── CL
231     ├── datasets
232     ├── fixtures
233     └── Neon
234
235Then, build the library with `external_tests_dir=<PATH_TO_EXTERNAL_TESTS_DIR>`.
236
Freddie Liardetf289e572021-08-06 09:12:26 +0100237@b high_priority: Generate a library using only the high priority operators
238
239@b data_layout_support: Enable a list of data layout to support
240
Sheri Zhangd813bab2021-04-30 16:53:41 +0100241@section S1_2_linux Building for Linux
242
243@subsection S1_2_1_library How to build the library ?
244
245For Linux, the library was successfully built and tested using the following Linaro GCC toolchain:
246
247 - gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf
248 - gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu
249
250To cross-compile the library in debug mode, with Arm® Neon™ only support, for Linux 32bit:
251
252 scons Werror=1 -j8 debug=1 neon=1 opencl=0 os=linux arch=armv7a
253
254To cross-compile the library in asserts mode, with OpenCL only support, for Linux 64bit:
255
Gunes Bayiree905002022-02-25 15:20:00 +0000256 scons Werror=1 -j8 debug=0 asserts=1 neon=0 opencl=1 embed_kernels=1 os=linux arch=armv8a
Sheri Zhangd813bab2021-04-30 16:53:41 +0100257
258You can also compile the library natively on an Arm device by using <b>build=native</b>:
259
Gunes Bayiree905002022-02-25 15:20:00 +0000260 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv8a build=native
Sheri Zhangd813bab2021-04-30 16:53:41 +0100261 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a build=native
262
263@note g++ for Arm is mono-arch, therefore if you want to compile for Linux 32bit on a Linux 64bit platform you will have to use a cross compiler.
264
265For example on a 64bit Debian based system you would have to install <b>g++-arm-linux-gnueabihf</b>
266
267 apt-get install g++-arm-linux-gnueabihf
268
269Then run
270
271 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a build=cross_compile
272
273or simply remove the build parameter as build=cross_compile is the default value:
274
275 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a
276
277@subsection S1_2_2_examples How to manually build the examples ?
278
279The examples get automatically built by scons as part of the build process of the library described above. This section just describes how you can build and link your own application against our library.
280
281@note The following command lines assume the arm_compute libraries are present in the current directory or in the system library path. If this is not the case you can specify the location of the pre-built libraries with the compiler option -L. When building the OpenCL example the commands below assume that the CL headers are located in the include folder where the command is executed.
282
283To cross compile a Arm® Neon™ example for Linux 32bit:
284
Jakub Sujakee301b32021-06-04 09:46:08 +0100285 arm-linux-gnueabihf-g++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -mfpu=neon -L. -larm_compute -larm_compute_core -o neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +0100286
287To cross compile a Arm® Neon™ example for Linux 64bit:
288
Jakub Sujakee301b32021-06-04 09:46:08 +0100289 aarch64-linux-gnu-g++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -L. -larm_compute -larm_compute_core -o neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +0100290
291(notice the only difference with the 32 bit command is that we don't need the -mfpu option and the compiler's name is different)
292
293To cross compile an OpenCL example for Linux 32bit:
294
Jakub Sujakee301b32021-06-04 09:46:08 +0100295 arm-linux-gnueabihf-g++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -mfpu=neon -L. -larm_compute -larm_compute_core -o cl_sgemm -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +0100296
297To cross compile an OpenCL example for Linux 64bit:
298
Jakub Sujakee301b32021-06-04 09:46:08 +0100299 aarch64-linux-gnu-g++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -L. -larm_compute -larm_compute_core -o cl_sgemm -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +0100300
301(notice the only difference with the 32 bit command is that we don't need the -mfpu option and the compiler's name is different)
302
303To cross compile the examples with the Graph API, such as graph_lenet.cpp, you need to link the examples against arm_compute_graph.so too.
304
305i.e. to cross compile the "graph_lenet" example for Linux 32bit:
306
307 arm-linux-gnueabihf-g++ examples/graph_lenet.cpp utils/Utils.cpp utils/GraphUtils.cpp utils/CommonGraphOptions.cpp -I. -Iinclude -std=c++14 -mfpu=neon -L. -larm_compute_graph -larm_compute -larm_compute_core -Wl,--allow-shlib-undefined -o graph_lenet
308
309i.e. to cross compile the "graph_lenet" example for Linux 64bit:
310
311 aarch64-linux-gnu-g++ examples/graph_lenet.cpp utils/Utils.cpp utils/GraphUtils.cpp utils/CommonGraphOptions.cpp -I. -Iinclude -std=c++14 -L. -larm_compute_graph -larm_compute -larm_compute_core -Wl,--allow-shlib-undefined -o graph_lenet
312
313(notice the only difference with the 32 bit command is that we don't need the -mfpu option and the compiler's name is different)
314
315@note If compiling using static libraries, this order must be followed when linking: arm_compute_graph_static, arm_compute, arm_compute_core
316
317To compile natively (i.e directly on an Arm device) for Arm® Neon™ for Linux 32bit:
318
Jakub Sujakee301b32021-06-04 09:46:08 +0100319 g++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -mfpu=neon -larm_compute -larm_compute_core -o neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +0100320
321To compile natively (i.e directly on an Arm device) for Arm® Neon™ for Linux 64bit:
322
Jakub Sujakee301b32021-06-04 09:46:08 +0100323 g++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute -larm_compute_core -o neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +0100324
325(notice the only difference with the 32 bit command is that we don't need the -mfpu option)
326
327To compile natively (i.e directly on an Arm device) for OpenCL for Linux 32bit or Linux 64bit:
328
Jakub Sujakee301b32021-06-04 09:46:08 +0100329 g++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute -larm_compute_core -o cl_sgemm -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +0100330
331To compile natively the examples with the Graph API, such as graph_lenet.cpp, you need to link the examples against arm_compute_graph.so too.
332
333i.e. to natively compile the "graph_lenet" example for Linux 32bit:
334
335 g++ examples/graph_lenet.cpp utils/Utils.cpp utils/GraphUtils.cpp utils/CommonGraphOptions.cpp -I. -Iinclude -std=c++14 -mfpu=neon -L. -larm_compute_graph -larm_compute -larm_compute_core -Wl,--allow-shlib-undefined -o graph_lenet
336
337i.e. to natively compile the "graph_lenet" example for Linux 64bit:
338
339 g++ examples/graph_lenet.cpp utils/Utils.cpp utils/GraphUtils.cpp utils/CommonGraphOptions.cpp -I. -Iinclude -std=c++14 -L. -larm_compute_graph -larm_compute -larm_compute_core -Wl,--allow-shlib-undefined -o graph_lenet
340
341(notice the only difference with the 32 bit command is that we don't need the -mfpu option)
342
343@note If compiling using static libraries, this order must be followed when linking: arm_compute_graph_static, arm_compute, arm_compute_core
344
Gunes Bayiree905002022-02-25 15:20:00 +0000345@note These two commands assume libarm_compute.so is available in your library path, if not add the path to it using -L (e.g. -Llib/linux-armv8a-neon-cl-asserts/)
Sheri Zhangd813bab2021-04-30 16:53:41 +0100346@note You might need to export the path to OpenCL library as well in your LD_LIBRARY_PATH if Compute Library was built with OpenCL enabled.
347
348To run the built executable simply run:
349
Jakub Sujakee301b32021-06-04 09:46:08 +0100350 LD_LIBRARY_PATH=build ./neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +0100351
352or
353
Jakub Sujakee301b32021-06-04 09:46:08 +0100354 LD_LIBRARY_PATH=build ./cl_sgemm
Sheri Zhangd813bab2021-04-30 16:53:41 +0100355
356@note Examples accept different types of arguments, to find out what they are run the example with \a --help as an argument. If no arguments are specified then random values will be used to execute the graph.
357
358For example:
359
360 LD_LIBRARY_PATH=. ./graph_lenet --help
361
362Below is a list of the common parameters among the graph examples :
363@snippet utils/CommonGraphOptions.h Common graph examples parameters
364
365@subsection S1_2_3_sve Build for SVE or SVE2
366
367In order to build for SVE or SVE2 you need a compiler that supports them. You can find more information in the following these links:
368 -# GCC: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/sve-support
369 -# LLVM: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/llvm-toolchain/sve-support
370
371@note You the need to indicate the toolchains using the scons "toolchain_prefix" parameter.
372
373An example build command with SVE is:
374
Gunes Bayiree905002022-02-25 15:20:00 +0000375 scons arch=armv8.2-a-sve os=linux build_dir=arm64 -j55 standalone=0 opencl=0 openmp=0 validation_tests=1 neon=1 cppthreads=1 toolchain_prefix=aarch64-none-linux-gnu-
Sheri Zhangd813bab2021-04-30 16:53:41 +0100376
377@section S1_3_android Building for Android
378
379For Android, the library was successfully built and tested using Google's standalone toolchains:
380 - clang++ from NDK r18b for armv7a
Gunes Bayiree905002022-02-25 15:20:00 +0000381 - clang++ from NDK r20b for armv8a
382 - clang++ from NDK r20b for armv8.2-a with FP16 support
Sheri Zhangd813bab2021-04-30 16:53:41 +0100383
384For NDK r18 or older, here is a guide to <a href="https://developer.android.com/ndk/guides/standalone_toolchain.html">create your Android standalone toolchains from the NDK</a>:
385- Download the NDK r18b from here: https://developer.android.com/ndk/downloads/index.html to directory $NDK
386- Make sure you have Python 2.7 installed on your machine.
Jakub Sujakee301b32021-06-04 09:46:08 +0100387- Generate the 32 and/or 64 toolchains by running the following commands to your toolchain directory $MY_TOOLCHAINS:
Sheri Zhangd813bab2021-04-30 16:53:41 +0100388
389 $NDK/build/tools/make_standalone_toolchain.py --arch arm64 --install-dir $MY_TOOLCHAINS/aarch64-linux-android-ndk-r18b --stl libc++ --api 21
390 $NDK/build/tools/make_standalone_toolchain.py --arch arm --install-dir $MY_TOOLCHAINS/arm-linux-android-ndk-r18b --stl libc++ --api 21
391
392For NDK r19 or newer, you can directly <a href="https://developer.android.com/ndk/downloads">Download</a> the NDK package for your development platform, without the need to launch the make_standalone_toolchain.py script. You can find all the prebuilt binaries inside $NDK/toolchains/llvm/prebuilt/$OS_ARCH/bin/.
393@attention the building script will look for a binary named "aarch64-linux-android-clang++", while the prebuilt binaries will have their API version as a suffix to their filename (e.g. "aarch64-linux-android21-clang++"). You should copy/rename the binary removing this suffix, or - alternatively - create an alias for it.
394
395@attention We used to use gnustl but as of NDK r17 it is deprecated so we switched to libc++
396
397@note Make sure to add the toolchains to your PATH:
398
399 export PATH=$PATH:$MY_TOOLCHAINS/aarch64-linux-android-ndk-r18b/bin:$MY_TOOLCHAINS/arm-linux-android-ndk-r18b/bin
400
401@subsection S1_3_1_library How to build the library ?
402
403To cross-compile the library in debug mode, with Arm® Neon™ only support, for Android 32bit:
404
405 CXX=clang++ CC=clang scons Werror=1 -j8 debug=1 neon=1 opencl=0 os=android arch=armv7a
406
407To cross-compile the library in asserts mode, with OpenCL only support, for Android 64bit:
408
Gunes Bayiree905002022-02-25 15:20:00 +0000409 CXX=clang++ CC=clang scons Werror=1 -j8 debug=0 asserts=1 neon=0 opencl=1 embed_kernels=1 os=android arch=armv8a
Sheri Zhangd813bab2021-04-30 16:53:41 +0100410
411@subsection S1_3_2_examples How to manually build the examples ?
412
413The examples get automatically built by scons as part of the build process of the library described above. This section just describes how you can build and link your own application against our library.
414
415@note The following command lines assume the arm_compute libraries are present in the current directory or in the system library path. If this is not the case you can specify the location of the pre-built libraries with the compiler option -L. When building the OpenCL example the commands below assume that the CL headers are located in the include folder where the command is executed.
416
417Once you've got your Android standalone toolchain built and added to your path you can do the following:
418
419To cross compile a Arm® Neon™ example:
420
421 #32 bit:
Jakub Sujakee301b32021-06-04 09:46:08 +0100422 arm-linux-androideabi-clang++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute-static -larm_compute_core-static -L. -o neon_cnn_arm -static-libstdc++ -pie
Sheri Zhangd813bab2021-04-30 16:53:41 +0100423 #64 bit:
Jakub Sujakee301b32021-06-04 09:46:08 +0100424 aarch64-linux-android-clang++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute-static -larm_compute_core-static -L. -o neon_cnn_aarch64 -static-libstdc++ -pie
Sheri Zhangd813bab2021-04-30 16:53:41 +0100425
426To cross compile an OpenCL example:
427
428 #32 bit:
Jakub Sujakee301b32021-06-04 09:46:08 +0100429 arm-linux-androideabi-clang++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute-static -larm_compute_core-static -L. -o cl_sgemm_arm -static-libstdc++ -pie -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +0100430 #64 bit:
Jakub Sujakee301b32021-06-04 09:46:08 +0100431 aarch64-linux-android-clang++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute-static -larm_compute_core-static -L. -o cl_sgemm_aarch64 -static-libstdc++ -pie -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +0100432
433To cross compile the examples with the Graph API, such as graph_lenet.cpp, you need to link the library arm_compute_graph also.
434
435 #32 bit:
436 arm-linux-androideabi-clang++ examples/graph_lenet.cpp utils/Utils.cpp utils/GraphUtils.cpp utils/CommonGraphOptions.cpp -I. -Iinclude -std=c++14 -Wl,--whole-archive -larm_compute_graph-static -Wl,--no-whole-archive -larm_compute-static -larm_compute_core-static -L. -o graph_lenet_arm -static-libstdc++ -pie -DARM_COMPUTE_CL
437 #64 bit:
438 aarch64-linux-android-clang++ examples/graph_lenet.cpp utils/Utils.cpp utils/GraphUtils.cpp utils/CommonGraphOptions.cpp -I. -Iinclude -std=c++14 -Wl,--whole-archive -larm_compute_graph-static -Wl,--no-whole-archive -larm_compute-static -larm_compute_core-static -L. -o graph_lenet_aarch64 -static-libstdc++ -pie -DARM_COMPUTE_CL
439
440@note Due to some issues in older versions of the Arm® Mali™ OpenCL DDK (<= r13p0), we recommend to link arm_compute statically on Android.
441@note When linked statically the arm_compute_graph library currently needs the --whole-archive linker flag in order to work properly
442
443Then you need to do is upload the executable and the shared library to the device using ADB:
444
Jakub Sujakee301b32021-06-04 09:46:08 +0100445 adb push neon_cnn_arm /data/local/tmp/
446 adb push cl_sgemm_arm /data/local/tmp/
Sheri Zhangd813bab2021-04-30 16:53:41 +0100447 adb push gc_absdiff_arm /data/local/tmp/
448 adb shell chmod 777 -R /data/local/tmp/
449
450And finally to run the example:
451
Jakub Sujakee301b32021-06-04 09:46:08 +0100452 adb shell /data/local/tmp/neon_cnn_arm
453 adb shell /data/local/tmp/cl_sgemm_arm
Sheri Zhangd813bab2021-04-30 16:53:41 +0100454 adb shell /data/local/tmp/gc_absdiff_arm
455
456For 64bit:
457
Jakub Sujakee301b32021-06-04 09:46:08 +0100458 adb push neon_cnn_aarch64 /data/local/tmp/
459 adb push cl_sgemm_aarch64 /data/local/tmp/
Sheri Zhangd813bab2021-04-30 16:53:41 +0100460 adb push gc_absdiff_aarch64 /data/local/tmp/
461 adb shell chmod 777 -R /data/local/tmp/
462
463And finally to run the example:
464
Jakub Sujakee301b32021-06-04 09:46:08 +0100465 adb shell /data/local/tmp/neon_cnn_aarch64
466 adb shell /data/local/tmp/cl_sgemm_aarch64
Sheri Zhangd813bab2021-04-30 16:53:41 +0100467 adb shell /data/local/tmp/gc_absdiff_aarch64
468
469@note Examples accept different types of arguments, to find out what they are run the example with \a --help as an argument. If no arguments are specified then random values will be used to execute the graph.
470
471For example:
472 adb shell /data/local/tmp/graph_lenet --help
473
Jakub Sujakee301b32021-06-04 09:46:08 +0100474In this case the first argument of LeNet (like all the graph examples) is the target (i.e 0 to run on Neon™, 1 to run on OpenCL if available, 2 to run on OpenCL using the CLTuner), the second argument is the path to the folder containing the npy files for the weights and finally the third argument is the number of batches to run.
Sheri Zhangd813bab2021-04-30 16:53:41 +0100475
476@section S1_4_macos Building for macOS
477
478The library was successfully natively built for Apple Silicon under macOS 11.1 using clang v12.0.0.
479
480To natively compile the library with accelerated CPU support:
481
Gunes Bayiree905002022-02-25 15:20:00 +0000482 scons Werror=1 -j8 neon=1 opencl=0 os=macos arch=armv8a build=native
Sheri Zhangd813bab2021-04-30 16:53:41 +0100483
484@note Initial support disables feature discovery through HWCAPS and thread scheduling affinity controls
485
486@section S1_5_bare_metal Building for bare metal
487
488For bare metal, the library was successfully built using linaro's latest (gcc-linaro-6.3.1-2017.05) bare metal toolchains:
489 - arm-eabi for armv7a
Gunes Bayiree905002022-02-25 15:20:00 +0000490 - aarch64-elf for armv8a
Sheri Zhangd813bab2021-04-30 16:53:41 +0100491
Gunes Bayiree905002022-02-25 15:20:00 +0000492Download linaro for <a href="https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/arm-eabi/">armv7a</a> and <a href="https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/aarch64-elf/">armv8a</a>.
Sheri Zhangd813bab2021-04-30 16:53:41 +0100493
494@note Make sure to add the toolchains to your PATH: export PATH=$PATH:$MY_TOOLCHAINS/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-elf/bin:$MY_TOOLCHAINS/gcc-linaro-6.3.1-2017.05-x86_64_arm-eabi/bin
495
496@subsection S1_5_1_library How to build the library ?
497
Gunes Bayiree905002022-02-25 15:20:00 +0000498To cross-compile the library with Arm® Neon™ support for baremetal armv8a:
Sheri Zhangd813bab2021-04-30 16:53:41 +0100499
Gunes Bayiree905002022-02-25 15:20:00 +0000500 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=bare_metal arch=armv8a build=cross_compile cppthreads=0 openmp=0 standalone=1
Sheri Zhangd813bab2021-04-30 16:53:41 +0100501
502@subsection S1_5_2_examples How to manually build the examples ?
503
504Examples are disabled when building for bare metal. If you want to build the examples you need to provide a custom bootcode depending on the target architecture and link against the compute library. More information about bare metal bootcode can be found <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0527a/index.html">here</a>.
505
506@section S1_6_windows_host Building on a Windows host system
507
508Using `scons` directly from the Windows command line is known to cause
509problems. The reason seems to be that if `scons` is setup for cross-compilation
510it gets confused about Windows style paths (using backslashes). Thus it is
511recommended to follow one of the options outlined below.
512
513@subsection S1_6_1_ubuntu_on_windows Bash on Ubuntu on Windows
514
515The best and easiest option is to use
516<a href="https://msdn.microsoft.com/en-gb/commandline/wsl/about">Ubuntu on Windows</a>.
517This feature is still marked as *beta* and thus might not be available.
518However, if it is building the library is as simple as opening a *Bash on
519Ubuntu on Windows* shell and following the general guidelines given above.
520
521@subsection S1_6_2_cygwin Cygwin
522
523If the Windows subsystem for Linux is not available <a href="https://www.cygwin.com/">Cygwin</a>
524can be used to install and run `scons`, the minimum Cygwin version must be 3.0.7 or later. In addition
525to the default packages installed by Cygwin `scons` has to be selected in the installer. (`git` might
526also be useful but is not strictly required if you already have got the source
527code of the library.) Linaro provides pre-built versions of
528<a href="http://releases.linaro.org/components/toolchain/binaries/">GCC cross-compilers</a>
529that can be used from the Cygwin terminal. When building for Android the
530compiler is included in the Android standalone toolchain. After everything has
531been set up in the Cygwin terminal the general guide on building the library
532can be followed.
533
534@section S1_7_cl_requirements OpenCL DDK Requirements
535
536@subsection S1_7_1_cl_hard_requirements Hard Requirements
537
538Compute Library requires OpenCL 1.1 and above with support of non uniform workgroup sizes, which is officially supported in the Arm® Mali™ OpenCL DDK r8p0 and above as an extension (respective extension flag is \a -cl-arm-non-uniform-work-group-size).
539
540Enabling 16-bit floating point calculations require \a cl_khr_fp16 extension to be supported. All Arm® Mali™ GPUs with compute capabilities have native support for half precision floating points.
541
542@subsection S1_7_2_cl_performance_requirements Performance improvements
543
544Integer dot product built-in function extensions (and therefore optimized kernels) are available with Arm® Mali™ OpenCL DDK r22p0 and above for the following GPUs : G71, G76. The relevant extensions are \a cl_arm_integer_dot_product_int8, \a cl_arm_integer_dot_product_accumulate_int8 and \a cl_arm_integer_dot_product_accumulate_int16.
545
546OpenCL kernel level debugging can be simplified with the use of printf, this requires the \a cl_arm_printf extension to be supported.
547
548SVM allocations are supported for all the underlying allocations in Compute Library. To enable this OpenCL 2.0 and above is a requirement.
549
550*/
551} // namespace arm_compute