Compute Library
 19.11.1
main.cpp File Reference

Go to the source code of this file.

Namespaces

 arm_compute
 Copyright (c) 2017-2019 ARM Limited.
 
 arm_compute::test
 

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 93 of file main.cpp.

94 {
95  framework::Framework &framework = framework::Framework::get();
96 
98 
99  std::set<framework::DatasetMode> allowed_modes
100  {
101  framework::DatasetMode::DISABLED,
102  framework::DatasetMode::PRECOMMIT,
103  framework::DatasetMode::NIGHTLY,
104  framework::DatasetMode::ALL
105  };
106 
108 
109  auto dataset_mode = parser.add_option<utils::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT);
110  dataset_mode->set_help("For managed datasets select which group to use");
111  auto filter = parser.add_option<utils::SimpleOption<std::string>>("filter", ".*");
112  filter->set_help("Regular expression to select test cases");
113  auto filter_id = parser.add_option<utils::SimpleOption<std::string>>("filter-id");
114  filter_id->set_help("List of test ids. ... can be used to define a range.");
115  auto stop_on_error = parser.add_option<utils::ToggleOption>("stop-on-error");
116  stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
117  auto seed = parser.add_option<utils::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
118  seed->set_help("Global seed for random number generation");
119  auto list_tests = parser.add_option<utils::ToggleOption>("list-tests", false);
120  list_tests->set_help("List all test names");
121  auto test_instruments = parser.add_option<utils::ToggleOption>("test-instruments", false);
122  test_instruments->set_help("Test if the instruments work on the platform");
123  auto error_on_missing_assets = parser.add_option<utils::ToggleOption>("error-on-missing-assets", false);
124  error_on_missing_assets->set_help("Mark a test as failed instead of skipping it when assets are missing");
125  auto assets = parser.add_positional_option<utils::SimpleOption<std::string>>("assets");
126  assets->set_help("Path to the assets directory");
127 #ifdef ARM_COMPUTE_CL
128  auto enable_tuner = parser.add_option<utils::ToggleOption>("enable-tuner");
129  enable_tuner->set_help("Enable OpenCL dynamic tuner");
130 
131  const std::set<CLTunerMode> supported_tuner_modes
132  {
133  CLTunerMode::EXHAUSTIVE,
134  CLTunerMode::NORMAL,
135  CLTunerMode::RAPID
136  };
137  auto tuner_mode = parser.add_option<utils::EnumOption<CLTunerMode>>("tuner-mode", supported_tuner_modes, CLTunerMode::NORMAL);
138  tuner_mode->set_help("Configures the time taken by the tuner to tune. Slow tuner produces the most performant LWS configuration");
139 
140  auto tuner_file = parser.add_option<utils::SimpleOption<std::string>>("tuner-file", "");
141  tuner_file->set_help("File to load/save CLTuner values");
142 #endif /* ARM_COMPUTE_CL */
143  auto threads = parser.add_option<utils::SimpleOption<int>>("threads", 1);
144  threads->set_help("Number of threads to use");
145 
146  try
147  {
148  parser.parse(argc, argv);
149 
150  if(options.help->is_set() && options.help->value())
151  {
152  parser.print_help(argv[0]);
153  return 0;
154  }
155 
156  std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers();
157 
158  // Setup CPU Scheduler
159  Scheduler::get().set_num_threads(threads->value());
160 
161  // Create CPU context
162  auto cpu_ctx = support::cpp14::make_unique<RuntimeContext>();
163  cpu_ctx->set_scheduler(&Scheduler::get());
164 
165  // Track CPU context
166  auto cpu_ctx_track = support::cpp14::make_unique<ContextSchedulerUser>(cpu_ctx.get());
167 
168  // Create parameters
169  parameters = support::cpp14::make_unique<ParametersLibrary>();
170  parameters->set_cpu_ctx(std::move(cpu_ctx));
171 
172 #ifdef ARM_COMPUTE_GC
173  // Setup OpenGL context
174  {
175  auto gles_ctx = support::cpp14::make_unique<GCRuntimeContext>();
176  ARM_COMPUTE_ERROR_ON(gles_ctx == nullptr);
177  {
178  // Legacy singletons API: This has been deprecated and the singletons will be removed
179  // Setup singleton for backward compatibility
180  GCScheduler::get().default_init();
181  }
182  parameters->set_gc_ctx(std::move(gles_ctx));
183  };
184 #endif /* ARM_COMPUTE_GC */
185 
186 #ifdef ARM_COMPUTE_CL
187  CLTuner cl_tuner(false);
188  if(opencl_is_available())
189  {
190  auto ctx_dev_err = create_opencl_context_and_device();
191  ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context");
192  CLScheduler::get().default_init_with_context(std::get<1>(ctx_dev_err), std::get<0>(ctx_dev_err), &cl_tuner);
193  }
194 
195  if(enable_tuner->is_set())
196  {
197  cl_tuner.set_tune_new_kernels(enable_tuner->value());
198 
199  //set tuner mode
200  cl_tuner.set_tuner_mode(tuner_mode->value());
201 
202  // If that's the first run then the file won't exist yet
203  if(file_exists(tuner_file->value()))
204  {
205  cl_tuner.load_from_file(tuner_file->value());
206  }
207  }
208  else if(!tuner_file->value().empty())
209  {
210  //If we're not tuning and the file doesn't exist then we should raise an error:
211  cl_tuner.load_from_file(tuner_file->value());
212  }
213 #endif /* ARM_COMPUTE_CL */
214  if(options.log_level->value() > framework::LogLevel::NONE)
215  {
216  for(auto &p : printers)
217  {
218  p->print_global_header();
219  }
220  }
221 
222  if(options.log_level->value() >= framework::LogLevel::CONFIG)
223  {
224  for(auto &p : printers)
225  {
226  p->print_entry("Version", build_information());
227  p->print_entry("CommandLine", command_line(argc, argv));
228  p->print_entry("Seed", support::cpp11::to_string(seed->value()));
229 #ifdef ARM_COMPUTE_CL
230  if(opencl_is_available())
231  {
232  p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version());
233  }
234  else
235  {
236  p->print_entry("CL_DEVICE_VERSION", "Unavailable");
237  }
238 #endif /* ARM_COMPUTE_CL */
239  const arm_compute::CPUInfo &cpu_info = Scheduler::get().cpu_info();
240  const unsigned int num_cpus = cpu_info.get_cpu_num();
241  p->print_entry("cpu_has_fp16", support::cpp11::to_string(cpu_info.has_fp16()));
242  p->print_entry("cpu_has_dotprod", support::cpp11::to_string(cpu_info.has_dotprod()));
243 
244  for(unsigned int j = 0; j < num_cpus; ++j)
245  {
246  const CPUModel model = cpu_info.get_cpu_model(j);
247  p->print_entry("CPU" + support::cpp11::to_string(j), cpu_model_to_string(model));
248  }
249  p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
250  p->print_entry("Threads", support::cpp11::to_string(threads->value()));
251  {
253  p->print_entry("Dataset mode", to_string(dataset_mode->value()));
254  }
255  }
256  }
257 
258  // Setup instruments meta-data
260  instruments_info._scheduler_users.push_back(cpu_ctx_track.get());
262 
263  // Initialize framework
264  framework.init(options.instruments->value(),
265  options.iterations->value(),
266  dataset_mode->value(),
267  filter->value(),
268  filter_id->value(),
269  options.log_level->value());
270 
271  for(auto &p : printers)
272  {
273  framework.add_printer(p.get());
274  }
275  framework.set_throw_errors(options.throw_errors->value());
276  framework.set_stop_on_error(stop_on_error->value());
277  framework.set_error_on_missing_assets(error_on_missing_assets->value());
278 
279  bool success = true;
280 
281  if(list_tests->value())
282  {
283  for(auto &p : printers)
284  {
285  p->print_list_tests(framework.test_infos());
286  p->print_global_footer();
287  }
288 
289  return 0;
290  }
291 
292  if(test_instruments->value())
293  {
294  framework::Profiler profiler = framework.get_profiler();
295  profiler.start();
296  profiler.stop();
297  for(auto &p : printers)
298  {
299  p->print_measurements(profiler.measurements());
300  }
301 
302  return 0;
303  }
304 
305  library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
306 
307  if(!parser.validate())
308  {
309  return 1;
310  }
311 
312  success = framework.run();
313 
314  if(options.log_level->value() > framework::LogLevel::NONE)
315  {
316  for(auto &p : printers)
317  {
318  p->print_global_footer();
319  }
320  }
321 
322 #ifdef ARM_COMPUTE_CL
323  if(opencl_is_available())
324  {
325  CLScheduler::get().sync();
326  if(enable_tuner->is_set() && enable_tuner->value() && tuner_file->is_set())
327  {
328  cl_tuner.save_to_file(tuner_file->value());
329  }
330  }
331 #endif /* ARM_COMPUTE_CL */
332 
333  return (success ? 0 : 1);
334  }
335  catch(const std::exception &error)
336  {
337  std::cerr << error.what() << "\n";
338 
339  if(options.throw_errors->value())
340  {
341  throw;
342  }
343 
344  return 1;
345  }
346  return 0;
347 }
Basic implementation of the OpenCL tuner interface.
Definition: CLTuner.h:38
std::string to_string(DatasetMode mode)
Definition: DatasetModes.h:100
Profiler class to collect benchmark numbers.
Definition: Profiler.h:45
bool has_fp16() const
Checks if the cpu model supports fp16.
Definition: CPPTypes.cpp:58
void set_throw_errors(bool throw_errors)
Set whether errors are caught or thrown by the framework.
Definition: Framework.cpp:261
Implementation of an option that can be either true or false.
Definition: ToggleOption.h:36
void set_instruments_info(InstrumentsInfo instr_info)
Sets instruments info.
Definition: Framework.cpp:694
std::unique_ptr< InstrumentsInfo > instruments_info
Definition: Framework.cpp:49
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
CPUModel
CPU models - we only need to detect CPUs we have microarchitecture-specific code for.
Definition: CPPTypes.h:40
std::tuple< cl::Context, cl::Device, cl_int > create_opencl_context_and_device()
This function creates an OpenCL context and a device.
Definition: CLHelpers.cpp:88
void set_error_on_missing_assets(bool error_on_missing_assets)
Set whether a test should be considered as failed if its assets cannot be found.
Definition: Framework.cpp:281
Class to parse command line arguments.
CPUModel get_cpu_model(unsigned int cpuid) const
Gets the cpu model for a given cpuid.
Definition: CPPTypes.cpp:68
std::string cpu_model_to_string(CPUModel val)
Convert a cpumodel value to a string.
Definition: CPPTypes.h:69
void init(const std::vector< framework::InstrumentsDescription > &instruments, int num_iterations, DatasetMode mode, const std::string &name_filter, const std::string &id_filter, LogLevel log_level)
Init the framework.
Definition: Framework.cpp:128
bool run()
Run all enabled test cases.
Definition: Framework.cpp:538
std::vector< TestInfo > test_infos() const
List of TestInfo's.
Definition: Framework.cpp:668
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:77
std::unique_ptr< ParametersLibrary > parameters
Definition: Framework.cpp:45
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
bool has_dotprod() const
Checks if the cpu model supports dot product.
Definition: CPPTypes.cpp:63
Profiler get_profiler() const
Factory method to obtain a configured profiler.
Definition: Framework.cpp:634
const MeasurementsMap & measurements() const
Return measurements for all instruments.
Definition: Profiler.cpp:87
unsigned int get_cpu_num() const
Return the maximum number of CPUs present.
Definition: CPPTypes.cpp:54
Implementation of a simple option that accepts a value from a fixed set.
Definition: EnumOption.h:40
void start()
Call start() on all the added instruments.
Definition: Profiler.cpp:48
std::string build_information()
Returns the arm_compute library build information.
void add_printer(Printer *printer)
Set the printer used for the output of test results.
Definition: Framework.cpp:663
void stop()
Call stop() on all the added instruments.
Definition: Profiler.cpp:56
Common command line options used to configure the framework.
Definition: CommonOptions.h:54
void set_stop_on_error(bool stop_on_error)
Set whether to abort execution after the first failed test.
Definition: Framework.cpp:271
void set_help(std::string help)
Set the help message for the option.
Definition: Option.h:125
bool opencl_is_available()
Check if OpenCL is available.
Definition: OpenCL.cpp:142

