Michalis Spyrou | a8caa02 | 2022-05-18 17:43:39 +0100 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
Jakub Sujak | ebce280 | 2023-09-29 11:11:59 +0100 | [diff] [blame] | 4 | # Copyright (c) 2017-2023 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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') |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 29 | Import('install_bin') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | examples_env = env.Clone() |
| 32 | |
| 33 | examples_env.Append(CPPPATH = ["#"]) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
| 35 | # Build examples |
| 36 | utils = examples_env.Object("../utils/Utils.cpp") |
| 37 | |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 38 | if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']: |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 39 | Import('arm_compute_graph_a') |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 40 | Import('arm_compute_a') |
Jakub Sujak | e30c874 | 2023-11-13 14:57:16 +0000 | [diff] [blame] | 41 | arm_compute_libs = [ arm_compute_a ] |
Anthony Barbier | 8ddab14 | 2018-07-13 11:52:37 +0100 | [diff] [blame] | 42 | arm_compute_graph_libs = arm_compute_libs # The graph library needs to be linked separately with --whole-archive |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 43 | arm_compute_dependency = arm_compute_a |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 44 | graph_dependency = [arm_compute_graph_a] |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 45 | else: |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 46 | Import('arm_compute_graph_so') |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 47 | Import('arm_compute_so') |
Jakub Sujak | e30c874 | 2023-11-13 14:57:16 +0000 | [diff] [blame] | 48 | arm_compute_libs = ["arm_compute"] |
Anthony Barbier | 8ddab14 | 2018-07-13 11:52:37 +0100 | [diff] [blame] | 49 | arm_compute_graph_libs = [ "arm_compute_graph" ] + arm_compute_libs |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 50 | arm_compute_dependency = arm_compute_so |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 51 | graph_dependency = [arm_compute_graph_so] |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 52 | |
Michalis Spyrou | 6a9e801 | 2020-02-07 09:45:55 +0000 | [diff] [blame] | 53 | extra_link_flags = [] |
| 54 | if env['os'] != 'bare_metal': |
| 55 | extra_link_flags += ['-fstack-protector-strong'] |
| 56 | |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 57 | load_whole_archive = '-Wl,--whole-archive' |
| 58 | noload_whole_archive = '-Wl,--no-whole-archive' |
| 59 | if 'macos' in examples_env['os']: |
| 60 | load_whole_archive = '-Wl,-force_load' |
Jakub Sujak | ebce280 | 2023-09-29 11:11:59 +0100 | [diff] [blame] | 61 | noload_whole_archive = '' |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 62 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 63 | # Build graph examples |
| 64 | graph_utils = examples_env.Object("../utils/GraphUtils.cpp") |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 65 | graph_utils += examples_env.Object("../utils/CommonGraphOptions.cpp") |
Anthony Barbier | 7fb7b61 | 2018-05-16 11:58:52 +0100 | [diff] [blame] | 66 | examples_libs = examples_env.get("LIBS",[]) |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 67 | for file in Glob("./graph_*.cpp"): |
| 68 | example = os.path.basename(os.path.splitext(str(file))[0]) |
| 69 | prog = None |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 70 | if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']: |
| 71 | 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 Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 72 | Depends(prog, graph_dependency) |
Michalis Spyrou | 165308c | 2019-04-10 10:10:21 +0100 | [diff] [blame] | 73 | prog = install_bin(prog) |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 74 | else: |
| 75 | #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies |
Anthony Barbier | 7fb7b61 | 2018-05-16 11:58:52 +0100 | [diff] [blame] | 76 | 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 Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 77 | Depends(prog, graph_dependency) |
Michalis Spyrou | 165308c | 2019-04-10 10:10:21 +0100 | [diff] [blame] | 78 | prog = install_bin(prog) |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 79 | alias = examples_env.Alias(example, prog) |
| 80 | Default(alias) |
| 81 | |
Georgios Pinitas | 33893c3 | 2018-05-18 16:54:54 +0100 | [diff] [blame] | 82 | if env['opencl'] and env['neon']: |
Michalis Spyrou | 22dd8b9 | 2022-07-05 14:07:23 +0100 | [diff] [blame] | 83 | examples_env.Append(CPPDEFINES = ['ARM_COMPUTE_CL']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 84 | for file in Glob("./neoncl_*.cpp"): |
| 85 | example = os.path.basename(os.path.splitext(str(file))[0]) |
Michalis Spyrou | 22dd8b9 | 2022-07-05 14:07:23 +0100 | [diff] [blame] | 86 | prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs) |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 87 | Depends(prog, arm_compute_dependency) |
Michalis Spyrou | 165308c | 2019-04-10 10:10:21 +0100 | [diff] [blame] | 88 | prog = install_bin(prog) |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 89 | alias = examples_env.Alias(example, prog) |
| 90 | Default(alias) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 91 | |
| 92 | if env['opencl']: |
Michalis Spyrou | 22dd8b9 | 2022-07-05 14:07:23 +0100 | [diff] [blame] | 93 | examples_env.Append(CPPDEFINES = ['ARM_COMPUTE_CL']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 94 | for file in Glob("./cl_*.cpp"): |
| 95 | example = os.path.basename(os.path.splitext(str(file))[0]) |
Michalis Spyrou | 22dd8b9 | 2022-07-05 14:07:23 +0100 | [diff] [blame] | 96 | prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs) |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 97 | Depends(prog, arm_compute_dependency) |
Michalis Spyrou | 165308c | 2019-04-10 10:10:21 +0100 | [diff] [blame] | 98 | prog = install_bin(prog) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 99 | alias = examples_env.Alias(example, prog) |
| 100 | Default(alias) |
| 101 | |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 102 | if env['gemm_tuner'] and env['opencl']: |
SiCong Li | 240b79d | 2019-09-24 15:50:34 +0100 | [diff] [blame] | 103 | gemm_tuner_common_options = examples_env.Object("./gemm_tuner/CommonGemmExampleOptions.cpp") |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 104 | for file in Glob("./gemm_tuner/cl_*.cpp"): |
| 105 | example = os.path.basename(os.path.splitext(str(file))[0]) |
| 106 | example = os.path.join("gemm_tuner", example) |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 107 | if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']: |
Michalis Spyrou | 22dd8b9 | 2022-07-05 14:07:23 +0100 | [diff] [blame] | 108 | 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 Kopuz | 350099e | 2020-06-09 15:37:43 +0100 | [diff] [blame] | 109 | Depends(prog, graph_dependency) |
| 110 | prog = install_bin(prog) |
| 111 | else: |
| 112 | #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies |
Michalis Spyrou | 22dd8b9 | 2022-07-05 14:07:23 +0100 | [diff] [blame] | 113 | 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 Kopuz | 350099e | 2020-06-09 15:37:43 +0100 | [diff] [blame] | 114 | Depends(prog, graph_dependency) |
| 115 | prog = install_bin(prog) |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 116 | alias = examples_env.Alias(example, prog) |
| 117 | Default(alias) |
| 118 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 119 | if env['neon']: |
| 120 | for file in Glob("./neon_*.cpp"): |
| 121 | example = os.path.basename(os.path.splitext(str(file))[0]) |
Michalis Spyrou | 0183368 | 2020-01-09 15:15:13 +0000 | [diff] [blame] | 122 | |
| 123 | prog = None |
| 124 | if env['os'] in ['bare_metal']: |
Michalis Spyrou | 6a9e801 | 2020-02-07 09:45:55 +0000 | [diff] [blame] | 125 | prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LINKFLAGS=examples_env["LINKFLAGS"], LIBS = examples_libs + arm_compute_libs) |
Michalis Spyrou | 0183368 | 2020-01-09 15:15:13 +0000 | [diff] [blame] | 126 | else: |
| 127 | prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs) |
| 128 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 129 | Depends(prog, arm_compute_dependency) |
Michalis Spyrou | 165308c | 2019-04-10 10:10:21 +0100 | [diff] [blame] | 130 | prog = install_bin(prog) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 131 | alias = examples_env.Alias(example, prog) |
| 132 | Default(alias) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 133 | |
Michele Di Giorgio | 72610dc | 2020-11-18 15:29:08 +0000 | [diff] [blame] | 134 | if env['external_tests_dir']: |
| 135 | for file in Glob(env['external_tests_dir'] + "/examples/graph_*.cpp"): |
| 136 | example = os.path.basename(os.path.splitext(str(file))[0]) |
| 137 | prog = None |
Georgios Pinitas | 33893c3 | 2018-05-18 16:54:54 +0100 | [diff] [blame] | 138 | |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 139 | if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']: |
| 140 | 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 Giorgio | 72610dc | 2020-11-18 15:29:08 +0000 | [diff] [blame] | 141 | Depends(prog, graph_dependency) |
| 142 | prog = install_bin(prog) |
| 143 | else: |
| 144 | #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies |
| 145 | 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'] ) |
| 146 | Depends(prog, graph_dependency) |
| 147 | prog = install_bin(prog) |
| 148 | alias = examples_env.Alias(example, prog) |
| 149 | Default(alias) |