blob: 682f55310ee942c28a7721b08e8fc4b1b1cc92d6 [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
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
29VERSION = "v0.0-unreleased"
Sheri Zhang5b114252021-05-06 09:49:05 +010030LIBRARY_VERSION_MAJOR = 23
Sang-Hoon Park6d0b3842020-08-14 14:48:08 +010031LIBRARY_VERSION_MINOR = 0
Georgios Pinitas35fcc432020-03-26 18:47:46 +000032LIBRARY_VERSION_PATCH = 0
33SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
35Import('env')
36Import('vars')
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000037Import('install_lib')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038
Michalis Spyrou748a7c82019-10-07 13:00:44 +010039def build_bootcode_objs(sources):
Michalis Spyrou20fca522021-06-07 14:23:57 +010040
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
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010047def build_sve_objs(sources):
Michalis Spyrou20fca522021-06-07 14:23:57 +010048
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 +010055def build_objs(sources):
56
57 obj = arm_compute_env.SharedObject(sources)
Michalis Spyrou20fca522021-06-07 14:23:57 +010058 Default(obj)
59 return obj
60
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010061def build_library(name, build_env, sources, static=False, libs=[]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010062 if static:
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010063 obj = build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010064 else:
65 if env['set_soname']:
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010066 obj = build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067 else:
Georgios Pinitas4d9687e2020-10-21 18:33:36 +010068 obj = build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000070 obj = install_lib(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010071 Default(obj)
72 return obj
73
Georgios Pinitasf605bd22020-11-26 11:55:09 +000074def remove_incode_comments(code):
75 def replace_with_empty(match):
76 s = match.group(0)
77 if s.startswith('/'):
78 return " "
79 else:
80 return s
81
82 comment_regex = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
83 return re.sub(comment_regex, replace_with_empty, code)
84
Anthony Barbier6ff3b192017-09-04 18:44:23 +010085def resolve_includes(target, source, env):
86 # File collection
87 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
88
89 # Include pattern
90 pattern = re.compile("#include \"(.*)\"")
91
92 # Get file contents
93 files = []
94 for i in range(len(source)):
95 src = source[i]
96 dst = target[i]
Georgios Pinitasf605bd22020-11-26 11:55:09 +000097 contents = src.get_contents().decode('utf-8')
98 contents = remove_incode_comments(contents).splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +010099 entry = FileEntry(target_name=dst, file_contents=contents)
100 files.append((os.path.basename(src.get_path()),entry))
101
102 # Create dictionary of tupled list
103 files_dict = dict(files)
104
105 # Check for includes (can only be files in the same folder)
106 final_files = []
107 for file in files:
108 done = False
109 tmp_file = file[1].file_contents
110 while not done:
111 file_count = 0
112 updated_file = []
113 for line in tmp_file:
114 found = pattern.search(line)
115 if found:
116 include_file = found.group(1)
117 data = files_dict[include_file].file_contents
118 updated_file.extend(data)
119 else:
120 updated_file.append(line)
121 file_count += 1
122
123 # Check if all include are replaced.
124 if file_count == len(tmp_file):
125 done = True
126
127 # Update temp file
128 tmp_file = updated_file
129
130 # Append and prepend string literal identifiers and add expanded file to final list
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
132 final_files.append((file[0], entry))
133
134 # Write output files
135 for file in final_files:
136 with open(file[1].target_name.get_path(), 'w+') as out_file:
Georgios Pinitasea857272021-01-22 05:47:37 +0000137 file_to_write = "\n".join( file[1].file_contents )
138 if env['compress_kernels']:
139 file_to_write = zlib.compress(file_to_write, 9).encode("base64").replace("\n", "")
140 file_to_write = "R\"(" + file_to_write + ")\""
141 out_file.write(file_to_write)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100142
143def create_version_file(target, source, env):
144# Generate string with build options library version to embed in the library:
145 try:
146 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
147 except (OSError, subprocess.CalledProcessError):
148 git_hash="unknown"
149
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100150 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
151 with open(target[0].get_path(), "w") as fd:
152 fd.write(build_info)
153
Michalis Spyrou20fca522021-06-07 14:23:57 +0100154def get_cpu_runtime_files(operator):
155 file_list = []
156 operators = filelist['cpu']['operators']
157
158 if "operator" in operators[operator]["files"]:
159 file_list += operators[operator]["files"]["operator"]
160 return file_list
161
162def get_gpu_runtime_files(operator):
163 file_list = []
164 operators = filelist['gpu']['operators']
165
166 if "operator" in operators[operator]["files"]:
167 file_list += operators[operator]["files"]["operator"]
168 return file_list
169
170def get_cpu_kernel_files(operator):
171
172 file_list = []
173 file_list_sve = []
174 operators = filelist['cpu']['operators']
175
176 if env['estate'] == '64' and "neon" in operators[operator]['files'] and "estate64" in operators[operator]['files']['neon']:
177 file_list += operators[operator]['files']['neon']['estate64']
178 if env['estate'] == '32' and "neon" in operators[operator]['files'] and "estate32" in operators[operator]['files']['neon']:
179 file_list += operators[operator]['files']['neon']['estate32']
180
181 if "kernel" in operators[operator]["files"]:
182 file_list += operators[operator]["files"]["kernel"]
183
184 if ("neon" in operators[operator]["files"]):
185 if any(i in env['data_type_support'] for i in ['all', 'qasymm8']) and ("qasymm8" in operators[operator]["files"]["neon"]):
186 file_list += operators[operator]["files"]["neon"]["qasymm8"]
187 if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']) and ("qasymm8_signed" in operators[operator]["files"]["neon"]):
188 file_list += operators[operator]["files"]["neon"]["qasymm8_signed"]
189 if any(i in env['data_type_support'] for i in ['all', 'qsymm16']) and ("qsymm16" in operators[operator]["files"]["neon"]):
190 file_list += operators[operator]["files"]["neon"]["qsymm16"]
191 if any(i in env['data_type_support'] for i in ['all', 'integer']) and ("integer" in operators[operator]["files"]["neon"]):
192 file_list += operators[operator]["files"]["neon"]["integer"]
193
194 if (not "sve" in env['arch'] or env['fat_binary']) and ("neon" in operators[operator]["files"]):
195 if any(i in env['data_type_support'] for i in ['all', 'fp16']) and ("fp16" in operators[operator]["files"]["neon"]):
196 file_list += operators[operator]["files"]["neon"]["fp16"]
197 if any(i in env['data_type_support'] for i in ['all', 'fp32']) and ("fp32" in operators[operator]["files"]["neon"]):
198 file_list += operators[operator]["files"]["neon"]["fp32"]
199 if any(i in env['data_layout_support'] for i in ['all', 'nchw']) and ("nchw" in operators[operator]["files"]["neon"]):
200 file_list += operators[operator]['files']['neon']['nchw']
201 if ("all" in operators[operator]["files"]["neon"]):
202 file_list += operators[operator]["files"]["neon"]["all"]
203 if ("sve" in env['arch'] or env['fat_binary']) and ("sve" in operators[operator]["files"]):
204 if any(i in env['data_type_support'] for i in ['all', 'fp16']) and ("fp16" in operators[operator]["files"]["sve"]):
205 file_list_sve += operators[operator]["files"]["sve"]["fp16"]
206 if any(i in env['data_type_support'] for i in ['all', 'fp32']) and ("fp32" in operators[operator]["files"]["sve"]):
207 file_list_sve += operators[operator]["files"]["sve"]["fp32"]
208 if any(i in env['data_type_support'] for i in ['all', 'qasymm8']) and ("qasymm8" in operators[operator]["files"]["sve"]):
209 file_list_sve += operators[operator]["files"]["sve"]["qasymm8"]
210 if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']) and ("qasymm8_signed" in operators[operator]["files"]["sve"]):
211 file_list_sve += operators[operator]["files"]["sve"]["qasymm8_signed"]
212 if any(i in env['data_type_support'] for i in ['all', 'qsymm16']) and ("qsymm16" in operators[operator]["files"]["sve"]):
213 file_list_sve += operators[operator]["files"]["sve"]["qsymm16"]
214 if any(i in env['data_type_support'] for i in ['all', 'integer']) and ("integer" in operators[operator]["files"]["sve"]):
215 file_list_sve += operators[operator]["files"]["sve"]["integer"]
216 if ("all" in operators[operator]["files"]["sve"]):
217 file_list_sve += operators[operator]["files"]["sve"]["all"]
218
219 return file_list, file_list_sve
220
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100221arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100222version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
223arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000224
Georgios Pinitas45514032020-12-30 00:03:09 +0000225default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++'
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100226cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
227
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000228# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100229generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000230if env['opencl'] and env['embed_kernels']:
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100231
232 # Header files
233 cl_helper_files = [ 'src/core/CL/cl_kernels/activation_float_helpers.h',
234 'src/core/CL/cl_kernels/activation_quant_helpers.h',
235 'src/core/CL/cl_kernels/gemm_helpers.h',
236 'src/core/CL/cl_kernels/helpers_asymm.h',
237 'src/core/CL/cl_kernels/helpers.h',
238 'src/core/CL/cl_kernels/load_store_utility.h',
239 'src/core/CL/cl_kernels/repeat.h',
240 'src/core/CL/cl_kernels/tile_helpers.h',
241 'src/core/CL/cl_kernels/types.h',
242 'src/core/CL/cl_kernels/warp_helpers_quantized.h',
243 'src/core/CL/cl_kernels/warp_helpers.h'
244 ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000245
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100246 # Common kernels
247 cl_files_common = ['src/core/CL/cl_kernels/common/activation_layer.cl',
248 'src/core/CL/cl_kernels/common/activation_layer_quant.cl',
249 'src/core/CL/cl_kernels/common/arg_min_max.cl',
250 'src/core/CL/cl_kernels/common/batchnormalization_layer.cl',
251 'src/core/CL/cl_kernels/common/bounding_box_transform.cl',
252 'src/core/CL/cl_kernels/common/bounding_box_transform_quantized.cl',
253 'src/core/CL/cl_kernels/common/bitwise_op.cl',
254 'src/core/CL/cl_kernels/common/cast.cl',
255 'src/core/CL/cl_kernels/common/comparisons.cl',
256 'src/core/CL/cl_kernels/common/concatenate.cl',
257 'src/core/CL/cl_kernels/common/col2im.cl',
258 'src/core/CL/cl_kernels/common/convert_fc_weights.cl',
259 'src/core/CL/cl_kernels/common/copy_tensor.cl',
260 'src/core/CL/cl_kernels/common/crop_tensor.cl',
261 'src/core/CL/cl_kernels/common/deconvolution_layer.cl',
262 'src/core/CL/cl_kernels/common/dequantization_layer.cl',
263 'src/core/CL/cl_kernels/common/elementwise_operation.cl',
264 'src/core/CL/cl_kernels/common/elementwise_operation_quantized.cl',
265 'src/core/CL/cl_kernels/common/elementwise_unary.cl',
266 'src/core/CL/cl_kernels/common/fft_digit_reverse.cl',
267 'src/core/CL/cl_kernels/common/fft.cl',
268 'src/core/CL/cl_kernels/common/fft_scale.cl',
269 'src/core/CL/cl_kernels/common/fill_border.cl',
270 'src/core/CL/cl_kernels/common/floor.cl',
271 'src/core/CL/cl_kernels/common/gather.cl',
272 'src/core/CL/cl_kernels/common/gemm.cl',
273 'src/core/CL/cl_kernels/common/gemv.cl',
274 'src/core/CL/cl_kernels/common/gemm_v1.cl',
275 'src/core/CL/cl_kernels/common/gemmlowp.cl',
276 'src/core/CL/cl_kernels/common/generate_proposals.cl',
277 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl',
278 'src/core/CL/cl_kernels/common/instance_normalization.cl',
279 'src/core/CL/cl_kernels/common/l2_normalize.cl',
280 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl',
281 'src/core/CL/cl_kernels/common/unpooling_layer.cl',
282 'src/core/CL/cl_kernels/common/memset.cl',
283 'src/core/CL/cl_kernels/common/nonmax.cl',
284 'src/core/CL/cl_kernels/common/minmax_layer.cl',
285 'src/core/CL/cl_kernels/common/pad_layer.cl',
286 'src/core/CL/cl_kernels/common/permute.cl',
287 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl',
288 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl',
289 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl',
290 'src/core/CL/cl_kernels/common/quantization_layer.cl',
291 'src/core/CL/cl_kernels/common/range.cl',
292 'src/core/CL/cl_kernels/common/reduction_operation.cl',
293 'src/core/CL/cl_kernels/common/pooling_layer.cl',
294 'src/core/CL/cl_kernels/common/reshape_layer.cl',
295 'src/core/CL/cl_kernels/common/convolution_layer.cl',
296 'src/core/CL/cl_kernels/common/reverse.cl',
297 'src/core/CL/cl_kernels/common/roi_align_layer.cl',
298 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl',
299 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl',
300 'src/core/CL/cl_kernels/common/select.cl',
301 'src/core/CL/cl_kernels/common/softmax_layer.cl',
302 'src/core/CL/cl_kernels/common/softmax_layer_quantized.cl',
303 'src/core/CL/cl_kernels/common/stack_layer.cl',
304 'src/core/CL/cl_kernels/common/slice_ops.cl',
305 'src/core/CL/cl_kernels/common/tile.cl',
306 'src/core/CL/cl_kernels/common/transpose.cl'
307 ]
308
309 # NCHW kernels
310 cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl',
311 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl',
312 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl',
313 'src/core/CL/cl_kernels/nchw/depth_to_space.cl',
314 'src/core/CL/cl_kernels/nchw/direct_convolution_quantized.cl',
315 'src/core/CL/cl_kernels/nchw/direct_convolution1x1.cl',
316 'src/core/CL/cl_kernels/nchw/direct_convolution3x3.cl',
317 'src/core/CL/cl_kernels/nchw/direct_convolution5x5.cl',
318 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl',
319 'src/core/CL/cl_kernels/nchw/im2col.cl',
320 'src/core/CL/cl_kernels/nchw/normalization_layer.cl',
321 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl',
322 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl',
323 'src/core/CL/cl_kernels/nchw/pooling_layer.cl',
324 'src/core/CL/cl_kernels/nchw/pooling_layer_quantized.cl',
325 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl',
326 'src/core/CL/cl_kernels/nchw/remap.cl',
327 'src/core/CL/cl_kernels/nchw/reorg_layer.cl',
328 'src/core/CL/cl_kernels/nchw/scale.cl',
329 'src/core/CL/cl_kernels/nchw/scale_quantized.cl',
330 'src/core/CL/cl_kernels/nchw/space_to_batch.cl',
331 'src/core/CL/cl_kernels/nchw/space_to_depth.cl',
332 'src/core/CL/cl_kernels/nchw/upsample_layer.cl',
333 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl',
334 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl',
335 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl'
336 ]
337
338 # NHWC kernels
339 cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl',
340 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl',
341 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl',
342 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl',
343 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl',
344 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl',
345 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl',
346 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl',
347 'src/core/CL/cl_kernels/nhwc/im2col.cl',
348 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl',
349 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl',
350 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl',
351 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl',
352 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl',
353 'src/core/CL/cl_kernels/nhwc/remap.cl',
354 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl',
355 'src/core/CL/cl_kernels/nhwc/scale.cl',
356 'src/core/CL/cl_kernels/nhwc/scale_quantized.cl',
357 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl',
358 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl',
359 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl',
360 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl',
361 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl',
362 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl'
363 ]
364
365 cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc
366
367 embed_files = [ f+"embed" for f in cl_files ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000368 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
369
370 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
371
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000372Default(generate_embed)
373if env["build"] == "embed_only":
374 Return()
375
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000376# Append version defines for semantic versioning
377arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
378 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
379 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
380
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000381# Don't allow undefined references in the libraries:
Georgios Pinitas45514032020-12-30 00:03:09 +0000382undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined'
383arm_compute_env.Append(LINKFLAGS=[undefined_flag])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100384arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
385
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100386arm_compute_env.Append(LIBS = ['dl'])
387
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100388with (open(Dir('#').path + '/filelist.json')) as fp:
389 filelist = json.load(fp)
390
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100391core_files = Glob('src/core/*.cpp')
392core_files += Glob('src/core/CPP/*.cpp')
393core_files += Glob('src/core/CPP/kernels/*.cpp')
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100394core_files += Glob('src/core/helpers/*.cpp')
Sang-Hoon Park3687ee12020-06-24 13:34:04 +0100395core_files += Glob('src/core/utils/*.cpp')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000396core_files += Glob('src/core/utils/helpers/*.cpp')
397core_files += Glob('src/core/utils/io/*.cpp')
398core_files += Glob('src/core/utils/quantization/*.cpp')
Georgios Pinitasb8d5b952019-05-16 14:13:03 +0100399core_files += Glob('src/core/utils/misc/*.cpp')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000400if env["logging"]:
401 core_files += Glob('src/core/utils/logging/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100402
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100403runtime_files_hp = Glob('src/runtime/*.cpp')
404runtime_files_hp += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp')
405runtime_files = Glob('src/runtime/CPP/functions/*.cpp')
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000406
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000407# C API files
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100408runtime_files_hp += filelist['c_api']['common']
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100409
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000410if env['opencl']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100411 runtime_files_hp += filelist['c_api']['gpu']
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000412
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000413# Common backend files
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100414core_files += filelist['common']
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000415
Michalis Spyrou20fca522021-06-07 14:23:57 +0100416# Initialize high priority core files
417core_files_hp = core_files
418core_files_sve_hp = []
419core_files = []
420
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100421runtime_files_hp += Glob('src/runtime/CPP/SingleThreadScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100422
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100423graph_files = Glob('src/graph/*.cpp')
424graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000425
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100426if env['cppthreads']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100427 runtime_files_hp += Glob('src/runtime/CPP/CPPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100428
429if env['openmp']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100430 runtime_files_hp += Glob('src/runtime/OMP/OMPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100431
432if env['opencl']:
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100433 runtime_files_hp += filelist['gpu']['common']
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100434 runtime_files += Glob('src/runtime/CL/functions/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000435
Michalis Spyrou20fca522021-06-07 14:23:57 +0100436 operators = filelist['gpu']['operators']
437 for operator in operators:
438 runtime_files += get_gpu_runtime_files(operator)
439 if "kernel" in operators[operator]["files"]:
440 core_files += operators[operator]["files"]["kernel"]
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000441
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100442 graph_files += Glob('src/graph/backends/CL/*.cpp')
443
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100444sve_o = []
445core_files_sve = []
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100446if env['neon']:
447 core_files += Glob('src/core/NEON/*.cpp')
Pablo Telloeb82fd22018-02-23 13:43:50 +0000448
Georgios Pinitas30271c72019-06-24 14:56:34 +0100449 # build winograd/depthwise sources for either v7a / v8a
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100450 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100451 "src/core/NEON/kernels/convolution/winograd/",
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100452 "src/core/NEON/kernels/convolution/depthwise/",
453 "src/core/NEON/kernels/assembly/",
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +0100454 "arm_compute/core/NEON/kernels/assembly/",
455 "src/core/cpu/kernels/assembly/",])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000456
Michalis Spyrou20fca522021-06-07 14:23:57 +0100457 # Load files based on user's options
458 operators = filelist['cpu']['operators']
459 for operator in operators:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100460 if operator in filelist['cpu']['high_priority']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100461 runtime_files_hp += get_cpu_runtime_files(operator)
Michalis Spyrou20fca522021-06-07 14:23:57 +0100462 file_list, file_list_sve = get_cpu_kernel_files(operator)
463 core_files_hp += file_list
464 core_files_sve_hp += file_list_sve
465 else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100466 runtime_files += get_cpu_runtime_files(operator)
Michalis Spyrou20fca522021-06-07 14:23:57 +0100467 file_list, file_list_sve = get_cpu_kernel_files(operator)
468 core_files += file_list
469 core_files_sve += file_list_sve
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100470
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100471 runtime_files_hp += filelist['cpu']['common']
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100472 runtime_files_hp += Glob('src/runtime/NEON/*.cpp')
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100473 runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100474
475 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000476
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100477bootcode_o = []
478if env['os'] == 'bare_metal':
479 bootcode_files = Glob('bootcode/*.s')
480 bootcode_o = build_bootcode_objs(bootcode_files)
481Export('bootcode_o')
482
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100483high_priority_o = build_objs(core_files_hp + runtime_files_hp)
Michalis Spyrou20fca522021-06-07 14:23:57 +0100484high_priority_sve_o = []
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100485if (env['fat_binary']):
486 sve_o = build_sve_objs(core_files_sve)
Michalis Spyrou20fca522021-06-07 14:23:57 +0100487 high_priority_sve_o = build_sve_objs(core_files_sve_hp)
Michalis Spyrou680705c2021-06-25 10:44:08 +0100488 arm_compute_a = build_library('arm_compute-static', arm_compute_env, core_files + sve_o + high_priority_o + high_priority_sve_o + runtime_files, static=True)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100489else:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100490 high_priority_o += build_objs(core_files_sve_hp)
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100491 arm_compute_a = build_library('arm_compute-static', arm_compute_env, core_files + core_files_sve + high_priority_o + runtime_files, static=True)
492Export('arm_compute_a')
493if env['high_priority']:
494 arm_compute_hp_a = build_library('arm_compute_hp-static', arm_compute_env, high_priority_o + high_priority_sve_o, static=True)
495 Export('arm_compute_hp_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100496
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100497if env['os'] != 'bare_metal' and not env['standalone']:
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100498 if (env['fat_binary']):
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100499 arm_compute_so = build_library('arm_compute', arm_compute_env, core_files + sve_o + high_priority_sve_o + high_priority_o + runtime_files, static=False)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100500 else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100501 arm_compute_so = build_library('arm_compute', arm_compute_env, core_files + core_files_sve + high_priority_o + runtime_files , static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100502
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100503 Export('arm_compute_so')
504
505 if env['high_priority']:
506 arm_compute_hp_so = build_library('arm_compute_hp', arm_compute_env, high_priority_sve_o + high_priority_o, static=False)
507 Export('arm_compute_hp_so')
508
509# Generate dummy core lib for backwards compatibility
510arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [], static=True)
511Export('arm_compute_core_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100512
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100513if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100514 arm_compute_core_a_so = build_library('arm_compute_core', arm_compute_env, [], static=False)
515 Export('arm_compute_core_a_so')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100516
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000517arm_compute_graph_env = arm_compute_env.Clone()
518
519arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
520
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100521arm_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 +0100522Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000523
524if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100525 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 +0000526 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100527 Export('arm_compute_graph_so')
528
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100529if env['standalone']:
530 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
531else:
532 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
533
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100534Default(alias)
535
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100536if env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100537 Depends([alias], generate_embed)
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100538else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100539 Depends([alias], generate_embed)