blob: f2d7848a1288e3ee4ad760db1fbb24c23f6e6888 [file] [log] [blame]
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +00001# -*- coding: utf-8 -*-
2
Pablo Tello4e66d702022-03-07 18:20:12 +00003# Copyright (c) 2016-2022 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01004#
5# SPDX-License-Identifier: MIT
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to
9# deal in the Software without restriction, including without limitation the
10# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11# sell copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in all
15# copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23# SOFTWARE.
24
25import SCons
Georgios Pinitasb6af4822021-09-14 12:33:34 +010026import json
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027import os
Giorgio Arenab83e6722022-03-24 14:23:07 +000028from subprocess import check_output
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
30def version_at_least(version, required):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031
Michalis Spyroucfac3052020-10-14 12:06:28 +010032 version_list = version.split('.')
33 required_list = required.split('.')
34 end = min(len(version_list), len(required_list))
35 for i in range(0, end):
36 if int(version_list[i]) < int(required_list[i]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037 return False
Michalis Spyroucfac3052020-10-14 12:06:28 +010038 elif int(version_list[i]) > int(required_list[i]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039 return True
40
41 return True
42
Freddie Liardet487d3902021-09-21 12:36:43 +010043def read_build_config_json(build_config):
44 build_config_contents = {}
45 custom_types = []
46 custom_layouts = []
47 if os.path.isfile(build_config):
48 with open(build_config) as f:
49 try:
50 build_config_contents = json.load(f)
51 except:
52 print("Warning: Build configuration file is of invalid JSON format!")
53 else:
54 try:
55 build_config_contents = json.loads(build_config)
56 except:
57 print("Warning: Build configuration string is of invalid JSON format!")
58 if build_config_contents:
59 custom_types = build_config_contents.get("data_types", [])
60 custom_layouts = build_config_contents.get("data_layouts", [])
61 return custom_types, custom_layouts
62
63def update_data_type_layout_flags(env, data_types, data_layouts):
64 # Manage data-types
65 if any(i in data_types for i in ['all', 'fp16']):
66 env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS'])
67 if any(i in data_types for i in ['all', 'fp32']):
68 env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS'])
69 if any(i in data_types for i in ['all', 'qasymm8']):
70 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS'])
71 if any(i in data_types for i in ['all', 'qasymm8_signed']):
72 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS'])
73 if any(i in data_types for i in ['all', 'qsymm16']):
74 env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS'])
75 if any(i in data_types for i in ['all', 'integer']):
76 env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS'])
77
78 # Manage data-layouts
79 if any(i in data_layouts for i in ['all', 'nhwc']):
80 env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS'])
81 if any(i in data_layouts for i in ['all', 'nchw']):
82 env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS'])
83
84 return env
85
86
Anthony Barbier6ff3b192017-09-04 18:44:23 +010087vars = Variables("scons")
88vars.AddVariables(
89 BoolVariable("debug", "Debug", False),
90 BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False),
ramelg0193d6cf02021-09-23 13:59:22 +010091 BoolVariable("logging", "Enable Logging", False),
Michalis Spyroua3f7cd22022-07-04 15:32:02 +010092 EnumVariable("arch", "Target Architecture. The x86_32 and x86_64 targets can only be used with neon=0 and opencl=1.", "armv7a",
Slava Barinovdb0e2c82021-04-07 11:23:27 +030093 allowed_values=("armv7a", "armv7a-hf", "arm64-v8a", "arm64-v8.2-a", "arm64-v8.2-a-sve", "arm64-v8.2-a-sve2", "x86_32", "x86_64",
Sang-Hoon Park50e98bb2021-01-14 14:54:14 +000094 "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "armv8.6-a-sve2", "armv8r64", "x86")),
Georgios Pinitasf2cdce32019-12-09 18:35:57 +000095 EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")),
Michalis Spyroua3f7cd22022-07-04 15:32:02 +010096 EnumVariable("os", "Target OS. With bare metal selected, only Arm® Neon™ (not OpenCL) can be used, static libraries get built and Neon™'s multi-threading support is disabled.", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal", "openbsd","windows")),
97 EnumVariable("build", "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.", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010098 BoolVariable("examples", "Build example programs", True),
SiCong Li8b4c7302019-09-19 12:18:15 +010099 BoolVariable("gemm_tuner", "Build gemm_tuner programs", True),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100 BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True),
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200101 BoolVariable("multi_isa", "Build Multi ISA binary version of library. Note works only for armv8.2-a", False),
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100102 BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103 BoolVariable("opencl", "Enable OpenCL support", True),
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000104 BoolVariable("neon", "Enable Arm® Neon™ support", False),
Michalis Spyroua3f7cd22022-07-04 15:32:02 +0100105 BoolVariable("embed_kernels", "Enable 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'.", True),
106 BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary using zlib. Useful for reducing the binary size. embed_kernels should be enabled", False),
107 BoolVariable("set_soname", "If enabled the library will contain a SONAME and SHLIBVERSION and some symlinks will automatically be created between the objects. (requires SCons 2.4 or above)", False),
108 BoolVariable("openmp", "Enable OpenMP backend. Only works when building with g++ and not clang++", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109 BoolVariable("cppthreads", "Enable C++11 threads backend", True),
110 PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept),
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000111 PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept),
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000112 BoolVariable("exceptions", "Enable/disable C++ exception support", True),
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100113 BoolVariable("high_priority", "Generate a library containing only the high priority operators", False),
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100114 PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept),
Michalis Spyroua3f7cd22022-07-04 15:32:02 +0100115 PathVariable("external_tests_dir", """Add examples, benchmarks and tests to the tests suite from an external path. In order to use this option, the external tests directory must have the following structure:
116 EXTERNAL_TESTS_DIR:
117 └── tests
118 ├── benchmark
119 │   ├── CL
120 │   ├── datasets
121 │   ├── fixtures
122 │   └── Neon
123 └── validation
124     ├── CL
125     ├── datasets
126     ├── fixtures
127     └── Neon\n""", "", PathVariable.PathAccept),
Giorgio Arena232c4522022-03-03 10:09:01 +0000128 BoolVariable("experimental_dynamic_fusion", "Build the experimental dynamic fusion files", False),
Francesco.Petrogalli@arm.com5fcf22d2022-04-05 10:31:08 +0000129 BoolVariable("experimental_fixed_format_kernels", "Enable fixed format kernels for GEMM", False),
Georgios Pinitas49c6ced2020-09-21 17:16:09 +0100130 ListVariable("custom_options", "Custom options that can be used to turn on/off features", "none", ["disable_mmla_fp"]),
Michalis Spyroua3c9a3b2020-12-08 21:02:16 +0000131 ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32", "integer"]),
Sheri Zhang79144a62021-02-08 17:43:04 +0000132 ListVariable("data_layout_support", "Enable a list of data layout to support", "all", ["nhwc", "nchw"]),
SiCong Life1b1f62022-05-19 18:58:31 +0100133 ("toolchain_prefix", "Override the toolchain prefix; used by all toolchain components: compilers, linker, assembler etc. If unspecified, use default(auto) prefixes; if passed an empty string '' prefixes would be disabled", "auto"),
134 ("compiler_prefix", "Override the compiler prefix; used by just compilers (CC,CXX); further overrides toolchain_prefix for compilers; this is for when the compiler prefixes are different from that of the linkers, archivers etc. If unspecified, this is the same as toolchain_prefix; if passed an empty string '' prefixes would be disabled", "auto"),
Anthony Barbier7390e052018-03-13 09:29:41 +0000135 ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""),
Georgios Pinitas421405b2018-10-26 19:05:32 +0100136 ("extra_link_flags", "Extra LD flags to be appended to the build command", ""),
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000137 ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""),
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100138 ("specs_file", "Specs file to use (e.g. rdimon.specs)", ""),
139 ("build_config", "Operator/Data-type/Data-layout configuration to use for tailored ComputeLibrary builds. Can be a JSON file or a JSON formatted string", "")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100140)
141
Motti Gondabif76a5022021-12-21 13:19:29 +0200142
Pablo Tello4e66d702022-03-07 18:20:12 +0000143env = Environment(variables=vars, ENV = os.environ)
144
145
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100146build_path = env['build_dir']
147# If build_dir is a relative path then add a #build/ prefix:
148if not env['build_dir'].startswith('/'):
149 SConsignFile('build/%s/.scons' % build_path)
150 build_path = "#build/%s" % build_path
151else:
152 SConsignFile('%s/.scons' % build_path)
153
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000154install_path = env['install_dir']
155#If the install_dir is a relative path then assume it's from inside build_dir
156if not env['install_dir'].startswith('/') and install_path != "":
157 install_path = "%s/%s" % (build_path, install_path)
158
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100159env.Append(LIBPATH = [build_path])
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000160Export('env')
161Export('vars')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100162
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000163def install_lib( lib ):
164 # If there is no install folder, then there is nothing to do:
165 if install_path == "":
166 return lib
167 return env.Install( "%s/lib/" % install_path, lib)
168def install_bin( bin ):
169 # If there is no install folder, then there is nothing to do:
170 if install_path == "":
171 return bin
172 return env.Install( "%s/bin/" % install_path, bin)
173def install_include( inc ):
174 if install_path == "":
175 return inc
176 return env.Install( "%s/include/" % install_path, inc)
177
178Export('install_lib')
179Export('install_bin')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100180
181Help(vars.GenerateHelpText(env))
182
Michalis Spyrou14ce0942022-06-13 15:40:35 +0100183if 'armv7a' in env['arch'] and env['os'] == 'android':
SiCong Li13f96d02022-06-21 10:06:51 +0100184 print("WARNING: armv7a on Android is no longer maintained")
Michalis Spyrou14ce0942022-06-13 15:40:35 +0100185
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100186if env['linker_script'] and env['os'] != 'bare_metal':
187 print("Linker script is only supported for bare_metal builds")
188 Exit(1)
189
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000190if env['build'] == "embed_only":
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100191 SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000192 Return()
193
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100194if env['neon'] and 'x86' in env['arch']:
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000195 print("Cannot compile Arm® Neon™ for x86")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100196 Exit(1)
197
198if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"):
ggardet767c9f72018-06-29 17:01:01 +0200199 print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above")
200 print("Update your version of SCons or use set_soname=0")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100201 Exit(1)
202
203if env['os'] == 'bare_metal':
204 if env['cppthreads'] or env['openmp']:
205 print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0")
206 Exit(1)
207
Georgios Pinitasea857272021-01-22 05:47:37 +0000208if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']:
209 print("Compressed kernels are supported only for android builds")
210 Exit(1)
211
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000212if not env['exceptions']:
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +0000213 if env['opencl']:
214 print("ERROR: OpenCL is not supported when building without exceptions. Use opencl=0")
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000215 Exit(1)
216
217 env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED'])
218 env.Append(CXXFLAGS = ['-fno-exceptions'])
219
Pablo Tello29cab362022-03-10 17:05:34 +0000220env.Append(CXXFLAGS = ['-DARCH_ARM',
Pablo Tello4e66d702022-03-07 18:20:12 +0000221 '-Wextra','-Wdisabled-optimization','-Wformat=2',
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100222 '-Winit-self','-Wstrict-overflow=2','-Wswitch-default',
Pablo Tello4e66d702022-03-07 18:20:12 +0000223 '-Woverloaded-virtual', '-Wformat-security',
Michalis Spyroufae513c2019-10-16 17:41:33 +0100224 '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings'])
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000225
Pablo Tello4e66d702022-03-07 18:20:12 +0000226if not 'windows' in env['os']:
Pablo Tello29cab362022-03-10 17:05:34 +0000227 env.Append(CXXFLAGS = ['-Wall','-std=c++14', '-pedantic' ])
Pablo Tello4e66d702022-03-07 18:20:12 +0000228
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100229env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP'])
230
Pablo Tello4e66d702022-03-07 18:20:12 +0000231cpp_tool = {'linux': 'g++', 'android' : 'clang++',
232 'tizen': 'g++', 'macos':'clang++',
233 'bare_metal':'g++', 'openbsd':'g++','windows':'clang-cl'}
234
235c_tool = {'linux':'gcc', 'android': 'clang', 'tizen':'gcc',
236 'macos':'clang','bare_metal':'gcc',
237 'openbsd':'gcc','windows':'clang-cl'}
238
239default_cpp_compiler = cpp_tool[env['os']]
240default_c_compiler = c_tool[env['os']]
Anthony Barbiera026e982018-01-18 10:57:52 +0000241cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
242c_compiler = os.environ.get('CC', default_c_compiler)
243
Anthony Barbierdd669372018-03-01 17:08:54 +0000244if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ):
ggardet767c9f72018-06-29 17:01:01 +0200245 print( "WARNING: Only clang is officially supported to build the Compute Library for Android")
Anthony Barbiera026e982018-01-18 10:57:52 +0000246
Anthony Barbierdd669372018-03-01 17:08:54 +0000247if 'clang++' in cpp_compiler:
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100248 env.Append(CXXFLAGS = ['-Wno-vla-extension'])
Georgios Pinitase874ef92019-09-09 17:40:33 +0100249elif 'armclang' in cpp_compiler:
250 pass
Pablo Tello4e66d702022-03-07 18:20:12 +0000251elif not 'windows' in env['os']:
Giorgio Arenab83e6722022-03-24 14:23:07 +0000252 env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel','-Wno-misleading-indentation'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100253
SiCongLi410e21e2020-12-11 15:07:53 +0000254if cpp_compiler == 'g++':
255 # Don't strip comments that could include markers
256 env.Append(CXXFLAGS = ['-C'])
257
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100258if env['cppthreads']:
259 env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)])
260
261if env['openmp']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100262 env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)])
263 env.Append(CXXFLAGS = ['-fopenmp'])
264 env.Append(LINKFLAGS = ['-fopenmp'])
265
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000266# Validate and define state
267if env['estate'] == 'auto':
268 if 'v7a' in env['arch']:
269 env['estate'] = '32'
270 else:
271 env['estate'] = '64'
272
273# Map legacy arch
274if 'arm64' in env['arch']:
275 env['estate'] = '64'
276
277if 'v7a' in env['estate'] and env['estate'] == '64':
278 print("ERROR: armv7a architecture has only 32-bit execution state")
279 Exit(1)
280
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200281env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON'])
282
Motti Gondabif76a5022021-12-21 13:19:29 +0200283if 'sve' in env['arch']:
284 env.Append(CPPDEFINES = ['ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE'])
285 if 'sve2' in env['arch']:
286 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2'])
Motti Gondabif76a5022021-12-21 13:19:29 +0200287
Georgios Pinitase874ef92019-09-09 17:40:33 +0100288# Add architecture specific flags
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200289if env['multi_isa']:
290 # assert arch version is v8
291 if 'v8' not in env['arch']:
292 print("Currently Multi ISA binary is only supported for arm v8 family")
293 Exit(1)
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000294
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +0100295 if 'v8.6-a' in env['arch']:
Georgios Pinitas49c6ced2020-09-21 17:16:09 +0100296 if "disable_mmla_fp" not in env['custom_options']:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100297 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +0100298
Giorgio Arena73fa0a72022-02-10 15:06:51 +0000299 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
300
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200301else: # NONE "multi_isa" builds
302
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200303 if 'v7a' in env['arch']:
304 env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon'])
305 if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']:
306 env.Append(CXXFLAGS = ['-mfloat-abi=softfp'])
307 else:
308 env.Append(CXXFLAGS = ['-mfloat-abi=hard'])
Pablo Marquez Tellod208f4f2022-07-19 12:19:46 +0100309 elif 'v8.6-a' in env['arch']:
310 if 'armv8.6-a-sve2' == env['arch']:
311 env.Append(CXXFLAGS = ['-march=armv8.6-a+sve2'])
312 elif 'armv8.6-a-sve' == env['arch']:
313 env.Append(CXXFLAGS = ['-march=armv8.6-a+sve'])
314 elif 'armv8.6-a' == env['arch']:
Pablo Marquez Tellocf07d112022-09-28 21:37:37 +0100315 env.Append(CXXFLAGS = ['-march=armv8.6-a+fp16'])
Pablo Marquez Tellod208f4f2022-07-19 12:19:46 +0100316
317 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_BF16','ARM_COMPUTE_ENABLE_FP16'])
318 if "disable_mmla_fp" not in env['custom_options']:
319 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200320 elif 'v8' in env['arch']:
321 # Preserve the V8 archs for non-multi-ISA variants
322 if 'sve2' in env['arch']:
323 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod'])
324 elif 'sve' in env['arch']:
325 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod'])
326 elif 'armv8r64' in env['arch']:
327 env.Append(CXXFLAGS = ['-march=armv8.4-a'])
328 elif 'v8.' in env['arch']:
329 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
330 else:
331 env.Append(CXXFLAGS = ['-march=armv8-a'])
332
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200333 if 'v8.' in env['arch']:
334 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FP16'])
335
336 elif 'x86' in env['arch']:
337 if env['estate'] == '32':
338 env.Append(CCFLAGS = ['-m32'])
339 env.Append(LINKFLAGS = ['-m32'])
340 else:
341 env.Append(CXXFLAGS = ['-fPIC'])
342 env.Append(CCFLAGS = ['-m64'])
343 env.Append(LINKFLAGS = ['-m64'])
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000344
345# Define toolchain
SiCongLifecdb8f2022-01-04 18:33:17 +0000346# The reason why we distinguish toolchain_prefix from compiler_prefix is for cases where the linkers/archivers use a
347# different prefix than the compilers. An example is the NDK r20 toolchain
SiCong Life1b1f62022-05-19 18:58:31 +0100348auto_toolchain_prefix = ""
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000349if 'x86' not in env['arch']:
350 if env['estate'] == '32':
351 if env['os'] == 'linux':
SiCong Life1b1f62022-05-19 18:58:31 +0100352 auto_toolchain_prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000353 elif env['os'] == 'bare_metal':
SiCong Life1b1f62022-05-19 18:58:31 +0100354 auto_toolchain_prefix = "arm-eabi-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000355 elif env['os'] == 'android':
SiCong Life1b1f62022-05-19 18:58:31 +0100356 auto_toolchain_prefix = "arm-linux-androideabi-"
Inki Dae51a95582020-03-23 08:29:02 +0900357 elif env['os'] == 'tizen':
SiCong Life1b1f62022-05-19 18:58:31 +0100358 auto_toolchain_prefix = "armv7l-tizen-linux-gnueabi-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000359 elif env['estate'] == '64' and 'v8' in env['arch']:
360 if env['os'] == 'linux':
SiCong Life1b1f62022-05-19 18:58:31 +0100361 auto_toolchain_prefix = "aarch64-linux-gnu-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000362 elif env['os'] == 'bare_metal':
SiCong Life1b1f62022-05-19 18:58:31 +0100363 auto_toolchain_prefix = "aarch64-elf-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000364 elif env['os'] == 'android':
SiCong Life1b1f62022-05-19 18:58:31 +0100365 auto_toolchain_prefix = "aarch64-linux-android-"
Inki Dae51a95582020-03-23 08:29:02 +0900366 elif env['os'] == 'tizen':
SiCong Life1b1f62022-05-19 18:58:31 +0100367 auto_toolchain_prefix = "aarch64-tizen-linux-gnu-"
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100368
Pablo Marquez Telloddf2f6c2022-06-28 12:56:27 +0100369if env['build'] == 'native' or env["toolchain_prefix"] == "":
SiCong Life1b1f62022-05-19 18:58:31 +0100370 toolchain_prefix = ""
371elif env["toolchain_prefix"] == "auto":
372 toolchain_prefix = auto_toolchain_prefix
373else:
SiCongLifecdb8f2022-01-04 18:33:17 +0000374 toolchain_prefix = env["toolchain_prefix"]
Anthony Barbier149de5b2018-12-06 10:27:37 +0000375
Pablo Marquez Telloddf2f6c2022-06-28 12:56:27 +0100376if env['build'] == 'native' or env["compiler_prefix"] == "":
SiCong Life1b1f62022-05-19 18:58:31 +0100377 compiler_prefix = ""
378elif env["compiler_prefix"] == "auto":
379 compiler_prefix = toolchain_prefix
380else:
alered01d8872c12020-02-10 11:29:45 +0000381 compiler_prefix = env["compiler_prefix"]
382
383env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler
384env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler
SiCongLifecdb8f2022-01-04 18:33:17 +0000385env['LD'] = toolchain_prefix + "ld"
386env['AS'] = toolchain_prefix + "as"
Pablo Tello29cab362022-03-10 17:05:34 +0000387
Pablo Tello4e66d702022-03-07 18:20:12 +0000388if env['os'] == 'windows':
Pablo Tello29cab362022-03-10 17:05:34 +0000389 env['AR'] = "llvm-lib"
390 env['RANLIB'] = "llvm-ranlib"
Pablo Tello4e66d702022-03-07 18:20:12 +0000391else:
SiCongLifecdb8f2022-01-04 18:33:17 +0000392 env['AR'] = toolchain_prefix + "ar"
Pablo Tello29cab362022-03-10 17:05:34 +0000393
SiCongLifecdb8f2022-01-04 18:33:17 +0000394env['RANLIB'] = toolchain_prefix + "ranlib"
Pablo Tello4e66d702022-03-07 18:20:12 +0000395
SiCong Life1b1f62022-05-19 18:58:31 +0100396print("Using compilers:")
397print("CC", env['CC'])
398print("CXX", env['CXX'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100399
400if not GetOption("help"):
401 try:
Pablo Tello4e66d702022-03-07 18:20:12 +0000402 if env['os'] == 'windows':
Giorgio Arenab83e6722022-03-24 14:23:07 +0000403 compiler_ver = check_output("clang++ -dumpversion").decode().strip()
Pablo Tello4e66d702022-03-07 18:20:12 +0000404 else:
Giorgio Arenab83e6722022-03-24 14:23:07 +0000405 compiler_ver = check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100406 except OSError:
407 print("ERROR: Compiler '%s' not found" % env['CXX'])
408 Exit(1)
409
Georgios Pinitase874ef92019-09-09 17:40:33 +0100410 if 'armclang' in cpp_compiler:
411 pass
412 elif 'clang++' not in cpp_compiler:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100413 if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'):
ggardet767c9f72018-06-29 17:01:01 +0200414 print("GCC 6.2.1 or newer is required to compile armv8.2-a code")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100415 Exit(1)
416 elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'):
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000417 print("GCC 4.9 or newer is required to compile Arm® Neon™ code for AArch64")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100418 Exit(1)
419
420 if version_at_least(compiler_ver, '6.1'):
421 env.Append(CXXFLAGS = ['-Wno-ignored-attributes'])
422
423 if compiler_ver == '4.8.3':
424 env.Append(CXXFLAGS = ['-Wno-array-bounds'])
425
Michalis Spyroucfac3052020-10-14 12:06:28 +0100426 if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal':
427 env.Append(LINKFLAGS = ['-fstack-protector-strong'])
428
SiCong Libf5274d2022-07-20 17:45:36 +0100429 # Add Android NDK toolchain specific flags
430 if 'clang++' in cpp_compiler and env['os'] == 'android':
431 # For NDK >= r21, clang 9 or above is used
432 if version_at_least(compiler_ver, '9.0.0'):
433 env['ndk_above_r21'] = True
Giorgio Arenab83e6722022-03-24 14:23:07 +0000434
SiCong Libf5274d2022-07-20 17:45:36 +0100435 if env['openmp']:
436 env.Append(LINKFLAGS = ['-static-openmp'])
437
438 # For NDK >= r23, clang 12 or above is used. This condition detects NDK < r23
439 if not version_at_least(compiler_ver, '12.0.0'):
440 # System assembler is deprecated and integrated assembler is preferred since r23.
441 # However integrated assembler has always been suppressed for NDK < r23.
442 # Thus for backward compatibility, we include this flag only for NDK < r23
443 env.Append(CXXFLAGS = ['-no-integrated-as'])
Giorgio Arenab83e6722022-03-24 14:23:07 +0000444
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100445if env['high_priority'] and env['build_config']:
SiCongLidc85d782021-12-17 13:22:55 +0000446 print("The high priority library cannot be built in conjunction with a user-specified build configuration")
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100447 Exit(1)
448
449if not env['high_priority'] and not env['build_config']:
450 env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED'])
451
Freddie Liardet487d3902021-09-21 12:36:43 +0100452data_types = []
453data_layouts = []
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100454
Freddie Liardet487d3902021-09-21 12:36:43 +0100455# Set correct data types / layouts to build
456if env['high_priority']:
457 data_types = ['all']
458 data_layouts = ['all']
459elif env['build_config']:
460 data_types, data_layouts = read_build_config_json(env['build_config'])
461else:
462 data_types = env['data_type_support']
463 data_layouts = env['data_layout_support']
464
465env = update_data_type_layout_flags(env, data_types, data_layouts)
Sheri Zhang79144a62021-02-08 17:43:04 +0000466
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100467if env['standalone']:
Pablo Tello29cab362022-03-10 17:05:34 +0000468 if not 'windows' in env['os']:
Pablo Tello4e66d702022-03-07 18:20:12 +0000469 env.Append(CXXFLAGS = ['-fPIC'])
Pablo Tello29cab362022-03-10 17:05:34 +0000470 env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++'])
471
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100472if env['Werror']:
473 env.Append(CXXFLAGS = ['-Werror'])
474
475if env['os'] == 'android':
476 env.Append(CPPDEFINES = ['ANDROID'])
Michalis Spyrou2d22c3f2020-02-12 14:50:19 +0000477 env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100478elif env['os'] == 'bare_metal':
479 env.Append(LINKFLAGS = ['-static'])
480 env.Append(CXXFLAGS = ['-fPIC'])
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000481 if env['specs_file'] == "":
482 env.Append(LINKFLAGS = ['-specs=rdimon.specs'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100483 env.Append(CPPDEFINES = ['NO_MULTI_THREADING'])
Michalis Spyrou07781ac2017-08-31 15:11:41 +0100484 env.Append(CPPDEFINES = ['BARE_METAL'])
Manuel Bottini827817e2020-11-19 12:12:06 +0000485if env['os'] == 'linux' and env['arch'] == 'armv7a':
486 env.Append(CXXFLAGS = [ '-Wno-psabi' ])
Pablo Tello4e66d702022-03-07 18:20:12 +0000487if env['os'] == 'windows':
488 env.Append(CXXFLAGS = [ '/std:c++14','/EHa'])
489 env.Append(CXXFLAGS = [ '-Wno-c++98-compat', '-Wno-covered-switch-default','-Wno-c++98-compat-pedantic'])
490 env.Append(CXXFLAGS = [ '-Wno-shorten-64-to-32', '-Wno-sign-conversion','-Wno-documentation'])
491 env.Append(CXXFLAGS = [ '-Wno-extra-semi-stmt', '-Wno-float-equal','-Wno-implicit-int-conversion'])
492 env.Append(CXXFLAGS = [ '-Wno-documentation-pedantic', '-Wno-extra-semi','-Wno-shadow-field-in-constructor'])
493 env.Append(CXXFLAGS = [ '-Wno-float-conversion', '-Wno-switch-enum','-Wno-comma'])
494 env.Append(CXXFLAGS = [ '-Wno-implicit-float-conversion', '-Wno-deprecated-declarations','-Wno-old-style-cast'])
495 env.Append(CXXFLAGS = [ '-Wno-zero-as-null-pointer-constant', '-Wno-inconsistent-missing-destructor-override'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100496
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000497if env['specs_file'] != "":
498 env.Append(LINKFLAGS = ['-specs='+env['specs_file']])
499
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000500if env['neon']:
501 env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED'])
502
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100503if env['opencl']:
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000504 env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED'])
Georgios Pinitase6032da2017-10-26 14:13:35 +0100505 if env['os'] in ['bare_metal'] or env['standalone']:
Anthony Barbier5f0124d2018-04-13 14:05:34 +0100506 print("Cannot link OpenCL statically, which is required for bare metal / standalone builds")
507 Exit(1)
508
Pablo Tello29cab362022-03-10 17:05:34 +0000509if env["os"] not in ["windows","android", "bare_metal"] and (env['opencl'] or env['cppthreads']):
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100510 env.Append(LIBS = ['pthread'])
511
Kevin Lo7195f712022-01-07 15:46:02 +0800512if env['os'] == 'openbsd':
513 env.Append(LIBS = ['c'])
514 env.Append(CXXFLAGS = ['-fPIC'])
515
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +0000516if env['opencl']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100517 if env['embed_kernels']:
518 env.Append(CPPDEFINES = ['EMBEDDED_KERNELS'])
Georgios Pinitasea857272021-01-22 05:47:37 +0000519 if env['compress_kernels']:
520 env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS'])
521 env.Append(LIBS = ['z'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100522
523if env['debug']:
524 env['asserts'] = True
Pablo Tello29cab362022-03-10 17:05:34 +0000525 if not 'windows' in env['os']:
526 env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2'])
527 else:
528 env.Append(CXXFLAGS = ['-Z7','-MTd','-fms-compatibility','-fdelayed-template-parsing'])
529 env.Append(LINKFLAGS = ['-DEBUG'])
530
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100531 env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED'])
532else:
Pablo Tello4e66d702022-03-07 18:20:12 +0000533 if not 'windows' in env['os']:
534 env.Append(CXXFLAGS = ['-O3'])
535 else:
536 # on windows we use clang-cl which does not support the option -O3
537 env.Append(CXXFLAGS = ['-O2'])
Pablo Tello29cab362022-03-10 17:05:34 +0000538
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100539if env['asserts']:
540 env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED'])
Pablo Tello29cab362022-03-10 17:05:34 +0000541 if not 'windows' in env['os']:
542 env.Append(CXXFLAGS = ['-fstack-protector-strong'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100543
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +0100544if env['logging']:
545 env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED'])
546
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100547env.Append(CPPPATH = ['#/include', "#"])
548env.Append(CXXFLAGS = env['extra_cxx_flags'])
Georgios Pinitas421405b2018-10-26 19:05:32 +0100549env.Append(LINKFLAGS = env['extra_link_flags'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100550
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000551Default( install_include("arm_compute"))
Anthony Barbier10565952018-11-15 09:50:06 +0000552Default( install_include("support"))
Michele Di Giorgio6afea902019-04-03 11:40:20 +0100553Default( install_include("utils"))
554for dirname in os.listdir("./include"):
555 Default( install_include("include/%s" % dirname))
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000556
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100557Export('version_at_least')
558
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100559SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6c0348f2017-11-10 18:32:38 +0000560
Freddie Liardet487d3902021-09-21 12:36:43 +0100561if env['examples'] and (env['build_config'] or env['high_priority']):
562 print("WARNING: Building examples for selected operators not supported. Use examples=0")
563 Return()
564
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100565if env['examples'] and env['exceptions']:
566 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
Michalis Spyrou35f35a62019-12-23 11:29:52 +0000567 print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0")
568 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100569 SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100570
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100571if env['exceptions']:
Freddie Liardet487d3902021-09-21 12:36:43 +0100572 if env['build_config'] or env['high_priority']:
573 print("WARNING: Building tests for selected operators not supported")
574 Return()
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100575 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
576 print("WARNING: Building tests for bare metal and armv7a is not supported")
577 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100578 SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0)
Motti Gondabif76a5022021-12-21 13:19:29 +0200579
580# Unknown variables are not allowed
581# Note: we must delay the call of UnknownVariables until after
582# we have applied the Variables object to the construction environment
583unknown = vars.UnknownVariables()
584if unknown:
585 print("Unknown variables: %s" % " ".join(unknown.keys()))
Ramy Elgammal451c3092022-02-01 23:01:27 +0000586 Exit(1)