Jenkins | 18b685f | 2020-08-21 10:26:22 +0100 | [diff] [blame] | 1 | # Copyright (c) 2016, 2017 Arm Limited. |
Anthony Barbier | 871448e | 2017-03-24 14:54:29 +0000 | [diff] [blame] | 2 | # |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | # of this software and associated documentation files (the "Software"), to |
| 7 | # deal in the Software without restriction, including without limitation the |
| 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 9 | # sell copies of the Software, and to permit persons to whom the Software is |
| 10 | # furnished to do so, subject to the following conditions: |
| 11 | # |
| 12 | # The above copyright notice and this permission notice shall be included in all |
| 13 | # copies or substantial portions of the Software. |
| 14 | # |
| 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | # SOFTWARE. |
| 22 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 23 | import SCons |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 24 | import os |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 25 | import subprocess |
| 26 | |
| 27 | def version_at_least(version, required): |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 28 | |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 29 | version_list = version.split('.') |
| 30 | required_list = required.split('.') |
| 31 | end = min(len(version_list), len(required_list)) |
| 32 | for i in range(0, end): |
| 33 | if int(version_list[i]) < int(required_list[i]): |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 34 | return False |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 35 | elif int(version_list[i]) > int(required_list[i]): |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 36 | return True |
| 37 | |
| 38 | return True |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 39 | |
| 40 | vars = Variables("scons") |
| 41 | vars.AddVariables( |
| 42 | BoolVariable("debug", "Debug", False), |
| 43 | BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False), |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 44 | BoolVariable("logging", "Logging (this flag is forced to 1 for debug=1)", False), |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 45 | EnumVariable("arch", "Target Architecture", "armv7a", |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 46 | allowed_values=("armv7a", "arm64-v8a", "arm64-v8.2-a", "arm64-v8.2-a-sve", "arm64-v8.2-a-sve2", "x86_32", "x86_64", |
| 47 | "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "armv8.6-a-sve2", "armv8r64", "x86")), |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 48 | EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")), |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 49 | EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal")), |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 50 | EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")), |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 51 | BoolVariable("examples", "Build example programs", True), |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 52 | BoolVariable("gemm_tuner", "Build gemm_tuner programs", True), |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 53 | BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True), |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 54 | BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False), |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 55 | BoolVariable("opencl", "Enable OpenCL support", True), |
| 56 | BoolVariable("neon", "Enable Neon support", False), |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 57 | BoolVariable("gles_compute", "Enable OpenGL ES Compute Shader support", False), |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 58 | BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True), |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 59 | BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary. Note embed_kernels should be enabled", False), |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 60 | BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False), |
Jenkins | 6a7771e | 2020-05-28 11:28:36 +0100 | [diff] [blame] | 61 | BoolVariable("tracing", "Enable runtime tracing", False), |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 62 | BoolVariable("openmp", "Enable OpenMP backend", False), |
| 63 | BoolVariable("cppthreads", "Enable C++11 threads backend", True), |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 64 | PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept), |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 65 | PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept), |
Jenkins | 514be65 | 2019-02-28 12:25:18 +0000 | [diff] [blame] | 66 | BoolVariable("exceptions", "Enable/disable C++ exception support", True), |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 67 | PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept), |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 68 | PathVariable("external_tests_dir", "Add examples, benchmarks and tests to the tests suite", "", PathVariable.PathAccept), |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 69 | ListVariable("custom_options", "Custom options that can be used to turn on/off features", "none", ["disable_mmla_fp"]), |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 70 | ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32", "integer"]), |
| 71 | ListVariable("data_layout_support", "Enable a list of data layout to support", "all", ["nhwc", "nchw"]), |
Jenkins | 514be65 | 2019-02-28 12:25:18 +0000 | [diff] [blame] | 72 | ("toolchain_prefix", "Override the toolchain prefix", ""), |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 73 | ("compiler_prefix", "Override the compiler prefix", ""), |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 74 | ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""), |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 75 | ("extra_link_flags", "Extra LD flags to be appended to the build command", ""), |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 76 | ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""), |
| 77 | ("specs_file", "Specs file to use (e.g. rdimon.specs)", "") |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 78 | ) |
| 79 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 80 | env = Environment(platform="posix", variables=vars, ENV = os.environ) |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 81 | build_path = env['build_dir'] |
| 82 | # If build_dir is a relative path then add a #build/ prefix: |
| 83 | if not env['build_dir'].startswith('/'): |
| 84 | SConsignFile('build/%s/.scons' % build_path) |
| 85 | build_path = "#build/%s" % build_path |
| 86 | else: |
| 87 | SConsignFile('%s/.scons' % build_path) |
| 88 | |
| 89 | install_path = env['install_dir'] |
| 90 | #If the install_dir is a relative path then assume it's from inside build_dir |
| 91 | if not env['install_dir'].startswith('/') and install_path != "": |
| 92 | install_path = "%s/%s" % (build_path, install_path) |
| 93 | |
| 94 | env.Append(LIBPATH = [build_path]) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 95 | Export('env') |
| 96 | Export('vars') |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 97 | |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 98 | def install_lib( lib ): |
| 99 | # If there is no install folder, then there is nothing to do: |
| 100 | if install_path == "": |
| 101 | return lib |
| 102 | return env.Install( "%s/lib/" % install_path, lib) |
| 103 | def install_bin( bin ): |
| 104 | # If there is no install folder, then there is nothing to do: |
| 105 | if install_path == "": |
| 106 | return bin |
| 107 | return env.Install( "%s/bin/" % install_path, bin) |
| 108 | def install_include( inc ): |
| 109 | if install_path == "": |
| 110 | return inc |
| 111 | return env.Install( "%s/include/" % install_path, inc) |
| 112 | |
| 113 | Export('install_lib') |
| 114 | Export('install_bin') |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 115 | |
| 116 | Help(vars.GenerateHelpText(env)) |
| 117 | |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 118 | if env['linker_script'] and env['os'] != 'bare_metal': |
| 119 | print("Linker script is only supported for bare_metal builds") |
| 120 | Exit(1) |
| 121 | |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 122 | if env['build'] == "embed_only": |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 123 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 124 | Return() |
| 125 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 126 | if env['neon'] and 'x86' in env['arch']: |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 127 | print("Cannot compile Neon for x86") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 128 | Exit(1) |
| 129 | |
| 130 | if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"): |
ggardet | e2542c9 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 131 | print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above") |
| 132 | print("Update your version of SCons or use set_soname=0") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 133 | Exit(1) |
| 134 | |
| 135 | if env['os'] == 'bare_metal': |
| 136 | if env['cppthreads'] or env['openmp']: |
| 137 | print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0") |
| 138 | Exit(1) |
| 139 | |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 140 | if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']: |
| 141 | print("Compressed kernels are supported only for android builds") |
| 142 | Exit(1) |
| 143 | |
Jenkins | 514be65 | 2019-02-28 12:25:18 +0000 | [diff] [blame] | 144 | if not env['exceptions']: |
| 145 | if env['opencl'] or env['gles_compute']: |
| 146 | print("ERROR: OpenCL and GLES are not supported when building without exceptions. Use opencl=0 gles_compute=0") |
| 147 | Exit(1) |
| 148 | |
| 149 | env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED']) |
| 150 | env.Append(CXXFLAGS = ['-fno-exceptions']) |
| 151 | |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 152 | env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM', |
| 153 | '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2', |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 154 | '-Winit-self','-Wstrict-overflow=2','-Wswitch-default', |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 155 | '-std=c++14','-Woverloaded-virtual', '-Wformat-security', |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 156 | '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings']) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 157 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 158 | env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP']) |
| 159 | |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 160 | default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++' |
| 161 | default_c_compiler = 'gcc' if env['os'] not in ['android', 'macos'] else 'clang' |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 162 | cpp_compiler = os.environ.get('CXX', default_cpp_compiler) |
| 163 | c_compiler = os.environ.get('CC', default_c_compiler) |
| 164 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 165 | if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ): |
ggardet | e2542c9 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 166 | print( "WARNING: Only clang is officially supported to build the Compute Library for Android") |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 167 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 168 | if 'clang++' in cpp_compiler: |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 169 | env.Append(CXXFLAGS = ['-Wno-vla-extension']) |
| 170 | elif 'armclang' in cpp_compiler: |
| 171 | pass |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 172 | else: |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 173 | env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 174 | |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 175 | if cpp_compiler == 'g++': |
| 176 | # Don't strip comments that could include markers |
| 177 | env.Append(CXXFLAGS = ['-C']) |
| 178 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 179 | if env['cppthreads']: |
| 180 | env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)]) |
| 181 | |
| 182 | if env['openmp']: |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 183 | if 'clang++' in cpp_compiler: |
ggardet | e2542c9 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 184 | print( "Clang does not support OpenMP. Use scheduler=cpp.") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 185 | Exit(1) |
| 186 | |
| 187 | env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)]) |
| 188 | env.Append(CXXFLAGS = ['-fopenmp']) |
| 189 | env.Append(LINKFLAGS = ['-fopenmp']) |
| 190 | |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 191 | # Validate and define state |
| 192 | if env['estate'] == 'auto': |
| 193 | if 'v7a' in env['arch']: |
| 194 | env['estate'] = '32' |
| 195 | else: |
| 196 | env['estate'] = '64' |
| 197 | |
| 198 | # Map legacy arch |
| 199 | if 'arm64' in env['arch']: |
| 200 | env['estate'] = '64' |
| 201 | |
| 202 | if 'v7a' in env['estate'] and env['estate'] == '64': |
| 203 | print("ERROR: armv7a architecture has only 32-bit execution state") |
| 204 | Exit(1) |
| 205 | |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 206 | # Add architecture specific flags |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 207 | prefix = "" |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 208 | if 'v7a' in env['arch']: |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 209 | env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon']) |
Jenkins | 6a7771e | 2020-05-28 11:28:36 +0100 | [diff] [blame] | 210 | if env['os'] == 'android' or env['os'] == 'tizen': |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 211 | env.Append(CXXFLAGS = ['-mfloat-abi=softfp']) |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 212 | else: |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 213 | env.Append(CXXFLAGS = ['-mfloat-abi=hard']) |
| 214 | elif 'v8' in env['arch']: |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 215 | if 'sve2' in env['arch']: |
| 216 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod']) |
| 217 | env.Append(CPPDEFINES = ['SVE2']) |
| 218 | elif 'sve' in env['arch']: |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 219 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod']) |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 220 | elif 'armv8r64' in env['arch']: |
| 221 | env.Append(CXXFLAGS = ['-march=armv8.4-a']) |
| 222 | elif 'v8.' in env['arch']: |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 223 | env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 224 | else: |
| 225 | env.Append(CXXFLAGS = ['-march=armv8-a']) |
| 226 | |
| 227 | if 'v8.6-a' in env['arch']: |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 228 | env.Append(CPPDEFINES = ['MMLA_INT8', 'V8P6', 'V8P6_BF', 'ARM_COMPUTE_FORCE_BF16']) |
| 229 | if "disable_mmla_fp" not in env['custom_options']: |
| 230 | env.Append(CPPDEFINES = ['MMLA_FP32']) |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 231 | elif 'x86' in env['arch']: |
| 232 | if env['estate'] == '32': |
| 233 | env.Append(CCFLAGS = ['-m32']) |
| 234 | env.Append(LINKFLAGS = ['-m32']) |
| 235 | else: |
| 236 | env.Append(CXXFLAGS = ['-fPIC']) |
| 237 | env.Append(CCFLAGS = ['-m64']) |
| 238 | env.Append(LINKFLAGS = ['-m64']) |
| 239 | |
| 240 | # Define toolchain |
| 241 | prefix = "" |
| 242 | if 'x86' not in env['arch']: |
| 243 | if env['estate'] == '32': |
| 244 | if env['os'] == 'linux': |
| 245 | prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-" |
| 246 | elif env['os'] == 'bare_metal': |
| 247 | prefix = "arm-eabi-" |
| 248 | elif env['os'] == 'android': |
| 249 | prefix = "arm-linux-androideabi-" |
Jenkins | 6a7771e | 2020-05-28 11:28:36 +0100 | [diff] [blame] | 250 | elif env['os'] == 'tizen': |
| 251 | prefix = "armv7l-tizen-linux-gnueabi-" |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 252 | elif env['estate'] == '64' and 'v8' in env['arch']: |
| 253 | if env['os'] == 'linux': |
| 254 | prefix = "aarch64-linux-gnu-" |
| 255 | elif env['os'] == 'bare_metal': |
| 256 | prefix = "aarch64-elf-" |
| 257 | elif env['os'] == 'android': |
| 258 | prefix = "aarch64-linux-android-" |
Jenkins | 6a7771e | 2020-05-28 11:28:36 +0100 | [diff] [blame] | 259 | elif env['os'] == 'tizen': |
| 260 | prefix = "aarch64-tizen-linux-gnu-" |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 261 | |
| 262 | if env['build'] == 'native': |
| 263 | prefix = "" |
| 264 | |
Jenkins | 514be65 | 2019-02-28 12:25:18 +0000 | [diff] [blame] | 265 | if env["toolchain_prefix"] != "": |
| 266 | prefix = env["toolchain_prefix"] |
| 267 | |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 268 | compiler_prefix = prefix |
| 269 | if env["compiler_prefix"] != "": |
| 270 | compiler_prefix = env["compiler_prefix"] |
| 271 | |
| 272 | env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler |
| 273 | env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 274 | env['LD'] = prefix + "ld" |
| 275 | env['AS'] = prefix + "as" |
| 276 | env['AR'] = prefix + "ar" |
| 277 | env['RANLIB'] = prefix + "ranlib" |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 278 | |
| 279 | if not GetOption("help"): |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 280 | try: |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 281 | compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip() |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 282 | except OSError: |
| 283 | print("ERROR: Compiler '%s' not found" % env['CXX']) |
| 284 | Exit(1) |
| 285 | |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 286 | if 'armclang' in cpp_compiler: |
| 287 | pass |
| 288 | elif 'clang++' not in cpp_compiler: |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 289 | if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'): |
ggardet | e2542c9 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 290 | print("GCC 6.2.1 or newer is required to compile armv8.2-a code") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 291 | Exit(1) |
| 292 | elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'): |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 293 | print("GCC 4.9 or newer is required to compile Neon code for AArch64") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 294 | Exit(1) |
| 295 | |
| 296 | if version_at_least(compiler_ver, '6.1'): |
| 297 | env.Append(CXXFLAGS = ['-Wno-ignored-attributes']) |
| 298 | |
| 299 | if compiler_ver == '4.8.3': |
| 300 | env.Append(CXXFLAGS = ['-Wno-array-bounds']) |
| 301 | |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 302 | if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal': |
| 303 | env.Append(LINKFLAGS = ['-fstack-protector-strong']) |
| 304 | |
| 305 | if env['data_type_support']: |
| 306 | if any(i in env['data_type_support'] for i in ['all', 'fp16']): |
| 307 | env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS']) |
| 308 | if any(i in env['data_type_support'] for i in ['all', 'fp32']): |
| 309 | env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS']) |
| 310 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8']): |
| 311 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS']) |
| 312 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']): |
| 313 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS']) |
| 314 | if any(i in env['data_type_support'] for i in ['all', 'qsymm16']): |
| 315 | env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS']) |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 316 | if any(i in env['data_type_support'] for i in ['all', 'integer']): |
| 317 | env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS']) |
| 318 | |
| 319 | if env['data_layout_support']: |
| 320 | if any(i in env['data_layout_support'] for i in ['all', 'nhwc']): |
| 321 | env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS']) |
| 322 | if any(i in env['data_layout_support'] for i in ['all', 'nchw']): |
| 323 | env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS']) |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 324 | |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 325 | if env['standalone']: |
| 326 | env.Append(CXXFLAGS = ['-fPIC']) |
| 327 | env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++']) |
| 328 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 329 | if env['Werror']: |
| 330 | env.Append(CXXFLAGS = ['-Werror']) |
| 331 | |
| 332 | if env['os'] == 'android': |
| 333 | env.Append(CPPDEFINES = ['ANDROID']) |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 334 | env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 335 | elif env['os'] == 'bare_metal': |
| 336 | env.Append(LINKFLAGS = ['-static']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 337 | env.Append(CXXFLAGS = ['-fPIC']) |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 338 | if env['specs_file'] == "": |
| 339 | env.Append(LINKFLAGS = ['-specs=rdimon.specs']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 340 | env.Append(CPPDEFINES = ['NO_MULTI_THREADING']) |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 341 | env.Append(CPPDEFINES = ['BARE_METAL']) |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 342 | if env['os'] == 'linux' and env['arch'] == 'armv7a': |
| 343 | env.Append(CXXFLAGS = [ '-Wno-psabi' ]) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 344 | |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 345 | if env['specs_file'] != "": |
| 346 | env.Append(LINKFLAGS = ['-specs='+env['specs_file']]) |
| 347 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 348 | if env['opencl']: |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 349 | if env['os'] in ['bare_metal'] or env['standalone']: |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 350 | print("Cannot link OpenCL statically, which is required for bare metal / standalone builds") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 351 | Exit(1) |
| 352 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 353 | if env['gles_compute']: |
| 354 | if env['os'] in ['bare_metal'] or env['standalone']: |
| 355 | print("Cannot link OpenGLES statically, which is required for bare metal / standalone builds") |
| 356 | Exit(1) |
| 357 | |
| 358 | if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']): |
| 359 | env.Append(LIBS = ['pthread']) |
| 360 | |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 361 | if env['opencl'] or env['gles_compute']: |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 362 | if env['embed_kernels']: |
| 363 | env.Append(CPPDEFINES = ['EMBEDDED_KERNELS']) |
Jenkins | 7dcb9fa | 2021-02-23 22:45:28 +0000 | [diff] [blame^] | 364 | if env['compress_kernels']: |
| 365 | env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS']) |
| 366 | env.Append(LIBS = ['z']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 367 | |
| 368 | if env['debug']: |
| 369 | env['asserts'] = True |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 370 | env['logging'] = True |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 371 | env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2']) |
| 372 | env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED']) |
| 373 | else: |
Jenkins | 975dfe1 | 2019-09-02 11:47:54 +0100 | [diff] [blame] | 374 | env.Append(CXXFLAGS = ['-O3']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 375 | |
| 376 | if env['asserts']: |
| 377 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED']) |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 378 | env.Append(CXXFLAGS = ['-fstack-protector-strong']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 379 | |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 380 | if env['logging']: |
| 381 | env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED']) |
| 382 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 383 | env.Append(CPPPATH = ['#/include', "#"]) |
| 384 | env.Append(CXXFLAGS = env['extra_cxx_flags']) |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 385 | env.Append(LINKFLAGS = env['extra_link_flags']) |
| 386 | |
| 387 | Default( install_include("arm_compute")) |
| 388 | Default( install_include("support")) |
Jenkins | 4ba87db | 2019-05-23 17:11:51 +0100 | [diff] [blame] | 389 | Default( install_include("utils")) |
| 390 | for dirname in os.listdir("./include"): |
| 391 | Default( install_include("include/%s" % dirname)) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 392 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 393 | Export('version_at_least') |
| 394 | |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 395 | if env['gles_compute'] and env['os'] != 'android': |
| 396 | env.Append(CPPPATH = ['#/include/linux']) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 397 | |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 398 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 399 | |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 400 | if env['examples'] and env['exceptions']: |
| 401 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
| 402 | print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0") |
| 403 | Return() |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 404 | SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 405 | |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 406 | if env['exceptions']: |
| 407 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
| 408 | print("WARNING: Building tests for bare metal and armv7a is not supported") |
| 409 | Return() |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 410 | SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0) |