blob: 8cc734d44b62ffa83874d197cd94b645985b52c8 [file] [log] [blame]
Motti Gondabi9d9ad332022-01-23 12:42:24 +02001#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +00004# Copyright (c) 2016-2021 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"
Gunes Bayir456fb2b2021-11-04 16:14:37 +000035LIBRARY_VERSION_MAJOR = 25
Sang-Hoon Park6d0b3842020-08-14 14:48:08 +010036LIBRARY_VERSION_MINOR = 0
Georgios Pinitas35fcc432020-03-26 18:47:46 +000037LIBRARY_VERSION_PATCH = 0
38SONAME_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
52
53
54# @brief Create a list of object from a given file list.
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020055#
Motti Gondabi9d9ad332022-01-23 12:42:24 +020056# @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 Gondabi6f3a9f52021-11-09 15:47:17 +020060#
61# @return A list of objects for the corresponding architecture.
Michalis Spyrou20fca522021-06-07 14:23:57 +010062
Motti Gondabi9d9ad332022-01-23 12:42:24 +020063def build_obj_list(arch_info, sources, static=False):
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020064
Motti Gondabi9d9ad332022-01-23 12:42:24 +020065 # Clone environment
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010066 tmp_env = arm_compute_env.Clone()
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020067
Motti Gondabi9d9ad332022-01-23 12:42:24 +020068 # Append architecture spec
69 if 'cxxflags' in arch_info and len(arch_info['cxxflags']) > 0:
70 tmp_env.Append(CXXFLAGS = arch_info['cxxflags'])
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020071
Motti Gondabi9d9ad332022-01-23 12:42:24 +020072 # Build and return objects
73 if static:
74 objs = tmp_env.StaticObject(sources)
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020075 else:
Motti Gondabi9d9ad332022-01-23 12:42:24 +020076 objs = tmp_env.SharedObject(sources)
77
Motti Gondabif76a5022021-12-21 13:19:29 +020078 tmp_env.Default(objs)
79 return objs
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010080
Motti Gondabi9d9ad332022-01-23 12:42:24 +020081# @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 Spyrou20fca522021-06-07 14:23:57 +010086
Motti Gondabi9d9ad332022-01-23 12:42:24 +020087def 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 Spyrou20fca522021-06-07 14:23:57 +0100111
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100112
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100113def build_library(name, build_env, sources, static=False, libs=[]):
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000114 cloned_build_env = build_env.Clone()
Motti Gondabif76a5022021-12-21 13:19:29 +0200115 if env['os'] == 'android' and static == False:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000116 cloned_build_env["LINKFLAGS"].remove('-pie')
117 cloned_build_env["LINKFLAGS"].remove('-static-libstdc++')
118
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100119 if static:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000120 obj = cloned_build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100121 else:
122 if env['set_soname']:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000123 obj = cloned_build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100124 else:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000125 obj = cloned_build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100126
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000127 obj = install_lib(obj)
Motti Gondabif76a5022021-12-21 13:19:29 +0200128 build_env.Default(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100129 return obj
130
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100131
Georgios Pinitasf605bd22020-11-26 11:55:09 +0000132def 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 Pinitasb6af4822021-09-14 12:33:34 +0100143
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100144def 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 Pinitasf605bd22020-11-26 11:55:09 +0000156 contents = src.get_contents().decode('utf-8')
157 contents = remove_incode_comments(contents).splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100158 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:
175 include_file = found.group(1)
176 data = files_dict[include_file].file_contents
177 updated_file.extend(data)
178 else:
179 updated_file.append(line)
180 file_count += 1
181
182 # Check if all include are replaced.
183 if file_count == len(tmp_file):
184 done = True
185
186 # Update temp file
187 tmp_file = updated_file
188
189 # Append and prepend string literal identifiers and add expanded file to final list
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100190 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
191 final_files.append((file[0], entry))
192
193 # Write output files
194 for file in final_files:
195 with open(file[1].target_name.get_path(), 'w+') as out_file:
Georgios Pinitasea857272021-01-22 05:47:37 +0000196 file_to_write = "\n".join( file[1].file_contents )
197 if env['compress_kernels']:
Adnan AlSinan39aebd12021-08-06 12:44:51 +0100198 file_to_write = zlib.compress(file_to_write.encode('utf-8'), 9)
199 file_to_write = codecs.encode(file_to_write, "base64").decode('utf-8').replace("\n", "")
Georgios Pinitasea857272021-01-22 05:47:37 +0000200 file_to_write = "R\"(" + file_to_write + ")\""
201 out_file.write(file_to_write)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100202
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100203
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100204def create_version_file(target, source, env):
205# Generate string with build options library version to embed in the library:
206 try:
207 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
208 except (OSError, subprocess.CalledProcessError):
209 git_hash="unknown"
210
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100211 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
212 with open(target[0].get_path(), "w") as fd:
213 fd.write(build_info)
214
Michalis Spyrou20fca522021-06-07 14:23:57 +0100215
Freddie Liardet487d3902021-09-21 12:36:43 +0100216def get_attrs_list(env, data_types, data_layouts):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100217 attrs = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100218
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100219 # Manage data-types
Freddie Liardet487d3902021-09-21 12:36:43 +0100220 if 'all' in data_types:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100221 attrs += ['fp16', 'fp32', 'integer', 'qasymm8', 'qasymm8_signed', 'qsymm16']
222 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100223 if 'fp16' in data_types: attrs += ['fp16']
224 if 'fp32' in data_types: attrs += ['fp32']
225 if 'integer' in data_types: attrs += ['integer']
226 if 'qasymm8' in data_types: attrs += ['qasymm8']
227 if 'qasymm8_signed' in data_types: attrs += ['qasymm8_signed']
228 if 'qsymm16' in data_types: attrs += ['qsymm16']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100229 # Manage data-layouts
Freddie Liardet487d3902021-09-21 12:36:43 +0100230 if 'all' in data_layouts:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100231 attrs += ['nhwc', 'nchw']
232 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100233 if 'nhwc' in data_layouts: attrs += ['nhwc']
234 if 'nchw' in data_layouts: attrs += ['nchw']
Michalis Spyrou20fca522021-06-07 14:23:57 +0100235
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100236 # Manage execution state
Freddie Liardet487d3902021-09-21 12:36:43 +0100237 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 +0200238
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100239 return attrs
Michalis Spyrou20fca522021-06-07 14:23:57 +0100240
Michalis Spyrou20fca522021-06-07 14:23:57 +0100241
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100242def get_operator_backend_files(filelist, operators, backend='', techs=[], attrs=[]):
243 files = { "common" : [] }
Michalis Spyrou20fca522021-06-07 14:23:57 +0100244
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100245 # Early return if filelist is empty
246 if backend not in filelist:
247 return files
Michalis Spyrou20fca522021-06-07 14:23:57 +0100248
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100249 # Iterate over operators and create the file lists to compiler
250 for operator in operators:
251 if operator in filelist[backend]['operators']:
252 files['common'] += filelist[backend]['operators'][operator]["files"]["common"]
253 for tech in techs:
254 if tech in filelist[backend]['operators'][operator]["files"]:
255 # Add tech as a key to dictionary if not there
256 if tech not in files:
257 files[tech] = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100258
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100259 # Add tech files to the tech file list
260 tech_files = filelist[backend]['operators'][operator]["files"][tech]
261 files[tech] += tech_files.get('common', [])
262 for attr in attrs:
263 files[tech] += tech_files.get(attr, [])
264
265 # Remove duplicates if they exist
266 return {k: list(set(v)) for k,v in files.items()}
267
268def collect_operators(filelist, operators, backend=''):
269 ops = set()
270 for operator in operators:
271 if operator in filelist[backend]['operators']:
272 ops.add(operator)
273 if 'deps' in filelist[backend]['operators'][operator]:
274 ops.update(filelist[backend]['operators'][operator]['deps'])
275 else:
276 print("Operator {0} is unsupported on {1} backend!".format(operator, backend))
277
278 return ops
279
280
281def resolve_operator_dependencies(filelist, operators, backend=''):
282 resolved_operators = collect_operators(filelist, operators, backend)
283
284 are_ops_resolved = False
285 while not are_ops_resolved:
286 resolution_pass = collect_operators(filelist, resolved_operators, backend)
287 if len(resolution_pass) != len(resolved_operators):
288 resolved_operators.update(resolution_pass)
289 else:
290 are_ops_resolved = True
291
292 return resolved_operators
293
Freddie Liardet487d3902021-09-21 12:36:43 +0100294def read_build_config_json(build_config):
295 build_config_contents = {}
296 custom_operators = []
297 custom_types = []
298 custom_layouts = []
299 if os.path.isfile(build_config):
300 with open(build_config) as f:
301 try:
302 build_config_contents = json.load(f)
303 except:
304 print("Warning: Build configuration file is of invalid JSON format!")
305 else:
306 try:
307 build_config_contents = json.loads(build_config)
308 except:
309 print("Warning: Build configuration string is of invalid JSON format!")
310 if build_config_contents:
311 custom_operators = build_config_contents.get("operators", [])
312 custom_types = build_config_contents.get("data_types", [])
313 custom_layouts = build_config_contents.get("data_layouts", [])
314 return custom_operators, custom_types, custom_layouts
Michalis Spyrou20fca522021-06-07 14:23:57 +0100315
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100316arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100317version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
318arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000319
Kevin Lo7195f712022-01-07 15:46:02 +0800320default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos', 'openbsd'] else 'clang++'
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100321cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
322
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000323# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100324generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000325if env['opencl'] and env['embed_kernels']:
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100326
327 # Header files
328 cl_helper_files = [ 'src/core/CL/cl_kernels/activation_float_helpers.h',
329 'src/core/CL/cl_kernels/activation_quant_helpers.h',
330 'src/core/CL/cl_kernels/gemm_helpers.h',
331 'src/core/CL/cl_kernels/helpers_asymm.h',
332 'src/core/CL/cl_kernels/helpers.h',
333 'src/core/CL/cl_kernels/load_store_utility.h',
334 'src/core/CL/cl_kernels/repeat.h',
335 'src/core/CL/cl_kernels/tile_helpers.h',
336 'src/core/CL/cl_kernels/types.h',
SiCongLi1af54162021-10-06 15:25:57 +0100337 'src/core/CL/cl_kernels/warp_helpers.h',
338 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/fp_post_ops_act_eltwise_op_act.h',
339 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/fp_mixed_precision_helpers.h',
340 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/fp_elementwise_op_helpers.h',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100341 ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000342
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100343 # Common kernels
344 cl_files_common = ['src/core/CL/cl_kernels/common/activation_layer.cl',
345 'src/core/CL/cl_kernels/common/activation_layer_quant.cl',
346 'src/core/CL/cl_kernels/common/arg_min_max.cl',
347 'src/core/CL/cl_kernels/common/batchnormalization_layer.cl',
348 'src/core/CL/cl_kernels/common/bounding_box_transform.cl',
349 'src/core/CL/cl_kernels/common/bounding_box_transform_quantized.cl',
350 'src/core/CL/cl_kernels/common/bitwise_op.cl',
351 'src/core/CL/cl_kernels/common/cast.cl',
352 'src/core/CL/cl_kernels/common/comparisons.cl',
353 'src/core/CL/cl_kernels/common/concatenate.cl',
354 'src/core/CL/cl_kernels/common/col2im.cl',
355 'src/core/CL/cl_kernels/common/convert_fc_weights.cl',
356 'src/core/CL/cl_kernels/common/copy_tensor.cl',
357 'src/core/CL/cl_kernels/common/crop_tensor.cl',
358 'src/core/CL/cl_kernels/common/deconvolution_layer.cl',
359 'src/core/CL/cl_kernels/common/dequantization_layer.cl',
360 'src/core/CL/cl_kernels/common/elementwise_operation.cl',
361 'src/core/CL/cl_kernels/common/elementwise_operation_quantized.cl',
362 'src/core/CL/cl_kernels/common/elementwise_unary.cl',
363 'src/core/CL/cl_kernels/common/fft_digit_reverse.cl',
364 'src/core/CL/cl_kernels/common/fft.cl',
365 'src/core/CL/cl_kernels/common/fft_scale.cl',
366 'src/core/CL/cl_kernels/common/fill_border.cl',
367 'src/core/CL/cl_kernels/common/floor.cl',
368 'src/core/CL/cl_kernels/common/gather.cl',
369 'src/core/CL/cl_kernels/common/gemm.cl',
ramelg019cca5922021-11-11 10:05:00 +0000370 'src/core/CL/cl_kernels/common/gemm_utils.cl',
SiCongLiafa19722021-10-24 19:12:33 +0100371 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/gemm_mm_native.cl',
SiCongLi1af54162021-10-06 15:25:57 +0100372 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/gemm_mm_reshaped.cl',
Ramy Elgammal451c3092022-02-01 23:01:27 +0000373 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/gemm_mm_reshaped_only_rhs.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100374 'src/core/CL/cl_kernels/common/gemv.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100375 'src/core/CL/cl_kernels/common/gemmlowp.cl',
376 'src/core/CL/cl_kernels/common/generate_proposals.cl',
377 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl',
378 'src/core/CL/cl_kernels/common/instance_normalization.cl',
379 'src/core/CL/cl_kernels/common/l2_normalize.cl',
380 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl',
381 'src/core/CL/cl_kernels/common/unpooling_layer.cl',
382 'src/core/CL/cl_kernels/common/memset.cl',
383 'src/core/CL/cl_kernels/common/nonmax.cl',
384 'src/core/CL/cl_kernels/common/minmax_layer.cl',
385 'src/core/CL/cl_kernels/common/pad_layer.cl',
386 'src/core/CL/cl_kernels/common/permute.cl',
387 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl',
388 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl',
389 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl',
390 'src/core/CL/cl_kernels/common/quantization_layer.cl',
391 'src/core/CL/cl_kernels/common/range.cl',
392 'src/core/CL/cl_kernels/common/reduction_operation.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100393 'src/core/CL/cl_kernels/common/reshape_layer.cl',
394 'src/core/CL/cl_kernels/common/convolution_layer.cl',
395 'src/core/CL/cl_kernels/common/reverse.cl',
396 'src/core/CL/cl_kernels/common/roi_align_layer.cl',
397 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl',
398 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl',
399 'src/core/CL/cl_kernels/common/select.cl',
400 'src/core/CL/cl_kernels/common/softmax_layer.cl',
401 'src/core/CL/cl_kernels/common/softmax_layer_quantized.cl',
402 'src/core/CL/cl_kernels/common/stack_layer.cl',
403 'src/core/CL/cl_kernels/common/slice_ops.cl',
404 'src/core/CL/cl_kernels/common/tile.cl',
405 'src/core/CL/cl_kernels/common/transpose.cl'
406 ]
407
408 # NCHW kernels
409 cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl',
410 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl',
411 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl',
412 'src/core/CL/cl_kernels/nchw/depth_to_space.cl',
Adnan AlSinan30124352021-12-02 19:12:20 +0000413 'src/core/CL/cl_kernels/nchw/direct_convolution.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100414 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl',
415 'src/core/CL/cl_kernels/nchw/im2col.cl',
416 'src/core/CL/cl_kernels/nchw/normalization_layer.cl',
417 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl',
418 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl',
419 'src/core/CL/cl_kernels/nchw/pooling_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100420 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl',
421 'src/core/CL/cl_kernels/nchw/remap.cl',
422 'src/core/CL/cl_kernels/nchw/reorg_layer.cl',
423 'src/core/CL/cl_kernels/nchw/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100424 'src/core/CL/cl_kernels/nchw/space_to_batch.cl',
425 'src/core/CL/cl_kernels/nchw/space_to_depth.cl',
426 'src/core/CL/cl_kernels/nchw/upsample_layer.cl',
427 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl',
428 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl',
429 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl'
430 ]
431
432 # NHWC kernels
433 cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl',
434 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl',
435 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl',
436 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl',
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100437 'src/core/CL/cl_kernels/nhwc/direct_convolution3d.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100438 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl',
439 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl',
440 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl',
441 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl',
442 'src/core/CL/cl_kernels/nhwc/im2col.cl',
443 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl',
444 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl',
445 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl',
446 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl',
447 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl',
448 'src/core/CL/cl_kernels/nhwc/remap.cl',
449 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl',
450 'src/core/CL/cl_kernels/nhwc/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100451 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl',
452 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl',
453 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl',
454 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl',
455 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl',
456 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl'
457 ]
458
459 cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc
460
461 embed_files = [ f+"embed" for f in cl_files ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000462 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
463
464 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
465
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000466Default(generate_embed)
467if env["build"] == "embed_only":
468 Return()
469
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000470# Append version defines for semantic versioning
471arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
472 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
473 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
474
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000475# Don't allow undefined references in the libraries:
Georgios Pinitas45514032020-12-30 00:03:09 +0000476undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined'
477arm_compute_env.Append(LINKFLAGS=[undefined_flag])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100478arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
479
Kevin Lo7195f712022-01-07 15:46:02 +0800480if env['os'] != 'openbsd':
481 arm_compute_env.Append(LIBS = ['dl'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100482
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200483# Load build definitions file
484with (open(Dir('#').path + '/filedefs.json')) as fd:
485 filedefs = json.load(fd)
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200486 filedefs = filedefs['cpu']['arch']
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200487
488
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100489with (open(Dir('#').path + '/filelist.json')) as fp:
490 filelist = json.load(fp)
491
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100492# Common backend files
493lib_files = filelist['common']
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100494
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100495# Logging files
496if env["logging"]:
497 lib_files += filelist['logging']
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000498
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000499# C API files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100500lib_files += filelist['c_api']['common']
501lib_files += filelist['c_api']['operators']
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100502
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100503# Scheduler infrastructure
504lib_files += filelist['scheduler']['single']
505if env['cppthreads']:
506 lib_files += filelist['scheduler']['threads']
507if env['openmp']:
508 lib_files += filelist['scheduler']['omp']
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000509
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100510# Graph files
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100511graph_files = Glob('src/graph/*.cpp')
512graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000513
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100514# Specify user-defined priority operators
Freddie Liardet487d3902021-09-21 12:36:43 +0100515custom_operators = []
516custom_types = []
517custom_layouts = []
518
519use_custom_ops = env['high_priority'] or env['build_config'];
520
521if env['high_priority']:
522 custom_operators = filelist['high_priority']
523 custom_types = ['all']
524 custom_layouts = ['all']
525
526if env['build_config']:
527 custom_operators, custom_types, custom_layouts = read_build_config_json(env['build_config'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100528
529if env['opencl']:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100530 lib_files += filelist['c_api']['gpu']
531 lib_files += filelist['gpu']['common']
Michele Di Giorgio760c7832021-08-05 10:54:13 +0100532
Freddie Liardet487d3902021-09-21 12:36:43 +0100533 cl_operators = custom_operators if use_custom_ops else filelist['gpu']['operators'].keys()
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100534 cl_ops_to_build = resolve_operator_dependencies(filelist, cl_operators, 'gpu')
535 lib_files += get_operator_backend_files(filelist, cl_ops_to_build, 'gpu')['common']
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000536
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100537 graph_files += Glob('src/graph/backends/CL/*.cpp')
538
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200539
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100540lib_files_sve = []
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200541lib_files_sve2 = []
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200542
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100543if env['neon']:
Georgios Pinitas30271c72019-06-24 14:56:34 +0100544 # build winograd/depthwise sources for either v7a / v8a
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100545 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100546 "src/core/NEON/kernels/convolution/winograd/",
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100547 "src/core/NEON/kernels/convolution/depthwise/",
548 "src/core/NEON/kernels/assembly/",
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +0100549 "arm_compute/core/NEON/kernels/assembly/",
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200550 "src/cpu/kernels/assembly/"])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000551
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100552 lib_files += filelist['cpu']['common']
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100553
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100554 # Setup SIMD file list to include
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200555 simd = ['neon']
556 if env['multi_isa']:
557 simd += ['sve', 'sve2']
558 else:
559 if 'sve' in env['arch']: simd += ['sve']
560 if 'sve2' in env['arch']: simd += ['sve2']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100561
562 # Get attributes
Freddie Liardet487d3902021-09-21 12:36:43 +0100563 if(use_custom_ops):
564 attrs = get_attrs_list(env, custom_types, custom_layouts)
565 else:
566 attrs = get_attrs_list(env, env['data_type_support'], env['data_layout_support'])
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100567
568 # Setup data-type and data-layout files to include
Freddie Liardet487d3902021-09-21 12:36:43 +0100569 cpu_operators = custom_operators if use_custom_ops else filelist['cpu']['operators'].keys()
570 cpu_ops_to_build = resolve_operator_dependencies(filelist, cpu_operators, 'cpu')
571
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100572 cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200573
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200574 # Shared among ALL CPU files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100575 lib_files += cpu_files.get('common', [])
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200576
577 # Arm® Neon™ specific files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100578 lib_files += cpu_files.get('neon', [])
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200579
580 # SVE files only
581 lib_files_sve = cpu_files.get('sve', [])
582
583 # SVE2 files only
584 lib_files_sve2 = cpu_files.get('sve2', [])
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100585
586 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000587
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100588# Restrict from building graph API if a reduced operator list has been provided
Freddie Liardet487d3902021-09-21 12:36:43 +0100589if use_custom_ops:
590 print("WARNING: Graph library requires all operators to be built")
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100591 graph_files = []
592
593# Build bootcode in case of bare-metal
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100594bootcode_o = []
595if env['os'] == 'bare_metal':
596 bootcode_files = Glob('bootcode/*.s')
597 bootcode_o = build_bootcode_objs(bootcode_files)
598Export('bootcode_o')
599
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200600
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200601if (env['multi_isa']):
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200602 lib_static_objs, lib_shared_objs = build_lib_objects()
603
604
605# STATIC library build.
606if (env['multi_isa']):
607 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_static_objs, static=True)
608else:
609 if 'sve2' in env['arch']:
610 lib_files += lib_files_sve
611 lib_files += lib_files_sve2
612 elif 'sve' in env['arch']:
613 lib_files += lib_files_sve
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200614
Motti Gondabif76a5022021-12-21 13:19:29 +0200615 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_files, static=True)
Motti Gondabif76a5022021-12-21 13:19:29 +0200616
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100617Export('arm_compute_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100618
Motti Gondabif76a5022021-12-21 13:19:29 +0200619# SHARED library build.
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100620if env['os'] != 'bare_metal' and not env['standalone']:
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200621 if (env['multi_isa']):
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200622
623 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_shared_objs, static=False)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100624 else:
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200625 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100626
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100627 Export('arm_compute_so')
628
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100629# Generate dummy core lib for backwards compatibility
Pablo Marquez Tello48f26152021-11-18 10:15:23 +0000630if env['os'] == 'macos':
631 # macos static library archiver fails if given an empty list of files
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200632 arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, lib_files, static=True)
Pablo Marquez Tello48f26152021-11-18 10:15:23 +0000633else:
634 arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [], static=True)
635
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100636Export('arm_compute_core_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100637
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100638if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100639 arm_compute_core_a_so = build_library('arm_compute_core', arm_compute_env, [], static=False)
640 Export('arm_compute_core_a_so')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100641
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000642arm_compute_graph_env = arm_compute_env.Clone()
643
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100644# Build graph libraries
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000645arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
646
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200647arm_compute_graph_a = build_library('arm_compute_graph-static', arm_compute_graph_env, graph_files, static=True, libs = [ arm_compute_a ])
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100648Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000649
650if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100651 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 +0000652 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100653 Export('arm_compute_graph_so')
654
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100655if env['standalone']:
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200656 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100657else:
658 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
659
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100660Default(alias)
661
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100662if env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100663 Depends([alias], generate_embed)
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100664else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100665 Depends([alias], generate_embed)