blob: e1248fbb6bdedad84a0096ac16ca2e931693f334 [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{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010034 static const std::map<std::string, arm_compute::DataLayout> data_layouts = {
35 {"nhwc", DataLayout::NHWC},
36 {"nchw", DataLayout::NCHW},
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010037 };
38
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000039#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010040 try
41 {
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000042#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010043 return data_layouts.at(arm_compute::utility::tolower(name));
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000044
45#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010046 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010047 catch (const std::out_of_range &)
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010048 {
49 throw std::invalid_argument(name);
50 }
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000051#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010052}
53namespace graph
54{
55Target target_from_name(const std::string &name)
56{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010057 static const std::map<std::string, Target> targets = {
58 {"neon", Target::NEON},
59 {"cl", Target::CL},
60 {"clvk", Target::CLVK},
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010061 };
62
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000063#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010064 try
65 {
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000066#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010067 return targets.at(arm_compute::utility::tolower(name));
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000068
69#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010070 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010071 catch (const std::out_of_range &)
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010072 {
73 throw std::invalid_argument(name);
74 }
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000075#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010076}
John Kesapidesfb68ca12019-01-21 14:13:27 +000077
78ConvolutionMethod Convolution_method_from_name(const std::string &name)
79{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010080 static const std::map<std::string, ConvolutionMethod> methods = {
81 {"default", ConvolutionMethod::Default},
82 {"direct", ConvolutionMethod::Direct},
83 {"gemm", ConvolutionMethod::GEMM},
84 {"winograd", ConvolutionMethod::Winograd},
John Kesapidesfb68ca12019-01-21 14:13:27 +000085 };
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 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010095 catch (const std::out_of_range &)
John Kesapidesfb68ca12019-01-21 14:13:27 +000096 {
97 throw std::invalid_argument(name);
98 }
99#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
100}
John Kesapides8d942692019-02-26 14:52:12 +0000101
102DepthwiseConvolutionMethod depthwise_convolution_method_from_name(const std::string &name)
103{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100104 static const std::map<std::string, DepthwiseConvolutionMethod> methods = {
105 {"default", DepthwiseConvolutionMethod::Default},
106 {"optimized3x3", DepthwiseConvolutionMethod::Optimized3x3},
John Kesapides8d942692019-02-26 14:52:12 +0000107 };
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 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100117 catch (const std::out_of_range &)
John Kesapides8d942692019-02-26 14:52:12 +0000118 {
119 throw std::invalid_argument(name);
120 }
121#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
122}
123
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100124} // namespace graph
125} // namespace arm_compute