blob: bc4aa4ccb701deafb84416682a4ecc52ee74aeb2 [file] [log] [blame]
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01001# Copyright (c) 2016, 2017 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
26
morgolock26314d22020-11-19 18:42:37 +000027VERSION = "v20.11"
morgolock4bee61e2020-11-19 15:27:30 +000028LIBRARY_VERSION_MAJOR = 21
Sang-Hoon Park6d0b3842020-08-14 14:48:08 +010029LIBRARY_VERSION_MINOR = 0
Georgios Pinitas35fcc432020-03-26 18:47:46 +000030LIBRARY_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 else:
Anthony Barbierb2881fc2017-09-29 17:12:12 +010052 obj = arm_compute_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000054 obj = install_lib(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055 Default(obj)
56 return obj
57
58def resolve_includes(target, source, env):
59 # File collection
60 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
61
62 # Include pattern
63 pattern = re.compile("#include \"(.*)\"")
64
65 # Get file contents
66 files = []
67 for i in range(len(source)):
68 src = source[i]
69 dst = target[i]
Michalis Spyrou2d0e5212019-04-11 15:19:52 +010070 contents = src.get_contents().decode('utf-8').splitlines()
Anthony Barbier6ff3b192017-09-04 18:44:23 +010071 entry = FileEntry(target_name=dst, file_contents=contents)
72 files.append((os.path.basename(src.get_path()),entry))
73
74 # Create dictionary of tupled list
75 files_dict = dict(files)
76
77 # Check for includes (can only be files in the same folder)
78 final_files = []
79 for file in files:
80 done = False
81 tmp_file = file[1].file_contents
82 while not done:
83 file_count = 0
84 updated_file = []
85 for line in tmp_file:
86 found = pattern.search(line)
87 if found:
88 include_file = found.group(1)
89 data = files_dict[include_file].file_contents
90 updated_file.extend(data)
91 else:
92 updated_file.append(line)
93 file_count += 1
94
95 # Check if all include are replaced.
96 if file_count == len(tmp_file):
97 done = True
98
99 # Update temp file
100 tmp_file = updated_file
101
102 # Append and prepend string literal identifiers and add expanded file to final list
103 tmp_file.insert(0, "R\"(\n")
104 tmp_file.append("\n)\"")
105 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
106 final_files.append((file[0], entry))
107
108 # Write output files
109 for file in final_files:
110 with open(file[1].target_name.get_path(), 'w+') as out_file:
111 out_file.write( "\n".join( file[1].file_contents ))
112
113def create_version_file(target, source, env):
114# Generate string with build options library version to embed in the library:
115 try:
116 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
117 except (OSError, subprocess.CalledProcessError):
118 git_hash="unknown"
119
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100120 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
121 with open(target[0].get_path(), "w") as fd:
122 fd.write(build_info)
123
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100124arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100125version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
126arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000127
128# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100129generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000130if env['opencl'] and env['embed_kernels']:
131 cl_files = Glob('src/core/CL/cl_kernels/*.cl')
132 cl_files += Glob('src/core/CL/cl_kernels/*.h')
133
134 embed_files = [ f.get_path()+"embed" for f in cl_files ]
135 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
136
137 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
138
139if env['gles_compute'] and env['embed_kernels']:
140 cs_files = Glob('src/core/GLES_COMPUTE/cs_shaders/*.cs')
141 cs_files += Glob('src/core/GLES_COMPUTE/cs_shaders/*.h')
142
143 embed_files = [ f.get_path()+"embed" for f in cs_files ]
144 arm_compute_env.Append(CPPPATH =[Dir("./src/core/GLES_COMPUTE/").path] )
145
146 generate_embed.append(arm_compute_env.Command(embed_files, cs_files, action=resolve_includes))
147
148Default(generate_embed)
149if env["build"] == "embed_only":
150 Return()
151
Georgios Pinitas35fcc432020-03-26 18:47:46 +0000152# Append version defines for semantic versioning
153arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
154 ('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
155 ('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
156
157
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000158# Don't allow undefined references in the libraries:
Michalis Spyrou989f1b52018-01-23 16:47:45 +0000159arm_compute_env.Append(LINKFLAGS=['-Wl,--no-undefined'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100160arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
161
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100162arm_compute_env.Append(LIBS = ['dl'])
163
164core_files = Glob('src/core/*.cpp')
165core_files += Glob('src/core/CPP/*.cpp')
166core_files += Glob('src/core/CPP/kernels/*.cpp')
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100167core_files += Glob('src/core/helpers/*.cpp')
Sang-Hoon Park3687ee12020-06-24 13:34:04 +0100168core_files += Glob('src/core/utils/*.cpp')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000169core_files += Glob('src/core/utils/helpers/*.cpp')
170core_files += Glob('src/core/utils/io/*.cpp')
171core_files += Glob('src/core/utils/quantization/*.cpp')
Georgios Pinitasb8d5b952019-05-16 14:13:03 +0100172core_files += Glob('src/core/utils/misc/*.cpp')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000173if env["logging"]:
174 core_files += Glob('src/core/utils/logging/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100175
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100176runtime_files = Glob('src/runtime/*.cpp')
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000177runtime_files += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp')
178runtime_files += Glob('src/runtime/CPP/functions/*.cpp')
179
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100180# CLHarrisCorners uses the Scheduler to run CPP kernels
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100181runtime_files += Glob('src/runtime/CPP/SingleThreadScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100182
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100183graph_files = Glob('src/graph/*.cpp')
184graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000185
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100186if env['cppthreads']:
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100187 runtime_files += Glob('src/runtime/CPP/CPPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100188
189if env['openmp']:
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100190 runtime_files += Glob('src/runtime/OMP/OMPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100191
192if env['opencl']:
193 core_files += Glob('src/core/CL/*.cpp')
194 core_files += Glob('src/core/CL/kernels/*.cpp')
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000195 core_files += Glob('src/core/CL/gemm/*.cpp')
Gian Marco Iodice06be6f82019-06-24 17:47:51 +0100196 core_files += Glob('src/core/CL/gemm/native/*.cpp')
Gian Marco Iodice926afe12019-03-19 11:44:13 +0000197 core_files += Glob('src/core/CL/gemm/reshaped/*.cpp')
198 core_files += Glob('src/core/CL/gemm/reshaped_only_rhs/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100199
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100200 runtime_files += Glob('src/runtime/CL/*.cpp')
201 runtime_files += Glob('src/runtime/CL/functions/*.cpp')
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +0000202 runtime_files += Glob('src/runtime/CL/gemm/*.cpp')
Georgios Pinitasc0d1c862018-03-23 15:13:15 +0000203 runtime_files += Glob('src/runtime/CL/tuners/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100204
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100205 graph_files += Glob('src/graph/backends/CL/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000206
207
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100208if env['neon']:
209 core_files += Glob('src/core/NEON/*.cpp')
210 core_files += Glob('src/core/NEON/kernels/*.cpp')
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100211 core_files += Glob('src/core/NEON/kernels/assembly/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100212
Pablo Telloeb82fd22018-02-23 13:43:50 +0000213 core_files += Glob('src/core/NEON/kernels/arm_gemm/*.cpp')
214
Georgios Pinitas30271c72019-06-24 14:56:34 +0100215 # build winograd/depthwise sources for either v7a / v8a
Georgios Pinitas4074c992018-01-30 18:13:46 +0000216 core_files += Glob('src/core/NEON/kernels/convolution/*/*.cpp')
217 core_files += Glob('src/core/NEON/kernels/convolution/winograd/*/*.cpp')
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100218 arm_compute_env.Append(CPPPATH = ["src/core/NEON/kernels/convolution/common/",
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100219 "src/core/NEON/kernels/convolution/winograd/",
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100220 "src/core/NEON/kernels/convolution/depthwise/",
221 "src/core/NEON/kernels/assembly/",
Georgios Pinitas30271c72019-06-24 14:56:34 +0100222 "arm_compute/core/NEON/kernels/assembly/"])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000223
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100224 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000225
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000226 if env['estate'] == '32':
Pablo Telloeb82fd22018-02-23 13:43:50 +0000227 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a32_*/*.cpp')
228
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000229 if env['estate'] == '64':
Pablo Telloeb82fd22018-02-23 13:43:50 +0000230 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a64_*/*.cpp')
Georgios Pinitas421405b2018-10-26 19:05:32 +0100231 if "sve" in env['arch']:
232 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/sve_*/*.cpp')
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100233
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100234 if any(i in env['data_type_support'] for i in ['all', 'fp16']):
235 core_files += Glob('src/core/NEON/kernels/*/impl/fp16_*.cpp')
236 if any(i in env['data_type_support'] for i in ['all', 'fp32']):
237 core_files += Glob('src/core/NEON/kernels/*/impl/fp32_*.cpp')
Michalis Spyrouc4d45552020-10-19 12:41:30 +0100238 if any(i in env['data_type_support'] for i in ['all', 'qasymm8']):
239 core_files += Glob('src/core/NEON/kernels/*/impl/qasymm8_neon*.cpp')
240 if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']):
241 core_files += Glob('src/core/NEON/kernels/*/impl/qasymm8_signed_*.cpp')
242 if any(i in env['data_type_support'] for i in ['all', 'qsymm16']):
243 core_files += Glob('src/core/NEON/kernels/*/impl/qsymm16_*.cpp')
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100244
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100245 runtime_files += Glob('src/runtime/NEON/*.cpp')
246 runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100247 runtime_files += Glob('src/runtime/NEON/functions/assembly/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100248
Anthony Barbier7068f992017-10-26 15:23:08 +0100249if env['gles_compute']:
250 if env['os'] != 'android':
251 arm_compute_env.Append(CPPPATH = ["#opengles-3.1/include", "#opengles-3.1/mali_include"])
252
253 core_files += Glob('src/core/GLES_COMPUTE/*.cpp')
254 core_files += Glob('src/core/GLES_COMPUTE/kernels/*.cpp')
255
256 runtime_files += Glob('src/runtime/GLES_COMPUTE/*.cpp')
257 runtime_files += Glob('src/runtime/GLES_COMPUTE/functions/*.cpp')
258
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100259 graph_files += Glob('src/graph/backends/GLES/*.cpp')
Anthony Barbierb4670212018-05-18 16:55:39 +0100260if env['tracing']:
261 arm_compute_env.Append(CPPDEFINES = ['ARM_COMPUTE_TRACING_ENABLED'])
262else:
263 # Remove TracePoint files if tracing is disabled:
264 core_files = [ f for f in core_files if not "TracePoint" in str(f)]
265 runtime_files = [ f for f in runtime_files if not "TracePoint" in str(f)]
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100266
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100267bootcode_o = []
268if env['os'] == 'bare_metal':
269 bootcode_files = Glob('bootcode/*.s')
270 bootcode_o = build_bootcode_objs(bootcode_files)
271Export('bootcode_o')
272
Anthony Barbierab490732017-12-05 13:32:37 +0000273arm_compute_core_a = build_library('arm_compute_core-static', core_files, static=True)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100274Export('arm_compute_core_a')
275
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100276if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbierab490732017-12-05 13:32:37 +0000277 arm_compute_core_so = build_library('arm_compute_core', core_files, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100278 Export('arm_compute_core_so')
279
Anthony Barbierab490732017-12-05 13:32:37 +0000280arm_compute_a = build_library('arm_compute-static', runtime_files, static=True, libs = [ arm_compute_core_a ])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100281Export('arm_compute_a')
282
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100283if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbierab490732017-12-05 13:32:37 +0000284 arm_compute_so = build_library('arm_compute', runtime_files, static=False, libs = [ "arm_compute_core" ])
Anthony Barbierb2881fc2017-09-29 17:12:12 +0100285 Depends(arm_compute_so, arm_compute_core_so)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100286 Export('arm_compute_so')
287
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100288arm_compute_graph_a = build_library('arm_compute_graph-static', graph_files, static=True, libs = [ arm_compute_a])
289Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000290
291if env['os'] != 'bare_metal' and not env['standalone']:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100292 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 +0000293 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100294 Export('arm_compute_graph_so')
295
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100296if env['standalone']:
297 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
298else:
299 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
300
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100301Default(alias)
302
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100303if env['standalone']:
304 Depends([alias,arm_compute_core_a], generate_embed)
305else:
306 Depends([alias,arm_compute_core_so, arm_compute_core_a], generate_embed)