blob: 8ece7e60b24ae207caae5e3ad99704f864fda5fa [file] [log] [blame]
Michalis Spyroua8caa022022-05-18 17:43:39 +01001#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
Pablo Marquez Tello37d84452024-03-25 16:31:26 +00004# Copyright (c) 2017-2024 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01005#
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.
25import SCons
26import os.path
27
28Import('env')
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000029Import('install_bin')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031examples_env = env.Clone()
32
33examples_env.Append(CPPPATH = ["#"])
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
35# Build examples
36utils = examples_env.Object("../utils/Utils.cpp")
37
Georgios Pinitas45514032020-12-30 00:03:09 +000038if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010039 Import('arm_compute_graph_a')
Pablo Telloc6cb35a2017-06-21 15:39:47 +010040 Import('arm_compute_a')
Jakub Sujake30c8742023-11-13 14:57:16 +000041 arm_compute_libs = [ arm_compute_a ]
Anthony Barbier8ddab142018-07-13 11:52:37 +010042 arm_compute_graph_libs = arm_compute_libs # The graph library needs to be linked separately with --whole-archive
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043 arm_compute_dependency = arm_compute_a
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010044 graph_dependency = [arm_compute_graph_a]
Anthony Barbier6ff3b192017-09-04 18:44:23 +010045else:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010046 Import('arm_compute_graph_so')
Pablo Telloc6cb35a2017-06-21 15:39:47 +010047 Import('arm_compute_so')
Jakub Sujake30c8742023-11-13 14:57:16 +000048 arm_compute_libs = ["arm_compute"]
Anthony Barbier8ddab142018-07-13 11:52:37 +010049 arm_compute_graph_libs = [ "arm_compute_graph" ] + arm_compute_libs
Anthony Barbier6ff3b192017-09-04 18:44:23 +010050 arm_compute_dependency = arm_compute_so
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010051 graph_dependency = [arm_compute_graph_so]
Anthony Barbier6ff3b192017-09-04 18:44:23 +010052
Michalis Spyrou6a9e8012020-02-07 09:45:55 +000053extra_link_flags = []
Pablo Marquez Tello37d84452024-03-25 16:31:26 +000054
55if not env['os'] in ['windows','bare_metal'] :
Michalis Spyrou6a9e8012020-02-07 09:45:55 +000056 extra_link_flags += ['-fstack-protector-strong']
57
Pablo Marquez Tello37d84452024-03-25 16:31:26 +000058
59if env['os'] != 'windows' :
60 load_whole_archive = '-Wl,--whole-archive'
61 noload_whole_archive = '-Wl,--no-whole-archive'
62else:
63 load_whole_archive = '/wholearchive'
64 noload_whole_archive = ''
65
Georgios Pinitas45514032020-12-30 00:03:09 +000066if 'macos' in examples_env['os']:
67 load_whole_archive = '-Wl,-force_load'
Jakub Sujakebce2802023-09-29 11:11:59 +010068 noload_whole_archive = ''
Georgios Pinitas45514032020-12-30 00:03:09 +000069
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010070# Build graph examples
71graph_utils = examples_env.Object("../utils/GraphUtils.cpp")
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010072graph_utils += examples_env.Object("../utils/CommonGraphOptions.cpp")
Anthony Barbier7fb7b612018-05-16 11:58:52 +010073examples_libs = examples_env.get("LIBS",[])
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010074for file in Glob("./graph_*.cpp"):
75 example = os.path.basename(os.path.splitext(str(file))[0])
76 prog = None
Pablo Marquez Tello37d84452024-03-25 16:31:26 +000077 if env['os'] in ['android','windows', 'macos', 'bare_metal'] or env['standalone']:
Georgios Pinitas45514032020-12-30 00:03:09 +000078 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)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010079 Depends(prog, graph_dependency)
Michalis Spyrou165308c2019-04-10 10:10:21 +010080 prog = install_bin(prog)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010081 else:
82 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
Anthony Barbier7fb7b612018-05-16 11:58:52 +010083 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'] )
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010084 Depends(prog, graph_dependency)
Michalis Spyrou165308c2019-04-10 10:10:21 +010085 prog = install_bin(prog)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010086 alias = examples_env.Alias(example, prog)
87 Default(alias)
88
Georgios Pinitas33893c32018-05-18 16:54:54 +010089if env['opencl'] and env['neon']:
Michalis Spyrou22dd8b92022-07-05 14:07:23 +010090 examples_env.Append(CPPDEFINES = ['ARM_COMPUTE_CL'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +010091 for file in Glob("./neoncl_*.cpp"):
92 example = os.path.basename(os.path.splitext(str(file))[0])
Michalis Spyrou22dd8b92022-07-05 14:07:23 +010093 prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010094 Depends(prog, arm_compute_dependency)
Michalis Spyrou165308c2019-04-10 10:10:21 +010095 prog = install_bin(prog)
Anthony Barbier2a07e182017-08-04 18:20:27 +010096 alias = examples_env.Alias(example, prog)
97 Default(alias)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010098
99if env['opencl']:
Michalis Spyrou22dd8b92022-07-05 14:07:23 +0100100 examples_env.Append(CPPDEFINES = ['ARM_COMPUTE_CL'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100101 for file in Glob("./cl_*.cpp"):
102 example = os.path.basename(os.path.splitext(str(file))[0])
Michalis Spyrou22dd8b92022-07-05 14:07:23 +0100103 prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100104 Depends(prog, arm_compute_dependency)
Michalis Spyrou165308c2019-04-10 10:10:21 +0100105 prog = install_bin(prog)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106 alias = examples_env.Alias(example, prog)
107 Default(alias)
108
SiCong Li8b4c7302019-09-19 12:18:15 +0100109if env['gemm_tuner'] and env['opencl']:
SiCong Li240b79d2019-09-24 15:50:34 +0100110 gemm_tuner_common_options = examples_env.Object("./gemm_tuner/CommonGemmExampleOptions.cpp")
SiCong Li8b4c7302019-09-19 12:18:15 +0100111 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)
Georgios Pinitas45514032020-12-30 00:03:09 +0000114 if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']:
Michalis Spyrou22dd8b92022-07-05 14:07:23 +0100115 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'] )
Eren Kopuz350099e2020-06-09 15:37:43 +0100116 Depends(prog, graph_dependency)
117 prog = install_bin(prog)
118 else:
119 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
Michalis Spyrou22dd8b92022-07-05 14:07:23 +0100120 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'] )
Eren Kopuz350099e2020-06-09 15:37:43 +0100121 Depends(prog, graph_dependency)
122 prog = install_bin(prog)
SiCong Li8b4c7302019-09-19 12:18:15 +0100123 alias = examples_env.Alias(example, prog)
124 Default(alias)
125
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100126if env['neon']:
127 for file in Glob("./neon_*.cpp"):
128 example = os.path.basename(os.path.splitext(str(file))[0])
Michalis Spyrou01833682020-01-09 15:15:13 +0000129
130 prog = None
131 if env['os'] in ['bare_metal']:
Michalis Spyrou6a9e8012020-02-07 09:45:55 +0000132 prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LINKFLAGS=examples_env["LINKFLAGS"], LIBS = examples_libs + arm_compute_libs)
Michalis Spyrou01833682020-01-09 15:15:13 +0000133 else:
134 prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs)
135
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100136 Depends(prog, arm_compute_dependency)
Michalis Spyrou165308c2019-04-10 10:10:21 +0100137 prog = install_bin(prog)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100138 alias = examples_env.Alias(example, prog)
139 Default(alias)
Anthony Barbier7068f992017-10-26 15:23:08 +0100140
Michele Di Giorgio72610dc2020-11-18 15:29:08 +0000141if 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
Georgios Pinitas33893c32018-05-18 16:54:54 +0100145
Georgios Pinitas45514032020-12-30 00:03:09 +0000146 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)
Michele Di Giorgio72610dc2020-11-18 15:29:08 +0000148 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)