| 93 | }; |
| 94 | |
| 95 | int run_example(int argc, char **argv, std::unique_ptr<Example> example) |
| 96 | { |
| 97 | utils::CommandLineParser parser; |
| 98 | framework::CommonOptions options(parser); |
| 99 | auto example_args = parser.add_option<utils::ListOption<std::string>>("example_args"); |
| 100 | example_args->set_help("Arguments to pass to the example separated by commas (e.g: arg0,arg1,arg2)"); |
| 101 | framework::Framework &framework = framework::Framework::get(); |
| 102 | |
| 103 | parser.parse(argc, argv); |
| 104 | |
| 105 | if (options.help->is_set() && options.help->value()) |
| 106 | { |
| 107 | parser.print_help(argv[0]); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers(); |
| 112 | g_example = std::move(example); |
| 113 | g_example_argv.clear(); |
| 114 | g_example_argv.emplace_back(argv[0]); |
| 115 | for (auto &arg : example_args->value()) |
| 116 | { |
| 117 | g_example_argv.emplace_back(const_cast<char *>(arg.c_str())); // NOLINT |
| 118 | } |
| 119 | |
| 120 | if (options.log_level->value() > framework::LogLevel::NONE) |
| 121 | { |
| 122 | for (auto &p : printers) |
| 123 | { |
| 124 | p->print_global_header(); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | #ifdef ARM_COMPUTE_CL |
| 129 | CLGEMMHeuristicsHandle gemm_h; |
| 130 | if (opencl_is_available()) |
| 131 | { |
| 132 | CLBackendType backend_type = CLBackendType::Native; |
| 133 | for (auto &arg : example_args->value()) |
| 134 | { |
| 135 | if (arg.find("--target=clvk") != std::string::npos) |
| 136 | { |
| 137 | backend_type = CLBackendType::Clvk; |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | auto ctx_dev_err = create_opencl_context_and_device(backend_type); |
| 143 | ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context"); |
| 144 | CLScheduler::get().default_init_with_context(std::get<1>(ctx_dev_err), std::get<0>(ctx_dev_err), nullptr, |
| 145 | &gemm_h); |
| 146 | } |
| 147 | #endif /* ARM_COMPUTE_CL */ |
| 148 | |
| 149 | if (options.log_level->value() >= framework::LogLevel::CONFIG) |
| 150 | { |
| 151 | for (auto &p : printers) |
| 152 | { |
nothing calls this directly
no test coverage detected