blob: 31e7a5b4f4fa0c0829ad9fbfa272e1d0a3022966 [file] [log] [blame]
Motti Gondabi9d9ad332022-01-23 12:42:24 +02001#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
Pablo Tellofbbfa532023-01-26 16:24:04 +00004# Copyright (c) 2016-2023 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01005#
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 Gondabi6f3a9f52021-11-09 15:47:17 +020025
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026import collections
27import os.path
28import re
29import subprocess
Georgios Pinitasea857272021-01-22 05:47:37 +000030import zlib
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010031import json
Adnan AlSinan39aebd12021-08-06 12:44:51 +010032import codecs
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033
34VERSION = "v0.0-unreleased"
Anitha Raj1a450b42023-11-13 13:35:05 +000035LIBRARY_VERSION_MAJOR = 33
Sang-Hoon Park6d0b3842020-08-14 14:48:08 +010036LIBRARY_VERSION_MINOR = 0
ramy.elgammal@arm.com1d7aefb2023-08-09 14:41:32 +010037LIBRARY_VERSION_PATCH = 0
Georgios Pinitas35fcc432020-03-26 18:47:46 +000038SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039
40Import('env')
41Import('vars')
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000042Import('install_lib')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043
Michalis Spyrou748a7c82019-10-07 13:00:44 +010044def build_bootcode_objs(sources):
Michalis Spyrou748a7c82019-10-07 13:00:44 +010045 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 Gondabi9d9ad332022-01-23 12:42:24 +020051
Motti Gondabi9d9ad332022-01-23 12:42:24 +020052# @brief Create a list of object from a given file list.
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020053#
Motti Gondabi9d9ad332022-01-23 12:42:24 +020054# @param arch_info A dictionary represents the architecture info such as the
55# compiler flags and defines (filedefs.json).
56#
57# @param sources A list of files to build
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020058#
59# @return A list of objects for the corresponding architecture.
Michalis Spyrou20fca522021-06-07 14:23:57 +010060
Motti Gondabi9d9ad332022-01-23 12:42:24 +020061def build_obj_list(arch_info, sources, static=False):
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020062
Motti Gondabi9d9ad332022-01-23 12:42:24 +020063 # Clone environment
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010064 tmp_env = arm_compute_env.Clone()
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020065
Motti Gondabi9d9ad332022-01-23 12:42:24 +020066 # Append architecture spec
67 if 'cxxflags' in arch_info and len(arch_info['cxxflags']) > 0:
68 tmp_env.Append(CXXFLAGS = arch_info['cxxflags'])
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020069
Motti Gondabi9d9ad332022-01-23 12:42:24 +020070 # Build and return objects
71 if static:
72 objs = tmp_env.StaticObject(sources)
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020073 else:
Motti Gondabi9d9ad332022-01-23 12:42:24 +020074 objs = tmp_env.SharedObject(sources)
Giorgio Arena892b70a2022-03-30 12:23:10 +010075
Motti Gondabif76a5022021-12-21 13:19:29 +020076 tmp_env.Default(objs)
77 return objs
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010078
Motti Gondabi9d9ad332022-01-23 12:42:24 +020079# @brief Build multi-ISA files with the respective architecture.
80#
81# @return Two distinct lists:
82# A list of static objects
83# A list of shared objects
Michalis Spyrou20fca522021-06-07 14:23:57 +010084
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +010085def build_multiisa_lib_objects():
Motti Gondabi9d9ad332022-01-23 12:42:24 +020086 lib_static_objs = [] # static objects
87 lib_shared_objs = [] # shared objects
88
89 arm_compute_env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON',
90 'ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE',
91 'ARM_COMPUTE_ENABLE_FP16', 'ARM_COMPUTE_ENABLE_BF16',
92 'ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_SVEF32MM'])
93
94 # Build all the common files for the base architecture
Sunita Nadampalli911d5722023-05-02 14:05:39 +000095 if env['arch'] == 'armv8a':
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +010096 lib_static_objs += build_obj_list(filedefs["armv8-a"], misa_lib_files, static=True)
97 lib_shared_objs += build_obj_list(filedefs["armv8-a"], misa_lib_files, static=False)
Sunita Nadampalli911d5722023-05-02 14:05:39 +000098 else:
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +010099 lib_static_objs += build_obj_list(filedefs["armv8.2-a"], misa_lib_files, static=True)
100 lib_shared_objs += build_obj_list(filedefs["armv8.2-a"], misa_lib_files, static=False)
101
102 # Build the FP16 specific files
103 lib_static_objs += build_obj_list(filedefs["armv8.2-a"], misa_lib_files_neon_fp16, static=True)
104 lib_shared_objs += build_obj_list(filedefs["armv8.2-a"], misa_lib_files_neon_fp16, static=False)
Giorgio Arena892b70a2022-03-30 12:23:10 +0100105
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200106 # Build the SVE specific files
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100107 lib_static_objs += build_obj_list(filedefs["armv8.2-a-sve"], misa_lib_files_sve, static=True)
108 lib_shared_objs += build_obj_list(filedefs["armv8.2-a-sve"], misa_lib_files_sve, static=False)
109 lib_static_objs += build_obj_list(filedefs["armv8.2-a-sve"], misa_lib_files_sve_fp16, static=True)
110 lib_shared_objs += build_obj_list(filedefs["armv8.2-a-sve"], misa_lib_files_sve_fp16, static=False)
111
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200112
113 # Build the SVE2 specific files
114 arm_compute_env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2'])
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100115 lib_static_objs += build_obj_list(filedefs["armv8.6-a-sve2"], misa_lib_files_sve2, static=True)
116 lib_shared_objs += build_obj_list(filedefs["armv8.6-a-sve2"], misa_lib_files_sve2, static=False)
117 lib_static_objs += build_obj_list(filedefs["armv8.6-a-sve2"], misa_lib_files_sve2_fp16, static=True)
118 lib_shared_objs += build_obj_list(filedefs["armv8.6-a-sve2"], misa_lib_files_sve2_fp16, static=False)
119
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200120
121 return lib_static_objs, lib_shared_objs
122
Michalis Spyrou20fca522021-06-07 14:23:57 +0100123
Jakub Sujake86f9922023-07-05 17:30:02 +0100124# The built-in SCons Glob() method does not support recursive searching of directories, thus we implement our own:
125def recursive_glob(root_dir, pattern):
126 files = []
127 regex = re.compile(pattern)
128
129 for dirpath, _, filenames in os.walk(root_dir):
130 for f in filenames:
131 f = os.path.join(dirpath, f)
132 if regex.match(f):
133 files.append(f)
134
135 return files
136
137
138def get_ckw_obj_list():
139 cmake_obj_dir = os.path.abspath("prototype/CMakeFiles/ckw_prototype.dir/src")
Jakub Sujaka38b4ab2023-07-11 14:18:35 +0100140 return recursive_glob(root_dir=cmake_obj_dir, pattern=".*.o$")
Jakub Sujake86f9922023-07-05 17:30:02 +0100141
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100142
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100143def build_library(name, build_env, sources, static=False, libs=[]):
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000144 cloned_build_env = build_env.Clone()
Motti Gondabif76a5022021-12-21 13:19:29 +0200145 if env['os'] == 'android' and static == False:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000146 cloned_build_env["LINKFLAGS"].remove('-pie')
147 cloned_build_env["LINKFLAGS"].remove('-static-libstdc++')
148
Jakub Sujake86f9922023-07-05 17:30:02 +0100149 # -- Static Library --
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100150 if static:
Jakub Sujake86f9922023-07-05 17:30:02 +0100151 # Recreate the list to avoid mutating the original
152 static_sources = list(sources)
153
154 # Dynamic Fusion has a direct dependency on the Compute Kernel Writer (CKW) subproject, therefore we collect the
155 # built CKW objects to pack into the Compute Library archive.
156 if env['experimental_dynamic_fusion'] and name == "arm_compute-static":
157 static_sources += get_ckw_obj_list()
158
159 obj = cloned_build_env.StaticLibrary(name, source=static_sources, LIBS=arm_compute_env["LIBS"] + libs)
160
161 # -- Shared Library --
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100162 else:
Jakub Sujake86f9922023-07-05 17:30:02 +0100163 # Always statically link Compute Library against CKW
164 if env['experimental_dynamic_fusion'] and name == "arm_compute":
165 libs.append('libckw_prototype.a')
166
167 # Add shared library versioning
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100168 if env['set_soname']:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000169 obj = cloned_build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100170 else:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000171 obj = cloned_build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100172
Pablo Marquez Tello299d3a12022-10-12 14:58:24 +0100173 if env['mapfile']:
Pablo Marquez Telloa4f88702022-10-21 10:24:23 +0100174 if not 'windows' in env['os'] and not 'macos' in env['os']:
175 cloned_build_env['LINKFLAGS'].append('"-Wl,-Map='+ name + '.map"')
176 else:
177 cloned_build_env['LINKFLAGS'].append('-Wl,-map,' + name + '.map')
Pablo Marquez Tello299d3a12022-10-12 14:58:24 +0100178
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000179 obj = install_lib(obj)
Motti Gondabif76a5022021-12-21 13:19:29 +0200180 build_env.Default(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100181 return obj
182
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100183
Georgios Pinitasf605bd22020-11-26 11:55:09 +0000184def remove_incode_comments(code):
185 def replace_with_empty(match):
186 s = match.group(0)
187 if s.startswith('/'):
188 return " "
189 else:
190 return s
191
192 comment_regex = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
193 return re.sub(comment_regex, replace_with_empty, code)
194
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100195
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100196def resolve_includes(target, source, env):
197 # File collection
198 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
199
200 # Include pattern
201 pattern = re.compile("#include \"(.*)\"")
202
203 # Get file contents
204 files = []
205 for i in range(len(source)):
206 src = source[i]
207 dst = target[i]
Georgios Pinitasf605bd22020-11-26 11:55:09 +0000208 contents = src.get_contents().decode('utf-8')
209 contents = remove_incode_comments(contents).splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100210 entry = FileEntry(target_name=dst, file_contents=contents)
211 files.append((os.path.basename(src.get_path()),entry))
212
213 # Create dictionary of tupled list
214 files_dict = dict(files)
215
216 # Check for includes (can only be files in the same folder)
217 final_files = []
218 for file in files:
219 done = False
220 tmp_file = file[1].file_contents
221 while not done:
222 file_count = 0
223 updated_file = []
224 for line in tmp_file:
225 found = pattern.search(line)
226 if found:
Giorgio Arena09adcc42022-03-08 11:12:27 +0000227 # Only get the header file name and discard the relative path.
Jakub Sujak0d27b2e2023-08-24 14:01:20 +0100228 # E.g. "src/core/CL/cl_kernels/activation_float_helpers.h" -> "activation_float_helpers.h"
Giorgio Arena232c4522022-03-03 10:09:01 +0000229 include_file = found.group(1).split('/')[-1]
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100230 data = files_dict[include_file].file_contents
231 updated_file.extend(data)
232 else:
233 updated_file.append(line)
234 file_count += 1
235
236 # Check if all include are replaced.
237 if file_count == len(tmp_file):
238 done = True
239
240 # Update temp file
241 tmp_file = updated_file
242
243 # Append and prepend string literal identifiers and add expanded file to final list
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100244 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
245 final_files.append((file[0], entry))
246
247 # Write output files
248 for file in final_files:
249 with open(file[1].target_name.get_path(), 'w+') as out_file:
Georgios Pinitasea857272021-01-22 05:47:37 +0000250 file_to_write = "\n".join( file[1].file_contents )
251 if env['compress_kernels']:
Adnan AlSinan39aebd12021-08-06 12:44:51 +0100252 file_to_write = zlib.compress(file_to_write.encode('utf-8'), 9)
253 file_to_write = codecs.encode(file_to_write, "base64").decode('utf-8').replace("\n", "")
Georgios Pinitasea857272021-01-22 05:47:37 +0000254 file_to_write = "R\"(" + file_to_write + ")\""
255 out_file.write(file_to_write)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100256
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100257
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100258def create_version_file(target, source, env):
259# Generate string with build options library version to embed in the library:
260 try:
261 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
262 except (OSError, subprocess.CalledProcessError):
263 git_hash="unknown"
264
Matthew Benthamdd8d7f42023-06-15 11:50:57 +0000265 build_options = str(vars.args).replace('"', '\\"')
266 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION,build_options, git_hash.strip())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100267 with open(target[0].get_path(), "w") as fd:
268 fd.write(build_info)
269
Michalis Spyrou20fca522021-06-07 14:23:57 +0100270
Freddie Liardet487d3902021-09-21 12:36:43 +0100271def get_attrs_list(env, data_types, data_layouts):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100272 attrs = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100273
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100274 # Manage data-types
Freddie Liardet487d3902021-09-21 12:36:43 +0100275 if 'all' in data_types:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100276 attrs += ['fp16', 'fp32', 'integer', 'qasymm8', 'qasymm8_signed', 'qsymm16']
277 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100278 if 'fp16' in data_types: attrs += ['fp16']
279 if 'fp32' in data_types: attrs += ['fp32']
280 if 'integer' in data_types: attrs += ['integer']
281 if 'qasymm8' in data_types: attrs += ['qasymm8']
282 if 'qasymm8_signed' in data_types: attrs += ['qasymm8_signed']
283 if 'qsymm16' in data_types: attrs += ['qsymm16']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100284 # Manage data-layouts
Freddie Liardet487d3902021-09-21 12:36:43 +0100285 if 'all' in data_layouts:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100286 attrs += ['nhwc', 'nchw']
287 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100288 if 'nhwc' in data_layouts: attrs += ['nhwc']
289 if 'nchw' in data_layouts: attrs += ['nchw']
Michalis Spyrou20fca522021-06-07 14:23:57 +0100290
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100291 # Manage execution state
Freddie Liardet487d3902021-09-21 12:36:43 +0100292 attrs += ['estate32' if (env['estate'] == 'auto' and 'v7a' in env['arch']) or '32' in env['estate'] else 'estate64']
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200293
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100294 return attrs
Michalis Spyrou20fca522021-06-07 14:23:57 +0100295
Michalis Spyrou20fca522021-06-07 14:23:57 +0100296
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100297def get_operator_backend_files(filelist, operators, backend='', techs=[], attrs=[], include_common=True):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100298 files = { "common" : [] }
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100299 # Early return if filelist is empty
300 if backend not in filelist:
301 return files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100302 # Iterate over operators and create the file lists to compiler
303 for operator in operators:
304 if operator in filelist[backend]['operators']:
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100305 if include_common :
306 files['common'] += filelist[backend]['operators'][operator]["files"]["common"]
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100307 for tech in techs:
308 if tech in filelist[backend]['operators'][operator]["files"]:
309 # Add tech as a key to dictionary if not there
310 if tech not in files:
311 files[tech] = []
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100312 # Add tech files to the tech file list
313 tech_files = filelist[backend]['operators'][operator]["files"][tech]
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100314 if include_common:
315 files[tech] += tech_files.get('common', [])
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100316 for attr in attrs:
317 files[tech] += tech_files.get(attr, [])
318
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100319
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100320 # Remove duplicates if they exist
321 return {k: list(set(v)) for k,v in files.items()}
322
323def collect_operators(filelist, operators, backend=''):
324 ops = set()
325 for operator in operators:
326 if operator in filelist[backend]['operators']:
327 ops.add(operator)
328 if 'deps' in filelist[backend]['operators'][operator]:
329 ops.update(filelist[backend]['operators'][operator]['deps'])
330 else:
331 print("Operator {0} is unsupported on {1} backend!".format(operator, backend))
332
333 return ops
334
335
336def resolve_operator_dependencies(filelist, operators, backend=''):
337 resolved_operators = collect_operators(filelist, operators, backend)
338
339 are_ops_resolved = False
340 while not are_ops_resolved:
341 resolution_pass = collect_operators(filelist, resolved_operators, backend)
342 if len(resolution_pass) != len(resolved_operators):
343 resolved_operators.update(resolution_pass)
344 else:
345 are_ops_resolved = True
346
347 return resolved_operators
348
Freddie Liardet487d3902021-09-21 12:36:43 +0100349def read_build_config_json(build_config):
350 build_config_contents = {}
351 custom_operators = []
352 custom_types = []
353 custom_layouts = []
354 if os.path.isfile(build_config):
355 with open(build_config) as f:
356 try:
357 build_config_contents = json.load(f)
358 except:
359 print("Warning: Build configuration file is of invalid JSON format!")
360 else:
361 try:
362 build_config_contents = json.loads(build_config)
363 except:
364 print("Warning: Build configuration string is of invalid JSON format!")
365 if build_config_contents:
366 custom_operators = build_config_contents.get("operators", [])
367 custom_types = build_config_contents.get("data_types", [])
368 custom_layouts = build_config_contents.get("data_layouts", [])
369 return custom_operators, custom_types, custom_layouts
Michalis Spyrou20fca522021-06-07 14:23:57 +0100370
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100371arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100372version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
373arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000374
Kevin Lo7195f712022-01-07 15:46:02 +0800375default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos', 'openbsd'] else 'clang++'
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100376cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
377
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000378# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100379generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000380if env['opencl'] and env['embed_kernels']:
Giorgio Arena892b70a2022-03-30 12:23:10 +0100381
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100382 # Header files
383 cl_helper_files = [ 'src/core/CL/cl_kernels/activation_float_helpers.h',
384 'src/core/CL/cl_kernels/activation_quant_helpers.h',
385 'src/core/CL/cl_kernels/gemm_helpers.h',
386 'src/core/CL/cl_kernels/helpers_asymm.h',
387 'src/core/CL/cl_kernels/helpers.h',
388 'src/core/CL/cl_kernels/load_store_utility.h',
389 'src/core/CL/cl_kernels/repeat.h',
390 'src/core/CL/cl_kernels/tile_helpers.h',
391 'src/core/CL/cl_kernels/types.h',
SiCongLi1af54162021-10-06 15:25:57 +0100392 'src/core/CL/cl_kernels/warp_helpers.h',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100393 ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000394
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100395 # Common kernels
396 cl_files_common = ['src/core/CL/cl_kernels/common/activation_layer.cl',
397 'src/core/CL/cl_kernels/common/activation_layer_quant.cl',
398 'src/core/CL/cl_kernels/common/arg_min_max.cl',
399 'src/core/CL/cl_kernels/common/batchnormalization_layer.cl',
400 'src/core/CL/cl_kernels/common/bounding_box_transform.cl',
401 'src/core/CL/cl_kernels/common/bounding_box_transform_quantized.cl',
402 'src/core/CL/cl_kernels/common/bitwise_op.cl',
403 'src/core/CL/cl_kernels/common/cast.cl',
404 'src/core/CL/cl_kernels/common/comparisons.cl',
405 'src/core/CL/cl_kernels/common/concatenate.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000406 'src/core/CL/cl_kernels/common/convolution_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100407 'src/core/CL/cl_kernels/common/col2im.cl',
408 'src/core/CL/cl_kernels/common/convert_fc_weights.cl',
409 'src/core/CL/cl_kernels/common/copy_tensor.cl',
410 'src/core/CL/cl_kernels/common/crop_tensor.cl',
411 'src/core/CL/cl_kernels/common/deconvolution_layer.cl',
412 'src/core/CL/cl_kernels/common/dequantization_layer.cl',
413 'src/core/CL/cl_kernels/common/elementwise_operation.cl',
414 'src/core/CL/cl_kernels/common/elementwise_operation_quantized.cl',
415 'src/core/CL/cl_kernels/common/elementwise_unary.cl',
Ramy Elgammal14d7b532023-01-30 04:56:47 +0000416 'src/core/CL/cl_kernels/common/elementwise_unary_quantized.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100417 'src/core/CL/cl_kernels/common/fft_digit_reverse.cl',
418 'src/core/CL/cl_kernels/common/fft.cl',
419 'src/core/CL/cl_kernels/common/fft_scale.cl',
420 'src/core/CL/cl_kernels/common/fill_border.cl',
421 'src/core/CL/cl_kernels/common/floor.cl',
422 'src/core/CL/cl_kernels/common/gather.cl',
423 'src/core/CL/cl_kernels/common/gemm.cl',
Gunes Bayir4bfc70e2021-12-10 16:17:56 +0000424 'src/core/CL/cl_kernels/common/gemm_reshaped_only_rhs_mmul.cl',
ramelg019cca5922021-11-11 10:05:00 +0000425 'src/core/CL/cl_kernels/common/gemm_utils.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100426 'src/core/CL/cl_kernels/common/gemmlowp.cl',
Freddie Liardete572dff2022-05-16 14:09:10 +0100427 'src/core/CL/cl_kernels/common/gemmlowp_reshaped_only_rhs_mmul.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000428 'src/core/CL/cl_kernels/common/gemv.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100429 'src/core/CL/cl_kernels/common/generate_proposals.cl',
430 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl',
431 'src/core/CL/cl_kernels/common/instance_normalization.cl',
432 'src/core/CL/cl_kernels/common/l2_normalize.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000433 'src/core/CL/cl_kernels/common/mat_mul.cl',
SiCong Lia8d80582023-05-19 14:23:37 +0100434 'src/core/CL/cl_kernels/common/mat_mul_mmul.cl',
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100435 'src/core/CL/cl_kernels/common/mat_mul_quantized.cl',
Gunes Bayire87fa662023-09-07 12:20:33 +0100436 'src/core/CL/cl_kernels/common/mat_mul_quantized_mmul.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100437 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100438 'src/core/CL/cl_kernels/common/memset.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100439 'src/core/CL/cl_kernels/common/minmax_layer.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000440 'src/core/CL/cl_kernels/common/nonmax.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100441 'src/core/CL/cl_kernels/common/pad_layer.cl',
442 'src/core/CL/cl_kernels/common/permute.cl',
443 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl',
444 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl',
445 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl',
446 'src/core/CL/cl_kernels/common/quantization_layer.cl',
447 'src/core/CL/cl_kernels/common/range.cl',
448 'src/core/CL/cl_kernels/common/reduction_operation.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100449 'src/core/CL/cl_kernels/common/reshape_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100450 'src/core/CL/cl_kernels/common/reverse.cl',
451 'src/core/CL/cl_kernels/common/roi_align_layer.cl',
452 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl',
453 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl',
454 'src/core/CL/cl_kernels/common/select.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000455 'src/core/CL/cl_kernels/common/slice_ops.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100456 'src/core/CL/cl_kernels/common/softmax_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100457 'src/core/CL/cl_kernels/common/stack_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100458 'src/core/CL/cl_kernels/common/tile.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000459 'src/core/CL/cl_kernels/common/transpose.cl',
460 'src/core/CL/cl_kernels/common/unpooling_layer.cl'
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100461 ]
462
463 # NCHW kernels
464 cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl',
465 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl',
466 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl',
467 'src/core/CL/cl_kernels/nchw/depth_to_space.cl',
Adnan AlSinan30124352021-12-02 19:12:20 +0000468 'src/core/CL/cl_kernels/nchw/direct_convolution.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100469 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl',
470 'src/core/CL/cl_kernels/nchw/im2col.cl',
471 'src/core/CL/cl_kernels/nchw/normalization_layer.cl',
472 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl',
473 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl',
474 'src/core/CL/cl_kernels/nchw/pooling_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100475 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100476 'src/core/CL/cl_kernels/nchw/reorg_layer.cl',
477 'src/core/CL/cl_kernels/nchw/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100478 'src/core/CL/cl_kernels/nchw/space_to_batch.cl',
479 'src/core/CL/cl_kernels/nchw/space_to_depth.cl',
480 'src/core/CL/cl_kernels/nchw/upsample_layer.cl',
481 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl',
482 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl',
483 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl'
484 ]
485
486 # NHWC kernels
487 cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl',
488 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl',
489 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl',
490 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl',
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100491 'src/core/CL/cl_kernels/nhwc/direct_convolution3d.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100492 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl',
493 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl',
494 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl',
495 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl',
496 'src/core/CL/cl_kernels/nhwc/im2col.cl',
Gian Marco Iodice5d016812022-11-17 11:03:39 +0000497 'src/core/CL/cl_kernels/nhwc/indirect_convolution.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100498 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl',
499 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl',
500 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl',
501 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl',
ramelg0137515692022-02-26 22:06:20 +0000502 'src/core/CL/cl_kernels/nhwc/pooling_3d_layer.cl',
Mohammed Suhail Munshi5e549fa2022-03-16 11:14:06 +0000503 'src/core/CL/cl_kernels/nhwc/pooling_3d_layer_quantized.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100504 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100505 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl',
506 'src/core/CL/cl_kernels/nhwc/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100507 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl',
508 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl',
Gunes Bayirec0113d2022-11-09 09:26:27 +0000509 'src/core/CL/cl_kernels/nhwc/transposed_convolution.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100510 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl',
511 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl',
512 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl',
513 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl'
514 ]
515
516 cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc
517
518 embed_files = [ f+"embed" for f in cl_files ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000519 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
520
521 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
522
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000523Default(generate_embed)
524if env["build"] == "embed_only":
525 Return()
526
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000527# Append version defines for semantic versioning
528arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
529 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
530 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
531
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000532# Don't allow undefined references in the libraries:
Georgios Pinitas45514032020-12-30 00:03:09 +0000533undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined'
Matthew Bentham0a59e692023-07-19 15:01:00 +0000534if not env['thread_sanitizer']:
535 arm_compute_env.Append(LINKFLAGS=[undefined_flag])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100536arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
537
Kevin Lo7195f712022-01-07 15:46:02 +0800538if env['os'] != 'openbsd':
Pablo Tellofbbfa532023-01-26 16:24:04 +0000539 if env['os'] == 'windows':
540 arm_compute_env.Append(LIBS = [])
541 else:
542 arm_compute_env.Append(LIBS = ['dl'])
543
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100544
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200545# Load build definitions file
546with (open(Dir('#').path + '/filedefs.json')) as fd:
547 filedefs = json.load(fd)
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200548 filedefs = filedefs['cpu']['arch']
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200549
550
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100551with (open(Dir('#').path + '/filelist.json')) as fp:
552 filelist = json.load(fp)
553
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100554# Common backend files
555lib_files = filelist['common']
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100556
Nathan John Sircombed7113e42023-04-26 15:02:43 +0100557# Fixed format GEMM kernels.
558if env['fixed_format_kernels']:
559 arm_compute_env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS'])
560
Giorgio Arena232c4522022-03-03 10:09:01 +0000561# Experimental files
562# Dynamic fusion
563if env['experimental_dynamic_fusion']:
SiCong Li23882a92023-06-28 09:49:45 +0100564 lib_files += filelist['experimental']['dynamic_fusion']['common']
565 lib_files += filelist['experimental']['dynamic_fusion']['template_writer']
566
567if "ACL_INTERNAL_TEST_CKW_IN_DF" in env["extra_cxx_flags"]:
568 if not env["experimental_dynamic_fusion"]:
569 print("To use ACL_INTERNAL_TEST_CKW_IN_DF experimental_dynamic_fusion must be set to 1")
570 Exit(1)
571 lib_files += filelist['experimental']['dynamic_fusion']['ckw_driver']
Giorgio Arena232c4522022-03-03 10:09:01 +0000572
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100573# Logging files
574if env["logging"]:
575 lib_files += filelist['logging']
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000576
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000577# C API files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100578lib_files += filelist['c_api']['common']
579lib_files += filelist['c_api']['operators']
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100580
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100581# Scheduler infrastructure
582lib_files += filelist['scheduler']['single']
583if env['cppthreads']:
584 lib_files += filelist['scheduler']['threads']
585if env['openmp']:
586 lib_files += filelist['scheduler']['omp']
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000587
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100588# Graph files
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100589graph_files = Glob('src/graph/*.cpp')
590graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000591
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100592# Specify user-defined priority operators
Freddie Liardet487d3902021-09-21 12:36:43 +0100593custom_operators = []
594custom_types = []
595custom_layouts = []
596
Jakub Sujake86f9922023-07-05 17:30:02 +0100597use_custom_ops = env['high_priority'] or env['build_config']
Freddie Liardet487d3902021-09-21 12:36:43 +0100598
599if env['high_priority']:
600 custom_operators = filelist['high_priority']
601 custom_types = ['all']
602 custom_layouts = ['all']
603
604if env['build_config']:
605 custom_operators, custom_types, custom_layouts = read_build_config_json(env['build_config'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100606
607if env['opencl']:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100608 lib_files += filelist['c_api']['gpu']
609 lib_files += filelist['gpu']['common']
Michele Di Giorgio760c7832021-08-05 10:54:13 +0100610
Freddie Liardet487d3902021-09-21 12:36:43 +0100611 cl_operators = custom_operators if use_custom_ops else filelist['gpu']['operators'].keys()
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100612 cl_ops_to_build = resolve_operator_dependencies(filelist, cl_operators, 'gpu')
613 lib_files += get_operator_backend_files(filelist, cl_ops_to_build, 'gpu')['common']
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000614
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100615 graph_files += Glob('src/graph/backends/CL/*.cpp')
616
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200617
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100618lib_files_sve = []
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200619lib_files_sve2 = []
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200620
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100621# the variables below are used for the multi_isa builds
622# please note that the variables names without the _fp16 suffix
623# do not hold any fp16 files.
624
625misa_lib_files = lib_files
626misa_lib_files_sve = []
627misa_lib_files_sve2 = []
628misa_lib_files_neon_fp16 = []
629misa_lib_files_sve_fp16 = []
630misa_lib_files_sve2_fp16 = []
631
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100632if env['neon']:
Georgios Pinitas30271c72019-06-24 14:56:34 +0100633 # build winograd/depthwise sources for either v7a / v8a
Michael Tyler74921ee2023-04-12 17:43:17 +0100634 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/arm_gemm",
635 "src/core/NEON/kernels/convolution/common/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100636 "src/core/NEON/kernels/convolution/winograd/",
ramelg01c827e992022-04-08 03:52:28 +0100637 "src/core/NEON/kernels/arm_conv/depthwise/",
638 "src/core/NEON/kernels/arm_conv/pooling/",
ramelg018a164882022-04-07 02:42:52 +0100639 "src/core/NEON/kernels/arm_conv/",
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100640 "src/core/NEON/kernels/assembly/",
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +0100641 "arm_compute/core/NEON/kernels/assembly/",
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200642 "src/cpu/kernels/assembly/"])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000643
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100644 # Setup SIMD file list to include
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200645 simd = ['neon']
646 if env['multi_isa']:
647 simd += ['sve', 'sve2']
648 else:
649 if 'sve' in env['arch']: simd += ['sve']
650 if 'sve2' in env['arch']: simd += ['sve2']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100651
652 # Get attributes
Freddie Liardet487d3902021-09-21 12:36:43 +0100653 if(use_custom_ops):
654 attrs = get_attrs_list(env, custom_types, custom_layouts)
655 else:
656 attrs = get_attrs_list(env, env['data_type_support'], env['data_layout_support'])
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100657
Nathan John Sircombed7113e42023-04-26 15:02:43 +0100658 if env['fixed_format_kernels']:
659 attrs.append("fixed_format_kernels")
Francesco.Petrogalli@arm.com5fcf22d2022-04-05 10:31:08 +0000660
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100661 # Setup data-type and data-layout files to include
Freddie Liardet487d3902021-09-21 12:36:43 +0100662 cpu_operators = custom_operators if use_custom_ops else filelist['cpu']['operators'].keys()
663 cpu_ops_to_build = resolve_operator_dependencies(filelist, cpu_operators, 'cpu')
664
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100665 if env['multi_isa']:
666 misa_lib_files += filelist['cpu']['common']
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200667
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100668 # For multi_isa builds we need to build fp16 files for armv8.2-a+fp16 so we filter them out of cpu_files removing the attribute fp16
669 attrs.remove('fp16')
670 cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200671
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100672 # Shared among ALL CPU files
673 misa_lib_files += cpu_files.get('common', [])
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200674
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100675 # Arm® Neon™ specific files
676 misa_lib_files += cpu_files.get('neon', [])
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200677
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100678 # Get all the fp16 files
679 fp16_cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, ['fp16'],False)
680
681 misa_lib_files_neon_fp16 = fp16_cpu_files.get('neon',[])
682 misa_lib_files_sve_fp16 = fp16_cpu_files.get('sve',[])
683 misa_lib_files_sve2_fp16 = fp16_cpu_files.get('sve2',[])
684
685 # SVE files only minus FP16
686 misa_lib_files_sve = cpu_files.get('sve', [])
687
688 # SVE2 files only minus FP16
689 misa_lib_files_sve2 = cpu_files.get('sve2', [])
690 else:
691 lib_files += filelist['cpu']['common']
692
693 # Non multi_isa build
694 cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
695
696 # Shared among ALL CPU files
697 lib_files += cpu_files.get('common', [])
698
699 # Arm® Neon™ specific files
700 lib_files += cpu_files.get('neon', [])
701
702 lib_files_sve = cpu_files.get('sve', [])
703
704 lib_files_sve2 = cpu_files.get('sve2', [])
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100705
706 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000707
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100708# Restrict from building graph API if a reduced operator list has been provided
Freddie Liardet487d3902021-09-21 12:36:43 +0100709if use_custom_ops:
710 print("WARNING: Graph library requires all operators to be built")
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100711 graph_files = []
712
713# Build bootcode in case of bare-metal
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100714bootcode_o = []
715if env['os'] == 'bare_metal':
716 bootcode_files = Glob('bootcode/*.s')
717 bootcode_o = build_bootcode_objs(bootcode_files)
718Export('bootcode_o')
719
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200720
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200721if (env['multi_isa']):
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100722 lib_static_objs, lib_shared_objs = build_multiisa_lib_objects()
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200723
724
725# STATIC library build.
726if (env['multi_isa']):
727 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_static_objs, static=True)
728else:
729 if 'sve2' in env['arch']:
730 lib_files += lib_files_sve
731 lib_files += lib_files_sve2
732 elif 'sve' in env['arch']:
733 lib_files += lib_files_sve
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200734
Motti Gondabif76a5022021-12-21 13:19:29 +0200735 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_files, static=True)
Motti Gondabif76a5022021-12-21 13:19:29 +0200736
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100737Export('arm_compute_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100738
Motti Gondabif76a5022021-12-21 13:19:29 +0200739# SHARED library build.
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100740if env['os'] != 'bare_metal' and not env['standalone']:
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200741 if (env['multi_isa']):
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200742
743 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_shared_objs, static=False)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100744 else:
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200745 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100746
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100747 Export('arm_compute_so')
748
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100749
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000750arm_compute_graph_env = arm_compute_env.Clone()
751
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100752# Build graph libraries
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000753arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
754
Jakub Sujake86f9922023-07-05 17:30:02 +0100755arm_compute_graph_a = build_library('arm_compute_graph-static', arm_compute_graph_env, graph_files, static=True)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100756Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000757
758if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100759 arm_compute_graph_so = build_library('arm_compute_graph', arm_compute_graph_env, graph_files, static=False, libs = [ "arm_compute" ])
Georgios Pinitas9873ea32017-12-05 15:28:55 +0000760 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100761 Export('arm_compute_graph_so')
762
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100763if env['standalone']:
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200764 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100765else:
766 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
767
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100768Default(alias)
769
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100770if env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100771 Depends([alias], generate_embed)
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100772else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100773 Depends([alias], generate_embed)