blob: 1766199eb46d3a68c3bbe2fdcd8036a16fd0f630 [file] [log] [blame]
Sheri Zhangd813bab2021-04-30 16:53:41 +01001///
2/// Copyright (c) 2017-2021 Arm Limited.
3///
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
44 arch: Target Architecture (armv7a|arm64-v8a|arm64-v8.2-a|arm64-v8.2-a-sve|arm64-v8.2-a-sve2|x86_32|x86_64|armv8a|armv8.2-a|armv8.2-a-sve|armv8.6-a|armv8.6-a-sve|armv8.6-a-sve2|armv8r64|x86)
45 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
156@b debug / @b asserts:
157 - With debug=1 asserts are enabled, and the library is built with symbols and no optimisations enabled.
158 - 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)
159 - 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).
160
161@b arch: The x86_32 and x86_64 targets can only be used with neon=0 and opencl=1.
162
163@b os: Choose the operating system you are targeting: Linux, Android or bare metal.
Jakub Sujakee301b32021-06-04 09:46:08 +0100164@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 +0100165
166@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.
167
168@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.
169
170There 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.
171
Jakub Sujakee301b32021-06-04 09:46:08 +0100172In 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 +0100173
174@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).
175
Jakub Sujakee301b32021-06-04 09:46:08 +0100176@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 +0100177
178@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".
179
180@b set_soname: Do you want to build the versioned version of the library ?
181
182If enabled the library will contain a SONAME and SHLIBVERSION and some symlinks will automatically be created between the objects.
183Example:
184 libarm_compute_core.so -> libarm_compute_core.so.1.0.0
185 libarm_compute_core.so.1 -> libarm_compute_core.so.1.0.0
186 libarm_compute_core.so.1.0.0
187
188@note This options is disabled by default as it requires SCons version 2.4 or above.
189
190@b extra_cxx_flags: Custom CXX flags which will be appended to the end of the build command.
191
192@b build_dir: Build the library in a subfolder of the "build" folder. (Allows to build several configurations in parallel).
193
194@b examples: Build or not the examples
195
196@b validation_tests: Enable the build of the validation suite.
197
198@b benchmark_tests: Enable the build of the benchmark tests
199
200@b pmu: Enable the PMU cycle counter to measure execution time in benchmark tests. (Your device needs to support it)
201
202@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)
203
Jakub Sujakee301b32021-06-04 09:46:08 +0100204@b openmp Build in the OpenMP scheduler for Neon™.
Sheri Zhangd813bab2021-04-30 16:53:41 +0100205
206@note Only works when building with g++ not clang++
207
Jakub Sujakee301b32021-06-04 09:46:08 +0100208@b cppthreads Build in the C++11 scheduler for Neon™.
Sheri Zhangd813bab2021-04-30 16:53:41 +0100209
210@sa Scheduler::set
211
212@b external_tests_dir Add examples, benchmarks and tests to the tests suite from an external path ( /path/to/external_tests_dir )
213
214In order to use this option, the external tests directory must have the following structure:
215
216 EXTERNAL_TESTS_DIR:
217 └── tests
218 ├── benchmark
219 │   ├── CL
220 │   ├── datasets
221 │   ├── fixtures
222 │   └── Neon
223 └── validation
224    ├── CL
225     ├── datasets
226     ├── fixtures
227     └── Neon
228
229Then, build the library with `external_tests_dir=<PATH_TO_EXTERNAL_TESTS_DIR>`.
230
231@section S1_2_linux Building for Linux
232
233@subsection S1_2_1_library How to build the library ?
234
235For Linux, the library was successfully built and tested using the following Linaro GCC toolchain:
236
237 - gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf
238 - gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu
239
240To cross-compile the library in debug mode, with Arm® Neon™ only support, for Linux 32bit:
241
242 scons Werror=1 -j8 debug=1 neon=1 opencl=0 os=linux arch=armv7a
243
244To cross-compile the library in asserts mode, with OpenCL only support, for Linux 64bit:
245
246 scons Werror=1 -j8 debug=0 asserts=1 neon=0 opencl=1 embed_kernels=1 os=linux arch=arm64-v8a
247
248You can also compile the library natively on an Arm device by using <b>build=native</b>:
249
250 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=arm64-v8a build=native
251 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a build=native
252
253@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.
254
255For example on a 64bit Debian based system you would have to install <b>g++-arm-linux-gnueabihf</b>
256
257 apt-get install g++-arm-linux-gnueabihf
258
259Then run
260
261 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a build=cross_compile
262
263or simply remove the build parameter as build=cross_compile is the default value:
264
265 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a
266
267@subsection S1_2_2_examples How to manually build the examples ?
268
269The 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.
270
271@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.
272
273To cross compile a Arm® Neon™ example for Linux 32bit:
274
Jakub Sujakee301b32021-06-04 09:46:08 +0100275 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 +0100276
277To cross compile a Arm® Neon™ example for Linux 64bit:
278
Jakub Sujakee301b32021-06-04 09:46:08 +0100279 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 +0100280
281(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)
282
283To cross compile an OpenCL example for Linux 32bit:
284
Jakub Sujakee301b32021-06-04 09:46:08 +0100285 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 +0100286
287To cross compile an OpenCL example for Linux 64bit:
288
Jakub Sujakee301b32021-06-04 09:46:08 +0100289 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 +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 the examples with the Graph API, such as graph_lenet.cpp, you need to link the examples against arm_compute_graph.so too.
294
295i.e. to cross compile the "graph_lenet" example for Linux 32bit:
296
297 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
298
299i.e. to cross compile the "graph_lenet" example for Linux 64bit:
300
301 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
302
303(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)
304
305@note If compiling using static libraries, this order must be followed when linking: arm_compute_graph_static, arm_compute, arm_compute_core
306
307To compile natively (i.e directly on an Arm device) for Arm® Neon™ for Linux 32bit:
308
Jakub Sujakee301b32021-06-04 09:46:08 +0100309 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 +0100310
311To compile natively (i.e directly on an Arm device) for Arm® Neon™ for Linux 64bit:
312
Jakub Sujakee301b32021-06-04 09:46:08 +0100313 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 +0100314
315(notice the only difference with the 32 bit command is that we don't need the -mfpu option)
316
317To compile natively (i.e directly on an Arm device) for OpenCL for Linux 32bit or Linux 64bit:
318
Jakub Sujakee301b32021-06-04 09:46:08 +0100319 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 +0100320
321To 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.
322
323i.e. to natively compile the "graph_lenet" example for Linux 32bit:
324
325 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
326
327i.e. to natively compile the "graph_lenet" example for Linux 64bit:
328
329 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
330
331(notice the only difference with the 32 bit command is that we don't need the -mfpu option)
332
333@note If compiling using static libraries, this order must be followed when linking: arm_compute_graph_static, arm_compute, arm_compute_core
334
335@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-arm64-v8a-neon-cl-asserts/)
336@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.
337
338To run the built executable simply run:
339
Jakub Sujakee301b32021-06-04 09:46:08 +0100340 LD_LIBRARY_PATH=build ./neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +0100341
342or
343
Jakub Sujakee301b32021-06-04 09:46:08 +0100344 LD_LIBRARY_PATH=build ./cl_sgemm
Sheri Zhangd813bab2021-04-30 16:53:41 +0100345
346@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.
347
348For example:
349
350 LD_LIBRARY_PATH=. ./graph_lenet --help
351
352Below is a list of the common parameters among the graph examples :
353@snippet utils/CommonGraphOptions.h Common graph examples parameters
354
355@subsection S1_2_3_sve Build for SVE or SVE2
356
357In order to build for SVE or SVE2 you need a compiler that supports them. You can find more information in the following these links:
358 -# GCC: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/sve-support
359 -# LLVM: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/llvm-toolchain/sve-support
360
361@note You the need to indicate the toolchains using the scons "toolchain_prefix" parameter.
362
363An example build command with SVE is:
364
365 scons arch=arm64-v8.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-
366
367@section S1_3_android Building for Android
368
369For Android, the library was successfully built and tested using Google's standalone toolchains:
370 - clang++ from NDK r18b for armv7a
371 - clang++ from NDK r20b for arm64-v8a
372 - clang++ from NDK r20b for arm64-v8.2-a with FP16 support
373
374For 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>:
375- Download the NDK r18b from here: https://developer.android.com/ndk/downloads/index.html to directory $NDK
376- Make sure you have Python 2.7 installed on your machine.
Jakub Sujakee301b32021-06-04 09:46:08 +0100377- 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 +0100378
379 $NDK/build/tools/make_standalone_toolchain.py --arch arm64 --install-dir $MY_TOOLCHAINS/aarch64-linux-android-ndk-r18b --stl libc++ --api 21
380 $NDK/build/tools/make_standalone_toolchain.py --arch arm --install-dir $MY_TOOLCHAINS/arm-linux-android-ndk-r18b --stl libc++ --api 21
381
382For 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/.
383@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.
384
385@attention We used to use gnustl but as of NDK r17 it is deprecated so we switched to libc++
386
387@note Make sure to add the toolchains to your PATH:
388
389 export PATH=$PATH:$MY_TOOLCHAINS/aarch64-linux-android-ndk-r18b/bin:$MY_TOOLCHAINS/arm-linux-android-ndk-r18b/bin
390
391@subsection S1_3_1_library How to build the library ?
392
393To cross-compile the library in debug mode, with Arm® Neon™ only support, for Android 32bit:
394
395 CXX=clang++ CC=clang scons Werror=1 -j8 debug=1 neon=1 opencl=0 os=android arch=armv7a
396
397To cross-compile the library in asserts mode, with OpenCL only support, for Android 64bit:
398
399 CXX=clang++ CC=clang scons Werror=1 -j8 debug=0 asserts=1 neon=0 opencl=1 embed_kernels=1 os=android arch=arm64-v8a
400
401@subsection S1_3_2_examples How to manually build the examples ?
402
403The 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.
404
405@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.
406
407Once you've got your Android standalone toolchain built and added to your path you can do the following:
408
409To cross compile a Arm® Neon™ example:
410
411 #32 bit:
Jakub Sujakee301b32021-06-04 09:46:08 +0100412 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 +0100413 #64 bit:
Jakub Sujakee301b32021-06-04 09:46:08 +0100414 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 +0100415
416To cross compile an OpenCL example:
417
418 #32 bit:
Jakub Sujakee301b32021-06-04 09:46:08 +0100419 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 +0100420 #64 bit:
Jakub Sujakee301b32021-06-04 09:46:08 +0100421 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 +0100422
423To cross compile the examples with the Graph API, such as graph_lenet.cpp, you need to link the library arm_compute_graph also.
424
425 #32 bit:
426 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
427 #64 bit:
428 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
429
430@note Due to some issues in older versions of the Arm® Mali™ OpenCL DDK (<= r13p0), we recommend to link arm_compute statically on Android.
431@note When linked statically the arm_compute_graph library currently needs the --whole-archive linker flag in order to work properly
432
433Then you need to do is upload the executable and the shared library to the device using ADB:
434
Jakub Sujakee301b32021-06-04 09:46:08 +0100435 adb push neon_cnn_arm /data/local/tmp/
436 adb push cl_sgemm_arm /data/local/tmp/
Sheri Zhangd813bab2021-04-30 16:53:41 +0100437 adb push gc_absdiff_arm /data/local/tmp/
438 adb shell chmod 777 -R /data/local/tmp/
439
440And finally to run the example:
441
Jakub Sujakee301b32021-06-04 09:46:08 +0100442 adb shell /data/local/tmp/neon_cnn_arm
443 adb shell /data/local/tmp/cl_sgemm_arm
Sheri Zhangd813bab2021-04-30 16:53:41 +0100444 adb shell /data/local/tmp/gc_absdiff_arm
445
446For 64bit:
447
Jakub Sujakee301b32021-06-04 09:46:08 +0100448 adb push neon_cnn_aarch64 /data/local/tmp/
449 adb push cl_sgemm_aarch64 /data/local/tmp/
Sheri Zhangd813bab2021-04-30 16:53:41 +0100450 adb push gc_absdiff_aarch64 /data/local/tmp/
451 adb shell chmod 777 -R /data/local/tmp/
452
453And finally to run the example:
454
Jakub Sujakee301b32021-06-04 09:46:08 +0100455 adb shell /data/local/tmp/neon_cnn_aarch64
456 adb shell /data/local/tmp/cl_sgemm_aarch64
Sheri Zhangd813bab2021-04-30 16:53:41 +0100457 adb shell /data/local/tmp/gc_absdiff_aarch64
458
459@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.
460
461For example:
462 adb shell /data/local/tmp/graph_lenet --help
463
Jakub Sujakee301b32021-06-04 09:46:08 +0100464In 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 +0100465
466@section S1_4_macos Building for macOS
467
468The library was successfully natively built for Apple Silicon under macOS 11.1 using clang v12.0.0.
469
470To natively compile the library with accelerated CPU support:
471
472 scons Werror=1 -j8 neon=1 opencl=0 os=macos arch=arm64-v8a build=native
473
474@note Initial support disables feature discovery through HWCAPS and thread scheduling affinity controls
475
476@section S1_5_bare_metal Building for bare metal
477
478For bare metal, the library was successfully built using linaro's latest (gcc-linaro-6.3.1-2017.05) bare metal toolchains:
479 - arm-eabi for armv7a
480 - aarch64-elf for arm64-v8a
481
482Download 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/">arm64-v8a</a>.
483
484@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
485
486@subsection S1_5_1_library How to build the library ?
487
488To cross-compile the library with Arm® Neon™ support for baremetal arm64-v8a:
489
490 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=bare_metal arch=arm64-v8a build=cross_compile cppthreads=0 openmp=0 standalone=1
491
492@subsection S1_5_2_examples How to manually build the examples ?
493
494Examples 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>.
495
496@section S1_6_windows_host Building on a Windows host system
497
498Using `scons` directly from the Windows command line is known to cause
499problems. The reason seems to be that if `scons` is setup for cross-compilation
500it gets confused about Windows style paths (using backslashes). Thus it is
501recommended to follow one of the options outlined below.
502
503@subsection S1_6_1_ubuntu_on_windows Bash on Ubuntu on Windows
504
505The best and easiest option is to use
506<a href="https://msdn.microsoft.com/en-gb/commandline/wsl/about">Ubuntu on Windows</a>.
507This feature is still marked as *beta* and thus might not be available.
508However, if it is building the library is as simple as opening a *Bash on
509Ubuntu on Windows* shell and following the general guidelines given above.
510
511@subsection S1_6_2_cygwin Cygwin
512
513If the Windows subsystem for Linux is not available <a href="https://www.cygwin.com/">Cygwin</a>
514can be used to install and run `scons`, the minimum Cygwin version must be 3.0.7 or later. In addition
515to the default packages installed by Cygwin `scons` has to be selected in the installer. (`git` might
516also be useful but is not strictly required if you already have got the source
517code of the library.) Linaro provides pre-built versions of
518<a href="http://releases.linaro.org/components/toolchain/binaries/">GCC cross-compilers</a>
519that can be used from the Cygwin terminal. When building for Android the
520compiler is included in the Android standalone toolchain. After everything has
521been set up in the Cygwin terminal the general guide on building the library
522can be followed.
523
524@section S1_7_cl_requirements OpenCL DDK Requirements
525
526@subsection S1_7_1_cl_hard_requirements Hard Requirements
527
528Compute 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).
529
530Enabling 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.
531
532@subsection S1_7_2_cl_performance_requirements Performance improvements
533
534Integer 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.
535
536OpenCL kernel level debugging can be simplified with the use of printf, this requires the \a cl_arm_printf extension to be supported.
537
538SVM allocations are supported for all the underlying allocations in Compute Library. To enable this OpenCL 2.0 and above is a requirement.
539
540*/
541} // namespace arm_compute