Compute Library
 23.05
CLTunerTypes.h
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  */
24 #ifndef ARM_COMPUTE_CLTUNER_TYPES_H
25 #define ARM_COMPUTE_CLTUNER_TYPES_H
26 
27 #include "arm_compute/core/Error.h"
29 
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 
42 /**< OpenCL tuner tuning information */
44 {
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
48  the target platform. This OpenCL tuner extension is still in experimental phase */
49 };
50 
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
96 #endif /*ARM_COMPUTE_CLTUNER_TYPES_H */
Searches a subset of LWS configurations while tuning.
Copyright (c) 2017-2023 Arm Limited.
Searches a minimal subset of LWS configurations while tuning.
std::string tolower(std::string string)
Convert string to lower case.
Definition: Utility.h:206
const char * name
CLTunerMode
< OpenCL tuner modes
Definition: CLTunerTypes.h:35
CLTunerMode tuner_mode_from_name(const std::string &name)
Converts a string to a strong types enumeration CLTunerMode.
Definition: CLTunerTypes.h:57
Searches all possible LWS configurations while tuning.
inline ::std::istream & operator>>(::std::istream &stream, DataType &data_type)
Input Stream operator for DataType.
Definition: Utils.h:981