Vidhya Sudhan Loganathan | 050471e | 2019-04-25 09:27:24 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2021 Arm Limited. |
Vidhya Sudhan Loganathan | 050471e | 2019-04-25 09:27:24 +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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CLTUNER_TYPES_H |
| 25 | #define ARM_COMPUTE_CLTUNER_TYPES_H |
Vidhya Sudhan Loganathan | 050471e | 2019-04-25 09:27:24 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/utils/misc/Utility.h" |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 29 | |
Vidhya Sudhan Loganathan | 050471e | 2019-04-25 09:27:24 +0100 | [diff] [blame] | 30 | #include <map> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | /**< OpenCL tuner modes */ |
| 35 | enum class CLTunerMode |
| 36 | { |
| 37 | EXHAUSTIVE, /**< Searches all possible LWS configurations while tuning */ |
| 38 | NORMAL, /**< Searches a subset of LWS configurations while tuning */ |
| 39 | RAPID /**< Searches a minimal subset of LWS configurations while tuning */ |
| 40 | }; |
| 41 | |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 42 | /**< OpenCL tuner tuning information */ |
| 43 | struct CLTuningInfo |
| 44 | { |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 45 | CLTunerMode tuner_mode = CLTunerMode::NORMAL; /**< Parameter to select the level (granularity) of the tuning */ |
| 46 | bool tune_wbsm = false; /**< Flag to tune the batches of work groups distributed to compute units. |
| 47 | Internally, the library will check if this feature is available on |
Gian Marco Iodice | f5aad51 | 2021-02-08 17:34:40 +0000 | [diff] [blame] | 48 | the target platform. This OpenCL tuner extension is still in experimental phase */ |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Vidhya Sudhan Loganathan | 050471e | 2019-04-25 09:27:24 +0100 | [diff] [blame] | 51 | /** Converts a string to a strong types enumeration @ref CLTunerMode |
| 52 | * |
| 53 | * @param[in] name String to convert |
| 54 | * |
| 55 | * @return Converted CLTunerMode enumeration |
| 56 | */ |
| 57 | inline CLTunerMode tuner_mode_from_name(const std::string &name) |
| 58 | { |
| 59 | static const std::map<std::string, CLTunerMode> tuner_modes = |
| 60 | { |
| 61 | { "exhaustive", CLTunerMode::EXHAUSTIVE }, |
| 62 | { "normal", CLTunerMode::NORMAL }, |
| 63 | { "rapid", CLTunerMode::RAPID }, |
| 64 | }; |
| 65 | |
| 66 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
| 67 | try |
| 68 | { |
| 69 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
| 70 | return tuner_modes.at(arm_compute::utility::tolower(name)); |
| 71 | |
| 72 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
| 73 | } |
| 74 | catch(const std::out_of_range &) |
| 75 | { |
| 76 | throw std::invalid_argument(name); |
| 77 | } |
| 78 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
| 79 | } |
| 80 | |
| 81 | /** Input Stream operator for @ref CLTunerMode |
| 82 | * |
| 83 | * @param[in] stream Stream to parse |
| 84 | * @param[out] tuner_mode Output tuner mode |
| 85 | * |
| 86 | * @return Updated stream |
| 87 | */ |
| 88 | inline ::std::istream &operator>>(::std::istream &stream, CLTunerMode &tuner_mode) |
| 89 | { |
| 90 | std::string value; |
| 91 | stream >> value; |
| 92 | tuner_mode = tuner_mode_from_name(value); |
| 93 | return stream; |
| 94 | } |
| 95 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 96 | #endif /*ARM_COMPUTE_CLTUNER_TYPES_H */ |