Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | 40efd53 | 2021-03-18 17:32:00 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 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 | { |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 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 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 40 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 41 | try |
| 42 | { |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 43 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 44 | return data_layouts.at(arm_compute::utility::tolower(name)); |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 45 | |
| 46 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 47 | } |
| 48 | catch(const std::out_of_range &) |
| 49 | { |
| 50 | throw std::invalid_argument(name); |
| 51 | } |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 52 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 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 }, |
Michalis Spyrou | 402740d | 2021-04-20 11:26:21 +0100 | [diff] [blame] | 62 | { "clvk", Target::CLVK }, |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 65 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 66 | try |
| 67 | { |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 68 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 69 | return targets.at(arm_compute::utility::tolower(name)); |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 70 | |
| 71 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 72 | } |
| 73 | catch(const std::out_of_range &) |
| 74 | { |
| 75 | throw std::invalid_argument(name); |
| 76 | } |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 77 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 78 | } |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 79 | |
| 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 | } |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 104 | |
| 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 }, |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 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 | |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 128 | } // namespace graph |
| 129 | } // namespace arm_compute |