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