blob: c1346b1fcc079b1134421781420a37496e9b5a1b [file] [log] [blame]
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +01001/*
Georgios Pinitas4ffc42a2020-12-01 16:28:24 +00002 * Copyright (c) 2018-2020 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 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +010042 else if(version.find("TODX") != std::string::npos)
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010043 {
44 return arm_compute::GPUTarget::TODX;
45 }
46 else
47 {
48 return arm_compute::GPUTarget::VALHALL;
49 }
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 }
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010086 else
87 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +010088 return arm_compute::GPUTarget::UNKNOWN;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010089 }
90}
91
92arm_compute::GPUTarget get_midgard_target(const std::string &version)
93{
Michalis Spyrouc95988a2019-07-17 13:24:52 +010094 if(version.find("T600") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010095 {
96 return arm_compute::GPUTarget::T600;
97 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +010098 else if(version.find("T700") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010099 {
100 return arm_compute::GPUTarget::T700;
101 }
Michalis Spyrouc95988a2019-07-17 13:24:52 +0100102 else if(version.find("T800") != std::string::npos)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100103 {
104 return arm_compute::GPUTarget::T800;
105 }
106 else
107 {
108 return arm_compute::GPUTarget::MIDGARD;
109 }
110}
111} // namespace
112
113namespace arm_compute
114{
115const std::string &string_from_target(GPUTarget target)
116{
117 static std::map<GPUTarget, const std::string> gpu_target_map =
118 {
119 { GPUTarget::MIDGARD, "midgard" },
120 { GPUTarget::BIFROST, "bifrost" },
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100121 { GPUTarget::VALHALL, "valhall" },
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100122 { GPUTarget::T600, "t600" },
123 { GPUTarget::T700, "t700" },
124 { GPUTarget::T800, "t800" },
125 { GPUTarget::G71, "g71" },
126 { GPUTarget::G72, "g72" },
127 { GPUTarget::G51, "g51" },
128 { GPUTarget::G51BIG, "g51big" },
129 { GPUTarget::G51LIT, "g51lit" },
Georgios Pinitasa34286e2018-09-04 12:18:50 +0100130 { GPUTarget::G52, "g52" },
131 { GPUTarget::G52LIT, "g52lit" },
Georgios Pinitasb03f7c52018-07-12 10:49:53 +0100132 { GPUTarget::G76, "g76" },
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100133 { GPUTarget::G77, "g77" },
Georgios Pinitas4ffc42a2020-12-01 16:28:24 +0000134 { GPUTarget::G78, "g78" },
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100135 { GPUTarget::TODX, "todx" }
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100136 };
137
138 return gpu_target_map[target];
139}
140
141GPUTarget get_target_from_name(const std::string &device_name)
142{
143 std::regex mali_regex(R"(Mali-(.*))");
144 std::smatch name_parts;
145 const bool found_mali = std::regex_search(device_name, name_parts, mali_regex);
146
147 if(!found_mali)
148 {
Vidhya Sudhan Loganathanbdff4912018-05-22 15:03:09 +0100149 ARM_COMPUTE_LOG_INFO_MSG_CORE("Can't find valid Mali GPU. Target is set to default.");
150 return GPUTarget::MIDGARD;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100151 }
152
153 const char target = name_parts.str(1)[0];
154 const std::string &version = name_parts.str(1);
155
156 std::regex future_regex(R"(.*X)");
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100157 const bool is_future_gpu = std::regex_search(version, future_regex);
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100158
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100159 // Work-out gpu target
160 GPUTarget gpu_target;
161 if(target == 'G' || is_future_gpu)
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100162 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100163 // Check for Bifrost or Valhall
164 gpu_target = get_bifrost_target(version);
165 if(gpu_target == GPUTarget::UNKNOWN)
166 {
167 gpu_target = get_valhall_target(version);
168 }
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100169 }
170 else if(target == 'T')
171 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100172 gpu_target = get_midgard_target(version);
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100173 }
174 else
175 {
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100176 gpu_target = GPUTarget::UNKNOWN;
177 }
178
179 // Report in case of unknown target
180 if(gpu_target == GPUTarget::UNKNOWN)
181 {
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100182 ARM_COMPUTE_LOG_INFO_MSG_CORE("Mali GPU unknown. Target is set to the default one. (BIFROST)");
183 return GPUTarget::BIFROST;
184 }
Georgios Pinitasd5462ff2019-07-03 19:33:57 +0100185
186 return gpu_target;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100187}
188
189GPUTarget get_arch_from_target(GPUTarget target)
190{
191 return (target & GPUTarget::GPU_ARCH_MASK);
192}
193} // namespace arm_compute