blob: afff4e58bceda6e660fb4e19210be020ec802624 [file] [log] [blame]
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +00001# Copyright (c) 2016-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002#
3# SPDX-License-Identifier: MIT
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to
7# deal in the Software without restriction, including without limitation the
8# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9# sell copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020022
Anthony Barbier6ff3b192017-09-04 18:44:23 +010023import collections
24import os.path
25import re
26import subprocess
Georgios Pinitasea857272021-01-22 05:47:37 +000027import zlib
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010028import json
Adnan AlSinan39aebd12021-08-06 12:44:51 +010029import codecs
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
31VERSION = "v0.0-unreleased"
Gunes Bayir456fb2b2021-11-04 16:14:37 +000032LIBRARY_VERSION_MAJOR = 25
Sang-Hoon Park6d0b3842020-08-14 14:48:08 +010033LIBRARY_VERSION_MINOR = 0
Georgios Pinitas35fcc432020-03-26 18:47:46 +000034LIBRARY_VERSION_PATCH = 0
35SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036
37Import('env')
38Import('vars')
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000039Import('install_lib')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040
Michalis Spyrou748a7c82019-10-07 13:00:44 +010041def build_bootcode_objs(sources):
Michalis Spyrou748a7c82019-10-07 13:00:44 +010042 arm_compute_env.Append(ASFLAGS = "-I bootcode/")
43 obj = arm_compute_env.Object(sources)
44 obj = install_lib(obj)
45 Default(obj)
46 return obj
47
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020048# @brief Generates SVE/SVE2 shared object files for a specific V8 architechture.
49#
50# @param sources The target source files
51# @param arch_info A Tuple represents the architecture info
52# such as the compiler flags and defines.
53#
54# @return A list of objects for the corresponding architecture.
55def build_multi_isa_objs(sources, arch_v8_info):
Michalis Spyrou20fca522021-06-07 14:23:57 +010056
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020057 arch_v8 = arch_v8_info[0]
58
59 # Create a temp environment
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010060 tmp_env = arm_compute_env.Clone()
Motti Gondabi6f3a9f52021-11-09 15:47:17 +020061
62 if 'cxxflags' in arch_v8_info[1] and len(arch_v8_info[1]['cxxflags']) > 0:
63 tmp_env.Append(CXXFLAGS = arch_v8_info[1]['cxxflags'])
64 if 'cppdefines' in arch_v8_info[1] and len(arch_v8_info[1]['cppdefines']) > 0:
65 tmp_env.Append(CPPDEFINES = arch_v8_info[1]['cppdefines'])
66
67 if 'sve' in arch_v8:
68 # Toggle SVE/SVE2 specific extensions
69 tmp_env.Append(CPPDEFINES = ['ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE'])
70 if 'sve2' in arch_v8:
71 tmp_env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2'])
72 else:
73 # FIXME: The NEON flags should be always defined for CPU.
74 # however, build fails when SVE/SVE2 & NEON flags
75 # defined together.
76 tmp_env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON'])
77
78 # we must differentiate the file object names
79 # as we accumulate the set.
80 obj = []
81 for src in sources:
82 obj += tmp_env.SharedObject(target='{}-{}'.format(src, arch_v8), source=src)
83
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010084 Default(obj)
85 return obj
86
Michalis Spyrou20fca522021-06-07 14:23:57 +010087
Georgios Pinitasb6af4822021-09-14 12:33:34 +010088def build_objs(sources):
Michalis Spyrou20fca522021-06-07 14:23:57 +010089 obj = arm_compute_env.SharedObject(sources)
Michalis Spyrou20fca522021-06-07 14:23:57 +010090 Default(obj)
91 return obj
92
Georgios Pinitasb6af4822021-09-14 12:33:34 +010093
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010094def build_library(name, build_env, sources, static=False, libs=[]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010095 if static:
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010096 obj = build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010097 else:
98 if env['set_soname']:
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010099 obj = build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100 else:
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100101 obj = build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100102
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000103 obj = install_lib(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100104 Default(obj)
105 return obj
106
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100107
Georgios Pinitasf605bd22020-11-26 11:55:09 +0000108def remove_incode_comments(code):
109 def replace_with_empty(match):
110 s = match.group(0)
111 if s.startswith('/'):
112 return " "
113 else:
114 return s
115
116 comment_regex = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
117 return re.sub(comment_regex, replace_with_empty, code)
118
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100119
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100120def resolve_includes(target, source, env):
121 # File collection
122 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
123
124 # Include pattern
125 pattern = re.compile("#include \"(.*)\"")
126
127 # Get file contents
128 files = []
129 for i in range(len(source)):
130 src = source[i]
131 dst = target[i]
Georgios Pinitasf605bd22020-11-26 11:55:09 +0000132 contents = src.get_contents().decode('utf-8')
133 contents = remove_incode_comments(contents).splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134 entry = FileEntry(target_name=dst, file_contents=contents)
135 files.append((os.path.basename(src.get_path()),entry))
136
137 # Create dictionary of tupled list
138 files_dict = dict(files)
139
140 # Check for includes (can only be files in the same folder)
141 final_files = []
142 for file in files:
143 done = False
144 tmp_file = file[1].file_contents
145 while not done:
146 file_count = 0
147 updated_file = []
148 for line in tmp_file:
149 found = pattern.search(line)
150 if found:
151 include_file = found.group(1)
152 data = files_dict[include_file].file_contents
153 updated_file.extend(data)
154 else:
155 updated_file.append(line)
156 file_count += 1
157
158 # Check if all include are replaced.
159 if file_count == len(tmp_file):
160 done = True
161
162 # Update temp file
163 tmp_file = updated_file
164
165 # Append and prepend string literal identifiers and add expanded file to final list
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100166 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
167 final_files.append((file[0], entry))
168
169 # Write output files
170 for file in final_files:
171 with open(file[1].target_name.get_path(), 'w+') as out_file:
Georgios Pinitasea857272021-01-22 05:47:37 +0000172 file_to_write = "\n".join( file[1].file_contents )
173 if env['compress_kernels']:
Adnan AlSinan39aebd12021-08-06 12:44:51 +0100174 file_to_write = zlib.compress(file_to_write.encode('utf-8'), 9)
175 file_to_write = codecs.encode(file_to_write, "base64").decode('utf-8').replace("\n", "")
Georgios Pinitasea857272021-01-22 05:47:37 +0000176 file_to_write = "R\"(" + file_to_write + ")\""
177 out_file.write(file_to_write)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100178
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100179
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100180def create_version_file(target, source, env):
181# Generate string with build options library version to embed in the library:
182 try:
183 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
184 except (OSError, subprocess.CalledProcessError):
185 git_hash="unknown"
186
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
188 with open(target[0].get_path(), "w") as fd:
189 fd.write(build_info)
190
Michalis Spyrou20fca522021-06-07 14:23:57 +0100191
Freddie Liardet487d3902021-09-21 12:36:43 +0100192def get_attrs_list(env, data_types, data_layouts):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100193 attrs = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100194
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100195 # Manage data-types
Freddie Liardet487d3902021-09-21 12:36:43 +0100196 if 'all' in data_types:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100197 attrs += ['fp16', 'fp32', 'integer', 'qasymm8', 'qasymm8_signed', 'qsymm16']
198 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100199 if 'fp16' in data_types: attrs += ['fp16']
200 if 'fp32' in data_types: attrs += ['fp32']
201 if 'integer' in data_types: attrs += ['integer']
202 if 'qasymm8' in data_types: attrs += ['qasymm8']
203 if 'qasymm8_signed' in data_types: attrs += ['qasymm8_signed']
204 if 'qsymm16' in data_types: attrs += ['qsymm16']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100205 # Manage data-layouts
Freddie Liardet487d3902021-09-21 12:36:43 +0100206 if 'all' in data_layouts:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100207 attrs += ['nhwc', 'nchw']
208 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100209 if 'nhwc' in data_layouts: attrs += ['nhwc']
210 if 'nchw' in data_layouts: attrs += ['nchw']
Michalis Spyrou20fca522021-06-07 14:23:57 +0100211
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100212 # Manage execution state
Freddie Liardet487d3902021-09-21 12:36:43 +0100213 attrs += ['estate32' if (env['estate'] == 'auto' and 'v7a' in env['arch']) or '32' in env['estate'] else 'estate64']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100214 return attrs
Michalis Spyrou20fca522021-06-07 14:23:57 +0100215
Michalis Spyrou20fca522021-06-07 14:23:57 +0100216
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100217def get_operator_backend_files(filelist, operators, backend='', techs=[], attrs=[]):
218 files = { "common" : [] }
Michalis Spyrou20fca522021-06-07 14:23:57 +0100219
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100220 # Early return if filelist is empty
221 if backend not in filelist:
222 return files
Michalis Spyrou20fca522021-06-07 14:23:57 +0100223
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100224 # Iterate over operators and create the file lists to compiler
225 for operator in operators:
226 if operator in filelist[backend]['operators']:
227 files['common'] += filelist[backend]['operators'][operator]["files"]["common"]
228 for tech in techs:
229 if tech in filelist[backend]['operators'][operator]["files"]:
230 # Add tech as a key to dictionary if not there
231 if tech not in files:
232 files[tech] = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100233
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100234 # Add tech files to the tech file list
235 tech_files = filelist[backend]['operators'][operator]["files"][tech]
236 files[tech] += tech_files.get('common', [])
237 for attr in attrs:
238 files[tech] += tech_files.get(attr, [])
239
240 # Remove duplicates if they exist
241 return {k: list(set(v)) for k,v in files.items()}
242
243def collect_operators(filelist, operators, backend=''):
244 ops = set()
245 for operator in operators:
246 if operator in filelist[backend]['operators']:
247 ops.add(operator)
248 if 'deps' in filelist[backend]['operators'][operator]:
249 ops.update(filelist[backend]['operators'][operator]['deps'])
250 else:
251 print("Operator {0} is unsupported on {1} backend!".format(operator, backend))
252
253 return ops
254
255
256def resolve_operator_dependencies(filelist, operators, backend=''):
257 resolved_operators = collect_operators(filelist, operators, backend)
258
259 are_ops_resolved = False
260 while not are_ops_resolved:
261 resolution_pass = collect_operators(filelist, resolved_operators, backend)
262 if len(resolution_pass) != len(resolved_operators):
263 resolved_operators.update(resolution_pass)
264 else:
265 are_ops_resolved = True
266
267 return resolved_operators
268
Freddie Liardet487d3902021-09-21 12:36:43 +0100269def read_build_config_json(build_config):
270 build_config_contents = {}
271 custom_operators = []
272 custom_types = []
273 custom_layouts = []
274 if os.path.isfile(build_config):
275 with open(build_config) as f:
276 try:
277 build_config_contents = json.load(f)
278 except:
279 print("Warning: Build configuration file is of invalid JSON format!")
280 else:
281 try:
282 build_config_contents = json.loads(build_config)
283 except:
284 print("Warning: Build configuration string is of invalid JSON format!")
285 if build_config_contents:
286 custom_operators = build_config_contents.get("operators", [])
287 custom_types = build_config_contents.get("data_types", [])
288 custom_layouts = build_config_contents.get("data_layouts", [])
289 return custom_operators, custom_types, custom_layouts
Michalis Spyrou20fca522021-06-07 14:23:57 +0100290
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100291arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100292version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
293arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000294
Georgios Pinitas45514032020-12-30 00:03:09 +0000295default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++'
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100296cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
297
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000298# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100299generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000300if env['opencl'] and env['embed_kernels']:
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100301
302 # Header files
303 cl_helper_files = [ 'src/core/CL/cl_kernels/activation_float_helpers.h',
304 'src/core/CL/cl_kernels/activation_quant_helpers.h',
305 'src/core/CL/cl_kernels/gemm_helpers.h',
306 'src/core/CL/cl_kernels/helpers_asymm.h',
307 'src/core/CL/cl_kernels/helpers.h',
308 'src/core/CL/cl_kernels/load_store_utility.h',
309 'src/core/CL/cl_kernels/repeat.h',
310 'src/core/CL/cl_kernels/tile_helpers.h',
311 'src/core/CL/cl_kernels/types.h',
SiCongLi1af54162021-10-06 15:25:57 +0100312 'src/core/CL/cl_kernels/warp_helpers.h',
313 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/fp_post_ops_act_eltwise_op_act.h',
314 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/fp_mixed_precision_helpers.h',
315 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/fp_elementwise_op_helpers.h',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100316 ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000317
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100318 # Common kernels
319 cl_files_common = ['src/core/CL/cl_kernels/common/activation_layer.cl',
320 'src/core/CL/cl_kernels/common/activation_layer_quant.cl',
321 'src/core/CL/cl_kernels/common/arg_min_max.cl',
322 'src/core/CL/cl_kernels/common/batchnormalization_layer.cl',
323 'src/core/CL/cl_kernels/common/bounding_box_transform.cl',
324 'src/core/CL/cl_kernels/common/bounding_box_transform_quantized.cl',
325 'src/core/CL/cl_kernels/common/bitwise_op.cl',
326 'src/core/CL/cl_kernels/common/cast.cl',
327 'src/core/CL/cl_kernels/common/comparisons.cl',
328 'src/core/CL/cl_kernels/common/concatenate.cl',
329 'src/core/CL/cl_kernels/common/col2im.cl',
330 'src/core/CL/cl_kernels/common/convert_fc_weights.cl',
331 'src/core/CL/cl_kernels/common/copy_tensor.cl',
332 'src/core/CL/cl_kernels/common/crop_tensor.cl',
333 'src/core/CL/cl_kernels/common/deconvolution_layer.cl',
334 'src/core/CL/cl_kernels/common/dequantization_layer.cl',
335 'src/core/CL/cl_kernels/common/elementwise_operation.cl',
336 'src/core/CL/cl_kernels/common/elementwise_operation_quantized.cl',
337 'src/core/CL/cl_kernels/common/elementwise_unary.cl',
338 'src/core/CL/cl_kernels/common/fft_digit_reverse.cl',
339 'src/core/CL/cl_kernels/common/fft.cl',
340 'src/core/CL/cl_kernels/common/fft_scale.cl',
341 'src/core/CL/cl_kernels/common/fill_border.cl',
342 'src/core/CL/cl_kernels/common/floor.cl',
343 'src/core/CL/cl_kernels/common/gather.cl',
344 'src/core/CL/cl_kernels/common/gemm.cl',
ramelg019cca5922021-11-11 10:05:00 +0000345 'src/core/CL/cl_kernels/common/gemm_utils.cl',
SiCongLiafa19722021-10-24 19:12:33 +0100346 '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 +0100347 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/gemm_mm_reshaped.cl',
SiCongLiafa19722021-10-24 19:12:33 +0100348 '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 +0100349 'src/core/CL/cl_kernels/common/gemv.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100350 'src/core/CL/cl_kernels/common/gemmlowp.cl',
351 'src/core/CL/cl_kernels/common/generate_proposals.cl',
352 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl',
353 'src/core/CL/cl_kernels/common/instance_normalization.cl',
354 'src/core/CL/cl_kernels/common/l2_normalize.cl',
355 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl',
356 'src/core/CL/cl_kernels/common/unpooling_layer.cl',
357 'src/core/CL/cl_kernels/common/memset.cl',
358 'src/core/CL/cl_kernels/common/nonmax.cl',
359 'src/core/CL/cl_kernels/common/minmax_layer.cl',
360 'src/core/CL/cl_kernels/common/pad_layer.cl',
361 'src/core/CL/cl_kernels/common/permute.cl',
362 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl',
363 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl',
364 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl',
365 'src/core/CL/cl_kernels/common/quantization_layer.cl',
366 'src/core/CL/cl_kernels/common/range.cl',
367 'src/core/CL/cl_kernels/common/reduction_operation.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100368 'src/core/CL/cl_kernels/common/reshape_layer.cl',
369 'src/core/CL/cl_kernels/common/convolution_layer.cl',
370 'src/core/CL/cl_kernels/common/reverse.cl',
371 'src/core/CL/cl_kernels/common/roi_align_layer.cl',
372 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl',
373 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl',
374 'src/core/CL/cl_kernels/common/select.cl',
375 'src/core/CL/cl_kernels/common/softmax_layer.cl',
376 'src/core/CL/cl_kernels/common/softmax_layer_quantized.cl',
377 'src/core/CL/cl_kernels/common/stack_layer.cl',
378 'src/core/CL/cl_kernels/common/slice_ops.cl',
379 'src/core/CL/cl_kernels/common/tile.cl',
380 'src/core/CL/cl_kernels/common/transpose.cl'
381 ]
382
383 # NCHW kernels
384 cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl',
385 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl',
386 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl',
387 'src/core/CL/cl_kernels/nchw/depth_to_space.cl',
Adnan AlSinan30124352021-12-02 19:12:20 +0000388 'src/core/CL/cl_kernels/nchw/direct_convolution.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100389 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl',
390 'src/core/CL/cl_kernels/nchw/im2col.cl',
391 'src/core/CL/cl_kernels/nchw/normalization_layer.cl',
392 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl',
393 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl',
394 'src/core/CL/cl_kernels/nchw/pooling_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100395 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl',
396 'src/core/CL/cl_kernels/nchw/remap.cl',
397 'src/core/CL/cl_kernels/nchw/reorg_layer.cl',
398 'src/core/CL/cl_kernels/nchw/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100399 'src/core/CL/cl_kernels/nchw/space_to_batch.cl',
400 'src/core/CL/cl_kernels/nchw/space_to_depth.cl',
401 'src/core/CL/cl_kernels/nchw/upsample_layer.cl',
402 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl',
403 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl',
404 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl'
405 ]
406
407 # NHWC kernels
408 cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl',
409 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl',
410 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl',
411 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl',
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100412 'src/core/CL/cl_kernels/nhwc/direct_convolution3d.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100413 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl',
414 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl',
415 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl',
416 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl',
417 'src/core/CL/cl_kernels/nhwc/im2col.cl',
418 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl',
419 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl',
420 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl',
421 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl',
422 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl',
423 'src/core/CL/cl_kernels/nhwc/remap.cl',
424 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl',
425 'src/core/CL/cl_kernels/nhwc/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100426 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl',
427 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl',
428 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl',
429 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl',
430 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl',
431 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl'
432 ]
433
434 cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc
435
436 embed_files = [ f+"embed" for f in cl_files ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000437 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
438
439 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
440
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000441Default(generate_embed)
442if env["build"] == "embed_only":
443 Return()
444
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000445# Append version defines for semantic versioning
446arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
447 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
448 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
449
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000450# Don't allow undefined references in the libraries:
Georgios Pinitas45514032020-12-30 00:03:09 +0000451undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined'
452arm_compute_env.Append(LINKFLAGS=[undefined_flag])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100453arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
454
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100455arm_compute_env.Append(LIBS = ['dl'])
456
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200457# Load build definitions file
458with (open(Dir('#').path + '/filedefs.json')) as fd:
459 filedefs = json.load(fd)
460
461
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100462with (open(Dir('#').path + '/filelist.json')) as fp:
463 filelist = json.load(fp)
464
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100465# Common backend files
466lib_files = filelist['common']
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100467
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100468# Logging files
469if env["logging"]:
470 lib_files += filelist['logging']
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000471
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000472# C API files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100473lib_files += filelist['c_api']['common']
474lib_files += filelist['c_api']['operators']
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100475
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100476# Scheduler infrastructure
477lib_files += filelist['scheduler']['single']
478if env['cppthreads']:
479 lib_files += filelist['scheduler']['threads']
480if env['openmp']:
481 lib_files += filelist['scheduler']['omp']
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000482
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100483# Graph files
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100484graph_files = Glob('src/graph/*.cpp')
485graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000486
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100487# Specify user-defined priority operators
Freddie Liardet487d3902021-09-21 12:36:43 +0100488custom_operators = []
489custom_types = []
490custom_layouts = []
491
492use_custom_ops = env['high_priority'] or env['build_config'];
493
494if env['high_priority']:
495 custom_operators = filelist['high_priority']
496 custom_types = ['all']
497 custom_layouts = ['all']
498
499if env['build_config']:
500 custom_operators, custom_types, custom_layouts = read_build_config_json(env['build_config'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100501
502if env['opencl']:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100503 lib_files += filelist['c_api']['gpu']
504 lib_files += filelist['gpu']['common']
Michele Di Giorgio760c7832021-08-05 10:54:13 +0100505
Freddie Liardet487d3902021-09-21 12:36:43 +0100506 cl_operators = custom_operators if use_custom_ops else filelist['gpu']['operators'].keys()
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100507 cl_ops_to_build = resolve_operator_dependencies(filelist, cl_operators, 'gpu')
508 lib_files += get_operator_backend_files(filelist, cl_ops_to_build, 'gpu')['common']
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000509
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100510 graph_files += Glob('src/graph/backends/CL/*.cpp')
511
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200512multi_isa_objs_list = []
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100513lib_files_sve = []
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200514
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100515if env['neon']:
Georgios Pinitas30271c72019-06-24 14:56:34 +0100516 # build winograd/depthwise sources for either v7a / v8a
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100517 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100518 "src/core/NEON/kernels/convolution/winograd/",
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100519 "src/core/NEON/kernels/convolution/depthwise/",
520 "src/core/NEON/kernels/assembly/",
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +0100521 "arm_compute/core/NEON/kernels/assembly/",
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200522 "src/cpu/kernels/assembly/"])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000523
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100524 lib_files += filelist['cpu']['common']
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100525
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100526 # Setup SIMD file list to include
527 simd = []
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200528 if 'sve' in env['arch'] or env['multi_isa']: simd += ['sve']
529 if 'sve' not in env['arch'] or env['multi_isa']: simd += ['neon']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100530
531 # Get attributes
Freddie Liardet487d3902021-09-21 12:36:43 +0100532 if(use_custom_ops):
533 attrs = get_attrs_list(env, custom_types, custom_layouts)
534 else:
535 attrs = get_attrs_list(env, env['data_type_support'], env['data_layout_support'])
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100536
537 # Setup data-type and data-layout files to include
Freddie Liardet487d3902021-09-21 12:36:43 +0100538 cpu_operators = custom_operators if use_custom_ops else filelist['cpu']['operators'].keys()
539 cpu_ops_to_build = resolve_operator_dependencies(filelist, cpu_operators, 'cpu')
540
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100541 cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200542
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100543 lib_files += cpu_files.get('common', [])
544 lib_files += cpu_files.get('neon', [])
545 lib_files_sve += cpu_files.get('sve', [])
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100546
547 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000548
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100549# Restrict from building graph API if a reduced operator list has been provided
Freddie Liardet487d3902021-09-21 12:36:43 +0100550if use_custom_ops:
551 print("WARNING: Graph library requires all operators to be built")
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100552 graph_files = []
553
554# Build bootcode in case of bare-metal
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100555bootcode_o = []
556if env['os'] == 'bare_metal':
557 bootcode_files = Glob('bootcode/*.s')
558 bootcode_o = build_bootcode_objs(bootcode_files)
559Export('bootcode_o')
560
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100561# Build static libraries
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200562if (env['multi_isa']):
563 # Available architecture
564 arch_v8s = filedefs['cpu']['arch']
565 for arch_v8_info in arch_v8s.items():
566 multi_isa_objs_list += build_multi_isa_objs(lib_files_sve, arch_v8_info)
567
568 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_files + multi_isa_objs_list, static=True)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100569else:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100570 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_files + lib_files_sve, static=True)
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100571Export('arm_compute_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100572
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100573# Build shared libraries
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100574if env['os'] != 'bare_metal' and not env['standalone']:
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200575 if (env['multi_isa']):
576 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files + multi_isa_objs_list, static=False)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100577 else:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100578 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files + lib_files_sve, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100579
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100580 Export('arm_compute_so')
581
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100582# Generate dummy core lib for backwards compatibility
Pablo Marquez Tello48f26152021-11-18 10:15:23 +0000583if env['os'] == 'macos':
584 # macos static library archiver fails if given an empty list of files
585 arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [lib_files], static=True)
586else:
587 arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [], static=True)
588
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100589Export('arm_compute_core_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100590
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100591if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100592 arm_compute_core_a_so = build_library('arm_compute_core', arm_compute_env, [], static=False)
593 Export('arm_compute_core_a_so')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100594
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000595arm_compute_graph_env = arm_compute_env.Clone()
596
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100597# Build graph libraries
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000598arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
599
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100600arm_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 +0100601Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000602
603if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100604 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 +0000605 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100606 Export('arm_compute_graph_so')
607
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100608if env['standalone']:
609 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
610else:
611 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
612
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100613Default(alias)
614
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100615if env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100616 Depends([alias], generate_embed)
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100617else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100618 Depends([alias], generate_embed)