Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
Jakub Sujak | b5d6082 | 2024-01-28 18:30:50 +0000 | [diff] [blame] | 3 | # Copyright (c) 2016-2024 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 |
Jakub Sujak | 78a17a1 | 2023-06-09 09:51:31 +0100 | [diff] [blame] | 28 | import subprocess |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | |
| 30 | def version_at_least(version, required): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 32 | version_list = version.split('.') |
| 33 | required_list = required.split('.') |
| 34 | end = min(len(version_list), len(required_list)) |
| 35 | for i in range(0, end): |
| 36 | if int(version_list[i]) < int(required_list[i]): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | return False |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 38 | elif int(version_list[i]) > int(required_list[i]): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | return True |
| 40 | |
| 41 | return True |
| 42 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 43 | def read_build_config_json(build_config): |
| 44 | build_config_contents = {} |
| 45 | custom_types = [] |
| 46 | custom_layouts = [] |
| 47 | if os.path.isfile(build_config): |
| 48 | with open(build_config) as f: |
| 49 | try: |
| 50 | build_config_contents = json.load(f) |
| 51 | except: |
| 52 | print("Warning: Build configuration file is of invalid JSON format!") |
| 53 | else: |
| 54 | try: |
| 55 | build_config_contents = json.loads(build_config) |
| 56 | except: |
| 57 | print("Warning: Build configuration string is of invalid JSON format!") |
| 58 | if build_config_contents: |
| 59 | custom_types = build_config_contents.get("data_types", []) |
| 60 | custom_layouts = build_config_contents.get("data_layouts", []) |
| 61 | return custom_types, custom_layouts |
| 62 | |
| 63 | def update_data_type_layout_flags(env, data_types, data_layouts): |
| 64 | # Manage data-types |
Pablo Marquez Tello | 9f7aca9 | 2023-08-16 15:21:44 +0100 | [diff] [blame] | 65 | if env['multi_isa']: |
| 66 | if any(i in data_types for i in ['all', 'fp16']): |
Pablo Marquez Tello | 391f872 | 2023-12-07 15:27:26 +0000 | [diff] [blame] | 67 | env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS', '-DARM_COMPUTE_ENABLE_FP16']) |
Pablo Marquez Tello | 9f7aca9 | 2023-08-16 15:21:44 +0100 | [diff] [blame] | 68 | else: |
Pablo Marquez Tello | 23158b0 | 2023-11-28 16:58:02 +0000 | [diff] [blame] | 69 | if not 'v8a' in env['arch'] and not 'v7a' in env['arch'] and not 'armv8r64' in env['arch']: |
Pablo Marquez Tello | 9f7aca9 | 2023-08-16 15:21:44 +0100 | [diff] [blame] | 70 | if any(i in data_types for i in ['all', 'fp16']): |
Pablo Marquez Tello | 391f872 | 2023-12-07 15:27:26 +0000 | [diff] [blame] | 71 | env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS','-DARM_COMPUTE_ENABLE_FP16']) |
Pablo Marquez Tello | 9f7aca9 | 2023-08-16 15:21:44 +0100 | [diff] [blame] | 72 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 73 | if any(i in data_types for i in ['all', 'fp32']): |
| 74 | env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS']) |
| 75 | if any(i in data_types for i in ['all', 'qasymm8']): |
| 76 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS']) |
| 77 | if any(i in data_types for i in ['all', 'qasymm8_signed']): |
| 78 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS']) |
| 79 | if any(i in data_types for i in ['all', 'qsymm16']): |
| 80 | env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS']) |
| 81 | if any(i in data_types for i in ['all', 'integer']): |
| 82 | env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS']) |
| 83 | |
| 84 | # Manage data-layouts |
| 85 | if any(i in data_layouts for i in ['all', 'nhwc']): |
| 86 | env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS']) |
| 87 | if any(i in data_layouts for i in ['all', 'nchw']): |
| 88 | env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS']) |
| 89 | |
| 90 | return env |
| 91 | |
| 92 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 93 | vars = Variables("scons") |
| 94 | vars.AddVariables( |
| 95 | BoolVariable("debug", "Debug", False), |
| 96 | 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] | 97 | BoolVariable("logging", "Enable Logging", False), |
Michalis Spyrou | a3f7cd2 | 2022-07-04 15:32:02 +0100 | [diff] [blame] | 98 | EnumVariable("arch", "Target Architecture. The x86_32 and x86_64 targets can only be used with neon=0 and opencl=1.", "armv7a", |
Slava Barinov | db0e2c8 | 2021-04-07 11:23:27 +0300 | [diff] [blame] | 99 | 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", |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 100 | "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "armv8.6-a-sve2", "armv8.6-a-sve2-sme2", "armv8r64", "x86")), |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 101 | EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")), |
Michalis Spyrou | a3f7cd2 | 2022-07-04 15:32:02 +0100 | [diff] [blame] | 102 | EnumVariable("os", "Target OS. With bare metal selected, only Arm® Neon™ (not OpenCL) can be used, static libraries get built and Neon™'s multi-threading support is disabled.", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal", "openbsd","windows")), |
| 103 | EnumVariable("build", "Either build directly on your device (native) or cross compile from your desktop machine (cross-compile). In both cases make sure the compiler is available in your path.", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 104 | BoolVariable("examples", "Build example programs", True), |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 105 | BoolVariable("gemm_tuner", "Build gemm_tuner programs", True), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 106 | BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True), |
Sunita Nadampalli | 911d572 | 2023-05-02 14:05:39 +0000 | [diff] [blame] | 107 | BoolVariable("multi_isa", "Build Multi ISA binary version of library. Works for armv8a without the support for FP16 vector arithmetic. Use armv8.2-a or beyond to enable FP16 vector arithmetic support", False), |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 108 | 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] | 109 | BoolVariable("opencl", "Enable OpenCL support", True), |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 110 | BoolVariable("neon", "Enable Arm® Neon™ support", False), |
Michalis Spyrou | a3f7cd2 | 2022-07-04 15:32:02 +0100 | [diff] [blame] | 111 | BoolVariable("embed_kernels", "Enable if you want the OpenCL kernels to be built in the library's binaries instead of being read from separate '.cl' / '.cs' files. If embed_kernels is set to 0 then the application can set the path to the folder containing the OpenCL kernel files by calling CLKernelLibrary::init(). By default the path is set to './cl_kernels'.", True), |
| 112 | BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary using zlib. Useful for reducing the binary size. embed_kernels should be enabled", False), |
| 113 | BoolVariable("set_soname", "If enabled the library will contain a SONAME and SHLIBVERSION and some symlinks will automatically be created between the objects. (requires SCons 2.4 or above)", False), |
| 114 | BoolVariable("openmp", "Enable OpenMP backend. Only works when building with g++ and not clang++", False), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 115 | BoolVariable("cppthreads", "Enable C++11 threads backend", True), |
| 116 | PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept), |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 117 | PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept), |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 118 | BoolVariable("exceptions", "Enable/disable C++ exception support", True), |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 119 | 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] | 120 | PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept), |
Pablo Marquez Tello | 9f7aca9 | 2023-08-16 15:21:44 +0100 | [diff] [blame] | 121 | PathVariable("external_tests_dir", """Add examples, benchmarks and tests to the tests suite from an external path. In order to use this option, the external tests directory must have the following structure: |
Michalis Spyrou | a3f7cd2 | 2022-07-04 15:32:02 +0100 | [diff] [blame] | 122 | EXTERNAL_TESTS_DIR: |
| 123 | └── tests |
| 124 | ├── benchmark |
| 125 | │ ├── CL |
| 126 | │ ├── datasets |
| 127 | │ ├── fixtures |
| 128 | │ └── Neon |
| 129 | └── validation |
| 130 | ├── CL |
| 131 | ├── datasets |
| 132 | ├── fixtures |
| 133 | └── Neon\n""", "", PathVariable.PathAccept), |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 134 | BoolVariable("experimental_dynamic_fusion", "Build the experimental dynamic fusion files. This option also enables opencl=1 on which it has a direct dependency.", False), |
Nathan John Sircombe | d7113e4 | 2023-04-26 15:02:43 +0100 | [diff] [blame] | 135 | BoolVariable("fixed_format_kernels", "Enable fixed format kernels for GEMM", False), |
Pablo Marquez Tello | 299d3a1 | 2022-10-12 14:58:24 +0100 | [diff] [blame] | 136 | BoolVariable("mapfile", "Generate a map file", False), |
Georgios Pinitas | 49c6ced | 2020-09-21 17:16:09 +0100 | [diff] [blame] | 137 | 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] | 138 | 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] | 139 | ListVariable("data_layout_support", "Enable a list of data layout to support", "all", ["nhwc", "nchw"]), |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 140 | ("toolchain_prefix", "Override the toolchain prefix; used by all toolchain components: compilers, linker, assembler etc. If unspecified, use default(auto) prefixes; if passed an empty string '' prefixes would be disabled", "auto"), |
| 141 | ("compiler_prefix", "Override the compiler prefix; used by just compilers (CC,CXX); further overrides toolchain_prefix for compilers; this is for when the compiler prefixes are different from that of the linkers, archivers etc. If unspecified, this is the same as toolchain_prefix; if passed an empty string '' prefixes would be disabled", "auto"), |
Jakub Sujak | b5d6082 | 2024-01-28 18:30:50 +0000 | [diff] [blame] | 142 | BoolVariable("address_sanitizer", "Enable AddressSanitizer", False), |
| 143 | BoolVariable("undefined_sanitizer", "Enable UndefinedBehaviorSanitizer", False), |
Matthew Bentham | 0a59e69 | 2023-07-19 15:01:00 +0000 | [diff] [blame] | 144 | BoolVariable("thread_sanitizer", "Enable ThreadSanitizer", False), |
Anthony Barbier | 7390e05 | 2018-03-13 09:29:41 +0000 | [diff] [blame] | 145 | ("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] | 146 | ("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] | 147 | ("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] | 148 | ("specs_file", "Specs file to use (e.g. rdimon.specs)", ""), |
| 149 | ("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] | 150 | ) |
| 151 | |
Viet-Hoa Do | 36dc77d | 2023-03-03 10:44:58 +0000 | [diff] [blame] | 152 | if version_at_least(SCons.__version__, "4.0"): |
| 153 | vars.Add(BoolVariable("export_compile_commands", "Export compile_commands.json file.", False)) |
| 154 | |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 155 | |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 156 | env = Environment(variables=vars, ENV = os.environ) |
| 157 | |
| 158 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 159 | build_path = env['build_dir'] |
| 160 | # If build_dir is a relative path then add a #build/ prefix: |
| 161 | if not env['build_dir'].startswith('/'): |
| 162 | SConsignFile('build/%s/.scons' % build_path) |
| 163 | build_path = "#build/%s" % build_path |
| 164 | else: |
| 165 | SConsignFile('%s/.scons' % build_path) |
| 166 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 167 | install_path = env['install_dir'] |
| 168 | #If the install_dir is a relative path then assume it's from inside build_dir |
| 169 | if not env['install_dir'].startswith('/') and install_path != "": |
| 170 | install_path = "%s/%s" % (build_path, install_path) |
| 171 | |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame] | 172 | env.Append(LIBPATH = [build_path, os.path.join(build_path, "")]) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 173 | Export('env') |
| 174 | Export('vars') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 175 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 176 | def install_lib( lib ): |
| 177 | # If there is no install folder, then there is nothing to do: |
| 178 | if install_path == "": |
| 179 | return lib |
| 180 | return env.Install( "%s/lib/" % install_path, lib) |
| 181 | def install_bin( bin ): |
| 182 | # If there is no install folder, then there is nothing to do: |
| 183 | if install_path == "": |
| 184 | return bin |
| 185 | return env.Install( "%s/bin/" % install_path, bin) |
| 186 | def install_include( inc ): |
| 187 | if install_path == "": |
| 188 | return inc |
| 189 | return env.Install( "%s/include/" % install_path, inc) |
| 190 | |
| 191 | Export('install_lib') |
| 192 | Export('install_bin') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 193 | |
| 194 | Help(vars.GenerateHelpText(env)) |
| 195 | |
Viet-Hoa Do | 36dc77d | 2023-03-03 10:44:58 +0000 | [diff] [blame] | 196 | # Export compile_commands.json file |
| 197 | if env.get("export_compile_commands", False): |
| 198 | env.Tool("compilation_db") |
| 199 | env.CompilationDatabase("%s/compile_commands.json" % build_path) |
| 200 | |
Michalis Spyrou | 14ce094 | 2022-06-13 15:40:35 +0100 | [diff] [blame] | 201 | if 'armv7a' in env['arch'] and env['os'] == 'android': |
SiCong Li | 13f96d0 | 2022-06-21 10:06:51 +0100 | [diff] [blame] | 202 | print("WARNING: armv7a on Android is no longer maintained") |
Michalis Spyrou | 14ce094 | 2022-06-13 15:40:35 +0100 | [diff] [blame] | 203 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 204 | if env['linker_script'] and env['os'] != 'bare_metal': |
| 205 | print("Linker script is only supported for bare_metal builds") |
| 206 | Exit(1) |
| 207 | |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 208 | if env['build'] == "embed_only": |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 209 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 210 | Return() |
| 211 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 212 | if env['neon'] and 'x86' in env['arch']: |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 213 | print("Cannot compile Arm® Neon™ for x86") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 214 | Exit(1) |
| 215 | |
| 216 | if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 217 | print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above") |
| 218 | print("Update your version of SCons or use set_soname=0") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 219 | Exit(1) |
| 220 | |
| 221 | if env['os'] == 'bare_metal': |
| 222 | if env['cppthreads'] or env['openmp']: |
| 223 | print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0") |
| 224 | Exit(1) |
| 225 | |
Jakub Sujak | 8c49f16 | 2023-06-16 09:52:50 +0100 | [diff] [blame] | 226 | if env['experimental_dynamic_fusion']: |
| 227 | # Dynamic Fusion on GPU has a direct dependency on OpenCL and Compute Kernel Writer |
| 228 | env['opencl'] = 1 |
Jakub Sujak | 8c49f16 | 2023-06-16 09:52:50 +0100 | [diff] [blame] | 229 | |
Gunes Bayir | 1561d40 | 2024-02-06 16:04:15 +0000 | [diff] [blame^] | 230 | # Build CKW by default |
| 231 | env["extra_cxx_flags"] += ' -DACL_INTERNAL_TEST_CKW_IN_DF' |
| 232 | |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 233 | if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']: |
| 234 | print("Compressed kernels are supported only for android builds") |
| 235 | Exit(1) |
| 236 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 237 | if not env['exceptions']: |
Manuel Bottini | ceaa0bf | 2021-02-16 15:15:19 +0000 | [diff] [blame] | 238 | if env['opencl']: |
| 239 | 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] | 240 | Exit(1) |
| 241 | |
| 242 | env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED']) |
| 243 | env.Append(CXXFLAGS = ['-fno-exceptions']) |
| 244 | |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 245 | env.Append(CXXFLAGS = ['-DARCH_ARM', |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 246 | '-Wextra','-Wdisabled-optimization','-Wformat=2', |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 247 | '-Winit-self','-Wstrict-overflow=2','-Wswitch-default', |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 248 | '-Woverloaded-virtual', '-Wformat-security', |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 249 | '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings']) |
Isabella Gottardi | b28f29d | 2017-11-09 17:05:07 +0000 | [diff] [blame] | 250 | |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 251 | if not 'windows' in env['os']: |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 252 | env.Append(CXXFLAGS = ['-Wall','-std=c++14', '-pedantic' ]) |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 253 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 254 | |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 255 | cpp_tool = {'linux': 'g++', 'android' : 'clang++', |
| 256 | 'tizen': 'g++', 'macos':'clang++', |
| 257 | 'bare_metal':'g++', 'openbsd':'g++','windows':'clang-cl'} |
| 258 | |
| 259 | c_tool = {'linux':'gcc', 'android': 'clang', 'tizen':'gcc', |
| 260 | 'macos':'clang','bare_metal':'gcc', |
| 261 | 'openbsd':'gcc','windows':'clang-cl'} |
| 262 | |
| 263 | default_cpp_compiler = cpp_tool[env['os']] |
| 264 | default_c_compiler = c_tool[env['os']] |
Anthony Barbier | a026e98 | 2018-01-18 10:57:52 +0000 | [diff] [blame] | 265 | cpp_compiler = os.environ.get('CXX', default_cpp_compiler) |
| 266 | c_compiler = os.environ.get('CC', default_c_compiler) |
| 267 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 268 | 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] | 269 | 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] | 270 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 271 | if 'clang++' in cpp_compiler: |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 272 | env.Append(CXXFLAGS = ['-Wno-vla-extension']) |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 273 | elif 'armclang' in cpp_compiler: |
| 274 | pass |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 275 | elif not 'windows' in env['os']: |
Giorgio Arena | b83e672 | 2022-03-24 14:23:07 +0000 | [diff] [blame] | 276 | env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel','-Wno-misleading-indentation']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 277 | |
SiCongLi | 410e21e | 2020-12-11 15:07:53 +0000 | [diff] [blame] | 278 | if cpp_compiler == 'g++': |
| 279 | # Don't strip comments that could include markers |
| 280 | env.Append(CXXFLAGS = ['-C']) |
| 281 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 282 | if env['cppthreads']: |
| 283 | env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)]) |
| 284 | |
| 285 | if env['openmp']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 286 | env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)]) |
| 287 | env.Append(CXXFLAGS = ['-fopenmp']) |
| 288 | env.Append(LINKFLAGS = ['-fopenmp']) |
| 289 | |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 290 | # Validate and define state |
| 291 | if env['estate'] == 'auto': |
| 292 | if 'v7a' in env['arch']: |
| 293 | env['estate'] = '32' |
| 294 | else: |
| 295 | env['estate'] = '64' |
| 296 | |
| 297 | # Map legacy arch |
| 298 | if 'arm64' in env['arch']: |
| 299 | env['estate'] = '64' |
| 300 | |
| 301 | if 'v7a' in env['estate'] and env['estate'] == '64': |
| 302 | print("ERROR: armv7a architecture has only 32-bit execution state") |
| 303 | Exit(1) |
| 304 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 305 | env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON']) |
| 306 | |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 307 | if 'sve' in env['arch']: |
| 308 | env.Append(CPPDEFINES = ['ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE']) |
| 309 | if 'sve2' in env['arch']: |
| 310 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2']) |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 311 | |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 312 | if 'sme' in env['arch']: |
| 313 | env.Append(CPPDEFINES = ['ENABLE_SME', 'ARM_COMPUTE_ENABLE_SME']) |
| 314 | if 'sme2' in env['arch']: |
| 315 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SME2']) |
| 316 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 317 | # Add architecture specific flags |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 318 | if env['multi_isa']: |
| 319 | # assert arch version is v8 |
| 320 | if 'v8' not in env['arch']: |
| 321 | print("Currently Multi ISA binary is only supported for arm v8 family") |
| 322 | Exit(1) |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 323 | |
Sunita Nadampalli | 911d572 | 2023-05-02 14:05:39 +0000 | [diff] [blame] | 324 | if 'v8a' in env['arch']: |
Pablo Marquez Tello | 9f7aca9 | 2023-08-16 15:21:44 +0100 | [diff] [blame] | 325 | env.Append(CXXFLAGS = ['-march=armv8-a']) |
Sunita Nadampalli | 911d572 | 2023-05-02 14:05:39 +0000 | [diff] [blame] | 326 | else: |
| 327 | if 'v8.6-a' in env['arch']: |
| 328 | if "disable_mmla_fp" not in env['custom_options']: |
| 329 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM']) |
Georgios Pinitas | 8e2f64f | 2021-07-28 13:18:46 +0100 | [diff] [blame] | 330 | |
Sunita Nadampalli | 911d572 | 2023-05-02 14:05:39 +0000 | [diff] [blame] | 331 | env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined |
Giorgio Arena | 73fa0a7 | 2022-02-10 15:06:51 +0000 | [diff] [blame] | 332 | |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 333 | else: # NONE "multi_isa" builds |
| 334 | |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 335 | if 'v7a' in env['arch']: |
| 336 | env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon']) |
| 337 | if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']: |
| 338 | env.Append(CXXFLAGS = ['-mfloat-abi=softfp']) |
| 339 | else: |
| 340 | env.Append(CXXFLAGS = ['-mfloat-abi=hard']) |
Pablo Marquez Tello | d208f4f | 2022-07-19 12:19:46 +0100 | [diff] [blame] | 341 | elif 'v8.6-a' in env['arch']: |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 342 | if 'armv8.6-a-sve2' in env['arch']: |
Pablo Marquez Tello | d208f4f | 2022-07-19 12:19:46 +0100 | [diff] [blame] | 343 | env.Append(CXXFLAGS = ['-march=armv8.6-a+sve2']) |
| 344 | elif 'armv8.6-a-sve' == env['arch']: |
| 345 | env.Append(CXXFLAGS = ['-march=armv8.6-a+sve']) |
| 346 | elif 'armv8.6-a' == env['arch']: |
Pablo Marquez Tello | cf07d11 | 2022-09-28 21:37:37 +0100 | [diff] [blame] | 347 | env.Append(CXXFLAGS = ['-march=armv8.6-a+fp16']) |
Pablo Marquez Tello | d208f4f | 2022-07-19 12:19:46 +0100 | [diff] [blame] | 348 | |
| 349 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_BF16','ARM_COMPUTE_ENABLE_FP16']) |
| 350 | if "disable_mmla_fp" not in env['custom_options']: |
| 351 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM']) |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 352 | elif 'v8' in env['arch']: |
| 353 | # Preserve the V8 archs for non-multi-ISA variants |
| 354 | if 'sve2' in env['arch']: |
| 355 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod']) |
| 356 | elif 'sve' in env['arch']: |
| 357 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod']) |
| 358 | elif 'armv8r64' in env['arch']: |
| 359 | env.Append(CXXFLAGS = ['-march=armv8.4-a']) |
| 360 | elif 'v8.' in env['arch']: |
| 361 | env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined |
| 362 | else: |
| 363 | env.Append(CXXFLAGS = ['-march=armv8-a']) |
| 364 | |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 365 | if 'v8.' in env['arch']: |
| 366 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FP16']) |
| 367 | |
| 368 | elif 'x86' in env['arch']: |
| 369 | if env['estate'] == '32': |
| 370 | env.Append(CCFLAGS = ['-m32']) |
| 371 | env.Append(LINKFLAGS = ['-m32']) |
| 372 | else: |
| 373 | env.Append(CXXFLAGS = ['-fPIC']) |
| 374 | env.Append(CCFLAGS = ['-m64']) |
| 375 | env.Append(LINKFLAGS = ['-m64']) |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 376 | |
| 377 | # Define toolchain |
SiCongLi | fecdb8f | 2022-01-04 18:33:17 +0000 | [diff] [blame] | 378 | # The reason why we distinguish toolchain_prefix from compiler_prefix is for cases where the linkers/archivers use a |
| 379 | # different prefix than the compilers. An example is the NDK r20 toolchain |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 380 | auto_toolchain_prefix = "" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 381 | if 'x86' not in env['arch']: |
| 382 | if env['estate'] == '32': |
| 383 | if env['os'] == 'linux': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 384 | auto_toolchain_prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 385 | elif env['os'] == 'bare_metal': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 386 | auto_toolchain_prefix = "arm-eabi-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 387 | elif env['os'] == 'android': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 388 | auto_toolchain_prefix = "arm-linux-androideabi-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 389 | elif env['os'] == 'tizen': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 390 | auto_toolchain_prefix = "armv7l-tizen-linux-gnueabi-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 391 | elif env['estate'] == '64' and 'v8' in env['arch']: |
| 392 | if env['os'] == 'linux': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 393 | auto_toolchain_prefix = "aarch64-linux-gnu-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 394 | elif env['os'] == 'bare_metal': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 395 | auto_toolchain_prefix = "aarch64-elf-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 396 | elif env['os'] == 'android': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 397 | auto_toolchain_prefix = "aarch64-linux-android-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 398 | elif env['os'] == 'tizen': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 399 | auto_toolchain_prefix = "aarch64-tizen-linux-gnu-" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 400 | |
Pablo Marquez Tello | ddf2f6c | 2022-06-28 12:56:27 +0100 | [diff] [blame] | 401 | if env['build'] == 'native' or env["toolchain_prefix"] == "": |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 402 | toolchain_prefix = "" |
| 403 | elif env["toolchain_prefix"] == "auto": |
| 404 | toolchain_prefix = auto_toolchain_prefix |
| 405 | else: |
SiCongLi | fecdb8f | 2022-01-04 18:33:17 +0000 | [diff] [blame] | 406 | toolchain_prefix = env["toolchain_prefix"] |
Anthony Barbier | 149de5b | 2018-12-06 10:27:37 +0000 | [diff] [blame] | 407 | |
Pablo Marquez Tello | ddf2f6c | 2022-06-28 12:56:27 +0100 | [diff] [blame] | 408 | if env['build'] == 'native' or env["compiler_prefix"] == "": |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 409 | compiler_prefix = "" |
| 410 | elif env["compiler_prefix"] == "auto": |
| 411 | compiler_prefix = toolchain_prefix |
| 412 | else: |
alered01 | d8872c1 | 2020-02-10 11:29:45 +0000 | [diff] [blame] | 413 | compiler_prefix = env["compiler_prefix"] |
| 414 | |
| 415 | env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler |
| 416 | env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler |
SiCongLi | fecdb8f | 2022-01-04 18:33:17 +0000 | [diff] [blame] | 417 | env['LD'] = toolchain_prefix + "ld" |
| 418 | env['AS'] = toolchain_prefix + "as" |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 419 | |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 420 | if env['os'] == 'windows': |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 421 | env['AR'] = "llvm-lib" |
| 422 | env['RANLIB'] = "llvm-ranlib" |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 423 | else: |
SiCongLi | fecdb8f | 2022-01-04 18:33:17 +0000 | [diff] [blame] | 424 | env['AR'] = toolchain_prefix + "ar" |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 425 | |
SiCongLi | fecdb8f | 2022-01-04 18:33:17 +0000 | [diff] [blame] | 426 | env['RANLIB'] = toolchain_prefix + "ranlib" |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 427 | |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 428 | print("Using compilers:") |
| 429 | print("CC", env['CC']) |
| 430 | print("CXX", env['CXX']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 431 | |
Jakub Sujak | 78a17a1 | 2023-06-09 09:51:31 +0100 | [diff] [blame] | 432 | """Build the Compute Kernel Writer subproject""" |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 433 | if env['experimental_dynamic_fusion']: |
Jakub Sujak | 7a698a3 | 2023-06-21 09:45:41 +0100 | [diff] [blame] | 434 | # Strip ccache prefix from CC and CXX to obtain only the target triple |
Jakub Sujak | 78a17a1 | 2023-06-09 09:51:31 +0100 | [diff] [blame] | 435 | CKW_CC = env['CC'].replace(env['compiler_cache'] + " ", "") |
| 436 | CKW_CXX = env['CXX'].replace(env['compiler_cache'] + " ", "") |
| 437 | CKW_CCACHE = 1 if env['compiler_cache'] else 0 |
| 438 | |
| 439 | CKW_BUILD_TYPE = "Debug" if env['debug'] else "Release" |
| 440 | |
| 441 | CKW_ENABLE_OPENCL = env['opencl'] |
| 442 | CKW_ENABLE_ASSERTS = env['debug'] or env['asserts'] |
| 443 | |
| 444 | CKW_PROJECT_DIR = Dir('.').path + "/compute_kernel_writer" |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame] | 445 | CKW_INCLUDE_DIR = CKW_PROJECT_DIR + "/include" |
Jakub Sujak | 78a17a1 | 2023-06-09 09:51:31 +0100 | [diff] [blame] | 446 | CKW_BUILD_DIR = build_path.replace("#", "") |
| 447 | |
Jakub Sujak | bec9b03 | 2023-06-09 14:13:30 +0100 | [diff] [blame] | 448 | CKW_CMAKE_CMD = "CC={CKW_CC} CXX={CKW_CXX} cmake -G \"Unix Makefiles\" " \ |
Jakub Sujak | 78a17a1 | 2023-06-09 09:51:31 +0100 | [diff] [blame] | 449 | "-S {CKW_PROJECT_DIR} -B {CKW_BUILD_DIR} " \ |
| 450 | "-DCMAKE_BUILD_TYPE={CKW_BUILD_TYPE} " \ |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame] | 451 | "-DCKW_ENABLE_OPENCL=ON " \ |
Jakub Sujak | 78a17a1 | 2023-06-09 09:51:31 +0100 | [diff] [blame] | 452 | "-DCKW_ENABLE_ASSERTS={CKW_ENABLE_ASSERTS} " \ |
| 453 | "-DCKW_CCACHE={CKW_CCACHE} ".format(CKW_CC=CKW_CC, |
| 454 | CKW_CXX=CKW_CXX, |
| 455 | CKW_PROJECT_DIR=CKW_PROJECT_DIR, |
| 456 | CKW_BUILD_DIR=CKW_BUILD_DIR, |
| 457 | CKW_BUILD_TYPE=CKW_BUILD_TYPE, |
| 458 | CKW_ENABLE_OPENCL=CKW_ENABLE_OPENCL, |
| 459 | CKW_ENABLE_ASSERTS=CKW_ENABLE_ASSERTS, |
| 460 | CKW_CCACHE=CKW_CCACHE |
| 461 | ) |
| 462 | |
Jakub Sujak | 7a698a3 | 2023-06-21 09:45:41 +0100 | [diff] [blame] | 463 | # Configure CKW static objects with -fPIC (CMAKE_POSITION_INDEPENDENT_CODE) option to enable linking statically to ACL |
| 464 | CKW_CMAKE_CONFIGURE_STATIC = CKW_CMAKE_CMD + "-DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON" |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame] | 465 | CKW_CMAKE_BUILD = "cmake --build {CKW_BUILD_DIR} --target ckw -j{NUM_JOBS}".format(CKW_BUILD_DIR=CKW_BUILD_DIR, |
Jakub Sujak | e86f992 | 2023-07-05 17:30:02 +0100 | [diff] [blame] | 466 | NUM_JOBS=GetOption('num_jobs') |
| 467 | ) |
Jakub Sujak | 78a17a1 | 2023-06-09 09:51:31 +0100 | [diff] [blame] | 468 | |
| 469 | # Build Compute Kernel Writer Static Library |
| 470 | subprocess.check_call(CKW_CMAKE_CONFIGURE_STATIC, stderr=subprocess.STDOUT, shell=True) |
| 471 | subprocess.check_call(CKW_CMAKE_BUILD, stderr=subprocess.STDOUT, shell=True) |
| 472 | |
Jakub Sujak | 7a698a3 | 2023-06-21 09:45:41 +0100 | [diff] [blame] | 473 | # Let ACL know where to find CKW headers |
Jakub Sujak | 78a17a1 | 2023-06-09 09:51:31 +0100 | [diff] [blame] | 474 | env.Append(CPPPATH = CKW_INCLUDE_DIR) |
| 475 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 476 | if not GetOption("help"): |
| 477 | try: |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 478 | if env['os'] == 'windows': |
Jakub Sujak | 78a17a1 | 2023-06-09 09:51:31 +0100 | [diff] [blame] | 479 | compiler_ver = subprocess.check_output("clang++ -dumpversion").decode().strip() |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 480 | else: |
Jakub Sujak | 78a17a1 | 2023-06-09 09:51:31 +0100 | [diff] [blame] | 481 | compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 482 | except OSError: |
| 483 | print("ERROR: Compiler '%s' not found" % env['CXX']) |
| 484 | Exit(1) |
| 485 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 486 | if 'armclang' in cpp_compiler: |
| 487 | pass |
| 488 | elif 'clang++' not in cpp_compiler: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 489 | 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] | 490 | 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] | 491 | Exit(1) |
| 492 | 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] | 493 | 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] | 494 | Exit(1) |
| 495 | |
| 496 | if version_at_least(compiler_ver, '6.1'): |
| 497 | env.Append(CXXFLAGS = ['-Wno-ignored-attributes']) |
| 498 | |
| 499 | if compiler_ver == '4.8.3': |
| 500 | env.Append(CXXFLAGS = ['-Wno-array-bounds']) |
| 501 | |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 502 | if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal': |
| 503 | env.Append(LINKFLAGS = ['-fstack-protector-strong']) |
| 504 | |
SiCong Li | bf5274d | 2022-07-20 17:45:36 +0100 | [diff] [blame] | 505 | # Add Android NDK toolchain specific flags |
| 506 | if 'clang++' in cpp_compiler and env['os'] == 'android': |
| 507 | # For NDK >= r21, clang 9 or above is used |
| 508 | if version_at_least(compiler_ver, '9.0.0'): |
| 509 | env['ndk_above_r21'] = True |
Giorgio Arena | b83e672 | 2022-03-24 14:23:07 +0000 | [diff] [blame] | 510 | |
SiCong Li | bf5274d | 2022-07-20 17:45:36 +0100 | [diff] [blame] | 511 | if env['openmp']: |
| 512 | env.Append(LINKFLAGS = ['-static-openmp']) |
| 513 | |
| 514 | # For NDK >= r23, clang 12 or above is used. This condition detects NDK < r23 |
| 515 | if not version_at_least(compiler_ver, '12.0.0'): |
| 516 | # System assembler is deprecated and integrated assembler is preferred since r23. |
| 517 | # However integrated assembler has always been suppressed for NDK < r23. |
| 518 | # Thus for backward compatibility, we include this flag only for NDK < r23 |
| 519 | env.Append(CXXFLAGS = ['-no-integrated-as']) |
Giorgio Arena | b83e672 | 2022-03-24 14:23:07 +0000 | [diff] [blame] | 520 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 521 | if env['high_priority'] and env['build_config']: |
SiCongLi | dc85d78 | 2021-12-17 13:22:55 +0000 | [diff] [blame] | 522 | 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] | 523 | Exit(1) |
| 524 | |
| 525 | if not env['high_priority'] and not env['build_config']: |
| 526 | env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED']) |
| 527 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 528 | data_types = [] |
| 529 | data_layouts = [] |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 530 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 531 | # Set correct data types / layouts to build |
| 532 | if env['high_priority']: |
| 533 | data_types = ['all'] |
| 534 | data_layouts = ['all'] |
| 535 | elif env['build_config']: |
| 536 | data_types, data_layouts = read_build_config_json(env['build_config']) |
| 537 | else: |
| 538 | data_types = env['data_type_support'] |
| 539 | data_layouts = env['data_layout_support'] |
| 540 | |
| 541 | env = update_data_type_layout_flags(env, data_types, data_layouts) |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 542 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 543 | if env['standalone']: |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 544 | if not 'windows' in env['os']: |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 545 | env.Append(CXXFLAGS = ['-fPIC']) |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 546 | env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++']) |
Pablo Marquez Tello | 9f7aca9 | 2023-08-16 15:21:44 +0100 | [diff] [blame] | 547 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 548 | if env['Werror']: |
| 549 | env.Append(CXXFLAGS = ['-Werror']) |
| 550 | |
| 551 | if env['os'] == 'android': |
| 552 | env.Append(CPPDEFINES = ['ANDROID']) |
Michalis Spyrou | 2d22c3f | 2020-02-12 14:50:19 +0000 | [diff] [blame] | 553 | env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 554 | elif env['os'] == 'bare_metal': |
| 555 | env.Append(LINKFLAGS = ['-static']) |
| 556 | env.Append(CXXFLAGS = ['-fPIC']) |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 557 | if env['specs_file'] == "": |
| 558 | env.Append(LINKFLAGS = ['-specs=rdimon.specs']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 559 | env.Append(CPPDEFINES = ['NO_MULTI_THREADING']) |
Michalis Spyrou | 07781ac | 2017-08-31 15:11:41 +0100 | [diff] [blame] | 560 | env.Append(CPPDEFINES = ['BARE_METAL']) |
Manuel Bottini | 827817e | 2020-11-19 12:12:06 +0000 | [diff] [blame] | 561 | if env['os'] == 'linux' and env['arch'] == 'armv7a': |
| 562 | env.Append(CXXFLAGS = [ '-Wno-psabi' ]) |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 563 | if env['os'] == 'windows': |
| 564 | env.Append(CXXFLAGS = [ '/std:c++14','/EHa']) |
| 565 | env.Append(CXXFLAGS = [ '-Wno-c++98-compat', '-Wno-covered-switch-default','-Wno-c++98-compat-pedantic']) |
| 566 | env.Append(CXXFLAGS = [ '-Wno-shorten-64-to-32', '-Wno-sign-conversion','-Wno-documentation']) |
| 567 | env.Append(CXXFLAGS = [ '-Wno-extra-semi-stmt', '-Wno-float-equal','-Wno-implicit-int-conversion']) |
| 568 | env.Append(CXXFLAGS = [ '-Wno-documentation-pedantic', '-Wno-extra-semi','-Wno-shadow-field-in-constructor']) |
| 569 | env.Append(CXXFLAGS = [ '-Wno-float-conversion', '-Wno-switch-enum','-Wno-comma']) |
| 570 | env.Append(CXXFLAGS = [ '-Wno-implicit-float-conversion', '-Wno-deprecated-declarations','-Wno-old-style-cast']) |
| 571 | env.Append(CXXFLAGS = [ '-Wno-zero-as-null-pointer-constant', '-Wno-inconsistent-missing-destructor-override']) |
Pablo Tello | fbbfa53 | 2023-01-26 16:24:04 +0000 | [diff] [blame] | 572 | env.Append(CXXFLAGS = [ '-Wno-asm-operand-widths']) |
| 573 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 574 | |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 575 | if env['specs_file'] != "": |
| 576 | env.Append(LINKFLAGS = ['-specs='+env['specs_file']]) |
| 577 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 578 | if env['neon']: |
| 579 | env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED']) |
| 580 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 581 | if env['opencl']: |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 582 | env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED']) |
Georgios Pinitas | e6032da | 2017-10-26 14:13:35 +0100 | [diff] [blame] | 583 | if env['os'] in ['bare_metal'] or env['standalone']: |
Anthony Barbier | 5f0124d | 2018-04-13 14:05:34 +0100 | [diff] [blame] | 584 | print("Cannot link OpenCL statically, which is required for bare metal / standalone builds") |
| 585 | Exit(1) |
| 586 | |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 587 | if env["os"] not in ["windows","android", "bare_metal"] and (env['opencl'] or env['cppthreads']): |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 588 | env.Append(LIBS = ['pthread']) |
| 589 | |
Kevin Lo | 7195f71 | 2022-01-07 15:46:02 +0800 | [diff] [blame] | 590 | if env['os'] == 'openbsd': |
| 591 | env.Append(LIBS = ['c']) |
| 592 | env.Append(CXXFLAGS = ['-fPIC']) |
| 593 | |
Manuel Bottini | ceaa0bf | 2021-02-16 15:15:19 +0000 | [diff] [blame] | 594 | if env['opencl']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 595 | if env['embed_kernels']: |
| 596 | env.Append(CPPDEFINES = ['EMBEDDED_KERNELS']) |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 597 | if env['compress_kernels']: |
| 598 | env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS']) |
| 599 | env.Append(LIBS = ['z']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 600 | |
| 601 | if env['debug']: |
| 602 | env['asserts'] = True |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 603 | if not 'windows' in env['os']: |
| 604 | env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2']) |
| 605 | else: |
| 606 | env.Append(CXXFLAGS = ['-Z7','-MTd','-fms-compatibility','-fdelayed-template-parsing']) |
| 607 | env.Append(LINKFLAGS = ['-DEBUG']) |
Pablo Marquez Tello | 9f7aca9 | 2023-08-16 15:21:44 +0100 | [diff] [blame] | 608 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 609 | env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED']) |
| 610 | else: |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 611 | if not 'windows' in env['os']: |
| 612 | env.Append(CXXFLAGS = ['-O3']) |
| 613 | else: |
| 614 | # on windows we use clang-cl which does not support the option -O3 |
| 615 | env.Append(CXXFLAGS = ['-O2']) |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 616 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 617 | if env['asserts']: |
| 618 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED']) |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 619 | if not 'windows' in env['os']: |
| 620 | env.Append(CXXFLAGS = ['-fstack-protector-strong']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 621 | |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 622 | if env['logging']: |
| 623 | env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED']) |
| 624 | |
Jakub Sujak | b5d6082 | 2024-01-28 18:30:50 +0000 | [diff] [blame] | 625 | if env['address_sanitizer']: |
| 626 | if 'android' in env['os']: |
| 627 | env.Append(CXXFLAGS = ['-fsanitize=hwaddress']) |
| 628 | env.Append(LINKFLAGS = ['-fsanitize=hwaddress']) |
| 629 | else: |
| 630 | env.Append(CXXFLAGS = ['-fsanitize=address']) |
| 631 | env.Append(LINKFLAGS = ['-fsanitize=address']) |
| 632 | |
| 633 | if env['undefined_sanitizer']: |
| 634 | env.Append(CXXFLAGS = ['-fsanitize=undefined']) |
| 635 | env.Append(LINKFLAGS = ['-fsanitize=undefined']) |
| 636 | |
Matthew Bentham | 0a59e69 | 2023-07-19 15:01:00 +0000 | [diff] [blame] | 637 | if env['thread_sanitizer']: |
| 638 | env.Append(CXXFLAGS = ['-fsanitize=thread']) |
| 639 | env.Append(LINKFLAGS = ['-fsanitize=thread']) |
| 640 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 641 | env.Append(CPPPATH = ['#/include', "#"]) |
| 642 | env.Append(CXXFLAGS = env['extra_cxx_flags']) |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 643 | env.Append(LINKFLAGS = env['extra_link_flags']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 644 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 645 | Default( install_include("arm_compute")) |
Anthony Barbier | 1056595 | 2018-11-15 09:50:06 +0000 | [diff] [blame] | 646 | Default( install_include("support")) |
Michele Di Giorgio | 6afea90 | 2019-04-03 11:40:20 +0100 | [diff] [blame] | 647 | Default( install_include("utils")) |
| 648 | for dirname in os.listdir("./include"): |
| 649 | Default( install_include("include/%s" % dirname)) |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 650 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 651 | Export('version_at_least') |
| 652 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 653 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6c0348f | 2017-11-10 18:32:38 +0000 | [diff] [blame] | 654 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 655 | if env['examples'] and (env['build_config'] or env['high_priority']): |
| 656 | print("WARNING: Building examples for selected operators not supported. Use examples=0") |
| 657 | Return() |
| 658 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 659 | if env['examples'] and env['exceptions']: |
| 660 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
Michalis Spyrou | 35f35a6 | 2019-12-23 11:29:52 +0000 | [diff] [blame] | 661 | print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0") |
| 662 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 663 | SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 664 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 665 | if env['exceptions']: |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 666 | if env['build_config'] or env['high_priority']: |
| 667 | print("WARNING: Building tests for selected operators not supported") |
| 668 | Return() |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 669 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
| 670 | print("WARNING: Building tests for bare metal and armv7a is not supported") |
| 671 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 672 | SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0) |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 673 | |
| 674 | # Unknown variables are not allowed |
| 675 | # Note: we must delay the call of UnknownVariables until after |
| 676 | # we have applied the Variables object to the construction environment |
| 677 | unknown = vars.UnknownVariables() |
| 678 | if unknown: |
| 679 | print("Unknown variables: %s" % " ".join(unknown.keys())) |
Ramy Elgammal | 451c309 | 2022-02-01 23:01:27 +0000 | [diff] [blame] | 680 | Exit(1) |