blob: 2d1a13cb335b05bedfaeb32c33fdfab8fde04809 [file] [log] [blame]
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +01001/*
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +00002 * Copyright (c) 2018-2022 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{
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010033arm_compute::GPUTarget get_valhall_target(const std::string &version)
34{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010035 if (version.find("G77") != std::string::npos)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010036 {
37 return arm_compute::GPUTarget::G77;
38 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010039 else if (version.find("G57") != std::string::npos)
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010040 {
41 return arm_compute::GPUTarget::G57;
42 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010043 if (version.find("G68") != std::string::npos)
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010044 {
45 return arm_compute::GPUTarget::G68;
46 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010047 if (version.find("G78AE") != std::string::npos)
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010048 {
49 return arm_compute::GPUTarget::G78AE;
50 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010051 if (version.find("G78") != std::string::npos)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010052 {
Georgios Pinitas4ffc42a2020-12-01 16:28:24 +000053 return arm_compute::GPUTarget::G78;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010054 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010055 else if (version.find("G710") != std::string::npos)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010056 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +000057 return arm_compute::GPUTarget::G710;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010058 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010059 else if (version.find("G610") != std::string::npos)
SiCong Lia3cf2412022-07-01 15:01:10 +010060 {
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010061 return arm_compute::GPUTarget::G610;
62 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010063 else if (version.find("G510") != std::string::npos)
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010064 {
65 return arm_compute::GPUTarget::G510;
66 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010067 else if (version.find("G310") != std::string::npos)
Gian Marco Iodice3c4d0852022-07-11 12:09:45 +010068 {
69 return arm_compute::GPUTarget::G310;
SiCong Lia3cf2412022-07-01 15:01:10 +010070 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010071 else if (version.find("G715") != std::string::npos)
Gunes Bayir4bfc70e2021-12-10 16:17:56 +000072 {
73 return arm_compute::GPUTarget::G715;
74 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010075 else if (version.find("G615") != std::string::npos)
Gunes Bayir4bfc70e2021-12-10 16:17:56 +000076 {
77 return arm_compute::GPUTarget::G615;
78 }
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010079 else
80 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +000081 return arm_compute::GPUTarget::UNKNOWN;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010082 }
83}
84
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010085arm_compute::GPUTarget get_bifrost_target(const std::string &version)
86{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010087 if (version.find("G71") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010088 {
89 return arm_compute::GPUTarget::G71;
90 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010091 else if (version.find("G72") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010092 {
93 return arm_compute::GPUTarget::G72;
94 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010095 else if (version.find("G51BIG") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010096 {
97 return arm_compute::GPUTarget::G51BIG;
98 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010099 else if (version.find("G51LIT") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100100 {
101 return arm_compute::GPUTarget::G51LIT;
102 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100103 else if (version.find("G51") != std::string::npos)
Georgios Pinitasa34286e2018-09-04 12:18:50 +0100104 {
Michalis Spyrouc95988a2019-07-17 13:24:52 +0100105 return arm_compute::GPUTarget::G51;
Georgios Pinitasa34286e2018-09-04 12:18:50 +0100106 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100107 else if (version.find("G52LIT") != std::string::npos)
Georgios Pinitasa34286e2018-09-04 12:18:50 +0100108 {
109 return arm_compute::GPUTarget::G52LIT;
110 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100111 else if (version.find("G52") != std::string::npos)
Michalis Spyrouc95988a2019-07-17 13:24:52 +0100112 {
113 return arm_compute::GPUTarget::G52;
114 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100115 else if (version.find("G76") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100116 {
Georgios Pinitasb03f7c52018-07-12 10:49:53 +0100117 return arm_compute::GPUTarget::G76;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100118 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100119 else if (version.find("G31") != std::string::npos)
Pablo Marquez Tellob1496e62021-06-25 14:49:37 +0100120 {
121 return arm_compute::GPUTarget::G31;
122 }
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100123 else
124 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100125 return arm_compute::GPUTarget::UNKNOWN;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100126 }
127}
128
129arm_compute::GPUTarget get_midgard_target(const std::string &version)
130{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100131 if (version.find("T600") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100132 {
133 return arm_compute::GPUTarget::T600;
134 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100135 else if (version.find("T700") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100136 {
137 return arm_compute::GPUTarget::T700;
138 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100139 else if (version.find("T800") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100140 {
141 return arm_compute::GPUTarget::T800;
142 }
143 else
144 {
145 return arm_compute::GPUTarget::MIDGARD;
146 }
147}
148} // namespace
149
150namespace arm_compute
151{
152const std::string &string_from_target(GPUTarget target)
153{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100154 static std::map<GPUTarget, const std::string> gpu_target_map = {
155 {GPUTarget::MIDGARD, "midgard"}, {GPUTarget::BIFROST, "bifrost"}, {GPUTarget::VALHALL, "valhall"},
156 {GPUTarget::T600, "t600"}, {GPUTarget::T700, "t700"}, {GPUTarget::T800, "t800"},
157 {GPUTarget::G71, "g71"}, {GPUTarget::G72, "g72"}, {GPUTarget::G51, "g51"},
158 {GPUTarget::G51BIG, "g51big"}, {GPUTarget::G51LIT, "g51lit"}, {GPUTarget::G31, "g31"},
159 {GPUTarget::G76, "g76"}, {GPUTarget::G52, "g52"}, {GPUTarget::G52LIT, "g52lit"},
160 {GPUTarget::G77, "g77"}, {GPUTarget::G57, "g57"}, {GPUTarget::G78, "g78"},
161 {GPUTarget::G68, "g68"}, {GPUTarget::G78AE, "g78ae"}, {GPUTarget::G710, "g710"},
162 {GPUTarget::G610, "g610"}, {GPUTarget::G510, "g510"}, {GPUTarget::G310, "g310"},
163 {GPUTarget::G715, "g715"}, {GPUTarget::G615, "g615"},
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100164 };
165
166 return gpu_target_map[target];
167}
168
169GPUTarget get_target_from_name(const std::string &device_name)
170{
171 std::regex mali_regex(R"(Mali-(.*))");
172 std::smatch name_parts;
173 const bool found_mali = std::regex_search(device_name, name_parts, mali_regex);
174
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100175 if (!found_mali)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100176 {
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000177 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 +0100178 return GPUTarget::MIDGARD;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100179 }
180
181 const char target = name_parts.str(1)[0];
182 const std::string &version = name_parts.str(1);
183
184 std::regex future_regex(R"(.*X)");
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100185 const bool is_future_gpu = std::regex_search(version, future_regex);
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100186
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100187 // Work-out gpu target
188 GPUTarget gpu_target;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100189 if (target == 'G' || is_future_gpu)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100190 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +0000191 // Check for Valhall or Bifrost
192 gpu_target = get_valhall_target(version);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100193 if (gpu_target == GPUTarget::UNKNOWN)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100194 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +0000195 gpu_target = get_bifrost_target(version);
196 }
197
198 // Default GPUTarget
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100199 if (gpu_target == GPUTarget::UNKNOWN)
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +0000200 {
201 gpu_target = GPUTarget::VALHALL;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100202 }
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100203 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100204 else if (target == 'T')
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100205 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100206 gpu_target = get_midgard_target(version);
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100207 }
208 else
209 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100210 gpu_target = GPUTarget::UNKNOWN;
211 }
212
213 // Report in case of unknown target
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100214 if (gpu_target == GPUTarget::UNKNOWN)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100215 {
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000216 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 +0100217 return GPUTarget::BIFROST;
218 }
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100219
220 return gpu_target;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100221}
222
223GPUTarget get_arch_from_target(GPUTarget target)
224{
225 return (target & GPUTarget::GPU_ARCH_MASK);
226}
227} // namespace arm_compute