Compute Library
 21.08
CommonGemmExampleOptions.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2021 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  */
25 
26 namespace gemm_tuner
27 {
28 using namespace arm_compute;
29 using namespace utils;
30 
31 ::std::ostream &operator<<(::std::ostream &os, const CommonGemmExampleParams &common_params)
32 {
33  os << "M : " << common_params.M << std::endl;
34  os << "N : " << common_params.N << std::endl;
35  os << "K : " << common_params.K << std::endl;
36  os << "B : " << common_params.B << std::endl;
37  os << "Data type : " << common_params.data_type << std::endl;
38  os << "OpenCL tuner mode : " << common_params.tuner_mode << std::endl;
39  return os;
40 }
41 
43  : help(parser.add_option<ToggleOption>("help")),
44  M(parser.add_positional_option<SimpleOption<size_t>>("M", 100)),
45  N(parser.add_positional_option<SimpleOption<size_t>>("N", 100)),
46  K(parser.add_positional_option<SimpleOption<size_t>>("K", 50)),
47  B(parser.add_positional_option<SimpleOption<size_t>>("B", 1)),
48  data_type(),
49  tuner_mode()
50 {
51  const std::set<DataType> supported_data_types
52  {
53  DataType::F16,
54  DataType::F32,
55  DataType::QASYMM8,
56  };
57 
58  const std::set<CLTunerMode> supported_tuner_modes
59  {
60  CLTunerMode::EXHAUSTIVE,
61  CLTunerMode::NORMAL,
62  CLTunerMode::RAPID
63  };
64 
65  ARM_COMPUTE_ERROR_ON_MSG(supported_data_types.find(default_data_type) == supported_data_types.end(), "Default data type unsupported");
66 
67  data_type = parser.add_option<EnumOption<DataType>>("type", supported_data_types, default_data_type);
68  tuner_mode = parser.add_option<EnumOption<CLTunerMode>>("tuner-mode", supported_tuner_modes, CLTunerMode::RAPID);
69 
70  help->set_help("Show this help message.");
71  M->set_help("Number of lhs matrix rows.");
72  N->set_help("Number of rhs matrix columns.");
73  K->set_help("Number of lhs matrix columns/rhs matrix rows.");
74  B->set_help("Batch size.");
75  data_type->set_help("Data type to use");
76  tuner_mode->set_help("OpenCL tuner mode");
77 }
78 
80 {
81  CommonGemmExampleParams common_params;
82  common_params.M = options.M->value();
83  common_params.N = options.N->value();
84  common_params.K = options.K->value();
85  common_params.B = options.B->value();
86  common_params.data_type = options.data_type->value();
87  common_params.tuner_mode = options.tuner_mode->value();
88  return common_params;
89 }
90 } // namespace gemm_tuner
arm_compute::utils::SimpleOption< size_t > * K
Number of lhs matrix columns/rhs matrix rows option.
arm_compute::utils::SimpleOption< size_t > * M
Number of lhs matrix rows option.
constexpr auto default_data_type
Definition: Scale.cpp:97
size_t M
Number of lhs matrix rows.
unsigned int M
Class to parse command line arguments.
arm_compute::DataType data_type
Data type.
arm_compute::utils::SimpleOption< size_t > * B
Batch size option.
Copyright (c) 2017-2021 Arm Limited.
size_t N
Number of rhs matrix columns.
const DataType data_type
Definition: Im2Col.cpp:150
T * add_option(const std::string &name, As &&... args)
Function to add a new option to the parser.
arm_compute::utils::EnumOption< arm_compute::CLTunerMode > * tuner_mode
OpenCL tuner mode.
Structure holding all the common gemm example parameters.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
unsigned int N
const T & value() const
Get the option value.
Definition: SimpleOption.h:112
::std::ostream & operator<<(::std::ostream &os, const CommonGemmExampleParams &common_params)
Formatted output of the CommonGemmExampleParams type.
CommonGemmExampleOptions(arm_compute::utils::CommandLineParser &parser, arm_compute::DataType default_data_type=arm_compute::DataType::F32)
Constructor.
arm_compute::utils::ToggleOption * help
Show help option.
Common command line options used to configure the gemm examples.
arm_compute::utils::EnumOption< arm_compute::DataType > * data_type
Data type.
CommonGemmExampleParams consume_common_gemm_example_parameters(const CommonGemmExampleOptions &options)
Consumes the common gemm example options and creates a structure containing all information.
arm_compute::CLTunerMode tuner_mode
OpenCL tuner mode.
arm_compute::utils::SimpleOption< size_t > * N
Number of rhs matrix columns option.
const T & value() const
Get the selected value.
DataType
Available data types.
Definition: Types.h:77
void set_help(std::string help)
Set the help message for the option.
Definition: Option.h:125
size_t K
Number of lhs matrix columns/rhs matrix rows.
unsigned int K