Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 OTHERWNISE, ARISING FROM, |
| 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 | } |
| 103 | } // namespace graph |
| 104 | } // namespace arm_compute |