Compute Library
 21.05
GPUTarget.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 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  */
25 #include "arm_compute/core/Log.h"
26 
27 #include <map>
28 #include <regex>
29 
30 namespace
31 {
32 arm_compute::GPUTarget get_valhall_target(const std::string &version)
33 {
34  if(version.find("G77") != std::string::npos)
35  {
37  }
38  if(version.find("G78") != std::string::npos)
39  {
41  }
42  else if(version.find("TODX") != std::string::npos)
43  {
45  }
46  else
47  {
49  }
50 }
51 
52 arm_compute::GPUTarget get_bifrost_target(const std::string &version)
53 {
54  if(version.find("G71") != std::string::npos)
55  {
57  }
58  else if(version.find("G72") != std::string::npos)
59  {
61  }
62  else if(version.find("G51BIG") != std::string::npos)
63  {
65  }
66  else if(version.find("G51LIT") != std::string::npos)
67  {
69  }
70  else if(version.find("G51") != std::string::npos)
71  {
73  }
74  else if(version.find("G52LIT") != std::string::npos)
75  {
77  }
78  else if(version.find("G52") != std::string::npos)
79  {
81  }
82  else if(version.find("G76") != std::string::npos)
83  {
85  }
86  else
87  {
89  }
90 }
91 
92 arm_compute::GPUTarget get_midgard_target(const std::string &version)
93 {
94  if(version.find("T600") != std::string::npos)
95  {
97  }
98  else if(version.find("T700") != std::string::npos)
99  {
101  }
102  else if(version.find("T800") != std::string::npos)
103  {
105  }
106  else
107  {
109  }
110 }
111 } // namespace
112 
113 namespace arm_compute
114 {
115 const 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" },
121  { GPUTarget::VALHALL, "valhall" },
122  { 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" },
130  { GPUTarget::G52, "g52" },
131  { GPUTarget::G52LIT, "g52lit" },
132  { GPUTarget::G76, "g76" },
133  { GPUTarget::G77, "g77" },
134  { GPUTarget::G78, "g78" },
135  { GPUTarget::TODX, "todx" }
136  };
137 
138  return gpu_target_map[target];
139 }
140 
141 GPUTarget 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  {
149  ARM_COMPUTE_LOG_INFO_MSG_CORE("Can't find valid Arm® Mali™ GPU. Target is set to default.");
150  return GPUTarget::MIDGARD;
151  }
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)");
157  const bool is_future_gpu = std::regex_search(version, future_regex);
158 
159  // Work-out gpu target
160  GPUTarget gpu_target;
161  if(target == 'G' || is_future_gpu)
162  {
163  // 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  }
169  }
170  else if(target == 'T')
171  {
172  gpu_target = get_midgard_target(version);
173  }
174  else
175  {
176  gpu_target = GPUTarget::UNKNOWN;
177  }
178 
179  // Report in case of unknown target
180  if(gpu_target == GPUTarget::UNKNOWN)
181  {
182  ARM_COMPUTE_LOG_INFO_MSG_CORE("Arm® Mali™ Mali GPU unknown. Target is set to the default one. (BIFROST)");
183  return GPUTarget::BIFROST;
184  }
185 
186  return gpu_target;
187 }
188 
190 {
191  return (target & GPUTarget::GPU_ARCH_MASK);
192 }
193 } // namespace arm_compute
GPUTarget get_target_from_name(const std::string &device_name)
Helper function to get the GPU target from a device name.
Definition: GPUTarget.cpp:141
GPUTarget get_arch_from_target(GPUTarget target)
Helper function to get the GPU arch.
Definition: GPUTarget.cpp:189
const std::string & string_from_target(GPUTarget target)
Translates a given gpu device target to string.
Definition: GPUTarget.cpp:115
Copyright (c) 2017-2021 Arm Limited.
GPUTarget
Available GPU Targets.
Definition: GPUTarget.h:34
#define ARM_COMPUTE_LOG_INFO_MSG_CORE(msg)
Log information level message to the core system logger.
Definition: Log.h:87