SiCong Li | 240b79d | 2019-09-24 15:50:34 +0100 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | ca419dd | 2021-03-03 17:25:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2021 Arm Limited. |
SiCong Li | 240b79d | 2019-09-24 15:50:34 +0100 | [diff] [blame] | 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 "CommonGemmExampleOptions.h" |
| 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; |
Eren Kopuz | 350099e | 2020-06-09 15:37:43 +0100 | [diff] [blame] | 37 | os << "Data type : " << common_params.data_type << std::endl; |
Gian Marco Iodice | ca419dd | 2021-03-03 17:25:07 +0000 | [diff] [blame] | 38 | os << "OpenCL tuner mode : " << common_params.tuner_mode << std::endl; |
SiCong Li | 240b79d | 2019-09-24 15:50:34 +0100 | [diff] [blame] | 39 | return os; |
| 40 | } |
| 41 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 42 | CommonGemmExampleOptions::CommonGemmExampleOptions(arm_compute::utils::CommandLineParser &parser, |
| 43 | arm_compute::DataType default_data_type) |
SiCong Li | 240b79d | 2019-09-24 15:50:34 +0100 | [diff] [blame] | 44 | : help(parser.add_option<ToggleOption>("help")), |
| 45 | M(parser.add_positional_option<SimpleOption<size_t>>("M", 100)), |
| 46 | N(parser.add_positional_option<SimpleOption<size_t>>("N", 100)), |
| 47 | K(parser.add_positional_option<SimpleOption<size_t>>("K", 50)), |
Eren Kopuz | 350099e | 2020-06-09 15:37:43 +0100 | [diff] [blame] | 48 | B(parser.add_positional_option<SimpleOption<size_t>>("B", 1)), |
Gian Marco Iodice | ca419dd | 2021-03-03 17:25:07 +0000 | [diff] [blame] | 49 | data_type(), |
| 50 | tuner_mode() |
SiCong Li | 240b79d | 2019-09-24 15:50:34 +0100 | [diff] [blame] | 51 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 52 | const std::set<DataType> supported_data_types{ |
Eren Kopuz | 350099e | 2020-06-09 15:37:43 +0100 | [diff] [blame] | 53 | DataType::F16, |
| 54 | DataType::F32, |
SiCongLi | 282f324 | 2020-11-24 15:24:16 +0000 | [diff] [blame] | 55 | DataType::QASYMM8, |
Eren Kopuz | 350099e | 2020-06-09 15:37:43 +0100 | [diff] [blame] | 56 | }; |
Gian Marco Iodice | ca419dd | 2021-03-03 17:25:07 +0000 | [diff] [blame] | 57 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 58 | const std::set<CLTunerMode> supported_tuner_modes{CLTunerMode::EXHAUSTIVE, CLTunerMode::NORMAL, CLTunerMode::RAPID}; |
Gian Marco Iodice | ca419dd | 2021-03-03 17:25:07 +0000 | [diff] [blame] | 59 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 60 | ARM_COMPUTE_ERROR_ON_MSG(supported_data_types.find(default_data_type) == supported_data_types.end(), |
| 61 | "Default data type unsupported"); |
Eren Kopuz | 350099e | 2020-06-09 15:37:43 +0100 | [diff] [blame] | 62 | |
Gian Marco Iodice | ca419dd | 2021-03-03 17:25:07 +0000 | [diff] [blame] | 63 | data_type = parser.add_option<EnumOption<DataType>>("type", supported_data_types, default_data_type); |
| 64 | tuner_mode = parser.add_option<EnumOption<CLTunerMode>>("tuner-mode", supported_tuner_modes, CLTunerMode::RAPID); |
Eren Kopuz | 350099e | 2020-06-09 15:37:43 +0100 | [diff] [blame] | 65 | |
SiCong Li | 240b79d | 2019-09-24 15:50:34 +0100 | [diff] [blame] | 66 | help->set_help("Show this help message."); |
| 67 | M->set_help("Number of lhs matrix rows."); |
| 68 | N->set_help("Number of rhs matrix columns."); |
| 69 | K->set_help("Number of lhs matrix columns/rhs matrix rows."); |
| 70 | B->set_help("Batch size."); |
Eren Kopuz | 350099e | 2020-06-09 15:37:43 +0100 | [diff] [blame] | 71 | data_type->set_help("Data type to use"); |
Gian Marco Iodice | ca419dd | 2021-03-03 17:25:07 +0000 | [diff] [blame] | 72 | tuner_mode->set_help("OpenCL tuner mode"); |
SiCong Li | 240b79d | 2019-09-24 15:50:34 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | CommonGemmExampleParams consume_common_gemm_example_parameters(const CommonGemmExampleOptions &options) |
| 76 | { |
| 77 | CommonGemmExampleParams common_params; |
Gian Marco Iodice | ca419dd | 2021-03-03 17:25:07 +0000 | [diff] [blame] | 78 | common_params.M = options.M->value(); |
| 79 | common_params.N = options.N->value(); |
| 80 | common_params.K = options.K->value(); |
| 81 | common_params.B = options.B->value(); |
| 82 | common_params.data_type = options.data_type->value(); |
| 83 | common_params.tuner_mode = options.tuner_mode->value(); |
SiCong Li | 240b79d | 2019-09-24 15:50:34 +0100 | [diff] [blame] | 84 | return common_params; |
| 85 | } |
| 86 | } // namespace gemm_tuner |