1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
# Copyright (c) 2016, 2017 Arm Limited.
#
# SPDX-License-Identifier: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import collections
import os.path
import re
import subprocess
VERSION = "v20.08"
LIBRARY_VERSION_MAJOR = 20
LIBRARY_VERSION_MINOR = 0
LIBRARY_VERSION_PATCH = 0
SONAME_VERSION = str(LIBRARY_VERSION_MAJOR) + "." + str(LIBRARY_VERSION_MINOR) + "." + str(LIBRARY_VERSION_PATCH)
Import('env')
Import('vars')
Import('install_lib')
def build_bootcode_objs(sources):
arm_compute_env.Append(ASFLAGS = "-I bootcode/")
obj = arm_compute_env.Object(sources)
obj = install_lib(obj)
Default(obj)
return obj
def build_library(name, sources, static=False, libs=[]):
if static:
obj = arm_compute_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
else:
if env['set_soname']:
obj = arm_compute_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
symlinks = []
# Manually delete symlinks or SCons will get confused:
directory = os.path.dirname(obj[0].path)
library_prefix = obj[0].path[:-(1 + len(SONAME_VERSION))]
real_lib = "%s.%s" % (library_prefix, SONAME_VERSION)
for f in Glob("#%s.*" % library_prefix):
if str(f) != real_lib:
symlinks.append("%s/%s" % (directory,str(f)))
clean = arm_compute_env.Command('clean-%s' % str(obj[0]), [], Delete(symlinks))
Default(clean)
Depends(obj, clean)
else:
obj = arm_compute_env.SharedLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
obj = install_lib(obj)
Default(obj)
return obj
def resolve_includes(target, source, env):
# File collection
FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
# Include pattern
pattern = re.compile("#include \"(.*)\"")
# Get file contents
files = []
for i in range(len(source)):
src = source[i]
dst = target[i]
contents = src.get_contents().decode('utf-8').splitlines()
entry = FileEntry(target_name=dst, file_contents=contents)
files.append((os.path.basename(src.get_path()),entry))
# Create dictionary of tupled list
files_dict = dict(files)
# Check for includes (can only be files in the same folder)
final_files = []
for file in files:
done = False
tmp_file = file[1].file_contents
while not done:
file_count = 0
updated_file = []
for line in tmp_file:
found = pattern.search(line)
if found:
include_file = found.group(1)
data = files_dict[include_file].file_contents
updated_file.extend(data)
else:
updated_file.append(line)
file_count += 1
# Check if all include are replaced.
if file_count == len(tmp_file):
done = True
# Update temp file
tmp_file = updated_file
# Append and prepend string literal identifiers and add expanded file to final list
tmp_file.insert(0, "R\"(\n")
tmp_file.append("\n)\"")
entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
final_files.append((file[0], entry))
# Write output files
for file in final_files:
with open(file[1].target_name.get_path(), 'w+') as out_file:
out_file.write( "\n".join( file[1].file_contents ))
def create_version_file(target, source, env):
# Generate string with build options library version to embed in the library:
git_hash="unknown"
build_info = "\"arm_compute_version=%s Build options: %s Git hash=%s\"" % (VERSION, vars.args, git_hash.strip())
with open(target[0].get_path(), "w") as fd:
fd.write(build_info)
arm_compute_env = env.Clone()
version_file = arm_compute_env.Command("src/core/arm_compute_version.embed", "", action=create_version_file)
arm_compute_env.AlwaysBuild(version_file)
# Generate embed files
generate_embed = [ version_file ]
if env['opencl'] and env['embed_kernels']:
cl_files = Glob('src/core/CL/cl_kernels/*.cl')
cl_files += Glob('src/core/CL/cl_kernels/*.h')
embed_files = [ f.get_path()+"embed" for f in cl_files ]
arm_compute_env.Append(CPPPATH =[Dir("./src/core/CL/").path] )
generate_embed.append(arm_compute_env.Command(embed_files, cl_files, action=resolve_includes))
if env['gles_compute'] and env['embed_kernels']:
cs_files = Glob('src/core/GLES_COMPUTE/cs_shaders/*.cs')
cs_files += Glob('src/core/GLES_COMPUTE/cs_shaders/*.h')
embed_files = [ f.get_path()+"embed" for f in cs_files ]
arm_compute_env.Append(CPPPATH =[Dir("./src/core/GLES_COMPUTE/").path] )
generate_embed.append(arm_compute_env.Command(embed_files, cs_files, action=resolve_includes))
Default(generate_embed)
if env["build"] == "embed_only":
Return()
# Append version defines for semantic versioning
arm_compute_env.Append(CPPDEFINES = [('ARM_COMPUTE_VERSION_MAJOR', LIBRARY_VERSION_MAJOR),
('ARM_COMPUTE_VERSION_MINOR', LIBRARY_VERSION_MINOR),
('ARM_COMPUTE_VERSION_PATCH', LIBRARY_VERSION_PATCH)])
# Don't allow undefined references in the libraries:
arm_compute_env.Append(LINKFLAGS=['-Wl,--no-undefined'])
arm_compute_env.Append(CPPPATH =[Dir("./src/core/").path] )
arm_compute_env.Append(LIBS = ['dl'])
core_files = Glob('src/core/*.cpp')
core_files += Glob('src/core/CPP/*.cpp')
core_files += Glob('src/core/CPP/kernels/*.cpp')
core_files += Glob('src/core/utils/*.cpp')
core_files += Glob('src/core/utils/helpers/*.cpp')
core_files += Glob('src/core/utils/io/*.cpp')
core_files += Glob('src/core/utils/quantization/*.cpp')
core_files += Glob('src/core/utils/misc/*.cpp')
if env["logging"]:
core_files += Glob('src/core/utils/logging/*.cpp')
runtime_files = Glob('src/runtime/*.cpp')
runtime_files += Glob('src/runtime/CPP/ICPPSimpleFunction.cpp')
runtime_files += Glob('src/runtime/CPP/functions/*.cpp')
# CLHarrisCorners uses the Scheduler to run CPP kernels
runtime_files += Glob('src/runtime/CPP/SingleThreadScheduler.cpp')
graph_files = Glob('src/graph/*.cpp')
graph_files += Glob('src/graph/*/*.cpp')
if env['cppthreads']:
runtime_files += Glob('src/runtime/CPP/CPPScheduler.cpp')
if env['openmp']:
runtime_files += Glob('src/runtime/OMP/OMPScheduler.cpp')
if env['opencl']:
core_files += Glob('src/core/CL/*.cpp')
core_files += Glob('src/core/CL/kernels/*.cpp')
core_files += Glob('src/core/CL/gemm/*.cpp')
core_files += Glob('src/core/CL/gemm/native/*.cpp')
core_files += Glob('src/core/CL/gemm/reshaped/*.cpp')
core_files += Glob('src/core/CL/gemm/reshaped_only_rhs/*.cpp')
runtime_files += Glob('src/runtime/CL/*.cpp')
runtime_files += Glob('src/runtime/CL/functions/*.cpp')
runtime_files += Glob('src/runtime/CL/gemm/*.cpp')
runtime_files += Glob('src/runtime/CL/tuners/*.cpp')
graph_files += Glob('src/graph/backends/CL/*.cpp')
if env['neon']:
core_files += Glob('src/core/NEON/*.cpp')
core_files += Glob('src/core/NEON/kernels/*.cpp')
core_files += Glob('src/core/NEON/kernels/assembly/*.cpp')
core_files += Glob('src/core/NEON/kernels/arm_gemm/*.cpp')
# build winograd/depthwise sources for either v7a / v8a
core_files += Glob('src/core/NEON/kernels/convolution/*/*.cpp')
core_files += Glob('src/core/NEON/kernels/convolution/winograd/*/*.cpp')
arm_compute_env.Append(CPPPATH = ["arm_compute/core/NEON/kernels/convolution/common/",
"arm_compute/core/NEON/kernels/convolution/winograd/",
"arm_compute/core/NEON/kernels/convolution/depthwise/",
"src/core/NEON/kernels/assembly/",
"src/core/NEON/kernels/convolution/winograd/",
"arm_compute/core/NEON/kernels/assembly/"])
graph_files += Glob('src/graph/backends/NEON/*.cpp')
if env['estate'] == '32':
core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a32_*/*.cpp')
if env['estate'] == '64':
core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/a64_*/*.cpp')
if "sve" in env['arch']:
core_files += Glob('src/core/NEON/kernels/arm_gemm/kernels/sve_*/*.cpp')
runtime_files += Glob('src/runtime/NEON/*.cpp')
runtime_files += Glob('src/runtime/NEON/functions/*.cpp')
runtime_files += Glob('src/runtime/NEON/functions/assembly/*.cpp')
if env['gles_compute']:
if env['os'] != 'android':
arm_compute_env.Append(CPPPATH = ["#opengles-3.1/include", "#opengles-3.1/mali_include"])
core_files += Glob('src/core/GLES_COMPUTE/*.cpp')
core_files += Glob('src/core/GLES_COMPUTE/kernels/*.cpp')
runtime_files += Glob('src/runtime/GLES_COMPUTE/*.cpp')
runtime_files += Glob('src/runtime/GLES_COMPUTE/functions/*.cpp')
graph_files += Glob('src/graph/backends/GLES/*.cpp')
if env['tracing']:
arm_compute_env.Append(CPPDEFINES = ['ARM_COMPUTE_TRACING_ENABLED'])
else:
# Remove TracePoint files if tracing is disabled:
core_files = [ f for f in core_files if not "TracePoint" in str(f)]
runtime_files = [ f for f in runtime_files if not "TracePoint" in str(f)]
bootcode_o = []
if env['os'] == 'bare_metal':
bootcode_files = Glob('bootcode/*.s')
bootcode_o = build_bootcode_objs(bootcode_files)
Export('bootcode_o')
arm_compute_core_a = build_library('arm_compute_core-static', core_files, static=True)
Export('arm_compute_core_a')
if env['os'] != 'bare_metal' and not env['standalone']:
arm_compute_core_so = build_library('arm_compute_core', core_files, static=False)
Export('arm_compute_core_so')
arm_compute_a = build_library('arm_compute-static', runtime_files, static=True, libs = [ arm_compute_core_a ])
Export('arm_compute_a')
if env['os'] != 'bare_metal' and not env['standalone']:
arm_compute_so = build_library('arm_compute', runtime_files, static=False, libs = [ "arm_compute_core" ])
Depends(arm_compute_so, arm_compute_core_so)
Export('arm_compute_so')
arm_compute_graph_a = build_library('arm_compute_graph-static', graph_files, static=True, libs = [ arm_compute_a])
Export('arm_compute_graph_a')
if env['os'] != 'bare_metal' and not env['standalone']:
arm_compute_graph_so = build_library('arm_compute_graph', graph_files, static=False, libs = [ "arm_compute" , "arm_compute_core"])
Depends(arm_compute_graph_so, arm_compute_so)
Export('arm_compute_graph_so')
if env['standalone']:
alias = arm_compute_env.Alias("arm_compute", [arm_compute_a])
else:
alias = arm_compute_env.Alias("arm_compute", [arm_compute_a, arm_compute_so])
Default(alias)
if env['standalone']:
Depends([alias,arm_compute_core_a], generate_embed)
else:
Depends([alias,arm_compute_core_so, arm_compute_core_a], generate_embed)
|