blob: 80aa87cae882efdddb1f893af103181b45a593ad [file] [log] [blame]
Motti Gondabi9d9ad332022-01-23 12:42:24 +02001#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
Felix Thomasmathibalan3a704ae2024-01-18 09:11:13 +00004# Copyright (c) 2016-2024 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
Jakub Sujak6a827872024-03-20 18:18:08 +000033import platform
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
35VERSION = "v0.0-unreleased"
Michael Kozlov5057ce92024-04-17 14:34:46 +010036LIBRARY_VERSION_MAJOR = 36
Sang-Hoon Park6d0b3842020-08-14 14:48:08 +010037LIBRARY_VERSION_MINOR = 0
Michael Kozlov5057ce92024-04-17 14:34:46 +010038LIBRARY_VERSION_PATCH = 0
Georgios Pinitas35fcc432020-03-26 18:47:46 +000039SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040
41Import('env')
42Import('vars')
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000043Import('install_lib')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010044
Jakub Sujak6a827872024-03-20 18:18:08 +000045# Workaround to enable cross-compiling from macOS® to Android™ using the Android NDK.
46if platform.system() == 'Darwin' and env['os'] == 'android':
47 # SCons incorrectly assumes that we always want to build a dynamic library on a macOS host.
48 # When targeting Android, we overwrite the following construction variables to build a shared library instead.
49 env.Replace(SHLIBSUFFIX = '.so') # overwrites .dylib
50 env.Replace(SHLINKFLAGS = ['$LINKFLAGS', '-shared']) # overwrites -dynamiclib
51
Michalis Spyrou748a7c82019-10-07 13:00:44 +010052def build_bootcode_objs(sources):
Michalis Spyrou748a7c82019-10-07 13:00:44 +010053 arm_compute_env.Append(ASFLAGS = "-I bootcode/")
54 obj = arm_compute_env.Object(sources)
55 obj = install_lib(obj)
56 Default(obj)
57 return obj
58
Motti Gondabi9d9ad332022-01-23 12:42:24 +020059
Motti Gondabi9d9ad332022-01-23 12:42:24 +020060# @brief Create a list of object from a given file list.
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020061#
Motti Gondabi9d9ad332022-01-23 12:42:24 +020062# @param arch_info A dictionary represents the architecture info such as the
63# compiler flags and defines (filedefs.json).
64#
65# @param sources A list of files to build
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020066#
67# @return A list of objects for the corresponding architecture.
Michalis Spyrou20fca522021-06-07 14:23:57 +010068
Motti Gondabi9d9ad332022-01-23 12:42:24 +020069def build_obj_list(arch_info, sources, static=False):
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020070
Motti Gondabi9d9ad332022-01-23 12:42:24 +020071 # Clone environment
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010072 tmp_env = arm_compute_env.Clone()
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020073
Motti Gondabi9d9ad332022-01-23 12:42:24 +020074 # Append architecture spec
75 if 'cxxflags' in arch_info and len(arch_info['cxxflags']) > 0:
76 tmp_env.Append(CXXFLAGS = arch_info['cxxflags'])
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020077
Motti Gondabi9d9ad332022-01-23 12:42:24 +020078 # Build and return objects
79 if static:
80 objs = tmp_env.StaticObject(sources)
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020081 else:
Motti Gondabi9d9ad332022-01-23 12:42:24 +020082 objs = tmp_env.SharedObject(sources)
Giorgio Arena892b70a2022-03-30 12:23:10 +010083
Motti Gondabif76a5022021-12-21 13:19:29 +020084 tmp_env.Default(objs)
85 return objs
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010086
Motti Gondabi9d9ad332022-01-23 12:42:24 +020087# @brief Build multi-ISA files with the respective architecture.
88#
89# @return Two distinct lists:
90# A list of static objects
91# A list of shared objects
Michalis Spyrou20fca522021-06-07 14:23:57 +010092
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +010093def build_multiisa_lib_objects():
Motti Gondabi9d9ad332022-01-23 12:42:24 +020094 lib_static_objs = [] # static objects
95 lib_shared_objs = [] # shared objects
96
Pablo Marquez Tello391f8722023-12-07 15:27:26 +000097 # note that ARM_COMPUTE_ENABLE_FP16 is enabled in update_data_type_layout_flags() to make
98 # sure the environment is progated to the validation suite
Motti Gondabi9d9ad332022-01-23 12:42:24 +020099 arm_compute_env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON',
Pablo Marquez Tello391f8722023-12-07 15:27:26 +0000100 'ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE','ARM_COMPUTE_ENABLE_BF16',
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200101 'ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_SVEF32MM'])
102
103 # Build all the common files for the base architecture
Pablo Marquez Telloec89b912024-01-29 16:07:17 +0000104 if env['arch'] == 'armv8a' or env['arch'] == 'arm64-v8a':
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100105 lib_static_objs += build_obj_list(filedefs["armv8-a"], misa_lib_files, static=True)
106 lib_shared_objs += build_obj_list(filedefs["armv8-a"], misa_lib_files, static=False)
Sunita Nadampalli911d5722023-05-02 14:05:39 +0000107 else:
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100108 lib_static_objs += build_obj_list(filedefs["armv8.2-a"], misa_lib_files, static=True)
109 lib_shared_objs += build_obj_list(filedefs["armv8.2-a"], misa_lib_files, static=False)
110
111 # Build the FP16 specific files
112 lib_static_objs += build_obj_list(filedefs["armv8.2-a"], misa_lib_files_neon_fp16, static=True)
113 lib_shared_objs += build_obj_list(filedefs["armv8.2-a"], misa_lib_files_neon_fp16, static=False)
Giorgio Arena892b70a2022-03-30 12:23:10 +0100114
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200115 # Build the SVE specific files
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100116 lib_static_objs += build_obj_list(filedefs["armv8.2-a-sve"], misa_lib_files_sve, static=True)
117 lib_shared_objs += build_obj_list(filedefs["armv8.2-a-sve"], misa_lib_files_sve, static=False)
118 lib_static_objs += build_obj_list(filedefs["armv8.2-a-sve"], misa_lib_files_sve_fp16, static=True)
119 lib_shared_objs += build_obj_list(filedefs["armv8.2-a-sve"], misa_lib_files_sve_fp16, static=False)
120
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200121
122 # Build the SVE2 specific files
123 arm_compute_env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2'])
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100124 lib_static_objs += build_obj_list(filedefs["armv8.6-a-sve2"], misa_lib_files_sve2, static=True)
125 lib_shared_objs += build_obj_list(filedefs["armv8.6-a-sve2"], misa_lib_files_sve2, static=False)
126 lib_static_objs += build_obj_list(filedefs["armv8.6-a-sve2"], misa_lib_files_sve2_fp16, static=True)
127 lib_shared_objs += build_obj_list(filedefs["armv8.6-a-sve2"], misa_lib_files_sve2_fp16, static=False)
128
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200129
130 return lib_static_objs, lib_shared_objs
131
Michalis Spyrou20fca522021-06-07 14:23:57 +0100132
Jakub Sujake86f9922023-07-05 17:30:02 +0100133# The built-in SCons Glob() method does not support recursive searching of directories, thus we implement our own:
134def recursive_glob(root_dir, pattern):
135 files = []
136 regex = re.compile(pattern)
137
138 for dirpath, _, filenames in os.walk(root_dir):
139 for f in filenames:
140 f = os.path.join(dirpath, f)
141 if regex.match(f):
142 files.append(f)
143
144 return files
145
146
147def get_ckw_obj_list():
Gunes Bayir2b9fa592024-01-17 16:07:03 +0000148 cmake_obj_dir = os.path.abspath("CMakeFiles/ckw.dir/src")
Jakub Sujaka38b4ab2023-07-11 14:18:35 +0100149 return recursive_glob(root_dir=cmake_obj_dir, pattern=".*.o$")
Jakub Sujake86f9922023-07-05 17:30:02 +0100150
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100151
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100152def build_library(name, build_env, sources, static=False, libs=[]):
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000153 cloned_build_env = build_env.Clone()
Motti Gondabif76a5022021-12-21 13:19:29 +0200154 if env['os'] == 'android' and static == False:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000155 cloned_build_env["LINKFLAGS"].remove('-pie')
156 cloned_build_env["LINKFLAGS"].remove('-static-libstdc++')
157
Jakub Sujake86f9922023-07-05 17:30:02 +0100158 # -- Static Library --
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100159 if static:
Jakub Sujake86f9922023-07-05 17:30:02 +0100160 # Recreate the list to avoid mutating the original
161 static_sources = list(sources)
162
163 # Dynamic Fusion has a direct dependency on the Compute Kernel Writer (CKW) subproject, therefore we collect the
164 # built CKW objects to pack into the Compute Library archive.
165 if env['experimental_dynamic_fusion'] and name == "arm_compute-static":
166 static_sources += get_ckw_obj_list()
167
168 obj = cloned_build_env.StaticLibrary(name, source=static_sources, LIBS=arm_compute_env["LIBS"] + libs)
169
170 # -- Shared Library --
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100171 else:
Jakub Sujake86f9922023-07-05 17:30:02 +0100172 # Always statically link Compute Library against CKW
173 if env['experimental_dynamic_fusion'] and name == "arm_compute":
Gunes Bayir2b9fa592024-01-17 16:07:03 +0000174 libs.append('libckw.a')
Jakub Sujake86f9922023-07-05 17:30:02 +0100175
176 # Add shared library versioning
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100177 if env['set_soname']:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000178 obj = cloned_build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100179 else:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000180 obj = cloned_build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100181
Pablo Marquez Tello299d3a12022-10-12 14:58:24 +0100182 if env['mapfile']:
Pablo Marquez Telloa4f88702022-10-21 10:24:23 +0100183 if not 'windows' in env['os'] and not 'macos' in env['os']:
184 cloned_build_env['LINKFLAGS'].append('"-Wl,-Map='+ name + '.map"')
185 else:
186 cloned_build_env['LINKFLAGS'].append('-Wl,-map,' + name + '.map')
Pablo Marquez Tello299d3a12022-10-12 14:58:24 +0100187
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000188 obj = install_lib(obj)
Motti Gondabif76a5022021-12-21 13:19:29 +0200189 build_env.Default(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100190 return obj
191
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100192
Georgios Pinitasf605bd22020-11-26 11:55:09 +0000193def remove_incode_comments(code):
194 def replace_with_empty(match):
195 s = match.group(0)
196 if s.startswith('/'):
197 return " "
198 else:
199 return s
200
201 comment_regex = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
202 return re.sub(comment_regex, replace_with_empty, code)
203
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100204
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100205def resolve_includes(target, source, env):
206 # File collection
207 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
208
209 # Include pattern
210 pattern = re.compile("#include \"(.*)\"")
211
212 # Get file contents
213 files = []
214 for i in range(len(source)):
215 src = source[i]
216 dst = target[i]
Georgios Pinitasf605bd22020-11-26 11:55:09 +0000217 contents = src.get_contents().decode('utf-8')
218 contents = remove_incode_comments(contents).splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100219 entry = FileEntry(target_name=dst, file_contents=contents)
220 files.append((os.path.basename(src.get_path()),entry))
221
222 # Create dictionary of tupled list
223 files_dict = dict(files)
224
225 # Check for includes (can only be files in the same folder)
226 final_files = []
227 for file in files:
228 done = False
229 tmp_file = file[1].file_contents
230 while not done:
231 file_count = 0
232 updated_file = []
233 for line in tmp_file:
234 found = pattern.search(line)
235 if found:
Giorgio Arena09adcc42022-03-08 11:12:27 +0000236 # Only get the header file name and discard the relative path.
Jakub Sujak0d27b2e2023-08-24 14:01:20 +0100237 # E.g. "src/core/CL/cl_kernels/activation_float_helpers.h" -> "activation_float_helpers.h"
Giorgio Arena232c4522022-03-03 10:09:01 +0000238 include_file = found.group(1).split('/')[-1]
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100239 data = files_dict[include_file].file_contents
240 updated_file.extend(data)
241 else:
242 updated_file.append(line)
243 file_count += 1
244
245 # Check if all include are replaced.
246 if file_count == len(tmp_file):
247 done = True
248
249 # Update temp file
250 tmp_file = updated_file
251
252 # Append and prepend string literal identifiers and add expanded file to final list
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100253 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
254 final_files.append((file[0], entry))
255
256 # Write output files
257 for file in final_files:
258 with open(file[1].target_name.get_path(), 'w+') as out_file:
Georgios Pinitasea857272021-01-22 05:47:37 +0000259 file_to_write = "\n".join( file[1].file_contents )
260 if env['compress_kernels']:
Adnan AlSinan39aebd12021-08-06 12:44:51 +0100261 file_to_write = zlib.compress(file_to_write.encode('utf-8'), 9)
262 file_to_write = codecs.encode(file_to_write, "base64").decode('utf-8').replace("\n", "")
Georgios Pinitasea857272021-01-22 05:47:37 +0000263 file_to_write = "R\"(" + file_to_write + ")\""
264 out_file.write(file_to_write)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100265
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100266
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100267def create_version_file(target, source, env):
268# Generate string with build options library version to embed in the library:
269 try:
270 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
271 except (OSError, subprocess.CalledProcessError):
272 git_hash="unknown"
273
Matthew Benthamdd8d7f42023-06-15 11:50:57 +0000274 build_options = str(vars.args).replace('"', '\\"')
275 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 +0100276 with open(target[0].get_path(), "w") as fd:
277 fd.write(build_info)
278
Michalis Spyrou20fca522021-06-07 14:23:57 +0100279
Freddie Liardet487d3902021-09-21 12:36:43 +0100280def get_attrs_list(env, data_types, data_layouts):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100281 attrs = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100282
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100283 # Manage data-types
Freddie Liardet487d3902021-09-21 12:36:43 +0100284 if 'all' in data_types:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100285 attrs += ['fp16', 'fp32', 'integer', 'qasymm8', 'qasymm8_signed', 'qsymm16']
286 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100287 if 'fp16' in data_types: attrs += ['fp16']
288 if 'fp32' in data_types: attrs += ['fp32']
289 if 'integer' in data_types: attrs += ['integer']
290 if 'qasymm8' in data_types: attrs += ['qasymm8']
291 if 'qasymm8_signed' in data_types: attrs += ['qasymm8_signed']
292 if 'qsymm16' in data_types: attrs += ['qsymm16']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100293 # Manage data-layouts
Freddie Liardet487d3902021-09-21 12:36:43 +0100294 if 'all' in data_layouts:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100295 attrs += ['nhwc', 'nchw']
296 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100297 if 'nhwc' in data_layouts: attrs += ['nhwc']
298 if 'nchw' in data_layouts: attrs += ['nchw']
Michalis Spyrou20fca522021-06-07 14:23:57 +0100299
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100300 # Manage execution state
Freddie Liardet487d3902021-09-21 12:36:43 +0100301 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 +0200302
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100303 return attrs
Michalis Spyrou20fca522021-06-07 14:23:57 +0100304
Michalis Spyrou20fca522021-06-07 14:23:57 +0100305
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100306def get_operator_backend_files(filelist, operators, backend='', techs=[], attrs=[], include_common=True):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100307 files = { "common" : [] }
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100308 # Early return if filelist is empty
309 if backend not in filelist:
310 return files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100311 # Iterate over operators and create the file lists to compiler
312 for operator in operators:
313 if operator in filelist[backend]['operators']:
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100314 if include_common :
315 files['common'] += filelist[backend]['operators'][operator]["files"]["common"]
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100316 for tech in techs:
317 if tech in filelist[backend]['operators'][operator]["files"]:
318 # Add tech as a key to dictionary if not there
319 if tech not in files:
320 files[tech] = []
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100321 # Add tech files to the tech file list
322 tech_files = filelist[backend]['operators'][operator]["files"][tech]
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100323 if include_common:
324 files[tech] += tech_files.get('common', [])
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100325 for attr in attrs:
326 files[tech] += tech_files.get(attr, [])
327
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100328
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100329 # Remove duplicates if they exist
330 return {k: list(set(v)) for k,v in files.items()}
331
332def collect_operators(filelist, operators, backend=''):
333 ops = set()
334 for operator in operators:
335 if operator in filelist[backend]['operators']:
336 ops.add(operator)
337 if 'deps' in filelist[backend]['operators'][operator]:
338 ops.update(filelist[backend]['operators'][operator]['deps'])
339 else:
340 print("Operator {0} is unsupported on {1} backend!".format(operator, backend))
341
342 return ops
343
344
345def resolve_operator_dependencies(filelist, operators, backend=''):
346 resolved_operators = collect_operators(filelist, operators, backend)
347
348 are_ops_resolved = False
349 while not are_ops_resolved:
350 resolution_pass = collect_operators(filelist, resolved_operators, backend)
351 if len(resolution_pass) != len(resolved_operators):
352 resolved_operators.update(resolution_pass)
353 else:
354 are_ops_resolved = True
355
356 return resolved_operators
357
Freddie Liardet487d3902021-09-21 12:36:43 +0100358def read_build_config_json(build_config):
359 build_config_contents = {}
360 custom_operators = []
361 custom_types = []
362 custom_layouts = []
363 if os.path.isfile(build_config):
364 with open(build_config) as f:
365 try:
366 build_config_contents = json.load(f)
367 except:
368 print("Warning: Build configuration file is of invalid JSON format!")
369 else:
370 try:
371 build_config_contents = json.loads(build_config)
372 except:
373 print("Warning: Build configuration string is of invalid JSON format!")
374 if build_config_contents:
375 custom_operators = build_config_contents.get("operators", [])
376 custom_types = build_config_contents.get("data_types", [])
377 custom_layouts = build_config_contents.get("data_layouts", [])
378 return custom_operators, custom_types, custom_layouts
Michalis Spyrou20fca522021-06-07 14:23:57 +0100379
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100380arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100381version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
382arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000383
Kevin Lo7195f712022-01-07 15:46:02 +0800384default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos', 'openbsd'] else 'clang++'
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100385cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
386
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000387# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100388generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000389if env['opencl'] and env['embed_kernels']:
Giorgio Arena892b70a2022-03-30 12:23:10 +0100390
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100391 # Header files
392 cl_helper_files = [ 'src/core/CL/cl_kernels/activation_float_helpers.h',
393 'src/core/CL/cl_kernels/activation_quant_helpers.h',
394 'src/core/CL/cl_kernels/gemm_helpers.h',
395 'src/core/CL/cl_kernels/helpers_asymm.h',
396 'src/core/CL/cl_kernels/helpers.h',
397 'src/core/CL/cl_kernels/load_store_utility.h',
398 'src/core/CL/cl_kernels/repeat.h',
399 'src/core/CL/cl_kernels/tile_helpers.h',
400 'src/core/CL/cl_kernels/types.h',
SiCongLi1af54162021-10-06 15:25:57 +0100401 'src/core/CL/cl_kernels/warp_helpers.h',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100402 ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000403
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100404 # Common kernels
405 cl_files_common = ['src/core/CL/cl_kernels/common/activation_layer.cl',
406 'src/core/CL/cl_kernels/common/activation_layer_quant.cl',
407 'src/core/CL/cl_kernels/common/arg_min_max.cl',
408 'src/core/CL/cl_kernels/common/batchnormalization_layer.cl',
409 'src/core/CL/cl_kernels/common/bounding_box_transform.cl',
410 'src/core/CL/cl_kernels/common/bounding_box_transform_quantized.cl',
411 'src/core/CL/cl_kernels/common/bitwise_op.cl',
412 'src/core/CL/cl_kernels/common/cast.cl',
413 'src/core/CL/cl_kernels/common/comparisons.cl',
414 'src/core/CL/cl_kernels/common/concatenate.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000415 'src/core/CL/cl_kernels/common/convolution_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100416 'src/core/CL/cl_kernels/common/col2im.cl',
417 'src/core/CL/cl_kernels/common/convert_fc_weights.cl',
418 'src/core/CL/cl_kernels/common/copy_tensor.cl',
419 'src/core/CL/cl_kernels/common/crop_tensor.cl',
420 'src/core/CL/cl_kernels/common/deconvolution_layer.cl',
421 'src/core/CL/cl_kernels/common/dequantization_layer.cl',
422 'src/core/CL/cl_kernels/common/elementwise_operation.cl',
423 'src/core/CL/cl_kernels/common/elementwise_operation_quantized.cl',
424 'src/core/CL/cl_kernels/common/elementwise_unary.cl',
Ramy Elgammal14d7b532023-01-30 04:56:47 +0000425 'src/core/CL/cl_kernels/common/elementwise_unary_quantized.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100426 'src/core/CL/cl_kernels/common/fft_digit_reverse.cl',
427 'src/core/CL/cl_kernels/common/fft.cl',
428 'src/core/CL/cl_kernels/common/fft_scale.cl',
429 'src/core/CL/cl_kernels/common/fill_border.cl',
430 'src/core/CL/cl_kernels/common/floor.cl',
431 'src/core/CL/cl_kernels/common/gather.cl',
Mohammed Suhail Munshi73771072024-03-25 15:55:42 +0000432 'src/core/CL/cl_kernels/common/scatter.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100433 'src/core/CL/cl_kernels/common/gemm.cl',
Gunes Bayir4bfc70e2021-12-10 16:17:56 +0000434 'src/core/CL/cl_kernels/common/gemm_reshaped_only_rhs_mmul.cl',
ramelg019cca5922021-11-11 10:05:00 +0000435 'src/core/CL/cl_kernels/common/gemm_utils.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100436 'src/core/CL/cl_kernels/common/gemmlowp.cl',
Freddie Liardete572dff2022-05-16 14:09:10 +0100437 'src/core/CL/cl_kernels/common/gemmlowp_reshaped_only_rhs_mmul.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000438 'src/core/CL/cl_kernels/common/gemv.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100439 'src/core/CL/cl_kernels/common/generate_proposals.cl',
440 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl',
441 'src/core/CL/cl_kernels/common/instance_normalization.cl',
442 'src/core/CL/cl_kernels/common/l2_normalize.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000443 'src/core/CL/cl_kernels/common/mat_mul.cl',
SiCong Lia8d80582023-05-19 14:23:37 +0100444 'src/core/CL/cl_kernels/common/mat_mul_mmul.cl',
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100445 'src/core/CL/cl_kernels/common/mat_mul_quantized.cl',
Gunes Bayire87fa662023-09-07 12:20:33 +0100446 'src/core/CL/cl_kernels/common/mat_mul_quantized_mmul.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100447 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100448 'src/core/CL/cl_kernels/common/memset.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100449 'src/core/CL/cl_kernels/common/minmax_layer.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000450 'src/core/CL/cl_kernels/common/nonmax.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100451 'src/core/CL/cl_kernels/common/pad_layer.cl',
452 'src/core/CL/cl_kernels/common/permute.cl',
453 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl',
454 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl',
455 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl',
456 'src/core/CL/cl_kernels/common/quantization_layer.cl',
457 'src/core/CL/cl_kernels/common/range.cl',
458 'src/core/CL/cl_kernels/common/reduction_operation.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100459 'src/core/CL/cl_kernels/common/reshape_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100460 'src/core/CL/cl_kernels/common/reverse.cl',
461 'src/core/CL/cl_kernels/common/roi_align_layer.cl',
462 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl',
463 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl',
464 'src/core/CL/cl_kernels/common/select.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000465 'src/core/CL/cl_kernels/common/slice_ops.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100466 'src/core/CL/cl_kernels/common/softmax_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100467 'src/core/CL/cl_kernels/common/stack_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100468 'src/core/CL/cl_kernels/common/tile.cl',
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000469 'src/core/CL/cl_kernels/common/transpose.cl',
470 'src/core/CL/cl_kernels/common/unpooling_layer.cl'
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100471 ]
472
473 # NCHW kernels
474 cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl',
475 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl',
476 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl',
477 'src/core/CL/cl_kernels/nchw/depth_to_space.cl',
Adnan AlSinan30124352021-12-02 19:12:20 +0000478 'src/core/CL/cl_kernels/nchw/direct_convolution.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100479 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl',
480 'src/core/CL/cl_kernels/nchw/im2col.cl',
481 'src/core/CL/cl_kernels/nchw/normalization_layer.cl',
482 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl',
483 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl',
484 'src/core/CL/cl_kernels/nchw/pooling_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100485 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100486 'src/core/CL/cl_kernels/nchw/reorg_layer.cl',
487 'src/core/CL/cl_kernels/nchw/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100488 'src/core/CL/cl_kernels/nchw/space_to_batch.cl',
489 'src/core/CL/cl_kernels/nchw/space_to_depth.cl',
490 'src/core/CL/cl_kernels/nchw/upsample_layer.cl',
491 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl',
492 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl',
493 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl'
494 ]
495
496 # NHWC kernels
497 cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl',
498 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl',
499 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl',
500 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl',
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100501 'src/core/CL/cl_kernels/nhwc/direct_convolution3d.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100502 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl',
503 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl',
504 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl',
505 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl',
506 'src/core/CL/cl_kernels/nhwc/im2col.cl',
Gian Marco Iodice5d016812022-11-17 11:03:39 +0000507 'src/core/CL/cl_kernels/nhwc/indirect_convolution.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100508 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl',
509 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl',
510 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl',
511 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl',
ramelg0137515692022-02-26 22:06:20 +0000512 'src/core/CL/cl_kernels/nhwc/pooling_3d_layer.cl',
Mohammed Suhail Munshi5e549fa2022-03-16 11:14:06 +0000513 'src/core/CL/cl_kernels/nhwc/pooling_3d_layer_quantized.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100514 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100515 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl',
516 'src/core/CL/cl_kernels/nhwc/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100517 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl',
518 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl',
Gunes Bayirec0113d2022-11-09 09:26:27 +0000519 'src/core/CL/cl_kernels/nhwc/transposed_convolution.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100520 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl',
521 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl',
522 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl',
523 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl'
524 ]
525
526 cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc
527
528 embed_files = [ f+"embed" for f in cl_files ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000529 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
530
531 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
532
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000533Default(generate_embed)
534if env["build"] == "embed_only":
535 Return()
536
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000537# Append version defines for semantic versioning
538arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
539 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
540 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
541
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000542# Don't allow undefined references in the libraries:
Georgios Pinitas45514032020-12-30 00:03:09 +0000543undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined'
Jakub Sujak7ab7fca2024-01-31 17:20:07 +0000544if not env['thread_sanitizer'] and not env['address_sanitizer'] and not env['undefined_sanitizer']:
Matthew Bentham0a59e692023-07-19 15:01:00 +0000545 arm_compute_env.Append(LINKFLAGS=[undefined_flag])
Jakub Sujakb5d60822024-01-28 18:30:50 +0000546
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100547arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
548
Kevin Lo7195f712022-01-07 15:46:02 +0800549if env['os'] != 'openbsd':
Pablo Tellofbbfa532023-01-26 16:24:04 +0000550 if env['os'] == 'windows':
551 arm_compute_env.Append(LIBS = [])
552 else:
553 arm_compute_env.Append(LIBS = ['dl'])
554
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100555
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200556# Load build definitions file
557with (open(Dir('#').path + '/filedefs.json')) as fd:
558 filedefs = json.load(fd)
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200559 filedefs = filedefs['cpu']['arch']
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200560
561
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100562with (open(Dir('#').path + '/filelist.json')) as fp:
563 filelist = json.load(fp)
564
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100565# Common backend files
566lib_files = filelist['common']
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100567
Nathan John Sircombed7113e42023-04-26 15:02:43 +0100568# Fixed format GEMM kernels.
569if env['fixed_format_kernels']:
570 arm_compute_env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS'])
571
Giorgio Arena232c4522022-03-03 10:09:01 +0000572# Experimental files
573# Dynamic fusion
574if env['experimental_dynamic_fusion']:
SiCong Li23882a92023-06-28 09:49:45 +0100575 lib_files += filelist['experimental']['dynamic_fusion']['common']
SiCong Li23882a92023-06-28 09:49:45 +0100576 lib_files += filelist['experimental']['dynamic_fusion']['ckw_driver']
Giorgio Arena232c4522022-03-03 10:09:01 +0000577
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100578# Logging files
579if env["logging"]:
580 lib_files += filelist['logging']
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000581
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000582# C API files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100583lib_files += filelist['c_api']['common']
584lib_files += filelist['c_api']['operators']
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100585
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100586# Scheduler infrastructure
587lib_files += filelist['scheduler']['single']
588if env['cppthreads']:
589 lib_files += filelist['scheduler']['threads']
590if env['openmp']:
591 lib_files += filelist['scheduler']['omp']
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000592
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100593# Graph files
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100594graph_files = Glob('src/graph/*.cpp')
595graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000596
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100597# Specify user-defined priority operators
Freddie Liardet487d3902021-09-21 12:36:43 +0100598custom_operators = []
599custom_types = []
600custom_layouts = []
601
Jakub Sujake86f9922023-07-05 17:30:02 +0100602use_custom_ops = env['high_priority'] or env['build_config']
Freddie Liardet487d3902021-09-21 12:36:43 +0100603
604if env['high_priority']:
605 custom_operators = filelist['high_priority']
606 custom_types = ['all']
607 custom_layouts = ['all']
608
609if env['build_config']:
610 custom_operators, custom_types, custom_layouts = read_build_config_json(env['build_config'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100611
612if env['opencl']:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100613 lib_files += filelist['c_api']['gpu']
614 lib_files += filelist['gpu']['common']
Michele Di Giorgio760c7832021-08-05 10:54:13 +0100615
Freddie Liardet487d3902021-09-21 12:36:43 +0100616 cl_operators = custom_operators if use_custom_ops else filelist['gpu']['operators'].keys()
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100617 cl_ops_to_build = resolve_operator_dependencies(filelist, cl_operators, 'gpu')
618 lib_files += get_operator_backend_files(filelist, cl_ops_to_build, 'gpu')['common']
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000619
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100620 graph_files += Glob('src/graph/backends/CL/*.cpp')
621
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200622
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100623lib_files_sve = []
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200624lib_files_sve2 = []
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200625
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100626# the variables below are used for the multi_isa builds
627# please note that the variables names without the _fp16 suffix
628# do not hold any fp16 files.
629
630misa_lib_files = lib_files
631misa_lib_files_sve = []
632misa_lib_files_sve2 = []
633misa_lib_files_neon_fp16 = []
634misa_lib_files_sve_fp16 = []
635misa_lib_files_sve2_fp16 = []
636
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100637if env['neon']:
Georgios Pinitas30271c72019-06-24 14:56:34 +0100638 # build winograd/depthwise sources for either v7a / v8a
Michael Tyler74921ee2023-04-12 17:43:17 +0100639 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/arm_gemm",
640 "src/core/NEON/kernels/convolution/common/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100641 "src/core/NEON/kernels/convolution/winograd/",
ramelg01c827e992022-04-08 03:52:28 +0100642 "src/core/NEON/kernels/arm_conv/depthwise/",
643 "src/core/NEON/kernels/arm_conv/pooling/",
ramelg018a164882022-04-07 02:42:52 +0100644 "src/core/NEON/kernels/arm_conv/",
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100645 "src/core/NEON/kernels/assembly/",
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +0100646 "arm_compute/core/NEON/kernels/assembly/",
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200647 "src/cpu/kernels/assembly/"])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000648
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100649 # Setup SIMD file list to include
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200650 simd = ['neon']
651 if env['multi_isa']:
652 simd += ['sve', 'sve2']
653 else:
654 if 'sve' in env['arch']: simd += ['sve']
655 if 'sve2' in env['arch']: simd += ['sve2']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100656
657 # Get attributes
Freddie Liardet487d3902021-09-21 12:36:43 +0100658 if(use_custom_ops):
659 attrs = get_attrs_list(env, custom_types, custom_layouts)
660 else:
661 attrs = get_attrs_list(env, env['data_type_support'], env['data_layout_support'])
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100662
Nathan John Sircombed7113e42023-04-26 15:02:43 +0100663 if env['fixed_format_kernels']:
664 attrs.append("fixed_format_kernels")
Francesco.Petrogalli@arm.com5fcf22d2022-04-05 10:31:08 +0000665
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100666 # Setup data-type and data-layout files to include
Freddie Liardet487d3902021-09-21 12:36:43 +0100667 cpu_operators = custom_operators if use_custom_ops else filelist['cpu']['operators'].keys()
668 cpu_ops_to_build = resolve_operator_dependencies(filelist, cpu_operators, 'cpu')
669
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100670 if env['multi_isa']:
671 misa_lib_files += filelist['cpu']['common']
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200672
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100673 # 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
674 attrs.remove('fp16')
675 cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200676
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100677 # Shared among ALL CPU files
678 misa_lib_files += cpu_files.get('common', [])
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200679
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100680 # Arm® Neon™ specific files
681 misa_lib_files += cpu_files.get('neon', [])
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200682
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100683 # Get all the fp16 files
684 fp16_cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, ['fp16'],False)
685
686 misa_lib_files_neon_fp16 = fp16_cpu_files.get('neon',[])
687 misa_lib_files_sve_fp16 = fp16_cpu_files.get('sve',[])
688 misa_lib_files_sve2_fp16 = fp16_cpu_files.get('sve2',[])
689
690 # SVE files only minus FP16
691 misa_lib_files_sve = cpu_files.get('sve', [])
692
693 # SVE2 files only minus FP16
694 misa_lib_files_sve2 = cpu_files.get('sve2', [])
695 else:
696 lib_files += filelist['cpu']['common']
697
698 # Non multi_isa build
699 cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
700
701 # Shared among ALL CPU files
702 lib_files += cpu_files.get('common', [])
703
704 # Arm® Neon™ specific files
705 lib_files += cpu_files.get('neon', [])
706
707 lib_files_sve = cpu_files.get('sve', [])
708
709 lib_files_sve2 = cpu_files.get('sve2', [])
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100710
711 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000712
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100713# Restrict from building graph API if a reduced operator list has been provided
Freddie Liardet487d3902021-09-21 12:36:43 +0100714if use_custom_ops:
715 print("WARNING: Graph library requires all operators to be built")
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100716 graph_files = []
717
718# Build bootcode in case of bare-metal
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100719bootcode_o = []
720if env['os'] == 'bare_metal':
721 bootcode_files = Glob('bootcode/*.s')
722 bootcode_o = build_bootcode_objs(bootcode_files)
723Export('bootcode_o')
724
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200725
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200726if (env['multi_isa']):
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100727 lib_static_objs, lib_shared_objs = build_multiisa_lib_objects()
Renato Arantes36a75da2024-01-26 17:31:18 +0000728 # STATIC library build.
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200729 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_static_objs, static=True)
730else:
731 if 'sve2' in env['arch']:
732 lib_files += lib_files_sve
733 lib_files += lib_files_sve2
734 elif 'sve' in env['arch']:
735 lib_files += lib_files_sve
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200736
Motti Gondabif76a5022021-12-21 13:19:29 +0200737 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_files, static=True)
Motti Gondabif76a5022021-12-21 13:19:29 +0200738
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100739Export('arm_compute_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100740
Motti Gondabif76a5022021-12-21 13:19:29 +0200741# SHARED library build.
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100742if env['os'] != 'bare_metal' and not env['standalone']:
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200743 if (env['multi_isa']):
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200744
745 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_shared_objs, static=False)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100746 else:
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200747 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100748
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100749 Export('arm_compute_so')
750
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100751
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000752arm_compute_graph_env = arm_compute_env.Clone()
753
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100754# Build graph libraries
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000755arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
756
Jakub Sujake86f9922023-07-05 17:30:02 +0100757arm_compute_graph_a = build_library('arm_compute_graph-static', arm_compute_graph_env, graph_files, static=True)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100758Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000759
760if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100761 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 +0000762 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100763 Export('arm_compute_graph_so')
764
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100765if env['standalone']:
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200766 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100767else:
768 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
769
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100770Default(alias)
771
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100772if env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100773 Depends([alias], generate_embed)
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100774else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100775 Depends([alias], generate_embed)