blob: c88a86773c88e95c33fc90d00dffc7c255774491 [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"
Freddie Liardet1562af32021-08-04 12:22:51 +010031LIBRARY_VERSION_MAJOR = 24
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
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100160def get_attrs_list(arch, estate, data_types, data_layouts):
161 attrs = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100162
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100163 # Manage data-types
164 if any(i in data_types for i in ['all']):
165 attrs += ['fp16', 'fp32', 'integer', 'qasymm8', 'qasymm8_signed', 'qsymm16']
166 else:
167 if any(i in data_types for i in ['fp16']): attrs += ['fp16']
168 if any(i in data_types for i in ['fp32']): attrs += ['fp32']
169 if any(i in data_types for i in ['integer']): attrs += ['integer']
170 if any(i in data_types for i in ['qasymm8']): attrs += ['qasymm8']
171 if any(i in data_types for i in ['qasymm8_signed']): attrs += ['qasymm8_signed']
172 if any(i in data_types for i in ['qsymm16']): attrs += ['qsymm16']
Michalis Spyrou20fca522021-06-07 14:23:57 +0100173
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100174 # Manage data-layouts
175 if any(i in data_layouts for i in ['all']):
176 attrs += ['nhwc', 'nchw']
177 else:
178 if any(i in data_layouts for i in ['nhwc']): attrs += ['nhwc']
179 if any(i in data_layouts for i in ['nchw']): attrs += ['nchw']
Michalis Spyrou20fca522021-06-07 14:23:57 +0100180
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100181 # Manage execution state
182 estate_attr = 'estate32' if (estate == 'auto' and 'v7a' in arch) or '32' in estate else 'estate64'
183 attrs += [ estate_attr ]
Michalis Spyrou20fca522021-06-07 14:23:57 +0100184
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100185 return attrs
Michalis Spyrou20fca522021-06-07 14:23:57 +0100186
Michalis Spyrou20fca522021-06-07 14:23:57 +0100187
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100188def get_operator_backend_files(filelist, operators, backend='', techs=[], attrs=[]):
189 files = { "common" : [] }
Michalis Spyrou20fca522021-06-07 14:23:57 +0100190
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100191 # Early return if filelist is empty
192 if backend not in filelist:
193 return files
Michalis Spyrou20fca522021-06-07 14:23:57 +0100194
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100195 # Iterate over operators and create the file lists to compiler
196 for operator in operators:
197 if operator in filelist[backend]['operators']:
198 files['common'] += filelist[backend]['operators'][operator]["files"]["common"]
199 for tech in techs:
200 if tech in filelist[backend]['operators'][operator]["files"]:
201 # Add tech as a key to dictionary if not there
202 if tech not in files:
203 files[tech] = []
Michalis Spyrou20fca522021-06-07 14:23:57 +0100204
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100205 # Add tech files to the tech file list
206 tech_files = filelist[backend]['operators'][operator]["files"][tech]
207 files[tech] += tech_files.get('common', [])
208 for attr in attrs:
209 files[tech] += tech_files.get(attr, [])
210
211 # Remove duplicates if they exist
212 return {k: list(set(v)) for k,v in files.items()}
213
214def collect_operators(filelist, operators, backend=''):
215 ops = set()
216 for operator in operators:
217 if operator in filelist[backend]['operators']:
218 ops.add(operator)
219 if 'deps' in filelist[backend]['operators'][operator]:
220 ops.update(filelist[backend]['operators'][operator]['deps'])
221 else:
222 print("Operator {0} is unsupported on {1} backend!".format(operator, backend))
223
224 return ops
225
226
227def resolve_operator_dependencies(filelist, operators, backend=''):
228 resolved_operators = collect_operators(filelist, operators, backend)
229
230 are_ops_resolved = False
231 while not are_ops_resolved:
232 resolution_pass = collect_operators(filelist, resolved_operators, backend)
233 if len(resolution_pass) != len(resolved_operators):
234 resolved_operators.update(resolution_pass)
235 else:
236 are_ops_resolved = True
237
238 return resolved_operators
239
Michalis Spyrou20fca522021-06-07 14:23:57 +0100240
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100241arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100242version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
243arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000244
Georgios Pinitas45514032020-12-30 00:03:09 +0000245default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++'
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100246cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
247
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000248# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100249generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000250if env['opencl'] and env['embed_kernels']:
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100251
252 # Header files
253 cl_helper_files = [ 'src/core/CL/cl_kernels/activation_float_helpers.h',
254 'src/core/CL/cl_kernels/activation_quant_helpers.h',
255 'src/core/CL/cl_kernels/gemm_helpers.h',
256 'src/core/CL/cl_kernels/helpers_asymm.h',
257 'src/core/CL/cl_kernels/helpers.h',
258 'src/core/CL/cl_kernels/load_store_utility.h',
259 'src/core/CL/cl_kernels/repeat.h',
260 'src/core/CL/cl_kernels/tile_helpers.h',
261 'src/core/CL/cl_kernels/types.h',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100262 'src/core/CL/cl_kernels/warp_helpers.h'
263 ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000264
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100265 # Common kernels
266 cl_files_common = ['src/core/CL/cl_kernels/common/activation_layer.cl',
267 'src/core/CL/cl_kernels/common/activation_layer_quant.cl',
268 'src/core/CL/cl_kernels/common/arg_min_max.cl',
269 'src/core/CL/cl_kernels/common/batchnormalization_layer.cl',
270 'src/core/CL/cl_kernels/common/bounding_box_transform.cl',
271 'src/core/CL/cl_kernels/common/bounding_box_transform_quantized.cl',
272 'src/core/CL/cl_kernels/common/bitwise_op.cl',
273 'src/core/CL/cl_kernels/common/cast.cl',
274 'src/core/CL/cl_kernels/common/comparisons.cl',
275 'src/core/CL/cl_kernels/common/concatenate.cl',
276 'src/core/CL/cl_kernels/common/col2im.cl',
277 'src/core/CL/cl_kernels/common/convert_fc_weights.cl',
278 'src/core/CL/cl_kernels/common/copy_tensor.cl',
279 'src/core/CL/cl_kernels/common/crop_tensor.cl',
280 'src/core/CL/cl_kernels/common/deconvolution_layer.cl',
281 'src/core/CL/cl_kernels/common/dequantization_layer.cl',
282 'src/core/CL/cl_kernels/common/elementwise_operation.cl',
283 'src/core/CL/cl_kernels/common/elementwise_operation_quantized.cl',
284 'src/core/CL/cl_kernels/common/elementwise_unary.cl',
285 'src/core/CL/cl_kernels/common/fft_digit_reverse.cl',
286 'src/core/CL/cl_kernels/common/fft.cl',
287 'src/core/CL/cl_kernels/common/fft_scale.cl',
288 'src/core/CL/cl_kernels/common/fill_border.cl',
289 'src/core/CL/cl_kernels/common/floor.cl',
290 'src/core/CL/cl_kernels/common/gather.cl',
291 'src/core/CL/cl_kernels/common/gemm.cl',
292 'src/core/CL/cl_kernels/common/gemv.cl',
293 'src/core/CL/cl_kernels/common/gemm_v1.cl',
294 'src/core/CL/cl_kernels/common/gemmlowp.cl',
295 'src/core/CL/cl_kernels/common/generate_proposals.cl',
296 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl',
297 'src/core/CL/cl_kernels/common/instance_normalization.cl',
298 'src/core/CL/cl_kernels/common/l2_normalize.cl',
299 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl',
300 'src/core/CL/cl_kernels/common/unpooling_layer.cl',
301 'src/core/CL/cl_kernels/common/memset.cl',
302 'src/core/CL/cl_kernels/common/nonmax.cl',
303 'src/core/CL/cl_kernels/common/minmax_layer.cl',
304 'src/core/CL/cl_kernels/common/pad_layer.cl',
305 'src/core/CL/cl_kernels/common/permute.cl',
306 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl',
307 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl',
308 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl',
309 'src/core/CL/cl_kernels/common/quantization_layer.cl',
310 'src/core/CL/cl_kernels/common/range.cl',
311 'src/core/CL/cl_kernels/common/reduction_operation.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100312 'src/core/CL/cl_kernels/common/reshape_layer.cl',
313 'src/core/CL/cl_kernels/common/convolution_layer.cl',
314 'src/core/CL/cl_kernels/common/reverse.cl',
315 'src/core/CL/cl_kernels/common/roi_align_layer.cl',
316 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl',
317 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl',
318 'src/core/CL/cl_kernels/common/select.cl',
319 'src/core/CL/cl_kernels/common/softmax_layer.cl',
320 'src/core/CL/cl_kernels/common/softmax_layer_quantized.cl',
321 'src/core/CL/cl_kernels/common/stack_layer.cl',
322 'src/core/CL/cl_kernels/common/slice_ops.cl',
323 'src/core/CL/cl_kernels/common/tile.cl',
324 'src/core/CL/cl_kernels/common/transpose.cl'
325 ]
326
327 # NCHW kernels
328 cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl',
329 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl',
330 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl',
331 'src/core/CL/cl_kernels/nchw/depth_to_space.cl',
332 'src/core/CL/cl_kernels/nchw/direct_convolution_quantized.cl',
333 'src/core/CL/cl_kernels/nchw/direct_convolution1x1.cl',
334 'src/core/CL/cl_kernels/nchw/direct_convolution3x3.cl',
335 'src/core/CL/cl_kernels/nchw/direct_convolution5x5.cl',
336 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl',
337 'src/core/CL/cl_kernels/nchw/im2col.cl',
338 'src/core/CL/cl_kernels/nchw/normalization_layer.cl',
339 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl',
340 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl',
341 'src/core/CL/cl_kernels/nchw/pooling_layer.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100342 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl',
343 'src/core/CL/cl_kernels/nchw/remap.cl',
344 'src/core/CL/cl_kernels/nchw/reorg_layer.cl',
345 'src/core/CL/cl_kernels/nchw/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100346 'src/core/CL/cl_kernels/nchw/space_to_batch.cl',
347 'src/core/CL/cl_kernels/nchw/space_to_depth.cl',
348 'src/core/CL/cl_kernels/nchw/upsample_layer.cl',
349 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl',
350 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl',
351 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl'
352 ]
353
354 # NHWC kernels
355 cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl',
356 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl',
357 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl',
358 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl',
359 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl',
360 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl',
361 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl',
362 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl',
363 'src/core/CL/cl_kernels/nhwc/im2col.cl',
364 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl',
365 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl',
366 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl',
367 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl',
368 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl',
369 'src/core/CL/cl_kernels/nhwc/remap.cl',
370 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl',
371 'src/core/CL/cl_kernels/nhwc/scale.cl',
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100372 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl',
373 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl',
374 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl',
375 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl',
376 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl',
377 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl'
378 ]
379
380 cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc
381
382 embed_files = [ f+"embed" for f in cl_files ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000383 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
384
385 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
386
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000387Default(generate_embed)
388if env["build"] == "embed_only":
389 Return()
390
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000391# Append version defines for semantic versioning
392arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
393 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
394 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
395
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000396# Don't allow undefined references in the libraries:
Georgios Pinitas45514032020-12-30 00:03:09 +0000397undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined'
398arm_compute_env.Append(LINKFLAGS=[undefined_flag])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100399arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
400
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100401arm_compute_env.Append(LIBS = ['dl'])
402
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100403with (open(Dir('#').path + '/filelist.json')) as fp:
404 filelist = json.load(fp)
405
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100406# Common backend files
407lib_files = filelist['common']
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100408
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100409# Logging files
410if env["logging"]:
411 lib_files += filelist['logging']
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000412
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000413# C API files
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100414lib_files += filelist['c_api']['common']
415lib_files += filelist['c_api']['operators']
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100416
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100417# Scheduler infrastructure
418lib_files += filelist['scheduler']['single']
419if env['cppthreads']:
420 lib_files += filelist['scheduler']['threads']
421if env['openmp']:
422 lib_files += filelist['scheduler']['omp']
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000423
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100424# Graph files
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100425graph_files = Glob('src/graph/*.cpp')
426graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000427
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100428# Specify user-defined priority operators
429use_priority_ops = env['high_priority']
430priority_operators = filelist['high_priority']
431if env['build_config'] != "":
432 build_config = env['build_config']
433 build_config_contents = {}
434 if os.path.isfile(build_config):
435 with open(build_config) as f:
436 try:
437 build_config_contents = json.load(f)
438 except:
439 print("Warning: Build configuration file is of invalid JSON format!")
440 else:
441 try:
442 build_config_contents = json.loads(build_config)
443 except:
444 print("Warning: Build configuration string is of invalid JSON format!")
445 if build_config_contents:
446 priority_operators = build_config_contents.get("operators", [])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100447
448if env['opencl']:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100449 lib_files += filelist['c_api']['gpu']
450 lib_files += filelist['gpu']['common']
Michele Di Giorgio760c7832021-08-05 10:54:13 +0100451
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100452 cl_operators = priority_operators if use_priority_ops else filelist['gpu']['operators'].keys()
453 cl_ops_to_build = resolve_operator_dependencies(filelist, cl_operators, 'gpu')
454 lib_files += get_operator_backend_files(filelist, cl_ops_to_build, 'gpu')['common']
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000455
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100456 graph_files += Glob('src/graph/backends/CL/*.cpp')
457
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100458sve_o = []
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100459lib_files_sve = []
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100460if env['neon']:
Georgios Pinitas30271c72019-06-24 14:56:34 +0100461 # build winograd/depthwise sources for either v7a / v8a
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100462 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100463 "src/core/NEON/kernels/convolution/winograd/",
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100464 "src/core/NEON/kernels/convolution/depthwise/",
465 "src/core/NEON/kernels/assembly/",
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +0100466 "arm_compute/core/NEON/kernels/assembly/",
Georgios Pinitas7891a732021-08-20 21:39:25 +0100467 "src/cpu/kernels/assembly/",])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000468
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100469 lib_files += filelist['cpu']['common']
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100470
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100471 # Setup SIMD file list to include
472 simd = []
473 if 'sve' in env['arch'] or env['fat_binary']: simd += ['sve']
474 if 'sve' not in env['arch'] or env['fat_binary']: simd += ['neon']
475
476 # Get attributes
477 attrs = get_attrs_list(env['arch'], env['estate'], env['data_type_support'], env['data_layout_support'])
478
479 # Setup data-type and data-layout files to include
480 cpu_operators = priority_operators if use_priority_ops else filelist['cpu']['operators'].keys()
481 cpu_ops_to_build = resolve_operator_dependencies(filelist, filelist['cpu']['operators'], 'cpu')
482 cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
483 lib_files += cpu_files.get('common', [])
484 lib_files += cpu_files.get('neon', [])
485 lib_files_sve += cpu_files.get('sve', [])
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100486
487 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000488
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100489# Restrict from building graph API if a reduced operator list has been provided
490if use_priority_ops:
491 print("Graph library requires all operators to be built")
492 graph_files = []
493
494# Build bootcode in case of bare-metal
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100495bootcode_o = []
496if env['os'] == 'bare_metal':
497 bootcode_files = Glob('bootcode/*.s')
498 bootcode_o = build_bootcode_objs(bootcode_files)
499Export('bootcode_o')
500
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100501# Build static libraries
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100502if (env['fat_binary']):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100503 sve_o = build_sve_objs(lib_files_sve)
504 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_files + sve_o, static=True)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100505else:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100506 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 +0100507Export('arm_compute_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100508
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100509# Build shared libraries
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100510if env['os'] != 'bare_metal' and not env['standalone']:
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100511 if (env['fat_binary']):
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100512 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files + sve_o, static=False)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100513 else:
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100514 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files + lib_files_sve, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100515
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100516 Export('arm_compute_so')
517
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100518# Generate dummy core lib for backwards compatibility
519arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [], static=True)
520Export('arm_compute_core_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100521
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100522if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100523 arm_compute_core_a_so = build_library('arm_compute_core', arm_compute_env, [], static=False)
524 Export('arm_compute_core_a_so')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100525
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000526arm_compute_graph_env = arm_compute_env.Clone()
527
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100528# Build graph libraries
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000529arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
530
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100531arm_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 +0100532Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000533
534if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100535 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 +0000536 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100537 Export('arm_compute_graph_so')
538
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100539if env['standalone']:
540 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
541else:
542 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
543
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100544Default(alias)
545
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100546if env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100547 Depends([alias], generate_embed)
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100548else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100549 Depends([alias], generate_embed)