1 /*
2 * Copyright (c) 2019 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"
28 #include "arm_compute/core/utils/misc/Utility.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 /** Converts a string to a strong types enumeration @ref CLTunerMode
43 *
44 * @param[in] name String to convert
45 *
46 * @return Converted CLTunerMode enumeration
47 */
tuner_mode_from_name(const std::string & name)48 inline CLTunerMode tuner_mode_from_name(const std::string &name)
49 {
50 static const std::map<std::string, CLTunerMode> tuner_modes =
51 {
52 { "exhaustive", CLTunerMode::EXHAUSTIVE },
53 { "normal", CLTunerMode::NORMAL },
54 { "rapid", CLTunerMode::RAPID },
55 };
56
57 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
58 try
59 {
60 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
61 return tuner_modes.at(arm_compute::utility::tolower(name));
62
63 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
64 }
65 catch(const std::out_of_range &)
66 {
67 throw std::invalid_argument(name);
68 }
69 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
70 }
71
72 /** Input Stream operator for @ref CLTunerMode
73 *
74 * @param[in] stream Stream to parse
75 * @param[out] tuner_mode Output tuner mode
76 *
77 * @return Updated stream
78 */
79 inline ::std::istream &operator>>(::std::istream &stream, CLTunerMode &tuner_mode)
80 {
81 std::string value;
82 stream >> value;
83 tuner_mode = tuner_mode_from_name(value);
84 return stream;
85 }
86 } // namespace arm_compute
87 #endif /*ARM_COMPUTE_CLTUNER_TYPES_H */
88