Compute Library
 21.11
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 if(version.find("G31") != std::string::npos)
87  {
89  }
90  else
91  {
93  }
94 }
95 
96 arm_compute::GPUTarget get_midgard_target(const std::string &version)
97 {
98  if(version.find("T600") != std::string::npos)
99  {
101  }
102  else if(version.find("T700") != std::string::npos)
103  {
105  }
106  else if(version.find("T800") != std::string::npos)
107  {
109  }
110  else
111  {
113  }
114 }
115 } // namespace
116 
117 namespace arm_compute
118 {
119 const 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" },
125  { GPUTarget::VALHALL, "valhall" },
126  { 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" },
134  { GPUTarget::G52, "g52" },
135  { GPUTarget::G52LIT, "g52lit" },
136  { GPUTarget::G76, "g76" },
137  { GPUTarget::G77, "g77" },
138  { GPUTarget::G78, "g78" },
139  { GPUTarget::TODX, "todx" }
140  };
141 
142  return gpu_target_map[target];
143 }
144 
145 GPUTarget 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  {
153  ARM_COMPUTE_LOG_INFO_MSG_CORE("Can't find valid Arm® Mali™ GPU. Target is set to default.");
154  return GPUTarget::MIDGARD;
155  }
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)");
161  const bool is_future_gpu = std::regex_search(version, future_regex);
162 
163  // Work-out gpu target
164  GPUTarget gpu_target;
165  if(target == 'G' || is_future_gpu)
166  {
167  // Check for Bifrost or Valhall
168  gpu_target = get_bifrost_target(version);
169  if(gpu_target == GPUTarget::UNKNOWN)
170  {
171  gpu_target = get_valhall_target(version);
172  }
173  }
174  else if(target == 'T')
175  {
176  gpu_target = get_midgard_target(version);
177  }
178  else
179  {
180  gpu_target = GPUTarget::UNKNOWN;
181  }
182 
183  // Report in case of unknown target
184  if(gpu_target == GPUTarget::UNKNOWN)
185  {
186  ARM_COMPUTE_LOG_INFO_MSG_CORE("Arm® Mali™ Mali GPU unknown. Target is set to the default one. (BIFROST)");
187  return GPUTarget::BIFROST;
188  }
189 
190  return gpu_target;
191 }
192 
194 {
195  return (target & GPUTarget::GPU_ARCH_MASK);
196 }
197 } // 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:145
GPUTarget get_arch_from_target(GPUTarget target)
Helper function to get the GPU arch.
Definition: GPUTarget.cpp:193
const std::string & string_from_target(GPUTarget target)
Translates a given gpu device target to string.
Definition: GPUTarget.cpp:119
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