blob: 0b8a23b3682cb8b1e48ac0be9f263db9dfc3d9b4 [file] [log] [blame]
Sheri Zhangd813bab2021-04-30 16:53:41 +01001///
Jakub Sujak9b72a6c2023-11-28 14:40:22 +00002/// Copyright (c) 2017-2024 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.
Michalis Spyroua3f7cd22022-07-04 15:32:02 +010033To see the build options available simply run ```scons -h```
Freddie Liardetf289e572021-08-06 09:12:26 +010034
Sheri Zhangd813bab2021-04-30 16:53:41 +010035@section S1_2_linux Building for Linux
36
37@subsection S1_2_1_library How to build the library ?
38
39For Linux, the library was successfully built and tested using the following Linaro GCC toolchain:
40
41 - gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf
42 - gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu
43
44To cross-compile the library in debug mode, with Arm® Neon™ only support, for Linux 32bit:
45
46 scons Werror=1 -j8 debug=1 neon=1 opencl=0 os=linux arch=armv7a
47
48To cross-compile the library in asserts mode, with OpenCL only support, for Linux 64bit:
49
Gunes Bayiree905002022-02-25 15:20:00 +000050 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 +010051
52You can also compile the library natively on an Arm device by using <b>build=native</b>:
53
Gunes Bayiree905002022-02-25 15:20:00 +000054 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv8a build=native
Sheri Zhangd813bab2021-04-30 16:53:41 +010055 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a build=native
56
57@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.
58
59For example on a 64bit Debian based system you would have to install <b>g++-arm-linux-gnueabihf</b>
60
61 apt-get install g++-arm-linux-gnueabihf
62
63Then run
64
65 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a build=cross_compile
66
67or simply remove the build parameter as build=cross_compile is the default value:
68
69 scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a
70
71@subsection S1_2_2_examples How to manually build the examples ?
72
73The 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.
74
75@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.
76
77To cross compile a Arm® Neon™ example for Linux 32bit:
78
Jakub Sujake30c8742023-11-13 14:57:16 +000079 arm-linux-gnueabihf-g++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -mfpu=neon -L. -larm_compute -o neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +010080
81To cross compile a Arm® Neon™ example for Linux 64bit:
82
Jakub Sujake30c8742023-11-13 14:57:16 +000083 aarch64-linux-gnu-g++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -L. -larm_compute -o neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +010084
85(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)
86
87To cross compile an OpenCL example for Linux 32bit:
88
Jakub Sujake30c8742023-11-13 14:57:16 +000089 arm-linux-gnueabihf-g++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -mfpu=neon -L. -larm_compute -o cl_sgemm -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +010090
91To cross compile an OpenCL example for Linux 64bit:
92
Jakub Sujake30c8742023-11-13 14:57:16 +000093 aarch64-linux-gnu-g++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -L. -larm_compute -o cl_sgemm -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +010094
95(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)
96
97To 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.
98
99i.e. to cross compile the "graph_lenet" example for Linux 32bit:
100
Jakub Sujake30c8742023-11-13 14:57:16 +0000101 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 -Wl,--allow-shlib-undefined -o graph_lenet
Sheri Zhangd813bab2021-04-30 16:53:41 +0100102
103i.e. to cross compile the "graph_lenet" example for Linux 64bit:
104
Jakub Sujake30c8742023-11-13 14:57:16 +0000105 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 -Wl,--allow-shlib-undefined -o graph_lenet
Sheri Zhangd813bab2021-04-30 16:53:41 +0100106
107(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)
108
Jakub Sujake30c8742023-11-13 14:57:16 +0000109@note If compiling using static libraries, this order must be followed when linking: arm_compute_graph_static, arm_compute
Sheri Zhangd813bab2021-04-30 16:53:41 +0100110
111To compile natively (i.e directly on an Arm device) for Arm® Neon™ for Linux 32bit:
112
Jakub Sujake30c8742023-11-13 14:57:16 +0000113 g++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -mfpu=neon -larm_compute -o neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +0100114
115To compile natively (i.e directly on an Arm device) for Arm® Neon™ for Linux 64bit:
116
Jakub Sujake30c8742023-11-13 14:57:16 +0000117 g++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute -o neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +0100118
119(notice the only difference with the 32 bit command is that we don't need the -mfpu option)
120
121To compile natively (i.e directly on an Arm device) for OpenCL for Linux 32bit or Linux 64bit:
122
Jakub Sujake30c8742023-11-13 14:57:16 +0000123 g++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute -o cl_sgemm -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +0100124
125To 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.
126
127i.e. to natively compile the "graph_lenet" example for Linux 32bit:
128
Jakub Sujake30c8742023-11-13 14:57:16 +0000129 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 -Wl,--allow-shlib-undefined -o graph_lenet
Sheri Zhangd813bab2021-04-30 16:53:41 +0100130
131i.e. to natively compile the "graph_lenet" example for Linux 64bit:
132
Jakub Sujake30c8742023-11-13 14:57:16 +0000133 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 -Wl,--allow-shlib-undefined -o graph_lenet
Sheri Zhangd813bab2021-04-30 16:53:41 +0100134
135(notice the only difference with the 32 bit command is that we don't need the -mfpu option)
136
Jakub Sujake30c8742023-11-13 14:57:16 +0000137@note If compiling using static libraries, this order must be followed when linking: arm_compute_graph_static, arm_compute
Sheri Zhangd813bab2021-04-30 16:53:41 +0100138
Gunes Bayiree905002022-02-25 15:20:00 +0000139@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 +0100140@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.
141
142To run the built executable simply run:
143
Jakub Sujakee301b32021-06-04 09:46:08 +0100144 LD_LIBRARY_PATH=build ./neon_cnn
Sheri Zhangd813bab2021-04-30 16:53:41 +0100145
146or
147
Jakub Sujakee301b32021-06-04 09:46:08 +0100148 LD_LIBRARY_PATH=build ./cl_sgemm
Sheri Zhangd813bab2021-04-30 16:53:41 +0100149
150@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.
151
152For example:
153
154 LD_LIBRARY_PATH=. ./graph_lenet --help
155
156Below is a list of the common parameters among the graph examples :
157@snippet utils/CommonGraphOptions.h Common graph examples parameters
158
159@subsection S1_2_3_sve Build for SVE or SVE2
160
161In order to build for SVE or SVE2 you need a compiler that supports them. You can find more information in the following these links:
162 -# GCC: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/sve-support
163 -# LLVM: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/llvm-toolchain/sve-support
164
165@note You the need to indicate the toolchains using the scons "toolchain_prefix" parameter.
166
167An example build command with SVE is:
168
Gunes Bayiree905002022-02-25 15:20:00 +0000169 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 +0100170
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100171@subsection S1_2_4_sme Build for SME2
172
173In order to build for SME2 you need to use a compiler that supports SVE2 and enable SVE2 in the build as well.
174
175@note You the need to indicate the toolchains using the scons "toolchain_prefix" parameter.
176
177An example build command with SME2 is:
178
179 scons arch=armv8.6-a-sve2-sme2 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-
180
Gunes Bayira63ece72023-11-01 10:27:53 +0000181@subsection S1_2_5_clang_build_linux Building with LLVM+Clang Natively on Linux
182
183The library can be built with LLVM+Clang by specifying CC and CXX environment variables appropriately as below. The **minimum** supported clang version is 11, as LLVM 11 introduces SVE/SVE2 VLA intrinsics: https://developer.arm.com/Tools%20and%20Software/LLVM%20Toolchain#Supported-Devices.
184
185 CC=clang CXX=clang++ <build command>
186
187Or, if the environment has multiple clang versions:
188
189 CC=clang-16 CXX=clang++-16
190
191Examples for different build tools look like below.
192
193(experimental) CMake:
194
195 mkdir build
196 cd build
197 CC=clang CXX=clang++ cmake .. -DCMAKE_BUILD_TYPE=Release -DARM_COMPUTE_OPENMP=1 -DARM_COMPUTE_WERROR=0 -DARM_COMPUTE_BUILD_EXAMPLES=1 -DARM_COMPUTE_BUILD_TESTING=1 -DCMAKE_INSTALL_LIBDIR=.
198 CC=clang CXX=clang++ cmake --build . -j32
199
200(experimental) Bazel:
201
202 CC=clang CXX=clang++ bazel build //...
203
204Scons:
205
206 CC=clang CXX=clang++ scons -j32 Werror=1 debug=0 neon=1 openmp=1 cppthreads=1 os=linux arch=armv8a multi_isa=1 build=native validation_tests=1
207
208Configurations supported are limited to the configurations supported by our CMake, Bazel and Multi ISA Scons builds. For more details on CMake and Bazel builds, please see @ref S1_8_experimental_builds
209
Sheri Zhangd813bab2021-04-30 16:53:41 +0100210@section S1_3_android Building for Android
211
212For Android, the library was successfully built and tested using Google's standalone toolchains:
Gunes Bayiree905002022-02-25 15:20:00 +0000213 - clang++ from NDK r20b for armv8a
214 - clang++ from NDK r20b for armv8.2-a with FP16 support
Sheri Zhangd813bab2021-04-30 16:53:41 +0100215
SiCong Li90e57202023-02-01 14:39:41 +0000216(From 23.02, NDK >= r20b is highly recommended) For 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>:
Sheri Zhangd813bab2021-04-30 16:53:41 +0100217- Download the NDK r18b from here: https://developer.android.com/ndk/downloads/index.html to directory $NDK
218- Make sure you have Python 2.7 installed on your machine.
Jakub Sujakee301b32021-06-04 09:46:08 +0100219- 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 +0100220
221 $NDK/build/tools/make_standalone_toolchain.py --arch arm64 --install-dir $MY_TOOLCHAINS/aarch64-linux-android-ndk-r18b --stl libc++ --api 21
SiCong Li56c3ca82022-05-19 18:43:33 +0100222
Sheri Zhangd813bab2021-04-30 16:53:41 +0100223 $NDK/build/tools/make_standalone_toolchain.py --arch arm --install-dir $MY_TOOLCHAINS/arm-linux-android-ndk-r18b --stl libc++ --api 21
224
225For 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/.
Pablo Marquez Telloab659ad2022-07-21 13:55:27 +0100226
SiCong Life1b1f62022-05-19 18:58:31 +0100227@parblock
228@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 can instruct scons to use the correct version by using a combination of the toolchain_prefix and the "CC" "CXX" environment variables.
229@attention For this particular example, you can specify:
Sheri Zhangd813bab2021-04-30 16:53:41 +0100230
SiCong Life1b1f62022-05-19 18:58:31 +0100231 CC=clang CXX=clang++ scons toolchain_prefix=aarch64-linux-android21-
232
233@attention or:
234
235 CC=aarch64-linux-android21-clang CXX=aarch64-linux-android21-clang++ scons toolchain_prefix=""
236
237@endparblock
238
239@parblock
Sheri Zhangd813bab2021-04-30 16:53:41 +0100240@attention We used to use gnustl but as of NDK r17 it is deprecated so we switched to libc++
SiCong Life1b1f62022-05-19 18:58:31 +0100241@endparblock
Sheri Zhangd813bab2021-04-30 16:53:41 +0100242
243@note Make sure to add the toolchains to your PATH:
244
245 export PATH=$PATH:$MY_TOOLCHAINS/aarch64-linux-android-ndk-r18b/bin:$MY_TOOLCHAINS/arm-linux-android-ndk-r18b/bin
246
247@subsection S1_3_1_library How to build the library ?
248
249To cross-compile the library in debug mode, with Arm® Neon™ only support, for Android 32bit:
250
251 CXX=clang++ CC=clang scons Werror=1 -j8 debug=1 neon=1 opencl=0 os=android arch=armv7a
252
253To cross-compile the library in asserts mode, with OpenCL only support, for Android 64bit:
254
Gunes Bayiree905002022-02-25 15:20:00 +0000255 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 +0100256
257@subsection S1_3_2_examples How to manually build the examples ?
258
259The 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.
260
261@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.
262
263Once you've got your Android standalone toolchain built and added to your path you can do the following:
264
265To cross compile a Arm® Neon™ example:
266
267 #32 bit:
Jakub Sujake30c8742023-11-13 14:57:16 +0000268 arm-linux-androideabi-clang++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute-static -L. -o neon_cnn_arm -static-libstdc++ -pie
Sheri Zhangd813bab2021-04-30 16:53:41 +0100269 #64 bit:
Jakub Sujake30c8742023-11-13 14:57:16 +0000270 aarch64-linux-android-clang++ examples/neon_cnn.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute-static -L. -o neon_cnn_aarch64 -static-libstdc++ -pie
Sheri Zhangd813bab2021-04-30 16:53:41 +0100271
272To cross compile an OpenCL example:
273
274 #32 bit:
Jakub Sujake30c8742023-11-13 14:57:16 +0000275 arm-linux-androideabi-clang++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute-static -L. -o cl_sgemm_arm -static-libstdc++ -pie -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +0100276 #64 bit:
Jakub Sujake30c8742023-11-13 14:57:16 +0000277 aarch64-linux-android-clang++ examples/cl_sgemm.cpp utils/Utils.cpp -I. -Iinclude -std=c++14 -larm_compute-static -L. -o cl_sgemm_aarch64 -static-libstdc++ -pie -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +0100278
279To cross compile the examples with the Graph API, such as graph_lenet.cpp, you need to link the library arm_compute_graph also.
280
281 #32 bit:
Jakub Sujake30c8742023-11-13 14:57:16 +0000282 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 -L. -o graph_lenet_arm -static-libstdc++ -pie -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +0100283 #64 bit:
Jakub Sujake30c8742023-11-13 14:57:16 +0000284 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 -L. -o graph_lenet_aarch64 -static-libstdc++ -pie -DARM_COMPUTE_CL
Sheri Zhangd813bab2021-04-30 16:53:41 +0100285
286@note Due to some issues in older versions of the Arm® Mali™ OpenCL DDK (<= r13p0), we recommend to link arm_compute statically on Android.
287@note When linked statically the arm_compute_graph library currently needs the --whole-archive linker flag in order to work properly
288
289Then you need to do is upload the executable and the shared library to the device using ADB:
290
Jakub Sujakee301b32021-06-04 09:46:08 +0100291 adb push neon_cnn_arm /data/local/tmp/
292 adb push cl_sgemm_arm /data/local/tmp/
Sheri Zhangd813bab2021-04-30 16:53:41 +0100293 adb push gc_absdiff_arm /data/local/tmp/
294 adb shell chmod 777 -R /data/local/tmp/
295
296And finally to run the example:
297
Jakub Sujakee301b32021-06-04 09:46:08 +0100298 adb shell /data/local/tmp/neon_cnn_arm
299 adb shell /data/local/tmp/cl_sgemm_arm
Sheri Zhangd813bab2021-04-30 16:53:41 +0100300 adb shell /data/local/tmp/gc_absdiff_arm
301
302For 64bit:
303
Jakub Sujakee301b32021-06-04 09:46:08 +0100304 adb push neon_cnn_aarch64 /data/local/tmp/
305 adb push cl_sgemm_aarch64 /data/local/tmp/
Sheri Zhangd813bab2021-04-30 16:53:41 +0100306 adb push gc_absdiff_aarch64 /data/local/tmp/
307 adb shell chmod 777 -R /data/local/tmp/
308
309And finally to run the example:
310
Jakub Sujakee301b32021-06-04 09:46:08 +0100311 adb shell /data/local/tmp/neon_cnn_aarch64
312 adb shell /data/local/tmp/cl_sgemm_aarch64
Sheri Zhangd813bab2021-04-30 16:53:41 +0100313 adb shell /data/local/tmp/gc_absdiff_aarch64
314
315@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.
316
317For example:
318 adb shell /data/local/tmp/graph_lenet --help
319
Jakub Sujakee301b32021-06-04 09:46:08 +0100320In 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 +0100321
322@section S1_4_macos Building for macOS
323
324The library was successfully natively built for Apple Silicon under macOS 11.1 using clang v12.0.0.
325
326To natively compile the library with accelerated CPU support:
327
Gunes Bayiree905002022-02-25 15:20:00 +0000328 scons Werror=1 -j8 neon=1 opencl=0 os=macos arch=armv8a build=native
Sheri Zhangd813bab2021-04-30 16:53:41 +0100329
330@note Initial support disables feature discovery through HWCAPS and thread scheduling affinity controls
331
332@section S1_5_bare_metal Building for bare metal
333
334For bare metal, the library was successfully built using linaro's latest (gcc-linaro-6.3.1-2017.05) bare metal toolchains:
335 - arm-eabi for armv7a
Gunes Bayiree905002022-02-25 15:20:00 +0000336 - aarch64-elf for armv8a
Sheri Zhangd813bab2021-04-30 16:53:41 +0100337
Gunes Bayiree905002022-02-25 15:20:00 +0000338Download 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 +0100339
340@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
341
342@subsection S1_5_1_library How to build the library ?
343
Gunes Bayiree905002022-02-25 15:20:00 +0000344To cross-compile the library with Arm® Neon™ support for baremetal armv8a:
Sheri Zhangd813bab2021-04-30 16:53:41 +0100345
Gunes Bayiree905002022-02-25 15:20:00 +0000346 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 +0100347
348@subsection S1_5_2_examples How to manually build the examples ?
349
350Examples 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>.
351
Jakub Sujak117e17e2023-02-21 10:52:57 +0000352@section S1_6_windows_host Building on a Windows® host system (cross-compile)
Sheri Zhangd813bab2021-04-30 16:53:41 +0100353
Jakub Sujak117e17e2023-02-21 10:52:57 +0000354Using `scons` directly from the Windows® command line is known to cause
Sheri Zhangd813bab2021-04-30 16:53:41 +0100355problems. The reason seems to be that if `scons` is setup for cross-compilation
Jakub Sujak117e17e2023-02-21 10:52:57 +0000356it gets confused about Windows® style paths (using backslashes). Thus it is
Sheri Zhangd813bab2021-04-30 16:53:41 +0100357recommended to follow one of the options outlined below.
358
Jakub Sujak117e17e2023-02-21 10:52:57 +0000359@subsection S1_6_1_ubuntu_on_windows Bash on Ubuntu on Windows® (cross-compile)
Sheri Zhangd813bab2021-04-30 16:53:41 +0100360
361The best and easiest option is to use
Jakub Sujak117e17e2023-02-21 10:52:57 +0000362<a href="https://msdn.microsoft.com/en-gb/commandline/wsl/about">Ubuntu on Windows®</a>.
Sheri Zhangd813bab2021-04-30 16:53:41 +0100363This feature is still marked as *beta* and thus might not be available.
364However, if it is building the library is as simple as opening a *Bash on
Jakub Sujak117e17e2023-02-21 10:52:57 +0000365Ubuntu on Windows®* shell and following the general guidelines given above.
Sheri Zhangd813bab2021-04-30 16:53:41 +0100366
Pablo Marquez Telloab659ad2022-07-21 13:55:27 +0100367@subsection S1_6_2_cygwin Cygwin (cross-compile)
Sheri Zhangd813bab2021-04-30 16:53:41 +0100368
Jakub Sujak117e17e2023-02-21 10:52:57 +0000369If the Windows® subsystem for Linux is not available <a href="https://www.cygwin.com/">Cygwin</a>
Sheri Zhangd813bab2021-04-30 16:53:41 +0100370can be used to install and run `scons`, the minimum Cygwin version must be 3.0.7 or later. In addition
371to the default packages installed by Cygwin `scons` has to be selected in the installer. (`git` might
372also be useful but is not strictly required if you already have got the source
373code of the library.) Linaro provides pre-built versions of
374<a href="http://releases.linaro.org/components/toolchain/binaries/">GCC cross-compilers</a>
375that can be used from the Cygwin terminal. When building for Android the
376compiler is included in the Android standalone toolchain. After everything has
377been set up in the Cygwin terminal the general guide on building the library
378can be followed.
379
Jakub Sujak117e17e2023-02-21 10:52:57 +0000380@subsection S1_6_3_WoA Windows® on Arm™ (native build)
Pablo Marquez Telloab659ad2022-07-21 13:55:27 +0100381
Jakub Sujak117e17e2023-02-21 10:52:57 +0000382 Native builds on Windows® are experimental and some features from the library interacting with the OS are missing.
Pablo Marquez Telloab659ad2022-07-21 13:55:27 +0100383
Jakub Sujak117e17e2023-02-21 10:52:57 +0000384It's possible to build Compute Library natively on a Windows® system running on Arm™.
Pablo Marquez Telloab659ad2022-07-21 13:55:27 +0100385
Jakub Sujak117e17e2023-02-21 10:52:57 +0000386Windows® on Arm™ (WoA) systems provide compatibility emulating x86 binaries on aarch64. Unfortunately Visual Studio 2022 does not work on aarch64 systems because it's an x86_64bit application and these binaries cannot be exectuted on WoA yet.
Pablo Marquez Telloab659ad2022-07-21 13:55:27 +0100387
Jakub Sujak117e17e2023-02-21 10:52:57 +0000388Because we cannot use Visual Studio to build Compute Library we have to set up a native standalone toolchain to compile C++ code for arm64 on Windows®.
Pablo Marquez Telloab659ad2022-07-21 13:55:27 +0100389
390Native arm64 toolchain installation for WoA:
391- LLVM+Clang-12 which can be downloaded from: https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/LLVM-12.0.0-woa64.exe
392- Arm64 VC Runtime which can be downloaded from https://aka.ms/vs/17/release/vc_redist.arm64.exe
393
394- While full VS22 cannot be installed on WoA, we can install some components
395 -# Desktop development with C++ and all Arm64 components for Visual Studio, refer to: https://developer.arm.com/documentation/102528/0100/Install-Visual-Studio
396 -# VS22 build tools: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022
397
398There are some additional tools we need to install to build Compute Library:
399
400- git https://git-scm.com/download/win
401- python 3 https://www.python.org/downloads/windows/
402- scons can be installed with pip install scons
403
Jakub Sujak117e17e2023-02-21 10:52:57 +0000404In order to use clang to build Windows® binaries natively we have to initialize the environment variables from VS22 correctly so that the compiler could find the arm64 C++ libraries. This can be done by pressing the key windows + r and running the command:
Pablo Marquez Telloab659ad2022-07-21 13:55:27 +0100405
406 cmd /k "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsx86_arm64.bat"
407
408To build Compute Library type:
409
410 scons opencl=0 neon=1 os=windows examples=0 validation_tests=1 benchmark_examples=0 build=native arch=armv8a Werror=0 exceptions=1 standalone=1
411
Sheri Zhangd813bab2021-04-30 16:53:41 +0100412@section S1_7_cl_requirements OpenCL DDK Requirements
413
414@subsection S1_7_1_cl_hard_requirements Hard Requirements
415
416Compute 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).
417
418Enabling 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.
419
420@subsection S1_7_2_cl_performance_requirements Performance improvements
421
422Integer 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.
423
424OpenCL kernel level debugging can be simplified with the use of printf, this requires the \a cl_arm_printf extension to be supported.
425
426SVM allocations are supported for all the underlying allocations in Compute Library. To enable this OpenCL 2.0 and above is a requirement.
427
David Svantessone0c42ef2022-12-15 16:25:57 +0000428@section S1_8_experimental_builds Experimental Bazel and CMake builds
429
430In addition to the scons build the repository includes experimental Bazel and CMake builds.
David Svantessonb5d6c282023-04-24 16:47:04 +0000431These builds currently support a limited range of options. Both are similar to the scons multi_isa build. It compiles all libraries with Neon (TM) support, as well as SVE and SVE2 libraries. The build is CPU only, not including OpenCL support. Only Linux environment is targeted for now. Both were successfully built with gcc / g++ version 10.2.
David Svantessone0c42ef2022-12-15 16:25:57 +0000432
433@subsection S1_8_1_bazel_build Bazel build
434
435@subsubsection S1_8_1_1_file_structure File structure
436
437File structure for all files included in the Bazel build:
438
439 .
440 ├── .bazelrc
441 ├── BUILD
442 ├── WORKSPACE
443 ├── arm_compute
444 │  └── BUILD
445 ├── examples
446 │  └── BUILD
447 ├── include
448 │  └── BUILD
449 ├── scripts
450 │ ├── print_version_file.py
451 │  └── BUILD
452 ├── src
453 │  └── BUILD
454 ├── support
455 │  └── BUILD
456 ├── tests
457 │ ├── BUILD
458 │  └── framework
459 │  └── BUILD
460 └── utils
461 └── BUILD
462
463@subsubsection S1_8_1_2_build_options Build options
464
465Available build options:
466
467 - debug: Enable ['-O0','-g','-gdwarf-2'] compilation flags
468 - Werror: Enable -Werror compilation flag
469 - logging: Enable logging
470 - cppthreads: Enable C++11 threads backend
471 - openmp: Enable OpenMP backend
472
473@subsubsection S1_8_1_3_example_builds Example builds
474
475Build everything (libraries, examples, tests):
476
477 bazel build //...
478
479Build libraries:
480
481 bazel build //:all
482
483Build arm_compute only:
484
485 bazel build //:arm_compute
486
487Build examples:
488
489 bazel build //examples:all
490
491Build resnet50 example:
492
493 bazel build //examples:graph_resnet50
494
495Build validation and benchmarking:
496
497 bazel build //tests:all
498
499@subsection S1_8_2_cmake_build CMake build
500
501@subsubsection S1_8_2_1_file_structure File structure
502
503File structure for all files included in the CMake build:
504
505 .
506 ├── CMakeLists.txt
507 ├── cmake
508 │ ├── Options.cmake
509 │ ├── Version.cmake
510 │  └── toolchains
511 │  └── aarch64_linux_toolchain.cmake
512 ├── examples
513 │  └── CMakeLists.txt
514 ├── src
515 │ └── CMakeLists.txt
516 └── tests
517 ├── CMakeLists.txt
518 ├── benchmark
519 │ └── CMakeLists.txt
520 └── validation
521 └── CMakeLists.txt
522
523@subsubsection S1_8_2_2_build_options Build options
524
525Available build options:
526
David Svantessonb5d6c282023-04-24 16:47:04 +0000527 - CMAKE_BUILD_TYPE: "Release" (default) enables ['-O3', '-DNDEBUG'] compilation flags, "Debug" enables ['-O0','-g','-gdwarf-2', '-DARM_COMPUTE_ASSERTS_ENABLED']
528 - ARM_COMPUTE_WERROR: Enable -Werror compilation flag
529 - ARM_COMPUTE_EXCEPTIONS: If disabled ARM_COMPUTE_EXCEPTIONS_DISABLED is enabled
530 - ARM_COMPUTE_LOGGING: Enable logging
531 - ARM_COMPUTE_BUILD_EXAMPLES: Build examples
532 - ARM_COMPUTE_BUILD_TESTING: Build tests
533 - ARM_COMPUTE_CPPTHREADS: Enable C++11 threads backend
534 - ARM_COMPUTE_OPENMP: Enable OpenMP backend
David Svantessone0c42ef2022-12-15 16:25:57 +0000535
536@subsubsection S1_8_2_3_example_builds Example builds
537
538To build libraries, examples and tests:
539
540 mkdir build
541 cd build
David Svantessonb5d6c282023-04-24 16:47:04 +0000542 cmake .. -DCMAKE_BUILD_TYPE=Release -DARM_COMPUTE_OPENMP=1 -DARM_COMPUTE_WERROR=0 -DARM_COMPUTE_BUILD_EXAMPLES=1 -DARM_COMPUTE_BUILD_TESTING=1 -DCMAKE_INSTALL_LIBDIR=.
David Svantessone0c42ef2022-12-15 16:25:57 +0000543 cmake --build . -j32
544
Jakub Sujak9b72a6c2023-11-28 14:40:22 +0000545@section S1_9_fixed_format Building with support for fixed format kernels
Nathan John Sircombed7113e42023-04-26 15:02:43 +0100546
Jakub Sujak9b72a6c2023-11-28 14:40:22 +0000547@subsection S1_9_1_intro_to_fixed_format_kernels What are fixed format kernels?
Nathan John Sircombed7113e42023-04-26 15:02:43 +0100548
549The GEMM kernels used for convolutions and fully-connected layers in Compute Library employ memory layouts optimized for each kernel implementation. This then requires the supplied weights to be re-ordered into a buffer ready for consumption by the GEMM kernel. Where Compute Library is being called from a framework or library which implements operator caching, the re-ordering of the inputted weights into an intermediate buffer may no longer be desirable. When using a cached operator, the caller may wish to re-write the weights tensor, and re-run the operator using the updated weights. With the default GEMM kernels in Compute Library, the GEMM will be executed with the old weights, leading to incorrect results.
550
551To address this, Compute Library provides a set of GEMM kernels which use a common blocked memory format. These kernels consume the input weights directly from the weights buffer and do not execute an intermediate pre-transpose step. With this approach, it is the responsibility of the user (in this case the calling framework) to ensure that the weights are re-ordered into the required memory format. @ref NEGEMM::has_opt_impl is a static function that queries whether there exists fixed-format kernel, and if so will return in the expected weights format. The supported weight formats are enumerated in @ref arm_compute::WeightFormat.
552
Jakub Sujak9b72a6c2023-11-28 14:40:22 +0000553@subsection S1_9_2_building_fixed_format Building with fixed format kernels
Nathan John Sircombed7113e42023-04-26 15:02:43 +0100554
555Fixed format kernels are only available for the CPU backend. To build Compute Library with fixed format kernels set fixed_format_kernels=1:
556
557 scons Werror=1 debug=0 neon=1 opencl=0 embed_kernels=0 os=linux multi_isa=1 build=native cppthreads=1 openmp=0 fixed_format_kernels=1
558
Jakub Sujak9b72a6c2023-11-28 14:40:22 +0000559@section S1_10_doxygen Building the Doxygen Documentation
560
561This documentation has been generated using the following shell command:
562
563 $ ./scripts/generate_documentation.sh
564
565This requires Doxygen to be installed and available on your system.
566
Sheri Zhangd813bab2021-04-30 16:53:41 +0100567*/
Jakub Sujak9b72a6c2023-11-28 14:40:22 +0000568
Sheri Zhangd813bab2021-04-30 16:53:41 +0100569} // namespace arm_compute