blob: 7ec6217d193ba47e266e57643d2659e239844cb6 [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
44using namespace arm_compute;
45using namespace arm_compute::test;
46
47namespace arm_compute
48{
49namespace utils
50{
51static Example *g_example = nullptr;
52class ExampleTest : public arm_compute::test::framework::TestCase
53{
54public:
55 ExampleTest() = default;
56 void do_run() override
57 {
58 g_example->do_run();
59 }
60 void do_teardown() override
61 {
62 g_example->do_teardown();
63 }
64};
65
66int run_example(int argc, char **argv, Example &example)
67{
68 framework::CommandLineParser parser;
69 framework::CommonOptions options(parser);
70 auto example_args = parser.add_option<framework::ListOption<std::string>>("example_args");
71 example_args->set_help("Arguments to pass to the example");
72 framework::Framework &framework = framework::Framework::get();
73
74 parser.parse(argc, argv);
75
76 if(options.help->is_set() && options.help->value())
77 {
78 parser.print_help(argv[0]);
79 return 0;
80 }
81
82 std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers();
83 g_example = &example;
84 std::vector<char *> example_argv = {};
85 example_argv.clear();
86 example_argv.emplace_back(argv[0]);
87 for(auto &arg : example_args->value())
88 {
89 example_argv.emplace_back(const_cast<char *>(arg.c_str())); // NOLINT
90 }
Georgios Pinitas3364c4c2018-02-07 14:00:05 +000091
92 // Set number of threads in Scheduler
93 Scheduler::get().set_num_threads(options.threads->value());
94
Anthony Barbier6db0ff52018-01-05 10:59:12 +000095 // We need to do the setup here because framework.init() will need CL / GLES to be initialised
96 try
97 {
98 example.do_setup(example_argv.size(), &example_argv[0]);
99 }
100#ifdef ARM_COMPUTE_CL
101 catch(cl::Error &err)
102 {
103 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
104 std::cerr << std::endl
105 << "ERROR " << err.what() << "(" << err.err() << ")" << std::endl;
106 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
107 return 1;
108 }
109#endif /* ARM_COMPUTE_CL */
110 catch(std::runtime_error &err)
111 {
112 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
113 std::cerr << std::endl
114 << "ERROR " << err.what() << " " << (errno ? strerror(errno) : "") << std::endl;
115 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
116 return 1;
117 }
118
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000119 if(options.log_level->value() > framework::LogLevel::NONE)
120 {
121 for(auto &p : printers)
122 {
123 p->print_global_header();
124 }
125 }
126
127 if(options.log_level->value() >= framework::LogLevel::CONFIG)
128 {
129 for(auto &p : printers)
130 {
131 p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
132 p->print_entry("Threads", support::cpp11::to_string(options.threads->value()));
133 }
134 }
135
136 framework.init(options.instruments->value(), options.iterations->value(), framework::DatasetMode::ALL, "", "", options.log_level->value());
137 for(auto &p : printers)
138 {
139 framework.add_printer(p.get());
140 }
141 framework.set_throw_errors(options.throw_errors->value());
142 arm_compute::test::framework::detail::TestSuiteRegistrar suite{ "Examples" };
143 framework.add_test_case<ExampleTest>(argv[0], framework::DatasetMode::ALL, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE);
144
145 //func(argc, argv);
146 bool success = framework.run();
147 if(options.log_level->value() > framework::LogLevel::NONE)
148 {
149 for(auto &p : printers)
150 {
151 p->print_global_footer();
152 }
153 }
154
155 return (success ? 0 : 1);
156}
157
158} // namespace utils
159} // namespace arm_compute