Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +0000 | [diff] [blame] | 4 | # Copyright (c) 2016-2021 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 5 | # |
| 6 | # SPDX-License-Identifier: MIT |
| 7 | # |
| 8 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | # of this software and associated documentation files (the "Software"), to |
| 10 | # deal in the Software without restriction, including without limitation the |
| 11 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 12 | # sell copies of the Software, and to permit persons to whom the Software is |
| 13 | # furnished to do so, subject to the following conditions: |
| 14 | # |
| 15 | # The above copyright notice and this permission notice shall be included in all |
| 16 | # copies or substantial portions of the Software. |
| 17 | # |
| 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | # SOFTWARE. |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 25 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | import collections |
| 27 | import os.path |
| 28 | import re |
| 29 | import subprocess |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 30 | import zlib |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 31 | import json |
Adnan AlSinan | 39aebd1 | 2021-08-06 12:44:51 +0100 | [diff] [blame] | 32 | import codecs |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 33 | |
| 34 | VERSION = "v0.0-unreleased" |
Adnan AlSinan | b631b6d | 2022-02-04 14:08:07 +0000 | [diff] [blame] | 35 | LIBRARY_VERSION_MAJOR = 26 |
Sang-Hoon Park | 6d0b384 | 2020-08-14 14:48:08 +0100 | [diff] [blame] | 36 | LIBRARY_VERSION_MINOR = 0 |
Georgios Pinitas | 35fcc43 | 2020-03-26 18:47:46 +0000 | [diff] [blame] | 37 | LIBRARY_VERSION_PATCH = 0 |
| 38 | 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] | 39 | |
| 40 | Import('env') |
| 41 | Import('vars') |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 42 | Import('install_lib') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 43 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 44 | def build_bootcode_objs(sources): |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 45 | arm_compute_env.Append(ASFLAGS = "-I bootcode/") |
| 46 | obj = arm_compute_env.Object(sources) |
| 47 | obj = install_lib(obj) |
| 48 | Default(obj) |
| 49 | return obj |
| 50 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 51 | |
| 52 | |
| 53 | |
| 54 | # @brief Create a list of object from a given file list. |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 55 | # |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 56 | # @param arch_info A dictionary represents the architecture info such as the |
| 57 | # compiler flags and defines (filedefs.json). |
| 58 | # |
| 59 | # @param sources A list of files to build |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 60 | # |
| 61 | # @return A list of objects for the corresponding architecture. |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 62 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 63 | def build_obj_list(arch_info, sources, static=False): |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 64 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 65 | # Clone environment |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 66 | tmp_env = arm_compute_env.Clone() |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 67 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 68 | # Append architecture spec |
| 69 | if 'cxxflags' in arch_info and len(arch_info['cxxflags']) > 0: |
| 70 | tmp_env.Append(CXXFLAGS = arch_info['cxxflags']) |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 71 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 72 | # Build and return objects |
| 73 | if static: |
| 74 | objs = tmp_env.StaticObject(sources) |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 75 | else: |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 76 | objs = tmp_env.SharedObject(sources) |
| 77 | |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 78 | tmp_env.Default(objs) |
| 79 | return objs |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 80 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 81 | # @brief Build multi-ISA files with the respective architecture. |
| 82 | # |
| 83 | # @return Two distinct lists: |
| 84 | # A list of static objects |
| 85 | # A list of shared objects |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 86 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 87 | def build_lib_objects(): |
| 88 | lib_static_objs = [] # static objects |
| 89 | lib_shared_objs = [] # shared objects |
| 90 | |
| 91 | arm_compute_env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON', |
| 92 | 'ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE', |
| 93 | 'ARM_COMPUTE_ENABLE_FP16', 'ARM_COMPUTE_ENABLE_BF16', |
| 94 | 'ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_SVEF32MM']) |
| 95 | |
| 96 | # Build all the common files for the base architecture |
| 97 | lib_static_objs += build_obj_list(filedefs["armv8.2-a"], lib_files, static=True) |
| 98 | lib_shared_objs += build_obj_list(filedefs["armv8.2-a"], lib_files, static=False) |
| 99 | |
| 100 | # Build the SVE specific files |
| 101 | lib_static_objs += build_obj_list(filedefs["armv8.2-a-sve"], lib_files_sve, static=True) |
| 102 | lib_shared_objs += build_obj_list(filedefs["armv8.2-a-sve"], lib_files_sve, static=False) |
| 103 | |
| 104 | # Build the SVE2 specific files |
| 105 | arm_compute_env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2']) |
| 106 | lib_static_objs += build_obj_list(filedefs["armv8.6-a-sve2"], lib_files_sve2, static=True) |
| 107 | lib_shared_objs += build_obj_list(filedefs["armv8.6-a-sve2"], lib_files_sve2, static=False) |
| 108 | |
| 109 | return lib_static_objs, lib_shared_objs |
| 110 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 111 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 112 | |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 113 | def build_library(name, build_env, sources, static=False, libs=[]): |
Mohammed Suhail Munshi | de60ed9 | 2021-12-21 11:07:27 +0000 | [diff] [blame] | 114 | cloned_build_env = build_env.Clone() |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 115 | if env['os'] == 'android' and static == False: |
Mohammed Suhail Munshi | de60ed9 | 2021-12-21 11:07:27 +0000 | [diff] [blame] | 116 | cloned_build_env["LINKFLAGS"].remove('-pie') |
| 117 | cloned_build_env["LINKFLAGS"].remove('-static-libstdc++') |
| 118 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 119 | if static: |
Mohammed Suhail Munshi | de60ed9 | 2021-12-21 11:07:27 +0000 | [diff] [blame] | 120 | obj = cloned_build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 121 | else: |
| 122 | if env['set_soname']: |
Mohammed Suhail Munshi | de60ed9 | 2021-12-21 11:07:27 +0000 | [diff] [blame] | 123 | obj = cloned_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] | 124 | else: |
Mohammed Suhail Munshi | de60ed9 | 2021-12-21 11:07:27 +0000 | [diff] [blame] | 125 | obj = cloned_build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 126 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 127 | obj = install_lib(obj) |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 128 | build_env.Default(obj) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 129 | return obj |
| 130 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 131 | |
Georgios Pinitas | f605bd2 | 2020-11-26 11:55:09 +0000 | [diff] [blame] | 132 | def remove_incode_comments(code): |
| 133 | def replace_with_empty(match): |
| 134 | s = match.group(0) |
| 135 | if s.startswith('/'): |
| 136 | return " " |
| 137 | else: |
| 138 | return s |
| 139 | |
| 140 | comment_regex = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE) |
| 141 | return re.sub(comment_regex, replace_with_empty, code) |
| 142 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 143 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 144 | def resolve_includes(target, source, env): |
| 145 | # File collection |
| 146 | FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents') |
| 147 | |
| 148 | # Include pattern |
| 149 | pattern = re.compile("#include \"(.*)\"") |
| 150 | |
| 151 | # Get file contents |
| 152 | files = [] |
| 153 | for i in range(len(source)): |
| 154 | src = source[i] |
| 155 | dst = target[i] |
Georgios Pinitas | f605bd2 | 2020-11-26 11:55:09 +0000 | [diff] [blame] | 156 | contents = src.get_contents().decode('utf-8') |
| 157 | contents = remove_incode_comments(contents).splitlines() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 158 | entry = FileEntry(target_name=dst, file_contents=contents) |
| 159 | files.append((os.path.basename(src.get_path()),entry)) |
| 160 | |
| 161 | # Create dictionary of tupled list |
| 162 | files_dict = dict(files) |
| 163 | |
| 164 | # Check for includes (can only be files in the same folder) |
| 165 | final_files = [] |
| 166 | for file in files: |
| 167 | done = False |
| 168 | tmp_file = file[1].file_contents |
| 169 | while not done: |
| 170 | file_count = 0 |
| 171 | updated_file = [] |
| 172 | for line in tmp_file: |
| 173 | found = pattern.search(line) |
| 174 | if found: |
Giorgio Arena | 09adcc4 | 2022-03-08 11:12:27 +0000 | [diff] [blame] | 175 | # Only get the header file name and discard the relative path. |
| 176 | # E.g. "common/experimental/gemm_fused_post_ops/fp_mixed_precision_helpers.h" -> "fp_mixed_precision_helpers.h" |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 177 | include_file = found.group(1).split('/')[-1] |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 178 | data = files_dict[include_file].file_contents |
| 179 | updated_file.extend(data) |
| 180 | else: |
| 181 | updated_file.append(line) |
| 182 | file_count += 1 |
| 183 | |
| 184 | # Check if all include are replaced. |
| 185 | if file_count == len(tmp_file): |
| 186 | done = True |
| 187 | |
| 188 | # Update temp file |
| 189 | tmp_file = updated_file |
| 190 | |
| 191 | # 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] | 192 | entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file) |
| 193 | final_files.append((file[0], entry)) |
| 194 | |
| 195 | # Write output files |
| 196 | for file in final_files: |
| 197 | with open(file[1].target_name.get_path(), 'w+') as out_file: |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 198 | file_to_write = "\n".join( file[1].file_contents ) |
| 199 | if env['compress_kernels']: |
Adnan AlSinan | 39aebd1 | 2021-08-06 12:44:51 +0100 | [diff] [blame] | 200 | file_to_write = zlib.compress(file_to_write.encode('utf-8'), 9) |
| 201 | file_to_write = codecs.encode(file_to_write, "base64").decode('utf-8').replace("\n", "") |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 202 | file_to_write = "R\"(" + file_to_write + ")\"" |
| 203 | out_file.write(file_to_write) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 204 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 205 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 206 | def create_version_file(target, source, env): |
| 207 | # Generate string with build options library version to embed in the library: |
| 208 | try: |
| 209 | git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]) |
| 210 | except (OSError, subprocess.CalledProcessError): |
| 211 | git_hash="unknown" |
| 212 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 213 | build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip()) |
| 214 | with open(target[0].get_path(), "w") as fd: |
| 215 | fd.write(build_info) |
| 216 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 217 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 218 | def get_attrs_list(env, data_types, data_layouts): |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 219 | attrs = [] |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 220 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 221 | # Manage data-types |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 222 | if 'all' in data_types: |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 223 | attrs += ['fp16', 'fp32', 'integer', 'qasymm8', 'qasymm8_signed', 'qsymm16'] |
| 224 | else: |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 225 | if 'fp16' in data_types: attrs += ['fp16'] |
| 226 | if 'fp32' in data_types: attrs += ['fp32'] |
| 227 | if 'integer' in data_types: attrs += ['integer'] |
| 228 | if 'qasymm8' in data_types: attrs += ['qasymm8'] |
| 229 | if 'qasymm8_signed' in data_types: attrs += ['qasymm8_signed'] |
| 230 | if 'qsymm16' in data_types: attrs += ['qsymm16'] |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 231 | # Manage data-layouts |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 232 | if 'all' in data_layouts: |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 233 | attrs += ['nhwc', 'nchw'] |
| 234 | else: |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 235 | if 'nhwc' in data_layouts: attrs += ['nhwc'] |
| 236 | if 'nchw' in data_layouts: attrs += ['nchw'] |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 237 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 238 | # Manage execution state |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 239 | attrs += ['estate32' if (env['estate'] == 'auto' and 'v7a' in env['arch']) or '32' in env['estate'] else 'estate64'] |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 240 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 241 | return attrs |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 242 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 243 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 244 | def get_operator_backend_files(filelist, operators, backend='', techs=[], attrs=[]): |
| 245 | files = { "common" : [] } |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 246 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 247 | # Early return if filelist is empty |
| 248 | if backend not in filelist: |
| 249 | return files |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 250 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 251 | # Iterate over operators and create the file lists to compiler |
| 252 | for operator in operators: |
| 253 | if operator in filelist[backend]['operators']: |
| 254 | files['common'] += filelist[backend]['operators'][operator]["files"]["common"] |
| 255 | for tech in techs: |
| 256 | if tech in filelist[backend]['operators'][operator]["files"]: |
| 257 | # Add tech as a key to dictionary if not there |
| 258 | if tech not in files: |
| 259 | files[tech] = [] |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 260 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 261 | # Add tech files to the tech file list |
| 262 | tech_files = filelist[backend]['operators'][operator]["files"][tech] |
| 263 | files[tech] += tech_files.get('common', []) |
| 264 | for attr in attrs: |
| 265 | files[tech] += tech_files.get(attr, []) |
| 266 | |
| 267 | # Remove duplicates if they exist |
| 268 | return {k: list(set(v)) for k,v in files.items()} |
| 269 | |
| 270 | def collect_operators(filelist, operators, backend=''): |
| 271 | ops = set() |
| 272 | for operator in operators: |
| 273 | if operator in filelist[backend]['operators']: |
| 274 | ops.add(operator) |
| 275 | if 'deps' in filelist[backend]['operators'][operator]: |
| 276 | ops.update(filelist[backend]['operators'][operator]['deps']) |
| 277 | else: |
| 278 | print("Operator {0} is unsupported on {1} backend!".format(operator, backend)) |
| 279 | |
| 280 | return ops |
| 281 | |
| 282 | |
| 283 | def resolve_operator_dependencies(filelist, operators, backend=''): |
| 284 | resolved_operators = collect_operators(filelist, operators, backend) |
| 285 | |
| 286 | are_ops_resolved = False |
| 287 | while not are_ops_resolved: |
| 288 | resolution_pass = collect_operators(filelist, resolved_operators, backend) |
| 289 | if len(resolution_pass) != len(resolved_operators): |
| 290 | resolved_operators.update(resolution_pass) |
| 291 | else: |
| 292 | are_ops_resolved = True |
| 293 | |
| 294 | return resolved_operators |
| 295 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 296 | def read_build_config_json(build_config): |
| 297 | build_config_contents = {} |
| 298 | custom_operators = [] |
| 299 | custom_types = [] |
| 300 | custom_layouts = [] |
| 301 | if os.path.isfile(build_config): |
| 302 | with open(build_config) as f: |
| 303 | try: |
| 304 | build_config_contents = json.load(f) |
| 305 | except: |
| 306 | print("Warning: Build configuration file is of invalid JSON format!") |
| 307 | else: |
| 308 | try: |
| 309 | build_config_contents = json.loads(build_config) |
| 310 | except: |
| 311 | print("Warning: Build configuration string is of invalid JSON format!") |
| 312 | if build_config_contents: |
| 313 | custom_operators = build_config_contents.get("operators", []) |
| 314 | custom_types = build_config_contents.get("data_types", []) |
| 315 | custom_layouts = build_config_contents.get("data_layouts", []) |
| 316 | return custom_operators, custom_types, custom_layouts |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 317 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 318 | arm_compute_env = env.Clone() |
Anthony Barbier | 0e72c69 | 2018-08-24 11:22:08 +0100 | [diff] [blame] | 319 | version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file) |
| 320 | arm_compute_env.AlwaysBuild(version_file) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 321 | |
Kevin Lo | 7195f71 | 2022-01-07 15:46:02 +0800 | [diff] [blame] | 322 | default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos', 'openbsd'] else 'clang++' |
Georgios Pinitas | 4d9687e | 2020-10-21 18:33:36 +0100 | [diff] [blame] | 323 | cpp_compiler = os.environ.get('CXX', default_cpp_compiler) |
| 324 | |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 325 | # Generate embed files |
Anthony Barbier | 0e72c69 | 2018-08-24 11:22:08 +0100 | [diff] [blame] | 326 | generate_embed = [ version_file ] |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 327 | if env['opencl'] and env['embed_kernels']: |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 328 | |
| 329 | # Header files |
| 330 | cl_helper_files = [ 'src/core/CL/cl_kernels/activation_float_helpers.h', |
| 331 | 'src/core/CL/cl_kernels/activation_quant_helpers.h', |
| 332 | 'src/core/CL/cl_kernels/gemm_helpers.h', |
| 333 | 'src/core/CL/cl_kernels/helpers_asymm.h', |
| 334 | 'src/core/CL/cl_kernels/helpers.h', |
| 335 | 'src/core/CL/cl_kernels/load_store_utility.h', |
| 336 | 'src/core/CL/cl_kernels/repeat.h', |
| 337 | 'src/core/CL/cl_kernels/tile_helpers.h', |
| 338 | 'src/core/CL/cl_kernels/types.h', |
SiCongLi | 1af5416 | 2021-10-06 15:25:57 +0100 | [diff] [blame] | 339 | 'src/core/CL/cl_kernels/warp_helpers.h', |
| 340 | 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/fp_post_ops_act_eltwise_op_act.h', |
| 341 | 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/fp_mixed_precision_helpers.h', |
| 342 | 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/fp_elementwise_op_helpers.h', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 343 | ] |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 344 | |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 345 | # Common kernels |
| 346 | cl_files_common = ['src/core/CL/cl_kernels/common/activation_layer.cl', |
| 347 | 'src/core/CL/cl_kernels/common/activation_layer_quant.cl', |
| 348 | 'src/core/CL/cl_kernels/common/arg_min_max.cl', |
| 349 | 'src/core/CL/cl_kernels/common/batchnormalization_layer.cl', |
| 350 | 'src/core/CL/cl_kernels/common/bounding_box_transform.cl', |
| 351 | 'src/core/CL/cl_kernels/common/bounding_box_transform_quantized.cl', |
| 352 | 'src/core/CL/cl_kernels/common/bitwise_op.cl', |
| 353 | 'src/core/CL/cl_kernels/common/cast.cl', |
| 354 | 'src/core/CL/cl_kernels/common/comparisons.cl', |
| 355 | 'src/core/CL/cl_kernels/common/concatenate.cl', |
| 356 | 'src/core/CL/cl_kernels/common/col2im.cl', |
| 357 | 'src/core/CL/cl_kernels/common/convert_fc_weights.cl', |
| 358 | 'src/core/CL/cl_kernels/common/copy_tensor.cl', |
| 359 | 'src/core/CL/cl_kernels/common/crop_tensor.cl', |
| 360 | 'src/core/CL/cl_kernels/common/deconvolution_layer.cl', |
| 361 | 'src/core/CL/cl_kernels/common/dequantization_layer.cl', |
| 362 | 'src/core/CL/cl_kernels/common/elementwise_operation.cl', |
| 363 | 'src/core/CL/cl_kernels/common/elementwise_operation_quantized.cl', |
| 364 | 'src/core/CL/cl_kernels/common/elementwise_unary.cl', |
| 365 | 'src/core/CL/cl_kernels/common/fft_digit_reverse.cl', |
| 366 | 'src/core/CL/cl_kernels/common/fft.cl', |
| 367 | 'src/core/CL/cl_kernels/common/fft_scale.cl', |
| 368 | 'src/core/CL/cl_kernels/common/fill_border.cl', |
| 369 | 'src/core/CL/cl_kernels/common/floor.cl', |
| 370 | 'src/core/CL/cl_kernels/common/gather.cl', |
| 371 | 'src/core/CL/cl_kernels/common/gemm.cl', |
ramelg01 | 9cca592 | 2021-11-11 10:05:00 +0000 | [diff] [blame] | 372 | 'src/core/CL/cl_kernels/common/gemm_utils.cl', |
SiCongLi | afa1972 | 2021-10-24 19:12:33 +0100 | [diff] [blame] | 373 | 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/gemm_mm_native.cl', |
SiCongLi | 1af5416 | 2021-10-06 15:25:57 +0100 | [diff] [blame] | 374 | 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/gemm_mm_reshaped.cl', |
Ramy Elgammal | 451c309 | 2022-02-01 23:01:27 +0000 | [diff] [blame] | 375 | 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/gemm_mm_reshaped_only_rhs.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 376 | 'src/core/CL/cl_kernels/common/gemv.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 377 | 'src/core/CL/cl_kernels/common/gemmlowp.cl', |
| 378 | 'src/core/CL/cl_kernels/common/generate_proposals.cl', |
| 379 | 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl', |
| 380 | 'src/core/CL/cl_kernels/common/instance_normalization.cl', |
| 381 | 'src/core/CL/cl_kernels/common/l2_normalize.cl', |
| 382 | 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl', |
| 383 | 'src/core/CL/cl_kernels/common/unpooling_layer.cl', |
| 384 | 'src/core/CL/cl_kernels/common/memset.cl', |
| 385 | 'src/core/CL/cl_kernels/common/nonmax.cl', |
| 386 | 'src/core/CL/cl_kernels/common/minmax_layer.cl', |
| 387 | 'src/core/CL/cl_kernels/common/pad_layer.cl', |
| 388 | 'src/core/CL/cl_kernels/common/permute.cl', |
| 389 | 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl', |
| 390 | 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl', |
| 391 | 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl', |
| 392 | 'src/core/CL/cl_kernels/common/quantization_layer.cl', |
| 393 | 'src/core/CL/cl_kernels/common/range.cl', |
| 394 | 'src/core/CL/cl_kernels/common/reduction_operation.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 395 | 'src/core/CL/cl_kernels/common/reshape_layer.cl', |
| 396 | 'src/core/CL/cl_kernels/common/convolution_layer.cl', |
| 397 | 'src/core/CL/cl_kernels/common/reverse.cl', |
| 398 | 'src/core/CL/cl_kernels/common/roi_align_layer.cl', |
| 399 | 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl', |
| 400 | 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl', |
| 401 | 'src/core/CL/cl_kernels/common/select.cl', |
| 402 | 'src/core/CL/cl_kernels/common/softmax_layer.cl', |
| 403 | 'src/core/CL/cl_kernels/common/softmax_layer_quantized.cl', |
| 404 | 'src/core/CL/cl_kernels/common/stack_layer.cl', |
| 405 | 'src/core/CL/cl_kernels/common/slice_ops.cl', |
| 406 | 'src/core/CL/cl_kernels/common/tile.cl', |
| 407 | 'src/core/CL/cl_kernels/common/transpose.cl' |
| 408 | ] |
| 409 | |
| 410 | # NCHW kernels |
| 411 | cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl', |
| 412 | 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl', |
| 413 | 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl', |
| 414 | 'src/core/CL/cl_kernels/nchw/depth_to_space.cl', |
Adnan AlSinan | 3012435 | 2021-12-02 19:12:20 +0000 | [diff] [blame] | 415 | 'src/core/CL/cl_kernels/nchw/direct_convolution.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 416 | 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl', |
| 417 | 'src/core/CL/cl_kernels/nchw/im2col.cl', |
| 418 | 'src/core/CL/cl_kernels/nchw/normalization_layer.cl', |
| 419 | 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl', |
| 420 | 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl', |
| 421 | 'src/core/CL/cl_kernels/nchw/pooling_layer.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 422 | 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 423 | 'src/core/CL/cl_kernels/nchw/reorg_layer.cl', |
| 424 | 'src/core/CL/cl_kernels/nchw/scale.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 425 | 'src/core/CL/cl_kernels/nchw/space_to_batch.cl', |
| 426 | 'src/core/CL/cl_kernels/nchw/space_to_depth.cl', |
| 427 | 'src/core/CL/cl_kernels/nchw/upsample_layer.cl', |
| 428 | 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl', |
| 429 | 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl', |
| 430 | 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl' |
| 431 | ] |
| 432 | |
| 433 | # NHWC kernels |
| 434 | cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl', |
| 435 | 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl', |
| 436 | 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl', |
| 437 | 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl', |
Giorgio Arena | 945ae9e | 2021-10-13 11:13:04 +0100 | [diff] [blame] | 438 | 'src/core/CL/cl_kernels/nhwc/direct_convolution3d.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 439 | 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl', |
| 440 | 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl', |
| 441 | 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl', |
| 442 | 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl', |
| 443 | 'src/core/CL/cl_kernels/nhwc/im2col.cl', |
| 444 | 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl', |
| 445 | 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl', |
| 446 | 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl', |
| 447 | 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl', |
ramelg01 | 3751569 | 2022-02-26 22:06:20 +0000 | [diff] [blame] | 448 | 'src/core/CL/cl_kernels/nhwc/pooling_3d_layer.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 449 | 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 450 | 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl', |
| 451 | 'src/core/CL/cl_kernels/nhwc/scale.cl', |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 452 | 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl', |
| 453 | 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl', |
| 454 | 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl', |
| 455 | 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl', |
| 456 | 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl', |
| 457 | 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl' |
| 458 | ] |
| 459 | |
| 460 | cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc |
| 461 | |
| 462 | embed_files = [ f+"embed" for f in cl_files ] |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 463 | arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] ) |
| 464 | |
| 465 | generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes)) |
| 466 | |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 467 | Default(generate_embed) |
| 468 | if env["build"] == "embed_only": |
| 469 | Return() |
| 470 | |
Georgios Pinitas | 35fcc43 | 2020-03-26 18:47:46 +0000 | [diff] [blame] | 471 | # Append version defines for semantic versioning |
| 472 | arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR), |
| 473 | ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR), |
| 474 | ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)]) |
| 475 | |
Isabella Gottardi | b28f29d | 2017-11-09 17:05:07 +0000 | [diff] [blame] | 476 | # Don't allow undefined references in the libraries: |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 477 | undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined' |
| 478 | arm_compute_env.Append(LINKFLAGS=[undefined_flag]) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 479 | arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] ) |
| 480 | |
Kevin Lo | 7195f71 | 2022-01-07 15:46:02 +0800 | [diff] [blame] | 481 | if env['os'] != 'openbsd': |
| 482 | arm_compute_env.Append(LIBS = ['dl']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 483 | |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 484 | # Load build definitions file |
| 485 | with (open(Dir('#').path + '/filedefs.json')) as fd: |
| 486 | filedefs = json.load(fd) |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 487 | filedefs = filedefs['cpu']['arch'] |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 488 | |
| 489 | |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 490 | with (open(Dir('#').path + '/filelist.json')) as fp: |
| 491 | filelist = json.load(fp) |
| 492 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 493 | # Common backend files |
| 494 | lib_files = filelist['common'] |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 495 | |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 496 | # Experimental files |
| 497 | # Dynamic fusion |
| 498 | if env['experimental_dynamic_fusion']: |
| 499 | if env['embed_kernels']: |
Giorgio Arena | 09adcc4 | 2022-03-08 11:12:27 +0000 | [diff] [blame] | 500 | # COMPMID-5176 |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 501 | print("Dynamic fusion with embed_kernels=1 not supported. Skipping.") |
| 502 | else: |
| 503 | lib_files += filelist['experimental']['dynamic_fusion'] |
| 504 | arm_compute_env.Append(CPPDEFINES = ['ENABLE_EXPERIMENTAL_DYNAMIC_FUSION']) |
| 505 | |
| 506 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 507 | # Logging files |
| 508 | if env["logging"]: |
| 509 | lib_files += filelist['logging'] |
Georgios Pinitas | 8795ffb | 2017-12-01 16:13:40 +0000 | [diff] [blame] | 510 | |
Georgios Pinitas | c3c352e | 2021-03-18 10:59:40 +0000 | [diff] [blame] | 511 | # C API files |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 512 | lib_files += filelist['c_api']['common'] |
| 513 | lib_files += filelist['c_api']['operators'] |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 514 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 515 | # Scheduler infrastructure |
| 516 | lib_files += filelist['scheduler']['single'] |
| 517 | if env['cppthreads']: |
| 518 | lib_files += filelist['scheduler']['threads'] |
| 519 | if env['openmp']: |
| 520 | lib_files += filelist['scheduler']['omp'] |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 521 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 522 | # Graph files |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 523 | graph_files = Glob('src/graph/*.cpp') |
| 524 | graph_files += Glob('src/graph/*/*.cpp') |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 525 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 526 | # Specify user-defined priority operators |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 527 | custom_operators = [] |
| 528 | custom_types = [] |
| 529 | custom_layouts = [] |
| 530 | |
| 531 | use_custom_ops = env['high_priority'] or env['build_config']; |
| 532 | |
| 533 | if env['high_priority']: |
| 534 | custom_operators = filelist['high_priority'] |
| 535 | custom_types = ['all'] |
| 536 | custom_layouts = ['all'] |
| 537 | |
| 538 | if env['build_config']: |
| 539 | custom_operators, custom_types, custom_layouts = read_build_config_json(env['build_config']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 540 | |
| 541 | if env['opencl']: |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 542 | lib_files += filelist['c_api']['gpu'] |
| 543 | lib_files += filelist['gpu']['common'] |
Michele Di Giorgio | 760c783 | 2021-08-05 10:54:13 +0100 | [diff] [blame] | 544 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 545 | cl_operators = custom_operators if use_custom_ops else filelist['gpu']['operators'].keys() |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 546 | cl_ops_to_build = resolve_operator_dependencies(filelist, cl_operators, 'gpu') |
| 547 | lib_files += get_operator_backend_files(filelist, cl_ops_to_build, 'gpu')['common'] |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 548 | |
Georgios Pinitas | 13ef176 | 2021-07-14 17:14:43 +0100 | [diff] [blame] | 549 | graph_files += Glob('src/graph/backends/CL/*.cpp') |
| 550 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 551 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 552 | lib_files_sve = [] |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 553 | lib_files_sve2 = [] |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 554 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 555 | if env['neon']: |
Georgios Pinitas | 30271c7 | 2019-06-24 14:56:34 +0100 | [diff] [blame] | 556 | # build winograd/depthwise sources for either v7a / v8a |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 557 | arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/", |
Michele Di Giorgio | 6ad60af | 2020-06-09 14:52:15 +0100 | [diff] [blame] | 558 | "src/core/NEON/kernels/convolution/winograd/", |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 559 | "src/core/NEON/kernels/convolution/depthwise/", |
| 560 | "src/core/NEON/kernels/assembly/", |
Sang-Hoon Park | 4f7693d | 2021-05-12 13:59:10 +0100 | [diff] [blame] | 561 | "arm_compute/core/NEON/kernels/assembly/", |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 562 | "src/cpu/kernels/assembly/"]) |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 563 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 564 | lib_files += filelist['cpu']['common'] |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 565 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 566 | # Setup SIMD file list to include |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 567 | simd = ['neon'] |
| 568 | if env['multi_isa']: |
| 569 | simd += ['sve', 'sve2'] |
| 570 | else: |
| 571 | if 'sve' in env['arch']: simd += ['sve'] |
| 572 | if 'sve2' in env['arch']: simd += ['sve2'] |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 573 | |
| 574 | # Get attributes |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 575 | if(use_custom_ops): |
| 576 | attrs = get_attrs_list(env, custom_types, custom_layouts) |
| 577 | else: |
| 578 | attrs = get_attrs_list(env, env['data_type_support'], env['data_layout_support']) |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 579 | |
| 580 | # Setup data-type and data-layout files to include |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 581 | cpu_operators = custom_operators if use_custom_ops else filelist['cpu']['operators'].keys() |
| 582 | cpu_ops_to_build = resolve_operator_dependencies(filelist, cpu_operators, 'cpu') |
| 583 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 584 | cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs) |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 585 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 586 | # Shared among ALL CPU files |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 587 | lib_files += cpu_files.get('common', []) |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 588 | |
| 589 | # Arm® Neon™ specific files |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 590 | lib_files += cpu_files.get('neon', []) |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 591 | |
| 592 | # SVE files only |
| 593 | lib_files_sve = cpu_files.get('sve', []) |
| 594 | |
| 595 | # SVE2 files only |
| 596 | lib_files_sve2 = cpu_files.get('sve2', []) |
Georgios Pinitas | 13ef176 | 2021-07-14 17:14:43 +0100 | [diff] [blame] | 597 | |
| 598 | graph_files += Glob('src/graph/backends/NEON/*.cpp') |
Georgios Pinitas | 70eb53b | 2021-01-06 19:42:21 +0000 | [diff] [blame] | 599 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 600 | # Restrict from building graph API if a reduced operator list has been provided |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 601 | if use_custom_ops: |
| 602 | print("WARNING: Graph library requires all operators to be built") |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 603 | graph_files = [] |
| 604 | |
| 605 | # Build bootcode in case of bare-metal |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 606 | bootcode_o = [] |
| 607 | if env['os'] == 'bare_metal': |
| 608 | bootcode_files = Glob('bootcode/*.s') |
| 609 | bootcode_o = build_bootcode_objs(bootcode_files) |
| 610 | Export('bootcode_o') |
| 611 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 612 | |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 613 | if (env['multi_isa']): |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 614 | lib_static_objs, lib_shared_objs = build_lib_objects() |
| 615 | |
| 616 | |
| 617 | # STATIC library build. |
| 618 | if (env['multi_isa']): |
| 619 | arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_static_objs, static=True) |
| 620 | else: |
| 621 | if 'sve2' in env['arch']: |
| 622 | lib_files += lib_files_sve |
| 623 | lib_files += lib_files_sve2 |
| 624 | elif 'sve' in env['arch']: |
| 625 | lib_files += lib_files_sve |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 626 | |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 627 | arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_files, static=True) |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 628 | |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 629 | Export('arm_compute_a') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 630 | |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 631 | # SHARED library build. |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 632 | if env['os'] != 'bare_metal' and not env['standalone']: |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 633 | if (env['multi_isa']): |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 634 | |
| 635 | arm_compute_so = build_library('arm_compute', arm_compute_env, lib_shared_objs, static=False) |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 636 | else: |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 637 | arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files, static=False) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 638 | |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 639 | Export('arm_compute_so') |
| 640 | |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 641 | # Generate dummy core lib for backwards compatibility |
Pablo Marquez Tello | 48f2615 | 2021-11-18 10:15:23 +0000 | [diff] [blame] | 642 | if env['os'] == 'macos': |
| 643 | # macos static library archiver fails if given an empty list of files |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 644 | arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, lib_files, static=True) |
Pablo Marquez Tello | 48f2615 | 2021-11-18 10:15:23 +0000 | [diff] [blame] | 645 | else: |
| 646 | arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [], static=True) |
| 647 | |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 648 | Export('arm_compute_core_a') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 649 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 650 | if env['os'] != 'bare_metal' and not env['standalone']: |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 651 | arm_compute_core_a_so = build_library('arm_compute_core', arm_compute_env, [], static=False) |
| 652 | Export('arm_compute_core_a_so') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 653 | |
Sang-Hoon Park | 18fbb92 | 2021-01-14 14:50:25 +0000 | [diff] [blame] | 654 | arm_compute_graph_env = arm_compute_env.Clone() |
| 655 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 656 | # Build graph libraries |
Sang-Hoon Park | 18fbb92 | 2021-01-14 14:50:25 +0000 | [diff] [blame] | 657 | arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move']) |
| 658 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 659 | 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] | 660 | Export('arm_compute_graph_a') |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 661 | |
| 662 | if env['os'] != 'bare_metal' and not env['standalone']: |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 663 | arm_compute_graph_so = build_library('arm_compute_graph', arm_compute_graph_env, graph_files, static=False, libs = [ "arm_compute" ]) |
Georgios Pinitas | 9873ea3 | 2017-12-05 15:28:55 +0000 | [diff] [blame] | 664 | Depends(arm_compute_graph_so, arm_compute_so) |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 665 | Export('arm_compute_graph_so') |
| 666 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 667 | if env['standalone']: |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 668 | alias = arm_compute_env.Alias("arm_compute", [arm_compute_a]) |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 669 | else: |
| 670 | alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so]) |
| 671 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 672 | Default(alias) |
| 673 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 674 | if env['standalone']: |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 675 | Depends([alias], generate_embed) |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 676 | else: |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 677 | Depends([alias], generate_embed) |