blob: 26d422c10be927c0b992647a9590d2e4bd14b416 [file] [log] [blame]
Michalis Spyrou6bff1952019-10-02 17:22:11 +01001# Copyright (c) 2017-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002#
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('vars')
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000027Import('install_bin')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
29# vars is imported from arm_compute:
30variables = [
Anthony Barbiere8a49832018-01-18 10:04:05 +000031 BoolVariable("benchmark_examples", "Build benchmark examples programs", True),
Isabella Gottardi883bad72019-07-15 17:33:07 +010032 BoolVariable("validate_examples", "Build validate examples programs", True),
Michalis Spyroud1d77222020-04-08 14:10:15 +010033 BoolVariable("reference_openmp", "Build reference validation with openmp", True),
Anthony Barbiere4904c72018-02-21 15:57:15 +000034 #FIXME Switch the following two options to False before releasing
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035 BoolVariable("validation_tests", "Build validation test programs", True),
Pablo Telloea1c9502017-11-09 11:49:18 +000036 BoolVariable("benchmark_tests", "Build benchmark test programs", True),
37 ("test_filter", "Pattern to specify the tests' filenames to be compiled", "*.cpp")
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038]
39
40# We need a separate set of Variables for the Help message (Otherwise the global variables will get displayed twice)
41new_options = Variables('scons')
42
43for v in variables:
44 new_options.Add(v)
45 vars.Add(v)
46
47# Clone the environment to make sure we're not polluting the arm_compute one:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010048test_env = env.Clone()
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010049vars.Update(test_env)
50
51Help(new_options.GenerateHelpText(test_env))
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010052
Georgios Pinitas6a342642020-01-28 15:54:20 +000053# Check if we need to build the test framework
54build_test_framework = False
55for opt in new_options.keys():
56 option_value = test_env[opt]
57 if type(option_value) is bool and option_value:
58 build_test_framework = True
59 break
60
61if not build_test_framework:
62 Return()
63else:
64 SConscript('./framework/SConscript', duplicate=0)
65
Anthony Barbier6db0ff52018-01-05 10:59:12 +000066Import("arm_compute_test_framework")
67test_env.Append(LIBS = arm_compute_test_framework)
68
Georgios Pinitas6a342642020-01-28 15:54:20 +000069# Disable floating-point expression contraction (e.g. fused multiply-add operations)
70test_env.Append(CXXFLAGS = ['-ffp-contract=off'])
71
Georgios Pinitasf8d8f3a2018-06-06 17:57:04 +010072# Remove -Wnoexcept from tests
73if 'g++' in test_env['CXX'] and '-Wnoexcept' in test_env['CXXFLAGS']:
74 test_env['CXXFLAGS'].remove("-Wnoexcept")
75
Georgios Pinitas9873ea32017-12-05 15:28:55 +000076if env['os'] in ['android', 'bare_metal'] or env['standalone']:
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010077 Import("arm_compute_a")
Anthony Barbierb2881fc2017-09-29 17:12:12 +010078 Import("arm_compute_core_a")
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010079 Import("arm_compute_graph_a")
80 test_env.Append(LIBS = [arm_compute_graph_a, arm_compute_a, arm_compute_core_a])
81 arm_compute_lib = arm_compute_graph_a
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010082else:
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010083 Import("arm_compute_graph_so")
Anthony Barbier2df1f992018-07-11 13:37:23 +010084 Import("arm_compute_core_a")
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010085 test_env.Append(LIBS = ["arm_compute_graph", "arm_compute", "arm_compute_core"])
86 arm_compute_lib = arm_compute_graph_so
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010087
Michalis Spyrou748a7c82019-10-07 13:00:44 +010088if env['os'] in ['bare_metal']:
89 Import("bootcode_o")
90
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010091#FIXME Delete before release
Anthony Barbiera4e5e1e2017-10-05 14:55:34 +010092if env['internal_only']:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010093 test_env.Append(CPPDEFINES=['INTERNAL_ONLY'])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010094
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010095test_env.Append(CPPPATH = ["#3rdparty/include"])
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010096test_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010097
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010098common_files = Glob('*.cpp')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010099common_objects = [test_env.StaticObject(f) for f in common_files]
100
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100101files_benchmark = Glob('benchmark/*.cpp')
Georgios Pinitaseb6aad72018-11-28 15:07:29 +0000102#FIXME Delete before release
103if env['internal_only']:
104 files_benchmark += Glob('../3rdparty/tests/benchmark/*.cpp')
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100105
Abe Mbise925ca0f2017-10-02 19:16:33 +0100106# Add unit tests
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000107files_validation = Glob('validation/UNIT/*/*.cpp')
Abe Mbise925ca0f2017-10-02 19:16:33 +0100108files_validation += Glob('validation/UNIT/*.cpp')
109
Georgios Pinitas8795ffb2017-12-01 16:13:40 +0000110# Add CPP tests
111filter_pattern = test_env['test_filter']
112files_validation += Glob('validation/CPP/' + filter_pattern)
113
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100114if env['opencl']:
Pablo Telloea1c9502017-11-09 11:49:18 +0000115 filter_pattern = test_env['test_filter']
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100116
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100117 test_env.Append(CPPDEFINES=['ARM_COMPUTE_CL'])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100118
Pablo Telloea1c9502017-11-09 11:49:18 +0000119 files_benchmark += Glob('benchmark/CL/*/' + filter_pattern)
120 files_benchmark += Glob('benchmark/CL/' + filter_pattern)
Georgios Pinitaseb6aad72018-11-28 15:07:29 +0000121 #FIXME Delete before release
122 if env['internal_only']:
123 files_benchmark += Glob('../3rdparty/tests/benchmark/CL/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100124
Pablo Telloea1c9502017-11-09 11:49:18 +0000125 files_validation += Glob('validation/CL/*/' + filter_pattern)
126 files_validation += Glob('validation/CL/' + filter_pattern)
Georgios Pinitas088d7b42019-05-28 19:08:47 +0100127 #FIXME Delete before release
128 if env['internal_only']:
129 files_validation += Glob('../3rdparty/tests/validation/CL/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100130
131if env['neon']:
Pablo Telloea1c9502017-11-09 11:49:18 +0000132 filter_pattern = test_env['test_filter']
133 files_benchmark += Glob('benchmark/NEON/*/' + filter_pattern)
134 files_benchmark += Glob('benchmark/NEON/' + filter_pattern)
Georgios Pinitaseb6aad72018-11-28 15:07:29 +0000135 #FIXME Delete before release
136 if env['internal_only']:
137 files_benchmark += Glob('../3rdparty/tests/benchmark/NEON/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100138
Pablo Telloea1c9502017-11-09 11:49:18 +0000139 files_validation += Glob('validation/NEON/' + filter_pattern)
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100140 if env['os'] == 'bare_metal':
141 files_validation += Glob('validation/NEON/UNIT/MemoryManager.cpp' + filter_pattern)
142 files_validation += Glob('validation/NEON/UNIT/DynamicTensor.cpp' + filter_pattern)
143 files_validation += Glob('validation/NEON/UNIT/TensorAllocator.cpp' + filter_pattern)
144 else:
145 files_validation += Glob('validation/NEON/*/' + filter_pattern)
146
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100147
Anthony Barbier7068f992017-10-26 15:23:08 +0100148if env['gles_compute']:
Anthony Barbier7068f992017-10-26 15:23:08 +0100149 test_env.Append(CPPDEFINES=['ARM_COMPUTE_GC'])
150
151 files_benchmark += Glob('benchmark/GLES_COMPUTE/*/*.cpp')
152 files_benchmark += Glob('benchmark/GLES_COMPUTE/*.cpp')
153
154 files_validation += Glob('validation/GLES_COMPUTE/*/*.cpp')
155 files_validation += Glob('validation/GLES_COMPUTE/*.cpp')
156
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100157if env['os'] == 'android':
158 test_env.Append(LIBS = ["log"])
Georgios Pinitas421405b2018-10-26 19:05:32 +0100159elif env['os'] != 'bare_metal':
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100160 test_env.Append(LIBS = ["rt"])
161
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100162if test_env['benchmark_tests']:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100163 arm_compute_benchmark = test_env.Program('arm_compute_benchmark', files_benchmark + common_objects)
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000164 arm_compute_benchmark = install_bin(arm_compute_benchmark)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100165 Depends(arm_compute_benchmark, arm_compute_test_framework)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100166 Depends(arm_compute_benchmark, arm_compute_lib)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100167 Default(arm_compute_benchmark)
168 Export('arm_compute_benchmark')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100169
Michalis Spyrou7d303522020-01-07 12:56:01 +0000170bm_link_flags = ['-fstack-protector-strong']
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100171if test_env['linker_script']:
Michalis Spyrou7d303522020-01-07 12:56:01 +0000172 bm_link_flags += ['-Wl,--build-id=none', '-T', env['linker_script']]
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100173
Michalis Spyroud1d77222020-04-08 14:10:15 +0100174if test_env['reference_openmp'] and env['os'] != 'bare_metal':
175 test_env['CXXFLAGS'].append('-fopenmp')
176 test_env['LINKFLAGS'].append('-fopenmp')
177
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100178if test_env['validation_tests']:
Michalis Spyroud1d77222020-04-08 14:10:15 +0100179 arm_compute_validation_framework = env.StaticLibrary('arm_compute_validation_framework', Glob('validation/reference/*.cpp') + Glob('validation/*.cpp'), LINKFLAGS=test_env['LINKFLAGS'], CXXFLAGS=test_env['CXXFLAGS'], LIBS= [ arm_compute_test_framework, arm_compute_core_a])
Anthony Barbier2df1f992018-07-11 13:37:23 +0100180 Depends(arm_compute_validation_framework , arm_compute_test_framework)
181 Depends(arm_compute_validation_framework , arm_compute_core_a)
182
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100183 program_objects = files_validation + common_objects
184 if test_env['os'] == 'bare_metal':
185 Depends(arm_compute_validation_framework , bootcode_o)
186 program_objects += bootcode_o
187
188
189 arm_compute_validation = test_env.Program('arm_compute_validation', program_objects, LIBS=[arm_compute_validation_framework] + test_env['LIBS'], LINKFLAGS=test_env['LINKFLAGS'] + bm_link_flags)
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000190 arm_compute_validation = install_bin(arm_compute_validation)
Anthony Barbier2df1f992018-07-11 13:37:23 +0100191 Depends(arm_compute_validation, arm_compute_validation_framework)
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100192 Depends(arm_compute_validation, arm_compute_test_framework)
193 Depends(arm_compute_validation, arm_compute_lib)
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100194
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100195 Default(arm_compute_validation)
196 Export('arm_compute_validation')
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000197
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000198 if test_env['validate_examples']:
Anthony Barbier2df1f992018-07-11 13:37:23 +0100199 files_validate_examples = [ test_env.Object('validate_examples/RunExample.cpp') ] + [ x for x in common_objects if not "main.o" in str(x)]
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100200 if test_env['os'] == 'bare_metal':
201 files_validate_examples += bootcode_o
202
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000203 arm_compute_validate_examples = []
204 if test_env['neon']:
205 for file in Glob("validate_examples/neon_*.cpp"):
206 example = "validate_" + os.path.basename(os.path.splitext(str(file))[0])
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100207 arm_compute_validate_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_validate_examples, LIBS = [ arm_compute_validation_framework], LINKFLAGS=test_env['LINKFLAGS'] + bm_link_flags) ]
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000208 if test_env['opencl']:
209 cl_examples = []
210 files = Glob("validate_examples/cl_*.cpp")
211 if test_env['neon']:
212 files += Glob("validate_examples/neoncl_*.cpp")
213 for file in files:
214 example = "validate_" + os.path.basename(os.path.splitext(str(file))[0])
Anthony Barbier2df1f992018-07-11 13:37:23 +0100215 cl_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_validate_examples, LIBS = test_env["LIBS"] + [ arm_compute_validation_framework ]) ]
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000216 arm_compute_validate_examples += cl_examples
217 if test_env['opencl'] and test_env['neon']:
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000218 graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils")
219 for file in Glob("validate_examples/graph_*.cpp"):
220 example = "validate_" + os.path.basename(os.path.splitext(str(file))[0])
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100221 if env['os'] in ['android', 'bare_metal'] or env['standalone']:
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100222 prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_validate_examples, LIBS = test_env["LIBS"] + [ arm_compute_validation_framework ], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--whole-archive',arm_compute_lib,'-Wl,--no-whole-archive'] + bm_link_flags)
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000223 arm_compute_validate_examples += [ prog ]
224 else:
225 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
Anthony Barbier2df1f992018-07-11 13:37:23 +0100226 prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_validate_examples, LIBS = test_env["LIBS"] + ["arm_compute_graph", arm_compute_validation_framework], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] )
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000227 arm_compute_validate_examples += [ prog ]
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000228 arm_compute_validate_examples = install_bin(arm_compute_validate_examples)
Anthony Barbier2df1f992018-07-11 13:37:23 +0100229 Depends(arm_compute_validate_examples, arm_compute_validation_framework)
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000230 Depends(arm_compute_validate_examples, arm_compute_test_framework)
231 Depends(arm_compute_validate_examples, arm_compute_lib)
232 Default(arm_compute_validate_examples)
233 Export('arm_compute_validate_examples')
234
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000235if test_env['benchmark_examples']:
236 files_benchmark_examples = test_env.Object('benchmark_examples/RunExample.cpp')
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100237 if test_env['os'] == 'bare_metal':
238 files_benchmark_examples += bootcode_o
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100239 graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils")
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100240 graph_params = test_env.Object(source="../utils/CommonGraphOptions.cpp", target="CommonGraphOptions")
Anthony Barbier3b6cdbb2018-09-14 11:58:05 +0100241 arm_compute_benchmark_examples = []
242 for examples_folder in [ "../examples", "../3rdparty/examples"]:
243 if test_env['neon']:
244 for file in Glob("%s/neon_*.cpp" % examples_folder):
245 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100246 arm_compute_benchmark_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples, LINKFLAGS=test_env["LINKFLAGS"]+ bm_link_flags) ]
Anthony Barbier3b6cdbb2018-09-14 11:58:05 +0100247 if test_env['opencl']:
248 cl_examples = []
249 files = Glob("%s/cl_*.cpp" % examples_folder)
250 if test_env['neon']:
251 files += Glob("%s/neoncl_*.cpp" % examples_folder)
252 for file in files:
253 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
254 cl_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples, LIBS = test_env["LIBS"]) ]
255 arm_compute_benchmark_examples += cl_examples
256
SiCong Li8b4c7302019-09-19 12:18:15 +0100257 if test_env['gemm_tuner'] and test_env['opencl']:
258 gemm_tuner_examples = []
SiCong Li240b79d2019-09-24 15:50:34 +0100259 gemm_tuner_common_options = test_env.Object(source="../examples/gemm_tuner/CommonGemmExampleOptions.cpp", target="CommonGemmExampleOptions")
SiCong Li8b4c7302019-09-19 12:18:15 +0100260 files = Glob("%s/gemm_tuner/cl_*.cpp" % examples_folder)
261 for file in files:
262 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
263 example = os.path.join("gemm_tuner", example)
SiCong Li240b79d2019-09-24 15:50:34 +0100264 gemm_tuner_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example), gemm_tuner_common_options ] + files_benchmark_examples, LIBS = test_env["LIBS"]) ]
SiCong Li8b4c7302019-09-19 12:18:15 +0100265 arm_compute_benchmark_examples += gemm_tuner_examples
266
Anthony Barbier3b6cdbb2018-09-14 11:58:05 +0100267 # Graph examples
268 for file in Glob("%s/graph_*.cpp" % examples_folder ):
269 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
270 if env['os'] in ['android', 'bare_metal'] or env['standalone']:
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100271 prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils, graph_params]+ files_benchmark_examples, LIBS = test_env["LIBS"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--whole-archive',arm_compute_lib,'-Wl,--no-whole-archive'] + bm_link_flags)
Anthony Barbier3b6cdbb2018-09-14 11:58:05 +0100272 arm_compute_benchmark_examples += [ prog ]
273 else:
274 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100275 prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils, graph_params]+ files_benchmark_examples, LIBS = test_env["LIBS"] + ["arm_compute_graph"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'])
Anthony Barbier3b6cdbb2018-09-14 11:58:05 +0100276 arm_compute_benchmark_examples += [ prog ]
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000277 arm_compute_benchmark_examples = install_bin(arm_compute_benchmark_examples)
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000278 Depends(arm_compute_benchmark_examples, arm_compute_test_framework)
279 Depends(arm_compute_benchmark_examples, arm_compute_lib)
280 Default(arm_compute_benchmark_examples)
281 Export('arm_compute_benchmark_examples')