Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 3 | * |
| 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 Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 24 | #include "framework/DatasetModes.h" |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 25 | #include "framework/Macros.h" |
| 26 | #include "framework/command_line/CommandLineOptions.h" |
| 27 | #include "framework/command_line/CommandLineParser.h" |
| 28 | #include "framework/instruments/Instruments.h" |
| 29 | #include "framework/printers/Printers.h" |
| 30 | #include "support/ToolchainSupport.h" |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 31 | #include "tests/AssetsLibrary.h" |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 32 | |
Anthony Barbier | 15d5ac8 | 2017-07-17 15:22:17 +0100 | [diff] [blame] | 33 | #ifdef ARM_COMPUTE_CL |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 34 | #include "arm_compute/runtime/CL/CLScheduler.h" |
Anthony Barbier | 15d5ac8 | 2017-07-17 15:22:17 +0100 | [diff] [blame] | 35 | #endif /* ARM_COMPUTE_CL */ |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 36 | #include "arm_compute/runtime/Scheduler.h" |
| 37 | |
| 38 | #include <fstream> |
| 39 | #include <initializer_list> |
| 40 | #include <iostream> |
| 41 | #include <memory> |
| 42 | #include <random> |
| 43 | #include <utility> |
| 44 | |
| 45 | using namespace arm_compute; |
| 46 | using namespace arm_compute::test; |
| 47 | |
| 48 | namespace arm_compute |
| 49 | { |
| 50 | namespace test |
| 51 | { |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 52 | std::unique_ptr<AssetsLibrary> library; |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 53 | } // namespace test |
| 54 | } // namespace arm_compute |
| 55 | |
| 56 | int main(int argc, char **argv) |
| 57 | { |
Anthony Barbier | 15d5ac8 | 2017-07-17 15:22:17 +0100 | [diff] [blame] | 58 | #ifdef ARM_COMPUTE_CL |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 59 | CLScheduler::get().default_init(); |
Anthony Barbier | 15d5ac8 | 2017-07-17 15:22:17 +0100 | [diff] [blame] | 60 | #endif /* ARM_COMPUTE_CL */ |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 61 | |
| 62 | framework::Framework &framework = framework::Framework::get(); |
| 63 | |
| 64 | framework::CommandLineParser parser; |
| 65 | |
| 66 | std::set<framework::InstrumentType> allowed_instruments |
| 67 | { |
| 68 | framework::InstrumentType::ALL, |
| 69 | framework::InstrumentType::NONE, |
| 70 | }; |
| 71 | |
| 72 | for(const auto &type : framework.available_instruments()) |
| 73 | { |
| 74 | allowed_instruments.insert(type); |
| 75 | } |
| 76 | |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 77 | std::set<framework::DatasetMode> allowed_modes |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 78 | { |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 79 | framework::DatasetMode::PRECOMMIT, |
| 80 | framework::DatasetMode::NIGHTLY, |
| 81 | framework::DatasetMode::ALL |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | std::set<framework::LogFormat> supported_log_formats |
| 85 | { |
| 86 | framework::LogFormat::NONE, |
| 87 | framework::LogFormat::PRETTY, |
| 88 | framework::LogFormat::JSON, |
| 89 | }; |
| 90 | |
| 91 | auto help = parser.add_option<framework::ToggleOption>("help"); |
| 92 | help->set_help("Show this help message"); |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 93 | auto dataset_mode = parser.add_option<framework::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::ALL); |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 94 | dataset_mode->set_help("For managed datasets select which group to use"); |
| 95 | auto instruments = parser.add_option<framework::EnumListOption<framework::InstrumentType>>("instruments", allowed_instruments, std::initializer_list<framework::InstrumentType> { framework::InstrumentType::ALL }); |
| 96 | instruments->set_help("Set the profiling instruments to use"); |
| 97 | auto iterations = parser.add_option<framework::SimpleOption<int>>("iterations", 1); |
| 98 | iterations->set_help("Number of iterations per test case"); |
| 99 | auto threads = parser.add_option<framework::SimpleOption<int>>("threads", 1); |
| 100 | threads->set_help("Number of threads to use"); |
| 101 | auto log_format = parser.add_option<framework::EnumOption<framework::LogFormat>>("log-format", supported_log_formats, framework::LogFormat::PRETTY); |
| 102 | log_format->set_help("Output format for measurements and failures"); |
| 103 | auto filter = parser.add_option<framework::SimpleOption<std::string>>("filter", ".*"); |
| 104 | filter->set_help("Regular expression to select test cases"); |
Moritz Pflanzer | 81527bf | 2017-07-20 15:11:33 +0100 | [diff] [blame] | 105 | auto filter_id = parser.add_option<framework::SimpleOption<int64_t>>("filter-id", -1); |
| 106 | filter_id->set_help("Test id. Only this test will be executed."); |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 107 | auto log_file = parser.add_option<framework::SimpleOption<std::string>>("log-file"); |
| 108 | log_file->set_help("Write output to file instead of to the console"); |
| 109 | auto throw_errors = parser.add_option<framework::ToggleOption>("throw-errors"); |
| 110 | throw_errors->set_help("Don't catch errors (useful for debugging)"); |
| 111 | auto seed = parser.add_option<framework::SimpleOption<std::random_device::result_type>>("seed", std::random_device()()); |
| 112 | seed->set_help("Global seed for random number generation"); |
| 113 | auto color_output = parser.add_option<framework::ToggleOption>("color-output", true); |
| 114 | color_output->set_help("Produce colored output on the console"); |
| 115 | auto list_tests = parser.add_option<framework::ToggleOption>("list-tests", false); |
| 116 | list_tests->set_help("List all test names"); |
| 117 | auto assets = parser.add_positional_option<framework::SimpleOption<std::string>>("assets"); |
| 118 | assets->set_help("Path to the assets directory"); |
| 119 | assets->set_required(true); |
| 120 | |
| 121 | try |
| 122 | { |
| 123 | parser.parse(argc, argv); |
| 124 | |
| 125 | if(help->is_set() && help->value()) |
| 126 | { |
| 127 | parser.print_help(argv[0]); |
| 128 | return 0; |
| 129 | } |
| 130 | |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 131 | std::unique_ptr<framework::Printer> printer; |
| 132 | std::ofstream log_stream; |
| 133 | |
| 134 | switch(log_format->value()) |
| 135 | { |
| 136 | case framework::LogFormat::JSON: |
| 137 | printer = support::cpp14::make_unique<framework::JSONPrinter>(); |
| 138 | break; |
| 139 | case framework::LogFormat::NONE: |
| 140 | break; |
| 141 | case framework::LogFormat::PRETTY: |
| 142 | default: |
| 143 | { |
| 144 | auto pretty_printer = support::cpp14::make_unique<framework::PrettyPrinter>(); |
| 145 | pretty_printer->set_color_output(color_output->value()); |
| 146 | printer = std::move(pretty_printer); |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if(printer != nullptr) |
| 152 | { |
| 153 | if(log_file->is_set()) |
| 154 | { |
| 155 | log_stream.open(log_file->value()); |
| 156 | printer->set_stream(log_stream); |
| 157 | } |
| 158 | } |
| 159 | |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 160 | Scheduler::get().set_num_threads(threads->value()); |
| 161 | |
| 162 | printer->print_global_header(); |
| 163 | printer->print_entry("Seed", support::cpp11::to_string(seed->value())); |
| 164 | printer->print_entry("Iterations", support::cpp11::to_string(iterations->value())); |
| 165 | printer->print_entry("Threads", support::cpp11::to_string(threads->value())); |
| 166 | { |
| 167 | using support::cpp11::to_string; |
| 168 | printer->print_entry("Dataset mode", to_string(dataset_mode->value())); |
| 169 | } |
| 170 | |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 171 | framework.init(instruments->value(), iterations->value(), dataset_mode->value(), filter->value(), filter_id->value()); |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 172 | framework.set_printer(printer.get()); |
| 173 | framework.set_throw_errors(throw_errors->value()); |
| 174 | |
| 175 | bool success = true; |
| 176 | |
| 177 | if(list_tests->value()) |
| 178 | { |
Moritz Pflanzer | bf234e0 | 2017-07-24 15:04:14 +0100 | [diff] [blame^] | 179 | for(const auto &info : framework.test_infos()) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 180 | { |
Moritz Pflanzer | bf234e0 | 2017-07-24 15:04:14 +0100 | [diff] [blame^] | 181 | std::cout << "[" << info.id << ", " << info.mode << ", " << info.status << "] " << info.name << "\n"; |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 182 | } |
Moritz Pflanzer | aab4354 | 2017-07-18 13:15:39 +0100 | [diff] [blame] | 183 | |
| 184 | return 0; |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 185 | } |
Moritz Pflanzer | aab4354 | 2017-07-18 13:15:39 +0100 | [diff] [blame] | 186 | |
Moritz Pflanzer | fb5aabb | 2017-07-18 14:39:55 +0100 | [diff] [blame] | 187 | library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value()); |
Moritz Pflanzer | aab4354 | 2017-07-18 13:15:39 +0100 | [diff] [blame] | 188 | |
| 189 | if(!parser.validate()) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 190 | { |
Moritz Pflanzer | aab4354 | 2017-07-18 13:15:39 +0100 | [diff] [blame] | 191 | return 1; |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Moritz Pflanzer | aab4354 | 2017-07-18 13:15:39 +0100 | [diff] [blame] | 194 | success = framework.run(); |
| 195 | |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 196 | printer->print_global_footer(); |
| 197 | |
| 198 | return (success ? 0 : 1); |
| 199 | } |
| 200 | catch(const std::exception &error) |
| 201 | { |
| 202 | std::cerr << error.what() << "\n"; |
| 203 | |
| 204 | if(throw_errors->value()) |
| 205 | { |
| 206 | throw; |
| 207 | } |
| 208 | |
| 209 | return 1; |
| 210 | } |
| 211 | |
| 212 | return 0; |
| 213 | } |