• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 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 SCons
23import os.path
24
25Import('env')
26Import('install_bin')
27
28examples_env = env.Clone()
29
30examples_env.Append(CPPPATH = ["#"])
31
32# Build examples
33utils = examples_env.Object("../utils/Utils.cpp")
34
35if env['os'] in ['android', 'bare_metal'] or env['standalone']:
36    Import('arm_compute_graph_a')
37    Import('arm_compute_a')
38    Import('arm_compute_core_a')
39    arm_compute_libs = [ arm_compute_a, arm_compute_core_a ]
40    arm_compute_graph_libs = arm_compute_libs # The graph library needs to be linked separately with --whole-archive
41    arm_compute_dependency = arm_compute_a
42    graph_dependency = [arm_compute_graph_a]
43else:
44    Import('arm_compute_graph_so')
45    Import('arm_compute_so')
46    arm_compute_libs = ["arm_compute", "arm_compute_core"]
47    arm_compute_graph_libs = [ "arm_compute_graph" ] + arm_compute_libs
48    arm_compute_dependency = arm_compute_so
49    graph_dependency = [arm_compute_graph_so]
50
51extra_link_flags = []
52if env['os'] != 'bare_metal':
53    extra_link_flags += ['-fstack-protector-strong']
54
55# Build graph examples
56graph_utils = examples_env.Object("../utils/GraphUtils.cpp")
57graph_utils += examples_env.Object("../utils/CommonGraphOptions.cpp")
58examples_libs = examples_env.get("LIBS",[])
59for file in Glob("./graph_*.cpp"):
60    example = os.path.basename(os.path.splitext(str(file))[0])
61    prog = None
62
63    if env['os'] in ['android', 'bare_metal'] or env['standalone']:
64        prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--whole-archive',graph_dependency,'-Wl,--no-whole-archive'] + extra_link_flags)
65        Depends(prog, graph_dependency)
66        prog = install_bin(prog)
67    else:
68        #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
69        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'] )
70        Depends(prog, graph_dependency)
71        prog = install_bin(prog)
72    alias = examples_env.Alias(example, prog)
73    Default(alias)
74
75if env['opencl'] and env['neon']:
76    for file in Glob("./neoncl_*.cpp"):
77        example = os.path.basename(os.path.splitext(str(file))[0])
78        prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = examples_libs + arm_compute_libs)
79        Depends(prog, arm_compute_dependency)
80        prog = install_bin(prog)
81        alias = examples_env.Alias(example, prog)
82        Default(alias)
83
84if env['opencl']:
85    for file in Glob("./cl_*.cpp"):
86        example = os.path.basename(os.path.splitext(str(file))[0])
87        prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = examples_libs + arm_compute_libs)
88        Depends(prog, arm_compute_dependency)
89        prog = install_bin(prog)
90        alias = examples_env.Alias(example, prog)
91        Default(alias)
92
93if env['gemm_tuner'] and env['opencl']:
94    gemm_tuner_common_options = examples_env.Object("./gemm_tuner/CommonGemmExampleOptions.cpp")
95    for file in Glob("./gemm_tuner/cl_*.cpp"):
96        example = os.path.basename(os.path.splitext(str(file))[0])
97        example = os.path.join("gemm_tuner", example)
98        if env['os'] in ['android', 'bare_metal'] or env['standalone']:
99            prog = examples_env.Program(example, ["{}.cpp".format(example), utils, gemm_tuner_common_options], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--whole-archive',graph_dependency,'-Wl,--no-whole-archive', '-fstack-protector-strong'] )
100            Depends(prog, graph_dependency)
101            prog = install_bin(prog)
102        else:
103            #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
104            prog = examples_env.Program(example, ["{}.cpp".format(example), utils, gemm_tuner_common_options], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] )
105            Depends(prog, graph_dependency)
106            prog = install_bin(prog)
107        alias = examples_env.Alias(example, prog)
108        Default(alias)
109
110if env['neon']:
111    for file in Glob("./neon_*.cpp"):
112        example = os.path.basename(os.path.splitext(str(file))[0])
113
114        prog = None
115        if env['os'] in ['bare_metal']:
116            prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LINKFLAGS=examples_env["LINKFLAGS"], LIBS = examples_libs + arm_compute_libs)
117        else:
118            prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs)
119
120        Depends(prog, arm_compute_dependency)
121        prog = install_bin(prog)
122        alias = examples_env.Alias(example, prog)
123        Default(alias)
124
125if env['gles_compute']:
126    for file in Glob("./gc_*.cpp"):
127        example = os.path.basename(os.path.splitext(str(file))[0])
128        prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_GC'], LIBS = examples_libs + arm_compute_libs)
129        Depends(prog, arm_compute_dependency)
130        prog = install_bin(prog)
131        alias = examples_env.Alias(example, prog)
132        Default(alias)
133
134