blob: 8d5e60867c7d4ec36d3116889d2a3bb50d86e744 [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=[]):
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +000095 cloned_build_env = build_env.Clone()
96 if env['os'] == 'android' and static == False:
97 cloned_build_env["LINKFLAGS"].remove('-pie')
98 cloned_build_env["LINKFLAGS"].remove('-static-libstdc++')
99
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100 if static:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000101 obj = cloned_build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100102 else:
103 if env['set_soname']:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000104 obj = cloned_build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100105 else:
Mohammed Suhail Munshide60ed92021-12-21 11:07:27 +0000106 obj = cloned_build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100107
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000108 obj = install_lib(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109 Default(obj)
110 return obj
111
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100112
Georgios Pinitasf605bd22020-11-26 11:55:09 +0000113def remove_incode_comments(code):
114 def replace_with_empty(match):
115 s = match.group(0)
116 if s.startswith('/'):
117 return " "
118 else:
119 return s
120
121 comment_regex = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
122 return re.sub(comment_regex, replace_with_empty, code)
123
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100124
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100125def resolve_includes(target, source, env):
126 # File collection
127 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
128
129 # Include pattern
130 pattern = re.compile("#include \"(.*)\"")
131
132 # Get file contents
133 files = []
134 for i in range(len(source)):
135 src = source[i]
136 dst = target[i]
Georgios Pinitasf605bd22020-11-26 11:55:09 +0000137 contents = src.get_contents().decode('utf-8')
138 contents = remove_incode_comments(contents).splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100139 entry = FileEntry(target_name=dst, file_contents=contents)
140 files.append((os.path.basename(src.get_path()),entry))
141
142 # Create dictionary of tupled list
143 files_dict = dict(files)
144
145 # Check for includes (can only be files in the same folder)
146 final_files = []
147 for file in files:
148 done = False
149 tmp_file = file[1].file_contents
150 while not done:
151 file_count = 0
152 updated_file = []
153 for line in tmp_file:
154 found = pattern.search(line)
155 if found:
156 include_file = found.group(1)
157 data = files_dict[include_file].file_contents
158 updated_file.extend(data)
159 else:
160 updated_file.append(line)
161 file_count += 1
162
163 # Check if all include are replaced.
164 if file_count == len(tmp_file):
165 done = True
166
167 # Update temp file
168 tmp_file = updated_file
169
170 # Append and prepend string literal identifiers and add expanded file to final list
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100171 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
172 final_files.append((file[0], entry))
173
174 # Write output files
175 for file in final_files:
176 with open(file[1].target_name.get_path(), 'w+') as out_file:
Georgios Pinitasea857272021-01-22 05:47:37 +0000177 file_to_write = "\n".join( file[1].file_contents )
178 if env['compress_kernels']:
Adnan AlSinan39aebd12021-08-06 12:44:51 +0100179 file_to_write = zlib.compress(file_to_write.encode('utf-8'), 9)
180 file_to_write = codecs.encode(file_to_write, "base64").decode('utf-8').replace("\n", "")
Georgios Pinitasea857272021-01-22 05:47:37 +0000181 file_to_write = "R\"(" + file_to_write + ")\""
182 out_file.write(file_to_write)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100183
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100184
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100185def create_version_file(target, source, env):
186# Generate string with build options library version to embed in the library:
187 try:
188 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
189 except (OSError, subprocess.CalledProcessError):
190 git_hash="unknown"
191
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100192 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
193 with open(target[0].get_path(), "w") as fd:
194 fd.write(build_info)
195
Michalis Spyrou20fca522021-06-07 14:23:57 +0100196
Freddie Liardet487d3902021-09-21 12:36:43 +0100197def get_attrs_list(env, data_types, data_layouts):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100198 attrs = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100199
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100200 # Manage data-types
Freddie Liardet487d3902021-09-21 12:36:43 +0100201 if 'all' in data_types:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100202 attrs += ['fp16', 'fp32', 'integer', 'qasymm8', 'qasymm8_signed', 'qsymm16']
203 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100204 if 'fp16' in data_types: attrs += ['fp16']
205 if 'fp32' in data_types: attrs += ['fp32']
206 if 'integer' in data_types: attrs += ['integer']
207 if 'qasymm8' in data_types: attrs += ['qasymm8']
208 if 'qasymm8_signed' in data_types: attrs += ['qasymm8_signed']
209 if 'qsymm16' in data_types: attrs += ['qsymm16']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100210 # Manage data-layouts
Freddie Liardet487d3902021-09-21 12:36:43 +0100211 if 'all' in data_layouts:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100212 attrs += ['nhwc', 'nchw']
213 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100214 if 'nhwc' in data_layouts: attrs += ['nhwc']
215 if 'nchw' in data_layouts: attrs += ['nchw']
Michalis Spyrou20fca522021-06-07 14:23:57 +0100216
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100217 # Manage execution state
Freddie Liardet487d3902021-09-21 12:36:43 +0100218 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 +0100219 return attrs
Michalis Spyrou20fca522021-06-07 14:23:57 +0100220
Michalis Spyrou20fca522021-06-07 14:23:57 +0100221
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100222def get_operator_backend_files(filelist, operators, backend='', techs=[], attrs=[]):
223 files = { "common" : [] }
Michalis Spyrou20fca522021-06-07 14:23:57 +0100224
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100225 # Early return if filelist is empty
226 if backend not in filelist:
227 return files
Michalis Spyrou20fca522021-06-07 14:23:57 +0100228
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100229 # Iterate over operators and create the file lists to compiler
230 for operator in operators:
231 if operator in filelist[backend]['operators']:
232 files['common'] += filelist[backend]['operators'][operator]["files"]["common"]
233 for tech in techs:
234 if tech in filelist[backend]['operators'][operator]["files"]:
235 # Add tech as a key to dictionary if not there
236 if tech not in files:
237 files[tech] = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100238
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100239 # Add tech files to the tech file list
240 tech_files = filelist[backend]['operators'][operator]["files"][tech]
241 files[tech] += tech_files.get('common', [])
242 for attr in attrs:
243 files[tech] += tech_files.get(attr, [])
244
245 # Remove duplicates if they exist
246 return {k: list(set(v)) for k,v in files.items()}
247
248def collect_operators(filelist, operators, backend=''):
249 ops = set()
250 for operator in operators:
251 if operator in filelist[backend]['operators']:
252 ops.add(operator)
253 if 'deps' in filelist[backend]['operators'][operator]:
254 ops.update(filelist[backend]['operators'][operator]['deps'])
255 else:
256 print("Operator {0} is unsupported on {1} backend!".format(operator, backend))
257
258 return ops
259
260
261def resolve_operator_dependencies(filelist, operators, backend=''):
262 resolved_operators = collect_operators(filelist, operators, backend)
263
264 are_ops_resolved = False
265 while not are_ops_resolved:
266 resolution_pass = collect_operators(filelist, resolved_operators, backend)
267 if len(resolution_pass) != len(resolved_operators):
268 resolved_operators.update(resolution_pass)
269 else:
270 are_ops_resolved = True
271
272 return resolved_operators
273
Freddie Liardet487d3902021-09-21 12:36:43 +0100274def read_build_config_json(build_config):
275 build_config_contents = {}
276 custom_operators = []
277 custom_types = []
278 custom_layouts = []
279 if os.path.isfile(build_config):
280 with open(build_config) as f:
281 try:
282 build_config_contents = json.load(f)
283 except:
284 print("Warning: Build configuration file is of invalid JSON format!")
285 else:
286 try:
287 build_config_contents = json.loads(build_config)
288 except:
289 print("Warning: Build configuration string is of invalid JSON format!")
290 if build_config_contents:
291 custom_operators = build_config_contents.get("operators", [])
292 custom_types = build_config_contents.get("data_types", [])
293 custom_layouts = build_config_contents.get("data_layouts", [])
294 return custom_operators, custom_types, custom_layouts
Michalis Spyrou20fca522021-06-07 14:23:57 +0100295
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100296arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100297version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
298arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000299
Georgios Pinitas45514032020-12-30 00:03:09 +0000300default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++'
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100301cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
302
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000303# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100304generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000305if env['opencl'] and env['embed_kernels']:
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100306
307 # Header files
308 cl_helper_files = [ 'src/core/CL/cl_kernels/activation_float_helpers.h',
309 'src/core/CL/cl_kernels/activation_quant_helpers.h',
310 'src/core/CL/cl_kernels/gemm_helpers.h',
311 'src/core/CL/cl_kernels/helpers_asymm.h',
312 'src/core/CL/cl_kernels/helpers.h',
313 'src/core/CL/cl_kernels/load_store_utility.h',
314 'src/core/CL/cl_kernels/repeat.h',
315 'src/core/CL/cl_kernels/tile_helpers.h',
316 'src/core/CL/cl_kernels/types.h',
SiCongLi1af54162021-10-06 15:25:57 +0100317 'src/core/CL/cl_kernels/warp_helpers.h',
318 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/fp_post_ops_act_eltwise_op_act.h',
319 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/fp_mixed_precision_helpers.h',
320 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/fp_elementwise_op_helpers.h',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100321 ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000322
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100323 # Common kernels
324 cl_files_common = ['src/core/CL/cl_kernels/common/activation_layer.cl',
325 'src/core/CL/cl_kernels/common/activation_layer_quant.cl',
326 'src/core/CL/cl_kernels/common/arg_min_max.cl',
327 'src/core/CL/cl_kernels/common/batchnormalization_layer.cl',
328 'src/core/CL/cl_kernels/common/bounding_box_transform.cl',
329 'src/core/CL/cl_kernels/common/bounding_box_transform_quantized.cl',
330 'src/core/CL/cl_kernels/common/bitwise_op.cl',
331 'src/core/CL/cl_kernels/common/cast.cl',
332 'src/core/CL/cl_kernels/common/comparisons.cl',
333 'src/core/CL/cl_kernels/common/concatenate.cl',
334 'src/core/CL/cl_kernels/common/col2im.cl',
335 'src/core/CL/cl_kernels/common/convert_fc_weights.cl',
336 'src/core/CL/cl_kernels/common/copy_tensor.cl',
337 'src/core/CL/cl_kernels/common/crop_tensor.cl',
338 'src/core/CL/cl_kernels/common/deconvolution_layer.cl',
339 'src/core/CL/cl_kernels/common/dequantization_layer.cl',
340 'src/core/CL/cl_kernels/common/elementwise_operation.cl',
341 'src/core/CL/cl_kernels/common/elementwise_operation_quantized.cl',
342 'src/core/CL/cl_kernels/common/elementwise_unary.cl',
343 'src/core/CL/cl_kernels/common/fft_digit_reverse.cl',
344 'src/core/CL/cl_kernels/common/fft.cl',
345 'src/core/CL/cl_kernels/common/fft_scale.cl',
346 'src/core/CL/cl_kernels/common/fill_border.cl',
347 'src/core/CL/cl_kernels/common/floor.cl',
348 'src/core/CL/cl_kernels/common/gather.cl',
349 'src/core/CL/cl_kernels/common/gemm.cl',
ramelg019cca5922021-11-11 10:05:00 +0000350 'src/core/CL/cl_kernels/common/gemm_utils.cl',
SiCongLiafa19722021-10-24 19:12:33 +0100351 '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 +0100352 '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 +0100353 '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 +0100354 'src/core/CL/cl_kernels/common/gemv.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100355 'src/core/CL/cl_kernels/common/gemmlowp.cl',
356 'src/core/CL/cl_kernels/common/generate_proposals.cl',
357 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl',
358 'src/core/CL/cl_kernels/common/instance_normalization.cl',
359 'src/core/CL/cl_kernels/common/l2_normalize.cl',
360 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl',
361 'src/core/CL/cl_kernels/common/unpooling_layer.cl',
362 'src/core/CL/cl_kernels/common/memset.cl',
363 'src/core/CL/cl_kernels/common/nonmax.cl',
364 'src/core/CL/cl_kernels/common/minmax_layer.cl',
365 'src/core/CL/cl_kernels/common/pad_layer.cl',
366 'src/core/CL/cl_kernels/common/permute.cl',
367 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl',
368 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl',
369 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl',
370 'src/core/CL/cl_kernels/common/quantization_layer.cl',
371 'src/core/CL/cl_kernels/common/range.cl',
372 'src/core/CL/cl_kernels/common/reduction_operation.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100373 'src/core/CL/cl_kernels/common/reshape_layer.cl',
374 'src/core/CL/cl_kernels/common/convolution_layer.cl',
375 'src/core/CL/cl_kernels/common/reverse.cl',
376 'src/core/CL/cl_kernels/common/roi_align_layer.cl',
377 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl',
378 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl',
379 'src/core/CL/cl_kernels/common/select.cl',
380 'src/core/CL/cl_kernels/common/softmax_layer.cl',
381 'src/core/CL/cl_kernels/common/softmax_layer_quantized.cl',
382 'src/core/CL/cl_kernels/common/stack_layer.cl',
383 'src/core/CL/cl_kernels/common/slice_ops.cl',
384 'src/core/CL/cl_kernels/common/tile.cl',
385 'src/core/CL/cl_kernels/common/transpose.cl'
386 ]
387
388 # NCHW kernels
389 cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl',
390 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl',
391 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl',
392 'src/core/CL/cl_kernels/nchw/depth_to_space.cl',
Adnan AlSinan30124352021-12-02 19:12:20 +0000393 'src/core/CL/cl_kernels/nchw/direct_convolution.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100394 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl',
395 'src/core/CL/cl_kernels/nchw/im2col.cl',
396 'src/core/CL/cl_kernels/nchw/normalization_layer.cl',
397 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl',
398 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl',
399 'src/core/CL/cl_kernels/nchw/pooling_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100400 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl',
401 'src/core/CL/cl_kernels/nchw/remap.cl',
402 'src/core/CL/cl_kernels/nchw/reorg_layer.cl',
403 'src/core/CL/cl_kernels/nchw/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100404 'src/core/CL/cl_kernels/nchw/space_to_batch.cl',
405 'src/core/CL/cl_kernels/nchw/space_to_depth.cl',
406 'src/core/CL/cl_kernels/nchw/upsample_layer.cl',
407 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl',
408 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl',
409 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl'
410 ]
411
412 # NHWC kernels
413 cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl',
414 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl',
415 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl',
416 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl',
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100417 'src/core/CL/cl_kernels/nhwc/direct_convolution3d.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100418 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl',
419 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl',
420 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl',
421 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl',
422 'src/core/CL/cl_kernels/nhwc/im2col.cl',
423 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl',
424 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl',
425 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl',
426 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl',
427 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl',
428 'src/core/CL/cl_kernels/nhwc/remap.cl',
429 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl',
430 'src/core/CL/cl_kernels/nhwc/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100431 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl',
432 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl',
433 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl',
434 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl',
435 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl',
436 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl'
437 ]
438
439 cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc
440
441 embed_files = [ f+"embed" for f in cl_files ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000442 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
443
444 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
445
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000446Default(generate_embed)
447if env["build"] == "embed_only":
448 Return()
449
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000450# Append version defines for semantic versioning
451arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
452 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
453 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
454
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000455# Don't allow undefined references in the libraries:
Georgios Pinitas45514032020-12-30 00:03:09 +0000456undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined'
457arm_compute_env.Append(LINKFLAGS=[undefined_flag])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100458arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
459
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100460arm_compute_env.Append(LIBS = ['dl'])
461
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200462# Load build definitions file
463with (open(Dir('#').path + '/filedefs.json')) as fd:
464 filedefs = json.load(fd)
465
466
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100467with (open(Dir('#').path + '/filelist.json')) as fp:
468 filelist = json.load(fp)
469
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100470# Common backend files
471lib_files = filelist['common']
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100472
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100473# Logging files
474if env["logging"]:
475 lib_files += filelist['logging']
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000476
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000477# C API files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100478lib_files += filelist['c_api']['common']
479lib_files += filelist['c_api']['operators']
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100480
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100481# Scheduler infrastructure
482lib_files += filelist['scheduler']['single']
483if env['cppthreads']:
484 lib_files += filelist['scheduler']['threads']
485if env['openmp']:
486 lib_files += filelist['scheduler']['omp']
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000487
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100488# Graph files
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100489graph_files = Glob('src/graph/*.cpp')
490graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000491
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100492# Specify user-defined priority operators
Freddie Liardet487d3902021-09-21 12:36:43 +0100493custom_operators = []
494custom_types = []
495custom_layouts = []
496
497use_custom_ops = env['high_priority'] or env['build_config'];
498
499if env['high_priority']:
500 custom_operators = filelist['high_priority']
501 custom_types = ['all']
502 custom_layouts = ['all']
503
504if env['build_config']:
505 custom_operators, custom_types, custom_layouts = read_build_config_json(env['build_config'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100506
507if env['opencl']:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100508 lib_files += filelist['c_api']['gpu']
509 lib_files += filelist['gpu']['common']
Michele Di Giorgio760c7832021-08-05 10:54:13 +0100510
Freddie Liardet487d3902021-09-21 12:36:43 +0100511 cl_operators = custom_operators if use_custom_ops else filelist['gpu']['operators'].keys()
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100512 cl_ops_to_build = resolve_operator_dependencies(filelist, cl_operators, 'gpu')
513 lib_files += get_operator_backend_files(filelist, cl_ops_to_build, 'gpu')['common']
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000514
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100515 graph_files += Glob('src/graph/backends/CL/*.cpp')
516
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200517multi_isa_objs_list = []
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100518lib_files_sve = []
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200519
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100520if env['neon']:
Georgios Pinitas30271c72019-06-24 14:56:34 +0100521 # build winograd/depthwise sources for either v7a / v8a
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100522 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100523 "src/core/NEON/kernels/convolution/winograd/",
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100524 "src/core/NEON/kernels/convolution/depthwise/",
525 "src/core/NEON/kernels/assembly/",
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +0100526 "arm_compute/core/NEON/kernels/assembly/",
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200527 "src/cpu/kernels/assembly/"])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000528
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100529 lib_files += filelist['cpu']['common']
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100530
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100531 # Setup SIMD file list to include
532 simd = []
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200533 if 'sve' in env['arch'] or env['multi_isa']: simd += ['sve']
534 if 'sve' not in env['arch'] or env['multi_isa']: simd += ['neon']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100535
536 # Get attributes
Freddie Liardet487d3902021-09-21 12:36:43 +0100537 if(use_custom_ops):
538 attrs = get_attrs_list(env, custom_types, custom_layouts)
539 else:
540 attrs = get_attrs_list(env, env['data_type_support'], env['data_layout_support'])
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100541
542 # Setup data-type and data-layout files to include
Freddie Liardet487d3902021-09-21 12:36:43 +0100543 cpu_operators = custom_operators if use_custom_ops else filelist['cpu']['operators'].keys()
544 cpu_ops_to_build = resolve_operator_dependencies(filelist, cpu_operators, 'cpu')
545
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100546 cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200547
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100548 lib_files += cpu_files.get('common', [])
549 lib_files += cpu_files.get('neon', [])
550 lib_files_sve += cpu_files.get('sve', [])
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100551
552 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000553
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100554# Restrict from building graph API if a reduced operator list has been provided
Freddie Liardet487d3902021-09-21 12:36:43 +0100555if use_custom_ops:
556 print("WARNING: Graph library requires all operators to be built")
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100557 graph_files = []
558
559# Build bootcode in case of bare-metal
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100560bootcode_o = []
561if env['os'] == 'bare_metal':
562 bootcode_files = Glob('bootcode/*.s')
563 bootcode_o = build_bootcode_objs(bootcode_files)
564Export('bootcode_o')
565
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100566# Build static libraries
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200567if (env['multi_isa']):
568 # Available architecture
569 arch_v8s = filedefs['cpu']['arch']
570 for arch_v8_info in arch_v8s.items():
571 multi_isa_objs_list += build_multi_isa_objs(lib_files_sve, arch_v8_info)
572
573 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 +0100574else:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100575 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 +0100576Export('arm_compute_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100577
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100578# Build shared libraries
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100579if env['os'] != 'bare_metal' and not env['standalone']:
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200580 if (env['multi_isa']):
581 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 +0100582 else:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100583 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files + lib_files_sve, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100584
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100585 Export('arm_compute_so')
586
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100587# Generate dummy core lib for backwards compatibility
Pablo Marquez Tello48f26152021-11-18 10:15:23 +0000588if env['os'] == 'macos':
589 # macos static library archiver fails if given an empty list of files
590 arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [lib_files], static=True)
591else:
592 arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [], static=True)
593
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100594Export('arm_compute_core_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100595
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100596if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100597 arm_compute_core_a_so = build_library('arm_compute_core', arm_compute_env, [], static=False)
598 Export('arm_compute_core_a_so')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100599
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000600arm_compute_graph_env = arm_compute_env.Clone()
601
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100602# Build graph libraries
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000603arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
604
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100605arm_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 +0100606Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000607
608if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100609 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 +0000610 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100611 Export('arm_compute_graph_so')
612
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100613if env['standalone']:
614 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
615else:
616 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
617
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100618Default(alias)
619
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100620if env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100621 Depends([alias], generate_embed)
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100622else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100623 Depends([alias], generate_embed)