• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-2019 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  */
24 #include "arm_compute/core/GPUTarget.h"
25 #include "arm_compute/core/Log.h"
26 
27 #include <map>
28 #include <regex>
29 
30 namespace
31 {
get_valhall_target(const std::string & version)32 arm_compute::GPUTarget get_valhall_target(const std::string &version)
33 {
34     if(version.find("G77") != std::string::npos)
35     {
36         return arm_compute::GPUTarget::G77;
37     }
38     else if(version.find("TBOX") != std::string::npos)
39     {
40         return arm_compute::GPUTarget::TBOX;
41     }
42     else if(version.find("TODX") != std::string::npos)
43     {
44         return arm_compute::GPUTarget::TODX;
45     }
46     else
47     {
48         return arm_compute::GPUTarget::VALHALL;
49     }
50 }
51 
get_bifrost_target(const std::string & version)52 arm_compute::GPUTarget get_bifrost_target(const std::string &version)
53 {
54     if(version.find("G71") != std::string::npos)
55     {
56         return arm_compute::GPUTarget::G71;
57     }
58     else if(version.find("G72") != std::string::npos)
59     {
60         return arm_compute::GPUTarget::G72;
61     }
62     else if(version.find("G51BIG") != std::string::npos)
63     {
64         return arm_compute::GPUTarget::G51BIG;
65     }
66     else if(version.find("G51LIT") != std::string::npos)
67     {
68         return arm_compute::GPUTarget::G51LIT;
69     }
70     else if(version.find("G51") != std::string::npos)
71     {
72         return arm_compute::GPUTarget::G51;
73     }
74     else if(version.find("G52LIT") != std::string::npos)
75     {
76         return arm_compute::GPUTarget::G52LIT;
77     }
78     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)
83     {
84         return arm_compute::GPUTarget::G76;
85     }
86     else
87     {
88         return arm_compute::GPUTarget::UNKNOWN;
89     }
90 }
91 
get_midgard_target(const std::string & version)92 arm_compute::GPUTarget get_midgard_target(const std::string &version)
93 {
94     if(version.find("T600") != std::string::npos)
95     {
96         return arm_compute::GPUTarget::T600;
97     }
98     else if(version.find("T700") != std::string::npos)
99     {
100         return arm_compute::GPUTarget::T700;
101     }
102     else if(version.find("T800") != std::string::npos)
103     {
104         return arm_compute::GPUTarget::T800;
105     }
106     else
107     {
108         return arm_compute::GPUTarget::MIDGARD;
109     }
110 }
111 } // namespace
112 
113 namespace arm_compute
114 {
string_from_target(GPUTarget target)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::TBOX, "tbox" },
135         { GPUTarget::TODX, "todx" }
136     };
137 
138     return gpu_target_map[target];
139 }
140 
get_target_from_name(const std::string & device_name)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 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("Mali GPU unknown. Target is set to the default one. (BIFROST)");
183         return GPUTarget::BIFROST;
184     }
185 
186     return gpu_target;
187 }
188 
get_arch_from_target(GPUTarget target)189 GPUTarget get_arch_from_target(GPUTarget target)
190 {
191     return (target & GPUTarget::GPU_ARCH_MASK);
192 }
193 } // namespace arm_compute
194