blob: a128d399f8b1edec16ae412975349f9c5f151c67 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001# 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.
22import SCons
23import os.path
24
25Import('env')
26Import('vars')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010028SConscript('./framework/SConscript', duplicate=0)
29
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030# vars is imported from arm_compute:
31variables = [
Anthony Barbiere8a49832018-01-18 10:04:05 +000032 #FIXME: Remove before release!
33 BoolVariable("benchmark_examples", "Build benchmark examples programs", True),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034 BoolVariable("validation_tests", "Build validation test programs", True),
Pablo Telloea1c9502017-11-09 11:49:18 +000035 BoolVariable("benchmark_tests", "Build benchmark test programs", True),
36 ("test_filter", "Pattern to specify the tests' filenames to be compiled", "*.cpp")
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037]
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
Gian Marco Iodicef2399532017-09-13 14:16:41 +010046# Disable floating-point expression contraction (e.g. fused multiply-add operations)
47env.Append(CXXFLAGS = ['-ffp-contract=off'])
48
Anthony Barbier6ff3b192017-09-04 18:44:23 +010049# Clone the environment to make sure we're not polluting the arm_compute one:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010050test_env = env.Clone()
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010051vars.Update(test_env)
52
53Help(new_options.GenerateHelpText(test_env))
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010054
Anthony Barbier6db0ff52018-01-05 10:59:12 +000055Import("arm_compute_test_framework")
56test_env.Append(LIBS = arm_compute_test_framework)
57
Georgios Pinitas9873ea32017-12-05 15:28:55 +000058if env['os'] in ['android', 'bare_metal'] or env['standalone']:
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010059 Import("arm_compute_a")
Anthony Barbierb2881fc2017-09-29 17:12:12 +010060 Import("arm_compute_core_a")
61 test_env.Append(LIBS = [arm_compute_a, arm_compute_core_a])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010062 arm_compute_lib = arm_compute_a
63else:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010064 Import("arm_compute_so")
Anthony Barbierb2881fc2017-09-29 17:12:12 +010065 test_env.Append(LIBS = ["arm_compute", "arm_compute_core"])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010066 arm_compute_lib = arm_compute_so
67
68#FIXME Delete before release
Anthony Barbiera4e5e1e2017-10-05 14:55:34 +010069if env['internal_only']:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010070 test_env.Append(CPPDEFINES=['INTERNAL_ONLY'])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010071
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010072test_env.Append(CPPPATH = ["#3rdparty/include"])
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010073test_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])])
74test_env.Append(LIBPATH = ["#build/%s" % env['build_dir']])
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010075test_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010076
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010077common_files = Glob('*.cpp')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010078common_objects = [test_env.StaticObject(f) for f in common_files]
79
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010080files_benchmark = Glob('benchmark/*.cpp')
81files_validation = Glob('validation/*.cpp')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010082
83# Always compile reference for validation
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000084files_validation += Glob('validation/reference/*.cpp')
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010085
Abe Mbise925ca0f2017-10-02 19:16:33 +010086# Add unit tests
87files_validation += Glob('validation/UNIT/*/*.cpp')
88files_validation += Glob('validation/UNIT/*.cpp')
89
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000090# Add CPP tests
91filter_pattern = test_env['test_filter']
92files_validation += Glob('validation/CPP/' + filter_pattern)
93
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010094if env['opencl']:
95 Import('opencl')
Pablo Telloea1c9502017-11-09 11:49:18 +000096 filter_pattern = test_env['test_filter']
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010097
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010098 test_env.Append(CPPDEFINES=['ARM_COMPUTE_CL'])
99 test_env.Append(LIBS = ["OpenCL"])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100100
Pablo Telloea1c9502017-11-09 11:49:18 +0000101 files_benchmark += Glob('benchmark/CL/*/' + filter_pattern)
102 files_benchmark += Glob('benchmark/CL/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100103
Pablo Telloea1c9502017-11-09 11:49:18 +0000104 files_validation += Glob('validation/CL/*/' + filter_pattern)
105 files_validation += Glob('validation/CL/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100106
107if env['neon']:
Pablo Telloea1c9502017-11-09 11:49:18 +0000108 filter_pattern = test_env['test_filter']
109 files_benchmark += Glob('benchmark/NEON/*/' + filter_pattern)
110 files_benchmark += Glob('benchmark/NEON/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100111
Pablo Telloea1c9502017-11-09 11:49:18 +0000112 files_validation += Glob('validation/NEON/*/' + filter_pattern)
113 files_validation += Glob('validation/NEON/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100114
Anthony Barbier7068f992017-10-26 15:23:08 +0100115if env['gles_compute']:
116 if env['os'] != 'android':
117 Import('egl')
118 Import('glesv2')
119
Anthony Barbier7068f992017-10-26 15:23:08 +0100120 test_env.Append(LIBS = ["EGL", "GLESv2"])
121 else:
122 if env['arch'] != 'armv7a':
123 test_env.Append(LIBS = ["EGL", "GLESv3"])
124 else:
125 test_env.Append(LIBS = ["EGL", "GLESv2"])
126
127 test_env.Append(CPPDEFINES=['ARM_COMPUTE_GC'])
128
129 files_benchmark += Glob('benchmark/GLES_COMPUTE/*/*.cpp')
130 files_benchmark += Glob('benchmark/GLES_COMPUTE/*.cpp')
131
132 files_validation += Glob('validation/GLES_COMPUTE/*/*.cpp')
133 files_validation += Glob('validation/GLES_COMPUTE/*.cpp')
134
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100135if env['os'] == 'android':
136 test_env.Append(LIBS = ["log"])
137else:
138 test_env.Append(LIBS = ["rt"])
139
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100140if test_env['benchmark_tests']:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100141 arm_compute_benchmark = test_env.Program('arm_compute_benchmark', files_benchmark + common_objects)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100142 Depends(arm_compute_benchmark, arm_compute_test_framework)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100143 Depends(arm_compute_benchmark, arm_compute_lib)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100144
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100145 if env['opencl']:
146 Depends(arm_compute_benchmark, opencl)
Anthony Barbier7068f992017-10-26 15:23:08 +0100147 if env['gles_compute'] and env['os'] != 'android':
148 Depends(arm_compute_benchmark, egl)
149 Depends(arm_compute_benchmark, glesv2)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100150
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100151 Default(arm_compute_benchmark)
152 Export('arm_compute_benchmark')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100153
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100154if test_env['validation_tests']:
155 arm_compute_validation = test_env.Program('arm_compute_validation', files_validation + common_objects)
156 Depends(arm_compute_validation, arm_compute_test_framework)
157 Depends(arm_compute_validation, arm_compute_lib)
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100158
159 if env['opencl']:
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100160 Depends(arm_compute_validation, opencl)
Anthony Barbier7068f992017-10-26 15:23:08 +0100161 if env['gles_compute'] and env['os'] != 'android':
162 Depends(arm_compute_validation, egl)
163 Depends(arm_compute_validation, glesv2)
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100164
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100165 Default(arm_compute_validation)
166 Export('arm_compute_validation')
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000167
Anthony Barbiere8a49832018-01-18 10:04:05 +0000168#FIXME: Remove before release!
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000169if test_env['benchmark_examples']:
170 files_benchmark_examples = test_env.Object('benchmark_examples/RunExample.cpp')
171 arm_compute_benchmark_examples = []
172 if test_env['neon']:
173 for file in Glob("../examples/neon_*.cpp"):
174 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
175 arm_compute_benchmark_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples) ]
176 if test_env['opencl']:
177 cl_examples = []
178 files = Glob("../examples/cl_*.cpp")
179 if test_env['neon']:
180 files += Glob("../examples/neoncl_*.cpp")
181 for file in files:
182 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
183 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"]) ]
184 Depends(cl_examples, opencl)
185 arm_compute_benchmark_examples += cl_examples
186 if test_env['opencl'] and test_env['neon']:
187 if env['os'] == 'android':
188 Import('arm_compute_graph_a')
189 graph_dependency = arm_compute_graph_a
190 else:
191 Import('arm_compute_graph_so')
192 graph_dependency = arm_compute_graph_so
193
194 graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils")
195 for file in Glob("../examples/graph_*.cpp"):
196 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
197 if env['os'] == 'android':
198 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'])
199 Depends(prog, [graph_dependency, opencl])
200 arm_compute_benchmark_examples += [ prog ]
201 else:
202 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
203 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'] )
204 Depends(prog, graph_dependency)
205 arm_compute_benchmark_examples += [ prog ]
206 Depends(arm_compute_benchmark_examples, arm_compute_test_framework)
207 Depends(arm_compute_benchmark_examples, arm_compute_lib)
208 Default(arm_compute_benchmark_examples)
209 Export('arm_compute_benchmark_examples')
210