blob: 78e36fe635a78f1ea560e455ead7c6fde5e4e82a [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
Michele Di Giorgio34df2e12020-03-04 12:45:50 +000027VERSION = "v20.02.1"
28SONAME_VERSION="18.1.0"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
30Import('env')
31Import('vars')
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000032Import('install_lib')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033
Michalis Spyrou748a7c82019-10-07 13:00:44 +010034def build_bootcode_objs(sources):
35
36 arm_compute_env.Append(ASFLAGS = "-I bootcode/")
37 obj = arm_compute_env.Object(sources)
38 obj = install_lib(obj)
39 Default(obj)
40 return obj
41
Anthony Barbierb2881fc2017-09-29 17:12:12 +010042def build_library(name, sources, static=False, libs=[]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043 if static:
Anthony Barbierb2881fc2017-09-29 17:12:12 +010044 obj = arm_compute_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010045 else:
46 if env['set_soname']:
Anthony Barbierb2881fc2017-09-29 17:12:12 +010047 obj = arm_compute_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048
49 symlinks = []
50 # Manually delete symlinks or SCons will get confused:
51 directory = os.path.dirname(obj[0].path)
52 library_prefix = obj[0].path[:-(1 + len(SONAME_VERSION))]
53 real_lib = "%s.%s" % (library_prefix, SONAME_VERSION)
54
Anthony Barbier4ead11a2018-08-06 09:25:36 +010055 for f in Glob("#%s.*" % library_prefix):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056 if str(f) != real_lib:
57 symlinks.append("%s/%s" % (directory,str(f)))
58
59 clean = arm_compute_env.Command('clean-%s' % str(obj[0]), [], Delete(symlinks))
60 Default(clean)
61 Depends(obj, clean)
62 else:
Anthony Barbierb2881fc2017-09-29 17:12:12 +010063 obj = arm_compute_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010064
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000065 obj = install_lib(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066 Default(obj)
67 return obj
68
69def resolve_includes(target, source, env):
70 # File collection
71 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
72
73 # Include pattern
74 pattern = re.compile("#include \"(.*)\"")
75
76 # Get file contents
77 files = []
78 for i in range(len(source)):
79 src = source[i]
80 dst = target[i]
Michalis Spyrou2d0e5212019-04-11 15:19:52 +010081 contents = src.get_contents().decode('utf-8').splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +010082 entry = FileEntry(target_name=dst, file_contents=contents)
83 files.append((os.path.basename(src.get_path()),entry))
84
85 # Create dictionary of tupled list
86 files_dict = dict(files)
87
88 # Check for includes (can only be files in the same folder)
89 final_files = []
90 for file in files:
91 done = False
92 tmp_file = file[1].file_contents
93 while not done:
94 file_count = 0
95 updated_file = []
96 for line in tmp_file:
97 found = pattern.search(line)
98 if found:
99 include_file = found.group(1)
100 data = files_dict[include_file].file_contents
101 updated_file.extend(data)
102 else:
103 updated_file.append(line)
104 file_count += 1
105
106 # Check if all include are replaced.
107 if file_count == len(tmp_file):
108 done = True
109
110 # Update temp file
111 tmp_file = updated_file
112
113 # Append and prepend string literal identifiers and add expanded file to final list
114 tmp_file.insert(0, "R\"(\n")
115 tmp_file.append("\n)\"")
116 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
117 final_files.append((file[0], entry))
118
119 # Write output files
120 for file in final_files:
121 with open(file[1].target_name.get_path(), 'w+') as out_file:
122 out_file.write( "\n".join( file[1].file_contents ))
123
124def create_version_file(target, source, env):
125# Generate string with build options library version to embed in the library:
126 try:
127 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
128 except (OSError, subprocess.CalledProcessError):
129 git_hash="unknown"
130
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
132 with open(target[0].get_path(), "w") as fd:
133 fd.write(build_info)
134
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100135arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100136version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
137arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000138
139# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100140generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000141if env['opencl'] and env['embed_kernels']:
142 cl_files = Glob('src/core/CL/cl_kernels/*.cl')
143 cl_files += Glob('src/core/CL/cl_kernels/*.h')
144
145 embed_files = [ f.get_path()+"embed" for f in cl_files ]
146 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
147
148 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
149
150if env['gles_compute'] and env['embed_kernels']:
151 cs_files = Glob('src/core/GLES_COMPUTE/cs_shaders/*.cs')
152 cs_files += Glob('src/core/GLES_COMPUTE/cs_shaders/*.h')
153
154 embed_files = [ f.get_path()+"embed" for f in cs_files ]
155 arm_compute_env.Append(CPPPATH =[Dir("./src/core/GLES_COMPUTE/").path] )
156
157 generate_embed.append(arm_compute_env.Command(embed_files, cs_files, action=resolve_includes))
158
159Default(generate_embed)
160if env["build"] == "embed_only":
161 Return()
162
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000163# Don't allow undefined references in the libraries:
Michalis Spyrou989f1b52018-01-23 16:47:45 +0000164arm_compute_env.Append(LINKFLAGS=['-Wl,--no-undefined'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100165arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
166
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100167arm_compute_env.Append(LIBS = ['dl'])
168
169core_files = Glob('src/core/*.cpp')
170core_files += Glob('src/core/CPP/*.cpp')
171core_files += Glob('src/core/CPP/kernels/*.cpp')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000172core_files += Glob('src/core/utils/helpers/*.cpp')
173core_files += Glob('src/core/utils/io/*.cpp')
174core_files += Glob('src/core/utils/quantization/*.cpp')
Georgios Pinitasb8d5b952019-05-16 14:13:03 +0100175core_files += Glob('src/core/utils/misc/*.cpp')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000176if env["logging"]:
177 core_files += Glob('src/core/utils/logging/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100178
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100179runtime_files = Glob('src/runtime/*.cpp')
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000180runtime_files += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp')
181runtime_files += Glob('src/runtime/CPP/functions/*.cpp')
182
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100183# CLHarrisCorners uses the Scheduler to run CPP kernels
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100184runtime_files += Glob('src/runtime/CPP/SingleThreadScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100185
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100186graph_files = Glob('src/graph/*.cpp')
187graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000188
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100189if env['cppthreads']:
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100190 runtime_files += Glob('src/runtime/CPP/CPPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100191
192if env['openmp']:
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100193 runtime_files += Glob('src/runtime/OMP/OMPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100194
195if env['opencl']:
196 core_files += Glob('src/core/CL/*.cpp')
197 core_files += Glob('src/core/CL/kernels/*.cpp')
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000198 core_files += Glob('src/core/CL/gemm/*.cpp')
Gian Marco Iodice06be6f82019-06-24 17:47:51 +0100199 core_files += Glob('src/core/CL/gemm/native/*.cpp')
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000200 core_files += Glob('src/core/CL/gemm/reshaped/*.cpp')
201 core_files += Glob('src/core/CL/gemm/reshaped_only_rhs/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100202
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100203 runtime_files += Glob('src/runtime/CL/*.cpp')
204 runtime_files += Glob('src/runtime/CL/functions/*.cpp')
Georgios Pinitasc0d1c862018-03-23 15:13:15 +0000205 runtime_files += Glob('src/runtime/CL/tuners/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100206
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100207 graph_files += Glob('src/graph/backends/CL/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000208
209
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100210if env['neon']:
211 core_files += Glob('src/core/NEON/*.cpp')
212 core_files += Glob('src/core/NEON/kernels/*.cpp')
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100213 core_files += Glob('src/core/NEON/kernels/assembly/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100214
Pablo Telloeb82fd22018-02-23 13:43:50 +0000215 core_files += Glob('src/core/NEON/kernels/arm_gemm/*.cpp')
216
Georgios Pinitas30271c72019-06-24 14:56:34 +0100217 # build winograd/depthwise sources for either v7a / v8a
Georgios Pinitas4074c992018-01-30 18:13:46 +0000218 core_files += Glob('src/core/NEON/kernels/convolution/*/*.cpp')
219 core_files += Glob('src/core/NEON/kernels/convolution/winograd/*/*.cpp')
Georgios Pinitas30271c72019-06-24 14:56:34 +0100220 arm_compute_env.Append(CPPPATH = ["arm_compute/core/NEON/kernels/convolution/common/",
221 "arm_compute/core/NEON/kernels/convolution/winograd/",
222 "arm_compute/core/NEON/kernels/convolution/depthwise/",
223 "arm_compute/core/NEON/kernels/assembly/"])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000224
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100225 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000226
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000227 if env['estate'] == '32':
Pablo Telloeb82fd22018-02-23 13:43:50 +0000228 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a32_*/*.cpp')
229
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000230 if env['estate'] == '64':
Pablo Telloeb82fd22018-02-23 13:43:50 +0000231 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a64_*/*.cpp')
Georgios Pinitas421405b2018-10-26 19:05:32 +0100232 if "sve" in env['arch']:
233 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/sve_*/*.cpp')
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100234
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100235 runtime_files += Glob('src/runtime/NEON/*.cpp')
236 runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100237 runtime_files += Glob('src/runtime/NEON/functions/assembly/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100238
Anthony Barbier7068f992017-10-26 15:23:08 +0100239if env['gles_compute']:
240 if env['os'] != 'android':
241 arm_compute_env.Append(CPPPATH = ["#opengles-3.1/include", "#opengles-3.1/mali_include"])
242
243 core_files += Glob('src/core/GLES_COMPUTE/*.cpp')
244 core_files += Glob('src/core/GLES_COMPUTE/kernels/*.cpp')
245
246 runtime_files += Glob('src/runtime/GLES_COMPUTE/*.cpp')
247 runtime_files += Glob('src/runtime/GLES_COMPUTE/functions/*.cpp')
248
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100249 graph_files += Glob('src/graph/backends/GLES/*.cpp')
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100250
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100251bootcode_o = []
252if env['os'] == 'bare_metal':
253 bootcode_files = Glob('bootcode/*.s')
254 bootcode_o = build_bootcode_objs(bootcode_files)
255Export('bootcode_o')
256
Anthony Barbierab490732017-12-05 13:32:37 +0000257arm_compute_core_a = build_library('arm_compute_core-static', core_files, static=True)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100258Export('arm_compute_core_a')
259
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100260if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbierab490732017-12-05 13:32:37 +0000261 arm_compute_core_so = build_library('arm_compute_core', core_files, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100262 Export('arm_compute_core_so')
263
Anthony Barbierab490732017-12-05 13:32:37 +0000264arm_compute_a = build_library('arm_compute-static', runtime_files, static=True, libs = [ arm_compute_core_a ])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100265Export('arm_compute_a')
266
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100267if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbierab490732017-12-05 13:32:37 +0000268 arm_compute_so = build_library('arm_compute', runtime_files, static=False, libs = [ "arm_compute_core" ])
Anthony Barbierb2881fc2017-09-29 17:12:12 +0100269 Depends(arm_compute_so, arm_compute_core_so)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100270 Export('arm_compute_so')
271
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100272arm_compute_graph_a = build_library('arm_compute_graph-static', graph_files, static=True, libs = [ arm_compute_a])
273Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000274
275if env['os'] != 'bare_metal' and not env['standalone']:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100276 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 +0000277 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100278 Export('arm_compute_graph_so')
279
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100280if env['standalone']:
281 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
282else:
283 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
284
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100285Default(alias)
286
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100287if env['standalone']:
288 Depends([alias,arm_compute_core_a], generate_embed)
289else:
290 Depends([alias,arm_compute_core_so, arm_compute_core_a], generate_embed)