Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 | */ |
| 24 | #include "utils/Utils.h" |
| 25 | //FIXME / INTERNAL_ONLY: This file should not be released! |
| 26 | |
| 27 | #define BENCHMARK_EXAMPLES |
| 28 | #include "utils/Utils.cpp" |
| 29 | |
| 30 | #include "arm_compute/runtime/Scheduler.h" |
| 31 | #include "tests/framework/Framework.h" |
| 32 | #include "tests/framework/Macros.h" |
| 33 | #include "tests/framework/command_line/CommandLineParser.h" |
| 34 | #include "tests/framework/command_line/CommonOptions.h" |
| 35 | #include "tests/framework/instruments/Instruments.h" |
| 36 | |
| 37 | #ifdef ARM_COMPUTE_CL |
| 38 | #include "arm_compute/runtime/CL/CLScheduler.h" |
| 39 | #endif /* ARM_COMPUTE_CL */ |
| 40 | #ifdef ARM_COMPUTE_GC |
| 41 | #include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h" |
| 42 | #endif /* ARM_COMPUTE_GC */ |
| 43 | |
Anthony Barbier | fadfc6d | 2018-02-28 14:02:42 +0000 | [diff] [blame] | 44 | #include <libgen.h> |
| 45 | |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 46 | using namespace arm_compute; |
| 47 | using namespace arm_compute::test; |
| 48 | |
| 49 | namespace arm_compute |
| 50 | { |
| 51 | namespace utils |
| 52 | { |
| 53 | static Example *g_example = nullptr; |
| 54 | class ExampleTest : public arm_compute::test::framework::TestCase |
| 55 | { |
| 56 | public: |
| 57 | ExampleTest() = default; |
| 58 | void do_run() override |
| 59 | { |
| 60 | g_example->do_run(); |
| 61 | } |
| 62 | void do_teardown() override |
| 63 | { |
| 64 | g_example->do_teardown(); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | int run_example(int argc, char **argv, Example &example) |
| 69 | { |
| 70 | framework::CommandLineParser parser; |
| 71 | framework::CommonOptions options(parser); |
| 72 | auto example_args = parser.add_option<framework::ListOption<std::string>>("example_args"); |
| 73 | example_args->set_help("Arguments to pass to the example"); |
| 74 | framework::Framework &framework = framework::Framework::get(); |
| 75 | |
| 76 | parser.parse(argc, argv); |
| 77 | |
| 78 | if(options.help->is_set() && options.help->value()) |
| 79 | { |
| 80 | parser.print_help(argv[0]); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers(); |
| 85 | g_example = &example; |
| 86 | std::vector<char *> example_argv = {}; |
| 87 | example_argv.clear(); |
| 88 | example_argv.emplace_back(argv[0]); |
| 89 | for(auto &arg : example_args->value()) |
| 90 | { |
| 91 | example_argv.emplace_back(const_cast<char *>(arg.c_str())); // NOLINT |
| 92 | } |
Georgios Pinitas | 3364c4c | 2018-02-07 14:00:05 +0000 | [diff] [blame] | 93 | |
| 94 | // Set number of threads in Scheduler |
| 95 | Scheduler::get().set_num_threads(options.threads->value()); |
| 96 | |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 97 | // We need to do the setup here because framework.init() will need CL / GLES to be initialised |
| 98 | try |
| 99 | { |
| 100 | example.do_setup(example_argv.size(), &example_argv[0]); |
| 101 | } |
| 102 | #ifdef ARM_COMPUTE_CL |
| 103 | catch(cl::Error &err) |
| 104 | { |
| 105 | std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; |
| 106 | std::cerr << std::endl |
| 107 | << "ERROR " << err.what() << "(" << err.err() << ")" << std::endl; |
| 108 | std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; |
| 109 | return 1; |
| 110 | } |
| 111 | #endif /* ARM_COMPUTE_CL */ |
| 112 | catch(std::runtime_error &err) |
| 113 | { |
| 114 | std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; |
| 115 | std::cerr << std::endl |
| 116 | << "ERROR " << err.what() << " " << (errno ? strerror(errno) : "") << std::endl; |
| 117 | std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; |
| 118 | return 1; |
| 119 | } |
| 120 | |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 121 | if(options.log_level->value() > framework::LogLevel::NONE) |
| 122 | { |
| 123 | for(auto &p : printers) |
| 124 | { |
| 125 | p->print_global_header(); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | if(options.log_level->value() >= framework::LogLevel::CONFIG) |
| 130 | { |
| 131 | for(auto &p : printers) |
| 132 | { |
Anthony Barbier | 847864d | 2018-03-07 11:35:53 +0000 | [diff] [blame^] | 133 | #ifdef ARM_COMPUTE_CL |
| 134 | if(opencl_is_available()) |
| 135 | { |
| 136 | p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version()); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | p->print_entry("CL_DEVICE_VERSION", "Unavailable"); |
| 141 | } |
| 142 | #endif /* ARM_COMPUTE_CL */ |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 143 | p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value())); |
| 144 | p->print_entry("Threads", support::cpp11::to_string(options.threads->value())); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | framework.init(options.instruments->value(), options.iterations->value(), framework::DatasetMode::ALL, "", "", options.log_level->value()); |
| 149 | for(auto &p : printers) |
| 150 | { |
| 151 | framework.add_printer(p.get()); |
| 152 | } |
| 153 | framework.set_throw_errors(options.throw_errors->value()); |
| 154 | arm_compute::test::framework::detail::TestSuiteRegistrar suite{ "Examples" }; |
Anthony Barbier | fadfc6d | 2018-02-28 14:02:42 +0000 | [diff] [blame] | 155 | framework.add_test_case<ExampleTest>(basename(argv[0]), framework::DatasetMode::ALL, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE); |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 156 | |
| 157 | //func(argc, argv); |
| 158 | bool success = framework.run(); |
| 159 | if(options.log_level->value() > framework::LogLevel::NONE) |
| 160 | { |
| 161 | for(auto &p : printers) |
| 162 | { |
| 163 | p->print_global_footer(); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return (success ? 0 : 1); |
| 168 | } |
| 169 | |
| 170 | } // namespace utils |
| 171 | } // namespace arm_compute |