blob: 30a3546821c103a29386b5927f124464ea70af4f [file] [log] [blame]
Georgios Pinitas12be7ab2018-07-03 12:06:23 +01001/*
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
30namespace arm_compute
31{
32arm_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
41 try
42 {
43 return data_types.at(arm_compute::utility::tolower(name));
44 }
45 catch(const std::out_of_range &)
46 {
47 throw std::invalid_argument(name);
48 }
49}
50
51arm_compute::DataLayout data_layout_from_name(const std::string &name)
52{
53 static const std::map<std::string, arm_compute::DataLayout> data_layouts =
54 {
55 { "nhwc", DataLayout::NHWC },
56 { "nchw", DataLayout::NCHW },
57 };
58
59 try
60 {
61 return data_layouts.at(arm_compute::utility::tolower(name));
62 }
63 catch(const std::out_of_range &)
64 {
65 throw std::invalid_argument(name);
66 }
67}
68namespace graph
69{
70Target target_from_name(const std::string &name)
71{
72 static const std::map<std::string, Target> targets =
73 {
74 { "neon", Target::NEON },
75 { "cl", Target::CL },
76 { "gles", Target::GC },
77 };
78
79 try
80 {
81 return targets.at(arm_compute::utility::tolower(name));
82 }
83 catch(const std::out_of_range &)
84 {
85 throw std::invalid_argument(name);
86 }
87}
88} // namespace graph
89} // namespace arm_compute