blob: e0ba7e2d50169f0d9135e5620471c189f7d04f44 [file] [log] [blame]
Georgios Pinitas12be7ab2018-07-03 12:06:23 +01001/*
2 * Copyright (c) 2018 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 OTHERWNISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/graph/TypeLoader.h"
25
26#include "arm_compute/core/utils/misc/Utility.h"
27
28#include <map>
29
30namespace arm_compute
31{
32arm_compute::DataType data_type_from_name(const std::string &name)
33{
34 static const std::map<std::string, arm_compute::DataType> data_types =
35 {
36 { "f16", DataType::F16 },
37 { "f32", DataType::F32 },
38 { "qasymm8", DataType::QASYMM8 },
39 };
40
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000041#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010042 try
43 {
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000044#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010045 return data_types.at(arm_compute::utility::tolower(name));
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000046
47#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010048 }
49 catch(const std::out_of_range &)
50 {
51 throw std::invalid_argument(name);
52 }
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000053#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010054}
55
56arm_compute::DataLayout data_layout_from_name(const std::string &name)
57{
58 static const std::map<std::string, arm_compute::DataLayout> data_layouts =
59 {
60 { "nhwc", DataLayout::NHWC },
61 { "nchw", DataLayout::NCHW },
62 };
63
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000064#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010065 try
66 {
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000067#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010068 return data_layouts.at(arm_compute::utility::tolower(name));
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000069
70#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010071 }
72 catch(const std::out_of_range &)
73 {
74 throw std::invalid_argument(name);
75 }
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000076#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010077}
78namespace graph
79{
80Target target_from_name(const std::string &name)
81{
82 static const std::map<std::string, Target> targets =
83 {
84 { "neon", Target::NEON },
85 { "cl", Target::CL },
Georgios Pinitas1d7cbb92018-12-10 13:55:01 +000086 { "gc", Target::GC },
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010087 };
88
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000089#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010090 try
91 {
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000092#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010093 return targets.at(arm_compute::utility::tolower(name));
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000094
95#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010096 }
97 catch(const std::out_of_range &)
98 {
99 throw std::invalid_argument(name);
100 }
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000101#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100102}
103} // namespace graph
104} // namespace arm_compute