blob: bbb43c9a39439c8af5ab266288b5f699e282d823 [file] [log] [blame]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01001/*
Georgios Pinitas7f152512019-12-16 19:59:52 +00002 * Copyright (c) 2017-2020 ARM Limited.
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Matthew Bentham92046462020-03-07 22:15:55 +000024#include "support/MemorySupport.h"
25#include "support/StringSupport.h"
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010026#include "tests/AssetsLibrary.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010027#include "tests/framework/DatasetModes.h"
28#include "tests/framework/Exceptions.h"
29#include "tests/framework/Framework.h"
30#include "tests/framework/Macros.h"
Pablo Tellodb8485a2019-09-24 11:03:47 +010031#include "tests/framework/ParametersLibrary.h"
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +010032#include "tests/framework/Profiler.h"
Anthony Barbier6db0ff52018-01-05 10:59:12 +000033#include "tests/framework/command_line/CommonOptions.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010034#include "tests/framework/instruments/Instruments.h"
35#include "tests/framework/printers/Printers.h"
Georgios Pinitas12833d02019-07-25 13:31:10 +010036#include "tests/instruments/Helpers.h"
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010037#include "utils/command_line/CommandLineOptions.h"
38#include "utils/command_line/CommandLineParser.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010039
Anthony Barbier15d5ac82017-07-17 15:22:17 +010040#ifdef ARM_COMPUTE_CL
Pablo Tellob7c308a2019-01-22 12:59:26 +000041#include "arm_compute/core/CL/OpenCL.h"
42#include "arm_compute/runtime/CL/CLHelpers.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010043#include "arm_compute/runtime/CL/CLScheduler.h"
Anthony Barbier943a40b2018-07-12 18:03:54 +010044#include "arm_compute/runtime/CL/CLTuner.h"
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010045#include "utils/TypePrinter.h"
Anthony Barbier15d5ac82017-07-17 15:22:17 +010046#endif /* ARM_COMPUTE_CL */
Anthony Barbier7068f992017-10-26 15:23:08 +010047#ifdef ARM_COMPUTE_GC
48#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
49#endif /* ARM_COMPUTE_GC */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010050#include "arm_compute/runtime/Scheduler.h"
51
52#include <fstream>
53#include <initializer_list>
54#include <iostream>
55#include <memory>
56#include <random>
57#include <utility>
58
59using namespace arm_compute;
60using namespace arm_compute::test;
61
Anthony Barbier1fa17c22018-08-23 15:44:20 +010062namespace
63{
64std::string command_line(int argc, char **argv)
65{
66 std::stringstream ss;
67 for(int i = 0; i < argc; i++)
68 {
69 ss << argv[i] << " ";
70 }
71 return ss.str();
72}
73} // namespace
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010074namespace arm_compute
75{
76namespace test
77{
Pablo Tellodb8485a2019-09-24 11:03:47 +010078std::unique_ptr<AssetsLibrary> library;
79extern std::unique_ptr<ParametersLibrary> parameters;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010080} // namespace test
81} // namespace arm_compute
82
Anthony Barbier7b607dc2018-07-13 15:55:24 +010083namespace
84{
85#ifdef ARM_COMPUTE_CL
86bool file_exists(const std::string &filename)
87{
88 std::ifstream file(filename);
89 return file.good();
90}
91#endif /* ARM_COMPUTE_CL */
92} //namespace
93
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010094int main(int argc, char **argv)
95{
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010096 framework::Framework &framework = framework::Framework::get();
97
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010098 utils::CommandLineParser parser;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010099
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +0100100 std::set<framework::DatasetMode> allowed_modes
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100101 {
Georgios Pinitas557d4ae2019-04-18 18:10:34 +0100102 framework::DatasetMode::DISABLED,
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +0100103 framework::DatasetMode::PRECOMMIT,
104 framework::DatasetMode::NIGHTLY,
105 framework::DatasetMode::ALL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100106 };
107
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000108 framework::CommonOptions options(parser);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100109
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100110 auto dataset_mode = parser.add_option<utils::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100111 dataset_mode->set_help("For managed datasets select which group to use");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100112 auto filter = parser.add_option<utils::SimpleOption<std::string>>("filter", ".*");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100113 filter->set_help("Regular expression to select test cases");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100114 auto filter_id = parser.add_option<utils::SimpleOption<std::string>>("filter-id");
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100115 filter_id->set_help("List of test ids. ... can be used to define a range.");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100116 auto stop_on_error = parser.add_option<utils::ToggleOption>("stop-on-error");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100117 stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100118 auto seed = parser.add_option<utils::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100119 seed->set_help("Global seed for random number generation");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100120 auto list_tests = parser.add_option<utils::ToggleOption>("list-tests", false);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100121 list_tests->set_help("List all test names");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100122 auto test_instruments = parser.add_option<utils::ToggleOption>("test-instruments", false);
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100123 test_instruments->set_help("Test if the instruments work on the platform");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100124 auto error_on_missing_assets = parser.add_option<utils::ToggleOption>("error-on-missing-assets", false);
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100125 error_on_missing_assets->set_help("Mark a test as failed instead of skipping it when assets are missing");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100126 auto assets = parser.add_positional_option<utils::SimpleOption<std::string>>("assets");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100127 assets->set_help("Path to the assets directory");
Anthony Barbier943a40b2018-07-12 18:03:54 +0100128#ifdef ARM_COMPUTE_CL
129 auto enable_tuner = parser.add_option<utils::ToggleOption>("enable-tuner");
130 enable_tuner->set_help("Enable OpenCL dynamic tuner");
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +0100131
132 const std::set<CLTunerMode> supported_tuner_modes
133 {
134 CLTunerMode::EXHAUSTIVE,
135 CLTunerMode::NORMAL,
136 CLTunerMode::RAPID
137 };
Michalis Spyrou083a0692019-05-13 15:35:50 +0100138 auto tuner_mode = parser.add_option<utils::EnumOption<CLTunerMode>>("tuner-mode", supported_tuner_modes, CLTunerMode::NORMAL);
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +0100139 tuner_mode->set_help("Configures the time taken by the tuner to tune. Slow tuner produces the most performant LWS configuration");
140
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100141 auto tuner_file = parser.add_option<utils::SimpleOption<std::string>>("tuner-file", "");
142 tuner_file->set_help("File to load/save CLTuner values");
Anthony Barbier943a40b2018-07-12 18:03:54 +0100143#endif /* ARM_COMPUTE_CL */
Anthony Barbier94522332018-07-13 09:26:51 +0100144 auto threads = parser.add_option<utils::SimpleOption<int>>("threads", 1);
145 threads->set_help("Number of threads to use");
Georgios Pinitas7f152512019-12-16 19:59:52 +0000146 auto cooldown_sec = parser.add_option<utils::SimpleOption<float>>("delay", -1.f);
147 cooldown_sec->set_help("Delay to add between test executions in seconds");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100148
149 try
150 {
151 parser.parse(argc, argv);
152
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000153 if(options.help->is_set() && options.help->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100154 {
155 parser.print_help(argv[0]);
156 return 0;
157 }
158
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000159 std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100160
Georgios Pinitas12833d02019-07-25 13:31:10 +0100161 // Setup CPU Scheduler
Anthony Barbier94522332018-07-13 09:26:51 +0100162 Scheduler::get().set_num_threads(threads->value());
Georgios Pinitas12833d02019-07-25 13:31:10 +0100163
164 // Create CPU context
165 auto cpu_ctx = support::cpp14::make_unique<RuntimeContext>();
166 cpu_ctx->set_scheduler(&Scheduler::get());
167
168 // Track CPU context
169 auto cpu_ctx_track = support::cpp14::make_unique<ContextSchedulerUser>(cpu_ctx.get());
170
171 // Create parameters
172 parameters = support::cpp14::make_unique<ParametersLibrary>();
173 parameters->set_cpu_ctx(std::move(cpu_ctx));
174
Georgios Pinitas7ae80a92019-10-25 18:25:17 +0100175#ifdef ARM_COMPUTE_GC
176 // Setup OpenGL context
177 {
178 auto gles_ctx = support::cpp14::make_unique<GCRuntimeContext>();
179 ARM_COMPUTE_ERROR_ON(gles_ctx == nullptr);
180 {
181 // Legacy singletons API: This has been deprecated and the singletons will be removed
182 // Setup singleton for backward compatibility
183 GCScheduler::get().default_init();
184 }
185 parameters->set_gc_ctx(std::move(gles_ctx));
186 };
187#endif /* ARM_COMPUTE_GC */
188
Anthony Barbier943a40b2018-07-12 18:03:54 +0100189#ifdef ARM_COMPUTE_CL
Pablo Tellodb8485a2019-09-24 11:03:47 +0100190 CLTuner cl_tuner(false);
Georgios Pinitasc9f163b2019-11-18 14:25:45 +0000191 if(opencl_is_available())
Pablo Tellodb8485a2019-09-24 11:03:47 +0100192 {
Georgios Pinitasc9f163b2019-11-18 14:25:45 +0000193 auto ctx_dev_err = create_opencl_context_and_device();
194 ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context");
195 CLScheduler::get().default_init_with_context(std::get<1>(ctx_dev_err), std::get<0>(ctx_dev_err), &cl_tuner);
Pablo Tellodb8485a2019-09-24 11:03:47 +0100196 }
Pablo Tellodb8485a2019-09-24 11:03:47 +0100197
Anthony Barbier943a40b2018-07-12 18:03:54 +0100198 if(enable_tuner->is_set())
199 {
Pablo Tello5f98d742019-07-22 16:41:10 +0100200 cl_tuner.set_tune_new_kernels(enable_tuner->value());
201
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +0100202 //set tuner mode
203 cl_tuner.set_tuner_mode(tuner_mode->value());
204
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100205 // If that's the first run then the file won't exist yet
206 if(file_exists(tuner_file->value()))
207 {
208 cl_tuner.load_from_file(tuner_file->value());
209 }
210 }
211 else if(!tuner_file->value().empty())
212 {
213 //If we're not tuning and the file doesn't exist then we should raise an error:
214 cl_tuner.load_from_file(tuner_file->value());
Anthony Barbier943a40b2018-07-12 18:03:54 +0100215 }
216#endif /* ARM_COMPUTE_CL */
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000217 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100218 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000219 for(auto &p : printers)
220 {
221 p->print_global_header();
222 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100223 }
224
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000225 if(options.log_level->value() >= framework::LogLevel::CONFIG)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100226 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000227 for(auto &p : printers)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100228 {
Anthony Barbier4b9c58a2018-01-10 14:34:00 +0000229 p->print_entry("Version", build_information());
Anthony Barbier1fa17c22018-08-23 15:44:20 +0100230 p->print_entry("CommandLine", command_line(argc, argv));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000231 p->print_entry("Seed", support::cpp11::to_string(seed->value()));
Anthony Barbier847864d2018-03-07 11:35:53 +0000232#ifdef ARM_COMPUTE_CL
233 if(opencl_is_available())
234 {
Georgios Pinitasc9f163b2019-11-18 14:25:45 +0000235 p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version());
Anthony Barbier847864d2018-03-07 11:35:53 +0000236 }
237 else
238 {
239 p->print_entry("CL_DEVICE_VERSION", "Unavailable");
240 }
241#endif /* ARM_COMPUTE_CL */
Gian Marco Iodice555c3d62018-10-16 16:00:50 +0100242 const arm_compute::CPUInfo &cpu_info = Scheduler::get().cpu_info();
243 const unsigned int num_cpus = cpu_info.get_cpu_num();
244 p->print_entry("cpu_has_fp16", support::cpp11::to_string(cpu_info.has_fp16()));
245 p->print_entry("cpu_has_dotprod", support::cpp11::to_string(cpu_info.has_dotprod()));
246
247 for(unsigned int j = 0; j < num_cpus; ++j)
248 {
249 const CPUModel model = cpu_info.get_cpu_model(j);
250 p->print_entry("CPU" + support::cpp11::to_string(j), cpu_model_to_string(model));
251 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000252 p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
Anthony Barbier94522332018-07-13 09:26:51 +0100253 p->print_entry("Threads", support::cpp11::to_string(threads->value()));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000254 {
255 using support::cpp11::to_string;
256 p->print_entry("Dataset mode", to_string(dataset_mode->value()));
257 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100258 }
259 }
260
Georgios Pinitas12833d02019-07-25 13:31:10 +0100261 // Setup instruments meta-data
262 framework::InstrumentsInfo instruments_info;
263 instruments_info._scheduler_users.push_back(cpu_ctx_track.get());
264 framework.set_instruments_info(instruments_info);
265
266 // Initialize framework
Georgios Pinitas7f152512019-12-16 19:59:52 +0000267 framework::FrameworkConfig fconfig;
268 fconfig.instruments = options.instruments->value();
269 fconfig.name_filter = filter->value();
270 fconfig.id_filter = filter_id->value();
271 fconfig.num_iterations = options.iterations->value();
272 fconfig.mode = dataset_mode->value();
273 fconfig.log_level = options.log_level->value();
274 fconfig.cooldown_sec = cooldown_sec->value();
275 framework.init(fconfig);
Georgios Pinitas12833d02019-07-25 13:31:10 +0100276
Giorgio Arenac5d54392017-10-31 15:18:49 +0000277 for(auto &p : printers)
278 {
279 framework.add_printer(p.get());
280 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000281 framework.set_throw_errors(options.throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100282 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100283 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100284
285 bool success = true;
286
287 if(list_tests->value())
288 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000289 for(auto &p : printers)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100290 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000291 p->print_list_tests(framework.test_infos());
292 p->print_global_footer();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100293 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100294
295 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100296 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100297
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100298 if(test_instruments->value())
299 {
300 framework::Profiler profiler = framework.get_profiler();
301 profiler.start();
302 profiler.stop();
Giorgio Arenac5d54392017-10-31 15:18:49 +0000303 for(auto &p : printers)
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100304 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000305 p->print_measurements(profiler.measurements());
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100306 }
Giorgio Arenac5d54392017-10-31 15:18:49 +0000307
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100308 return 0;
309 }
310
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100311 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100312
313 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100314 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100315 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100316 }
317
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100318 success = framework.run();
319
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000320 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100321 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000322 for(auto &p : printers)
323 {
324 p->print_global_footer();
325 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100326 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100327
Michalis Spyrou84f3ae82018-01-15 11:15:26 +0000328#ifdef ARM_COMPUTE_CL
Anthony Barbier2113b9d2018-08-23 09:48:40 +0100329 if(opencl_is_available())
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100330 {
Anthony Barbier2113b9d2018-08-23 09:48:40 +0100331 CLScheduler::get().sync();
332 if(enable_tuner->is_set() && enable_tuner->value() && tuner_file->is_set())
333 {
334 cl_tuner.save_to_file(tuner_file->value());
335 }
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100336 }
Michalis Spyrou84f3ae82018-01-15 11:15:26 +0000337#endif /* ARM_COMPUTE_CL */
338
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100339 return (success ? 0 : 1);
340 }
341 catch(const std::exception &error)
342 {
343 std::cerr << error.what() << "\n";
344
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000345 if(options.throw_errors->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100346 {
347 throw;
348 }
349
350 return 1;
351 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100352 return 0;
353}