Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +0000 | [diff] [blame] | 1 | # Copyright (c) 2016-2021 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 2 | # |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | # of this software and associated documentation files (the "Software"), to |
| 7 | # deal in the Software without restriction, including without limitation the |
| 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 9 | # sell copies of the Software, and to permit persons to whom the Software is |
| 10 | # furnished to do so, subject to the following conditions: |
| 11 | # |
| 12 | # The above copyright notice and this permission notice shall be included in all |
| 13 | # copies or substantial portions of the Software. |
| 14 | # |
| 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | # SOFTWARE. |
| 22 | import collections |
| 23 | import os.path |
| 24 | import re |
| 25 | import subprocess |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 26 | import zlib |
| 27 | import base64 |
| 28 | import string |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 29 | import json |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | |
| 31 | VERSION = "v0.0-unreleased" |
Sheri Zhang | 5b11425 | 2021-05-06 09:49:05 +0100 | [diff] [blame] | 32 | LIBRARY_VERSION_MAJOR = 23 |
Sang-Hoon Park | 6d0b384 | 2020-08-14 14:48:08 +0100 | [diff] [blame] | 33 | LIBRARY_VERSION_MINOR = 0 |
Georgios Pinitas | 35fcc43 | 2020-03-26 18:47:46 +0000 | [diff] [blame] | 34 | LIBRARY_VERSION_PATCH = 0 |
| 35 | SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | |
| 37 | Import('env') |
| 38 | Import('vars') |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 39 | Import('install_lib') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 41 | def build_bootcode_objs(sources): |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 42 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 43 | arm_compute_env.Append(ASFLAGS = "-I bootcode/") |
| 44 | obj = arm_compute_env.Object(sources) |
| 45 | obj = install_lib(obj) |
| 46 | Default(obj) |
| 47 | return obj |
| 48 | |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 49 | def build_sve_objs(sources): |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 50 | |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 51 | tmp_env = arm_compute_env.Clone() |
| 52 | tmp_env.Append(CXXFLAGS = "-march=armv8.2-a+sve+fp16") |
| 53 | obj = tmp_env.SharedObject(sources) |
| 54 | obj = install_lib(obj) |
| 55 | Default(obj) |
| 56 | return obj |
| 57 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 58 | def build_objs(sources): |
| 59 | |
| 60 | obj = arm_compute_env.SharedObject(sources) |
| 61 | obj = install_lib(obj) |
| 62 | Default(obj) |
| 63 | return obj |
| 64 | |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 65 | def build_library(name, build_env, sources, static=False, libs=[]): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 66 | if static: |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 67 | obj = build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | else: |
| 69 | if env['set_soname']: |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 70 | obj = build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 71 | else: |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 72 | obj = build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 73 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 74 | obj = install_lib(obj) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 75 | Default(obj) |
| 76 | return obj |
| 77 | |
Georgios Pinitas | f605bd2 | 2020-11-26 11:55:09 +0000 | [diff] [blame] | 78 | def remove_incode_comments(code): |
| 79 | def replace_with_empty(match): |
| 80 | s = match.group(0) |
| 81 | if s.startswith('/'): |
| 82 | return " " |
| 83 | else: |
| 84 | return s |
| 85 | |
| 86 | comment_regex = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE) |
| 87 | return re.sub(comment_regex, replace_with_empty, code) |
| 88 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 89 | def resolve_includes(target, source, env): |
| 90 | # File collection |
| 91 | FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents') |
| 92 | |
| 93 | # Include pattern |
| 94 | pattern = re.compile("#include \"(.*)\"") |
| 95 | |
| 96 | # Get file contents |
| 97 | files = [] |
| 98 | for i in range(len(source)): |
| 99 | src = source[i] |
| 100 | dst = target[i] |
Georgios Pinitas | f605bd2 | 2020-11-26 11:55:09 +0000 | [diff] [blame] | 101 | contents = src.get_contents().decode('utf-8') |
| 102 | contents = remove_incode_comments(contents).splitlines() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 103 | entry = FileEntry(target_name=dst, file_contents=contents) |
| 104 | files.append((os.path.basename(src.get_path()),entry)) |
| 105 | |
| 106 | # Create dictionary of tupled list |
| 107 | files_dict = dict(files) |
| 108 | |
| 109 | # Check for includes (can only be files in the same folder) |
| 110 | final_files = [] |
| 111 | for file in files: |
| 112 | done = False |
| 113 | tmp_file = file[1].file_contents |
| 114 | while not done: |
| 115 | file_count = 0 |
| 116 | updated_file = [] |
| 117 | for line in tmp_file: |
| 118 | found = pattern.search(line) |
| 119 | if found: |
| 120 | include_file = found.group(1) |
| 121 | data = files_dict[include_file].file_contents |
| 122 | updated_file.extend(data) |
| 123 | else: |
| 124 | updated_file.append(line) |
| 125 | file_count += 1 |
| 126 | |
| 127 | # Check if all include are replaced. |
| 128 | if file_count == len(tmp_file): |
| 129 | done = True |
| 130 | |
| 131 | # Update temp file |
| 132 | tmp_file = updated_file |
| 133 | |
| 134 | # Append and prepend string literal identifiers and add expanded file to final list |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 135 | entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file) |
| 136 | final_files.append((file[0], entry)) |
| 137 | |
| 138 | # Write output files |
| 139 | for file in final_files: |
| 140 | with open(file[1].target_name.get_path(), 'w+') as out_file: |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 141 | file_to_write = "\n".join( file[1].file_contents ) |
| 142 | if env['compress_kernels']: |
| 143 | file_to_write = zlib.compress(file_to_write, 9).encode("base64").replace("\n", "") |
| 144 | file_to_write = "R\"(" + file_to_write + ")\"" |
| 145 | out_file.write(file_to_write) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 146 | |
| 147 | def create_version_file(target, source, env): |
| 148 | # Generate string with build options library version to embed in the library: |
| 149 | try: |
| 150 | git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]) |
| 151 | except (OSError, subprocess.CalledProcessError): |
| 152 | git_hash="unknown" |
| 153 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 154 | build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip()) |
| 155 | with open(target[0].get_path(), "w") as fd: |
| 156 | fd.write(build_info) |
| 157 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 158 | def get_cpu_runtime_files(operator): |
| 159 | file_list = [] |
| 160 | operators = filelist['cpu']['operators'] |
| 161 | |
| 162 | if "operator" in operators[operator]["files"]: |
| 163 | file_list += operators[operator]["files"]["operator"] |
| 164 | return file_list |
| 165 | |
| 166 | def get_gpu_runtime_files(operator): |
| 167 | file_list = [] |
| 168 | operators = filelist['gpu']['operators'] |
| 169 | |
| 170 | if "operator" in operators[operator]["files"]: |
| 171 | file_list += operators[operator]["files"]["operator"] |
| 172 | return file_list |
| 173 | |
| 174 | def get_cpu_kernel_files(operator): |
| 175 | |
| 176 | file_list = [] |
| 177 | file_list_sve = [] |
| 178 | operators = filelist['cpu']['operators'] |
| 179 | |
| 180 | if env['estate'] == '64' and "neon" in operators[operator]['files'] and "estate64" in operators[operator]['files']['neon']: |
| 181 | file_list += operators[operator]['files']['neon']['estate64'] |
| 182 | if env['estate'] == '32' and "neon" in operators[operator]['files'] and "estate32" in operators[operator]['files']['neon']: |
| 183 | file_list += operators[operator]['files']['neon']['estate32'] |
| 184 | |
| 185 | if "kernel" in operators[operator]["files"]: |
| 186 | file_list += operators[operator]["files"]["kernel"] |
| 187 | |
| 188 | if ("neon" in operators[operator]["files"]): |
| 189 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8']) and ("qasymm8" in operators[operator]["files"]["neon"]): |
| 190 | file_list += operators[operator]["files"]["neon"]["qasymm8"] |
| 191 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']) and ("qasymm8_signed" in operators[operator]["files"]["neon"]): |
| 192 | file_list += operators[operator]["files"]["neon"]["qasymm8_signed"] |
| 193 | if any(i in env['data_type_support'] for i in ['all', 'qsymm16']) and ("qsymm16" in operators[operator]["files"]["neon"]): |
| 194 | file_list += operators[operator]["files"]["neon"]["qsymm16"] |
| 195 | if any(i in env['data_type_support'] for i in ['all', 'integer']) and ("integer" in operators[operator]["files"]["neon"]): |
| 196 | file_list += operators[operator]["files"]["neon"]["integer"] |
| 197 | |
| 198 | if (not "sve" in env['arch'] or env['fat_binary']) and ("neon" in operators[operator]["files"]): |
| 199 | if any(i in env['data_type_support'] for i in ['all', 'fp16']) and ("fp16" in operators[operator]["files"]["neon"]): |
| 200 | file_list += operators[operator]["files"]["neon"]["fp16"] |
| 201 | if any(i in env['data_type_support'] for i in ['all', 'fp32']) and ("fp32" in operators[operator]["files"]["neon"]): |
| 202 | file_list += operators[operator]["files"]["neon"]["fp32"] |
| 203 | if any(i in env['data_layout_support'] for i in ['all', 'nchw']) and ("nchw" in operators[operator]["files"]["neon"]): |
| 204 | file_list += operators[operator]['files']['neon']['nchw'] |
| 205 | if ("all" in operators[operator]["files"]["neon"]): |
| 206 | file_list += operators[operator]["files"]["neon"]["all"] |
| 207 | if ("sve" in env['arch'] or env['fat_binary']) and ("sve" in operators[operator]["files"]): |
| 208 | if any(i in env['data_type_support'] for i in ['all', 'fp16']) and ("fp16" in operators[operator]["files"]["sve"]): |
| 209 | file_list_sve += operators[operator]["files"]["sve"]["fp16"] |
| 210 | if any(i in env['data_type_support'] for i in ['all', 'fp32']) and ("fp32" in operators[operator]["files"]["sve"]): |
| 211 | file_list_sve += operators[operator]["files"]["sve"]["fp32"] |
| 212 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8']) and ("qasymm8" in operators[operator]["files"]["sve"]): |
| 213 | file_list_sve += operators[operator]["files"]["sve"]["qasymm8"] |
| 214 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']) and ("qasymm8_signed" in operators[operator]["files"]["sve"]): |
| 215 | file_list_sve += operators[operator]["files"]["sve"]["qasymm8_signed"] |
| 216 | if any(i in env['data_type_support'] for i in ['all', 'qsymm16']) and ("qsymm16" in operators[operator]["files"]["sve"]): |
| 217 | file_list_sve += operators[operator]["files"]["sve"]["qsymm16"] |
| 218 | if any(i in env['data_type_support'] for i in ['all', 'integer']) and ("integer" in operators[operator]["files"]["sve"]): |
| 219 | file_list_sve += operators[operator]["files"]["sve"]["integer"] |
| 220 | if ("all" in operators[operator]["files"]["sve"]): |
| 221 | file_list_sve += operators[operator]["files"]["sve"]["all"] |
| 222 | |
| 223 | return file_list, file_list_sve |
| 224 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 225 | arm_compute_env = env.Clone() |
Anthony Barbier | 0e72c69 | 2018-08-24 11:22:08 +0100 | [diff] [blame] | 226 | version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file) |
| 227 | arm_compute_env.AlwaysBuild(version_file) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 228 | |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 229 | default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++' |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 230 | cpp_compiler = os.environ.get('CXX', default_cpp_compiler) |
| 231 | |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 232 | # Generate embed files |
Anthony Barbier | 0e72c69 | 2018-08-24 11:22:08 +0100 | [diff] [blame] | 233 | generate_embed = [ version_file ] |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 234 | if env['opencl'] and env['embed_kernels']: |
| 235 | cl_files = Glob('src/core/CL/cl_kernels/*.cl') |
| 236 | cl_files += Glob('src/core/CL/cl_kernels/*.h') |
| 237 | |
| 238 | embed_files = [ f.get_path()+"embed" for f in cl_files ] |
| 239 | arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] ) |
| 240 | |
| 241 | generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes)) |
| 242 | |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 243 | Default(generate_embed) |
| 244 | if env["build"] == "embed_only": |
| 245 | Return() |
| 246 | |
Georgios Pinitas | 35fcc43 | 2020-03-26 18:47:46 +0000 | [diff] [blame] | 247 | # Append version defines for semantic versioning |
| 248 | arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR), |
| 249 | ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR), |
| 250 | ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)]) |
| 251 | |
Isabella Gottardi | b28f29d | 2017-11-09 17:05:07 +0000 | [diff] [blame] | 252 | # Don't allow undefined references in the libraries: |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 253 | undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined' |
| 254 | arm_compute_env.Append(LINKFLAGS=[undefined_flag]) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 255 | arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] ) |
| 256 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 257 | arm_compute_env.Append(LIBS = ['dl']) |
| 258 | |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 259 | with (open(Dir('#').path + '/filelist.json')) as fp: |
| 260 | filelist = json.load(fp) |
| 261 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 262 | core_files = Glob('src/core/*.cpp') |
| 263 | core_files += Glob('src/core/CPP/*.cpp') |
| 264 | core_files += Glob('src/core/CPP/kernels/*.cpp') |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 265 | core_files += Glob('src/core/helpers/*.cpp') |
Sang-Hoon Park | 3687ee1 | 2020-06-24 13:34:04 +0100 | [diff] [blame] | 266 | core_files += Glob('src/core/utils/*.cpp') |
Michalis Spyrou | 7043d36 | 2018-12-03 13:58:32 +0000 | [diff] [blame] | 267 | core_files += Glob('src/core/utils/helpers/*.cpp') |
| 268 | core_files += Glob('src/core/utils/io/*.cpp') |
| 269 | core_files += Glob('src/core/utils/quantization/*.cpp') |
Georgios Pinitas | b8d5b95 | 2019-05-16 14:13:03 +0100 | [diff] [blame] | 270 | core_files += Glob('src/core/utils/misc/*.cpp') |
Michalis Spyrou | 7043d36 | 2018-12-03 13:58:32 +0000 | [diff] [blame] | 271 | if env["logging"]: |
| 272 | core_files += Glob('src/core/utils/logging/*.cpp') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 273 | |
Anthony Barbier | 8e6faf1 | 2017-08-01 17:03:19 +0100 | [diff] [blame] | 274 | runtime_files = Glob('src/runtime/*.cpp') |
Georgios Pinitas | 8795ffb | 2017-12-01 16:13:40 +0000 | [diff] [blame] | 275 | runtime_files += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp') |
| 276 | runtime_files += Glob('src/runtime/CPP/functions/*.cpp') |
| 277 | |
Georgios Pinitas | c3c352e | 2021-03-18 10:59:40 +0000 | [diff] [blame] | 278 | # C API files |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 279 | runtime_files += filelist['c_api']['cpu'] |
| 280 | |
Georgios Pinitas | c3c352e | 2021-03-18 10:59:40 +0000 | [diff] [blame] | 281 | if env['opencl']: |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 282 | runtime_files += filelist['c_api']['gpu'] |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 283 | |
Georgios Pinitas | c3c352e | 2021-03-18 10:59:40 +0000 | [diff] [blame] | 284 | # Common backend files |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 285 | core_files += filelist['common'] |
Georgios Pinitas | c3c352e | 2021-03-18 10:59:40 +0000 | [diff] [blame] | 286 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 287 | # Initialize high priority core files |
| 288 | core_files_hp = core_files |
| 289 | core_files_sve_hp = [] |
| 290 | core_files = [] |
| 291 | |
Anthony Barbier | 8e6faf1 | 2017-08-01 17:03:19 +0100 | [diff] [blame] | 292 | runtime_files += Glob('src/runtime/CPP/SingleThreadScheduler.cpp') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 293 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 294 | graph_files = Glob('src/graph/*.cpp') |
| 295 | graph_files += Glob('src/graph/*/*.cpp') |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 296 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 297 | if env['cppthreads']: |
Anthony Barbier | 8e6faf1 | 2017-08-01 17:03:19 +0100 | [diff] [blame] | 298 | runtime_files += Glob('src/runtime/CPP/CPPScheduler.cpp') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 299 | |
| 300 | if env['openmp']: |
Anthony Barbier | 8e6faf1 | 2017-08-01 17:03:19 +0100 | [diff] [blame] | 301 | runtime_files += Glob('src/runtime/OMP/OMPScheduler.cpp') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 302 | |
| 303 | if env['opencl']: |
| 304 | core_files += Glob('src/core/CL/*.cpp') |
Michele Di Giorgio | 7d61ff0 | 2021-01-18 21:15:59 +0000 | [diff] [blame] | 305 | core_files += Glob('src/core/gpu/cl/*.cpp') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 306 | |
Anthony Barbier | 8e6faf1 | 2017-08-01 17:03:19 +0100 | [diff] [blame] | 307 | runtime_files += Glob('src/runtime/CL/*.cpp') |
| 308 | runtime_files += Glob('src/runtime/CL/functions/*.cpp') |
Gian Marco Iodice | 5a4fe19 | 2020-03-16 12:22:37 +0000 | [diff] [blame] | 309 | runtime_files += Glob('src/runtime/CL/gemm/*.cpp') |
Georgios Pinitas | c0d1c86 | 2018-03-23 15:13:15 +0000 | [diff] [blame] | 310 | runtime_files += Glob('src/runtime/CL/tuners/*.cpp') |
Michele Di Giorgio | 7d61ff0 | 2021-01-18 21:15:59 +0000 | [diff] [blame] | 311 | runtime_files += Glob('src/runtime/gpu/cl/*.cpp') |
SiCong Li | 7061eb2 | 2021-01-08 15:16:02 +0000 | [diff] [blame] | 312 | runtime_files += Glob('src/runtime/CL/mlgo/*.cpp') |
SiCong Li | bd8b1e2 | 2021-02-04 13:07:09 +0000 | [diff] [blame] | 313 | runtime_files += Glob('src/runtime/CL/gemm_auto_heuristics/*.cpp') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 314 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 315 | runtime_files += Glob('src/gpu/cl/*.cpp') |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 316 | graph_files += Glob('src/graph/backends/CL/*.cpp') |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 317 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 318 | operators = filelist['gpu']['operators'] |
| 319 | for operator in operators: |
| 320 | runtime_files += get_gpu_runtime_files(operator) |
| 321 | if "kernel" in operators[operator]["files"]: |
| 322 | core_files += operators[operator]["files"]["kernel"] |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 323 | |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 324 | sve_o = [] |
| 325 | core_files_sve = [] |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 326 | if env['neon']: |
| 327 | core_files += Glob('src/core/NEON/*.cpp') |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 328 | |
Georgios Pinitas | 30271c7 | 2019-06-24 14:56:34 +0100 | [diff] [blame] | 329 | # build winograd/depthwise sources for either v7a / v8a |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 330 | arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/", |
Michele Di Giorgio | 6ad60af | 2020-06-09 14:52:15 +0100 | [diff] [blame] | 331 | "src/core/NEON/kernels/convolution/winograd/", |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 332 | "src/core/NEON/kernels/convolution/depthwise/", |
| 333 | "src/core/NEON/kernels/assembly/", |
Sang-Hoon Park | 4f7693d | 2021-05-12 13:59:10 +0100 | [diff] [blame] | 334 | "arm_compute/core/NEON/kernels/assembly/", |
| 335 | "src/core/cpu/kernels/assembly/",]) |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 336 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 337 | graph_files += Glob('src/graph/backends/NEON/*.cpp') |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 338 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 339 | # Load files based on user's options |
| 340 | operators = filelist['cpu']['operators'] |
| 341 | for operator in operators: |
| 342 | runtime_files += get_cpu_runtime_files(operator) |
| 343 | if operator in filelist['cpu']['high_priority']: |
| 344 | file_list, file_list_sve = get_cpu_kernel_files(operator) |
| 345 | core_files_hp += file_list |
| 346 | core_files_sve_hp += file_list_sve |
| 347 | else: |
| 348 | file_list, file_list_sve = get_cpu_kernel_files(operator) |
| 349 | core_files += file_list |
| 350 | core_files_sve += file_list_sve |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 351 | |
Anthony Barbier | 8e6faf1 | 2017-08-01 17:03:19 +0100 | [diff] [blame] | 352 | runtime_files += Glob('src/runtime/NEON/*.cpp') |
| 353 | runtime_files += Glob('src/runtime/NEON/functions/*.cpp') |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 354 | runtime_files += filelist['cpu']['all'] |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 355 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 356 | bootcode_o = [] |
| 357 | if env['os'] == 'bare_metal': |
| 358 | bootcode_files = Glob('bootcode/*.s') |
| 359 | bootcode_o = build_bootcode_objs(bootcode_files) |
| 360 | Export('bootcode_o') |
| 361 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 362 | high_priority_o = build_objs(core_files_hp) |
| 363 | high_priority_sve_o = [] |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 364 | if (env['fat_binary']): |
| 365 | sve_o = build_sve_objs(core_files_sve) |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 366 | high_priority_sve_o = build_sve_objs(core_files_sve_hp) |
| 367 | arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, core_files + high_priority_o + sve_o + high_priority_sve_o, static=True) |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 368 | else: |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 369 | high_priority_o += build_objs(core_files_sve_hp) |
| 370 | arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, core_files + core_files_sve + high_priority_o, static=True) |
| 371 | arm_compute_core_hp_a = build_library('arm_compute_core_hp-static', arm_compute_env, high_priority_o + high_priority_sve_o, static=True) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 372 | Export('arm_compute_core_a') |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 373 | Export('arm_compute_core_hp_a') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 374 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 375 | if env['os'] != 'bare_metal' and not env['standalone']: |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 376 | if (env['fat_binary']): |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 377 | arm_compute_core_so = build_library('arm_compute_core', arm_compute_env, core_files + high_priority_o + sve_o + high_priority_sve_o, static=False) |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 378 | else: |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 379 | arm_compute_core_so = build_library('arm_compute_core', arm_compute_env, core_files + core_files_sve + high_priority_o, static=False) |
| 380 | arm_compute_core_so_hp = build_library('arm_compute_core_hp', arm_compute_env, high_priority_o + high_priority_sve_o, static=False) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 381 | Export('arm_compute_core_so') |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 382 | Export('arm_compute_core_so_hp') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 383 | |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 384 | arm_compute_a = build_library('arm_compute-static', arm_compute_env, runtime_files, static=True, libs = [ arm_compute_core_a ]) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 385 | Export('arm_compute_a') |
| 386 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 387 | if env['os'] != 'bare_metal' and not env['standalone']: |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 388 | arm_compute_so = build_library('arm_compute', arm_compute_env, runtime_files, static=False, libs = [ "arm_compute_core" ]) |
Anthony Barbier | b2881fc | 2017-09-29 17:12:12 +0100 | [diff] [blame] | 389 | Depends(arm_compute_so, arm_compute_core_so) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 390 | Export('arm_compute_so') |
| 391 | |
Sang-Hoon Park | 18fbb92 | 2021-01-14 14:50:25 +0000 | [diff] [blame] | 392 | arm_compute_graph_env = arm_compute_env.Clone() |
| 393 | |
| 394 | arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move']) |
| 395 | |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 396 | arm_compute_graph_a = build_library('arm_compute_graph-static', arm_compute_graph_env, graph_files, static=True, libs = [ arm_compute_a]) |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 397 | Export('arm_compute_graph_a') |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 398 | |
| 399 | if env['os'] != 'bare_metal' and not env['standalone']: |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 400 | arm_compute_graph_so = build_library('arm_compute_graph', arm_compute_graph_env, graph_files, static=False, libs = [ "arm_compute" , "arm_compute_core"]) |
Georgios Pinitas | 9873ea3 | 2017-12-05 15:28:55 +0000 | [diff] [blame] | 401 | Depends(arm_compute_graph_so, arm_compute_so) |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 402 | Export('arm_compute_graph_so') |
| 403 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 404 | if env['standalone']: |
| 405 | alias = arm_compute_env.Alias("arm_compute", [arm_compute_a]) |
| 406 | else: |
| 407 | alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so]) |
| 408 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 409 | Default(alias) |
| 410 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 411 | if env['standalone']: |
| 412 | Depends([alias,arm_compute_core_a], generate_embed) |
| 413 | else: |
| 414 | Depends([alias,arm_compute_core_so, arm_compute_core_a], generate_embed) |