Compute Library
 23.11
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  {"nhwc", DataLayout::NHWC},
36  {"nchw", DataLayout::NCHW},
37  };
38 
39 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
40  try
41  {
42 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
43  return data_layouts.at(arm_compute::utility::tolower(name));
44 
45 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
46  }
47  catch (const std::out_of_range &)
48  {
49  throw std::invalid_argument(name);
50  }
51 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
52 }
53 namespace graph
54 {
55 Target target_from_name(const std::string &name)
56 {
57  static const std::map<std::string, Target> targets = {
58  {"neon", Target::NEON},
59  {"cl", Target::CL},
60  {"clvk", Target::CLVK},
61  };
62 
63 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
64  try
65  {
66 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
67  return targets.at(arm_compute::utility::tolower(name));
68 
69 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
70  }
71  catch (const std::out_of_range &)
72  {
73  throw std::invalid_argument(name);
74  }
75 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
76 }
77 
79 {
80  static const std::map<std::string, ConvolutionMethod> methods = {
81  {"default", ConvolutionMethod::Default},
82  {"direct", ConvolutionMethod::Direct},
83  {"gemm", ConvolutionMethod::GEMM},
84  {"winograd", ConvolutionMethod::Winograd},
85  };
86 
87 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
88  try
89  {
90 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
91  return methods.at(arm_compute::utility::tolower(name));
92 
93 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
94  }
95  catch (const std::out_of_range &)
96  {
97  throw std::invalid_argument(name);
98  }
99 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
100 }
101 
103 {
104  static const std::map<std::string, DepthwiseConvolutionMethod> methods = {
107  };
108 
109 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
110  try
111  {
112 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
113  return methods.at(arm_compute::utility::tolower(name));
114 
115 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
116  }
117  catch (const std::out_of_range &)
118  {
119  throw std::invalid_argument(name);
120  }
121 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
122 }
123 
124 } // namespace graph
125 } // namespace arm_compute
arm_compute::DataLayout::NCHW
@ NCHW
Num samples, channels, height, width.
arm_compute::graph::ConvolutionMethod::Default
@ Default
Default approach using internal heuristics.
arm_compute::graph::depthwise_convolution_method_from_name
DepthwiseConvolutionMethod depthwise_convolution_method_from_name(const std::string &name)
Converts a string to a strong types enumeration DepthwiseConvolutionMethod.
Definition: TypeLoader.cpp:102
arm_compute::utility::tolower
std::string tolower(std::string string)
Convert string to lower case.
Definition: Utility.h:204
arm_compute::graph::Target::CL
@ CL
OpenCL capable target device.
arm_compute::DataLayout
DataLayout
[DataLayout enum definition]
Definition: CoreTypes.h:110
arm_compute::graph::ConvolutionMethod::Direct
@ Direct
Deep direct convolution.
arm_compute::DataLayout::NHWC
@ NHWC
Num samples, height, width, channels.
arm_compute::graph::Target::NEON
@ NEON
Arm® Neon™ capable target device.
arm_compute::graph::Target::CLVK
@ CLVK
CLVK capable target device.
arm_compute::graph::target_from_name
Target target_from_name(const std::string &name)
Converts a string to a strong types enumeration Target.
Definition: TypeLoader.cpp:55
arm_compute::graph::Target
Target
Definition: Types.h:104
Utility.h
arm_compute::data_layout_from_name
arm_compute::DataLayout data_layout_from_name(const std::string &name)
Converts a string to a strong types enumeration DataLayout.
Definition: TypeLoader.cpp:32
name
const char * name
Definition: NEBatchNormalizationLayerKernel.cpp:66
TypeLoader.h
arm_compute::graph::ConvolutionMethod::GEMM
@ GEMM
GEMM based convolution.
arm_compute::graph::ConvolutionMethod
ConvolutionMethod
Supported Convolution layer methods.
Definition: Types.h:130
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::graph::DepthwiseConvolutionMethod::Optimized3x3
@ Optimized3x3
Optimized 3x3 direct depthwise convolution.
arm_compute::graph::DepthwiseConvolutionMethod
DepthwiseConvolutionMethod
Supported Depthwise Convolution layer methods.
Definition: Types.h:139
arm_compute::graph::DepthwiseConvolutionMethod::Default
@ Default
Default approach using internal heuristics.
arm_compute::graph::ConvolutionMethod::Winograd
@ Winograd
Winograd based convolution.
arm_compute::graph::Convolution_method_from_name
ConvolutionMethod Convolution_method_from_name(const std::string &name)
Converts a string to a strong types enumeration ConvolutionMethod.
Definition: TypeLoader.cpp:78