References Framework::add_printer(), arm_compute::test::framework::ALL, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MSG, arm_compute::build_information(), arm_compute::test::framework::CONFIG, IScheduler::cpu_info(), arm_compute::cpu_model_to_string(), arm_compute::create_opencl_context_and_device(), CommonOptions::create_printers(), GCScheduler::default_init(), CLScheduler::default_init_with_context(), arm_compute::test::framework::DISABLED, arm_compute::EXHAUSTIVE, GCScheduler::get(), CLScheduler::get(), Scheduler::get(), Framework::get(), CLKernelLibrary::get(), CPUInfo::get_cpu_model(), CPUInfo::get_cpu_num(), Framework::get_profiler(), CPUInfo::has_dotprod(), CPUInfo::has_fp16(), CommonOptions::help, Framework::init(), CommonOptions::instruments, arm_compute::test::framework::instruments_info, Option::is_set(), CommonOptions::iterations, arm_compute::test::library, CLTuner::load_from_file(), CommonOptions::log_level, Profiler::measurements(), arm_compute::test::framework::NIGHTLY, arm_compute::test::framework::NONE, arm_compute::NORMAL, arm_compute::opencl_is_available(), arm_compute::test::parameters, GemmTuner::parser, arm_compute::test::framework::PRECOMMIT, arm_compute::RAPID, Framework::run(), CLTuner::save_to_file(), Framework::set_error_on_missing_assets(), Option::set_help(), Framework::set_instruments_info(), IScheduler::set_num_threads(), Framework::set_stop_on_error(), Framework::set_throw_errors(), CLTuner::set_tune_new_kernels(), CLTuner::set_tuner_mode(), Profiler::start(), Profiler::stop(), CLScheduler::sync(), Framework::test_infos(), CommonOptions::throw_errors, arm_compute::to_string(), arm_compute::support::cpp11::to_string(), EnumOption< T >::value(), EnumListOption< T >::value(), and SimpleOption< T >::value().