blob: 575d858589bc8e27d254cf7ee3608aafc52792c6 [file] [log] [blame]
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +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 OTHERWISE, 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/core/GPUTarget.h"
25#include "arm_compute/core/Log.h"
26
27#include <map>
28#include <regex>
29
30namespace
31{
32arm_compute::GPUTarget get_bifrost_target(const std::string &version)
33{
34 if(version == "G71")
35 {
36 return arm_compute::GPUTarget::G71;
37 }
38 else if(version == "G72")
39 {
40 return arm_compute::GPUTarget::G72;
41 }
42 else if(version == "G51")
43 {
44 return arm_compute::GPUTarget::G51;
45 }
46 else if(version == "G51BIG")
47 {
48 return arm_compute::GPUTarget::G51BIG;
49 }
50 else if(version == "G51LIT")
51 {
52 return arm_compute::GPUTarget::G51LIT;
53 }
54 else if(version == "TNOX")
55 {
56 return arm_compute::GPUTarget::TNOX;
57 }
58 else if(version == "TTRX")
59 {
60 return arm_compute::GPUTarget::TTRX;
61 }
62 else if(version == "TBOX")
63 {
64 return arm_compute::GPUTarget::TBOX;
65 }
66 else
67 {
68 return arm_compute::GPUTarget::BIFROST;
69 }
70}
71
72arm_compute::GPUTarget get_midgard_target(const std::string &version)
73{
74 if(version == "T600")
75 {
76 return arm_compute::GPUTarget::T600;
77 }
78 else if(version == "T700")
79 {
80 return arm_compute::GPUTarget::T700;
81 }
82 else if(version == "T800")
83 {
84 return arm_compute::GPUTarget::T800;
85 }
86 else
87 {
88 return arm_compute::GPUTarget::MIDGARD;
89 }
90}
91} // namespace
92
93namespace arm_compute
94{
95const std::string &string_from_target(GPUTarget target)
96{
97 static std::map<GPUTarget, const std::string> gpu_target_map =
98 {
99 { GPUTarget::MIDGARD, "midgard" },
100 { GPUTarget::BIFROST, "bifrost" },
101 { GPUTarget::T600, "t600" },
102 { GPUTarget::T700, "t700" },
103 { GPUTarget::T800, "t800" },
104 { GPUTarget::G71, "g71" },
105 { GPUTarget::G72, "g72" },
106 { GPUTarget::G51, "g51" },
107 { GPUTarget::G51BIG, "g51big" },
108 { GPUTarget::G51LIT, "g51lit" },
109 { GPUTarget::TNOX, "tnox" },
110 { GPUTarget::TTRX, "ttrx" },
111 { GPUTarget::TBOX, "tbox" }
112 };
113
114 return gpu_target_map[target];
115}
116
117GPUTarget get_target_from_name(const std::string &device_name)
118{
119 std::regex mali_regex(R"(Mali-(.*))");
120 std::smatch name_parts;
121 const bool found_mali = std::regex_search(device_name, name_parts, mali_regex);
122
123 if(!found_mali)
124 {
125 ARM_COMPUTE_LOG_INFO_MSG_CORE("Can't find valid Mali GPU. Target is set to UNKNOWN.");
126 return GPUTarget::UNKNOWN;
127 }
128
129 const char target = name_parts.str(1)[0];
130 const std::string &version = name_parts.str(1);
131
132 std::regex future_regex(R"(.*X)");
133 const bool is_future_bifrost = std::regex_search(version, future_regex);
134
135 if(target == 'G' || is_future_bifrost)
136 {
137 return get_bifrost_target(version);
138 }
139 else if(target == 'T')
140 {
141 return get_midgard_target(version);
142 }
143 else
144 {
145 ARM_COMPUTE_LOG_INFO_MSG_CORE("Mali GPU unknown. Target is set to the default one. (BIFROST)");
146 return GPUTarget::BIFROST;
147 }
148}
149
150GPUTarget get_arch_from_target(GPUTarget target)
151{
152 return (target & GPUTarget::GPU_ARCH_MASK);
153}
154} // namespace arm_compute