blob: 3341c96bc23245a0ecf85b012cfea9e1e11515b1 [file] [log] [blame]
Jenkinsc66f0e02021-08-20 08:52:20 +00001# Copyright (c) 2016-2021 Arm Limited.
Anthony Barbierdbdab852017-06-23 15:42:00 +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
Jenkins7dcb9fa2021-02-23 22:45:28 +000026import zlib
Jenkinsc66f0e02021-08-20 08:52:20 +000027import json
28import codecs
Anthony Barbierdbdab852017-06-23 15:42:00 +010029
Jenkins91ee4d02021-11-15 14:37:16 +000030VERSION = "v21.11"
31LIBRARY_VERSION_MAJOR = 25
Jenkins18b685f2020-08-21 10:26:22 +010032LIBRARY_VERSION_MINOR = 0
Jenkins6a7771e2020-05-28 11:28:36 +010033LIBRARY_VERSION_PATCH = 0
34SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH)
Anthony Barbierdbdab852017-06-23 15:42:00 +010035
36Import('env')
37Import('vars')
Jenkinsb9abeae2018-11-22 11:58:08 +000038Import('install_lib')
Anthony Barbierdbdab852017-06-23 15:42:00 +010039
Jenkins36ccc902020-02-21 11:10:48 +000040def build_bootcode_objs(sources):
Jenkins36ccc902020-02-21 11:10:48 +000041 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
Jenkinsc66f0e02021-08-20 08:52:20 +000047
Jenkins91ee4d02021-11-15 14:37:16 +000048def build_sve_objs(sources):
Jenkinsc66f0e02021-08-20 08:52:20 +000049 tmp_env = arm_compute_env.Clone()
50 tmp_env.Append(CXXFLAGS = "-march=armv8.2-a+sve+fp16")
51 obj = tmp_env.SharedObject(sources)
52 Default(obj)
53 return obj
54
Jenkinsc66f0e02021-08-20 08:52:20 +000055
Jenkins91ee4d02021-11-15 14:37:16 +000056def build_objs(sources):
Jenkinsc66f0e02021-08-20 08:52:20 +000057 obj = arm_compute_env.SharedObject(sources)
58 Default(obj)
59 return obj
60
Jenkins91ee4d02021-11-15 14:37:16 +000061
Jenkins7dcb9fa2021-02-23 22:45:28 +000062def build_library(name, build_env, sources, static=False, libs=[]):
Anthony Barbierdbdab852017-06-23 15:42:00 +010063 if static:
Jenkins7dcb9fa2021-02-23 22:45:28 +000064 obj = build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbierdbdab852017-06-23 15:42:00 +010065 else:
66 if env['set_soname']:
Jenkins7dcb9fa2021-02-23 22:45:28 +000067 obj = build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbierdbdab852017-06-23 15:42:00 +010068 else:
Jenkins7dcb9fa2021-02-23 22:45:28 +000069 obj = build_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbierdbdab852017-06-23 15:42:00 +010070
Jenkinsb9abeae2018-11-22 11:58:08 +000071 obj = install_lib(obj)
Anthony Barbierdbdab852017-06-23 15:42:00 +010072 Default(obj)
73 return obj
74
Jenkins91ee4d02021-11-15 14:37:16 +000075
Jenkins7dcb9fa2021-02-23 22:45:28 +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
Jenkins91ee4d02021-11-15 14:37:16 +000087
Anthony Barbierdbdab852017-06-23 15:42:00 +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]
Jenkins7dcb9fa2021-02-23 22:45:28 +0000100 contents = src.get_contents().decode('utf-8')
101 contents = remove_incode_comments(contents).splitlines()
Anthony Barbierdbdab852017-06-23 15:42:00 +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 Barbierdbdab852017-06-23 15:42:00 +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:
Jenkins7dcb9fa2021-02-23 22:45:28 +0000140 file_to_write = "\n".join( file[1].file_contents )
141 if env['compress_kernels']:
Jenkinsc66f0e02021-08-20 08:52:20 +0000142 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", "")
Jenkins7dcb9fa2021-02-23 22:45:28 +0000144 file_to_write = "R\"(" + file_to_write + ")\""
145 out_file.write(file_to_write)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100146
Jenkins91ee4d02021-11-15 14:37:16 +0000147
Anthony Barbierdbdab852017-06-23 15:42:00 +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 Barbierdbdab852017-06-23 15:42:00 +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
Jenkinsc66f0e02021-08-20 08:52:20 +0000159
Jenkins91ee4d02021-11-15 14:37:16 +0000160def get_attrs_list(env, data_types, data_layouts):
161 attrs = []
Jenkinsc66f0e02021-08-20 08:52:20 +0000162
Jenkins91ee4d02021-11-15 14:37:16 +0000163 # Manage data-types
164 if 'all' in data_types:
165 attrs += ['fp16', 'fp32', 'integer', 'qasymm8', 'qasymm8_signed', 'qsymm16']
166 else:
167 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']
173 # Manage data-layouts
174 if 'all' in data_layouts:
175 attrs += ['nhwc', 'nchw']
176 else:
177 if 'nhwc' in data_layouts: attrs += ['nhwc']
178 if 'nchw' in data_layouts: attrs += ['nchw']
Jenkinsc66f0e02021-08-20 08:52:20 +0000179
Jenkins91ee4d02021-11-15 14:37:16 +0000180 # Manage execution state
181 attrs += ['estate32' if (env['estate'] == 'auto' and 'v7a' in env['arch']) or '32' in env['estate'] else 'estate64']
182 return attrs
Jenkinsc66f0e02021-08-20 08:52:20 +0000183
Jenkinsc66f0e02021-08-20 08:52:20 +0000184
Jenkins91ee4d02021-11-15 14:37:16 +0000185def get_operator_backend_files(filelist, operators, backend='', techs=[], attrs=[]):
186 files = { "common" : [] }
Jenkinsc66f0e02021-08-20 08:52:20 +0000187
Jenkins91ee4d02021-11-15 14:37:16 +0000188 # Early return if filelist is empty
189 if backend not in filelist:
190 return files
Jenkinsc66f0e02021-08-20 08:52:20 +0000191
Jenkins91ee4d02021-11-15 14:37:16 +0000192 # 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] = []
Jenkinsc66f0e02021-08-20 08:52:20 +0000201
Jenkins91ee4d02021-11-15 14:37:16 +0000202 # 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, [])
Jenkinsc66f0e02021-08-20 08:52:20 +0000207
Jenkins91ee4d02021-11-15 14:37:16 +0000208 # Remove duplicates if they exist
209 return {k: list(set(v)) for k,v in files.items()}
Jenkinsc66f0e02021-08-20 08:52:20 +0000210
Jenkins91ee4d02021-11-15 14:37:16 +0000211def 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
237def 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
Jenkinsc66f0e02021-08-20 08:52:20 +0000258
Anthony Barbierdbdab852017-06-23 15:42:00 +0100259arm_compute_env = env.Clone()
Jenkins52ba29e2018-08-29 15:32:11 +0000260version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
261arm_compute_env.AlwaysBuild(version_file)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100262
Jenkins7dcb9fa2021-02-23 22:45:28 +0000263default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++'
264cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
265
Anthony Barbier06ea0482018-02-22 15:45:35 +0000266# Generate embed files
Jenkins52ba29e2018-08-29 15:32:11 +0000267generate_embed = [ version_file ]
Anthony Barbier06ea0482018-02-22 15:45:35 +0000268if env['opencl'] and env['embed_kernels']:
Jenkinsc66f0e02021-08-20 08:52:20 +0000269
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',
Jenkins91ee4d02021-11-15 14:37:16 +0000280 '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',
Jenkinsc66f0e02021-08-20 08:52:20 +0000284 ]
Anthony Barbier06ea0482018-02-22 15:45:35 +0000285
Jenkinsc66f0e02021-08-20 08:52:20 +0000286 # 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',
Jenkins91ee4d02021-11-15 14:37:16 +0000313 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/gemm_mm_native.cl',
314 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/gemm_mm_reshaped.cl',
315 'src/core/CL/cl_kernels/common/experimental/gemm_fused_post_ops/act_eltwise_op_act/gemm_mm_reshaped_only_rhs.cl',
Jenkinsc66f0e02021-08-20 08:52:20 +0000316 'src/core/CL/cl_kernels/common/gemv.cl',
Jenkinsc66f0e02021-08-20 08:52:20 +0000317 'src/core/CL/cl_kernels/common/gemmlowp.cl',
318 'src/core/CL/cl_kernels/common/generate_proposals.cl',
319 'src/core/CL/cl_kernels/common/generate_proposals_quantized.cl',
320 'src/core/CL/cl_kernels/common/instance_normalization.cl',
321 'src/core/CL/cl_kernels/common/l2_normalize.cl',
322 'src/core/CL/cl_kernels/common/mean_stddev_normalization.cl',
323 'src/core/CL/cl_kernels/common/unpooling_layer.cl',
324 'src/core/CL/cl_kernels/common/memset.cl',
325 'src/core/CL/cl_kernels/common/nonmax.cl',
326 'src/core/CL/cl_kernels/common/minmax_layer.cl',
327 'src/core/CL/cl_kernels/common/pad_layer.cl',
328 'src/core/CL/cl_kernels/common/permute.cl',
329 'src/core/CL/cl_kernels/common/pixelwise_mul_float.cl',
330 'src/core/CL/cl_kernels/common/pixelwise_mul_int.cl',
331 'src/core/CL/cl_kernels/common/qlstm_layer_normalization.cl',
332 'src/core/CL/cl_kernels/common/quantization_layer.cl',
333 'src/core/CL/cl_kernels/common/range.cl',
334 'src/core/CL/cl_kernels/common/reduction_operation.cl',
Jenkinsc66f0e02021-08-20 08:52:20 +0000335 'src/core/CL/cl_kernels/common/reshape_layer.cl',
336 'src/core/CL/cl_kernels/common/convolution_layer.cl',
337 'src/core/CL/cl_kernels/common/reverse.cl',
338 'src/core/CL/cl_kernels/common/roi_align_layer.cl',
339 'src/core/CL/cl_kernels/common/roi_align_layer_quantized.cl',
340 'src/core/CL/cl_kernels/common/roi_pooling_layer.cl',
341 'src/core/CL/cl_kernels/common/select.cl',
342 'src/core/CL/cl_kernels/common/softmax_layer.cl',
343 'src/core/CL/cl_kernels/common/softmax_layer_quantized.cl',
344 'src/core/CL/cl_kernels/common/stack_layer.cl',
345 'src/core/CL/cl_kernels/common/slice_ops.cl',
346 'src/core/CL/cl_kernels/common/tile.cl',
347 'src/core/CL/cl_kernels/common/transpose.cl'
348 ]
349
350 # NCHW kernels
351 cl_files_nchw = ['src/core/CL/cl_kernels/nchw/batch_to_space.cl',
352 'src/core/CL/cl_kernels/nchw/batchnormalization_layer.cl',
353 'src/core/CL/cl_kernels/nchw/channel_shuffle.cl',
354 'src/core/CL/cl_kernels/nchw/depth_to_space.cl',
355 'src/core/CL/cl_kernels/nchw/direct_convolution_quantized.cl',
356 'src/core/CL/cl_kernels/nchw/direct_convolution1x1.cl',
357 'src/core/CL/cl_kernels/nchw/direct_convolution3x3.cl',
358 'src/core/CL/cl_kernels/nchw/direct_convolution5x5.cl',
359 'src/core/CL/cl_kernels/nchw/dequantization_layer.cl',
360 'src/core/CL/cl_kernels/nchw/im2col.cl',
361 'src/core/CL/cl_kernels/nchw/normalization_layer.cl',
362 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer.cl',
363 'src/core/CL/cl_kernels/nchw/normalize_planar_yuv_layer_quantized.cl',
364 'src/core/CL/cl_kernels/nchw/pooling_layer.cl',
Jenkinsc66f0e02021-08-20 08:52:20 +0000365 'src/core/CL/cl_kernels/nchw/prior_box_layer.cl',
366 'src/core/CL/cl_kernels/nchw/remap.cl',
367 'src/core/CL/cl_kernels/nchw/reorg_layer.cl',
368 'src/core/CL/cl_kernels/nchw/scale.cl',
Jenkinsc66f0e02021-08-20 08:52:20 +0000369 'src/core/CL/cl_kernels/nchw/space_to_batch.cl',
370 'src/core/CL/cl_kernels/nchw/space_to_depth.cl',
371 'src/core/CL/cl_kernels/nchw/upsample_layer.cl',
372 'src/core/CL/cl_kernels/nchw/winograd_filter_transform.cl',
373 'src/core/CL/cl_kernels/nchw/winograd_input_transform.cl',
374 'src/core/CL/cl_kernels/nchw/winograd_output_transform.cl'
375 ]
376
377 # NHWC kernels
378 cl_files_nhwc = ['src/core/CL/cl_kernels/nhwc/batch_to_space.cl',
379 'src/core/CL/cl_kernels/nhwc/batchnormalization_layer.cl',
380 'src/core/CL/cl_kernels/nhwc/channel_shuffle.cl',
381 'src/core/CL/cl_kernels/nhwc/direct_convolution.cl',
Jenkins91ee4d02021-11-15 14:37:16 +0000382 'src/core/CL/cl_kernels/nhwc/direct_convolution3d.cl',
Jenkinsc66f0e02021-08-20 08:52:20 +0000383 'src/core/CL/cl_kernels/nhwc/depth_to_space.cl',
384 'src/core/CL/cl_kernels/nhwc/dequantization_layer.cl',
385 'src/core/CL/cl_kernels/nhwc/dwc_native_fp_nhwc.cl',
386 'src/core/CL/cl_kernels/nhwc/dwc_native_quantized_nhwc.cl',
387 'src/core/CL/cl_kernels/nhwc/im2col.cl',
388 'src/core/CL/cl_kernels/nhwc/normalization_layer.cl',
389 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer.cl',
390 'src/core/CL/cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.cl',
391 'src/core/CL/cl_kernels/nhwc/pooling_layer.cl',
392 'src/core/CL/cl_kernels/nhwc/pooling_layer_quantized.cl',
393 'src/core/CL/cl_kernels/nhwc/remap.cl',
394 'src/core/CL/cl_kernels/nhwc/reorg_layer.cl',
395 'src/core/CL/cl_kernels/nhwc/scale.cl',
Jenkinsc66f0e02021-08-20 08:52:20 +0000396 'src/core/CL/cl_kernels/nhwc/space_to_batch.cl',
397 'src/core/CL/cl_kernels/nhwc/space_to_depth.cl',
398 'src/core/CL/cl_kernels/nhwc/upsample_layer.cl',
399 'src/core/CL/cl_kernels/nhwc/winograd_filter_transform.cl',
400 'src/core/CL/cl_kernels/nhwc/winograd_input_transform.cl',
401 'src/core/CL/cl_kernels/nhwc/winograd_output_transform.cl'
402 ]
403
404 cl_files = cl_helper_files + cl_files_common + cl_files_nchw + cl_files_nhwc
405
406 embed_files = [ f+"embed" for f in cl_files ]
Anthony Barbier06ea0482018-02-22 15:45:35 +0000407 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
408
409 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
410
Anthony Barbier06ea0482018-02-22 15:45:35 +0000411Default(generate_embed)
412if env["build"] == "embed_only":
413 Return()
414
Jenkins6a7771e2020-05-28 11:28:36 +0100415# Append version defines for semantic versioning
416arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
417 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
418 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
419
Anthony Barbier06ea0482018-02-22 15:45:35 +0000420# Don't allow undefined references in the libraries:
Jenkins7dcb9fa2021-02-23 22:45:28 +0000421undefined_flag = '-Wl,-undefined,error' if 'macos' in arm_compute_env["os"] else '-Wl,--no-undefined'
422arm_compute_env.Append(LINKFLAGS=[undefined_flag])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100423arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
424
Anthony Barbierdbdab852017-06-23 15:42:00 +0100425arm_compute_env.Append(LIBS = ['dl'])
426
Jenkinsc66f0e02021-08-20 08:52:20 +0000427with (open(Dir('#').path + '/filelist.json')) as fp:
428 filelist = json.load(fp)
429
Jenkins91ee4d02021-11-15 14:37:16 +0000430# Common backend files
431lib_files = filelist['common']
Anthony Barbierdbdab852017-06-23 15:42:00 +0100432
Jenkins91ee4d02021-11-15 14:37:16 +0000433# Logging files
434if env["logging"]:
435 lib_files += filelist['logging']
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000436
Jenkinsf7399fd2021-05-18 15:04:27 +0100437# C API files
Jenkins91ee4d02021-11-15 14:37:16 +0000438lib_files += filelist['c_api']['common']
439lib_files += filelist['c_api']['operators']
Jenkinsc66f0e02021-08-20 08:52:20 +0000440
Jenkins91ee4d02021-11-15 14:37:16 +0000441# Scheduler infrastructure
442lib_files += filelist['scheduler']['single']
443if env['cppthreads']:
444 lib_files += filelist['scheduler']['threads']
445if env['openmp']:
446 lib_files += filelist['scheduler']['omp']
Jenkinsf7399fd2021-05-18 15:04:27 +0100447
Jenkins91ee4d02021-11-15 14:37:16 +0000448# Graph files
Jenkinsb3a371b2018-05-23 11:36:53 +0100449graph_files = Glob('src/graph/*.cpp')
450graph_files += Glob('src/graph/*/*.cpp')
451
Jenkins91ee4d02021-11-15 14:37:16 +0000452# Specify user-defined priority operators
453custom_operators = []
454custom_types = []
455custom_layouts = []
Anthony Barbierdbdab852017-06-23 15:42:00 +0100456
Jenkins91ee4d02021-11-15 14:37:16 +0000457use_custom_ops = env['high_priority'] or env['build_config'];
458
459if env['high_priority']:
460 custom_operators = filelist['high_priority']
461 custom_types = ['all']
462 custom_layouts = ['all']
463
464if env['build_config']:
465 custom_operators, custom_types, custom_layouts = read_build_config_json(env['build_config'])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100466
467if env['opencl']:
Jenkins91ee4d02021-11-15 14:37:16 +0000468 lib_files += filelist['c_api']['gpu']
469 lib_files += filelist['gpu']['common']
Anthony Barbierdbdab852017-06-23 15:42:00 +0100470
Jenkins91ee4d02021-11-15 14:37:16 +0000471 cl_operators = custom_operators if use_custom_ops else filelist['gpu']['operators'].keys()
472 cl_ops_to_build = resolve_operator_dependencies(filelist, cl_operators, 'gpu')
473 lib_files += get_operator_backend_files(filelist, cl_ops_to_build, 'gpu')['common']
Jenkinsf7399fd2021-05-18 15:04:27 +0100474
Jenkinsb3a371b2018-05-23 11:36:53 +0100475 graph_files += Glob('src/graph/backends/CL/*.cpp')
476
Jenkinsc66f0e02021-08-20 08:52:20 +0000477sve_o = []
Jenkins91ee4d02021-11-15 14:37:16 +0000478lib_files_sve = []
Anthony Barbierdbdab852017-06-23 15:42:00 +0100479if env['neon']:
Jenkins975dfe12019-09-02 11:47:54 +0100480 # build winograd/depthwise sources for either v7a / v8a
Jenkins49b8f902020-11-27 12:49:11 +0000481 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/",
Jenkins18b685f2020-08-21 10:26:22 +0100482 "src/core/NEON/kernels/convolution/winograd/",
Jenkins49b8f902020-11-27 12:49:11 +0000483 "src/core/NEON/kernels/convolution/depthwise/",
484 "src/core/NEON/kernels/assembly/",
Jenkinsc66f0e02021-08-20 08:52:20 +0000485 "arm_compute/core/NEON/kernels/assembly/",
Jenkins91ee4d02021-11-15 14:37:16 +0000486 "src/cpu/kernels/assembly/",])
Jenkinsc66f0e02021-08-20 08:52:20 +0000487
Jenkins91ee4d02021-11-15 14:37:16 +0000488 lib_files += filelist['cpu']['common']
Jenkinsc66f0e02021-08-20 08:52:20 +0000489
Jenkins91ee4d02021-11-15 14:37:16 +0000490 # Setup SIMD file list to include
491 simd = []
492 if 'sve' in env['arch'] or env['fat_binary']: simd += ['sve']
493 if 'sve' not in env['arch'] or env['fat_binary']: simd += ['neon']
494
495 # Get attributes
496 if(use_custom_ops):
497 attrs = get_attrs_list(env, custom_types, custom_layouts)
498 else:
499 attrs = get_attrs_list(env, env['data_type_support'], env['data_layout_support'])
500
501 # Setup data-type and data-layout files to include
502 cpu_operators = custom_operators if use_custom_ops else filelist['cpu']['operators'].keys()
503 cpu_ops_to_build = resolve_operator_dependencies(filelist, cpu_operators, 'cpu')
504
505 cpu_files = get_operator_backend_files(filelist, cpu_ops_to_build, 'cpu', simd, attrs)
506 lib_files += cpu_files.get('common', [])
507 lib_files += cpu_files.get('neon', [])
508 lib_files_sve += cpu_files.get('sve', [])
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000509
Jenkinsb3a371b2018-05-23 11:36:53 +0100510 graph_files += Glob('src/graph/backends/NEON/*.cpp')
511
Jenkins91ee4d02021-11-15 14:37:16 +0000512# Restrict from building graph API if a reduced operator list has been provided
513if use_custom_ops:
514 print("WARNING: Graph library requires all operators to be built")
515 graph_files = []
516
517# Build bootcode in case of bare-metal
Jenkins36ccc902020-02-21 11:10:48 +0000518bootcode_o = []
519if env['os'] == 'bare_metal':
520 bootcode_files = Glob('bootcode/*.s')
521 bootcode_o = build_bootcode_objs(bootcode_files)
522Export('bootcode_o')
523
Jenkins91ee4d02021-11-15 14:37:16 +0000524# Build static libraries
Jenkinsc66f0e02021-08-20 08:52:20 +0000525if (env['fat_binary']):
Jenkins91ee4d02021-11-15 14:37:16 +0000526 sve_o = build_sve_objs(lib_files_sve)
527 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_files + sve_o, static=True)
Jenkinsc66f0e02021-08-20 08:52:20 +0000528else:
Jenkins91ee4d02021-11-15 14:37:16 +0000529 arm_compute_a = build_library('arm_compute-static', arm_compute_env, lib_files + lib_files_sve, static=True)
Jenkinsc66f0e02021-08-20 08:52:20 +0000530Export('arm_compute_a')
Jenkinsc66f0e02021-08-20 08:52:20 +0000531
Jenkins91ee4d02021-11-15 14:37:16 +0000532# Build shared libraries
Jenkinsc66f0e02021-08-20 08:52:20 +0000533if env['os'] != 'bare_metal' and not env['standalone']:
534 if (env['fat_binary']):
Jenkins91ee4d02021-11-15 14:37:16 +0000535 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files + sve_o, static=False)
Jenkinsc66f0e02021-08-20 08:52:20 +0000536 else:
Jenkins91ee4d02021-11-15 14:37:16 +0000537 arm_compute_so = build_library('arm_compute', arm_compute_env, lib_files + lib_files_sve, static=False)
Jenkinsc66f0e02021-08-20 08:52:20 +0000538
539 Export('arm_compute_so')
540
Jenkinsc66f0e02021-08-20 08:52:20 +0000541# Generate dummy core lib for backwards compatibility
542arm_compute_core_a = build_library('arm_compute_core-static', arm_compute_env, [], static=True)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100543Export('arm_compute_core_a')
544
Kaizen8938bd32017-09-28 14:38:23 +0100545if env['os'] != 'bare_metal' and not env['standalone']:
Jenkinsc66f0e02021-08-20 08:52:20 +0000546 arm_compute_core_a_so = build_library('arm_compute_core', arm_compute_env, [], static=False)
547 Export('arm_compute_core_a_so')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100548
Jenkins7dcb9fa2021-02-23 22:45:28 +0000549arm_compute_graph_env = arm_compute_env.Clone()
550
Jenkins91ee4d02021-11-15 14:37:16 +0000551# Build graph libraries
Jenkins7dcb9fa2021-02-23 22:45:28 +0000552arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
553
554arm_compute_graph_a = build_library('arm_compute_graph-static', arm_compute_graph_env, graph_files, static=True, libs = [ arm_compute_a])
Jenkinsb3a371b2018-05-23 11:36:53 +0100555Export('arm_compute_graph_a')
Kaizen8938bd32017-09-28 14:38:23 +0100556
Jenkinsb3a371b2018-05-23 11:36:53 +0100557if env['os'] != 'bare_metal' and not env['standalone']:
Jenkinsc66f0e02021-08-20 08:52:20 +0000558 arm_compute_graph_so = build_library('arm_compute_graph', arm_compute_graph_env, graph_files, static=False, libs = [ "arm_compute" ])
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000559 Depends(arm_compute_graph_so, arm_compute_so)
Kaizen8938bd32017-09-28 14:38:23 +0100560 Export('arm_compute_graph_so')
561
Kaizen8938bd32017-09-28 14:38:23 +0100562if env['standalone']:
563 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
564else:
565 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
566
Anthony Barbierdbdab852017-06-23 15:42:00 +0100567Default(alias)
568
Kaizen8938bd32017-09-28 14:38:23 +0100569if env['standalone']:
Jenkinsc66f0e02021-08-20 08:52:20 +0000570 Depends([alias], generate_embed)
Kaizen8938bd32017-09-28 14:38:23 +0100571else:
Jenkinsc66f0e02021-08-20 08:52:20 +0000572 Depends([alias], generate_embed)