blob: e8c6891f1bdb259324d312ded109e20393e21e70 [file] [log] [blame]
Anthony Barbierdbdab852017-06-23 15:42:00 +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
Jenkins52ba29e2018-08-29 15:32:11 +000027VERSION = "v18.08"
28SONAME_VERSION="12.0.0"
Anthony Barbierdbdab852017-06-23 15:42:00 +010029
30Import('env')
31Import('vars')
32
Kaizenbf8b01d2017-10-12 14:26:51 +010033def build_library(name, sources, static=False, libs=[]):
Anthony Barbierdbdab852017-06-23 15:42:00 +010034 if static:
Kaizenbf8b01d2017-10-12 14:26:51 +010035 obj = arm_compute_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbierdbdab852017-06-23 15:42:00 +010036 else:
37 if env['set_soname']:
Kaizenbf8b01d2017-10-12 14:26:51 +010038 obj = arm_compute_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbierdbdab852017-06-23 15:42:00 +010039
40 symlinks = []
41 # Manually delete symlinks or SCons will get confused:
42 directory = os.path.dirname(obj[0].path)
43 library_prefix = obj[0].path[:-(1 + len(SONAME_VERSION))]
44 real_lib = "%s.%s" % (library_prefix, SONAME_VERSION)
45
Jenkins52ba29e2018-08-29 15:32:11 +000046 for f in Glob("#%s.*" % library_prefix):
Anthony Barbierdbdab852017-06-23 15:42:00 +010047 if str(f) != real_lib:
48 symlinks.append("%s/%s" % (directory,str(f)))
49
50 clean = arm_compute_env.Command('clean-%s' % str(obj[0]), [], Delete(symlinks))
51 Default(clean)
52 Depends(obj, clean)
53 else:
Kaizenbf8b01d2017-10-12 14:26:51 +010054 obj = arm_compute_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
Anthony Barbierdbdab852017-06-23 15:42:00 +010055
56 Default(obj)
57 return obj
58
59def resolve_includes(target, source, env):
60 # File collection
61 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
62
63 # Include pattern
64 pattern = re.compile("#include \"(.*)\"")
65
66 # Get file contents
67 files = []
68 for i in range(len(source)):
69 src = source[i]
70 dst = target[i]
71 contents = src.get_contents().splitlines()
72 entry = FileEntry(target_name=dst, file_contents=contents)
73 files.append((os.path.basename(src.get_path()),entry))
74
75 # Create dictionary of tupled list
76 files_dict = dict(files)
77
78 # Check for includes (can only be files in the same folder)
79 final_files = []
80 for file in files:
81 done = False
82 tmp_file = file[1].file_contents
83 while not done:
84 file_count = 0
85 updated_file = []
86 for line in tmp_file:
87 found = pattern.search(line)
88 if found:
89 include_file = found.group(1)
90 data = files_dict[include_file].file_contents
91 updated_file.extend(data)
92 else:
93 updated_file.append(line)
94 file_count += 1
95
96 # Check if all include are replaced.
97 if file_count == len(tmp_file):
98 done = True
99
100 # Update temp file
101 tmp_file = updated_file
102
103 # Append and prepend string literal identifiers and add expanded file to final list
104 tmp_file.insert(0, "R\"(\n")
105 tmp_file.append("\n)\"")
106 entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
107 final_files.append((file[0], entry))
108
109 # Write output files
110 for file in final_files:
111 with open(file[1].target_name.get_path(), 'w+') as out_file:
112 out_file.write( "\n".join( file[1].file_contents ))
113
114def create_version_file(target, source, env):
115# Generate string with build options library version to embed in the library:
116 try:
117 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
118 except (OSError, subprocess.CalledProcessError):
119 git_hash="unknown"
120
Anthony Barbierdbdab852017-06-23 15:42:00 +0100121 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
122 with open(target[0].get_path(), "w") as fd:
123 fd.write(build_info)
124
Anthony Barbierdbdab852017-06-23 15:42:00 +0100125arm_compute_env = env.Clone()
Jenkins52ba29e2018-08-29 15:32:11 +0000126version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
127arm_compute_env.AlwaysBuild(version_file)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100128
Anthony Barbier06ea0482018-02-22 15:45:35 +0000129# Generate embed files
Jenkins52ba29e2018-08-29 15:32:11 +0000130generate_embed = [ version_file ]
Anthony Barbier06ea0482018-02-22 15:45:35 +0000131if env['opencl'] and env['embed_kernels']:
132 cl_files = Glob('src/core/CL/cl_kernels/*.cl')
133 cl_files += Glob('src/core/CL/cl_kernels/*.h')
134
135 embed_files = [ f.get_path()+"embed" for f in cl_files ]
136 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
137
138 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
139
140if env['gles_compute'] and env['embed_kernels']:
141 cs_files = Glob('src/core/GLES_COMPUTE/cs_shaders/*.cs')
142 cs_files += Glob('src/core/GLES_COMPUTE/cs_shaders/*.h')
143
144 embed_files = [ f.get_path()+"embed" for f in cs_files ]
145 arm_compute_env.Append(CPPPATH =[Dir("./src/core/GLES_COMPUTE/").path] )
146
147 generate_embed.append(arm_compute_env.Command(embed_files, cs_files, action=resolve_includes))
148
149Default(generate_embed)
150if env["build"] == "embed_only":
151 Return()
152
153# Don't allow undefined references in the libraries:
154arm_compute_env.Append(LINKFLAGS=['-Wl,--no-undefined'])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100155arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
156
Anthony Barbierdbdab852017-06-23 15:42:00 +0100157arm_compute_env.Append(LIBS = ['dl'])
158
159core_files = Glob('src/core/*.cpp')
160core_files += Glob('src/core/CPP/*.cpp')
161core_files += Glob('src/core/CPP/kernels/*.cpp')
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000162core_files += Glob('src/core/utils/*/*.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100163
Kaizen8938bd32017-09-28 14:38:23 +0100164runtime_files = Glob('src/runtime/*.cpp')
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000165runtime_files += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp')
166runtime_files += Glob('src/runtime/CPP/functions/*.cpp')
167
Anthony Barbierdbdab852017-06-23 15:42:00 +0100168# CLHarrisCorners uses the Scheduler to run CPP kernels
Kaizen8938bd32017-09-28 14:38:23 +0100169runtime_files += Glob('src/runtime/CPP/SingleThreadScheduler.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100170
Jenkinsb3a371b2018-05-23 11:36:53 +0100171graph_files = Glob('src/graph/*.cpp')
172graph_files += Glob('src/graph/*/*.cpp')
173
Anthony Barbierdbdab852017-06-23 15:42:00 +0100174if env['cppthreads']:
Kaizen8938bd32017-09-28 14:38:23 +0100175 runtime_files += Glob('src/runtime/CPP/CPPScheduler.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100176
177if env['openmp']:
Kaizen8938bd32017-09-28 14:38:23 +0100178 runtime_files += Glob('src/runtime/OMP/OMPScheduler.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100179
180if env['opencl']:
181 core_files += Glob('src/core/CL/*.cpp')
182 core_files += Glob('src/core/CL/kernels/*.cpp')
183
Kaizen8938bd32017-09-28 14:38:23 +0100184 runtime_files += Glob('src/runtime/CL/*.cpp')
185 runtime_files += Glob('src/runtime/CL/functions/*.cpp')
Jenkinsb3a371b2018-05-23 11:36:53 +0100186 runtime_files += Glob('src/runtime/CL/tuners/*.cpp')
187
188 graph_files += Glob('src/graph/backends/CL/*.cpp')
189
Anthony Barbierdbdab852017-06-23 15:42:00 +0100190
Anthony Barbierdbdab852017-06-23 15:42:00 +0100191if env['neon']:
192 core_files += Glob('src/core/NEON/*.cpp')
193 core_files += Glob('src/core/NEON/kernels/*.cpp')
Jenkins52ba29e2018-08-29 15:32:11 +0000194 core_files += Glob('src/core/NEON/kernels/assembly/*.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100195
Jenkinsb3a371b2018-05-23 11:36:53 +0100196 core_files += Glob('src/core/NEON/kernels/arm_gemm/*.cpp')
197
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000198 # build winograd sources for either v7a / v8a
Anthony Barbier06ea0482018-02-22 15:45:35 +0000199 core_files += Glob('src/core/NEON/kernels/convolution/*/*.cpp')
200 core_files += Glob('src/core/NEON/kernels/convolution/winograd/*/*.cpp')
201 arm_compute_env.Append(CPPPATH = ["arm_compute/core/NEON/kernels/winograd/", "arm_compute/core/NEON/kernels/assembly/"])
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000202
Jenkinsb3a371b2018-05-23 11:36:53 +0100203 graph_files += Glob('src/graph/backends/NEON/*.cpp')
204
Kaizen8938bd32017-09-28 14:38:23 +0100205 if env['arch'] == "armv7a":
Jenkinsb3a371b2018-05-23 11:36:53 +0100206 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a32_*/*.cpp')
207
Kaizen8938bd32017-09-28 14:38:23 +0100208
209 if "arm64-v8" in env['arch']:
Jenkinsb3a371b2018-05-23 11:36:53 +0100210 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a64_*/*.cpp')
Kaizen8938bd32017-09-28 14:38:23 +0100211
212 runtime_files += Glob('src/runtime/NEON/*.cpp')
213 runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
Jenkins52ba29e2018-08-29 15:32:11 +0000214 runtime_files += Glob('src/runtime/NEON/functions/assembly/*.cpp')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100215
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000216if env['gles_compute']:
217 if env['os'] != 'android':
218 arm_compute_env.Append(CPPPATH = ["#opengles-3.1/include", "#opengles-3.1/mali_include"])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100219
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000220 core_files += Glob('src/core/GLES_COMPUTE/*.cpp')
221 core_files += Glob('src/core/GLES_COMPUTE/kernels/*.cpp')
222
223 runtime_files += Glob('src/runtime/GLES_COMPUTE/*.cpp')
224 runtime_files += Glob('src/runtime/GLES_COMPUTE/functions/*.cpp')
225
Jenkinsb3a371b2018-05-23 11:36:53 +0100226 graph_files += Glob('src/graph/backends/GLES/*.cpp')
227
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000228arm_compute_core_a = build_library('arm_compute_core-static', core_files, static=True)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100229Export('arm_compute_core_a')
230
Kaizen8938bd32017-09-28 14:38:23 +0100231if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000232 arm_compute_core_so = build_library('arm_compute_core', core_files, static=False)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100233 Export('arm_compute_core_so')
234
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000235arm_compute_a = build_library('arm_compute-static', runtime_files, static=True, libs = [ arm_compute_core_a ])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100236Export('arm_compute_a')
237
Kaizen8938bd32017-09-28 14:38:23 +0100238if env['os'] != 'bare_metal' and not env['standalone']:
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000239 arm_compute_so = build_library('arm_compute', runtime_files, static=False, libs = [ "arm_compute_core" ])
Kaizenbf8b01d2017-10-12 14:26:51 +0100240 Depends(arm_compute_so, arm_compute_core_so)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100241 Export('arm_compute_so')
242
Jenkinsb3a371b2018-05-23 11:36:53 +0100243arm_compute_graph_a = build_library('arm_compute_graph-static', graph_files, static=True, libs = [ arm_compute_a])
244Export('arm_compute_graph_a')
Kaizen8938bd32017-09-28 14:38:23 +0100245
Jenkinsb3a371b2018-05-23 11:36:53 +0100246if env['os'] != 'bare_metal' and not env['standalone']:
247 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 +0000248 Depends(arm_compute_graph_so, arm_compute_so)
Kaizen8938bd32017-09-28 14:38:23 +0100249 Export('arm_compute_graph_so')
250
Kaizen8938bd32017-09-28 14:38:23 +0100251if env['standalone']:
252 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
253else:
254 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
255
Anthony Barbierdbdab852017-06-23 15:42:00 +0100256Default(alias)
257
Kaizen8938bd32017-09-28 14:38:23 +0100258if env['standalone']:
259 Depends([alias,arm_compute_core_a], generate_embed)
260else:
261 Depends([alias,arm_compute_core_so, arm_compute_core_a], generate_embed)