blob: 81a405b9614d84dc8e0b71acd6daef7c60d5236e [file] [log] [blame]
Georgios Pinitas12be7ab2018-07-03 12:06:23 +01001/*
John Kesapidesfb68ca12019-01-21 14:13:27 +00002 * Copyright (c) 2018-2019 ARM Limited.
Georgios Pinitas12be7ab2018-07-03 12:06:23 +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
John Kesapidesfb68ca12019-01-21 14:13:27 +000020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010021 * 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}
John Kesapidesfb68ca12019-01-21 14:13:27 +0000103
104ConvolutionMethod Convolution_method_from_name(const std::string &name)
105{
106 static const std::map<std::string, ConvolutionMethod> methods =
107 {
108 { "default", ConvolutionMethod::Default },
109 { "direct", ConvolutionMethod::Direct },
110 { "gemm", ConvolutionMethod::GEMM },
111 { "winograd", ConvolutionMethod::Winograd },
112 };
113
114#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
115 try
116 {
117#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
118 return methods.at(arm_compute::utility::tolower(name));
119
120#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
121 }
122 catch(const std::out_of_range &)
123 {
124 throw std::invalid_argument(name);
125 }
126#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
127}
John Kesapides8d942692019-02-26 14:52:12 +0000128
129DepthwiseConvolutionMethod depthwise_convolution_method_from_name(const std::string &name)
130{
131 static const std::map<std::string, DepthwiseConvolutionMethod> methods =
132 {
133 { "default", DepthwiseConvolutionMethod::Default },
John Kesapides8d942692019-02-26 14:52:12 +0000134 { "optimized3x3", DepthwiseConvolutionMethod::Optimized3x3 },
135 };
136
137#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
138 try
139 {
140#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
141 return methods.at(arm_compute::utility::tolower(name));
142
143#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
144 }
145 catch(const std::out_of_range &)
146 {
147 throw std::invalid_argument(name);
148 }
149#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
150}
151
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100152} // namespace graph
153} // namespace arm_compute