Compute Library
 23.08
Framework.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021, 2023 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 "Framework.h"
25 
29 
30 #ifdef ARM_COMPUTE_CL
33 
34 #endif /* ARM_COMPUTE_CL */
35 
36 #include <chrono>
37 #include <iostream>
38 #include <memory>
39 #include <sstream>
40 #include <type_traits>
41 
42 namespace arm_compute
43 {
44 namespace test
45 {
46 std::unique_ptr<ParametersLibrary> parameters;
47 
48 namespace framework
49 {
50 std::unique_ptr<InstrumentsInfo> instruments_info;
51 
52 Framework::Framework()
53  : _test_filter(nullptr)
54 {
55  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::WALL_CLOCK_TIMESTAMPS, ScaleFactor::NONE), Instrument::make_instrument<WallClockTimestamps, ScaleFactor::NONE>);
56  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::WALL_CLOCK_TIMESTAMPS, ScaleFactor::TIME_MS),
57  Instrument::make_instrument<WallClockTimestamps, ScaleFactor::TIME_MS>);
58  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::WALL_CLOCK_TIMESTAMPS, ScaleFactor::TIME_S),
59  Instrument::make_instrument<WallClockTimestamps, ScaleFactor::TIME_S>);
60  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::WALL_CLOCK_TIMER, ScaleFactor::NONE), Instrument::make_instrument<WallClockTimer, ScaleFactor::NONE>);
61  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::WALL_CLOCK_TIMER, ScaleFactor::TIME_MS), Instrument::make_instrument<WallClockTimer, ScaleFactor::TIME_MS>);
62  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::WALL_CLOCK_TIMER, ScaleFactor::TIME_S), Instrument::make_instrument<WallClockTimer, ScaleFactor::TIME_S>);
63  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::SCHEDULER_TIMESTAMPS, ScaleFactor::NONE), Instrument::make_instrument<SchedulerTimestamps, ScaleFactor::NONE>);
64  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::SCHEDULER_TIMESTAMPS, ScaleFactor::TIME_MS),
65  Instrument::make_instrument<SchedulerTimestamps, ScaleFactor::TIME_MS>);
66  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::SCHEDULER_TIMESTAMPS, ScaleFactor::TIME_S),
67  Instrument::make_instrument<SchedulerTimestamps, ScaleFactor::TIME_S>);
68  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::SCHEDULER_TIMER, ScaleFactor::NONE), Instrument::make_instrument<SchedulerTimer, ScaleFactor::NONE>);
69  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::SCHEDULER_TIMER, ScaleFactor::TIME_MS), Instrument::make_instrument<SchedulerTimer, ScaleFactor::TIME_MS>);
70  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::SCHEDULER_TIMER, ScaleFactor::TIME_S), Instrument::make_instrument<SchedulerTimer, ScaleFactor::TIME_S>);
71 #ifdef PMU_ENABLED
72  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::PMU, ScaleFactor::NONE), Instrument::make_instrument<PMUCounter, ScaleFactor::NONE>);
73  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::PMU, ScaleFactor::SCALE_1K), Instrument::make_instrument<PMUCounter, ScaleFactor::SCALE_1K>);
74  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::PMU, ScaleFactor::SCALE_1M), Instrument::make_instrument<PMUCounter, ScaleFactor::SCALE_1M>);
75 #endif /* PMU_ENABLED */
76 #ifdef MALI_ENABLED
77  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::MALI, ScaleFactor::NONE), Instrument::make_instrument<MaliCounter, ScaleFactor::NONE>);
78  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::MALI, ScaleFactor::SCALE_1K), Instrument::make_instrument<MaliCounter, ScaleFactor::SCALE_1K>);
79  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::MALI, ScaleFactor::SCALE_1M), Instrument::make_instrument<MaliCounter, ScaleFactor::SCALE_1M>);
80 #endif /* MALI_ENABLED */
81 #ifdef ARM_COMPUTE_CL
82  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_TIMESTAMPS, ScaleFactor::NONE), Instrument::make_instrument<OpenCLTimestamps, ScaleFactor::NONE>);
83  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_TIMESTAMPS, ScaleFactor::TIME_US), Instrument::make_instrument<OpenCLTimestamps, ScaleFactor::TIME_US>);
84  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_TIMESTAMPS, ScaleFactor::TIME_MS), Instrument::make_instrument<OpenCLTimestamps, ScaleFactor::TIME_MS>);
85  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_TIMESTAMPS, ScaleFactor::TIME_S), Instrument::make_instrument<OpenCLTimestamps, ScaleFactor::TIME_S>);
86  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_TIMER, ScaleFactor::NONE), Instrument::make_instrument<OpenCLTimer, ScaleFactor::NONE>);
87  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_TIMER, ScaleFactor::TIME_US), Instrument::make_instrument<OpenCLTimer, ScaleFactor::TIME_US>);
88  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_TIMER, ScaleFactor::TIME_MS), Instrument::make_instrument<OpenCLTimer, ScaleFactor::TIME_MS>);
89  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_TIMER, ScaleFactor::TIME_S), Instrument::make_instrument<OpenCLTimer, ScaleFactor::TIME_S>);
90  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_MEMORY_USAGE, ScaleFactor::NONE), Instrument::make_instrument<OpenCLMemoryUsage, ScaleFactor::NONE>);
91  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_MEMORY_USAGE, ScaleFactor::SCALE_1K),
92  Instrument::make_instrument<OpenCLMemoryUsage, ScaleFactor::SCALE_1K>);
93  _available_instruments.emplace(std::pair<InstrumentType, ScaleFactor>(InstrumentType::OPENCL_MEMORY_USAGE, ScaleFactor::SCALE_1M),
94  Instrument::make_instrument<OpenCLMemoryUsage, ScaleFactor::SCALE_1M>);
95 #endif /* ARM_COMPUTE_CL */
96 
97  instruments_info = std::make_unique<InstrumentsInfo>();
98 }
99 
100 std::set<InstrumentsDescription> Framework::available_instruments() const
101 {
102  std::set<InstrumentsDescription> types;
103 
104  for(const auto &instrument : _available_instruments)
105  {
106  types.emplace(instrument.first);
107  }
108 
109  return types;
110 }
111 
112 std::map<TestResult::Status, int> Framework::count_test_results() const
113 {
114  std::map<TestResult::Status, int> counts;
115 
116  for(const auto &test : _test_results)
117  {
118  ++counts[test.second.status];
119  }
120 
121  return counts;
122 }
123 
124 Framework &Framework::get()
125 {
126  static Framework instance;
127  return instance;
128 }
129 
130 void Framework::init(const FrameworkConfig &config)
131 {
132  _test_filter.reset(new TestFilter(config.mode, config.name_filter, config.id_filter));
133  _num_iterations = config.num_iterations;
134  _log_level = config.log_level;
135  _cooldown_sec = config.cooldown_sec;
136  _configure_only = config.configure_only;
137  _print_rerun_cmd = config.print_rerun_cmd;
138  _seed = config.seed;
139 
140  _instruments = std::set<framework::InstrumentsDescription>(std::begin(config.instruments), std::end(config.instruments));
141 }
142 
143 std::string Framework::current_suite_name() const
144 {
145  return join(_test_suite_name.cbegin(), _test_suite_name.cend(), "/");
146 }
147 
148 void Framework::push_suite(std::string name)
149 {
150  _test_suite_name.emplace_back(std::move(name));
151 }
152 
153 void Framework::pop_suite()
154 {
155  _test_suite_name.pop_back();
156 }
157 
158 void Framework::add_test_info(std::string info)
159 {
160  _test_info.emplace_back(std::move(info));
161 }
162 
163 void Framework::clear_test_info()
164 {
165  _test_info.clear();
166 }
167 
168 bool Framework::has_test_info() const
169 {
170  return !_test_info.empty();
171 }
172 
173 void Framework::print_test_info(std::ostream &os) const
174 {
175  if(!_test_info.empty())
176  {
177  os << "CONTEXT:\n";
178 
179  for(const auto &str : _test_info)
180  {
181  os << " " << str << "\n";
182  }
183  }
184 }
185 
186 template <typename F>
187 void Framework::func_on_all_printers(F &&func)
188 {
189  std::for_each(std::begin(_printers), std::end(_printers), func);
190 }
191 
192 void Framework::log_test_start(const TestInfo &info)
193 {
194  if(_log_level >= LogLevel::TESTS)
195  {
196  func_on_all_printers([&](Printer * p)
197  {
199  });
200  }
201 }
202 
203 void Framework::log_test_skipped(const TestInfo &info)
204 {
205  static_cast<void>(info);
206 }
207 
208 void Framework::log_test_end(const TestInfo &info)
209 {
210  if(_log_level >= LogLevel::MEASUREMENTS)
211  {
212  func_on_all_printers([&](Printer * p)
213  {
214  p->print_profiler_header(_test_results.at(info).header_data);
215  p->print_measurements(_test_results.at(info).measurements);
216  });
217  }
218 
219  if(_log_level >= LogLevel::TESTS)
220  {
221  func_on_all_printers([](Printer * p)
222  {
223  p->print_test_footer();
224  });
225  }
226 }
227 
228 void Framework::log_failed_expectation(const TestError &error)
229 {
230  ARM_COMPUTE_ERROR_ON(_current_test_info == nullptr);
231  ARM_COMPUTE_ERROR_ON(_current_test_result == nullptr);
232 
233  const bool is_expected_failure = _current_test_info->status == TestCaseFactory::Status::EXPECTED_FAILURE;
234 
235  if(_log_level >= error.level())
236  {
237  func_on_all_printers([&](Printer * p)
238  {
239  p->print_error(error, is_expected_failure);
240  });
241  }
242 
243  _current_test_result->status = TestResult::Status::FAILED;
244 }
245 
246 void Framework::log_info(const std::string &info)
247 {
248  if(_log_level >= LogLevel::DEBUG)
249  {
250  func_on_all_printers([&](Printer * p)
251  {
252  p->print_info(info);
253  });
254  }
255 }
256 
257 int Framework::num_iterations() const
258 {
259  return _num_iterations;
260 }
261 
262 void Framework::set_num_iterations(int num_iterations)
263 {
264  _num_iterations = num_iterations;
265 }
266 
267 void Framework::set_throw_errors(bool throw_errors)
268 {
269  _throw_errors = throw_errors;
270 }
271 
272 bool Framework::throw_errors() const
273 {
274  return _throw_errors;
275 }
276 
277 void Framework::set_stop_on_error(bool stop_on_error)
278 {
279  _stop_on_error = stop_on_error;
280 }
281 
282 bool Framework::stop_on_error() const
283 {
284  return _stop_on_error;
285 }
286 
287 void Framework::set_error_on_missing_assets(bool error_on_missing_assets)
288 {
289  _error_on_missing_assets = error_on_missing_assets;
290 }
291 
292 bool Framework::error_on_missing_assets() const
293 {
294  return _error_on_missing_assets;
295 }
296 
297 TestResult::Status Framework::run_test(const TestInfo &info, TestCaseFactory &test_factory)
298 {
299  if(test_factory.status() == TestCaseFactory::Status::DISABLED)
300  {
301  log_test_skipped(info);
302  set_test_result(info, TestResult(TestResult::Status::DISABLED));
303  return TestResult::Status::DISABLED;
304  }
305 
306  log_test_start(info);
307 
308  Profiler profiler = get_profiler();
309  TestResult result(TestResult::Status::NOT_RUN);
310 
311  _current_test_info = &info;
312  _current_test_result = &result;
313 
314  if(_log_level >= LogLevel::ERRORS)
315  {
316  func_on_all_printers([](Printer * p)
317  {
318  p->print_errors_header();
319  });
320  }
321 
322  const bool is_expected_failure = info.status == TestCaseFactory::Status::EXPECTED_FAILURE;
323 
324  try
325  {
326  std::unique_ptr<TestCase> test_case = test_factory.make();
327 
328  try
329  {
330  profiler.test_start();
331 
332  test_case->do_setup();
333 
334  for(int i = 0; i < _num_iterations; ++i)
335  {
336  //Start the profiler if:
337  //- there is only one iteration
338  //- it's not the first iteration of a multi-iterations run.
339  //
340  //Reason: if the CLTuner is enabled then the first run will be really messy
341  //as each kernel will be executed several times, messing up the instruments like OpenCL timers.
342  if(_num_iterations == 1 || i != 0)
343  {
344  profiler.start();
345  }
346  test_case->do_run();
347  test_case->do_sync();
348  if(_num_iterations == 1 || i != 0)
349  {
350  profiler.stop();
351  }
352  }
353 
354  test_case->do_teardown();
355 
356  profiler.test_stop();
357 
358  // Change status to success if no error has happend
359  if(result.status == TestResult::Status::NOT_RUN)
360  {
361  result.status = TestResult::Status::SUCCESS;
362  }
363  }
364  catch(const FileNotFound &error)
365  {
366  profiler.test_stop();
367  if(_error_on_missing_assets)
368  {
369  if(_log_level >= LogLevel::ERRORS)
370  {
371  TestError test_error(error.what(), LogLevel::ERRORS);
372  func_on_all_printers([&](Printer * p)
373  {
374  p->print_error(test_error, is_expected_failure);
375  });
376  }
377 
378  result.status = TestResult::Status::FAILED;
379 
380  if(_throw_errors)
381  {
382  throw;
383  }
384  }
385  else
386  {
387  if(_log_level >= LogLevel::DEBUG)
388  {
389  func_on_all_printers([&](Printer * p)
390  {
391  p->print_info(error.what());
392  });
393  }
394 
395  result.status = TestResult::Status::NOT_RUN;
396  }
397  }
398  catch(const TestError &error)
399  {
400  profiler.test_stop();
401  if(_log_level >= error.level())
402  {
403  func_on_all_printers([&](Printer * p)
404  {
405  p->print_error(error, is_expected_failure);
406  });
407  }
408 
409  result.status = TestResult::Status::FAILED;
410 
411  if(_throw_errors)
412  {
413  throw;
414  }
415  }
416 #ifdef ARM_COMPUTE_CL
417  catch(const ::cl::Error &error)
418  {
419  profiler.test_stop();
420  if(_log_level >= LogLevel::ERRORS)
421  {
422  std::stringstream stream;
423  stream << "Error code: " << error.err();
424  TestError test_error(error.what(), LogLevel::ERRORS, stream.str());
425  func_on_all_printers([&](Printer * p)
426  {
427  p->print_error(test_error, is_expected_failure);
428  });
429  }
430 
431  result.status = TestResult::Status::FAILED;
432 
433  if(_throw_errors)
434  {
435  throw;
436  }
437  }
438 #endif /* ARM_COMPUTE_CL */
439  catch(const std::exception &error)
440  {
441  profiler.test_stop();
442  if(_log_level >= LogLevel::ERRORS)
443  {
444  func_on_all_printers([&](Printer * p)
445  {
446  p->print_error(error, is_expected_failure);
447  });
448  }
449 
450  result.status = TestResult::Status::CRASHED;
451 
452  if(_throw_errors)
453  {
454  throw;
455  }
456  }
457  catch(...)
458  {
459  profiler.test_stop();
460  if(_log_level >= LogLevel::ERRORS)
461  {
462  func_on_all_printers([&](Printer * p)
463  {
464  p->print_error(TestError("Received unknown exception"), is_expected_failure);
465  });
466  }
467 
468  result.status = TestResult::Status::CRASHED;
469 
470  if(_throw_errors)
471  {
472  throw;
473  }
474  }
475  }
476  catch(const std::exception &error)
477  {
478  if(_log_level >= LogLevel::ERRORS)
479  {
480  func_on_all_printers([&](Printer * p)
481  {
482  p->print_error(error, is_expected_failure);
483  });
484  }
485 
486  result.status = TestResult::Status::CRASHED;
487 
488  if(_throw_errors)
489  {
490  throw;
491  }
492  }
493  catch(...)
494  {
495  if(_log_level >= LogLevel::ERRORS)
496  {
497  func_on_all_printers([&](Printer * p)
498  {
499  p->print_error(TestError("Received unknown exception"), is_expected_failure);
500  });
501  }
502 
503  result.status = TestResult::Status::CRASHED;
504 
505  if(_throw_errors)
506  {
507  throw;
508  }
509  }
510 
511  if(_log_level >= LogLevel::ERRORS)
512  {
513  func_on_all_printers([](Printer * p)
514  {
515  p->print_errors_footer();
516  });
517  }
518 
519  _current_test_info = nullptr;
520  _current_test_result = nullptr;
521 
522  if(result.status == TestResult::Status::FAILED)
523  {
524  if(info.status == TestCaseFactory::Status::EXPECTED_FAILURE)
525  {
526  result.status = TestResult::Status::EXPECTED_FAILURE;
527  }
528  }
529 
530  if(result.status == TestResult::Status::FAILED || result.status == TestResult::Status::CRASHED)
531  {
532  if(_stop_on_error)
533  {
534  throw std::runtime_error("Abandon on first error.");
535  }
536  }
537 
538  result.header_data = profiler.header();
539  result.measurements = profiler.measurements();
540 
541  set_test_result(info, result);
542  log_test_end(info);
543  return result.status;
544 }
545 
547 {
548  // Clear old test results
549  _test_results.clear();
550 
551  if(_log_level >= LogLevel::TESTS)
552  {
553  func_on_all_printers([](Printer * p)
554  {
555  p->print_run_header();
556  });
557  }
558 
559  const std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
560 
561  int id = 0;
562  int id_run_test = 0;
563  ARM_COMPUTE_UNUSED(id_run_test); // Not used if ARM_COMPUTE_CL is not defined
564 
565  for(auto &test_factory : _test_factories)
566  {
567  const std::string test_case_name = test_factory->name();
568  const TestInfo test_info{ id, test_case_name, test_factory->mode(), test_factory->status() };
569 
570  if(_test_filter->is_selected(test_info))
571  {
572 #ifdef ARM_COMPUTE_CL
573  // Every 100 tests, reset the OpenCL context to release the allocated memory
574  if(opencl_is_available() && (id_run_test % 100) == 0)
575  {
576  auto ctx_properties = CLScheduler::get().context().getInfo<CL_CONTEXT_PROPERTIES>(nullptr);
577  auto queue_properties = CLScheduler::get().queue().getInfo<CL_QUEUE_PROPERTIES>(nullptr);
578 
579  cl::Context new_ctx = cl::Context(CL_DEVICE_TYPE_DEFAULT, ctx_properties.data());
580  cl::CommandQueue new_queue = cl::CommandQueue(new_ctx, CLKernelLibrary::get().get_device(), queue_properties);
581 
583  CLScheduler::get().set_context(new_ctx);
584  CLScheduler::get().set_queue(new_queue);
585  }
586 #endif // ARM_COMPUTE_CL
587  TestResult::Status result = run_test(test_info, *test_factory);
588  if((_print_rerun_cmd) && (result == TestResult::Status::CRASHED || result == TestResult::Status::FAILED))
589  {
590  std::cout << "Rerun command: ./arm_compute_validation --filter='^" << test_info.name << "$' --seed=" << _seed << std::endl;
591  }
592  ++id_run_test;
593 
594  // Run test delay
595  sleep_in_seconds(_cooldown_sec);
596  }
597 
598  ++id;
599  }
600 
601  const std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
602 
603  if(_log_level >= LogLevel::TESTS)
604  {
605  func_on_all_printers([](Printer * p)
606  {
607  p->print_run_footer();
608  });
609  }
610 
611  auto runtime = std::chrono::duration_cast<std::chrono::seconds>(end - start);
612  std::map<TestResult::Status, int> results = count_test_results();
613 
614  if(_log_level > LogLevel::NONE)
615  {
616  std::cout << "Executed " << _test_results.size() << " test(s) ("
617  << results[TestResult::Status::SUCCESS] << " passed, "
618  << results[TestResult::Status::EXPECTED_FAILURE] << " expected failures, "
619  << results[TestResult::Status::FAILED] << " failed, "
620  << results[TestResult::Status::CRASHED] << " crashed, "
621  << results[TestResult::Status::DISABLED] << " disabled) in " << runtime.count() << " second(s)\n";
622  }
623 
624  int num_successful_tests = results[TestResult::Status::SUCCESS] + results[TestResult::Status::EXPECTED_FAILURE] + results[TestResult::Status::DISABLED];
625 
626  return (static_cast<unsigned int>(num_successful_tests) == _test_results.size());
627 }
628 
629 void Framework::set_test_result(TestInfo info, TestResult result)
630 {
631  _test_results.emplace(std::move(info), std::move(result));
632 }
633 
634 void Framework::print_test_results(Printer &printer) const
635 {
636  printer.print_run_header();
637 
638  for(const auto &test : _test_results)
639  {
640  printer.print_test_header(test.first);
641  printer.print_profiler_header(test.second.header_data);
642  printer.print_measurements(test.second.measurements);
643  printer.print_test_footer();
644  }
645 
646  printer.print_run_footer();
647 }
648 
649 Profiler Framework::get_profiler() const
650 {
651  Profiler profiler;
652 
653  const bool all_instruments = std::any_of(
654  _instruments.begin(),
655  _instruments.end(),
656  [](InstrumentsDescription type) -> bool { return type.first == InstrumentType::ALL; });
657 
658  auto is_selected = [&](InstrumentsDescription instrument) -> bool
659  {
660  return std::find_if(_instruments.begin(), _instruments.end(), [&](InstrumentsDescription type) -> bool {
661  const auto group = static_cast<InstrumentType>(static_cast<uint64_t>(type.first) & 0xFF00);
662  return (group == instrument.first) && (instrument.second == type.second);
663  })
664  != _instruments.end();
665  };
666 
667  for(const auto &instrument : _available_instruments)
668  {
669  if(all_instruments || is_selected(instrument.first))
670  {
671  profiler.add(instrument.second());
672  }
673  }
674 
675  return profiler;
676 }
677 
678 void Framework::add_printer(Printer *printer)
679 {
680  _printers.push_back(printer);
681 }
682 
683 std::vector<TestInfo> Framework::test_infos() const
684 {
685  std::vector<TestInfo> ids;
686 
687  int id = 0;
688 
689  for(const auto &factory : _test_factories)
690  {
691  const TestInfo test_info{ id, factory->name(), factory->mode(), factory->status() };
692 
693  if(_test_filter->is_selected(test_info))
694  {
695  ids.emplace_back(std::move(test_info));
696  }
697 
698  ++id;
699  }
700 
701  return ids;
702 }
703 
704 LogLevel Framework::log_level() const
705 {
706  return _log_level;
707 }
708 
709 void Framework::set_instruments_info(InstrumentsInfo instr_info)
710 {
712  *instruments_info = instr_info;
713 }
714 
715 bool Framework::configure_only() const
716 {
717  return _configure_only;
718 }
719 
720 bool Framework::new_fixture_call() const
721 {
722  return _new_fixture_call;
723 }
724 
725 void Framework::set_new_fixture_call(bool val)
726 {
727  _new_fixture_call = val;
728 }
729 } // namespace framework
730 } // namespace test
731 } // namespace arm_compute
arm_compute::test::framework::Printer::print_info
virtual void print_info(const std::string &info)=0
Print test log info.
TestFilter.h
arm_compute::test::framework::Profiler::add
void add(std::unique_ptr< Instrument > instrument)
Add instrument to the performance monitor.
Definition: Profiler.cpp:35
arm_compute::opencl_is_available
bool opencl_is_available()
Check if OpenCL is available.
Definition: OpenCL.cpp:203
arm_compute::test::framework::InstrumentType::MALI
@ MALI
arm_compute::test::framework::Printer::print_measurements
virtual void print_measurements(const Profiler::MeasurementsMap &measurements)=0
Print measurements for a test.
arm_compute::test::framework::FrameworkConfig
Framework configuration structure.
Definition: Framework.h:57
arm_compute::test::validation::run
lstmq run()
type
decltype(strategy::transforms) typedef type
Definition: gemm_interleaved.hpp:261
arm_compute::test::framework::FrameworkConfig::num_iterations
int num_iterations
Number of iterations per test.
Definition: Framework.h:63
arm_compute::test::framework::Profiler
Profiler class to collect benchmark numbers.
Definition: Profiler.h:45
arm_compute::test::framework::FrameworkConfig::print_rerun_cmd
bool print_rerun_cmd
Print the command to rerun the failed testcase.
Definition: Framework.h:67
arm_compute::test::framework::TestResult::Status
Status
Execution status of a test.
Definition: TestResult.h:42
CLRuntimeContext.h
arm_compute::test::framework::InstrumentType::SCHEDULER_TIMER
@ SCHEDULER_TIMER
arm_compute::test::framework::TestError
Error class for failures during test execution.
Definition: Exceptions.h:78
arm_compute::test::framework::InstrumentType::SCHEDULER_TIMESTAMPS
@ SCHEDULER_TIMESTAMPS
arm_compute::test::framework::FrameworkConfig::mode
DatasetMode mode
Dataset mode.
Definition: Framework.h:62
arm_compute::test::framework::InstrumentType::OPENCL_TIMER
@ OPENCL_TIMER
arm_compute::test::framework::Printer::print_run_footer
virtual void print_run_footer()=0
Print footer after running all tests.
arm_compute::test::framework::InstrumentType::OPENCL_MEMORY_USAGE
@ OPENCL_MEMORY_USAGE
arm_compute::test::sleep_in_seconds
void sleep_in_seconds(float seconds)
Makes the calling thread to sleep for a specified number of seconds.
Definition: Utils.cpp:38
arm_compute::test::framework::ScaleFactor::TIME_US
@ TIME_US
arm_compute::test::framework::TestFilter
Test filter class.
Definition: TestFilter.h:46
caffe_mnist_image_extractor.str
str
Definition: caffe_mnist_image_extractor.py:21
arm_compute::CLKernelLibrary::get
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Definition: CLKernelLibrary.cpp:39
arm_compute::test::framework::FrameworkConfig::log_level
LogLevel log_level
Verbosity of the output.
Definition: Framework.h:65
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:467
arm_compute::test::join
std::string join(T first, T last, const std::string &separator)
Helper function to concatenate multiple strings.
Definition: Utils.h:93
arm_compute::test::framework::Printer::print_run_header
virtual void print_run_header()=0
Print header before running all tests.
arm_compute::test::framework::InstrumentType::OPENCL_TIMESTAMPS
@ OPENCL_TIMESTAMPS
arm_compute::test::framework::Framework
Main framework class.
Definition: Framework.h:97
is_selected
const BatchNormalizationSelectorPtr is_selected
Definition: NEBatchNormalizationLayerKernel.cpp:61
arm_compute::test::framework::FrameworkConfig::configure_only
bool configure_only
Only configure kernels.
Definition: Framework.h:66
arm_compute::test::framework::FrameworkConfig::id_filter
std::string id_filter
String to match selected test ids.
Definition: Framework.h:61
CLScheduler.h
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
arm_compute::test::framework::FrameworkConfig::instruments
std::vector< framework::InstrumentsDescription > instruments
Instrument types that will be used for benchmarking.
Definition: Framework.h:59
arm_compute::test::framework::ScaleFactor::NONE
@ NONE
arm_compute::test::framework::Printer
Abstract printer class used by the Framework to present output.
Definition: Printer.h:43
name
const char * name
Definition: NEBatchNormalizationLayerKernel.cpp:60
arm_compute::CLKernelLibrary::clear_programs_cache
void clear_programs_cache()
Clear the library's cache of binary programs.
Definition: CLKernelLibrary.cpp:85
arm_compute::test::framework::ScaleFactor::TIME_S
@ TIME_S
arm_compute::test::framework::ScaleFactor::SCALE_1K
@ SCALE_1K
arm_compute::test::framework::TestError::level
LogLevel level() const
Severity of the error.
Definition: Exceptions.cpp:121
arm_compute::test::framework::ScaleFactor::TIME_MS
@ TIME_MS
ARM_COMPUTE_UNUSED
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
arm_compute::test::framework::TestCaseFactory::name
std::string name() const
Name of the test case.
Definition: TestCaseFactory.h:140
arm_compute::CLScheduler::get
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:103
Scheduler.h
arm_compute::test::framework::InstrumentsInfo
Definition: Instruments.h:63
arm_compute::CLScheduler::set_context
void set_context(cl::Context context)
Accessor to set the CL context to be used by the scheduler.
Definition: CLScheduler.cpp:148
arm_compute::test::framework::FrameworkConfig::name_filter
std::string name_filter
Regular expression to filter tests by name.
Definition: Framework.h:60
arm_compute::test::framework::TestCaseFactory
Abstract factory class to create test cases.
Definition: TestCaseFactory.h:40
arm_compute::test::parameters
std::unique_ptr< ParametersLibrary > parameters
Definition: Framework.cpp:46
arm_compute::test::framework::InstrumentType::WALL_CLOCK_TIMER
@ WALL_CLOCK_TIMER
arm_compute::test::framework::TestCaseFactory::make
virtual std::unique_ptr< TestCase > make() const =0
Factory function to create the test case.
arm_compute::test::framework::InstrumentType::WALL_CLOCK_TIMESTAMPS
@ WALL_CLOCK_TIMESTAMPS
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::test::framework::TestResult
Class to store results of a test.
Definition: TestResult.h:39
arm_compute::test::framework::Printer::print_error
virtual void print_error(const std::exception &error, bool expected)=0
Print test error.
arm_compute::mlgo::parser::end
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
arm_compute::test::framework::TestCaseFactory::status
Status status() const
Get the status of the test case.
Definition: TestCaseFactory.h:157
arm_compute::test::validation::info
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
arm_compute::test::framework::TestInfo
Information about a test case.
Definition: Framework.h:80
arm_compute::test::framework::Printer::print_test_footer
virtual void print_test_footer()=0
Print footer after a test.
arm_compute::test::framework::FrameworkConfig::seed
unsigned int seed
The seed that is used to fill tensors with random values.
Definition: Framework.h:68
arm_compute::test::framework::InstrumentType::PMU
@ PMU
arm_compute::CLScheduler::queue
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.cpp:39
arm_compute::test::framework::FrameworkConfig::cooldown_sec
float cooldown_sec
Delay between tests in seconds.
Definition: Framework.h:64
arm_compute::utility::for_each
void for_each(F &&)
Base case of for_each.
Definition: Utility.h:111
arm_compute::test::framework::LogLevel
LogLevel
Severity of the information.
Definition: Exceptions.h:50
arm_compute::CLScheduler::set_queue
void set_queue(cl::CommandQueue queue)
Accessor to set the CL command queue to be used by the scheduler.
Definition: CLScheduler.cpp:55
arm_compute::test::framework::Printer::print_profiler_header
virtual void print_profiler_header(const std::string &header_data)=0
Print header data.
arm_compute::test::framework::ScaleFactor::SCALE_1M
@ SCALE_1M
arm_compute::test::framework::instruments_info
std::unique_ptr< InstrumentsInfo > instruments_info
Definition: Framework.cpp:50
arm_compute::test::framework::TestCaseFactory::mode
DatasetMode mode() const
Get the mode for which test case will be enabled.
Definition: TestCaseFactory.h:152
arm_compute::CLScheduler::context
cl::Context & context()
Accessor for the associated CL context.
Definition: CLScheduler.cpp:32
arm_compute::test::framework::InstrumentsDescription
std::pair< InstrumentType, ScaleFactor > InstrumentsDescription
Definition: Instruments.h:69
arm_compute::test::framework::TestInfo::name
std::string name
Test name.
Definition: Framework.h:83
ParametersLibrary.h
arm_compute::test::framework::Printer::print_test_header
virtual void print_test_header(const TestInfo &info)=0
Print header before a test.
Framework.h