blob: efe64376279dd7d95787c1a920581dc5199c3289 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001# Copyright (c) 2017, 2018 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 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 Barbier979dc4f2018-03-07 09:27:48 +000034 BoolVariable("validate_examples", "Build benchmark examples programs", True),
Anthony Barbiere4904c72018-02-21 15:57:15 +000035 #FIXME Switch the following two options to False before releasing
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036 BoolVariable("validation_tests", "Build validation test programs", True),
Pablo Telloea1c9502017-11-09 11:49:18 +000037 BoolVariable("benchmark_tests", "Build benchmark test programs", True),
38 ("test_filter", "Pattern to specify the tests' filenames to be compiled", "*.cpp")
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039]
40
41# We need a separate set of Variables for the Help message (Otherwise the global variables will get displayed twice)
42new_options = Variables('scons')
43
44for v in variables:
45 new_options.Add(v)
46 vars.Add(v)
47
Gian Marco Iodicef2399532017-09-13 14:16:41 +010048# Disable floating-point expression contraction (e.g. fused multiply-add operations)
49env.Append(CXXFLAGS = ['-ffp-contract=off'])
50
Anthony Barbier6ff3b192017-09-04 18:44:23 +010051# Clone the environment to make sure we're not polluting the arm_compute one:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010052test_env = env.Clone()
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010053vars.Update(test_env)
54
55Help(new_options.GenerateHelpText(test_env))
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010056
Anthony Barbier6db0ff52018-01-05 10:59:12 +000057Import("arm_compute_test_framework")
58test_env.Append(LIBS = arm_compute_test_framework)
59
Georgios Pinitas9873ea32017-12-05 15:28:55 +000060if env['os'] in ['android', 'bare_metal'] or env['standalone']:
Georgios Pinitasd8734b52017-12-22 15:27:52 +000061 Import("arm_compute_graph2_a")
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010062 Import("arm_compute_a")
Anthony Barbierb2881fc2017-09-29 17:12:12 +010063 Import("arm_compute_core_a")
Georgios Pinitasd8734b52017-12-22 15:27:52 +000064 test_env.Append(LIBS = [arm_compute_graph2_a, arm_compute_a, arm_compute_core_a])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010065 arm_compute_lib = arm_compute_a
66else:
Georgios Pinitasd8734b52017-12-22 15:27:52 +000067 Import("arm_compute_graph2_so")
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010068 Import("arm_compute_so")
Georgios Pinitasd8734b52017-12-22 15:27:52 +000069 test_env.Append(LIBS = ["arm_compute_graph2", "arm_compute", "arm_compute_core"])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010070 arm_compute_lib = arm_compute_so
71
72#FIXME Delete before release
Anthony Barbiera4e5e1e2017-10-05 14:55:34 +010073if env['internal_only']:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010074 test_env.Append(CPPDEFINES=['INTERNAL_ONLY'])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010075
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010076test_env.Append(CPPPATH = ["#3rdparty/include"])
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010077test_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])])
78test_env.Append(LIBPATH = ["#build/%s" % env['build_dir']])
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010079test_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010080
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010081common_files = Glob('*.cpp')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010082common_objects = [test_env.StaticObject(f) for f in common_files]
83
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010084files_benchmark = Glob('benchmark/*.cpp')
Anthony Barbier979dc4f2018-03-07 09:27:48 +000085files_validation_framework = [test_env.Object(f) for f in Glob('validation/*.cpp')]
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010086
87# Always compile reference for validation
Anthony Barbier979dc4f2018-03-07 09:27:48 +000088files_validation_framework += [ test_env.Object(f) for f in Glob('validation/reference/*.cpp')]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010089
Abe Mbise925ca0f2017-10-02 19:16:33 +010090# Add unit tests
Anthony Barbier979dc4f2018-03-07 09:27:48 +000091files_validation = Glob('validation/UNIT/*/*.cpp')
Abe Mbise925ca0f2017-10-02 19:16:33 +010092files_validation += Glob('validation/UNIT/*.cpp')
93
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000094# Add CPP tests
95filter_pattern = test_env['test_filter']
96files_validation += Glob('validation/CPP/' + filter_pattern)
97
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010098if env['opencl']:
99 Import('opencl')
Pablo Telloea1c9502017-11-09 11:49:18 +0000100 filter_pattern = test_env['test_filter']
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100101
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100102 test_env.Append(CPPDEFINES=['ARM_COMPUTE_CL'])
103 test_env.Append(LIBS = ["OpenCL"])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100104
Pablo Telloea1c9502017-11-09 11:49:18 +0000105 files_benchmark += Glob('benchmark/CL/*/' + filter_pattern)
106 files_benchmark += Glob('benchmark/CL/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100107
Pablo Telloea1c9502017-11-09 11:49:18 +0000108 files_validation += Glob('validation/CL/*/' + filter_pattern)
109 files_validation += Glob('validation/CL/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100110
111if env['neon']:
Pablo Telloea1c9502017-11-09 11:49:18 +0000112 filter_pattern = test_env['test_filter']
113 files_benchmark += Glob('benchmark/NEON/*/' + filter_pattern)
114 files_benchmark += Glob('benchmark/NEON/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100115
Pablo Telloea1c9502017-11-09 11:49:18 +0000116 files_validation += Glob('validation/NEON/*/' + filter_pattern)
117 files_validation += Glob('validation/NEON/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100118
Anthony Barbier7068f992017-10-26 15:23:08 +0100119if env['gles_compute']:
120 if env['os'] != 'android':
121 Import('egl')
122 Import('glesv2')
123
Anthony Barbier7068f992017-10-26 15:23:08 +0100124 test_env.Append(LIBS = ["EGL", "GLESv2"])
125 else:
126 if env['arch'] != 'armv7a':
127 test_env.Append(LIBS = ["EGL", "GLESv3"])
128 else:
129 test_env.Append(LIBS = ["EGL", "GLESv2"])
130
131 test_env.Append(CPPDEFINES=['ARM_COMPUTE_GC'])
132
133 files_benchmark += Glob('benchmark/GLES_COMPUTE/*/*.cpp')
134 files_benchmark += Glob('benchmark/GLES_COMPUTE/*.cpp')
135
136 files_validation += Glob('validation/GLES_COMPUTE/*/*.cpp')
137 files_validation += Glob('validation/GLES_COMPUTE/*.cpp')
138
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100139if env['os'] == 'android':
140 test_env.Append(LIBS = ["log"])
141else:
142 test_env.Append(LIBS = ["rt"])
143
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100144if test_env['benchmark_tests']:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100145 arm_compute_benchmark = test_env.Program('arm_compute_benchmark', files_benchmark + common_objects)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100146 Depends(arm_compute_benchmark, arm_compute_test_framework)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100147 Depends(arm_compute_benchmark, arm_compute_lib)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100148
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100149 if env['opencl']:
150 Depends(arm_compute_benchmark, opencl)
Anthony Barbier7068f992017-10-26 15:23:08 +0100151 if env['gles_compute'] and env['os'] != 'android':
152 Depends(arm_compute_benchmark, egl)
153 Depends(arm_compute_benchmark, glesv2)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100154
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100155 Default(arm_compute_benchmark)
156 Export('arm_compute_benchmark')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100157
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100158if test_env['validation_tests']:
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000159 arm_compute_validation = test_env.Program('arm_compute_validation', files_validation_framework + files_validation + common_objects)
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100160 Depends(arm_compute_validation, arm_compute_test_framework)
161 Depends(arm_compute_validation, arm_compute_lib)
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100162
163 if env['opencl']:
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100164 Depends(arm_compute_validation, opencl)
Anthony Barbier7068f992017-10-26 15:23:08 +0100165 if env['gles_compute'] and env['os'] != 'android':
166 Depends(arm_compute_validation, egl)
167 Depends(arm_compute_validation, glesv2)
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100168
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100169 Default(arm_compute_validation)
170 Export('arm_compute_validation')
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000171
Anthony Barbier979dc4f2018-03-07 09:27:48 +0000172 #FIXME: Remove before release!
173 if test_env['validate_examples']:
174 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)]
175 arm_compute_validate_examples = []
176 if test_env['neon']:
177 for file in Glob("validate_examples/neon_*.cpp"):
178 example = "validate_" + os.path.basename(os.path.splitext(str(file))[0])
179 arm_compute_validate_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_validate_examples) ]
180 if test_env['opencl']:
181 cl_examples = []
182 files = Glob("validate_examples/cl_*.cpp")
183 if test_env['neon']:
184 files += Glob("validate_examples/neoncl_*.cpp")
185 for file in files:
186 example = "validate_" + os.path.basename(os.path.splitext(str(file))[0])
187 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"]) ]
188 Depends(cl_examples, opencl)
189 arm_compute_validate_examples += cl_examples
190 if test_env['opencl'] and test_env['neon']:
191 if env['os'] == 'android':
192 Import('arm_compute_graph_a')
193 graph_dependency = arm_compute_graph_a
194 else:
195 Import('arm_compute_graph_so')
196 graph_dependency = arm_compute_graph_so
197
198 graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils")
199 for file in Glob("validate_examples/graph_*.cpp"):
200 example = "validate_" + os.path.basename(os.path.splitext(str(file))[0])
201 if env['os'] == 'android':
202 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'])
203 Depends(prog, [graph_dependency, opencl])
204 arm_compute_validate_examples += [ prog ]
205 else:
206 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
207 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'] )
208 Depends(prog, graph_dependency)
209 arm_compute_validate_examples += [ prog ]
210 Depends(arm_compute_validate_examples, arm_compute_test_framework)
211 Depends(arm_compute_validate_examples, arm_compute_lib)
212 Default(arm_compute_validate_examples)
213 Export('arm_compute_validate_examples')
214
Anthony Barbiere8a49832018-01-18 10:04:05 +0000215#FIXME: Remove before release!
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000216if test_env['benchmark_examples']:
217 files_benchmark_examples = test_env.Object('benchmark_examples/RunExample.cpp')
218 arm_compute_benchmark_examples = []
219 if test_env['neon']:
220 for file in Glob("../examples/neon_*.cpp"):
221 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
222 arm_compute_benchmark_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples) ]
223 if test_env['opencl']:
224 cl_examples = []
225 files = Glob("../examples/cl_*.cpp")
226 if test_env['neon']:
227 files += Glob("../examples/neoncl_*.cpp")
228 for file in files:
229 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
230 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"]) ]
231 Depends(cl_examples, opencl)
232 arm_compute_benchmark_examples += cl_examples
233 if test_env['opencl'] and test_env['neon']:
234 if env['os'] == 'android':
235 Import('arm_compute_graph_a')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000236 Import("arm_compute_graph2_a")
237 graph_dependency = [arm_compute_graph_a, arm_compute_graph2_a]
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000238 else:
239 Import('arm_compute_graph_so')
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000240 Import('arm_compute_graph2_so')
241 graph_dependency = [arm_compute_graph_so, arm_compute_graph2_so]
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000242
243 graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils")
244 for file in Glob("../examples/graph_*.cpp"):
245 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
246 if env['os'] == 'android':
247 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'])
248 Depends(prog, [graph_dependency, opencl])
249 arm_compute_benchmark_examples += [ prog ]
250 else:
251 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000252 prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_benchmark_examples, LIBS = test_env["LIBS"] + ["arm_compute_graph", "arm_compute_graph2"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] )
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000253 Depends(prog, graph_dependency)
254 arm_compute_benchmark_examples += [ prog ]
255 Depends(arm_compute_benchmark_examples, arm_compute_test_framework)
256 Depends(arm_compute_benchmark_examples, arm_compute_lib)
257 Default(arm_compute_benchmark_examples)
258 Export('arm_compute_benchmark_examples')
259