blob: f6a9742048390737cb5f9cd132906ba7dfb55caf [file] [log] [blame]
Anthony Barbier6db0ff52018-01-05 10:59:12 +00001/*
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 Barbierfadfc6d2018-02-28 14:02:42 +000044#include <libgen.h>
45
Anthony Barbier6db0ff52018-01-05 10:59:12 +000046using namespace arm_compute;
47using namespace arm_compute::test;
48
49namespace arm_compute
50{
51namespace utils
52{
Anthony Barbier9fb0cac2018-04-20 15:46:21 +010053static std::unique_ptr<Example> g_example = nullptr;
54static std::vector<char *> g_example_argv = {};
Anthony Barbier6db0ff52018-01-05 10:59:12 +000055class ExampleTest : public arm_compute::test::framework::TestCase
56{
57public:
58 ExampleTest() = default;
Anthony Barbier9fb0cac2018-04-20 15:46:21 +010059 void do_setup() override
60 {
61 ARM_COMPUTE_ERROR_ON_NULLPTR(g_example.get());
62 g_example->do_setup(g_example_argv.size(), &g_example_argv[0]);
63 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +000064 void do_run() override
65 {
66 g_example->do_run();
67 }
68 void do_teardown() override
69 {
70 g_example->do_teardown();
Anthony Barbier9fb0cac2018-04-20 15:46:21 +010071 g_example = nullptr;
Anthony Barbier6db0ff52018-01-05 10:59:12 +000072 }
73};
74
Anthony Barbier9fb0cac2018-04-20 15:46:21 +010075int run_example(int argc, char **argv, std::unique_ptr<Example> example)
Anthony Barbier6db0ff52018-01-05 10:59:12 +000076{
77 framework::CommandLineParser parser;
78 framework::CommonOptions options(parser);
79 auto example_args = parser.add_option<framework::ListOption<std::string>>("example_args");
Anthony Barbier979dc4f2018-03-07 09:27:48 +000080 example_args->set_help("Arguments to pass to the example separated by commas (e.g: arg0,arg1,arg2)");
Anthony Barbier6db0ff52018-01-05 10:59:12 +000081 framework::Framework &framework = framework::Framework::get();
82
83 parser.parse(argc, argv);
84
85 if(options.help->is_set() && options.help->value())
86 {
87 parser.print_help(argv[0]);
88 return 0;
89 }
90
91 std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers();
Anthony Barbier9fb0cac2018-04-20 15:46:21 +010092 g_example = std::move(example);
93 g_example_argv.clear();
94 g_example_argv.emplace_back(argv[0]);
Anthony Barbier6db0ff52018-01-05 10:59:12 +000095 for(auto &arg : example_args->value())
96 {
Anthony Barbier9fb0cac2018-04-20 15:46:21 +010097 g_example_argv.emplace_back(const_cast<char *>(arg.c_str())); // NOLINT
Anthony Barbier6db0ff52018-01-05 10:59:12 +000098 }
Georgios Pinitas3364c4c2018-02-07 14:00:05 +000099
100 // Set number of threads in Scheduler
101 Scheduler::get().set_num_threads(options.threads->value());
102
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000103 if(options.log_level->value() > framework::LogLevel::NONE)
104 {
105 for(auto &p : printers)
106 {
107 p->print_global_header();
108 }
109 }
110
111 if(options.log_level->value() >= framework::LogLevel::CONFIG)
112 {
113 for(auto &p : printers)
114 {
Anthony Barbier9280c922018-03-14 14:23:47 +0000115 p->print_entry("Version", build_information());
Anthony Barbier847864d2018-03-07 11:35:53 +0000116#ifdef ARM_COMPUTE_CL
117 if(opencl_is_available())
118 {
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100119 if(!CLScheduler::get().is_initialised())
120 {
121 CLScheduler::get().default_init();
122 }
Anthony Barbier847864d2018-03-07 11:35:53 +0000123 p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version());
124 }
125 else
126 {
127 p->print_entry("CL_DEVICE_VERSION", "Unavailable");
128 }
129#endif /* ARM_COMPUTE_CL */
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000130 p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
131 p->print_entry("Threads", support::cpp11::to_string(options.threads->value()));
132 }
133 }
134
135 framework.init(options.instruments->value(), options.iterations->value(), framework::DatasetMode::ALL, "", "", options.log_level->value());
136 for(auto &p : printers)
137 {
138 framework.add_printer(p.get());
139 }
140 framework.set_throw_errors(options.throw_errors->value());
141 arm_compute::test::framework::detail::TestSuiteRegistrar suite{ "Examples" };
Anthony Barbierfadfc6d2018-02-28 14:02:42 +0000142 framework.add_test_case<ExampleTest>(basename(argv[0]), framework::DatasetMode::ALL, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE);
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000143
144 //func(argc, argv);
145 bool success = framework.run();
146 if(options.log_level->value() > framework::LogLevel::NONE)
147 {
148 for(auto &p : printers)
149 {
150 p->print_global_footer();
151 }
152 }
153
154 return (success ? 0 : 1);
155}
156
157} // namespace utils
158} // namespace arm_compute