blob: e57dd2390c33b5a6153f242cd011f356b6c008ca [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
Isabella Gottardicacb8782019-02-12 14:28:35 +000027VERSION = "v19.02"
28SONAME_VERSION="14.0.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
Anthony Barbierb2881fc2017-09-29 17:12:12 +010034def build_library(name, sources, static=False, libs=[]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035 if static:
Anthony Barbierb2881fc2017-09-29 17:12:12 +010036 obj = arm_compute_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037 else:
38 if env['set_soname']:
Anthony Barbierb2881fc2017-09-29 17:12:12 +010039 obj = arm_compute_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040
41 symlinks = []
42 # Manually delete symlinks or SCons will get confused:
43 directory = os.path.dirname(obj[0].path)
44 library_prefix = obj[0].path[:-(1 + len(SONAME_VERSION))]
45 real_lib = "%s.%s" % (library_prefix, SONAME_VERSION)
46
Anthony Barbier4ead11a2018-08-06 09:25:36 +010047 for f in Glob("#%s.*" % library_prefix):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 if str(f) != real_lib:
49 symlinks.append("%s/%s" % (directory,str(f)))
50
51 clean = arm_compute_env.Command('clean-%s' % str(obj[0]), [], Delete(symlinks))
52 Default(clean)
53 Depends(obj, clean)
54 else:
Anthony Barbierb2881fc2017-09-29 17:12:12 +010055 obj = arm_compute_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000057 obj = install_lib(obj)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010058 Default(obj)
59 return obj
60
61def resolve_includes(target, source, env):
62 # File collection
63 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
64
65 # Include pattern
66 pattern = re.compile("#include \"(.*)\"")
67
68 # Get file contents
69 files = []
70 for i in range(len(source)):
71 src = source[i]
72 dst = target[i]
73 contents = src.get_contents().splitlines()
74 entry = FileEntry(target_name=dst, file_contents=contents)
75 files.append((os.path.basename(src.get_path()),entry))
76
77 # Create dictionary of tupled list
78 files_dict = dict(files)
79
80 # Check for includes (can only be files in the same folder)
81 final_files = []
82 for file in files:
83 done = False
84 tmp_file = file[1].file_contents
85 while not done:
86 file_count = 0
87 updated_file = []
88 for line in tmp_file:
89 found = pattern.search(line)
90 if found:
91 include_file = found.group(1)
92 data = files_dict[include_file].file_contents
93 updated_file.extend(data)
94 else:
95 updated_file.append(line)
96 file_count += 1
97
98 # Check if all include are replaced.
99 if file_count == len(tmp_file):
100 done = True
101
102 # Update temp file
103 tmp_file = updated_file
104
105 # Append and prepend string literal identifiers and add expanded file to final list
106 tmp_file.insert(0, "R\"(\n")
107 tmp_file.append("\n)\"")
108 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
109 final_files.append((file[0], entry))
110
111 # Write output files
112 for file in final_files:
113 with open(file[1].target_name.get_path(), 'w+') as out_file:
114 out_file.write( "\n".join( file[1].file_contents ))
115
116def create_version_file(target, source, env):
117# Generate string with build options library version to embed in the library:
118 try:
119 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
120 except (OSError, subprocess.CalledProcessError):
121 git_hash="unknown"
122
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100123 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
124 with open(target[0].get_path(), "w") as fd:
125 fd.write(build_info)
126
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100127arm_compute_env = env.Clone()
Anthony Barbier0e72c692018-08-24 11:22:08 +0100128version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
129arm_compute_env.AlwaysBuild(version_file)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000130
131# Generate embed files
Anthony Barbier0e72c692018-08-24 11:22:08 +0100132generate_embed = [ version_file ]
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000133if env['opencl'] and env['embed_kernels']:
134 cl_files = Glob('src/core/CL/cl_kernels/*.cl')
135 cl_files += Glob('src/core/CL/cl_kernels/*.h')
136
137 embed_files = [ f.get_path()+"embed" for f in cl_files ]
138 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
139
140 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
141
142if env['gles_compute'] and env['embed_kernels']:
143 cs_files = Glob('src/core/GLES_COMPUTE/cs_shaders/*.cs')
144 cs_files += Glob('src/core/GLES_COMPUTE/cs_shaders/*.h')
145
146 embed_files = [ f.get_path()+"embed" for f in cs_files ]
147 arm_compute_env.Append(CPPPATH =[Dir("./src/core/GLES_COMPUTE/").path] )
148
149 generate_embed.append(arm_compute_env.Command(embed_files, cs_files, action=resolve_includes))
150
151Default(generate_embed)
152if env["build"] == "embed_only":
153 Return()
154
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000155# Don't allow undefined references in the libraries:
Michalis Spyrou989f1b52018-01-23 16:47:45 +0000156arm_compute_env.Append(LINKFLAGS=['-Wl,--no-undefined'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100157arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
158
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100159arm_compute_env.Append(LIBS = ['dl'])
160
161core_files = Glob('src/core/*.cpp')
162core_files += Glob('src/core/CPP/*.cpp')
163core_files += Glob('src/core/CPP/kernels/*.cpp')
Michalis Spyrou7043d362018-12-03 13:58:32 +0000164core_files += Glob('src/core/utils/helpers/*.cpp')
165core_files += Glob('src/core/utils/io/*.cpp')
166core_files += Glob('src/core/utils/quantization/*.cpp')
167if env["logging"]:
168 core_files += Glob('src/core/utils/logging/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100169
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100170runtime_files = Glob('src/runtime/*.cpp')
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000171runtime_files += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp')
172runtime_files += Glob('src/runtime/CPP/functions/*.cpp')
173
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100174# CLHarrisCorners uses the Scheduler to run CPP kernels
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100175runtime_files += Glob('src/runtime/CPP/SingleThreadScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100176
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100177graph_files = Glob('src/graph/*.cpp')
178graph_files += Glob('src/graph/*/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000179
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100180if env['cppthreads']:
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100181 runtime_files += Glob('src/runtime/CPP/CPPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100182
183if env['openmp']:
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100184 runtime_files += Glob('src/runtime/OMP/OMPScheduler.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100185
186if env['opencl']:
187 core_files += Glob('src/core/CL/*.cpp')
188 core_files += Glob('src/core/CL/kernels/*.cpp')
189
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100190 runtime_files += Glob('src/runtime/CL/*.cpp')
191 runtime_files += Glob('src/runtime/CL/functions/*.cpp')
Georgios Pinitasc0d1c862018-03-23 15:13:15 +0000192 runtime_files += Glob('src/runtime/CL/tuners/*.cpp')
Gian Marco Iodice90313eb2019-01-16 15:40:25 +0000193 runtime_files += Glob('src/runtime/CL/gemm_reshaped/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100194
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100195 graph_files += Glob('src/graph/backends/CL/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000196
197
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100198if env['neon']:
199 core_files += Glob('src/core/NEON/*.cpp')
200 core_files += Glob('src/core/NEON/kernels/*.cpp')
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100201 core_files += Glob('src/core/NEON/kernels/assembly/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100202
Pablo Telloeb82fd22018-02-23 13:43:50 +0000203 core_files += Glob('src/core/NEON/kernels/arm_gemm/*.cpp')
204
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000205 # build winograd sources for either v7a / v8a
Georgios Pinitas4074c992018-01-30 18:13:46 +0000206 core_files += Glob('src/core/NEON/kernels/convolution/*/*.cpp')
207 core_files += Glob('src/core/NEON/kernels/convolution/winograd/*/*.cpp')
Pablo Tello11c3b332018-01-25 15:05:13 +0000208 arm_compute_env.Append(CPPPATH = ["arm_compute/core/NEON/kernels/winograd/", "arm_compute/core/NEON/kernels/assembly/"])
Pablo Tello9ceebbe2018-01-10 16:44:13 +0000209
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100210 graph_files += Glob('src/graph/backends/NEON/*.cpp')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000211
Moritz Pflanzer80373f62017-09-15 10:42:58 +0100212 if env['arch'] == "armv7a":
Pablo Telloeb82fd22018-02-23 13:43:50 +0000213 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a32_*/*.cpp')
214
Moritz Pflanzer80373f62017-09-15 10:42:58 +0100215
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100216 if "arm64-v8" in env['arch']:
Pablo Telloeb82fd22018-02-23 13:43:50 +0000217 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a64_*/*.cpp')
Georgios Pinitas421405b2018-10-26 19:05:32 +0100218 if "sve" in env['arch']:
219 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/sve_*/*.cpp')
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100220
Anthony Barbier8e6faf12017-08-01 17:03:19 +0100221 runtime_files += Glob('src/runtime/NEON/*.cpp')
222 runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100223 runtime_files += Glob('src/runtime/NEON/functions/assembly/*.cpp')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100224
Anthony Barbier7068f992017-10-26 15:23:08 +0100225if env['gles_compute']:
226 if env['os'] != 'android':
227 arm_compute_env.Append(CPPPATH = ["#opengles-3.1/include", "#opengles-3.1/mali_include"])
228
229 core_files += Glob('src/core/GLES_COMPUTE/*.cpp')
230 core_files += Glob('src/core/GLES_COMPUTE/kernels/*.cpp')
231
232 runtime_files += Glob('src/runtime/GLES_COMPUTE/*.cpp')
233 runtime_files += Glob('src/runtime/GLES_COMPUTE/functions/*.cpp')
234
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100235 graph_files += Glob('src/graph/backends/GLES/*.cpp')
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100236
Anthony Barbierab490732017-12-05 13:32:37 +0000237arm_compute_core_a = build_library('arm_compute_core-static', core_files, static=True)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100238Export('arm_compute_core_a')
239
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100240if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbierab490732017-12-05 13:32:37 +0000241 arm_compute_core_so = build_library('arm_compute_core', core_files, static=False)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100242 Export('arm_compute_core_so')
243
Anthony Barbierab490732017-12-05 13:32:37 +0000244arm_compute_a = build_library('arm_compute-static', runtime_files, static=True, libs = [ arm_compute_core_a ])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100245Export('arm_compute_a')
246
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100247if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbierab490732017-12-05 13:32:37 +0000248 arm_compute_so = build_library('arm_compute', runtime_files, static=False, libs = [ "arm_compute_core" ])
Anthony Barbierb2881fc2017-09-29 17:12:12 +0100249 Depends(arm_compute_so, arm_compute_core_so)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100250 Export('arm_compute_so')
251
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100252arm_compute_graph_a = build_library('arm_compute_graph-static', graph_files, static=True, libs = [ arm_compute_a])
253Export('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000254
255if env['os'] != 'bare_metal' and not env['standalone']:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100256 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 +0000257 Depends(arm_compute_graph_so, arm_compute_so)
Anthony Barbier2a07e182017-08-04 18:20:27 +0100258 Export('arm_compute_graph_so')
259
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100260if env['standalone']:
261 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
262else:
263 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
264
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100265Default(alias)
266
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100267if env['standalone']:
268 Depends([alias,arm_compute_core_a], generate_embed)
269else:
270 Depends([alias,arm_compute_core_so, arm_compute_core_a], generate_embed)