blob: 87571a3bf423c9493188c6dbb2adbe2fdda7caf9 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001# Copyright (c) 2016, 2017 ARM Limited.
2#
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
27VERSION = "v0.0-unreleased"
Georgios Pinitas35fcc432020-03-26 18:47:46 +000028LIBRARY_VERSION_MAJOR = 18
29LIBRARY_VERSION_MINOR = 1
30LIBRARY_VERSION_PATCH = 0
31SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032
33Import('env')
34Import('vars')
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000035Import('install_lib')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036
Michalis Spyrou748a7c82019-10-07 13:00:44 +010037def 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
Anthony Barbierb2881fc2017-09-29 17:12:12 +010045def build_library(name, sources, static=False, libs=[]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046 if static:
Anthony Barbierb2881fc2017-09-29 17:12:12 +010047 obj = arm_compute_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 else:
49 if env['set_soname']:
Anthony Barbierb2881fc2017-09-29 17:12:12 +010050 obj = arm_compute_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +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
Anthony Barbier4ead11a2018-08-06 09:25:36 +010058 for f in Glob("#%s.*" % library_prefix):
Anthony Barbier6ff3b192017-09-04 18:44:23 +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:
Anthony Barbierb2881fc2017-09-29 17:12:12 +010066 obj = arm_compute_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000068 obj = install_lib(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +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]
Michalis Spyrou2d0e5212019-04-11 15:19:52 +010084 contents = src.get_contents().decode('utf-8').splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 Barbier6ff3b192017-09-04 18:44:23 +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 Barbier6ff3b192017-09-04 18:44:23 +0100138arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100139version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
140arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000141
142# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100143generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +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
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000166# 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
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000172# Don't allow undefined references in the libraries:
Michalis Spyrou989f1b52018-01-23 16:47:45 +0000173arm_compute_env.Append(LINKFLAGS=['-Wl,--no-undefined'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100174arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
175
Anthony Barbier6ff3b192017-09-04 18:44:23 +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')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000181core_files += Glob('src/core/utils/helpers/*.cpp')
182core_files += Glob('src/core/utils/io/*.cpp')
183core_files += Glob('src/core/utils/quantization/*.cpp')
Georgios Pinitasb8d5b952019-05-16 14:13:03 +0100184core_files += Glob('src/core/utils/misc/*.cpp')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000185if env["logging"]:
186 core_files += Glob('src/core/utils/logging/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100188runtime_files = Glob('src/runtime/*.cpp')
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000189runtime_files += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp')
190runtime_files += Glob('src/runtime/CPP/functions/*.cpp')
191
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100192# CLHarrisCorners uses the Scheduler to run CPP kernels
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100193runtime_files += Glob('src/runtime/CPP/SingleThreadScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100194
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100195graph_files = Glob('src/graph/*.cpp')
196graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000197
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100198if env['cppthreads']:
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100199 runtime_files += Glob('src/runtime/CPP/CPPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100200
201if env['openmp']:
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100202 runtime_files += Glob('src/runtime/OMP/OMPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100203
204if env['opencl']:
205 core_files += Glob('src/core/CL/*.cpp')
206 core_files += Glob('src/core/CL/kernels/*.cpp')
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000207 core_files += Glob('src/core/CL/gemm/*.cpp')
Gian Marco Iodice06be6f82019-06-24 17:47:51 +0100208 core_files += Glob('src/core/CL/gemm/native/*.cpp')
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000209 core_files += Glob('src/core/CL/gemm/reshaped/*.cpp')
210 core_files += Glob('src/core/CL/gemm/reshaped_only_rhs/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100211
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100212 runtime_files += Glob('src/runtime/CL/*.cpp')
213 runtime_files += Glob('src/runtime/CL/functions/*.cpp')
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +0000214 runtime_files += Glob('src/runtime/CL/gemm/*.cpp')
Georgios Pinitasc0d1c862018-03-23 15:13:15 +0000215 runtime_files += Glob('src/runtime/CL/tuners/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100216
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100217 graph_files += Glob('src/graph/backends/CL/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000218
219
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100220if env['neon']:
221 core_files += Glob('src/core/NEON/*.cpp')
222 core_files += Glob('src/core/NEON/kernels/*.cpp')
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100223 core_files += Glob('src/core/NEON/kernels/assembly/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100224
Pablo Telloeb82fd22018-02-23 13:43:50 +0000225 core_files += Glob('src/core/NEON/kernels/arm_gemm/*.cpp')
226
Georgios Pinitas30271c72019-06-24 14:56:34 +0100227 # build winograd/depthwise sources for either v7a / v8a
Georgios Pinitas4074c992018-01-30 18:13:46 +0000228 core_files += Glob('src/core/NEON/kernels/convolution/*/*.cpp')
229 core_files += Glob('src/core/NEON/kernels/convolution/winograd/*/*.cpp')
Georgios Pinitas30271c72019-06-24 14:56:34 +0100230 arm_compute_env.Append(CPPPATH = ["arm_compute/core/NEON/kernels/convolution/common/",
231 "arm_compute/core/NEON/kernels/convolution/winograd/",
232 "arm_compute/core/NEON/kernels/convolution/depthwise/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100233 "src/core/NEON/kernels/assembly/",
234 "src/core/NEON/kernels/convolution/winograd/",
Georgios Pinitas30271c72019-06-24 14:56:34 +0100235 "arm_compute/core/NEON/kernels/assembly/"])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000236
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100237 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000238
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000239 if env['estate'] == '32':
Pablo Telloeb82fd22018-02-23 13:43:50 +0000240 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a32_*/*.cpp')
241
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000242 if env['estate'] == '64':
Pablo Telloeb82fd22018-02-23 13:43:50 +0000243 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a64_*/*.cpp')
Georgios Pinitas421405b2018-10-26 19:05:32 +0100244 if "sve" in env['arch']:
245 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/sve_*/*.cpp')
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100246
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100247 runtime_files += Glob('src/runtime/NEON/*.cpp')
248 runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100249 runtime_files += Glob('src/runtime/NEON/functions/assembly/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100250
Anthony Barbier7068f992017-10-26 15:23:08 +0100251if env['gles_compute']:
252 if env['os'] != 'android':
253 arm_compute_env.Append(CPPPATH = ["#opengles-3.1/include", "#opengles-3.1/mali_include"])
254
255 core_files += Glob('src/core/GLES_COMPUTE/*.cpp')
256 core_files += Glob('src/core/GLES_COMPUTE/kernels/*.cpp')
257
258 runtime_files += Glob('src/runtime/GLES_COMPUTE/*.cpp')
259 runtime_files += Glob('src/runtime/GLES_COMPUTE/functions/*.cpp')
260
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100261 graph_files += Glob('src/graph/backends/GLES/*.cpp')
Anthony Barbierb4670212018-05-18 16:55:39 +0100262if env['tracing']:
263 arm_compute_env.Append(CPPDEFINES = ['ARM_COMPUTE_TRACING_ENABLED'])
264else:
265 # Remove TracePoint files if tracing is disabled:
266 core_files = [ f for f in core_files if not "TracePoint" in str(f)]
267 runtime_files = [ f for f in runtime_files if not "TracePoint" in str(f)]
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100268
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100269bootcode_o = []
270if env['os'] == 'bare_metal':
271 bootcode_files = Glob('bootcode/*.s')
272 bootcode_o = build_bootcode_objs(bootcode_files)
273Export('bootcode_o')
274
Anthony Barbierab490732017-12-05 13:32:37 +0000275arm_compute_core_a = build_library('arm_compute_core-static', core_files, static=True)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100276Export('arm_compute_core_a')
277
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100278if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbierab490732017-12-05 13:32:37 +0000279 arm_compute_core_so = build_library('arm_compute_core', core_files, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100280 Export('arm_compute_core_so')
281
Anthony Barbierab490732017-12-05 13:32:37 +0000282arm_compute_a = build_library('arm_compute-static', runtime_files, static=True, libs = [ arm_compute_core_a ])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100283Export('arm_compute_a')
284
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100285if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbierab490732017-12-05 13:32:37 +0000286 arm_compute_so = build_library('arm_compute', runtime_files, static=False, libs = [ "arm_compute_core" ])
Anthony Barbierb2881fc2017-09-29 17:12:12 +0100287 Depends(arm_compute_so, arm_compute_core_so)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100288 Export('arm_compute_so')
289
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100290arm_compute_graph_a = build_library('arm_compute_graph-static', graph_files, static=True, libs = [ arm_compute_a])
291Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000292
293if env['os'] != 'bare_metal' and not env['standalone']:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100294 arm_compute_graph_so = build_library('arm_compute_graph', graph_files, static=False, libs = [ "arm_compute" , "arm_compute_core"])
Georgios Pinitas9873ea32017-12-05 15:28:55 +0000295 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100296 Export('arm_compute_graph_so')
297
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100298if env['standalone']:
299 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
300else:
301 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
302
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100303Default(alias)
304
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100305if env['standalone']:
306 Depends([alias,arm_compute_core_a], generate_embed)
307else:
308 Depends([alias,arm_compute_core_so, arm_compute_core_a], generate_embed)