1 # Copyright (c) 2016, 2017 ARM Limited.
3 # SPDX-License-Identifier: MIT
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:
12 # The above copyright notice and this permission notice shall be included in all
13 # copies or substantial portions of the Software.
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
28 SONAME_VERSION="11.0.0"
33 def build_library(name, sources, static=False, libs=[]):
35 obj = arm_compute_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
38 obj = arm_compute_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
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)
46 for f in Glob("#%s*" % library_prefix):
47 if str(f) != real_lib:
48 symlinks.append("%s/%s" % (directory,str(f)))
50 clean = arm_compute_env.Command('clean-%s' % str(obj[0]), [], Delete(symlinks))
54 obj = arm_compute_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
59 def resolve_includes(target, source, env):
61 FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
64 pattern = re.compile("#include \"(.*)\"")
68 for i in range(len(source)):
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))
75 # Create dictionary of tupled list
76 files_dict = dict(files)
78 # Check for includes (can only be files in the same folder)
82 tmp_file = file[1].file_contents
87 found = pattern.search(line)
89 include_file = found.group(1)
90 data = files_dict[include_file].file_contents
91 updated_file.extend(data)
93 updated_file.append(line)
96 # Check if all include are replaced.
97 if file_count == len(tmp_file):
101 tmp_file = updated_file
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))
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 ))
114 def create_version_file(target, source, env):
115 # Generate string with build options library version to embed in the library:
117 git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"])
118 except (OSError, subprocess.CalledProcessError):
121 version_filename = "%s/arm_compute_version.embed" % Dir("src/core").path
122 build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
123 with open(target[0].get_path(), "w") as fd:
126 arm_compute_env = env.Clone()
128 # Generate embed files
129 generate_embed = [ arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file) ]
130 if 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')
134 embed_files = [ f.get_path()+"embed" for f in cl_files ]
135 arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
137 generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
139 if 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')
143 embed_files = [ f.get_path()+"embed" for f in cs_files ]
144 arm_compute_env.Append(CPPPATH =[Dir("./src/core/GLES_COMPUTE/").path] )
146 generate_embed.append(arm_compute_env.Command(embed_files, cs_files, action=resolve_includes))
148 Default(generate_embed)
149 if env["build"] == "embed_only":
152 # Don't allow undefined references in the libraries:
153 arm_compute_env.Append(LINKFLAGS=['-Wl,--no-undefined'])
154 arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
156 arm_compute_env.Append(LIBS = ['dl'])
158 core_files = Glob('src/core/*.cpp')
159 core_files += Glob('src/core/CPP/*.cpp')
160 core_files += Glob('src/core/CPP/kernels/*.cpp')
161 core_files += Glob('src/core/utils/*/*.cpp')
163 runtime_files = Glob('src/runtime/*.cpp')
164 runtime_files += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp')
165 runtime_files += Glob('src/runtime/CPP/functions/*.cpp')
167 # CLHarrisCorners uses the Scheduler to run CPP kernels
168 runtime_files += Glob('src/runtime/CPP/SingleThreadScheduler.cpp')
170 graph_files = Glob('src/graph/*.cpp')
171 graph_files += Glob('src/graph/*/*.cpp')
173 if env['cppthreads']:
174 runtime_files += Glob('src/runtime/CPP/CPPScheduler.cpp')
177 runtime_files += Glob('src/runtime/OMP/OMPScheduler.cpp')
180 core_files += Glob('src/core/CL/*.cpp')
181 core_files += Glob('src/core/CL/kernels/*.cpp')
183 runtime_files += Glob('src/runtime/CL/*.cpp')
184 runtime_files += Glob('src/runtime/CL/functions/*.cpp')
185 runtime_files += Glob('src/runtime/CL/tuners/*.cpp')
187 graph_files += Glob('src/graph/backends/CL/*.cpp')
191 core_files += Glob('src/core/NEON/*.cpp')
192 core_files += Glob('src/core/NEON/kernels/*.cpp')
194 core_files += Glob('src/core/NEON/kernels/arm_gemm/*.cpp')
196 # build winograd sources for either v7a / v8a
197 core_files += Glob('src/core/NEON/kernels/convolution/*/*.cpp')
198 core_files += Glob('src/core/NEON/kernels/convolution/winograd/*/*.cpp')
199 arm_compute_env.Append(CPPPATH = ["arm_compute/core/NEON/kernels/winograd/", "arm_compute/core/NEON/kernels/assembly/"])
201 graph_files += Glob('src/graph/backends/NEON/*.cpp')
203 if env['arch'] == "armv7a":
204 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a32_*/*.cpp')
207 if "arm64-v8" in env['arch']:
208 core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a64_*/*.cpp')
210 runtime_files += Glob('src/runtime/NEON/*.cpp')
211 runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
213 if env['gles_compute']:
214 if env['os'] != 'android':
215 arm_compute_env.Append(CPPPATH = ["#opengles-3.1/include", "#opengles-3.1/mali_include"])
217 core_files += Glob('src/core/GLES_COMPUTE/*.cpp')
218 core_files += Glob('src/core/GLES_COMPUTE/kernels/*.cpp')
220 runtime_files += Glob('src/runtime/GLES_COMPUTE/*.cpp')
221 runtime_files += Glob('src/runtime/GLES_COMPUTE/functions/*.cpp')
223 graph_files += Glob('src/graph/backends/GLES/*.cpp')
225 arm_compute_core_a = build_library('arm_compute_core-static', core_files, static=True)
226 Export('arm_compute_core_a')
228 if env['os'] != 'bare_metal' and not env['standalone']:
229 arm_compute_core_so = build_library('arm_compute_core', core_files, static=False)
230 Export('arm_compute_core_so')
232 arm_compute_a = build_library('arm_compute-static', runtime_files, static=True, libs = [ arm_compute_core_a ])
233 Export('arm_compute_a')
235 if env['os'] != 'bare_metal' and not env['standalone']:
236 arm_compute_so = build_library('arm_compute', runtime_files, static=False, libs = [ "arm_compute_core" ])
237 Depends(arm_compute_so, arm_compute_core_so)
238 Export('arm_compute_so')
240 arm_compute_graph_a = build_library('arm_compute_graph-static', graph_files, static=True, libs = [ arm_compute_a])
241 Export('arm_compute_graph_a')
243 if env['os'] != 'bare_metal' and not env['standalone']:
244 arm_compute_graph_so = build_library('arm_compute_graph', graph_files, static=False, libs = [ "arm_compute" , "arm_compute_core"])
245 Depends(arm_compute_graph_so, arm_compute_so)
246 Export('arm_compute_graph_so')
248 if env['standalone']:
249 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
251 alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
255 if env['standalone']:
256 Depends([alias,arm_compute_core_a], generate_embed)
258 Depends([alias,arm_compute_core_so, arm_compute_core_a], generate_embed)