blob: 9690eb9a00093411e607e503a866f4631eb24f0e [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"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010026#include "tests/framework/DatasetModes.h"
27#include "tests/framework/Exceptions.h"
28#include "tests/framework/Framework.h"
29#include "tests/framework/Macros.h"
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +010030#include "tests/framework/Profiler.h"
Anthony Barbier6db0ff52018-01-05 10:59:12 +000031#include "tests/framework/command_line/CommonOptions.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010032#include "tests/framework/instruments/Instruments.h"
33#include "tests/framework/printers/Printers.h"
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010034#include "utils/command_line/CommandLineOptions.h"
35#include "utils/command_line/CommandLineParser.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010036
Anthony Barbier15d5ac82017-07-17 15:22:17 +010037#ifdef ARM_COMPUTE_CL
Pablo Tellob7c308a2019-01-22 12:59:26 +000038#include "arm_compute/core/CL/OpenCL.h"
39#include "arm_compute/runtime/CL/CLHelpers.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010040#include "arm_compute/runtime/CL/CLScheduler.h"
Anthony Barbier943a40b2018-07-12 18:03:54 +010041#include "arm_compute/runtime/CL/CLTuner.h"
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010042#include "utils/TypePrinter.h"
Anthony Barbier15d5ac82017-07-17 15:22:17 +010043#endif /* ARM_COMPUTE_CL */
Anthony Barbier7068f992017-10-26 15:23:08 +010044#ifdef ARM_COMPUTE_GC
45#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
46#endif /* ARM_COMPUTE_GC */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010047#include "arm_compute/runtime/Scheduler.h"
48
49#include <fstream>
50#include <initializer_list>
51#include <iostream>
52#include <memory>
53#include <random>
54#include <utility>
55
56using namespace arm_compute;
57using namespace arm_compute::test;
58
Anthony Barbier1fa17c22018-08-23 15:44:20 +010059namespace
60{
61std::string command_line(int argc, char **argv)
62{
63 std::stringstream ss;
64 for(int i = 0; i < argc; i++)
65 {
66 ss << argv[i] << " ";
67 }
68 return ss.str();
69}
70} // namespace
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010071namespace arm_compute
72{
73namespace test
74{
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010075std::unique_ptr<AssetsLibrary> library;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010076} // namespace test
77} // namespace arm_compute
78
Anthony Barbier7b607dc2018-07-13 15:55:24 +010079namespace
80{
81#ifdef ARM_COMPUTE_CL
82bool file_exists(const std::string &filename)
83{
84 std::ifstream file(filename);
85 return file.good();
86}
87#endif /* ARM_COMPUTE_CL */
88} //namespace
89
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010090int main(int argc, char **argv)
91{
Anthony Barbier15d5ac82017-07-17 15:22:17 +010092#ifdef ARM_COMPUTE_CL
Anthony Barbier943a40b2018-07-12 18:03:54 +010093 CLTuner cl_tuner(false);
Anthony Barbier890ad1b2018-08-22 13:44:36 +010094 if(opencl_is_available())
95 {
Pablo Tellob7c308a2019-01-22 12:59:26 +000096 auto ctx_dev_err = create_opencl_context_and_device();
97 ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context");
98 CLScheduler::get()
99 .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 +0100100 }
Anthony Barbier15d5ac82017-07-17 15:22:17 +0100101#endif /* ARM_COMPUTE_CL */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100102
Anthony Barbier7068f992017-10-26 15:23:08 +0100103#ifdef ARM_COMPUTE_GC
104 GCScheduler::get().default_init();
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000105#endif /* ARM_COMPUTE_GC */
Anthony Barbier7068f992017-10-26 15:23:08 +0100106
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100107 framework::Framework &framework = framework::Framework::get();
108
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100109 utils::CommandLineParser parser;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100110
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +0100111 std::set<framework::DatasetMode> allowed_modes
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100112 {
Georgios Pinitas557d4ae2019-04-18 18:10:34 +0100113 framework::DatasetMode::DISABLED,
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +0100114 framework::DatasetMode::PRECOMMIT,
115 framework::DatasetMode::NIGHTLY,
116 framework::DatasetMode::ALL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100117 };
118
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000119 framework::CommonOptions options(parser);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100120
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100121 auto dataset_mode = parser.add_option<utils::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100122 dataset_mode->set_help("For managed datasets select which group to use");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100123 auto filter = parser.add_option<utils::SimpleOption<std::string>>("filter", ".*");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100124 filter->set_help("Regular expression to select test cases");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100125 auto filter_id = parser.add_option<utils::SimpleOption<std::string>>("filter-id");
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100126 filter_id->set_help("List of test ids. ... can be used to define a range.");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100127 auto stop_on_error = parser.add_option<utils::ToggleOption>("stop-on-error");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100128 stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100129 auto seed = parser.add_option<utils::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100130 seed->set_help("Global seed for random number generation");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100131 auto list_tests = parser.add_option<utils::ToggleOption>("list-tests", false);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100132 list_tests->set_help("List all test names");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100133 auto test_instruments = parser.add_option<utils::ToggleOption>("test-instruments", false);
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100134 test_instruments->set_help("Test if the instruments work on the platform");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100135 auto error_on_missing_assets = parser.add_option<utils::ToggleOption>("error-on-missing-assets", false);
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100136 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 +0100137 auto assets = parser.add_positional_option<utils::SimpleOption<std::string>>("assets");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100138 assets->set_help("Path to the assets directory");
Anthony Barbier943a40b2018-07-12 18:03:54 +0100139#ifdef ARM_COMPUTE_CL
140 auto enable_tuner = parser.add_option<utils::ToggleOption>("enable-tuner");
141 enable_tuner->set_help("Enable OpenCL dynamic tuner");
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +0100142
143 const std::set<CLTunerMode> supported_tuner_modes
144 {
145 CLTunerMode::EXHAUSTIVE,
146 CLTunerMode::NORMAL,
147 CLTunerMode::RAPID
148 };
Michalis Spyrou083a0692019-05-13 15:35:50 +0100149 auto tuner_mode = parser.add_option<utils::EnumOption<CLTunerMode>>("tuner-mode", supported_tuner_modes, CLTunerMode::NORMAL);
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +0100150 tuner_mode->set_help("Configures the time taken by the tuner to tune. Slow tuner produces the most performant LWS configuration");
151
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100152 auto tuner_file = parser.add_option<utils::SimpleOption<std::string>>("tuner-file", "");
153 tuner_file->set_help("File to load/save CLTuner values");
Anthony Barbier943a40b2018-07-12 18:03:54 +0100154#endif /* ARM_COMPUTE_CL */
Anthony Barbier94522332018-07-13 09:26:51 +0100155 auto threads = parser.add_option<utils::SimpleOption<int>>("threads", 1);
156 threads->set_help("Number of threads to use");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100157
158 try
159 {
160 parser.parse(argc, argv);
161
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000162 if(options.help->is_set() && options.help->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100163 {
164 parser.print_help(argv[0]);
165 return 0;
166 }
167
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000168 std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100169
Anthony Barbier94522332018-07-13 09:26:51 +0100170 Scheduler::get().set_num_threads(threads->value());
Anthony Barbier943a40b2018-07-12 18:03:54 +0100171#ifdef ARM_COMPUTE_CL
172 if(enable_tuner->is_set())
173 {
Pablo Tello5f98d742019-07-22 16:41:10 +0100174 cl_tuner.set_tune_new_kernels(enable_tuner->value());
175
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +0100176 //set tuner mode
177 cl_tuner.set_tuner_mode(tuner_mode->value());
178
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100179 // If that's the first run then the file won't exist yet
180 if(file_exists(tuner_file->value()))
181 {
182 cl_tuner.load_from_file(tuner_file->value());
183 }
184 }
185 else if(!tuner_file->value().empty())
186 {
187 //If we're not tuning and the file doesn't exist then we should raise an error:
188 cl_tuner.load_from_file(tuner_file->value());
Anthony Barbier943a40b2018-07-12 18:03:54 +0100189 }
190#endif /* ARM_COMPUTE_CL */
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000191 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100192 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000193 for(auto &p : printers)
194 {
195 p->print_global_header();
196 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100197 }
198
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000199 if(options.log_level->value() >= framework::LogLevel::CONFIG)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100200 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000201 for(auto &p : printers)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100202 {
Anthony Barbier4b9c58a2018-01-10 14:34:00 +0000203 p->print_entry("Version", build_information());
Anthony Barbier1fa17c22018-08-23 15:44:20 +0100204 p->print_entry("CommandLine", command_line(argc, argv));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000205 p->print_entry("Seed", support::cpp11::to_string(seed->value()));
Anthony Barbier847864d2018-03-07 11:35:53 +0000206#ifdef ARM_COMPUTE_CL
207 if(opencl_is_available())
208 {
209 p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version());
210 }
211 else
212 {
213 p->print_entry("CL_DEVICE_VERSION", "Unavailable");
214 }
215#endif /* ARM_COMPUTE_CL */
Gian Marco Iodice555c3d62018-10-16 16:00:50 +0100216 const arm_compute::CPUInfo &cpu_info = Scheduler::get().cpu_info();
217 const unsigned int num_cpus = cpu_info.get_cpu_num();
218 p->print_entry("cpu_has_fp16", support::cpp11::to_string(cpu_info.has_fp16()));
219 p->print_entry("cpu_has_dotprod", support::cpp11::to_string(cpu_info.has_dotprod()));
220
221 for(unsigned int j = 0; j < num_cpus; ++j)
222 {
223 const CPUModel model = cpu_info.get_cpu_model(j);
224 p->print_entry("CPU" + support::cpp11::to_string(j), cpu_model_to_string(model));
225 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000226 p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
Anthony Barbier94522332018-07-13 09:26:51 +0100227 p->print_entry("Threads", support::cpp11::to_string(threads->value()));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000228 {
229 using support::cpp11::to_string;
230 p->print_entry("Dataset mode", to_string(dataset_mode->value()));
231 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100232 }
233 }
234
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000235 framework.init(options.instruments->value(), options.iterations->value(), dataset_mode->value(), filter->value(), filter_id->value(), options.log_level->value());
Giorgio Arenac5d54392017-10-31 15:18:49 +0000236 for(auto &p : printers)
237 {
238 framework.add_printer(p.get());
239 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000240 framework.set_throw_errors(options.throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100241 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100242 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100243
244 bool success = true;
245
246 if(list_tests->value())
247 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000248 for(auto &p : printers)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100249 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000250 p->print_list_tests(framework.test_infos());
251 p->print_global_footer();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100252 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100253
254 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100255 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100256
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100257 if(test_instruments->value())
258 {
259 framework::Profiler profiler = framework.get_profiler();
260 profiler.start();
261 profiler.stop();
Giorgio Arenac5d54392017-10-31 15:18:49 +0000262 for(auto &p : printers)
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100263 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000264 p->print_measurements(profiler.measurements());
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100265 }
Giorgio Arenac5d54392017-10-31 15:18:49 +0000266
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100267 return 0;
268 }
269
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100270 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100271
272 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100273 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100274 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100275 }
276
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100277 success = framework.run();
278
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000279 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100280 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000281 for(auto &p : printers)
282 {
283 p->print_global_footer();
284 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100285 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100286
Michalis Spyrou84f3ae82018-01-15 11:15:26 +0000287#ifdef ARM_COMPUTE_CL
Anthony Barbier2113b9d2018-08-23 09:48:40 +0100288 if(opencl_is_available())
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100289 {
Anthony Barbier2113b9d2018-08-23 09:48:40 +0100290 CLScheduler::get().sync();
291 if(enable_tuner->is_set() && enable_tuner->value() && tuner_file->is_set())
292 {
293 cl_tuner.save_to_file(tuner_file->value());
294 }
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100295 }
Michalis Spyrou84f3ae82018-01-15 11:15:26 +0000296#endif /* ARM_COMPUTE_CL */
297
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100298 return (success ? 0 : 1);
299 }
300 catch(const std::exception &error)
301 {
302 std::cerr << error.what() << "\n";
303
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000304 if(options.throw_errors->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100305 {
306 throw;
307 }
308
309 return 1;
310 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100311 return 0;
312}