1# Copyright (c) 2017-2019 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('vars') 27Import('install_bin') 28 29# vars is imported from arm_compute: 30variables = [ 31 BoolVariable("benchmark_examples", "Build benchmark examples programs", True), 32 BoolVariable("validate_examples", "Build validate examples programs", True), 33 BoolVariable("reference_openmp", "Build reference validation with openmp", True), 34 BoolVariable("validation_tests", "Build validation test programs", False), 35 BoolVariable("benchmark_tests", "Build benchmark test programs", False), 36 ("test_filter", "Pattern to specify the tests' filenames to be compiled", "*.cpp") 37] 38 39# We need a separate set of Variables for the Help message (Otherwise the global variables will get displayed twice) 40new_options = Variables('scons') 41 42for v in variables: 43 new_options.Add(v) 44 vars.Add(v) 45 46# Clone the environment to make sure we're not polluting the arm_compute one: 47test_env = env.Clone() 48vars.Update(test_env) 49 50Help(new_options.GenerateHelpText(test_env)) 51 52# Check if we need to build the test framework 53build_test_framework = False 54for opt in new_options.keys(): 55 option_value = test_env[opt] 56 if type(option_value) is bool and option_value: 57 build_test_framework = True 58 break 59 60if not build_test_framework: 61 Return() 62else: 63 SConscript('./framework/SConscript', duplicate=0) 64 65Import("arm_compute_test_framework") 66test_env.Append(LIBS = arm_compute_test_framework) 67 68# Disable floating-point expression contraction (e.g. fused multiply-add operations) 69test_env.Append(CXXFLAGS = ['-ffp-contract=off']) 70 71# Remove -Wnoexcept from tests 72if 'g++' in test_env['CXX'] and '-Wnoexcept' in test_env['CXXFLAGS']: 73 test_env['CXXFLAGS'].remove("-Wnoexcept") 74 75if env['os'] in ['android', 'bare_metal'] or env['standalone']: 76 Import("arm_compute_a") 77 Import("arm_compute_core_a") 78 Import("arm_compute_graph_a") 79 test_env.Append(LIBS = [arm_compute_graph_a, arm_compute_a, arm_compute_core_a]) 80 arm_compute_lib = arm_compute_graph_a 81else: 82 Import("arm_compute_graph_so") 83 Import("arm_compute_core_a") 84 test_env.Append(LIBS = ["arm_compute_graph", "arm_compute", "arm_compute_core"]) 85 arm_compute_lib = arm_compute_graph_so 86 87if env['os'] in ['bare_metal']: 88 Import("bootcode_o") 89 90test_env.Append(CPPPATH = ["#3rdparty/include"]) 91test_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])]) 92 93common_files = Glob('*.cpp') 94common_objects = [test_env.StaticObject(f) for f in common_files] 95 96files_benchmark = Glob('benchmark/*.cpp') 97 98# Add unit tests 99files_validation = Glob('validation/UNIT/*/*.cpp') 100files_validation += Glob('validation/UNIT/*.cpp') 101 102# Add CPP tests 103filter_pattern = test_env['test_filter'] 104files_validation += Glob('validation/CPP/' + filter_pattern) 105 106if env['opencl']: 107 filter_pattern = test_env['test_filter'] 108 109 test_env.Append(CPPDEFINES=['ARM_COMPUTE_CL']) 110 111 files_benchmark += Glob('benchmark/CL/*/' + filter_pattern) 112 files_benchmark += Glob('benchmark/CL/' + filter_pattern) 113 files_validation += Glob('validation/CL/*/' + filter_pattern) 114 files_validation += Glob('validation/CL/' + filter_pattern) 115 116if env['neon']: 117 filter_pattern = test_env['test_filter'] 118 files_benchmark += Glob('benchmark/NEON/*/' + filter_pattern) 119 files_benchmark += Glob('benchmark/NEON/' + filter_pattern) 120 files_validation += Glob('validation/NEON/' + filter_pattern) 121 if env['os'] == 'bare_metal': 122 files_validation += Glob('validation/NEON/UNIT/MemoryManager.cpp' + filter_pattern) 123 files_validation += Glob('validation/NEON/UNIT/DynamicTensor.cpp' + filter_pattern) 124 files_validation += Glob('validation/NEON/UNIT/TensorAllocator.cpp' + filter_pattern) 125 else: 126 files_validation += Glob('validation/NEON/*/' + filter_pattern) 127 128 129if env['gles_compute']: 130 test_env.Append(CPPDEFINES=['ARM_COMPUTE_GC']) 131 132 files_benchmark += Glob('benchmark/GLES_COMPUTE/*/*.cpp') 133 files_benchmark += Glob('benchmark/GLES_COMPUTE/*.cpp') 134 135 files_validation += Glob('validation/GLES_COMPUTE/*/*.cpp') 136 files_validation += Glob('validation/GLES_COMPUTE/*.cpp') 137 138extra_link_flags = [] 139if env['os'] == 'android': 140 test_env.Append(LIBS = ["log"]) 141elif env['os'] != 'bare_metal': 142 test_env.Append(LIBS = ["rt"]) 143 extra_link_flags += ['-fstack-protector-strong'] 144 145if test_env['benchmark_tests']: 146 arm_compute_benchmark = test_env.Program('arm_compute_benchmark', files_benchmark + common_objects) 147 arm_compute_benchmark = install_bin(arm_compute_benchmark) 148 Depends(arm_compute_benchmark, arm_compute_test_framework) 149 Depends(arm_compute_benchmark, arm_compute_lib) 150 Default(arm_compute_benchmark) 151 Export('arm_compute_benchmark') 152 153bm_link_flags = [] 154if test_env['linker_script']: 155 bm_link_flags += ['-Wl,--build-id=none', '-T', env['linker_script']] 156 157if test_env['reference_openmp'] and env['os'] != 'bare_metal': 158 test_env['CXXFLAGS'].append('-fopenmp') 159 test_env['LINKFLAGS'].append('-fopenmp') 160 161if test_env['validation_tests']: 162 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]) 163 Depends(arm_compute_validation_framework , arm_compute_test_framework) 164 Depends(arm_compute_validation_framework , arm_compute_core_a) 165 166 program_objects = files_validation + common_objects 167 if test_env['os'] == 'bare_metal': 168 Depends(arm_compute_validation_framework , bootcode_o) 169 program_objects += bootcode_o 170 171 172 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) 173 arm_compute_validation = install_bin(arm_compute_validation) 174 Depends(arm_compute_validation, arm_compute_validation_framework) 175 Depends(arm_compute_validation, arm_compute_test_framework) 176 Depends(arm_compute_validation, arm_compute_lib) 177 178 Default(arm_compute_validation) 179 Export('arm_compute_validation') 180 181 if test_env['validate_examples']: 182 files_validate_examples = [ test_env.Object('validate_examples/RunExample.cpp') ] + [ x for x in common_objects if not "main.o" in str(x)] 183 if test_env['os'] == 'bare_metal': 184 files_validate_examples += bootcode_o 185 186 arm_compute_validate_examples = [] 187 if test_env['neon']: 188 for file in Glob("validate_examples/neon_*.cpp"): 189 example = "validate_" + os.path.basename(os.path.splitext(str(file))[0]) 190 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) ] 191 if test_env['opencl']: 192 cl_examples = [] 193 files = Glob("validate_examples/cl_*.cpp") 194 if test_env['neon']: 195 files += Glob("validate_examples/neoncl_*.cpp") 196 for file in files: 197 example = "validate_" + os.path.basename(os.path.splitext(str(file))[0]) 198 cl_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_validate_examples, LIBS = test_env["LIBS"] + [ arm_compute_validation_framework ]) ] 199 arm_compute_validate_examples += cl_examples 200 if test_env['opencl'] and test_env['neon']: 201 graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils") 202 for file in Glob("validate_examples/graph_*.cpp"): 203 example = "validate_" + os.path.basename(os.path.splitext(str(file))[0]) 204 if env['os'] in ['android', 'bare_metal'] or env['standalone']: 205 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 + extra_link_flags) 206 arm_compute_validate_examples += [ prog ] 207 else: 208 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies 209 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'] ) 210 arm_compute_validate_examples += [ prog ] 211 arm_compute_validate_examples = install_bin(arm_compute_validate_examples) 212 Depends(arm_compute_validate_examples, arm_compute_validation_framework) 213 Depends(arm_compute_validate_examples, arm_compute_test_framework) 214 Depends(arm_compute_validate_examples, arm_compute_lib) 215 Default(arm_compute_validate_examples) 216 Export('arm_compute_validate_examples') 217 218if test_env['benchmark_examples']: 219 files_benchmark_examples = test_env.Object('benchmark_examples/RunExample.cpp') 220 if test_env['os'] == 'bare_metal': 221 files_benchmark_examples += bootcode_o 222 graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils") 223 graph_params = test_env.Object(source="../utils/CommonGraphOptions.cpp", target="CommonGraphOptions") 224 arm_compute_benchmark_examples = [] 225 for examples_folder in [ "../examples", "../3rdparty/examples"]: 226 if test_env['neon']: 227 for file in Glob("%s/neon_*.cpp" % examples_folder): 228 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0]) 229 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) ] 230 if test_env['opencl']: 231 cl_examples = [] 232 files = Glob("%s/cl_*.cpp" % examples_folder) 233 if test_env['neon']: 234 files += Glob("%s/neoncl_*.cpp" % examples_folder) 235 for file in files: 236 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0]) 237 cl_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples, LIBS = test_env["LIBS"]) ] 238 arm_compute_benchmark_examples += cl_examples 239 240 if test_env['gemm_tuner'] and test_env['opencl']: 241 gemm_tuner_examples = [] 242 gemm_tuner_common_options = test_env.Object(source="../examples/gemm_tuner/CommonGemmExampleOptions.cpp", target="CommonGemmExampleOptions") 243 files = Glob("%s/gemm_tuner/cl_*.cpp" % examples_folder) 244 for file in files: 245 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0]) 246 example = os.path.join("gemm_tuner", example) 247 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"]) ] 248 arm_compute_benchmark_examples += gemm_tuner_examples 249 250 # Graph examples 251 for file in Glob("%s/graph_*.cpp" % examples_folder ): 252 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0]) 253 if env['os'] in ['android', 'bare_metal'] or env['standalone']: 254 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 + extra_link_flags) 255 arm_compute_benchmark_examples += [ prog ] 256 else: 257 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies 258 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']) 259 arm_compute_benchmark_examples += [ prog ] 260 arm_compute_benchmark_examples = install_bin(arm_compute_benchmark_examples) 261 Depends(arm_compute_benchmark_examples, arm_compute_test_framework) 262 Depends(arm_compute_benchmark_examples, arm_compute_lib) 263 Default(arm_compute_benchmark_examples) 264 Export('arm_compute_benchmark_examples') 265