blob: 625c0145dfa55b6fdf82b8aae498250829b184c9 [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"
25#include "arm_compute/core/Log.h"
26
27#include <map>
28#include <regex>
29
30namespace
31{
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010032arm_compute::GPUTarget get_valhall_target(const std::string &version)
33{
Michalis Spyrouc95988a2019-07-17 13:24:52 +010034 if(version.find("G77") != std::string::npos)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010035 {
36 return arm_compute::GPUTarget::G77;
37 }
Georgios Pinitas4ffc42a2020-12-01 16:28:24 +000038 if(version.find("G78") != std::string::npos)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010039 {
Georgios Pinitas4ffc42a2020-12-01 16:28:24 +000040 return arm_compute::GPUTarget::G78;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010041 }
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +000042 else if(version.find("G710") != std::string::npos)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010043 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +000044 return arm_compute::GPUTarget::G710;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010045 }
46 else
47 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +000048 return arm_compute::GPUTarget::UNKNOWN;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010049 }
50}
51
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010052arm_compute::GPUTarget get_bifrost_target(const std::string &version)
53{
Michalis Spyrouc95988a2019-07-17 13:24:52 +010054 if(version.find("G71") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010055 {
56 return arm_compute::GPUTarget::G71;
57 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +010058 else if(version.find("G72") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010059 {
60 return arm_compute::GPUTarget::G72;
61 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +010062 else if(version.find("G51BIG") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010063 {
64 return arm_compute::GPUTarget::G51BIG;
65 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +010066 else if(version.find("G51LIT") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010067 {
68 return arm_compute::GPUTarget::G51LIT;
69 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +010070 else if(version.find("G51") != std::string::npos)
Georgios Pinitasa34286e2018-09-04 12:18:50 +010071 {
Michalis Spyrouc95988a2019-07-17 13:24:52 +010072 return arm_compute::GPUTarget::G51;
Georgios Pinitasa34286e2018-09-04 12:18:50 +010073 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +010074 else if(version.find("G52LIT") != std::string::npos)
Georgios Pinitasa34286e2018-09-04 12:18:50 +010075 {
76 return arm_compute::GPUTarget::G52LIT;
77 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +010078 else if(version.find("G52") != std::string::npos)
79 {
80 return arm_compute::GPUTarget::G52;
81 }
82 else if(version.find("G76") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010083 {
Georgios Pinitasb03f7c52018-07-12 10:49:53 +010084 return arm_compute::GPUTarget::G76;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010085 }
Pablo Marquez Tellob1496e62021-06-25 14:49:37 +010086 else if(version.find("G31") != std::string::npos)
87 {
88 return arm_compute::GPUTarget::G31;
89 }
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010090 else
91 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010092 return arm_compute::GPUTarget::UNKNOWN;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010093 }
94}
95
96arm_compute::GPUTarget get_midgard_target(const std::string &version)
97{
Michalis Spyrouc95988a2019-07-17 13:24:52 +010098 if(version.find("T600") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010099 {
100 return arm_compute::GPUTarget::T600;
101 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +0100102 else if(version.find("T700") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100103 {
104 return arm_compute::GPUTarget::T700;
105 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +0100106 else if(version.find("T800") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100107 {
108 return arm_compute::GPUTarget::T800;
109 }
110 else
111 {
112 return arm_compute::GPUTarget::MIDGARD;
113 }
114}
115} // namespace
116
117namespace arm_compute
118{
119const std::string &string_from_target(GPUTarget target)
120{
121 static std::map<GPUTarget, const std::string> gpu_target_map =
122 {
123 { GPUTarget::MIDGARD, "midgard" },
124 { GPUTarget::BIFROST, "bifrost" },
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100125 { GPUTarget::VALHALL, "valhall" },
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100126 { GPUTarget::T600, "t600" },
127 { GPUTarget::T700, "t700" },
128 { GPUTarget::T800, "t800" },
129 { GPUTarget::G71, "g71" },
130 { GPUTarget::G72, "g72" },
131 { GPUTarget::G51, "g51" },
132 { GPUTarget::G51BIG, "g51big" },
133 { GPUTarget::G51LIT, "g51lit" },
Georgios Pinitasa34286e2018-09-04 12:18:50 +0100134 { GPUTarget::G52, "g52" },
135 { GPUTarget::G52LIT, "g52lit" },
Georgios Pinitasb03f7c52018-07-12 10:49:53 +0100136 { GPUTarget::G76, "g76" },
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100137 { GPUTarget::G77, "g77" },
Georgios Pinitas4ffc42a2020-12-01 16:28:24 +0000138 { GPUTarget::G78, "g78" },
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +0000139 { GPUTarget::G710, "g710" }
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100140 };
141
142 return gpu_target_map[target];
143}
144
145GPUTarget get_target_from_name(const std::string &device_name)
146{
147 std::regex mali_regex(R"(Mali-(.*))");
148 std::smatch name_parts;
149 const bool found_mali = std::regex_search(device_name, name_parts, mali_regex);
150
151 if(!found_mali)
152 {
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000153 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 +0100154 return GPUTarget::MIDGARD;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100155 }
156
157 const char target = name_parts.str(1)[0];
158 const std::string &version = name_parts.str(1);
159
160 std::regex future_regex(R"(.*X)");
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100161 const bool is_future_gpu = std::regex_search(version, future_regex);
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100162
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100163 // Work-out gpu target
164 GPUTarget gpu_target;
165 if(target == 'G' || is_future_gpu)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100166 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +0000167 // Check for Valhall or Bifrost
168 gpu_target = get_valhall_target(version);
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100169 if(gpu_target == GPUTarget::UNKNOWN)
170 {
Gian Marco Iodiceab2bc732022-01-19 10:06:45 +0000171 gpu_target = get_bifrost_target(version);
172 }
173
174 // Default GPUTarget
175 if(gpu_target == GPUTarget::UNKNOWN)
176 {
177 gpu_target = GPUTarget::VALHALL;
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100178 }
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100179 }
180 else if(target == 'T')
181 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100182 gpu_target = get_midgard_target(version);
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100183 }
184 else
185 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100186 gpu_target = GPUTarget::UNKNOWN;
187 }
188
189 // Report in case of unknown target
190 if(gpu_target == GPUTarget::UNKNOWN)
191 {
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000192 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 +0100193 return GPUTarget::BIFROST;
194 }
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100195
196 return gpu_target;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100197}
198
199GPUTarget get_arch_from_target(GPUTarget target)
200{
201 return (target & GPUTarget::GPU_ARCH_MASK);
202}
203} // namespace arm_compute