blob: 5904e1a06f172773b4d77a9259d97e40f8bdd7d5 [file] [log] [blame]
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +01001/*
Gunes Bayir85cafff2023-12-18 13:29:31 +00002 * Copyright (c) 2018-2023 Arm Limited.
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +01003 *
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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010025
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010026#include "arm_compute/core/Log.h"
27
28#include <map>
29#include <regex>
30
31namespace
32{
Gunes Bayir85cafff2023-12-18 13:29:31 +000033
34arm_compute::GPUTarget get_fifth_gen_target(const std::string &version)
35{
36 if (version.find("G720") != std::string::npos)
37 {
38 return arm_compute::GPUTarget::G720;
39 }
40 else if (version.find("G620") != std::string::npos)
41 {
42 return arm_compute::GPUTarget::G620;
43 }
44 else
45 {
46 return arm_compute::GPUTarget::UNKNOWN;
47 }
48}
49
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010050arm_compute::GPUTarget get_valhall_target(const std::string &version)
51{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010052 if (version.find("G77") != std::string::npos)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010053 {
54 return arm_compute::GPUTarget::G77;
55 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010056 else if (version.find("G57") != std::string::npos)
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010057 {
58 return arm_compute::GPUTarget::G57;
59 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010060 if (version.find("G68") != std::string::npos)
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010061 {
62 return arm_compute::GPUTarget::G68;
63 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010064 if (version.find("G78AE") != std::string::npos)
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010065 {
66 return arm_compute::GPUTarget::G78AE;
67 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010068 if (version.find("G78") != std::string::npos)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010069 {
Georgios Pinitas4ffc42a2020-12-01 16:28:24 +000070 return arm_compute::GPUTarget::G78;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010071 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010072 else if (version.find("G710") != std::string::npos)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010073 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +000074 return arm_compute::GPUTarget::G710;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010075 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010076 else if (version.find("G610") != std::string::npos)
SiCong Lia3cf2412022-07-01 15:01:10 +010077 {
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010078 return arm_compute::GPUTarget::G610;
79 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010080 else if (version.find("G510") != std::string::npos)
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010081 {
82 return arm_compute::GPUTarget::G510;
83 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010084 else if (version.find("G310") != std::string::npos)
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010085 {
86 return arm_compute::GPUTarget::G310;
SiCong Lia3cf2412022-07-01 15:01:10 +010087 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010088 else if (version.find("G715") != std::string::npos)
Gunes Bayir4bfc70e2021-12-10 16:17:56 +000089 {
90 return arm_compute::GPUTarget::G715;
91 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010092 else if (version.find("G615") != std::string::npos)
Gunes Bayir4bfc70e2021-12-10 16:17:56 +000093 {
94 return arm_compute::GPUTarget::G615;
95 }
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010096 else
97 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +000098 return arm_compute::GPUTarget::UNKNOWN;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010099 }
100}
101
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100102arm_compute::GPUTarget get_bifrost_target(const std::string &version)
103{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100104 if (version.find("G71") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100105 {
106 return arm_compute::GPUTarget::G71;
107 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100108 else if (version.find("G72") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100109 {
110 return arm_compute::GPUTarget::G72;
111 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100112 else if (version.find("G51BIG") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100113 {
114 return arm_compute::GPUTarget::G51BIG;
115 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100116 else if (version.find("G51LIT") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100117 {
118 return arm_compute::GPUTarget::G51LIT;
119 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100120 else if (version.find("G51") != std::string::npos)
Georgios Pinitasa34286e2018-09-04 12:18:50 +0100121 {
Michalis Spyrouc95988a2019-07-17 13:24:52 +0100122 return arm_compute::GPUTarget::G51;
Georgios Pinitasa34286e2018-09-04 12:18:50 +0100123 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100124 else if (version.find("G52LIT") != std::string::npos)
Georgios Pinitasa34286e2018-09-04 12:18:50 +0100125 {
126 return arm_compute::GPUTarget::G52LIT;
127 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100128 else if (version.find("G52") != std::string::npos)
Michalis Spyrouc95988a2019-07-17 13:24:52 +0100129 {
130 return arm_compute::GPUTarget::G52;
131 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100132 else if (version.find("G76") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100133 {
Georgios Pinitasb03f7c52018-07-12 10:49:53 +0100134 return arm_compute::GPUTarget::G76;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100135 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100136 else if (version.find("G31") != std::string::npos)
Pablo Marquez Tellob1496e62021-06-25 14:49:37 +0100137 {
138 return arm_compute::GPUTarget::G31;
139 }
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100140 else
141 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100142 return arm_compute::GPUTarget::UNKNOWN;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100143 }
144}
145
146arm_compute::GPUTarget get_midgard_target(const std::string &version)
147{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100148 if (version.find("T600") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100149 {
150 return arm_compute::GPUTarget::T600;
151 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100152 else if (version.find("T700") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100153 {
154 return arm_compute::GPUTarget::T700;
155 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100156 else if (version.find("T800") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100157 {
158 return arm_compute::GPUTarget::T800;
159 }
160 else
161 {
162 return arm_compute::GPUTarget::MIDGARD;
163 }
164}
165} // namespace
166
167namespace arm_compute
168{
169const std::string &string_from_target(GPUTarget target)
170{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100171 static std::map<GPUTarget, const std::string> gpu_target_map = {
Gunes Bayir85cafff2023-12-18 13:29:31 +0000172 {GPUTarget::MIDGARD, "midgard"}, {GPUTarget::BIFROST, "bifrost"}, {GPUTarget::VALHALL, "valhall"},
173 {GPUTarget::FIFTHGEN, "fifthgen"},
174
175 {GPUTarget::T600, "t600"}, {GPUTarget::T700, "t700"}, {GPUTarget::T800, "t800"},
176 {GPUTarget::G71, "g71"}, {GPUTarget::G72, "g72"}, {GPUTarget::G51, "g51"},
177 {GPUTarget::G51BIG, "g51big"}, {GPUTarget::G51LIT, "g51lit"}, {GPUTarget::G31, "g31"},
178 {GPUTarget::G76, "g76"}, {GPUTarget::G52, "g52"}, {GPUTarget::G52LIT, "g52lit"},
179 {GPUTarget::G77, "g77"}, {GPUTarget::G57, "g57"}, {GPUTarget::G78, "g78"},
180 {GPUTarget::G68, "g68"}, {GPUTarget::G78AE, "g78ae"}, {GPUTarget::G710, "g710"},
181 {GPUTarget::G610, "g610"}, {GPUTarget::G510, "g510"}, {GPUTarget::G310, "g310"},
182 {GPUTarget::G715, "g715"}, {GPUTarget::G615, "g615"}, {GPUTarget::G720, "g720"},
183 {GPUTarget::G620, "g620"}};
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100184
185 return gpu_target_map[target];
186}
187
188GPUTarget get_target_from_name(const std::string &device_name)
189{
190 std::regex mali_regex(R"(Mali-(.*))");
191 std::smatch name_parts;
192 const bool found_mali = std::regex_search(device_name, name_parts, mali_regex);
193
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100194 if (!found_mali)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100195 {
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000196 ARM_COMPUTE_LOG_INFO_MSG_CORE("Can't find valid Arm® Mali™ GPU. Target is set to default.");
Vidhya Sudhan Loganathanbdff4912018-05-22 15:03:09 +0100197 return GPUTarget::MIDGARD;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100198 }
199
200 const char target = name_parts.str(1)[0];
201 const std::string &version = name_parts.str(1);
202
203 std::regex future_regex(R"(.*X)");
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100204 const bool is_future_gpu = std::regex_search(version, future_regex);
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100205
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100206 // Work-out gpu target
207 GPUTarget gpu_target;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100208 if (target == 'G' || is_future_gpu)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100209 {
Gunes Bayir85cafff2023-12-18 13:29:31 +0000210 // Check for Valhall, Bifrost or 5-th Gen
211 gpu_target = get_fifth_gen_target(version);
212 if (gpu_target == GPUTarget::UNKNOWN)
213 {
214 gpu_target = get_valhall_target(version);
215 }
216
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100217 if (gpu_target == GPUTarget::UNKNOWN)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100218 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +0000219 gpu_target = get_bifrost_target(version);
220 }
221
222 // Default GPUTarget
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100223 if (gpu_target == GPUTarget::UNKNOWN)
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +0000224 {
225 gpu_target = GPUTarget::VALHALL;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100226 }
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100227 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100228 else if (target == 'T')
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100229 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100230 gpu_target = get_midgard_target(version);
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100231 }
232 else
233 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100234 gpu_target = GPUTarget::UNKNOWN;
235 }
236
237 // Report in case of unknown target
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100238 if (gpu_target == GPUTarget::UNKNOWN)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100239 {
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000240 ARM_COMPUTE_LOG_INFO_MSG_CORE("Arm® Mali™ Mali GPU unknown. Target is set to the default one. (BIFROST)");
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100241 return GPUTarget::BIFROST;
242 }
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100243
244 return gpu_target;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100245}
246
247GPUTarget get_arch_from_target(GPUTarget target)
248{
249 return (target & GPUTarget::GPU_ARCH_MASK);
250}
251} // namespace arm_compute