Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | # Copyright (c) 2016-2021 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 4 | # |
| 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 | |
| 25 | import SCons |
| 26 | import os |
| 27 | import subprocess |
| 28 | |
| 29 | def version_at_least(version, required): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 31 | version_list = version.split('.') |
| 32 | required_list = required.split('.') |
| 33 | end = min(len(version_list), len(required_list)) |
| 34 | for i in range(0, end): |
| 35 | if int(version_list[i]) < int(required_list[i]): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | return False |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 37 | elif int(version_list[i]) > int(required_list[i]): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 38 | return True |
| 39 | |
| 40 | return True |
| 41 | |
| 42 | vars = Variables("scons") |
| 43 | vars.AddVariables( |
| 44 | BoolVariable("debug", "Debug", False), |
| 45 | BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False), |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 46 | BoolVariable("logging", "Logging (this flag is forced to 1 for debug=1)", False), |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 47 | EnumVariable("arch", "Target Architecture", "armv7a", |
Slava Barinov | db0e2c8 | 2021-04-07 11:23:27 +0300 | [diff] [blame] | 48 | 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 Park | 50e98bb | 2021-01-14 14:54:14 +0000 | [diff] [blame] | 49 | "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "armv8.6-a-sve2", "armv8r64", "x86")), |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 50 | EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")), |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 51 | EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal")), |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 52 | EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 53 | BoolVariable("examples", "Build example programs", True), |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 54 | BoolVariable("gemm_tuner", "Build gemm_tuner programs", True), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 55 | BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True), |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 56 | BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 57 | BoolVariable("opencl", "Enable OpenCL support", True), |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 58 | BoolVariable("neon", "Enable Arm® Neon™ support", False), |
Anthony Barbier | cc0a80b | 2017-12-15 11:37:29 +0000 | [diff] [blame] | 59 | BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True), |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 60 | BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary. Note embed_kernels should be enabled", False), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False), |
Anthony Barbier | b467021 | 2018-05-18 16:55:39 +0100 | [diff] [blame] | 62 | BoolVariable("tracing", "Enable runtime tracing", False), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 63 | BoolVariable("openmp", "Enable OpenMP backend", False), |
| 64 | BoolVariable("cppthreads", "Enable C++11 threads backend", True), |
| 65 | PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept), |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 66 | PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept), |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 67 | BoolVariable("exceptions", "Enable/disable C++ exception support", True), |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 68 | PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept), |
Michele Di Giorgio | 72610dc | 2020-11-18 15:29:08 +0000 | [diff] [blame] | 69 | PathVariable("external_tests_dir", "Add examples, benchmarks and tests to the tests suite", "", PathVariable.PathAccept), |
Georgios Pinitas | 49c6ced | 2020-09-21 17:16:09 +0100 | [diff] [blame] | 70 | ListVariable("custom_options", "Custom options that can be used to turn on/off features", "none", ["disable_mmla_fp"]), |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 71 | ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32", "integer"]), |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 72 | ListVariable("data_layout_support", "Enable a list of data layout to support", "all", ["nhwc", "nchw"]), |
Anthony Barbier | 149de5b | 2018-12-06 10:27:37 +0000 | [diff] [blame] | 73 | ("toolchain_prefix", "Override the toolchain prefix", ""), |
alered01 | d8872c1 | 2020-02-10 11:29:45 +0000 | [diff] [blame] | 74 | ("compiler_prefix", "Override the compiler prefix", ""), |
Anthony Barbier | 7390e05 | 2018-03-13 09:29:41 +0000 | [diff] [blame] | 75 | ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""), |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 76 | ("extra_link_flags", "Extra LD flags to be appended to the build command", ""), |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 77 | ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""), |
| 78 | ("specs_file", "Specs file to use (e.g. rdimon.specs)", "") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 79 | ) |
| 80 | |
| 81 | env = Environment(platform="posix", variables=vars, ENV = os.environ) |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 82 | build_path = env['build_dir'] |
| 83 | # If build_dir is a relative path then add a #build/ prefix: |
| 84 | if not env['build_dir'].startswith('/'): |
| 85 | SConsignFile('build/%s/.scons' % build_path) |
| 86 | build_path = "#build/%s" % build_path |
| 87 | else: |
| 88 | SConsignFile('%s/.scons' % build_path) |
| 89 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 90 | install_path = env['install_dir'] |
| 91 | #If the install_dir is a relative path then assume it's from inside build_dir |
| 92 | if not env['install_dir'].startswith('/') and install_path != "": |
| 93 | install_path = "%s/%s" % (build_path, install_path) |
| 94 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 95 | env.Append(LIBPATH = [build_path]) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 96 | Export('env') |
| 97 | Export('vars') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 99 | def install_lib( lib ): |
| 100 | # If there is no install folder, then there is nothing to do: |
| 101 | if install_path == "": |
| 102 | return lib |
| 103 | return env.Install( "%s/lib/" % install_path, lib) |
| 104 | def install_bin( bin ): |
| 105 | # If there is no install folder, then there is nothing to do: |
| 106 | if install_path == "": |
| 107 | return bin |
| 108 | return env.Install( "%s/bin/" % install_path, bin) |
| 109 | def install_include( inc ): |
| 110 | if install_path == "": |
| 111 | return inc |
| 112 | return env.Install( "%s/include/" % install_path, inc) |
| 113 | |
| 114 | Export('install_lib') |
| 115 | Export('install_bin') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 116 | |
| 117 | Help(vars.GenerateHelpText(env)) |
| 118 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 119 | if env['linker_script'] and env['os'] != 'bare_metal': |
| 120 | print("Linker script is only supported for bare_metal builds") |
| 121 | Exit(1) |
| 122 | |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 123 | if env['build'] == "embed_only": |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 124 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 125 | Return() |
| 126 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 127 | if env['neon'] and 'x86' in env['arch']: |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 128 | print("Cannot compile Arm® Neon™ for x86") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 129 | Exit(1) |
| 130 | |
| 131 | if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 132 | print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above") |
| 133 | print("Update your version of SCons or use set_soname=0") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 134 | Exit(1) |
| 135 | |
| 136 | if env['os'] == 'bare_metal': |
| 137 | if env['cppthreads'] or env['openmp']: |
| 138 | print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0") |
| 139 | Exit(1) |
| 140 | |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 141 | if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']: |
| 142 | print("Compressed kernels are supported only for android builds") |
| 143 | Exit(1) |
| 144 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 145 | if not env['exceptions']: |
Manuel Bottini | ceaa0bf | 2021-02-16 15:15:19 +0000 | [diff] [blame] | 146 | if env['opencl']: |
| 147 | print("ERROR: OpenCL is not supported when building without exceptions. Use opencl=0") |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 148 | Exit(1) |
| 149 | |
| 150 | env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED']) |
| 151 | env.Append(CXXFLAGS = ['-fno-exceptions']) |
| 152 | |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 153 | env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM', |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 154 | '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2', |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 155 | '-Winit-self','-Wstrict-overflow=2','-Wswitch-default', |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 156 | '-std=c++14','-Woverloaded-virtual', '-Wformat-security', |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 157 | '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings']) |
Isabella Gottardi | b28f29d | 2017-11-09 17:05:07 +0000 | [diff] [blame] | 158 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 159 | env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP']) |
| 160 | |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 161 | default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++' |
| 162 | default_c_compiler = 'gcc' if env['os'] not in ['android', 'macos'] else 'clang' |
Anthony Barbier | a026e98 | 2018-01-18 10:57:52 +0000 | [diff] [blame] | 163 | cpp_compiler = os.environ.get('CXX', default_cpp_compiler) |
| 164 | c_compiler = os.environ.get('CC', default_c_compiler) |
| 165 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 166 | if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 167 | print( "WARNING: Only clang is officially supported to build the Compute Library for Android") |
Anthony Barbier | a026e98 | 2018-01-18 10:57:52 +0000 | [diff] [blame] | 168 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 169 | if 'clang++' in cpp_compiler: |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 170 | env.Append(CXXFLAGS = ['-Wno-vla-extension']) |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 171 | elif 'armclang' in cpp_compiler: |
| 172 | pass |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 173 | else: |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 174 | env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 175 | |
SiCongLi | 410e21e | 2020-12-11 15:07:53 +0000 | [diff] [blame] | 176 | if cpp_compiler == 'g++': |
| 177 | # Don't strip comments that could include markers |
| 178 | env.Append(CXXFLAGS = ['-C']) |
| 179 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 180 | if env['cppthreads']: |
| 181 | env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)]) |
| 182 | |
| 183 | if env['openmp']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 184 | env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)]) |
| 185 | env.Append(CXXFLAGS = ['-fopenmp']) |
| 186 | env.Append(LINKFLAGS = ['-fopenmp']) |
| 187 | |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 188 | # Validate and define state |
| 189 | if env['estate'] == 'auto': |
| 190 | if 'v7a' in env['arch']: |
| 191 | env['estate'] = '32' |
| 192 | else: |
| 193 | env['estate'] = '64' |
| 194 | |
| 195 | # Map legacy arch |
| 196 | if 'arm64' in env['arch']: |
| 197 | env['estate'] = '64' |
| 198 | |
| 199 | if 'v7a' in env['estate'] and env['estate'] == '64': |
| 200 | print("ERROR: armv7a architecture has only 32-bit execution state") |
| 201 | Exit(1) |
| 202 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 203 | # Add architecture specific flags |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 204 | prefix = "" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 205 | if 'v7a' in env['arch']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 206 | env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon']) |
Slava Barinov | db0e2c8 | 2021-04-07 11:23:27 +0300 | [diff] [blame] | 207 | if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 208 | env.Append(CXXFLAGS = ['-mfloat-abi=softfp']) |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 209 | else: |
| 210 | env.Append(CXXFLAGS = ['-mfloat-abi=hard']) |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 211 | elif 'v8' in env['arch']: |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 212 | if 'sve2' in env['arch']: |
| 213 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod']) |
Georgios Pinitas | 045d33c | 2020-12-07 20:52:55 +0000 | [diff] [blame] | 214 | env.Append(CPPDEFINES = ['SVE2']) |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 215 | elif 'sve' in env['arch']: |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 216 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod']) |
Sang-Hoon Park | 50e98bb | 2021-01-14 14:54:14 +0000 | [diff] [blame] | 217 | elif 'armv8r64' in env['arch']: |
| 218 | env.Append(CXXFLAGS = ['-march=armv8.4-a']) |
Georgios Pinitas | deb5b77 | 2020-12-07 20:39:51 +0000 | [diff] [blame] | 219 | elif 'v8.' in env['arch']: |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 220 | env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 221 | else: |
| 222 | env.Append(CXXFLAGS = ['-march=armv8-a']) |
| 223 | |
| 224 | if 'v8.6-a' in env['arch']: |
Georgios Pinitas | 49c6ced | 2020-09-21 17:16:09 +0100 | [diff] [blame] | 225 | env.Append(CPPDEFINES = ['MMLA_INT8', 'V8P6', 'V8P6_BF', 'ARM_COMPUTE_FORCE_BF16']) |
| 226 | if "disable_mmla_fp" not in env['custom_options']: |
| 227 | env.Append(CPPDEFINES = ['MMLA_FP32']) |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 228 | elif 'x86' in env['arch']: |
| 229 | if env['estate'] == '32': |
| 230 | env.Append(CCFLAGS = ['-m32']) |
| 231 | env.Append(LINKFLAGS = ['-m32']) |
| 232 | else: |
| 233 | env.Append(CXXFLAGS = ['-fPIC']) |
| 234 | env.Append(CCFLAGS = ['-m64']) |
| 235 | env.Append(LINKFLAGS = ['-m64']) |
| 236 | |
| 237 | # Define toolchain |
| 238 | prefix = "" |
| 239 | if 'x86' not in env['arch']: |
| 240 | if env['estate'] == '32': |
| 241 | if env['os'] == 'linux': |
| 242 | prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-" |
| 243 | elif env['os'] == 'bare_metal': |
| 244 | prefix = "arm-eabi-" |
| 245 | elif env['os'] == 'android': |
| 246 | prefix = "arm-linux-androideabi-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 247 | elif env['os'] == 'tizen': |
| 248 | prefix = "armv7l-tizen-linux-gnueabi-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 249 | elif env['estate'] == '64' and 'v8' in env['arch']: |
| 250 | if env['os'] == 'linux': |
| 251 | prefix = "aarch64-linux-gnu-" |
| 252 | elif env['os'] == 'bare_metal': |
| 253 | prefix = "aarch64-elf-" |
| 254 | elif env['os'] == 'android': |
| 255 | prefix = "aarch64-linux-android-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 256 | elif env['os'] == 'tizen': |
| 257 | prefix = "aarch64-tizen-linux-gnu-" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 258 | |
| 259 | if env['build'] == 'native': |
| 260 | prefix = "" |
| 261 | |
Anthony Barbier | 149de5b | 2018-12-06 10:27:37 +0000 | [diff] [blame] | 262 | if env["toolchain_prefix"] != "": |
| 263 | prefix = env["toolchain_prefix"] |
| 264 | |
alered01 | d8872c1 | 2020-02-10 11:29:45 +0000 | [diff] [blame] | 265 | compiler_prefix = prefix |
| 266 | if env["compiler_prefix"] != "": |
| 267 | compiler_prefix = env["compiler_prefix"] |
| 268 | |
| 269 | env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler |
| 270 | env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 271 | env['LD'] = prefix + "ld" |
| 272 | env['AS'] = prefix + "as" |
| 273 | env['AR'] = prefix + "ar" |
| 274 | env['RANLIB'] = prefix + "ranlib" |
| 275 | |
| 276 | if not GetOption("help"): |
| 277 | try: |
SiCong Li | 3b9a564 | 2020-10-16 12:10:15 +0100 | [diff] [blame] | 278 | compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 279 | except OSError: |
| 280 | print("ERROR: Compiler '%s' not found" % env['CXX']) |
| 281 | Exit(1) |
| 282 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 283 | if 'armclang' in cpp_compiler: |
| 284 | pass |
| 285 | elif 'clang++' not in cpp_compiler: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 286 | if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 287 | print("GCC 6.2.1 or newer is required to compile armv8.2-a code") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 288 | Exit(1) |
| 289 | elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'): |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 290 | print("GCC 4.9 or newer is required to compile Arm® Neon™ code for AArch64") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 291 | Exit(1) |
| 292 | |
| 293 | if version_at_least(compiler_ver, '6.1'): |
| 294 | env.Append(CXXFLAGS = ['-Wno-ignored-attributes']) |
| 295 | |
| 296 | if compiler_ver == '4.8.3': |
| 297 | env.Append(CXXFLAGS = ['-Wno-array-bounds']) |
| 298 | |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 299 | if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal': |
| 300 | env.Append(LINKFLAGS = ['-fstack-protector-strong']) |
| 301 | |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 302 | if env['data_type_support']: |
| 303 | if any(i in env['data_type_support'] for i in ['all', 'fp16']): |
| 304 | env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS']) |
| 305 | if any(i in env['data_type_support'] for i in ['all', 'fp32']): |
| 306 | env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS']) |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 307 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8']): |
| 308 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS']) |
| 309 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']): |
| 310 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS']) |
| 311 | if any(i in env['data_type_support'] for i in ['all', 'qsymm16']): |
| 312 | env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS']) |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 313 | if any(i in env['data_type_support'] for i in ['all', 'integer']): |
| 314 | env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS']) |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 315 | |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 316 | if env['data_layout_support']: |
| 317 | if any(i in env['data_layout_support'] for i in ['all', 'nhwc']): |
| 318 | env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS']) |
| 319 | if any(i in env['data_layout_support'] for i in ['all', 'nchw']): |
| 320 | env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS']) |
| 321 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 322 | if env['standalone']: |
| 323 | env.Append(CXXFLAGS = ['-fPIC']) |
Anthony Barbier | 665c89b | 2018-07-16 11:40:09 +0100 | [diff] [blame] | 324 | env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++']) |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 325 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 326 | if env['Werror']: |
| 327 | env.Append(CXXFLAGS = ['-Werror']) |
| 328 | |
| 329 | if env['os'] == 'android': |
| 330 | env.Append(CPPDEFINES = ['ANDROID']) |
Michalis Spyrou | 2d22c3f | 2020-02-12 14:50:19 +0000 | [diff] [blame] | 331 | env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 332 | elif env['os'] == 'bare_metal': |
| 333 | env.Append(LINKFLAGS = ['-static']) |
| 334 | env.Append(CXXFLAGS = ['-fPIC']) |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 335 | if env['specs_file'] == "": |
| 336 | env.Append(LINKFLAGS = ['-specs=rdimon.specs']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 337 | env.Append(CPPDEFINES = ['NO_MULTI_THREADING']) |
Michalis Spyrou | 07781ac | 2017-08-31 15:11:41 +0100 | [diff] [blame] | 338 | env.Append(CPPDEFINES = ['BARE_METAL']) |
Manuel Bottini | 827817e | 2020-11-19 12:12:06 +0000 | [diff] [blame] | 339 | if env['os'] == 'linux' and env['arch'] == 'armv7a': |
| 340 | env.Append(CXXFLAGS = [ '-Wno-psabi' ]) |
Giorgio Arena | e7254a0 | 2021-02-24 12:46:35 +0000 | [diff] [blame] | 341 | if not env['debug']: |
| 342 | env.Append(CPPDEFINES = ['LINUX_V7_RELEASE']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 343 | |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 344 | if env['specs_file'] != "": |
| 345 | env.Append(LINKFLAGS = ['-specs='+env['specs_file']]) |
| 346 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 347 | if env['neon']: |
| 348 | env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED']) |
| 349 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 350 | if env['opencl']: |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 351 | env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED']) |
Georgios Pinitas | e6032da | 2017-10-26 14:13:35 +0100 | [diff] [blame] | 352 | if env['os'] in ['bare_metal'] or env['standalone']: |
Anthony Barbier | 5f0124d | 2018-04-13 14:05:34 +0100 | [diff] [blame] | 353 | print("Cannot link OpenCL statically, which is required for bare metal / standalone builds") |
| 354 | Exit(1) |
| 355 | |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 356 | if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']): |
| 357 | env.Append(LIBS = ['pthread']) |
| 358 | |
Manuel Bottini | ceaa0bf | 2021-02-16 15:15:19 +0000 | [diff] [blame] | 359 | if env['opencl']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 360 | if env['embed_kernels']: |
| 361 | env.Append(CPPDEFINES = ['EMBEDDED_KERNELS']) |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 362 | if env['compress_kernels']: |
| 363 | env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS']) |
| 364 | env.Append(LIBS = ['z']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 365 | |
| 366 | if env['debug']: |
| 367 | env['asserts'] = True |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 368 | env['logging'] = True |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 369 | env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2']) |
| 370 | env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED']) |
| 371 | else: |
Ramana Radhakrishnan | d176d54 | 2019-07-04 11:38:45 +0100 | [diff] [blame] | 372 | env.Append(CXXFLAGS = ['-O3']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 373 | |
| 374 | if env['asserts']: |
| 375 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED']) |
Moritz Pflanzer | 8b74c78 | 2017-09-14 14:33:20 +0100 | [diff] [blame] | 376 | env.Append(CXXFLAGS = ['-fstack-protector-strong']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 377 | |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 378 | if env['logging']: |
| 379 | env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED']) |
| 380 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 381 | env.Append(CPPPATH = ['#/include', "#"]) |
| 382 | env.Append(CXXFLAGS = env['extra_cxx_flags']) |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 383 | env.Append(LINKFLAGS = env['extra_link_flags']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 384 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 385 | Default( install_include("arm_compute")) |
Anthony Barbier | 1056595 | 2018-11-15 09:50:06 +0000 | [diff] [blame] | 386 | Default( install_include("support")) |
Michele Di Giorgio | 6afea90 | 2019-04-03 11:40:20 +0100 | [diff] [blame] | 387 | Default( install_include("utils")) |
| 388 | for dirname in os.listdir("./include"): |
| 389 | Default( install_include("include/%s" % dirname)) |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 390 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 391 | Export('version_at_least') |
| 392 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 393 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6c0348f | 2017-11-10 18:32:38 +0000 | [diff] [blame] | 394 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 395 | if env['examples'] and env['exceptions']: |
| 396 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
Michalis Spyrou | 35f35a6 | 2019-12-23 11:29:52 +0000 | [diff] [blame] | 397 | print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0") |
| 398 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 399 | SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 400 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 401 | if env['exceptions']: |
| 402 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
| 403 | print("WARNING: Building tests for bare metal and armv7a is not supported") |
| 404 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 405 | SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0) |