blob: 1e332cb45701912127112b66ef8faf359ce75c9a [file] [log] [blame]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01001/*
Michalis Spyrou84f3ae82018-01-15 11:15:26 +00002 * Copyright (c) 2017-2018 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
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010038#include "arm_compute/runtime/CL/CLScheduler.h"
Anthony Barbier943a40b2018-07-12 18:03:54 +010039#include "arm_compute/runtime/CL/CLTuner.h"
Anthony Barbier15d5ac82017-07-17 15:22:17 +010040#endif /* ARM_COMPUTE_CL */
Anthony Barbier7068f992017-10-26 15:23:08 +010041#ifdef ARM_COMPUTE_GC
42#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
43#endif /* ARM_COMPUTE_GC */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010044#include "arm_compute/runtime/Scheduler.h"
45
46#include <fstream>
47#include <initializer_list>
48#include <iostream>
49#include <memory>
50#include <random>
51#include <utility>
52
53using namespace arm_compute;
54using namespace arm_compute::test;
55
Anthony Barbier1fa17c22018-08-23 15:44:20 +010056namespace
57{
58std::string command_line(int argc, char **argv)
59{
60 std::stringstream ss;
61 for(int i = 0; i < argc; i++)
62 {
63 ss << argv[i] << " ";
64 }
65 return ss.str();
66}
67} // namespace
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010068namespace arm_compute
69{
70namespace test
71{
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010072std::unique_ptr<AssetsLibrary> library;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010073} // namespace test
74} // namespace arm_compute
75
Anthony Barbier7b607dc2018-07-13 15:55:24 +010076namespace
77{
78#ifdef ARM_COMPUTE_CL
79bool file_exists(const std::string &filename)
80{
81 std::ifstream file(filename);
82 return file.good();
83}
84#endif /* ARM_COMPUTE_CL */
85} //namespace
86
Vidhya Sudhan Loganathan709d27b2018-10-10 11:46:55 +010087void print_cpu_info(std::ostream &os)
88{
89 const arm_compute::CPUInfo &cpu_info = Scheduler::get().cpu_info();
90 const unsigned int num_cpus = cpu_info.get_cpu_num();
91 os << "\ncpu_has_fp16 : " << cpu_info.has_fp16() << "\ncpu_has_dotprod : " << cpu_info.has_dotprod() << std::endl;
92 for(unsigned int j = 0; j < num_cpus; ++j)
93 {
94 const CPUModel model = cpu_info.get_cpu_model(j);
95 os << "CPU" << j << " : " << cpu_model_to_string(model) << std::endl;
96 }
97}
98
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010099int main(int argc, char **argv)
100{
Anthony Barbier15d5ac82017-07-17 15:22:17 +0100101#ifdef ARM_COMPUTE_CL
Anthony Barbier943a40b2018-07-12 18:03:54 +0100102 CLTuner cl_tuner(false);
Anthony Barbier890ad1b2018-08-22 13:44:36 +0100103 if(opencl_is_available())
104 {
105 CLScheduler::get().default_init(&cl_tuner);
106 }
Anthony Barbier15d5ac82017-07-17 15:22:17 +0100107#endif /* ARM_COMPUTE_CL */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100108
Anthony Barbier7068f992017-10-26 15:23:08 +0100109#ifdef ARM_COMPUTE_GC
110 GCScheduler::get().default_init();
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000111#endif /* ARM_COMPUTE_GC */
Anthony Barbier7068f992017-10-26 15:23:08 +0100112
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100113 framework::Framework &framework = framework::Framework::get();
114
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100115 utils::CommandLineParser parser;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100116
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +0100117 std::set<framework::DatasetMode> allowed_modes
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100118 {
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +0100119 framework::DatasetMode::PRECOMMIT,
120 framework::DatasetMode::NIGHTLY,
121 framework::DatasetMode::ALL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100122 };
123
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000124 framework::CommonOptions options(parser);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100125
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100126 auto dataset_mode = parser.add_option<utils::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100127 dataset_mode->set_help("For managed datasets select which group to use");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100128 auto filter = parser.add_option<utils::SimpleOption<std::string>>("filter", ".*");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100129 filter->set_help("Regular expression to select test cases");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100130 auto filter_id = parser.add_option<utils::SimpleOption<std::string>>("filter-id");
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100131 filter_id->set_help("List of test ids. ... can be used to define a range.");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100132 auto stop_on_error = parser.add_option<utils::ToggleOption>("stop-on-error");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100133 stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100134 auto seed = parser.add_option<utils::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100135 seed->set_help("Global seed for random number generation");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100136 auto list_tests = parser.add_option<utils::ToggleOption>("list-tests", false);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100137 list_tests->set_help("List all test names");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100138 auto test_instruments = parser.add_option<utils::ToggleOption>("test-instruments", false);
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100139 test_instruments->set_help("Test if the instruments work on the platform");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100140 auto error_on_missing_assets = parser.add_option<utils::ToggleOption>("error-on-missing-assets", false);
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100141 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 +0100142 auto assets = parser.add_positional_option<utils::SimpleOption<std::string>>("assets");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100143 assets->set_help("Path to the assets directory");
Anthony Barbier943a40b2018-07-12 18:03:54 +0100144#ifdef ARM_COMPUTE_CL
145 auto enable_tuner = parser.add_option<utils::ToggleOption>("enable-tuner");
146 enable_tuner->set_help("Enable OpenCL dynamic tuner");
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100147 auto tuner_file = parser.add_option<utils::SimpleOption<std::string>>("tuner-file", "");
148 tuner_file->set_help("File to load/save CLTuner values");
Anthony Barbier943a40b2018-07-12 18:03:54 +0100149#endif /* ARM_COMPUTE_CL */
Anthony Barbier94522332018-07-13 09:26:51 +0100150 auto threads = parser.add_option<utils::SimpleOption<int>>("threads", 1);
151 threads->set_help("Number of threads to use");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100152
153 try
154 {
155 parser.parse(argc, argv);
156
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000157 if(options.help->is_set() && options.help->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100158 {
159 parser.print_help(argv[0]);
160 return 0;
161 }
162
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000163 std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100164
Anthony Barbier94522332018-07-13 09:26:51 +0100165 Scheduler::get().set_num_threads(threads->value());
Anthony Barbier943a40b2018-07-12 18:03:54 +0100166#ifdef ARM_COMPUTE_CL
167 if(enable_tuner->is_set())
168 {
169 cl_tuner.set_tune_new_kernels(enable_tuner->value());
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100170 // If that's the first run then the file won't exist yet
171 if(file_exists(tuner_file->value()))
172 {
173 cl_tuner.load_from_file(tuner_file->value());
174 }
175 }
176 else if(!tuner_file->value().empty())
177 {
178 //If we're not tuning and the file doesn't exist then we should raise an error:
179 cl_tuner.load_from_file(tuner_file->value());
Anthony Barbier943a40b2018-07-12 18:03:54 +0100180 }
181#endif /* ARM_COMPUTE_CL */
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000182 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100183 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000184 for(auto &p : printers)
185 {
186 p->print_global_header();
187 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100188 }
189
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000190 if(options.log_level->value() >= framework::LogLevel::CONFIG)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100191 {
Vidhya Sudhan Loganathan709d27b2018-10-10 11:46:55 +0100192 std::stringstream ss;
Giorgio Arenac5d54392017-10-31 15:18:49 +0000193 for(auto &p : printers)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100194 {
Anthony Barbier4b9c58a2018-01-10 14:34:00 +0000195 p->print_entry("Version", build_information());
Anthony Barbier1fa17c22018-08-23 15:44:20 +0100196 p->print_entry("CommandLine", command_line(argc, argv));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000197 p->print_entry("Seed", support::cpp11::to_string(seed->value()));
Anthony Barbier847864d2018-03-07 11:35:53 +0000198#ifdef ARM_COMPUTE_CL
199 if(opencl_is_available())
200 {
201 p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version());
202 }
203 else
204 {
205 p->print_entry("CL_DEVICE_VERSION", "Unavailable");
206 }
207#endif /* ARM_COMPUTE_CL */
Vidhya Sudhan Loganathan709d27b2018-10-10 11:46:55 +0100208 print_cpu_info(ss);
209 p->print_entry("CPU_INFO", ss.str());
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000210 p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
Anthony Barbier94522332018-07-13 09:26:51 +0100211 p->print_entry("Threads", support::cpp11::to_string(threads->value()));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000212 {
213 using support::cpp11::to_string;
214 p->print_entry("Dataset mode", to_string(dataset_mode->value()));
215 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100216 }
217 }
218
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000219 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 +0000220 for(auto &p : printers)
221 {
222 framework.add_printer(p.get());
223 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000224 framework.set_throw_errors(options.throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100225 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100226 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100227
228 bool success = true;
229
230 if(list_tests->value())
231 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000232 for(auto &p : printers)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100233 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000234 p->print_list_tests(framework.test_infos());
235 p->print_global_footer();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100236 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100237
238 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100239 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100240
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100241 if(test_instruments->value())
242 {
243 framework::Profiler profiler = framework.get_profiler();
244 profiler.start();
245 profiler.stop();
Giorgio Arenac5d54392017-10-31 15:18:49 +0000246 for(auto &p : printers)
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100247 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000248 p->print_measurements(profiler.measurements());
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100249 }
Giorgio Arenac5d54392017-10-31 15:18:49 +0000250
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100251 return 0;
252 }
253
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100254 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100255
256 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100257 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100258 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100259 }
260
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100261 success = framework.run();
262
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000263 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100264 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000265 for(auto &p : printers)
266 {
267 p->print_global_footer();
268 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100269 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100270
Michalis Spyrou84f3ae82018-01-15 11:15:26 +0000271#ifdef ARM_COMPUTE_CL
Anthony Barbier2113b9d2018-08-23 09:48:40 +0100272 if(opencl_is_available())
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100273 {
Anthony Barbier2113b9d2018-08-23 09:48:40 +0100274 CLScheduler::get().sync();
275 if(enable_tuner->is_set() && enable_tuner->value() && tuner_file->is_set())
276 {
277 cl_tuner.save_to_file(tuner_file->value());
278 }
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100279 }
Michalis Spyrou84f3ae82018-01-15 11:15:26 +0000280#endif /* ARM_COMPUTE_CL */
281
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100282 return (success ? 0 : 1);
283 }
284 catch(const std::exception &error)
285 {
286 std::cerr << error.what() << "\n";
287
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000288 if(options.throw_errors->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100289 {
290 throw;
291 }
292
293 return 1;
294 }
295
296 return 0;
297}