blob: 3c51289dbac8e60d219e0eaf87285929011aac55 [file] [log] [blame]
Georgios Pinitas12be7ab2018-07-03 12:06:23 +01001/*
Michele Di Giorgio40efd532021-03-18 17:32:00 +00002 * Copyright (c) 2018-2021 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{
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010032arm_compute::DataLayout data_layout_from_name(const std::string &name)
33{
34 static const std::map<std::string, arm_compute::DataLayout> data_layouts =
35 {
36 { "nhwc", DataLayout::NHWC },
37 { "nchw", DataLayout::NCHW },
38 };
39
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000040#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010041 try
42 {
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000043#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010044 return data_layouts.at(arm_compute::utility::tolower(name));
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000045
46#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010047 }
48 catch(const std::out_of_range &)
49 {
50 throw std::invalid_argument(name);
51 }
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000052#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010053}
54namespace graph
55{
56Target target_from_name(const std::string &name)
57{
58 static const std::map<std::string, Target> targets =
59 {
60 { "neon", Target::NEON },
61 { "cl", Target::CL },
Michalis Spyrou402740d2021-04-20 11:26:21 +010062 { "clvk", Target::CLVK },
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010063 };
64
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000065#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010066 try
67 {
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000068#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010069 return targets.at(arm_compute::utility::tolower(name));
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000070
71#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010072 }
73 catch(const std::out_of_range &)
74 {
75 throw std::invalid_argument(name);
76 }
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000077#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010078}
John Kesapidesfb68ca12019-01-21 14:13:27 +000079
80ConvolutionMethod Convolution_method_from_name(const std::string &name)
81{
82 static const std::map<std::string, ConvolutionMethod> methods =
83 {
84 { "default", ConvolutionMethod::Default },
85 { "direct", ConvolutionMethod::Direct },
86 { "gemm", ConvolutionMethod::GEMM },
87 { "winograd", ConvolutionMethod::Winograd },
88 };
89
90#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
91 try
92 {
93#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
94 return methods.at(arm_compute::utility::tolower(name));
95
96#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
97 }
98 catch(const std::out_of_range &)
99 {
100 throw std::invalid_argument(name);
101 }
102#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
103}
John Kesapides8d942692019-02-26 14:52:12 +0000104
105DepthwiseConvolutionMethod depthwise_convolution_method_from_name(const std::string &name)
106{
107 static const std::map<std::string, DepthwiseConvolutionMethod> methods =
108 {
109 { "default", DepthwiseConvolutionMethod::Default },
John Kesapides8d942692019-02-26 14:52:12 +0000110 { "optimized3x3", DepthwiseConvolutionMethod::Optimized3x3 },
111 };
112
113#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
114 try
115 {
116#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
117 return methods.at(arm_compute::utility::tolower(name));
118
119#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
120 }
121 catch(const std::out_of_range &)
122 {
123 throw std::invalid_argument(name);
124 }
125#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
126}
127
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100128} // namespace graph
129} // namespace arm_compute