Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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. |
| 22 | import SCons |
| 23 | import os.path |
| 24 | |
| 25 | Import('env') |
| 26 | Import('vars') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 28 | SConscript('./framework/SConscript', duplicate=0) |
| 29 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | # vars is imported from arm_compute: |
| 31 | variables = [ |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 32 | #FIXME: Remove before release! |
| 33 | BoolVariable("benchmark_examples", "Build benchmark examples programs", True), |
Anthony Barbier | 979dc4f | 2018-03-07 09:27:48 +0000 | [diff] [blame^] | 34 | BoolVariable("validate_examples", "Build benchmark examples programs", True), |
Anthony Barbier | e4904c7 | 2018-02-21 15:57:15 +0000 | [diff] [blame] | 35 | #FIXME Switch the following two options to False before releasing |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | BoolVariable("validation_tests", "Build validation test programs", True), |
Pablo Tello | ea1c950 | 2017-11-09 11:49:18 +0000 | [diff] [blame] | 37 | BoolVariable("benchmark_tests", "Build benchmark test programs", True), |
| 38 | ("test_filter", "Pattern to specify the tests' filenames to be compiled", "*.cpp") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | ] |
| 40 | |
| 41 | # We need a separate set of Variables for the Help message (Otherwise the global variables will get displayed twice) |
| 42 | new_options = Variables('scons') |
| 43 | |
| 44 | for v in variables: |
| 45 | new_options.Add(v) |
| 46 | vars.Add(v) |
| 47 | |
Gian Marco Iodice | f239953 | 2017-09-13 14:16:41 +0100 | [diff] [blame] | 48 | # Disable floating-point expression contraction (e.g. fused multiply-add operations) |
| 49 | env.Append(CXXFLAGS = ['-ffp-contract=off']) |
| 50 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 51 | # Clone the environment to make sure we're not polluting the arm_compute one: |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 52 | test_env = env.Clone() |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 53 | vars.Update(test_env) |
| 54 | |
| 55 | Help(new_options.GenerateHelpText(test_env)) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 56 | |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 57 | Import("arm_compute_test_framework") |
| 58 | test_env.Append(LIBS = arm_compute_test_framework) |
| 59 | |
Georgios Pinitas | 9873ea3 | 2017-12-05 15:28:55 +0000 | [diff] [blame] | 60 | if env['os'] in ['android', 'bare_metal'] or env['standalone']: |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 61 | Import("arm_compute_a") |
Anthony Barbier | b2881fc | 2017-09-29 17:12:12 +0100 | [diff] [blame] | 62 | Import("arm_compute_core_a") |
| 63 | test_env.Append(LIBS = [arm_compute_a, arm_compute_core_a]) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 64 | arm_compute_lib = arm_compute_a |
| 65 | else: |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 66 | Import("arm_compute_so") |
Anthony Barbier | b2881fc | 2017-09-29 17:12:12 +0100 | [diff] [blame] | 67 | test_env.Append(LIBS = ["arm_compute", "arm_compute_core"]) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 68 | arm_compute_lib = arm_compute_so |
| 69 | |
| 70 | #FIXME Delete before release |
Anthony Barbier | a4e5e1e | 2017-10-05 14:55:34 +0100 | [diff] [blame] | 71 | if env['internal_only']: |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 72 | test_env.Append(CPPDEFINES=['INTERNAL_ONLY']) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 73 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 74 | test_env.Append(CPPPATH = ["#3rdparty/include"]) |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 75 | test_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])]) |
| 76 | test_env.Append(LIBPATH = ["#build/%s" % env['build_dir']]) |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 77 | test_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']]) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 78 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 79 | common_files = Glob('*.cpp') |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 80 | common_objects = [test_env.StaticObject(f) for f in common_files] |
| 81 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 82 | files_benchmark = Glob('benchmark/*.cpp') |
Anthony Barbier | 979dc4f | 2018-03-07 09:27:48 +0000 | [diff] [blame^] | 83 | files_validation_framework = [test_env.Object(f) for f in Glob('validation/*.cpp')] |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 84 | |
| 85 | # Always compile reference for validation |
Anthony Barbier | 979dc4f | 2018-03-07 09:27:48 +0000 | [diff] [blame^] | 86 | files_validation_framework += [ test_env.Object(f) for f in Glob('validation/reference/*.cpp')] |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 87 | |
Abe Mbise | 925ca0f | 2017-10-02 19:16:33 +0100 | [diff] [blame] | 88 | # Add unit tests |
Anthony Barbier | 979dc4f | 2018-03-07 09:27:48 +0000 | [diff] [blame^] | 89 | files_validation = Glob('validation/UNIT/*/*.cpp') |
Abe Mbise | 925ca0f | 2017-10-02 19:16:33 +0100 | [diff] [blame] | 90 | files_validation += Glob('validation/UNIT/*.cpp') |
| 91 | |
Georgios Pinitas | 8795ffb | 2017-12-01 16:13:40 +0000 | [diff] [blame] | 92 | # Add CPP tests |
| 93 | filter_pattern = test_env['test_filter'] |
| 94 | files_validation += Glob('validation/CPP/' + filter_pattern) |
| 95 | |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 96 | if env['opencl']: |
| 97 | Import('opencl') |
Pablo Tello | ea1c950 | 2017-11-09 11:49:18 +0000 | [diff] [blame] | 98 | filter_pattern = test_env['test_filter'] |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 99 | |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 100 | test_env.Append(CPPDEFINES=['ARM_COMPUTE_CL']) |
| 101 | test_env.Append(LIBS = ["OpenCL"]) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 102 | |
Pablo Tello | ea1c950 | 2017-11-09 11:49:18 +0000 | [diff] [blame] | 103 | files_benchmark += Glob('benchmark/CL/*/' + filter_pattern) |
| 104 | files_benchmark += Glob('benchmark/CL/' + filter_pattern) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 105 | |
Pablo Tello | ea1c950 | 2017-11-09 11:49:18 +0000 | [diff] [blame] | 106 | files_validation += Glob('validation/CL/*/' + filter_pattern) |
| 107 | files_validation += Glob('validation/CL/' + filter_pattern) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 108 | |
| 109 | if env['neon']: |
Pablo Tello | ea1c950 | 2017-11-09 11:49:18 +0000 | [diff] [blame] | 110 | filter_pattern = test_env['test_filter'] |
| 111 | files_benchmark += Glob('benchmark/NEON/*/' + filter_pattern) |
| 112 | files_benchmark += Glob('benchmark/NEON/' + filter_pattern) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 113 | |
Pablo Tello | ea1c950 | 2017-11-09 11:49:18 +0000 | [diff] [blame] | 114 | files_validation += Glob('validation/NEON/*/' + filter_pattern) |
| 115 | files_validation += Glob('validation/NEON/' + filter_pattern) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 116 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 117 | if env['gles_compute']: |
| 118 | if env['os'] != 'android': |
| 119 | Import('egl') |
| 120 | Import('glesv2') |
| 121 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 122 | test_env.Append(LIBS = ["EGL", "GLESv2"]) |
| 123 | else: |
| 124 | if env['arch'] != 'armv7a': |
| 125 | test_env.Append(LIBS = ["EGL", "GLESv3"]) |
| 126 | else: |
| 127 | test_env.Append(LIBS = ["EGL", "GLESv2"]) |
| 128 | |
| 129 | test_env.Append(CPPDEFINES=['ARM_COMPUTE_GC']) |
| 130 | |
| 131 | files_benchmark += Glob('benchmark/GLES_COMPUTE/*/*.cpp') |
| 132 | files_benchmark += Glob('benchmark/GLES_COMPUTE/*.cpp') |
| 133 | |
| 134 | files_validation += Glob('validation/GLES_COMPUTE/*/*.cpp') |
| 135 | files_validation += Glob('validation/GLES_COMPUTE/*.cpp') |
| 136 | |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 137 | if env['os'] == 'android': |
| 138 | test_env.Append(LIBS = ["log"]) |
| 139 | else: |
| 140 | test_env.Append(LIBS = ["rt"]) |
| 141 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 142 | if test_env['benchmark_tests']: |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 143 | arm_compute_benchmark = test_env.Program('arm_compute_benchmark', files_benchmark + common_objects) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 144 | Depends(arm_compute_benchmark, arm_compute_test_framework) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 145 | Depends(arm_compute_benchmark, arm_compute_lib) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 146 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 147 | if env['opencl']: |
| 148 | Depends(arm_compute_benchmark, opencl) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 149 | if env['gles_compute'] and env['os'] != 'android': |
| 150 | Depends(arm_compute_benchmark, egl) |
| 151 | Depends(arm_compute_benchmark, glesv2) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 152 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 153 | Default(arm_compute_benchmark) |
| 154 | Export('arm_compute_benchmark') |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 155 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 156 | if test_env['validation_tests']: |
Anthony Barbier | 979dc4f | 2018-03-07 09:27:48 +0000 | [diff] [blame^] | 157 | arm_compute_validation = test_env.Program('arm_compute_validation', files_validation_framework + files_validation + common_objects) |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 158 | Depends(arm_compute_validation, arm_compute_test_framework) |
| 159 | Depends(arm_compute_validation, arm_compute_lib) |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 160 | |
| 161 | if env['opencl']: |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 162 | Depends(arm_compute_validation, opencl) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 163 | if env['gles_compute'] and env['os'] != 'android': |
| 164 | Depends(arm_compute_validation, egl) |
| 165 | Depends(arm_compute_validation, glesv2) |
Moritz Pflanzer | c7d1503 | 2017-07-18 16:21:16 +0100 | [diff] [blame] | 166 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 167 | Default(arm_compute_validation) |
| 168 | Export('arm_compute_validation') |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 169 | |
Anthony Barbier | 979dc4f | 2018-03-07 09:27:48 +0000 | [diff] [blame^] | 170 | #FIXME: Remove before release! |
| 171 | if test_env['validate_examples']: |
| 172 | files_validate_examples = [ test_env.Object('validate_examples/RunExample.cpp') ] + files_validation_framework + [ x for x in common_objects if not "main.o" in str(x)] |
| 173 | arm_compute_validate_examples = [] |
| 174 | if test_env['neon']: |
| 175 | for file in Glob("validate_examples/neon_*.cpp"): |
| 176 | example = "validate_" + os.path.basename(os.path.splitext(str(file))[0]) |
| 177 | arm_compute_validate_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_validate_examples) ] |
| 178 | if test_env['opencl']: |
| 179 | cl_examples = [] |
| 180 | files = Glob("validate_examples/cl_*.cpp") |
| 181 | if test_env['neon']: |
| 182 | files += Glob("validate_examples/neoncl_*.cpp") |
| 183 | for file in files: |
| 184 | example = "validate_" + os.path.basename(os.path.splitext(str(file))[0]) |
| 185 | cl_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_validate_examples, CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = test_env["LIBS"] + ["OpenCL"]) ] |
| 186 | Depends(cl_examples, opencl) |
| 187 | arm_compute_validate_examples += cl_examples |
| 188 | if test_env['opencl'] and test_env['neon']: |
| 189 | if env['os'] == 'android': |
| 190 | Import('arm_compute_graph_a') |
| 191 | graph_dependency = arm_compute_graph_a |
| 192 | else: |
| 193 | Import('arm_compute_graph_so') |
| 194 | graph_dependency = arm_compute_graph_so |
| 195 | |
| 196 | graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils") |
| 197 | for file in Glob("validate_examples/graph_*.cpp"): |
| 198 | example = "validate_" + os.path.basename(os.path.splitext(str(file))[0]) |
| 199 | if env['os'] == 'android': |
| 200 | prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_validate_examples, LIBS = test_env["LIBS"] + ["OpenCL"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--whole-archive',graph_dependency,'-Wl,--no-whole-archive']) |
| 201 | Depends(prog, [graph_dependency, opencl]) |
| 202 | arm_compute_validate_examples += [ prog ] |
| 203 | else: |
| 204 | #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies |
| 205 | prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_validate_examples, LIBS = test_env["LIBS"] + ["arm_compute_graph"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] ) |
| 206 | Depends(prog, graph_dependency) |
| 207 | arm_compute_validate_examples += [ prog ] |
| 208 | Depends(arm_compute_validate_examples, arm_compute_test_framework) |
| 209 | Depends(arm_compute_validate_examples, arm_compute_lib) |
| 210 | Default(arm_compute_validate_examples) |
| 211 | Export('arm_compute_validate_examples') |
| 212 | |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 213 | #FIXME: Remove before release! |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 214 | if test_env['benchmark_examples']: |
| 215 | files_benchmark_examples = test_env.Object('benchmark_examples/RunExample.cpp') |
| 216 | arm_compute_benchmark_examples = [] |
| 217 | if test_env['neon']: |
| 218 | for file in Glob("../examples/neon_*.cpp"): |
| 219 | example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0]) |
| 220 | arm_compute_benchmark_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples) ] |
| 221 | if test_env['opencl']: |
| 222 | cl_examples = [] |
| 223 | files = Glob("../examples/cl_*.cpp") |
| 224 | if test_env['neon']: |
| 225 | files += Glob("../examples/neoncl_*.cpp") |
| 226 | for file in files: |
| 227 | example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0]) |
| 228 | cl_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples, CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = test_env["LIBS"] + ["OpenCL"]) ] |
| 229 | Depends(cl_examples, opencl) |
| 230 | arm_compute_benchmark_examples += cl_examples |
| 231 | if test_env['opencl'] and test_env['neon']: |
| 232 | if env['os'] == 'android': |
| 233 | Import('arm_compute_graph_a') |
| 234 | graph_dependency = arm_compute_graph_a |
| 235 | else: |
| 236 | Import('arm_compute_graph_so') |
| 237 | graph_dependency = arm_compute_graph_so |
| 238 | |
| 239 | graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils") |
| 240 | for file in Glob("../examples/graph_*.cpp"): |
| 241 | example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0]) |
| 242 | if env['os'] == 'android': |
| 243 | prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_benchmark_examples, LIBS = test_env["LIBS"] + ["OpenCL"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--whole-archive',graph_dependency,'-Wl,--no-whole-archive']) |
| 244 | Depends(prog, [graph_dependency, opencl]) |
| 245 | arm_compute_benchmark_examples += [ prog ] |
| 246 | else: |
| 247 | #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies |
| 248 | prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_benchmark_examples, LIBS = test_env["LIBS"] + ["arm_compute_graph"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] ) |
| 249 | Depends(prog, graph_dependency) |
| 250 | arm_compute_benchmark_examples += [ prog ] |
| 251 | Depends(arm_compute_benchmark_examples, arm_compute_test_framework) |
| 252 | Depends(arm_compute_benchmark_examples, arm_compute_lib) |
| 253 | Default(arm_compute_benchmark_examples) |
| 254 | Export('arm_compute_benchmark_examples') |
| 255 | |