blob: 9f6392653c0fa0dd3ce4ca818b9c963d9987df56 [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 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
Gian Marco Iodicef2399532017-09-13 14:16:41 +010047# Disable floating-point expression contraction (e.g. fused multiply-add operations)
48env.Append(CXXFLAGS = ['-ffp-contract=off'])
49
Anthony Barbier6ff3b192017-09-04 18:44:23 +010050# Clone the environment to make sure we're not polluting the arm_compute one:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010051test_env = env.Clone()
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010052vars.Update(test_env)
53
54Help(new_options.GenerateHelpText(test_env))
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010055
Anthony Barbier6db0ff52018-01-05 10:59:12 +000056Import("arm_compute_test_framework")
57test_env.Append(LIBS = arm_compute_test_framework)
58
Georgios Pinitas9873ea32017-12-05 15:28:55 +000059if env['os'] in ['android', 'bare_metal'] or env['standalone']:
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010060 Import("arm_compute_a")
Anthony Barbierb2881fc2017-09-29 17:12:12 +010061 Import("arm_compute_core_a")
62 test_env.Append(LIBS = [arm_compute_a, arm_compute_core_a])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010063 arm_compute_lib = arm_compute_a
64else:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010065 Import("arm_compute_so")
Anthony Barbierb2881fc2017-09-29 17:12:12 +010066 test_env.Append(LIBS = ["arm_compute", "arm_compute_core"])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010067 arm_compute_lib = arm_compute_so
68
69#FIXME Delete before release
Anthony Barbiera4e5e1e2017-10-05 14:55:34 +010070if env['internal_only']:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010071 test_env.Append(CPPDEFINES=['INTERNAL_ONLY'])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010072
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010073test_env.Append(CPPPATH = ["#3rdparty/include"])
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010074test_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])])
75test_env.Append(LIBPATH = ["#build/%s" % env['build_dir']])
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010076test_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010077
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010078common_files = Glob('*.cpp')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010079common_objects = [test_env.StaticObject(f) for f in common_files]
80
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010081files_benchmark = Glob('benchmark/*.cpp')
82files_validation = Glob('validation/*.cpp')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010083
84# Always compile reference for validation
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000085files_validation += Glob('validation/reference/*.cpp')
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010086
Abe Mbise925ca0f2017-10-02 19:16:33 +010087# Add unit tests
88files_validation += Glob('validation/UNIT/*/*.cpp')
89files_validation += Glob('validation/UNIT/*.cpp')
90
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000091# Add CPP tests
92filter_pattern = test_env['test_filter']
93files_validation += Glob('validation/CPP/' + filter_pattern)
94
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010095if env['opencl']:
96 Import('opencl')
Pablo Telloea1c9502017-11-09 11:49:18 +000097 filter_pattern = test_env['test_filter']
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010098
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010099 test_env.Append(CPPDEFINES=['ARM_COMPUTE_CL'])
100 test_env.Append(LIBS = ["OpenCL"])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100101
Pablo Telloea1c9502017-11-09 11:49:18 +0000102 files_benchmark += Glob('benchmark/CL/*/' + filter_pattern)
103 files_benchmark += Glob('benchmark/CL/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100104
Pablo Telloea1c9502017-11-09 11:49:18 +0000105 files_validation += Glob('validation/CL/*/' + filter_pattern)
106 files_validation += Glob('validation/CL/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100107
108if env['neon']:
Pablo Telloea1c9502017-11-09 11:49:18 +0000109 filter_pattern = test_env['test_filter']
110 files_benchmark += Glob('benchmark/NEON/*/' + filter_pattern)
111 files_benchmark += Glob('benchmark/NEON/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100112
Pablo Telloea1c9502017-11-09 11:49:18 +0000113 files_validation += Glob('validation/NEON/*/' + filter_pattern)
114 files_validation += Glob('validation/NEON/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100115
Anthony Barbier7068f992017-10-26 15:23:08 +0100116if env['gles_compute']:
117 if env['os'] != 'android':
118 Import('egl')
119 Import('glesv2')
120
Anthony Barbier7068f992017-10-26 15:23:08 +0100121 test_env.Append(LIBS = ["EGL", "GLESv2"])
122 else:
123 if env['arch'] != 'armv7a':
124 test_env.Append(LIBS = ["EGL", "GLESv3"])
125 else:
126 test_env.Append(LIBS = ["EGL", "GLESv2"])
127
128 test_env.Append(CPPDEFINES=['ARM_COMPUTE_GC'])
129
130 files_benchmark += Glob('benchmark/GLES_COMPUTE/*/*.cpp')
131 files_benchmark += Glob('benchmark/GLES_COMPUTE/*.cpp')
132
133 files_validation += Glob('validation/GLES_COMPUTE/*/*.cpp')
134 files_validation += Glob('validation/GLES_COMPUTE/*.cpp')
135
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100136if env['os'] == 'android':
137 test_env.Append(LIBS = ["log"])
138else:
139 test_env.Append(LIBS = ["rt"])
140
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100141if test_env['benchmark_tests']:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100142 arm_compute_benchmark = test_env.Program('arm_compute_benchmark', files_benchmark + common_objects)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100143 Depends(arm_compute_benchmark, arm_compute_test_framework)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100144 Depends(arm_compute_benchmark, arm_compute_lib)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100145
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146 if env['opencl']:
147 Depends(arm_compute_benchmark, opencl)
Anthony Barbier7068f992017-10-26 15:23:08 +0100148 if env['gles_compute'] and env['os'] != 'android':
149 Depends(arm_compute_benchmark, egl)
150 Depends(arm_compute_benchmark, glesv2)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100151
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152 Default(arm_compute_benchmark)
153 Export('arm_compute_benchmark')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100154
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100155if test_env['validation_tests']:
156 arm_compute_validation = test_env.Program('arm_compute_validation', files_validation + common_objects)
157 Depends(arm_compute_validation, arm_compute_test_framework)
158 Depends(arm_compute_validation, arm_compute_lib)
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100159
160 if env['opencl']:
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100161 Depends(arm_compute_validation, opencl)
Anthony Barbier7068f992017-10-26 15:23:08 +0100162 if env['gles_compute'] and env['os'] != 'android':
163 Depends(arm_compute_validation, egl)
164 Depends(arm_compute_validation, glesv2)
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100165
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100166 Default(arm_compute_validation)
167 Export('arm_compute_validation')
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000168
Anthony Barbiere8a49832018-01-18 10:04:05 +0000169#FIXME: Remove before release!
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000170if test_env['benchmark_examples']:
171 files_benchmark_examples = test_env.Object('benchmark_examples/RunExample.cpp')
172 arm_compute_benchmark_examples = []
173 if test_env['neon']:
174 for file in Glob("../examples/neon_*.cpp"):
175 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
176 arm_compute_benchmark_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples) ]
177 if test_env['opencl']:
178 cl_examples = []
179 files = Glob("../examples/cl_*.cpp")
180 if test_env['neon']:
181 files += Glob("../examples/neoncl_*.cpp")
182 for file in files:
183 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
184 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"]) ]
185 Depends(cl_examples, opencl)
186 arm_compute_benchmark_examples += cl_examples
187 if test_env['opencl'] and test_env['neon']:
188 if env['os'] == 'android':
189 Import('arm_compute_graph_a')
190 graph_dependency = arm_compute_graph_a
191 else:
192 Import('arm_compute_graph_so')
193 graph_dependency = arm_compute_graph_so
194
195 graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils")
196 for file in Glob("../examples/graph_*.cpp"):
197 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
198 if env['os'] == 'android':
199 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'])
200 Depends(prog, [graph_dependency, opencl])
201 arm_compute_benchmark_examples += [ prog ]
202 else:
203 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
204 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'] )
205 Depends(prog, graph_dependency)
206 arm_compute_benchmark_examples += [ prog ]
207 Depends(arm_compute_benchmark_examples, arm_compute_test_framework)
208 Depends(arm_compute_benchmark_examples, arm_compute_lib)
209 Default(arm_compute_benchmark_examples)
210 Export('arm_compute_benchmark_examples')
211