• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-2020 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 #include "arm_compute/graph/TypeLoader.h"
25 
26 #include "arm_compute/core/utils/misc/Utility.h"
27 
28 #include <map>
29 
30 namespace arm_compute
31 {
data_layout_from_name(const std::string & name)32 arm_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 
40 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
41     try
42     {
43 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
44         return data_layouts.at(arm_compute::utility::tolower(name));
45 
46 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
47     }
48     catch(const std::out_of_range &)
49     {
50         throw std::invalid_argument(name);
51     }
52 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
53 }
54 namespace graph
55 {
target_from_name(const std::string & name)56 Target 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 },
62         { "gc", Target::GC },
63     };
64 
65 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
66     try
67     {
68 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
69         return targets.at(arm_compute::utility::tolower(name));
70 
71 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
72     }
73     catch(const std::out_of_range &)
74     {
75         throw std::invalid_argument(name);
76     }
77 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
78 }
79 
Convolution_method_from_name(const std::string & name)80 ConvolutionMethod 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 }
104 
depthwise_convolution_method_from_name(const std::string & name)105 DepthwiseConvolutionMethod depthwise_convolution_method_from_name(const std::string &name)
106 {
107     static const std::map<std::string, DepthwiseConvolutionMethod> methods =
108     {
109         { "default", DepthwiseConvolutionMethod::Default },
110         { "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 
128 } // namespace graph
129 } // namespace arm_compute
130