| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright (c) 2017-2024 Arm Limited. |
| 5 |
# |
| 6 |
# SPDX-License-Identifier: MIT |
| 7 |
# |
| 8 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 |
# of this software and associated documentation files (the "Software"), to |
| 10 |
# deal in the Software without restriction, including without limitation the |
| 11 |
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 12 |
# sell copies of the Software, and to permit persons to whom the Software is |
| 13 |
# furnished to do so, subject to the following conditions: |
| 14 |
# |
| 15 |
# The above copyright notice and this permission notice shall be included in all |
| 16 |
# copies or substantial portions of the Software. |
| 17 |
# |
| 18 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 |
# SOFTWARE. |
| 25 |
import SCons |
| 26 |
import os.path |
| 27 |
|
| 28 |
Import('env') |
| 29 |
Import('install_bin') |
| 30 |
|
| 31 |
examples_env = env.Clone() |
| 32 |
|
| 33 |
examples_env.Append(CPPPATH = ["#"]) |
| 34 |
|
| 35 |
# Build examples |
| 36 |
utils = examples_env.Object("../utils/Utils.cpp") |
| 37 |
|
| 38 |
if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']: |
| 39 |
Import('arm_compute_graph_a') |
| 40 |
Import('arm_compute_a') |
| 41 |
arm_compute_libs = [ arm_compute_a ] |
| 42 |
arm_compute_graph_libs = arm_compute_libs # The graph library needs to be linked separately with --whole-archive |
| 43 |
arm_compute_dependency = arm_compute_a |
| 44 |
graph_dependency = [arm_compute_graph_a] |
| 45 |
else: |
| 46 |
Import('arm_compute_graph_so') |
| 47 |
Import('arm_compute_so') |
| 48 |
arm_compute_libs = ["arm_compute"] |
| 49 |
arm_compute_graph_libs = [ "arm_compute_graph" ] + arm_compute_libs |
| 50 |
arm_compute_dependency = arm_compute_so |
| 51 |
graph_dependency = [arm_compute_graph_so] |
| 52 |
|
| 53 |
extra_link_flags = [] |
| 54 |
|
| 55 |
if not env['os'] in ['windows','bare_metal'] : |
| 56 |
extra_link_flags += ['-fstack-protector-strong'] |
| 57 |
|
| 58 |
|
| 59 |
if env['os'] != 'windows' : |
| 60 |
load_whole_archive = '-Wl,--whole-archive' |
| 61 |
noload_whole_archive = '-Wl,--no-whole-archive' |
| 62 |
else: |
| 63 |
load_whole_archive = '/wholearchive' |
| 64 |
noload_whole_archive = '' |
| 65 |
|
| 66 |
if 'macos' in examples_env['os']: |
| 67 |
load_whole_archive = '-Wl,-force_load' |
| 68 |
noload_whole_archive = '' |
| 69 |
|
| 70 |
# Build graph examples |
| 71 |
graph_utils = examples_env.Object("../utils/GraphUtils.cpp") |
| 72 |
graph_utils += examples_env.Object("../utils/CommonGraphOptions.cpp") |
| 73 |
examples_libs = examples_env.get("LIBS",[]) |
| 74 |
for file in Glob("./graph_*.cpp"): |
| 75 |
example = os.path.basename(os.path.splitext(str(file))[0]) |
| 76 |
prog = None |
| 77 |
if env['os'] in ['android','windows', 'macos', 'bare_metal'] or env['standalone']: |
| 78 |
prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+[load_whole_archive, graph_dependency, noload_whole_archive] + extra_link_flags) |
| 79 |
Depends(prog, graph_dependency) |
| 80 |
prog = install_bin(prog) |
| 81 |
else: |
| 82 |
#-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies |
| 83 |
prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] ) |
| 84 |
Depends(prog, graph_dependency) |
| 85 |
prog = install_bin(prog) |
| 86 |
alias = examples_env.Alias(example, prog) |
| 87 |
Default(alias) |
| 88 |
|
| 89 |
if env['opencl'] and env['neon']: |
| 90 |
examples_env.Append(CPPDEFINES = ['ARM_COMPUTE_CL']) |
| 91 |
for file in Glob("./neoncl_*.cpp"): |
| 92 |
example = os.path.basename(os.path.splitext(str(file))[0]) |
| 93 |
prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs) |
| 94 |
Depends(prog, arm_compute_dependency) |
| 95 |
prog = install_bin(prog) |
| 96 |
alias = examples_env.Alias(example, prog) |
| 97 |
Default(alias) |
| 98 |
|
| 99 |
if env['opencl']: |
| 100 |
examples_env.Append(CPPDEFINES = ['ARM_COMPUTE_CL']) |
| 101 |
for file in Glob("./cl_*.cpp"): |
| 102 |
example = os.path.basename(os.path.splitext(str(file))[0]) |
| 103 |
prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs) |
| 104 |
Depends(prog, arm_compute_dependency) |
| 105 |
prog = install_bin(prog) |
| 106 |
alias = examples_env.Alias(example, prog) |
| 107 |
Default(alias) |
| 108 |
|
| 109 |
if env['gemm_tuner'] and env['opencl']: |
| 110 |
gemm_tuner_common_options = examples_env.Object("./gemm_tuner/CommonGemmExampleOptions.cpp") |
| 111 |
for file in Glob("./gemm_tuner/cl_*.cpp"): |
| 112 |
example = os.path.basename(os.path.splitext(str(file))[0]) |
| 113 |
example = os.path.join("gemm_tuner", example) |
| 114 |
if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']: |
| 115 |
prog = examples_env.Program(example, ["{}.cpp".format(example), utils, gemm_tuner_common_options], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+[load_whole_archive, graph_dependency, noload_whole_archive, '-fstack-protector-strong'] ) |
| 116 |
Depends(prog, graph_dependency) |
| 117 |
prog = install_bin(prog) |
| 118 |
else: |
| 119 |
#-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies |
| 120 |
prog = examples_env.Program(example, ["{}.cpp".format(example), utils, gemm_tuner_common_options], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] ) |
| 121 |
Depends(prog, graph_dependency) |
| 122 |
prog = install_bin(prog) |
| 123 |
alias = examples_env.Alias(example, prog) |
| 124 |
Default(alias) |
| 125 |
|
| 126 |
if env['neon']: |
| 127 |
for file in Glob("./neon_*.cpp"): |
| 128 |
example = os.path.basename(os.path.splitext(str(file))[0]) |
| 129 |
|
| 130 |
prog = None |
| 131 |
if env['os'] in ['bare_metal']: |
| 132 |
prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LINKFLAGS=examples_env["LINKFLAGS"], LIBS = examples_libs + arm_compute_libs) |
| 133 |
else: |
| 134 |
prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs) |
| 135 |
|
| 136 |
Depends(prog, arm_compute_dependency) |
| 137 |
prog = install_bin(prog) |
| 138 |
alias = examples_env.Alias(example, prog) |
| 139 |
Default(alias) |
| 140 |
|
| 141 |
if env['external_tests_dir']: |
| 142 |
for file in Glob(env['external_tests_dir'] + "/examples/graph_*.cpp"): |
| 143 |
example = os.path.basename(os.path.splitext(str(file))[0]) |
| 144 |
prog = None |
| 145 |
|
| 146 |
if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']: |
| 147 |
prog = examples_env.Program(example, [examples_env.Object(source=file, target=example), utils, graph_utils], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+[load_whole_archive, graph_dependency, noload_whole_archive] + extra_link_flags) |
| 148 |
Depends(prog, graph_dependency) |
| 149 |
prog = install_bin(prog) |
| 150 |
else: |
| 151 |
#-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies |
| 152 |
prog = examples_env.Program(example, [examples_env.Object(source=file, target=example), utils, graph_utils], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] ) |
| 153 |
Depends(prog, graph_dependency) |
| 154 |
prog = install_bin(prog) |
| 155 |
alias = examples_env.Alias(example, prog) |
| 156 |
Default(alias) |