Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 1 | /* |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 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 |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 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 | { |
| 32 | arm_compute::DataType data_type_from_name(const std::string &name) |
| 33 | { |
| 34 | static const std::map<std::string, arm_compute::DataType> data_types = |
| 35 | { |
| 36 | { "f16", DataType::F16 }, |
| 37 | { "f32", DataType::F32 }, |
| 38 | { "qasymm8", DataType::QASYMM8 }, |
| 39 | }; |
| 40 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 41 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 42 | try |
| 43 | { |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 44 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 45 | return data_types.at(arm_compute::utility::tolower(name)); |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 46 | |
| 47 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 48 | } |
| 49 | catch(const std::out_of_range &) |
| 50 | { |
| 51 | throw std::invalid_argument(name); |
| 52 | } |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 53 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | arm_compute::DataLayout data_layout_from_name(const std::string &name) |
| 57 | { |
| 58 | static const std::map<std::string, arm_compute::DataLayout> data_layouts = |
| 59 | { |
| 60 | { "nhwc", DataLayout::NHWC }, |
| 61 | { "nchw", DataLayout::NCHW }, |
| 62 | }; |
| 63 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 64 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 65 | try |
| 66 | { |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 67 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 68 | return data_layouts.at(arm_compute::utility::tolower(name)); |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 69 | |
| 70 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 71 | } |
| 72 | catch(const std::out_of_range &) |
| 73 | { |
| 74 | throw std::invalid_argument(name); |
| 75 | } |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 76 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 77 | } |
| 78 | namespace graph |
| 79 | { |
| 80 | Target target_from_name(const std::string &name) |
| 81 | { |
| 82 | static const std::map<std::string, Target> targets = |
| 83 | { |
| 84 | { "neon", Target::NEON }, |
| 85 | { "cl", Target::CL }, |
Georgios Pinitas | 1d7cbb9 | 2018-12-10 13:55:01 +0000 | [diff] [blame] | 86 | { "gc", Target::GC }, |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 89 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 90 | try |
| 91 | { |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 92 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 93 | return targets.at(arm_compute::utility::tolower(name)); |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 94 | |
| 95 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 96 | } |
| 97 | catch(const std::out_of_range &) |
| 98 | { |
| 99 | throw std::invalid_argument(name); |
| 100 | } |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 101 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 102 | } |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 103 | |
| 104 | ConvolutionMethod Convolution_method_from_name(const std::string &name) |
| 105 | { |
| 106 | static const std::map<std::string, ConvolutionMethod> methods = |
| 107 | { |
| 108 | { "default", ConvolutionMethod::Default }, |
| 109 | { "direct", ConvolutionMethod::Direct }, |
| 110 | { "gemm", ConvolutionMethod::GEMM }, |
| 111 | { "winograd", ConvolutionMethod::Winograd }, |
| 112 | }; |
| 113 | |
| 114 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
| 115 | try |
| 116 | { |
| 117 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
| 118 | return methods.at(arm_compute::utility::tolower(name)); |
| 119 | |
| 120 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
| 121 | } |
| 122 | catch(const std::out_of_range &) |
| 123 | { |
| 124 | throw std::invalid_argument(name); |
| 125 | } |
| 126 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
| 127 | } |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 128 | |
| 129 | DepthwiseConvolutionMethod depthwise_convolution_method_from_name(const std::string &name) |
| 130 | { |
| 131 | static const std::map<std::string, DepthwiseConvolutionMethod> methods = |
| 132 | { |
| 133 | { "default", DepthwiseConvolutionMethod::Default }, |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 134 | { "optimized3x3", DepthwiseConvolutionMethod::Optimized3x3 }, |
| 135 | }; |
| 136 | |
| 137 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
| 138 | try |
| 139 | { |
| 140 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
| 141 | return methods.at(arm_compute::utility::tolower(name)); |
| 142 | |
| 143 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
| 144 | } |
| 145 | catch(const std::out_of_range &) |
| 146 | { |
| 147 | throw std::invalid_argument(name); |
| 148 | } |
| 149 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
| 150 | } |
| 151 | |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 152 | } // namespace graph |
| 153 | } // namespace arm_compute |