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 |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 26 | import json |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | import os |
| 28 | import subprocess |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 29 | import sys |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | |
| 31 | def version_at_least(version, required): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 33 | version_list = version.split('.') |
| 34 | required_list = required.split('.') |
| 35 | end = min(len(version_list), len(required_list)) |
| 36 | for i in range(0, end): |
| 37 | if int(version_list[i]) < int(required_list[i]): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 38 | return False |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 39 | elif int(version_list[i]) > int(required_list[i]): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | return True |
| 41 | |
| 42 | return True |
| 43 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 44 | def read_build_config_json(build_config): |
| 45 | build_config_contents = {} |
| 46 | custom_types = [] |
| 47 | custom_layouts = [] |
| 48 | if os.path.isfile(build_config): |
| 49 | with open(build_config) as f: |
| 50 | try: |
| 51 | build_config_contents = json.load(f) |
| 52 | except: |
| 53 | print("Warning: Build configuration file is of invalid JSON format!") |
| 54 | else: |
| 55 | try: |
| 56 | build_config_contents = json.loads(build_config) |
| 57 | except: |
| 58 | print("Warning: Build configuration string is of invalid JSON format!") |
| 59 | if build_config_contents: |
| 60 | custom_types = build_config_contents.get("data_types", []) |
| 61 | custom_layouts = build_config_contents.get("data_layouts", []) |
| 62 | return custom_types, custom_layouts |
| 63 | |
| 64 | def update_data_type_layout_flags(env, data_types, data_layouts): |
| 65 | # Manage data-types |
| 66 | if any(i in data_types for i in ['all', 'fp16']): |
| 67 | env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS']) |
| 68 | if any(i in data_types for i in ['all', 'fp32']): |
| 69 | env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS']) |
| 70 | if any(i in data_types for i in ['all', 'qasymm8']): |
| 71 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS']) |
| 72 | if any(i in data_types for i in ['all', 'qasymm8_signed']): |
| 73 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS']) |
| 74 | if any(i in data_types for i in ['all', 'qsymm16']): |
| 75 | env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS']) |
| 76 | if any(i in data_types for i in ['all', 'integer']): |
| 77 | env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS']) |
| 78 | |
| 79 | # Manage data-layouts |
| 80 | if any(i in data_layouts for i in ['all', 'nhwc']): |
| 81 | env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS']) |
| 82 | if any(i in data_layouts for i in ['all', 'nchw']): |
| 83 | env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS']) |
| 84 | |
| 85 | return env |
| 86 | |
| 87 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 88 | vars = Variables("scons") |
| 89 | vars.AddVariables( |
| 90 | BoolVariable("debug", "Debug", False), |
| 91 | BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False), |
ramelg01 | 93d6cf0 | 2021-09-23 13:59:22 +0100 | [diff] [blame] | 92 | BoolVariable("logging", "Enable Logging", False), |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 93 | EnumVariable("arch", "Target Architecture", "armv7a", |
Slava Barinov | db0e2c8 | 2021-04-07 11:23:27 +0300 | [diff] [blame] | 94 | 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] | 95 | "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] | 96 | EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")), |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 97 | 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] | 98 | 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] | 99 | BoolVariable("examples", "Build example programs", True), |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 100 | BoolVariable("gemm_tuner", "Build gemm_tuner programs", True), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 101 | BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True), |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 102 | BoolVariable("multi_isa", "Build Multi ISA binary version of library. Note works only for armv8.2-a", False), |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 103 | 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] | 104 | BoolVariable("opencl", "Enable OpenCL support", True), |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 105 | BoolVariable("neon", "Enable Arm® Neon™ support", False), |
Anthony Barbier | cc0a80b | 2017-12-15 11:37:29 +0000 | [diff] [blame] | 106 | 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] | 107 | 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] | 108 | BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False), |
| 109 | BoolVariable("openmp", "Enable OpenMP backend", False), |
| 110 | BoolVariable("cppthreads", "Enable C++11 threads backend", True), |
| 111 | PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept), |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 112 | PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept), |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 113 | BoolVariable("exceptions", "Enable/disable C++ exception support", True), |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 114 | BoolVariable("high_priority", "Generate a library containing only the high priority operators", False), |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 115 | PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept), |
Michele Di Giorgio | 72610dc | 2020-11-18 15:29:08 +0000 | [diff] [blame] | 116 | 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] | 117 | 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] | 118 | 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] | 119 | 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] | 120 | ("toolchain_prefix", "Override the toolchain prefix", ""), |
alered01 | d8872c1 | 2020-02-10 11:29:45 +0000 | [diff] [blame] | 121 | ("compiler_prefix", "Override the compiler prefix", ""), |
Anthony Barbier | 7390e05 | 2018-03-13 09:29:41 +0000 | [diff] [blame] | 122 | ("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] | 123 | ("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] | 124 | ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""), |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 125 | ("specs_file", "Specs file to use (e.g. rdimon.specs)", ""), |
| 126 | ("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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 127 | ) |
| 128 | |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 129 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 130 | env = Environment(platform="posix", variables=vars, ENV = os.environ) |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 131 | build_path = env['build_dir'] |
| 132 | # If build_dir is a relative path then add a #build/ prefix: |
| 133 | if not env['build_dir'].startswith('/'): |
| 134 | SConsignFile('build/%s/.scons' % build_path) |
| 135 | build_path = "#build/%s" % build_path |
| 136 | else: |
| 137 | SConsignFile('%s/.scons' % build_path) |
| 138 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 139 | install_path = env['install_dir'] |
| 140 | #If the install_dir is a relative path then assume it's from inside build_dir |
| 141 | if not env['install_dir'].startswith('/') and install_path != "": |
| 142 | install_path = "%s/%s" % (build_path, install_path) |
| 143 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 144 | env.Append(LIBPATH = [build_path]) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 145 | Export('env') |
| 146 | Export('vars') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 147 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 148 | def install_lib( lib ): |
| 149 | # If there is no install folder, then there is nothing to do: |
| 150 | if install_path == "": |
| 151 | return lib |
| 152 | return env.Install( "%s/lib/" % install_path, lib) |
| 153 | def install_bin( bin ): |
| 154 | # If there is no install folder, then there is nothing to do: |
| 155 | if install_path == "": |
| 156 | return bin |
| 157 | return env.Install( "%s/bin/" % install_path, bin) |
| 158 | def install_include( inc ): |
| 159 | if install_path == "": |
| 160 | return inc |
| 161 | return env.Install( "%s/include/" % install_path, inc) |
| 162 | |
| 163 | Export('install_lib') |
| 164 | Export('install_bin') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 165 | |
| 166 | Help(vars.GenerateHelpText(env)) |
| 167 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 168 | if env['linker_script'] and env['os'] != 'bare_metal': |
| 169 | print("Linker script is only supported for bare_metal builds") |
| 170 | Exit(1) |
| 171 | |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 172 | if env['build'] == "embed_only": |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 173 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 174 | Return() |
| 175 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 176 | if env['neon'] and 'x86' in env['arch']: |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 177 | print("Cannot compile Arm® Neon™ for x86") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 178 | Exit(1) |
| 179 | |
| 180 | if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 181 | print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above") |
| 182 | print("Update your version of SCons or use set_soname=0") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 183 | Exit(1) |
| 184 | |
| 185 | if env['os'] == 'bare_metal': |
| 186 | if env['cppthreads'] or env['openmp']: |
| 187 | print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0") |
| 188 | Exit(1) |
| 189 | |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 190 | if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']: |
| 191 | print("Compressed kernels are supported only for android builds") |
| 192 | Exit(1) |
| 193 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 194 | if not env['exceptions']: |
Manuel Bottini | ceaa0bf | 2021-02-16 15:15:19 +0000 | [diff] [blame] | 195 | if env['opencl']: |
| 196 | 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] | 197 | Exit(1) |
| 198 | |
| 199 | env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED']) |
| 200 | env.Append(CXXFLAGS = ['-fno-exceptions']) |
| 201 | |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 202 | env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM', |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 203 | '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2', |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 204 | '-Winit-self','-Wstrict-overflow=2','-Wswitch-default', |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 205 | '-std=c++14','-Woverloaded-virtual', '-Wformat-security', |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 206 | '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings']) |
Isabella Gottardi | b28f29d | 2017-11-09 17:05:07 +0000 | [diff] [blame] | 207 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 208 | env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP']) |
| 209 | |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 210 | default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++' |
| 211 | 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] | 212 | cpp_compiler = os.environ.get('CXX', default_cpp_compiler) |
| 213 | c_compiler = os.environ.get('CC', default_c_compiler) |
| 214 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 215 | 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] | 216 | 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] | 217 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 218 | if 'clang++' in cpp_compiler: |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 219 | env.Append(CXXFLAGS = ['-Wno-vla-extension']) |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 220 | elif 'armclang' in cpp_compiler: |
| 221 | pass |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 222 | else: |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 223 | env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 224 | |
SiCongLi | 410e21e | 2020-12-11 15:07:53 +0000 | [diff] [blame] | 225 | if cpp_compiler == 'g++': |
| 226 | # Don't strip comments that could include markers |
| 227 | env.Append(CXXFLAGS = ['-C']) |
| 228 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 229 | if env['cppthreads']: |
| 230 | env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)]) |
| 231 | |
| 232 | if env['openmp']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 233 | env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)]) |
| 234 | env.Append(CXXFLAGS = ['-fopenmp']) |
| 235 | env.Append(LINKFLAGS = ['-fopenmp']) |
| 236 | |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 237 | # Validate and define state |
| 238 | if env['estate'] == 'auto': |
| 239 | if 'v7a' in env['arch']: |
| 240 | env['estate'] = '32' |
| 241 | else: |
| 242 | env['estate'] = '64' |
| 243 | |
| 244 | # Map legacy arch |
| 245 | if 'arm64' in env['arch']: |
| 246 | env['estate'] = '64' |
| 247 | |
| 248 | if 'v7a' in env['estate'] and env['estate'] == '64': |
| 249 | print("ERROR: armv7a architecture has only 32-bit execution state") |
| 250 | Exit(1) |
| 251 | |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 252 | if 'sve' in env['arch']: |
| 253 | env.Append(CPPDEFINES = ['ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE']) |
| 254 | if 'sve2' in env['arch']: |
| 255 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2']) |
| 256 | else: |
| 257 | env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON']) |
| 258 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 259 | # Add architecture specific flags |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 260 | prefix = "" |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 261 | if env['multi_isa']: |
| 262 | # assert arch version is v8 |
| 263 | if 'v8' not in env['arch']: |
| 264 | print("Currently Multi ISA binary is only supported for arm v8 family") |
| 265 | Exit(1) |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 266 | |
Georgios Pinitas | 8e2f64f | 2021-07-28 13:18:46 +0100 | [diff] [blame] | 267 | if 'v8.6-a' in env['arch']: |
Georgios Pinitas | 49c6ced | 2020-09-21 17:16:09 +0100 | [diff] [blame] | 268 | if "disable_mmla_fp" not in env['custom_options']: |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 269 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM']) |
Georgios Pinitas | 8e2f64f | 2021-07-28 13:18:46 +0100 | [diff] [blame] | 270 | |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 271 | else: # NONE "multi_isa" builds |
| 272 | |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 273 | if 'v7a' in env['arch']: |
| 274 | env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon']) |
| 275 | if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']: |
| 276 | env.Append(CXXFLAGS = ['-mfloat-abi=softfp']) |
| 277 | else: |
| 278 | env.Append(CXXFLAGS = ['-mfloat-abi=hard']) |
| 279 | elif 'v8' in env['arch']: |
| 280 | # Preserve the V8 archs for non-multi-ISA variants |
| 281 | if 'sve2' in env['arch']: |
| 282 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod']) |
| 283 | elif 'sve' in env['arch']: |
| 284 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod']) |
| 285 | elif 'armv8r64' in env['arch']: |
| 286 | env.Append(CXXFLAGS = ['-march=armv8.4-a']) |
| 287 | elif 'v8.' in env['arch']: |
| 288 | env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined |
| 289 | else: |
| 290 | env.Append(CXXFLAGS = ['-march=armv8-a']) |
| 291 | |
| 292 | if 'v8.6-a' in env['arch']: |
| 293 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_BF16']) |
| 294 | if "disable_mmla_fp" not in env['custom_options']: |
| 295 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM']) |
| 296 | if 'v8.' in env['arch']: |
| 297 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FP16']) |
| 298 | |
| 299 | elif 'x86' in env['arch']: |
| 300 | if env['estate'] == '32': |
| 301 | env.Append(CCFLAGS = ['-m32']) |
| 302 | env.Append(LINKFLAGS = ['-m32']) |
| 303 | else: |
| 304 | env.Append(CXXFLAGS = ['-fPIC']) |
| 305 | env.Append(CCFLAGS = ['-m64']) |
| 306 | env.Append(LINKFLAGS = ['-m64']) |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 307 | |
| 308 | # Define toolchain |
| 309 | prefix = "" |
| 310 | if 'x86' not in env['arch']: |
| 311 | if env['estate'] == '32': |
| 312 | if env['os'] == 'linux': |
| 313 | prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-" |
| 314 | elif env['os'] == 'bare_metal': |
| 315 | prefix = "arm-eabi-" |
| 316 | elif env['os'] == 'android': |
| 317 | prefix = "arm-linux-androideabi-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 318 | elif env['os'] == 'tizen': |
| 319 | prefix = "armv7l-tizen-linux-gnueabi-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 320 | elif env['estate'] == '64' and 'v8' in env['arch']: |
| 321 | if env['os'] == 'linux': |
| 322 | prefix = "aarch64-linux-gnu-" |
| 323 | elif env['os'] == 'bare_metal': |
| 324 | prefix = "aarch64-elf-" |
| 325 | elif env['os'] == 'android': |
| 326 | prefix = "aarch64-linux-android-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 327 | elif env['os'] == 'tizen': |
| 328 | prefix = "aarch64-tizen-linux-gnu-" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 329 | |
| 330 | if env['build'] == 'native': |
| 331 | prefix = "" |
| 332 | |
Anthony Barbier | 149de5b | 2018-12-06 10:27:37 +0000 | [diff] [blame] | 333 | if env["toolchain_prefix"] != "": |
| 334 | prefix = env["toolchain_prefix"] |
| 335 | |
alered01 | d8872c1 | 2020-02-10 11:29:45 +0000 | [diff] [blame] | 336 | compiler_prefix = prefix |
| 337 | if env["compiler_prefix"] != "": |
| 338 | compiler_prefix = env["compiler_prefix"] |
| 339 | |
| 340 | env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler |
| 341 | env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 342 | env['LD'] = prefix + "ld" |
| 343 | env['AS'] = prefix + "as" |
| 344 | env['AR'] = prefix + "ar" |
| 345 | env['RANLIB'] = prefix + "ranlib" |
| 346 | |
| 347 | if not GetOption("help"): |
| 348 | try: |
SiCong Li | 3b9a564 | 2020-10-16 12:10:15 +0100 | [diff] [blame] | 349 | compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 350 | except OSError: |
| 351 | print("ERROR: Compiler '%s' not found" % env['CXX']) |
| 352 | Exit(1) |
| 353 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 354 | if 'armclang' in cpp_compiler: |
| 355 | pass |
| 356 | elif 'clang++' not in cpp_compiler: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 357 | 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] | 358 | 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] | 359 | Exit(1) |
| 360 | 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] | 361 | 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] | 362 | Exit(1) |
| 363 | |
| 364 | if version_at_least(compiler_ver, '6.1'): |
| 365 | env.Append(CXXFLAGS = ['-Wno-ignored-attributes']) |
| 366 | |
| 367 | if compiler_ver == '4.8.3': |
| 368 | env.Append(CXXFLAGS = ['-Wno-array-bounds']) |
| 369 | |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 370 | if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal': |
| 371 | env.Append(LINKFLAGS = ['-fstack-protector-strong']) |
| 372 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 373 | if env['high_priority'] and env['build_config']: |
SiCongLi | dc85d78 | 2021-12-17 13:22:55 +0000 | [diff] [blame] | 374 | print("The high priority library cannot be built in conjunction with a user-specified build configuration") |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 375 | Exit(1) |
| 376 | |
| 377 | if not env['high_priority'] and not env['build_config']: |
| 378 | env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED']) |
| 379 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 380 | data_types = [] |
| 381 | data_layouts = [] |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 382 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 383 | # Set correct data types / layouts to build |
| 384 | if env['high_priority']: |
| 385 | data_types = ['all'] |
| 386 | data_layouts = ['all'] |
| 387 | elif env['build_config']: |
| 388 | data_types, data_layouts = read_build_config_json(env['build_config']) |
| 389 | else: |
| 390 | data_types = env['data_type_support'] |
| 391 | data_layouts = env['data_layout_support'] |
| 392 | |
| 393 | env = update_data_type_layout_flags(env, data_types, data_layouts) |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 394 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 395 | if env['standalone']: |
| 396 | env.Append(CXXFLAGS = ['-fPIC']) |
Anthony Barbier | 665c89b | 2018-07-16 11:40:09 +0100 | [diff] [blame] | 397 | env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++']) |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 398 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 399 | if env['Werror']: |
| 400 | env.Append(CXXFLAGS = ['-Werror']) |
| 401 | |
| 402 | if env['os'] == 'android': |
| 403 | env.Append(CPPDEFINES = ['ANDROID']) |
Michalis Spyrou | 2d22c3f | 2020-02-12 14:50:19 +0000 | [diff] [blame] | 404 | env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 405 | elif env['os'] == 'bare_metal': |
| 406 | env.Append(LINKFLAGS = ['-static']) |
| 407 | env.Append(CXXFLAGS = ['-fPIC']) |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 408 | if env['specs_file'] == "": |
| 409 | env.Append(LINKFLAGS = ['-specs=rdimon.specs']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 410 | env.Append(CPPDEFINES = ['NO_MULTI_THREADING']) |
Michalis Spyrou | 07781ac | 2017-08-31 15:11:41 +0100 | [diff] [blame] | 411 | env.Append(CPPDEFINES = ['BARE_METAL']) |
Manuel Bottini | 827817e | 2020-11-19 12:12:06 +0000 | [diff] [blame] | 412 | if env['os'] == 'linux' and env['arch'] == 'armv7a': |
| 413 | env.Append(CXXFLAGS = [ '-Wno-psabi' ]) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 414 | |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 415 | if env['specs_file'] != "": |
| 416 | env.Append(LINKFLAGS = ['-specs='+env['specs_file']]) |
| 417 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 418 | if env['neon']: |
| 419 | env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED']) |
| 420 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 421 | if env['opencl']: |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 422 | env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED']) |
Georgios Pinitas | e6032da | 2017-10-26 14:13:35 +0100 | [diff] [blame] | 423 | if env['os'] in ['bare_metal'] or env['standalone']: |
Anthony Barbier | 5f0124d | 2018-04-13 14:05:34 +0100 | [diff] [blame] | 424 | print("Cannot link OpenCL statically, which is required for bare metal / standalone builds") |
| 425 | Exit(1) |
| 426 | |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 427 | if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']): |
| 428 | env.Append(LIBS = ['pthread']) |
| 429 | |
Manuel Bottini | ceaa0bf | 2021-02-16 15:15:19 +0000 | [diff] [blame] | 430 | if env['opencl']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 431 | if env['embed_kernels']: |
| 432 | env.Append(CPPDEFINES = ['EMBEDDED_KERNELS']) |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 433 | if env['compress_kernels']: |
| 434 | env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS']) |
| 435 | env.Append(LIBS = ['z']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 436 | |
| 437 | if env['debug']: |
| 438 | env['asserts'] = True |
| 439 | env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2']) |
| 440 | env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED']) |
| 441 | else: |
Ramana Radhakrishnan | d176d54 | 2019-07-04 11:38:45 +0100 | [diff] [blame] | 442 | env.Append(CXXFLAGS = ['-O3']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 443 | |
| 444 | if env['asserts']: |
| 445 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED']) |
Moritz Pflanzer | 8b74c78 | 2017-09-14 14:33:20 +0100 | [diff] [blame] | 446 | env.Append(CXXFLAGS = ['-fstack-protector-strong']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 447 | |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 448 | if env['logging']: |
| 449 | env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED']) |
| 450 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 451 | env.Append(CPPPATH = ['#/include', "#"]) |
| 452 | env.Append(CXXFLAGS = env['extra_cxx_flags']) |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 453 | env.Append(LINKFLAGS = env['extra_link_flags']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 454 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 455 | Default( install_include("arm_compute")) |
Anthony Barbier | 1056595 | 2018-11-15 09:50:06 +0000 | [diff] [blame] | 456 | Default( install_include("support")) |
Michele Di Giorgio | 6afea90 | 2019-04-03 11:40:20 +0100 | [diff] [blame] | 457 | Default( install_include("utils")) |
| 458 | for dirname in os.listdir("./include"): |
| 459 | Default( install_include("include/%s" % dirname)) |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 460 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 461 | Export('version_at_least') |
| 462 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 463 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6c0348f | 2017-11-10 18:32:38 +0000 | [diff] [blame] | 464 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 465 | if env['examples'] and (env['build_config'] or env['high_priority']): |
| 466 | print("WARNING: Building examples for selected operators not supported. Use examples=0") |
| 467 | Return() |
| 468 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 469 | if env['examples'] and env['exceptions']: |
| 470 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
Michalis Spyrou | 35f35a6 | 2019-12-23 11:29:52 +0000 | [diff] [blame] | 471 | print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0") |
| 472 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 473 | SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 474 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 475 | if env['exceptions']: |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 476 | if env['build_config'] or env['high_priority']: |
| 477 | print("WARNING: Building tests for selected operators not supported") |
| 478 | Return() |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 479 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
| 480 | print("WARNING: Building tests for bare metal and armv7a is not supported") |
| 481 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 482 | SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0) |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 483 | |
| 484 | # Unknown variables are not allowed |
| 485 | # Note: we must delay the call of UnknownVariables until after |
| 486 | # we have applied the Variables object to the construction environment |
| 487 | unknown = vars.UnknownVariables() |
| 488 | if unknown: |
| 489 | print("Unknown variables: %s" % " ".join(unknown.keys())) |
| 490 | Exit(1) |