Compute Library
 22.05
TypeLoader.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 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  */
25 
27 
28 #include <map>
29 
30 namespace arm_compute
31 {
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 {
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  { "clvk", Target::CLVK },
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 
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 
106 {
107  static const std::map<std::string, DepthwiseConvolutionMethod> methods =
108  {
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
Arm® Neon™ capable target device.
DepthwiseConvolutionMethod depthwise_convolution_method_from_name(const std::string &name)
Converts a string to a strong types enumeration DepthwiseConvolutionMethod.
Definition: TypeLoader.cpp:105
ConvolutionMethod Convolution_method_from_name(const std::string &name)
Converts a string to a strong types enumeration ConvolutionMethod.
Definition: TypeLoader.cpp:80
CLVK capable target device.
Copyright (c) 2017-2022 Arm Limited.
std::string tolower(std::string string)
Convert string to lower case.
Definition: Utility.h:205
arm_compute::DataLayout data_layout_from_name(const std::string &name)
Converts a string to a strong types enumeration DataLayout.
Definition: TypeLoader.cpp:32
DepthwiseConvolutionMethod
Supported Depthwise Convolution layer methods.
Definition: Types.h:135
const char * name
Num samples, channels, height, width.
Target target_from_name(const std::string &name)
Converts a string to a strong types enumeration Target.
Definition: TypeLoader.cpp:56
Num samples, height, width, channels.
ConvolutionMethod
Supported Convolution layer methods.
Definition: Types.h:126
Default approach using internal heuristics.
Default approach using internal heuristics.
Optimized 3x3 direct depthwise convolution.
OpenCL capable target device.
DataLayout
[DataLayout enum definition]
Definition: Types.h:113