blob: e93ef5b2b380193a03266f251c210fb353ed5927 [file] [log] [blame]
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +01001/*
Manuel Bottinib56c1752020-11-18 17:56:30 +00002 * Copyright (c) 2019-2021 Arm Limited.
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +01003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CLTUNER_TYPES_H
25#define ARM_COMPUTE_CLTUNER_TYPES_H
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010026
27#include "arm_compute/core/Error.h"
28#include "arm_compute/core/utils/misc/Utility.h"
Georgios Pinitas4c5469b2019-05-21 13:32:43 +010029
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010030#include <map>
31
32namespace arm_compute
33{
34/**< OpenCL tuner modes */
35enum 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 Bottinib56c1752020-11-18 17:56:30 +000042/**< OpenCL tuner tuning information */
43struct CLTuningInfo
44{
Manuel Bottinibe9f9f92021-01-25 15:07:17 +000045 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 */
Manuel Bottinib56c1752020-11-18 17:56:30 +000049};
50
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010051/** 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 */
57inline 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 */
88inline ::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 Spyrouf4643372019-11-29 16:17:13 +000096#endif /*ARM_COMPUTE_CLTUNER_TYPES_H */