blob: 2eed75a1a50f568cfe351f8212b6bd095db722c6 [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 Spyrou20fca522021-06-07 14:23:57 +010041
Michalis Spyrou748a7c82019-10-07 13:00:44 +010042 arm_compute_env.Append(ASFLAGS = "-I bootcode/")
43 obj = arm_compute_env.Object(sources)
44 obj = install_lib(obj)
45 Default(obj)
46 return obj
47
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010048def build_sve_objs(sources):
Michalis Spyrou20fca522021-06-07 14:23:57 +010049
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010050 tmp_env = arm_compute_env.Clone()
51 tmp_env.Append(CXXFLAGS = "-march=armv8.2-a+sve+fp16")
52 obj = tmp_env.SharedObject(sources)
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010053 Default(obj)
54 return obj
55
Michalis Spyrou20fca522021-06-07 14:23:57 +010056def build_objs(sources):
57
58 obj = arm_compute_env.SharedObject(sources)
Michalis Spyrou20fca522021-06-07 14:23:57 +010059 Default(obj)
60 return obj
61
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 Pinitasf605bd22020-11-26 11:55:09 +000075def remove_incode_comments(code):
76 def replace_with_empty(match):
77 s = match.group(0)
78 if s.startswith('/'):
79 return " "
80 else:
81 return s
82
83 comment_regex = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
84 return re.sub(comment_regex, replace_with_empty, code)
85
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086def resolve_includes(target, source, env):
87 # File collection
88 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
89
90 # Include pattern
91 pattern = re.compile("#include \"(.*)\"")
92
93 # Get file contents
94 files = []
95 for i in range(len(source)):
96 src = source[i]
97 dst = target[i]
Georgios Pinitasf605bd22020-11-26 11:55:09 +000098 contents = src.get_contents().decode('utf-8')
99 contents = remove_incode_comments(contents).splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100 entry = FileEntry(target_name=dst, file_contents=contents)
101 files.append((os.path.basename(src.get_path()),entry))
102
103 # Create dictionary of tupled list
104 files_dict = dict(files)
105
106 # Check for includes (can only be files in the same folder)
107 final_files = []
108 for file in files:
109 done = False
110 tmp_file = file[1].file_contents
111 while not done:
112 file_count = 0
113 updated_file = []
114 for line in tmp_file:
115 found = pattern.search(line)
116 if found:
117 include_file = found.group(1)
118 data = files_dict[include_file].file_contents
119 updated_file.extend(data)
120 else:
121 updated_file.append(line)
122 file_count += 1
123
124 # Check if all include are replaced.
125 if file_count == len(tmp_file):
126 done = True
127
128 # Update temp file
129 tmp_file = updated_file
130
131 # Append and prepend string literal identifiers and add expanded file to final list
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100132 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
133 final_files.append((file[0], entry))
134
135 # Write output files
136 for file in final_files:
137 with open(file[1].target_name.get_path(), 'w+') as out_file:
Georgios Pinitasea857272021-01-22 05:47:37 +0000138 file_to_write = "\n".join( file[1].file_contents )
139 if env['compress_kernels']:
Adnan AlSinan39aebd12021-08-06 12:44:51 +0100140 file_to_write = zlib.compress(file_to_write.encode('utf-8'), 9)
141 file_to_write = codecs.encode(file_to_write, "base64").decode('utf-8').replace("\n", "")
Georgios Pinitasea857272021-01-22 05:47:37 +0000142 file_to_write = "R\"(" + file_to_write + ")\""
143 out_file.write(file_to_write)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100144
145def create_version_file(target, source, env):
146# Generate string with build options library version to embed in the library:
147 try:
148 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
149 except (OSError, subprocess.CalledProcessError):
150 git_hash="unknown"
151
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
153 with open(target[0].get_path(), "w") as fd:
154 fd.write(build_info)
155
Michalis Spyrou20fca522021-06-07 14:23:57 +0100156def get_cpu_runtime_files(operator):
157 file_list = []
158 operators = filelist['cpu']['operators']
159
160 if "operator" in operators[operator]["files"]:
161 file_list += operators[operator]["files"]["operator"]
162 return file_list
163
164def get_gpu_runtime_files(operator):
165 file_list = []
166 operators = filelist['gpu']['operators']
167
168 if "operator" in operators[operator]["files"]:
169 file_list += operators[operator]["files"]["operator"]
170 return file_list
171
172def get_cpu_kernel_files(operator):
173
174 file_list = []
175 file_list_sve = []
176 operators = filelist['cpu']['operators']
177
178 if env['estate'] == '64' and "neon" in operators[operator]['files'] and "estate64" in operators[operator]['files']['neon']:
179 file_list += operators[operator]['files']['neon']['estate64']
180 if env['estate'] == '32' and "neon" in operators[operator]['files'] and "estate32" in operators[operator]['files']['neon']:
181 file_list += operators[operator]['files']['neon']['estate32']
182
183 if "kernel" in operators[operator]["files"]:
184 file_list += operators[operator]["files"]["kernel"]
185
186 if ("neon" in operators[operator]["files"]):
187 if any(i in env['data_type_support'] for i in ['all', 'qasymm8']) and ("qasymm8" in operators[operator]["files"]["neon"]):
188 file_list += operators[operator]["files"]["neon"]["qasymm8"]
189 if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']) and ("qasymm8_signed" in operators[operator]["files"]["neon"]):
190 file_list += operators[operator]["files"]["neon"]["qasymm8_signed"]
191 if any(i in env['data_type_support'] for i in ['all', 'qsymm16']) and ("qsymm16" in operators[operator]["files"]["neon"]):
192 file_list += operators[operator]["files"]["neon"]["qsymm16"]
193 if any(i in env['data_type_support'] for i in ['all', 'integer']) and ("integer" in operators[operator]["files"]["neon"]):
194 file_list += operators[operator]["files"]["neon"]["integer"]
195
196 if (not "sve" in env['arch'] or env['fat_binary']) and ("neon" in operators[operator]["files"]):
197 if any(i in env['data_type_support'] for i in ['all', 'fp16']) and ("fp16" in operators[operator]["files"]["neon"]):
198 file_list += operators[operator]["files"]["neon"]["fp16"]
199 if any(i in env['data_type_support'] for i in ['all', 'fp32']) and ("fp32" in operators[operator]["files"]["neon"]):
200 file_list += operators[operator]["files"]["neon"]["fp32"]
201 if any(i in env['data_layout_support'] for i in ['all', 'nchw']) and ("nchw" in operators[operator]["files"]["neon"]):
202 file_list += operators[operator]['files']['neon']['nchw']
203 if ("all" in operators[operator]["files"]["neon"]):
204 file_list += operators[operator]["files"]["neon"]["all"]
205 if ("sve" in env['arch'] or env['fat_binary']) and ("sve" in operators[operator]["files"]):
206 if any(i in env['data_type_support'] for i in ['all', 'fp16']) and ("fp16" in operators[operator]["files"]["sve"]):
207 file_list_sve += operators[operator]["files"]["sve"]["fp16"]
208 if any(i in env['data_type_support'] for i in ['all', 'fp32']) and ("fp32" in operators[operator]["files"]["sve"]):
209 file_list_sve += operators[operator]["files"]["sve"]["fp32"]
210 if any(i in env['data_type_support'] for i in ['all', 'qasymm8']) and ("qasymm8" in operators[operator]["files"]["sve"]):
211 file_list_sve += operators[operator]["files"]["sve"]["qasymm8"]
212 if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']) and ("qasymm8_signed" in operators[operator]["files"]["sve"]):
213 file_list_sve += operators[operator]["files"]["sve"]["qasymm8_signed"]
214 if any(i in env['data_type_support'] for i in ['all', 'qsymm16']) and ("qsymm16" in operators[operator]["files"]["sve"]):
215 file_list_sve += operators[operator]["files"]["sve"]["qsymm16"]
216 if any(i in env['data_type_support'] for i in ['all', 'integer']) and ("integer" in operators[operator]["files"]["sve"]):
217 file_list_sve += operators[operator]["files"]["sve"]["integer"]
218 if ("all" in operators[operator]["files"]["sve"]):
219 file_list_sve += operators[operator]["files"]["sve"]["all"]
220
221 return file_list, file_list_sve
222
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100223arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100224version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
225arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000226
Georgios Pinitas45514032020-12-30 00:03:09 +0000227default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++'
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100228cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
229
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000230# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100231generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000232if env['opencl'] and env['embed_kernels']:
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100233
234 # Header files
235 cl_helper_files = [ 'src/core/CL/cl_kernels/activation_float_helpers.h',
236 'src/core/CL/cl_kernels/activation_quant_helpers.h',
237 'src/core/CL/cl_kernels/gemm_helpers.h',
238 'src/core/CL/cl_kernels/helpers_asymm.h',
239 'src/core/CL/cl_kernels/helpers.h',
240 'src/core/CL/cl_kernels/load_store_utility.h',
241 'src/core/CL/cl_kernels/repeat.h',
242 'src/core/CL/cl_kernels/tile_helpers.h',
243 'src/core/CL/cl_kernels/types.h',
244 'src/core/CL/cl_kernels/warp_helpers_quantized.h',
245 'src/core/CL/cl_kernels/warp_helpers.h'
246 ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000247
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100248 # Common kernels
249 cl_files_common = ['src/core/CL/cl_kernels/common/activation_layer.cl',
250 'src/core/CL/cl_kernels/common/activation_layer_quant.cl',
251 'src/core/CL/cl_kernels/common/arg_min_max.cl',
252 'src/core/CL/cl_kernels/common/batchnormalization_layer.cl',
253 'src/core/CL/cl_kernels/common/bounding_box_transform.cl',
254 'src/core/CL/cl_kernels/common/bounding_box_transform_quantized.cl',
255 'src/core/CL/cl_kernels/common/bitwise_op.cl',
256 'src/core/CL/cl_kernels/common/cast.cl',
257 'src/core/CL/cl_kernels/common/comparisons.cl',
258 'src/core/CL/cl_kernels/common/concatenate.cl',
259 'src/core/CL/cl_kernels/common/col2im.cl',
260 'src/core/CL/cl_kernels/common/convert_fc_weights.cl',
261 'src/core/CL/cl_kernels/common/copy_tensor.cl',
262 'src/core/CL/cl_kernels/common/crop_tensor.cl',
263 'src/core/CL/cl_kernels/common/deconvolution_layer.cl',
264 'src/core/CL/cl_kernels/common/dequantization_layer.cl',
265 'src/core/CL/cl_kernels/common/elementwise_operation.cl',
266 'src/core/CL/cl_kernels/common/elementwise_operation_quantized.cl',
267 'src/core/CL/cl_kernels/common/elementwise_unary.cl',
268 'src/core/CL/cl_kernels/common/fft_digit_reverse.cl',
269 'src/core/CL/cl_kernels/common/fft.cl',
270 'src/core/CL/cl_kernels/common/fft_scale.cl',
271 'src/core/CL/cl_kernels/common/fill_border.cl',
272 'src/core/CL/cl_kernels/common/floor.cl',
273 'src/core/CL/cl_kernels/common/gather.cl',
274 'src/core/CL/cl_kernels/common/gemm.cl',
275 'src/core/CL/cl_kernels/common/gemv.cl',
276 'src/core/CL/cl_kernels/common/gemm_v1.cl',
277 'src/core/CL/cl_kernels/common/gemmlowp.cl',
278 'src/core/CL/cl_kernels/common/generate_proposals.cl',
279 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl',
280 'src/core/CL/cl_kernels/common/instance_normalization.cl',
281 'src/core/CL/cl_kernels/common/l2_normalize.cl',
282 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl',
283 'src/core/CL/cl_kernels/common/unpooling_layer.cl',
284 'src/core/CL/cl_kernels/common/memset.cl',
285 'src/core/CL/cl_kernels/common/nonmax.cl',
286 'src/core/CL/cl_kernels/common/minmax_layer.cl',
287 'src/core/CL/cl_kernels/common/pad_layer.cl',
288 'src/core/CL/cl_kernels/common/permute.cl',
289 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl',
290 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl',
291 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl',
292 'src/core/CL/cl_kernels/common/quantization_layer.cl',
293 'src/core/CL/cl_kernels/common/range.cl',
294 'src/core/CL/cl_kernels/common/reduction_operation.cl',
295 'src/core/CL/cl_kernels/common/pooling_layer.cl',
296 'src/core/CL/cl_kernels/common/reshape_layer.cl',
297 'src/core/CL/cl_kernels/common/convolution_layer.cl',
298 'src/core/CL/cl_kernels/common/reverse.cl',
299 'src/core/CL/cl_kernels/common/roi_align_layer.cl',
300 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl',
301 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl',
302 'src/core/CL/cl_kernels/common/select.cl',
303 'src/core/CL/cl_kernels/common/softmax_layer.cl',
304 'src/core/CL/cl_kernels/common/softmax_layer_quantized.cl',
305 'src/core/CL/cl_kernels/common/stack_layer.cl',
306 'src/core/CL/cl_kernels/common/slice_ops.cl',
307 'src/core/CL/cl_kernels/common/tile.cl',
308 'src/core/CL/cl_kernels/common/transpose.cl'
309 ]
310
311 # NCHW kernels
312 cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl',
313 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl',
314 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl',
315 'src/core/CL/cl_kernels/nchw/depth_to_space.cl',
316 'src/core/CL/cl_kernels/nchw/direct_convolution_quantized.cl',
317 'src/core/CL/cl_kernels/nchw/direct_convolution1x1.cl',
318 'src/core/CL/cl_kernels/nchw/direct_convolution3x3.cl',
319 'src/core/CL/cl_kernels/nchw/direct_convolution5x5.cl',
320 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl',
321 'src/core/CL/cl_kernels/nchw/im2col.cl',
322 'src/core/CL/cl_kernels/nchw/normalization_layer.cl',
323 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl',
324 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl',
325 'src/core/CL/cl_kernels/nchw/pooling_layer.cl',
326 'src/core/CL/cl_kernels/nchw/pooling_layer_quantized.cl',
327 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl',
328 'src/core/CL/cl_kernels/nchw/remap.cl',
329 'src/core/CL/cl_kernels/nchw/reorg_layer.cl',
330 'src/core/CL/cl_kernels/nchw/scale.cl',
331 'src/core/CL/cl_kernels/nchw/scale_quantized.cl',
332 'src/core/CL/cl_kernels/nchw/space_to_batch.cl',
333 'src/core/CL/cl_kernels/nchw/space_to_depth.cl',
334 'src/core/CL/cl_kernels/nchw/upsample_layer.cl',
335 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl',
336 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl',
337 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl'
338 ]
339
340 # NHWC kernels
341 cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl',
342 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl',
343 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl',
344 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl',
345 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl',
346 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl',
347 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl',
348 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl',
349 'src/core/CL/cl_kernels/nhwc/im2col.cl',
350 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl',
351 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl',
352 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl',
353 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl',
354 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl',
355 'src/core/CL/cl_kernels/nhwc/remap.cl',
356 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl',
357 'src/core/CL/cl_kernels/nhwc/scale.cl',
358 'src/core/CL/cl_kernels/nhwc/scale_quantized.cl',
359 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl',
360 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl',
361 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl',
362 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl',
363 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl',
364 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl'
365 ]
366
367 cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc
368
369 embed_files = [ f+"embed" for f in cl_files ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000370 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
371
372 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
373
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000374Default(generate_embed)
375if env["build"] == "embed_only":
376 Return()
377
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000378# Append version defines for semantic versioning
379arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
380 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
381 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
382
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000383# Don't allow undefined references in the libraries:
Georgios Pinitas45514032020-12-30 00:03:09 +0000384undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined'
385arm_compute_env.Append(LINKFLAGS=[undefined_flag])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100386arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
387
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100388arm_compute_env.Append(LIBS = ['dl'])
389
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100390with (open(Dir('#').path + '/filelist.json')) as fp:
391 filelist = json.load(fp)
392
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100393core_files = Glob('src/core/*.cpp')
394core_files += Glob('src/core/CPP/*.cpp')
395core_files += Glob('src/core/CPP/kernels/*.cpp')
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100396core_files += Glob('src/core/helpers/*.cpp')
Sang-Hoon Park3687ee12020-06-24 13:34:04 +0100397core_files += Glob('src/core/utils/*.cpp')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000398core_files += Glob('src/core/utils/helpers/*.cpp')
399core_files += Glob('src/core/utils/io/*.cpp')
400core_files += Glob('src/core/utils/quantization/*.cpp')
Georgios Pinitasb8d5b952019-05-16 14:13:03 +0100401core_files += Glob('src/core/utils/misc/*.cpp')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000402if env["logging"]:
403 core_files += Glob('src/core/utils/logging/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100404
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100405runtime_files_hp = Glob('src/runtime/*.cpp')
406runtime_files_hp += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp')
407runtime_files = Glob('src/runtime/CPP/functions/*.cpp')
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000408
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000409# C API files
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100410runtime_files_hp += filelist['c_api']['common']
Georgios Pinitas41648142021-08-03 08:24:00 +0100411runtime_files_hp += filelist['c_api']['operators']
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100412
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000413if env['opencl']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100414 runtime_files_hp += filelist['c_api']['gpu']
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000415
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000416# Common backend files
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100417core_files += filelist['common']
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000418
Michalis Spyrou20fca522021-06-07 14:23:57 +0100419# Initialize high priority core files
420core_files_hp = core_files
421core_files_sve_hp = []
422core_files = []
423
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100424runtime_files_hp += Glob('src/runtime/CPP/SingleThreadScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100425
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100426graph_files = Glob('src/graph/*.cpp')
427graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000428
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100429if env['cppthreads']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100430 runtime_files_hp += Glob('src/runtime/CPP/CPPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100431
432if env['openmp']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100433 runtime_files_hp += Glob('src/runtime/OMP/OMPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100434
435if env['opencl']:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100436 operators = filelist['gpu']['operators']
437 for operator in operators:
Michele Di Giorgio760c7832021-08-05 10:54:13 +0100438 if operator in filelist['gpu']['high_priority']:
439 runtime_files_hp += get_gpu_runtime_files(operator)
440 if "kernel" in operators[operator]["files"]:
441 core_files_hp += operators[operator]["files"]["kernel"]
442 else:
443 runtime_files += get_gpu_runtime_files(operator)
444 if "kernel" in operators[operator]["files"]:
445 core_files += operators[operator]["files"]["kernel"]
446
447 runtime_files_hp += filelist['gpu']['common']
448 runtime_files += Glob('src/runtime/CL/functions/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000449
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100450 graph_files += Glob('src/graph/backends/CL/*.cpp')
451
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100452sve_o = []
453core_files_sve = []
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100454if env['neon']:
455 core_files += Glob('src/core/NEON/*.cpp')
Pablo Telloeb82fd22018-02-23 13:43:50 +0000456
Georgios Pinitas30271c72019-06-24 14:56:34 +0100457 # build winograd/depthwise sources for either v7a / v8a
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100458 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100459 "src/core/NEON/kernels/convolution/winograd/",
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100460 "src/core/NEON/kernels/convolution/depthwise/",
461 "src/core/NEON/kernels/assembly/",
Sang-Hoon Park4f7693d2021-05-12 13:59:10 +0100462 "arm_compute/core/NEON/kernels/assembly/",
463 "src/core/cpu/kernels/assembly/",])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000464
Michalis Spyrou20fca522021-06-07 14:23:57 +0100465 # Load files based on user's options
466 operators = filelist['cpu']['operators']
467 for operator in operators:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100468 if operator in filelist['cpu']['high_priority']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100469 runtime_files_hp += get_cpu_runtime_files(operator)
Michalis Spyrou20fca522021-06-07 14:23:57 +0100470 file_list, file_list_sve = get_cpu_kernel_files(operator)
471 core_files_hp += file_list
472 core_files_sve_hp += file_list_sve
473 else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100474 runtime_files += get_cpu_runtime_files(operator)
Michalis Spyrou20fca522021-06-07 14:23:57 +0100475 file_list, file_list_sve = get_cpu_kernel_files(operator)
476 core_files += file_list
477 core_files_sve += file_list_sve
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100478
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100479 runtime_files_hp += filelist['cpu']['common']
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100480 runtime_files_hp += Glob('src/runtime/NEON/*.cpp')
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100481 runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
Georgios Pinitas13ef1762021-07-14 17:14:43 +0100482
483 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitas70eb53b2021-01-06 19:42:21 +0000484
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100485bootcode_o = []
486if env['os'] == 'bare_metal':
487 bootcode_files = Glob('bootcode/*.s')
488 bootcode_o = build_bootcode_objs(bootcode_files)
489Export('bootcode_o')
490
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100491high_priority_o = build_objs(core_files_hp + runtime_files_hp)
Michalis Spyrou20fca522021-06-07 14:23:57 +0100492high_priority_sve_o = []
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100493if (env['fat_binary']):
494 sve_o = build_sve_objs(core_files_sve)
Michalis Spyrou20fca522021-06-07 14:23:57 +0100495 high_priority_sve_o = build_sve_objs(core_files_sve_hp)
Michalis Spyrou680705c2021-06-25 10:44:08 +0100496 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 +0100497else:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100498 high_priority_o += build_objs(core_files_sve_hp)
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100499 arm_compute_a = build_library('arm_compute-static', arm_compute_env, core_files + core_files_sve + high_priority_o + runtime_files, static=True)
500Export('arm_compute_a')
501if env['high_priority']:
502 arm_compute_hp_a = build_library('arm_compute_hp-static', arm_compute_env, high_priority_o + high_priority_sve_o, static=True)
503 Export('arm_compute_hp_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100504
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100505if env['os'] != 'bare_metal' and not env['standalone']:
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100506 if (env['fat_binary']):
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100507 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 +0100508 else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100509 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 +0100510
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100511 Export('arm_compute_so')
512
513 if env['high_priority']:
514 arm_compute_hp_so = build_library('arm_compute_hp', arm_compute_env, high_priority_sve_o + high_priority_o, static=False)
515 Export('arm_compute_hp_so')
516
517# Generate dummy core lib for backwards compatibility
518arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [], static=True)
519Export('arm_compute_core_a')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100520
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100521if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100522 arm_compute_core_a_so = build_library('arm_compute_core', arm_compute_env, [], static=False)
523 Export('arm_compute_core_a_so')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100524
Sang-Hoon Park18fbb922021-01-14 14:50:25 +0000525arm_compute_graph_env = arm_compute_env.Clone()
526
527arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
528
Georgios Pinitas4d9687e2020-10-21 18:33:36 +0100529arm_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 +0100530Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000531
532if env['os'] != 'bare_metal' and not env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100533 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 +0000534 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100535 Export('arm_compute_graph_so')
536
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100537if env['standalone']:
538 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
539else:
540 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
541
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100542Default(alias)
543
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100544if env['standalone']:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100545 Depends([alias], generate_embed)
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100546else:
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100547 Depends([alias], generate_embed)