blob: 6198445b08120aaaa806d642c4ed500f2e259696 [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.
22import collections
23import os.path
24import re
25import subprocess
Georgios Pinitasea857272021-01-22 05:47:37 +000026import zlib
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010027import json
Adnan AlSinan39aebd12021-08-06 12:44:51 +010028import codecs
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
30VERSION = "v0.0-unreleased"
Gunes Bayir456fb2b2021-11-04 16:14:37 +000031LIBRARY_VERSION_MAJOR = 25
Sang-Hoon Park6d0b3842020-08-14 14:48:08 +010032LIBRARY_VERSION_MINOR = 0
Georgios Pinitas35fcc432020-03-26 18:47:46 +000033LIBRARY_VERSION_PATCH = 0
34SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035
36Import('env')
37Import('vars')
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000038Import('install_lib')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039
Michalis Spyrou748a7c82019-10-07 13:00:44 +010040def build_bootcode_objs(sources):
Michalis Spyrou748a7c82019-10-07 13:00:44 +010041 arm_compute_env.Append(ASFLAGS = "-I bootcode/")
42 obj = arm_compute_env.Object(sources)
43 obj = install_lib(obj)
44 Default(obj)
45 return obj
46
Michalis Spyrou20fca522021-06-07 14:23:57 +010047
Georgios Pinitasb6af4822021-09-14 12:33:34 +010048def build_sve_objs(sources):
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010049 tmp_env = arm_compute_env.Clone()
50 tmp_env.Append(CXXFLAGS = "-march=armv8.2-a+sve+fp16")
51 obj = tmp_env.SharedObject(sources)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010052 Default(obj)
53 return obj
54
Michalis Spyrou20fca522021-06-07 14:23:57 +010055
Georgios Pinitasb6af4822021-09-14 12:33:34 +010056def build_objs(sources):
Michalis Spyrou20fca522021-06-07 14:23:57 +010057 obj = arm_compute_env.SharedObject(sources)
Michalis Spyrou20fca522021-06-07 14:23:57 +010058 Default(obj)
59 return obj
60
Georgios Pinitasb6af4822021-09-14 12:33:34 +010061
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010062def build_library(name, build_env, sources, static=False, libs=[]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063 if static:
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010064 obj = build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065 else:
66 if env['set_soname']:
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010067 obj = build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010068 else:
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010069 obj = build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000071 obj = install_lib(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072 Default(obj)
73 return obj
74
Georgios Pinitasb6af4822021-09-14 12:33:34 +010075
Georgios Pinitasf605bd22020-11-26 11:55:09 +000076def remove_incode_comments(code):
77 def replace_with_empty(match):
78 s = match.group(0)
79 if s.startswith('/'):
80 return " "
81 else:
82 return s
83
84 comment_regex = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
85 return re.sub(comment_regex, replace_with_empty, code)
86
Georgios Pinitasb6af4822021-09-14 12:33:34 +010087
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088def resolve_includes(target, source, env):
89 # File collection
90 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
91
92 # Include pattern
93 pattern = re.compile("#include \"(.*)\"")
94
95 # Get file contents
96 files = []
97 for i in range(len(source)):
98 src = source[i]
99 dst = target[i]
Georgios Pinitasf605bd22020-11-26 11:55:09 +0000100 contents = src.get_contents().decode('utf-8')
101 contents = remove_incode_comments(contents).splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100102 entry = FileEntry(target_name=dst, file_contents=contents)
103 files.append((os.path.basename(src.get_path()),entry))
104
105 # Create dictionary of tupled list
106 files_dict = dict(files)
107
108 # Check for includes (can only be files in the same folder)
109 final_files = []
110 for file in files:
111 done = False
112 tmp_file = file[1].file_contents
113 while not done:
114 file_count = 0
115 updated_file = []
116 for line in tmp_file:
117 found = pattern.search(line)
118 if found:
119 include_file = found.group(1)
120 data = files_dict[include_file].file_contents
121 updated_file.extend(data)
122 else:
123 updated_file.append(line)
124 file_count += 1
125
126 # Check if all include are replaced.
127 if file_count == len(tmp_file):
128 done = True
129
130 # Update temp file
131 tmp_file = updated_file
132
133 # Append and prepend string literal identifiers and add expanded file to final list
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
135 final_files.append((file[0], entry))
136
137 # Write output files
138 for file in final_files:
139 with open(file[1].target_name.get_path(), 'w+') as out_file:
Georgios Pinitasea857272021-01-22 05:47:37 +0000140 file_to_write = "\n".join( file[1].file_contents )
141 if env['compress_kernels']:
Adnan AlSinan39aebd12021-08-06 12:44:51 +0100142 file_to_write = zlib.compress(file_to_write.encode('utf-8'), 9)
143 file_to_write = codecs.encode(file_to_write, "base64").decode('utf-8').replace("\n", "")
Georgios Pinitasea857272021-01-22 05:47:37 +0000144 file_to_write = "R\"(" + file_to_write + ")\""
145 out_file.write(file_to_write)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100147
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100148def create_version_file(target, source, env):
149# Generate string with build options library version to embed in the library:
150 try:
151 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
152 except (OSError, subprocess.CalledProcessError):
153 git_hash="unknown"
154
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100155 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
156 with open(target[0].get_path(), "w") as fd:
157 fd.write(build_info)
158
Michalis Spyrou20fca522021-06-07 14:23:57 +0100159
Freddie Liardet487d3902021-09-21 12:36:43 +0100160def get_attrs_list(env, data_types, data_layouts):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100161 attrs = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100162
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100163 # Manage data-types
Freddie Liardet487d3902021-09-21 12:36:43 +0100164 if 'all' in data_types:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100165 attrs += ['fp16', 'fp32', 'integer', 'qasymm8', 'qasymm8_signed', 'qsymm16']
166 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100167 if 'fp16' in data_types: attrs += ['fp16']
168 if 'fp32' in data_types: attrs += ['fp32']
169 if 'integer' in data_types: attrs += ['integer']
170 if 'qasymm8' in data_types: attrs += ['qasymm8']
171 if 'qasymm8_signed' in data_types: attrs += ['qasymm8_signed']
172 if 'qsymm16' in data_types: attrs += ['qsymm16']
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100173 # Manage data-layouts
Freddie Liardet487d3902021-09-21 12:36:43 +0100174 if 'all' in data_layouts:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100175 attrs += ['nhwc', 'nchw']
176 else:
Freddie Liardet487d3902021-09-21 12:36:43 +0100177 if 'nhwc' in data_layouts: attrs += ['nhwc']
178 if 'nchw' in data_layouts: attrs += ['nchw']
Michalis Spyrou20fca522021-06-07 14:23:57 +0100179
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100180 # Manage execution state
Freddie Liardet487d3902021-09-21 12:36:43 +0100181 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 +0100182 return attrs
Michalis Spyrou20fca522021-06-07 14:23:57 +0100183
Michalis Spyrou20fca522021-06-07 14:23:57 +0100184
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100185def get_operator_backend_files(filelist, operators, backend='', techs=[], attrs=[]):
186 files = { "common" : [] }
Michalis Spyrou20fca522021-06-07 14:23:57 +0100187
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100188 # Early return if filelist is empty
189 if backend not in filelist:
190 return files
Michalis Spyrou20fca522021-06-07 14:23:57 +0100191
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100192 # Iterate over operators and create the file lists to compiler
193 for operator in operators:
194 if operator in filelist[backend]['operators']:
195 files['common'] += filelist[backend]['operators'][operator]["files"]["common"]
196 for tech in techs:
197 if tech in filelist[backend]['operators'][operator]["files"]:
198 # Add tech as a key to dictionary if not there
199 if tech not in files:
200 files[tech] = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100201
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100202 # Add tech files to the tech file list
203 tech_files = filelist[backend]['operators'][operator]["files"][tech]
204 files[tech] += tech_files.get('common', [])
205 for attr in attrs:
206 files[tech] += tech_files.get(attr, [])
207
208 # Remove duplicates if they exist
209 return {k: list(set(v)) for k,v in files.items()}
210
211def collect_operators(filelist, operators, backend=''):
212 ops = set()
213 for operator in operators:
214 if operator in filelist[backend]['operators']:
215 ops.add(operator)
216 if 'deps' in filelist[backend]['operators'][operator]:
217 ops.update(filelist[backend]['operators'][operator]['deps'])
218 else:
219 print("Operator {0} is unsupported on {1} backend!".format(operator, backend))
220
221 return ops
222
223
224def resolve_operator_dependencies(filelist, operators, backend=''):
225 resolved_operators = collect_operators(filelist, operators, backend)
226
227 are_ops_resolved = False
228 while not are_ops_resolved:
229 resolution_pass = collect_operators(filelist, resolved_operators, backend)
230 if len(resolution_pass) != len(resolved_operators):
231 resolved_operators.update(resolution_pass)
232 else:
233 are_ops_resolved = True
234
235 return resolved_operators
236
Freddie Liardet487d3902021-09-21 12:36:43 +0100237def read_build_config_json(build_config):
238 build_config_contents = {}
239 custom_operators = []
240 custom_types = []
241 custom_layouts = []
242 if os.path.isfile(build_config):
243 with open(build_config) as f:
244 try:
245 build_config_contents = json.load(f)
246 except:
247 print("Warning: Build configuration file is of invalid JSON format!")
248 else:
249 try:
250 build_config_contents = json.loads(build_config)
251 except:
252 print("Warning: Build configuration string is of invalid JSON format!")
253 if build_config_contents:
254 custom_operators = build_config_contents.get("operators", [])
255 custom_types = build_config_contents.get("data_types", [])
256 custom_layouts = build_config_contents.get("data_layouts", [])
257 return custom_operators, custom_types, custom_layouts
Michalis Spyrou20fca522021-06-07 14:23:57 +0100258
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100259arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100260version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
261arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000262
Georgios Pinitas45514032020-12-30 00:03:09 +0000263default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++'
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100264cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
265
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000266# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100267generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000268if env['opencl'] and env['embed_kernels']:
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100269
270 # Header files
271 cl_helper_files = [ 'src/core/CL/cl_kernels/activation_float_helpers.h',
272 'src/core/CL/cl_kernels/activation_quant_helpers.h',
273 'src/core/CL/cl_kernels/gemm_helpers.h',
274 'src/core/CL/cl_kernels/helpers_asymm.h',
275 'src/core/CL/cl_kernels/helpers.h',
276 'src/core/CL/cl_kernels/load_store_utility.h',
277 'src/core/CL/cl_kernels/repeat.h',
278 'src/core/CL/cl_kernels/tile_helpers.h',
279 'src/core/CL/cl_kernels/types.h',
SiCongLi1af54162021-10-06 15:25:57 +0100280 'src/core/CL/cl_kernels/warp_helpers.h',
281 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/fp_post_ops_act_eltwise_op_act.h',
282 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/fp_mixed_precision_helpers.h',
283 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/fp_elementwise_op_helpers.h',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100284 ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000285
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100286 # Common kernels
287 cl_files_common = ['src/core/CL/cl_kernels/common/activation_layer.cl',
288 'src/core/CL/cl_kernels/common/activation_layer_quant.cl',
289 'src/core/CL/cl_kernels/common/arg_min_max.cl',
290 'src/core/CL/cl_kernels/common/batchnormalization_layer.cl',
291 'src/core/CL/cl_kernels/common/bounding_box_transform.cl',
292 'src/core/CL/cl_kernels/common/bounding_box_transform_quantized.cl',
293 'src/core/CL/cl_kernels/common/bitwise_op.cl',
294 'src/core/CL/cl_kernels/common/cast.cl',
295 'src/core/CL/cl_kernels/common/comparisons.cl',
296 'src/core/CL/cl_kernels/common/concatenate.cl',
297 'src/core/CL/cl_kernels/common/col2im.cl',
298 'src/core/CL/cl_kernels/common/convert_fc_weights.cl',
299 'src/core/CL/cl_kernels/common/copy_tensor.cl',
300 'src/core/CL/cl_kernels/common/crop_tensor.cl',
301 'src/core/CL/cl_kernels/common/deconvolution_layer.cl',
302 'src/core/CL/cl_kernels/common/dequantization_layer.cl',
303 'src/core/CL/cl_kernels/common/elementwise_operation.cl',
304 'src/core/CL/cl_kernels/common/elementwise_operation_quantized.cl',
305 'src/core/CL/cl_kernels/common/elementwise_unary.cl',
306 'src/core/CL/cl_kernels/common/fft_digit_reverse.cl',
307 'src/core/CL/cl_kernels/common/fft.cl',
308 'src/core/CL/cl_kernels/common/fft_scale.cl',
309 'src/core/CL/cl_kernels/common/fill_border.cl',
310 'src/core/CL/cl_kernels/common/floor.cl',
311 'src/core/CL/cl_kernels/common/gather.cl',
312 'src/core/CL/cl_kernels/common/gemm.cl',
ramelg019cca5922021-11-11 10:05:00 +0000313 'src/core/CL/cl_kernels/common/gemm_utils.cl',
SiCongLiafa19722021-10-24 19:12:33 +0100314 '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 +0100315 '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 +0100316 '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 +0100317 'src/core/CL/cl_kernels/common/gemv.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100318 'src/core/CL/cl_kernels/common/gemmlowp.cl',
319 'src/core/CL/cl_kernels/common/generate_proposals.cl',
320 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl',
321 'src/core/CL/cl_kernels/common/instance_normalization.cl',
322 'src/core/CL/cl_kernels/common/l2_normalize.cl',
323 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl',
324 'src/core/CL/cl_kernels/common/unpooling_layer.cl',
325 'src/core/CL/cl_kernels/common/memset.cl',
326 'src/core/CL/cl_kernels/common/nonmax.cl',
327 'src/core/CL/cl_kernels/common/minmax_layer.cl',
328 'src/core/CL/cl_kernels/common/pad_layer.cl',
329 'src/core/CL/cl_kernels/common/permute.cl',
330 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl',
331 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl',
332 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl',
333 'src/core/CL/cl_kernels/common/quantization_layer.cl',
334 'src/core/CL/cl_kernels/common/range.cl',
335 'src/core/CL/cl_kernels/common/reduction_operation.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100336 'src/core/CL/cl_kernels/common/reshape_layer.cl',
337 'src/core/CL/cl_kernels/common/convolution_layer.cl',
338 'src/core/CL/cl_kernels/common/reverse.cl',
339 'src/core/CL/cl_kernels/common/roi_align_layer.cl',
340 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl',
341 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl',
342 'src/core/CL/cl_kernels/common/select.cl',
343 'src/core/CL/cl_kernels/common/softmax_layer.cl',
344 'src/core/CL/cl_kernels/common/softmax_layer_quantized.cl',
345 'src/core/CL/cl_kernels/common/stack_layer.cl',
346 'src/core/CL/cl_kernels/common/slice_ops.cl',
347 'src/core/CL/cl_kernels/common/tile.cl',
348 'src/core/CL/cl_kernels/common/transpose.cl'
349 ]
350
351 # NCHW kernels
352 cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl',
353 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl',
354 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl',
355 'src/core/CL/cl_kernels/nchw/depth_to_space.cl',
356 'src/core/CL/cl_kernels/nchw/direct_convolution_quantized.cl',
357 'src/core/CL/cl_kernels/nchw/direct_convolution1x1.cl',
358 'src/core/CL/cl_kernels/nchw/direct_convolution3x3.cl',
359 'src/core/CL/cl_kernels/nchw/direct_convolution5x5.cl',
360 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl',
361 'src/core/CL/cl_kernels/nchw/im2col.cl',
362 'src/core/CL/cl_kernels/nchw/normalization_layer.cl',
363 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl',
364 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl',
365 'src/core/CL/cl_kernels/nchw/pooling_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100366 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl',
367 'src/core/CL/cl_kernels/nchw/remap.cl',
368 'src/core/CL/cl_kernels/nchw/reorg_layer.cl',
369 'src/core/CL/cl_kernels/nchw/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100370 'src/core/CL/cl_kernels/nchw/space_to_batch.cl',
371 'src/core/CL/cl_kernels/nchw/space_to_depth.cl',
372 'src/core/CL/cl_kernels/nchw/upsample_layer.cl',
373 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl',
374 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl',
375 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl'
376 ]
377
378 # NHWC kernels
379 cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl',
380 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl',
381 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl',
382 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl',
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100383 'src/core/CL/cl_kernels/nhwc/direct_convolution3d.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100384 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl',
385 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl',
386 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl',
387 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl',
388 'src/core/CL/cl_kernels/nhwc/im2col.cl',
389 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl',
390 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl',
391 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl',
392 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl',
393 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl',
394 'src/core/CL/cl_kernels/nhwc/remap.cl',
395 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl',
396 'src/core/CL/cl_kernels/nhwc/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100397 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl',
398 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl',
399 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl',
400 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl',
401 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl',
402 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl'
403 ]
404
405 cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc
406
407 embed_files = [ f+"embed" for f in cl_files ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000408 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
409
410 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
411
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000412Default(generate_embed)
413if env["build"] == "embed_only":
414 Return()
415
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000416# Append version defines for semantic versioning
417arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
418 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
419 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
420
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000421# Don't allow undefined references in the libraries:
Georgios Pinitas45514032020-12-30 00:03:09 +0000422undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined'
423arm_compute_env.Append(LINKFLAGS=[undefined_flag])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100424arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
425
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100426arm_compute_env.Append(LIBS = ['dl'])
427
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100428with (open(Dir('#').path + '/filelist.json')) as fp:
429 filelist = json.load(fp)
430
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100431# Common backend files
432lib_files = filelist['common']
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100433
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100434# Logging files
435if env["logging"]:
436 lib_files += filelist['logging']
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000437
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000438# C API files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100439lib_files += filelist['c_api']['common']
440lib_files += filelist['c_api']['operators']
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100441
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100442# Scheduler infrastructure
443lib_files += filelist['scheduler']['single']
444if env['cppthreads']:
445 lib_files += filelist['scheduler']['threads']
446if env['openmp']:
447 lib_files += filelist['scheduler']['omp']
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000448
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100449# Graph files
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100450graph_files = Glob('src/graph/*.cpp')
451graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000452
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100453# Specify user-defined priority operators
Freddie Liardet487d3902021-09-21 12:36:43 +0100454custom_operators = []
455custom_types = []
456custom_layouts = []
457
458use_custom_ops = env['high_priority'] or env['build_config'];
459
460if env['high_priority']:
461 custom_operators = filelist['high_priority']
462 custom_types = ['all']
463 custom_layouts = ['all']
464
465if env['build_config']:
466 custom_operators, custom_types, custom_layouts = read_build_config_json(env['build_config'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100467
468if env['opencl']:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100469 lib_files += filelist['c_api']['gpu']
470 lib_files += filelist['gpu']['common']
Michele Di Giorgio760c7832021-08-05 10:54:13 +0100471
Freddie Liardet487d3902021-09-21 12:36:43 +0100472 cl_operators = custom_operators if use_custom_ops else filelist['gpu']['operators'].keys()
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100473 cl_ops_to_build = resolve_operator_dependencies(filelist, cl_operators, 'gpu')
474 lib_files += get_operator_backend_files(filelist, cl_ops_to_build, 'gpu')['common']
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000475
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100476 graph_files += Glob('src/graph/backends/CL/*.cpp')
477
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100478sve_o = []
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100479lib_files_sve = []
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100480if env['neon']:
Georgios Pinitas30271c72019-06-24 14:56:34 +0100481 # build winograd/depthwise sources for either v7a / v8a
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100482 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100483 "src/core/NEON/kernels/convolution/winograd/",
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100484 "src/core/NEON/kernels/convolution/depthwise/",
485 "src/core/NEON/kernels/assembly/",
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +0100486 "arm_compute/core/NEON/kernels/assembly/",
Georgios Pinitas7891a732021-08-20 21:39:25 +0100487 "src/cpu/kernels/assembly/",])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000488
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100489 lib_files += filelist['cpu']['common']
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100490
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100491 # Setup SIMD file list to include
492 simd = []
493 if 'sve' in env['arch'] or env['fat_binary']: simd += ['sve']
494 if 'sve' not in env['arch'] or env['fat_binary']: simd += ['neon']
495
496 # Get attributes
Freddie Liardet487d3902021-09-21 12:36:43 +0100497 if(use_custom_ops):
498 attrs = get_attrs_list(env, custom_types, custom_layouts)
499 else:
500 attrs = get_attrs_list(env, env['data_type_support'], env['data_layout_support'])
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100501
502 # Setup data-type and data-layout files to include
Freddie Liardet487d3902021-09-21 12:36:43 +0100503 cpu_operators = custom_operators if use_custom_ops else filelist['cpu']['operators'].keys()
504 cpu_ops_to_build = resolve_operator_dependencies(filelist, cpu_operators, 'cpu')
505
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100506 cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
507 lib_files += cpu_files.get('common', [])
508 lib_files += cpu_files.get('neon', [])
509 lib_files_sve += cpu_files.get('sve', [])
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100510
511 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000512
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100513# Restrict from building graph API if a reduced operator list has been provided
Freddie Liardet487d3902021-09-21 12:36:43 +0100514if use_custom_ops:
515 print("WARNING: Graph library requires all operators to be built")
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100516 graph_files = []
517
518# Build bootcode in case of bare-metal
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100519bootcode_o = []
520if env['os'] == 'bare_metal':
521 bootcode_files = Glob('bootcode/*.s')
522 bootcode_o = build_bootcode_objs(bootcode_files)
523Export('bootcode_o')
524
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100525# Build static libraries
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100526if (env['fat_binary']):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100527 sve_o = build_sve_objs(lib_files_sve)
528 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_files + sve_o, static=True)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100529else:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100530 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 +0100531Export('arm_compute_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100532
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100533# Build shared libraries
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100534if env['os'] != 'bare_metal' and not env['standalone']:
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100535 if (env['fat_binary']):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100536 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files + sve_o, static=False)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100537 else:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100538 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files + lib_files_sve, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100539
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100540 Export('arm_compute_so')
541
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100542# Generate dummy core lib for backwards compatibility
543arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [], static=True)
544Export('arm_compute_core_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100545
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100546if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100547 arm_compute_core_a_so = build_library('arm_compute_core', arm_compute_env, [], static=False)
548 Export('arm_compute_core_a_so')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100549
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000550arm_compute_graph_env = arm_compute_env.Clone()
551
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100552# Build graph libraries
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000553arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
554
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100555arm_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 +0100556Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000557
558if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100559 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 +0000560 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100561 Export('arm_compute_graph_so')
562
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100563if env['standalone']:
564 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
565else:
566 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
567
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100568Default(alias)
569
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100570if env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100571 Depends([alias], generate_embed)
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100572else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100573 Depends([alias], generate_embed)