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 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 34 | static const std::map<std::string, arm_compute::DataLayout> data_layouts = { |
| 35 | {"nhwc", DataLayout::NHWC}, |
| 36 | {"nchw", DataLayout::NCHW}, |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 39 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 40 | try |
| 41 | { |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 42 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 43 | return data_layouts.at(arm_compute::utility::tolower(name)); |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 44 | |
| 45 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 46 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 47 | catch (const std::out_of_range &) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 48 | { |
| 49 | throw std::invalid_argument(name); |
| 50 | } |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 51 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 52 | } |
| 53 | namespace graph |
| 54 | { |
| 55 | Target target_from_name(const std::string &name) |
| 56 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 57 | static const std::map<std::string, Target> targets = { |
| 58 | {"neon", Target::NEON}, |
| 59 | {"cl", Target::CL}, |
| 60 | {"clvk", Target::CLVK}, |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 63 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 64 | try |
| 65 | { |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 66 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 67 | return targets.at(arm_compute::utility::tolower(name)); |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 68 | |
| 69 | #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 70 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 71 | catch (const std::out_of_range &) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 72 | { |
| 73 | throw std::invalid_argument(name); |
| 74 | } |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 75 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 76 | } |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 77 | |
| 78 | ConvolutionMethod Convolution_method_from_name(const std::string &name) |
| 79 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 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}, |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 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 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 95 | catch (const std::out_of_range &) |
John Kesapides | fb68ca1 | 2019-01-21 14:13:27 +0000 | [diff] [blame] | 96 | { |
| 97 | throw std::invalid_argument(name); |
| 98 | } |
| 99 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
| 100 | } |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 101 | |
| 102 | DepthwiseConvolutionMethod depthwise_convolution_method_from_name(const std::string &name) |
| 103 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 104 | static const std::map<std::string, DepthwiseConvolutionMethod> methods = { |
| 105 | {"default", DepthwiseConvolutionMethod::Default}, |
| 106 | {"optimized3x3", DepthwiseConvolutionMethod::Optimized3x3}, |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 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 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 117 | catch (const std::out_of_range &) |
John Kesapides | 8d94269 | 2019-02-26 14:52:12 +0000 | [diff] [blame] | 118 | { |
| 119 | throw std::invalid_argument(name); |
| 120 | } |
| 121 | #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */ |
| 122 | } |
| 123 | |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 124 | } // namespace graph |
| 125 | } // namespace arm_compute |