blob: 7d13b6d3fa44d29f4d32fa1b6cf45c0659999b7e [file] [log] [blame]
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +01001/*
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#include <map>
30
31namespace arm_compute
32{
33/**< OpenCL tuner modes */
34enum class CLTunerMode
35{
36 EXHAUSTIVE, /**< Searches all possible LWS configurations while tuning */
37 NORMAL, /**< Searches a subset of LWS configurations while tuning */
38 RAPID /**< Searches a minimal subset of LWS configurations while tuning */
39};
40
41/** Converts a string to a strong types enumeration @ref CLTunerMode
42 *
43 * @param[in] name String to convert
44 *
45 * @return Converted CLTunerMode enumeration
46 */
47inline CLTunerMode tuner_mode_from_name(const std::string &name)
48{
49 static const std::map<std::string, CLTunerMode> tuner_modes =
50 {
51 { "exhaustive", CLTunerMode::EXHAUSTIVE },
52 { "normal", CLTunerMode::NORMAL },
53 { "rapid", CLTunerMode::RAPID },
54 };
55
56#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
57 try
58 {
59#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
60 return tuner_modes.at(arm_compute::utility::tolower(name));
61
62#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
63 }
64 catch(const std::out_of_range &)
65 {
66 throw std::invalid_argument(name);
67 }
68#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
69}
70
71/** Input Stream operator for @ref CLTunerMode
72 *
73 * @param[in] stream Stream to parse
74 * @param[out] tuner_mode Output tuner mode
75 *
76 * @return Updated stream
77 */
78inline ::std::istream &operator>>(::std::istream &stream, CLTunerMode &tuner_mode)
79{
80 std::string value;
81 stream >> value;
82 tuner_mode = tuner_mode_from_name(value);
83 return stream;
84}
85} // namespace arm_compute
86#endif /*__ARM_COMPUTE_CLTUNER_TYPES_H__ */