blob: 01741939a0383c2a66474bc6c9df07c9278b9de2 [file] [log] [blame]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01001/*
Pablo Tellob7c308a2019-01-22 12:59:26 +00002 * Copyright (c) 2017-2019 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 */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010024#include "support/ToolchainSupport.h"
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010025#include "tests/AssetsLibrary.h"
Georgios Pinitas12833d02019-07-25 13:31:10 +010026#include "tests/ParametersLibrary.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"
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +010031#include "tests/framework/Profiler.h"
Anthony Barbier6db0ff52018-01-05 10:59:12 +000032#include "tests/framework/command_line/CommonOptions.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010033#include "tests/framework/instruments/Instruments.h"
34#include "tests/framework/printers/Printers.h"
Georgios Pinitas12833d02019-07-25 13:31:10 +010035#include "tests/instruments/Helpers.h"
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010036#include "utils/command_line/CommandLineOptions.h"
37#include "utils/command_line/CommandLineParser.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010038
Anthony Barbier15d5ac82017-07-17 15:22:17 +010039#ifdef ARM_COMPUTE_CL
Pablo Tellob7c308a2019-01-22 12:59:26 +000040#include "arm_compute/core/CL/OpenCL.h"
41#include "arm_compute/runtime/CL/CLHelpers.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010042#include "arm_compute/runtime/CL/CLScheduler.h"
Anthony Barbier943a40b2018-07-12 18:03:54 +010043#include "arm_compute/runtime/CL/CLTuner.h"
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010044#include "utils/TypePrinter.h"
Anthony Barbier15d5ac82017-07-17 15:22:17 +010045#endif /* ARM_COMPUTE_CL */
Anthony Barbier7068f992017-10-26 15:23:08 +010046#ifdef ARM_COMPUTE_GC
47#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
48#endif /* ARM_COMPUTE_GC */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010049#include "arm_compute/runtime/Scheduler.h"
50
51#include <fstream>
52#include <initializer_list>
53#include <iostream>
54#include <memory>
55#include <random>
56#include <utility>
57
58using namespace arm_compute;
59using namespace arm_compute::test;
60
Anthony Barbier1fa17c22018-08-23 15:44:20 +010061namespace
62{
63std::string command_line(int argc, char **argv)
64{
65 std::stringstream ss;
66 for(int i = 0; i < argc; i++)
67 {
68 ss << argv[i] << " ";
69 }
70 return ss.str();
71}
72} // namespace
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010073namespace arm_compute
74{
75namespace test
76{
Georgios Pinitas12833d02019-07-25 13:31:10 +010077std::unique_ptr<AssetsLibrary> library;
78std::unique_ptr<ParametersLibrary> parameters;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010079} // namespace test
80} // namespace arm_compute
81
Anthony Barbier7b607dc2018-07-13 15:55:24 +010082namespace
83{
84#ifdef ARM_COMPUTE_CL
85bool file_exists(const std::string &filename)
86{
87 std::ifstream file(filename);
88 return file.good();
89}
90#endif /* ARM_COMPUTE_CL */
91} //namespace
92
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010093int main(int argc, char **argv)
94{
Anthony Barbier15d5ac82017-07-17 15:22:17 +010095#ifdef ARM_COMPUTE_CL
Anthony Barbier943a40b2018-07-12 18:03:54 +010096 CLTuner cl_tuner(false);
Anthony Barbier890ad1b2018-08-22 13:44:36 +010097 if(opencl_is_available())
98 {
Pablo Tellob7c308a2019-01-22 12:59:26 +000099 auto ctx_dev_err = create_opencl_context_and_device();
100 ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context");
101 CLScheduler::get()
102 .default_init_with_context(std::get<1>(ctx_dev_err), std::get<0>(ctx_dev_err), &cl_tuner);
Anthony Barbier890ad1b2018-08-22 13:44:36 +0100103 }
Anthony Barbier15d5ac82017-07-17 15:22:17 +0100104#endif /* ARM_COMPUTE_CL */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100105
Anthony Barbier7068f992017-10-26 15:23:08 +0100106#ifdef ARM_COMPUTE_GC
107 GCScheduler::get().default_init();
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000108#endif /* ARM_COMPUTE_GC */
Anthony Barbier7068f992017-10-26 15:23:08 +0100109
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100110 framework::Framework &framework = framework::Framework::get();
111
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100112 utils::CommandLineParser parser;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100113
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +0100114 std::set<framework::DatasetMode> allowed_modes
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100115 {
Georgios Pinitas557d4ae2019-04-18 18:10:34 +0100116 framework::DatasetMode::DISABLED,
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +0100117 framework::DatasetMode::PRECOMMIT,
118 framework::DatasetMode::NIGHTLY,
119 framework::DatasetMode::ALL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100120 };
121
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000122 framework::CommonOptions options(parser);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100123
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100124 auto dataset_mode = parser.add_option<utils::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100125 dataset_mode->set_help("For managed datasets select which group to use");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100126 auto filter = parser.add_option<utils::SimpleOption<std::string>>("filter", ".*");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100127 filter->set_help("Regular expression to select test cases");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100128 auto filter_id = parser.add_option<utils::SimpleOption<std::string>>("filter-id");
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100129 filter_id->set_help("List of test ids. ... can be used to define a range.");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100130 auto stop_on_error = parser.add_option<utils::ToggleOption>("stop-on-error");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100131 stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100132 auto seed = parser.add_option<utils::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100133 seed->set_help("Global seed for random number generation");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100134 auto list_tests = parser.add_option<utils::ToggleOption>("list-tests", false);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100135 list_tests->set_help("List all test names");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100136 auto test_instruments = parser.add_option<utils::ToggleOption>("test-instruments", false);
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100137 test_instruments->set_help("Test if the instruments work on the platform");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100138 auto error_on_missing_assets = parser.add_option<utils::ToggleOption>("error-on-missing-assets", false);
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100139 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 +0100140 auto assets = parser.add_positional_option<utils::SimpleOption<std::string>>("assets");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100141 assets->set_help("Path to the assets directory");
Anthony Barbier943a40b2018-07-12 18:03:54 +0100142#ifdef ARM_COMPUTE_CL
143 auto enable_tuner = parser.add_option<utils::ToggleOption>("enable-tuner");
144 enable_tuner->set_help("Enable OpenCL dynamic tuner");
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +0100145
146 const std::set<CLTunerMode> supported_tuner_modes
147 {
148 CLTunerMode::EXHAUSTIVE,
149 CLTunerMode::NORMAL,
150 CLTunerMode::RAPID
151 };
Michalis Spyrou083a0692019-05-13 15:35:50 +0100152 auto tuner_mode = parser.add_option<utils::EnumOption<CLTunerMode>>("tuner-mode", supported_tuner_modes, CLTunerMode::NORMAL);
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +0100153 tuner_mode->set_help("Configures the time taken by the tuner to tune. Slow tuner produces the most performant LWS configuration");
154
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100155 auto tuner_file = parser.add_option<utils::SimpleOption<std::string>>("tuner-file", "");
156 tuner_file->set_help("File to load/save CLTuner values");
Anthony Barbier943a40b2018-07-12 18:03:54 +0100157#endif /* ARM_COMPUTE_CL */
Anthony Barbier94522332018-07-13 09:26:51 +0100158 auto threads = parser.add_option<utils::SimpleOption<int>>("threads", 1);
159 threads->set_help("Number of threads to use");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100160
161 try
162 {
163 parser.parse(argc, argv);
164
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000165 if(options.help->is_set() && options.help->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100166 {
167 parser.print_help(argv[0]);
168 return 0;
169 }
170
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000171 std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100172
Georgios Pinitas12833d02019-07-25 13:31:10 +0100173 // Setup CPU Scheduler
Anthony Barbier94522332018-07-13 09:26:51 +0100174 Scheduler::get().set_num_threads(threads->value());
Georgios Pinitas12833d02019-07-25 13:31:10 +0100175
176 // Create CPU context
177 auto cpu_ctx = support::cpp14::make_unique<RuntimeContext>();
178 cpu_ctx->set_scheduler(&Scheduler::get());
179
180 // Track CPU context
181 auto cpu_ctx_track = support::cpp14::make_unique<ContextSchedulerUser>(cpu_ctx.get());
182
183 // Create parameters
184 parameters = support::cpp14::make_unique<ParametersLibrary>();
185 parameters->set_cpu_ctx(std::move(cpu_ctx));
186
Anthony Barbier943a40b2018-07-12 18:03:54 +0100187#ifdef ARM_COMPUTE_CL
188 if(enable_tuner->is_set())
189 {
Pablo Tello5f98d742019-07-22 16:41:10 +0100190 cl_tuner.set_tune_new_kernels(enable_tuner->value());
191
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +0100192 //set tuner mode
193 cl_tuner.set_tuner_mode(tuner_mode->value());
194
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100195 // If that's the first run then the file won't exist yet
196 if(file_exists(tuner_file->value()))
197 {
198 cl_tuner.load_from_file(tuner_file->value());
199 }
200 }
201 else if(!tuner_file->value().empty())
202 {
203 //If we're not tuning and the file doesn't exist then we should raise an error:
204 cl_tuner.load_from_file(tuner_file->value());
Anthony Barbier943a40b2018-07-12 18:03:54 +0100205 }
206#endif /* ARM_COMPUTE_CL */
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000207 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100208 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000209 for(auto &p : printers)
210 {
211 p->print_global_header();
212 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100213 }
214
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000215 if(options.log_level->value() >= framework::LogLevel::CONFIG)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100216 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000217 for(auto &p : printers)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100218 {
Anthony Barbier4b9c58a2018-01-10 14:34:00 +0000219 p->print_entry("Version", build_information());
Anthony Barbier1fa17c22018-08-23 15:44:20 +0100220 p->print_entry("CommandLine", command_line(argc, argv));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000221 p->print_entry("Seed", support::cpp11::to_string(seed->value()));
Anthony Barbier847864d2018-03-07 11:35:53 +0000222#ifdef ARM_COMPUTE_CL
223 if(opencl_is_available())
224 {
225 p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version());
226 }
227 else
228 {
229 p->print_entry("CL_DEVICE_VERSION", "Unavailable");
230 }
231#endif /* ARM_COMPUTE_CL */
Gian Marco Iodice555c3d62018-10-16 16:00:50 +0100232 const arm_compute::CPUInfo &cpu_info = Scheduler::get().cpu_info();
233 const unsigned int num_cpus = cpu_info.get_cpu_num();
234 p->print_entry("cpu_has_fp16", support::cpp11::to_string(cpu_info.has_fp16()));
235 p->print_entry("cpu_has_dotprod", support::cpp11::to_string(cpu_info.has_dotprod()));
236
237 for(unsigned int j = 0; j < num_cpus; ++j)
238 {
239 const CPUModel model = cpu_info.get_cpu_model(j);
240 p->print_entry("CPU" + support::cpp11::to_string(j), cpu_model_to_string(model));
241 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000242 p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
Anthony Barbier94522332018-07-13 09:26:51 +0100243 p->print_entry("Threads", support::cpp11::to_string(threads->value()));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000244 {
245 using support::cpp11::to_string;
246 p->print_entry("Dataset mode", to_string(dataset_mode->value()));
247 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100248 }
249 }
250
Georgios Pinitas12833d02019-07-25 13:31:10 +0100251 // Setup instruments meta-data
252 framework::InstrumentsInfo instruments_info;
253 instruments_info._scheduler_users.push_back(cpu_ctx_track.get());
254 framework.set_instruments_info(instruments_info);
255
256 // Initialize framework
257 framework.init(options.instruments->value(),
258 options.iterations->value(),
259 dataset_mode->value(),
260 filter->value(),
261 filter_id->value(),
262 options.log_level->value());
263
Giorgio Arenac5d54392017-10-31 15:18:49 +0000264 for(auto &p : printers)
265 {
266 framework.add_printer(p.get());
267 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000268 framework.set_throw_errors(options.throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100269 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100270 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100271
272 bool success = true;
273
274 if(list_tests->value())
275 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000276 for(auto &p : printers)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100277 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000278 p->print_list_tests(framework.test_infos());
279 p->print_global_footer();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100280 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100281
282 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100283 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100284
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100285 if(test_instruments->value())
286 {
287 framework::Profiler profiler = framework.get_profiler();
288 profiler.start();
289 profiler.stop();
Giorgio Arenac5d54392017-10-31 15:18:49 +0000290 for(auto &p : printers)
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100291 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000292 p->print_measurements(profiler.measurements());
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100293 }
Giorgio Arenac5d54392017-10-31 15:18:49 +0000294
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100295 return 0;
296 }
297
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100298 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100299
300 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100301 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100302 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100303 }
304
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100305 success = framework.run();
306
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000307 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100308 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000309 for(auto &p : printers)
310 {
311 p->print_global_footer();
312 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100313 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100314
Michalis Spyrou84f3ae82018-01-15 11:15:26 +0000315#ifdef ARM_COMPUTE_CL
Anthony Barbier2113b9d2018-08-23 09:48:40 +0100316 if(opencl_is_available())
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100317 {
Anthony Barbier2113b9d2018-08-23 09:48:40 +0100318 CLScheduler::get().sync();
319 if(enable_tuner->is_set() && enable_tuner->value() && tuner_file->is_set())
320 {
321 cl_tuner.save_to_file(tuner_file->value());
322 }
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100323 }
Michalis Spyrou84f3ae82018-01-15 11:15:26 +0000324#endif /* ARM_COMPUTE_CL */
325
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100326 return (success ? 0 : 1);
327 }
328 catch(const std::exception &error)
329 {
330 std::cerr << error.what() << "\n";
331
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000332 if(options.throw_errors->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100333 {
334 throw;
335 }
336
337 return 1;
338 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100339 return 0;
340}