blob: f19122c7033ebbe71e5f8c9d3800fcf63e52d43c [file] [log] [blame]
Jenkins18b685f2020-08-21 10:26:22 +01001# Copyright (c) 2016, 2017 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
26
Jenkins18b685f2020-08-21 10:26:22 +010027VERSION = "v20.08"
28LIBRARY_VERSION_MAJOR = 20
29LIBRARY_VERSION_MINOR = 0
Jenkins6a7771e2020-05-28 11:28:36 +010030LIBRARY_VERSION_PATCH = 0
31SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH)
Anthony Barbierdbdab852017-06-23 15:42:00 +010032
33Import('env')
34Import('vars')
Jenkinsb9abeae2018-11-22 11:58:08 +000035Import('install_lib')
Anthony Barbierdbdab852017-06-23 15:42:00 +010036
Jenkins36ccc902020-02-21 11:10:48 +000037def build_bootcode_objs(sources):
38
39 arm_compute_env.Append(ASFLAGS = "-I bootcode/")
40 obj = arm_compute_env.Object(sources)
41 obj = install_lib(obj)
42 Default(obj)
43 return obj
44
Kaizenbf8b01d2017-10-12 14:26:51 +010045def build_library(name, sources, static=False, libs=[]):
Anthony Barbierdbdab852017-06-23 15:42:00 +010046 if static:
Kaizenbf8b01d2017-10-12 14:26:51 +010047 obj = arm_compute_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbierdbdab852017-06-23 15:42:00 +010048 else:
49 if env['set_soname']:
Kaizenbf8b01d2017-10-12 14:26:51 +010050 obj = arm_compute_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbierdbdab852017-06-23 15:42:00 +010051
52 symlinks = []
53 # Manually delete symlinks or SCons will get confused:
54 directory = os.path.dirname(obj[0].path)
55 library_prefix = obj[0].path[:-(1 + len(SONAME_VERSION))]
56 real_lib = "%s.%s" % (library_prefix, SONAME_VERSION)
57
Jenkins52ba29e2018-08-29 15:32:11 +000058 for f in Glob("#%s.*" % library_prefix):
Anthony Barbierdbdab852017-06-23 15:42:00 +010059 if str(f) != real_lib:
60 symlinks.append("%s/%s" % (directory,str(f)))
61
62 clean = arm_compute_env.Command('clean-%s' % str(obj[0]), [], Delete(symlinks))
63 Default(clean)
64 Depends(obj, clean)
65 else:
Kaizenbf8b01d2017-10-12 14:26:51 +010066 obj = arm_compute_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbierdbdab852017-06-23 15:42:00 +010067
Jenkinsb9abeae2018-11-22 11:58:08 +000068 obj = install_lib(obj)
Anthony Barbierdbdab852017-06-23 15:42:00 +010069 Default(obj)
70 return obj
71
72def resolve_includes(target, source, env):
73 # File collection
74 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
75
76 # Include pattern
77 pattern = re.compile("#include \"(.*)\"")
78
79 # Get file contents
80 files = []
81 for i in range(len(source)):
82 src = source[i]
83 dst = target[i]
Jenkins4ba87db2019-05-23 17:11:51 +010084 contents = src.get_contents().decode('utf-8').splitlines()
Anthony Barbierdbdab852017-06-23 15:42:00 +010085 entry = FileEntry(target_name=dst, file_contents=contents)
86 files.append((os.path.basename(src.get_path()),entry))
87
88 # Create dictionary of tupled list
89 files_dict = dict(files)
90
91 # Check for includes (can only be files in the same folder)
92 final_files = []
93 for file in files:
94 done = False
95 tmp_file = file[1].file_contents
96 while not done:
97 file_count = 0
98 updated_file = []
99 for line in tmp_file:
100 found = pattern.search(line)
101 if found:
102 include_file = found.group(1)
103 data = files_dict[include_file].file_contents
104 updated_file.extend(data)
105 else:
106 updated_file.append(line)
107 file_count += 1
108
109 # Check if all include are replaced.
110 if file_count == len(tmp_file):
111 done = True
112
113 # Update temp file
114 tmp_file = updated_file
115
116 # Append and prepend string literal identifiers and add expanded file to final list
117 tmp_file.insert(0, "R\"(\n")
118 tmp_file.append("\n)\"")
119 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
120 final_files.append((file[0], entry))
121
122 # Write output files
123 for file in final_files:
124 with open(file[1].target_name.get_path(), 'w+') as out_file:
125 out_file.write( "\n".join( file[1].file_contents ))
126
127def create_version_file(target, source, env):
128# Generate string with build options library version to embed in the library:
129 try:
130 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
131 except (OSError, subprocess.CalledProcessError):
132 git_hash="unknown"
133
Anthony Barbierdbdab852017-06-23 15:42:00 +0100134 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
135 with open(target[0].get_path(), "w") as fd:
136 fd.write(build_info)
137
Anthony Barbierdbdab852017-06-23 15:42:00 +0100138arm_compute_env = env.Clone()
Jenkins52ba29e2018-08-29 15:32:11 +0000139version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
140arm_compute_env.AlwaysBuild(version_file)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100141
Anthony Barbier06ea0482018-02-22 15:45:35 +0000142# Generate embed files
Jenkins52ba29e2018-08-29 15:32:11 +0000143generate_embed = [ version_file ]
Anthony Barbier06ea0482018-02-22 15:45:35 +0000144if env['opencl'] and env['embed_kernels']:
145 cl_files = Glob('src/core/CL/cl_kernels/*.cl')
146 cl_files += Glob('src/core/CL/cl_kernels/*.h')
147
148 embed_files = [ f.get_path()+"embed" for f in cl_files ]
149 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
150
151 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
152
153if env['gles_compute'] and env['embed_kernels']:
154 cs_files = Glob('src/core/GLES_COMPUTE/cs_shaders/*.cs')
155 cs_files += Glob('src/core/GLES_COMPUTE/cs_shaders/*.h')
156
157 embed_files = [ f.get_path()+"embed" for f in cs_files ]
158 arm_compute_env.Append(CPPPATH =[Dir("./src/core/GLES_COMPUTE/").path] )
159
160 generate_embed.append(arm_compute_env.Command(embed_files, cs_files, action=resolve_includes))
161
162Default(generate_embed)
163if env["build"] == "embed_only":
164 Return()
165
Jenkins6a7771e2020-05-28 11:28:36 +0100166# Append version defines for semantic versioning
167arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
168 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
169 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
170
171
Anthony Barbier06ea0482018-02-22 15:45:35 +0000172# Don't allow undefined references in the libraries:
173arm_compute_env.Append(LINKFLAGS=['-Wl,--no-undefined'])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100174arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
175
Anthony Barbierdbdab852017-06-23 15:42:00 +0100176arm_compute_env.Append(LIBS = ['dl'])
177
178core_files = Glob('src/core/*.cpp')
179core_files += Glob('src/core/CPP/*.cpp')
180core_files += Glob('src/core/CPP/kernels/*.cpp')
Jenkins18b685f2020-08-21 10:26:22 +0100181core_files += Glob('src/core/utils/*.cpp')
Jenkins514be652019-02-28 12:25:18 +0000182core_files += Glob('src/core/utils/helpers/*.cpp')
183core_files += Glob('src/core/utils/io/*.cpp')
184core_files += Glob('src/core/utils/quantization/*.cpp')
Jenkins975dfe12019-09-02 11:47:54 +0100185core_files += Glob('src/core/utils/misc/*.cpp')
Jenkins514be652019-02-28 12:25:18 +0000186if env["logging"]:
187 core_files += Glob('src/core/utils/logging/*.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100188
Kaizen8938bd32017-09-28 14:38:23 +0100189runtime_files = Glob('src/runtime/*.cpp')
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000190runtime_files += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp')
191runtime_files += Glob('src/runtime/CPP/functions/*.cpp')
192
Anthony Barbierdbdab852017-06-23 15:42:00 +0100193# CLHarrisCorners uses the Scheduler to run CPP kernels
Kaizen8938bd32017-09-28 14:38:23 +0100194runtime_files += Glob('src/runtime/CPP/SingleThreadScheduler.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100195
Jenkinsb3a371b2018-05-23 11:36:53 +0100196graph_files = Glob('src/graph/*.cpp')
197graph_files += Glob('src/graph/*/*.cpp')
198
Anthony Barbierdbdab852017-06-23 15:42:00 +0100199if env['cppthreads']:
Kaizen8938bd32017-09-28 14:38:23 +0100200 runtime_files += Glob('src/runtime/CPP/CPPScheduler.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100201
202if env['openmp']:
Kaizen8938bd32017-09-28 14:38:23 +0100203 runtime_files += Glob('src/runtime/OMP/OMPScheduler.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100204
205if env['opencl']:
206 core_files += Glob('src/core/CL/*.cpp')
207 core_files += Glob('src/core/CL/kernels/*.cpp')
Jenkins4ba87db2019-05-23 17:11:51 +0100208 core_files += Glob('src/core/CL/gemm/*.cpp')
Jenkins975dfe12019-09-02 11:47:54 +0100209 core_files += Glob('src/core/CL/gemm/native/*.cpp')
Jenkins4ba87db2019-05-23 17:11:51 +0100210 core_files += Glob('src/core/CL/gemm/reshaped/*.cpp')
211 core_files += Glob('src/core/CL/gemm/reshaped_only_rhs/*.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100212
Kaizen8938bd32017-09-28 14:38:23 +0100213 runtime_files += Glob('src/runtime/CL/*.cpp')
214 runtime_files += Glob('src/runtime/CL/functions/*.cpp')
Jenkins6a7771e2020-05-28 11:28:36 +0100215 runtime_files += Glob('src/runtime/CL/gemm/*.cpp')
Jenkinsb3a371b2018-05-23 11:36:53 +0100216 runtime_files += Glob('src/runtime/CL/tuners/*.cpp')
217
218 graph_files += Glob('src/graph/backends/CL/*.cpp')
219
Anthony Barbierdbdab852017-06-23 15:42:00 +0100220
Anthony Barbierdbdab852017-06-23 15:42:00 +0100221if env['neon']:
222 core_files += Glob('src/core/NEON/*.cpp')
223 core_files += Glob('src/core/NEON/kernels/*.cpp')
Jenkins52ba29e2018-08-29 15:32:11 +0000224 core_files += Glob('src/core/NEON/kernels/assembly/*.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100225
Jenkinsb3a371b2018-05-23 11:36:53 +0100226 core_files += Glob('src/core/NEON/kernels/arm_gemm/*.cpp')
227
Jenkins975dfe12019-09-02 11:47:54 +0100228 # build winograd/depthwise sources for either v7a / v8a
Anthony Barbier06ea0482018-02-22 15:45:35 +0000229 core_files += Glob('src/core/NEON/kernels/convolution/*/*.cpp')
230 core_files += Glob('src/core/NEON/kernels/convolution/winograd/*/*.cpp')
Jenkins975dfe12019-09-02 11:47:54 +0100231 arm_compute_env.Append(CPPPATH = ["arm_compute/core/NEON/kernels/convolution/common/",
232 "arm_compute/core/NEON/kernels/convolution/winograd/",
233 "arm_compute/core/NEON/kernels/convolution/depthwise/",
Jenkins18b685f2020-08-21 10:26:22 +0100234 "src/core/NEON/kernels/assembly/",
235 "src/core/NEON/kernels/convolution/winograd/",
Jenkins975dfe12019-09-02 11:47:54 +0100236 "arm_compute/core/NEON/kernels/assembly/"])
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000237
Jenkinsb3a371b2018-05-23 11:36:53 +0100238 graph_files += Glob('src/graph/backends/NEON/*.cpp')
239
Jenkins36ccc902020-02-21 11:10:48 +0000240 if env['estate'] == '32':
Jenkinsb3a371b2018-05-23 11:36:53 +0100241 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a32_*/*.cpp')
242
Jenkins36ccc902020-02-21 11:10:48 +0000243 if env['estate'] == '64':
Jenkinsb3a371b2018-05-23 11:36:53 +0100244 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a64_*/*.cpp')
Jenkinsb9abeae2018-11-22 11:58:08 +0000245 if "sve" in env['arch']:
246 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/sve_*/*.cpp')
Kaizen8938bd32017-09-28 14:38:23 +0100247
248 runtime_files += Glob('src/runtime/NEON/*.cpp')
249 runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
Jenkins52ba29e2018-08-29 15:32:11 +0000250 runtime_files += Glob('src/runtime/NEON/functions/assembly/*.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100251
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000252if env['gles_compute']:
253 if env['os'] != 'android':
254 arm_compute_env.Append(CPPPATH = ["#opengles-3.1/include", "#opengles-3.1/mali_include"])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100255
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000256 core_files += Glob('src/core/GLES_COMPUTE/*.cpp')
257 core_files += Glob('src/core/GLES_COMPUTE/kernels/*.cpp')
258
259 runtime_files += Glob('src/runtime/GLES_COMPUTE/*.cpp')
260 runtime_files += Glob('src/runtime/GLES_COMPUTE/functions/*.cpp')
261
Jenkinsb3a371b2018-05-23 11:36:53 +0100262 graph_files += Glob('src/graph/backends/GLES/*.cpp')
Jenkins6a7771e2020-05-28 11:28:36 +0100263if env['tracing']:
264 arm_compute_env.Append(CPPDEFINES = ['ARM_COMPUTE_TRACING_ENABLED'])
265else:
266 # Remove TracePoint files if tracing is disabled:
267 core_files = [ f for f in core_files if not "TracePoint" in str(f)]
268 runtime_files = [ f for f in runtime_files if not "TracePoint" in str(f)]
Jenkinsb3a371b2018-05-23 11:36:53 +0100269
Jenkins36ccc902020-02-21 11:10:48 +0000270bootcode_o = []
271if env['os'] == 'bare_metal':
272 bootcode_files = Glob('bootcode/*.s')
273 bootcode_o = build_bootcode_objs(bootcode_files)
274Export('bootcode_o')
275
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000276arm_compute_core_a = build_library('arm_compute_core-static', core_files, static=True)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100277Export('arm_compute_core_a')
278
Kaizen8938bd32017-09-28 14:38:23 +0100279if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000280 arm_compute_core_so = build_library('arm_compute_core', core_files, static=False)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100281 Export('arm_compute_core_so')
282
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000283arm_compute_a = build_library('arm_compute-static', runtime_files, static=True, libs = [ arm_compute_core_a ])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100284Export('arm_compute_a')
285
Kaizen8938bd32017-09-28 14:38:23 +0100286if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000287 arm_compute_so = build_library('arm_compute', runtime_files, static=False, libs = [ "arm_compute_core" ])
Kaizenbf8b01d2017-10-12 14:26:51 +0100288 Depends(arm_compute_so, arm_compute_core_so)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100289 Export('arm_compute_so')
290
Jenkinsb3a371b2018-05-23 11:36:53 +0100291arm_compute_graph_a = build_library('arm_compute_graph-static', graph_files, static=True, libs = [ arm_compute_a])
292Export('arm_compute_graph_a')
Kaizen8938bd32017-09-28 14:38:23 +0100293
Jenkinsb3a371b2018-05-23 11:36:53 +0100294if env['os'] != 'bare_metal' and not env['standalone']:
295 arm_compute_graph_so = build_library('arm_compute_graph', graph_files, static=False, libs = [ "arm_compute" , "arm_compute_core"])
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000296 Depends(arm_compute_graph_so, arm_compute_so)
Kaizen8938bd32017-09-28 14:38:23 +0100297 Export('arm_compute_graph_so')
298
Kaizen8938bd32017-09-28 14:38:23 +0100299if env['standalone']:
300 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
301else:
302 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
303
Anthony Barbierdbdab852017-06-23 15:42:00 +0100304Default(alias)
305
Kaizen8938bd32017-09-28 14:38:23 +0100306if env['standalone']:
307 Depends([alias,arm_compute_core_a], generate_embed)
308else:
309 Depends([alias,arm_compute_core_so, arm_compute_core_a], generate_embed)