blob: 78e2df1599d098ddc4303e011c7176f7bde0f7d2 [file] [log] [blame]
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +01001/*
2 * Copyright (c) 2018 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
30namespace
31{
32arm_compute::GPUTarget get_bifrost_target(const std::string &version)
33{
34 if(version == "G71")
35 {
36 return arm_compute::GPUTarget::G71;
37 }
38 else if(version == "G72")
39 {
40 return arm_compute::GPUTarget::G72;
41 }
42 else if(version == "G51")
43 {
44 return arm_compute::GPUTarget::G51;
45 }
46 else if(version == "G51BIG")
47 {
48 return arm_compute::GPUTarget::G51BIG;
49 }
50 else if(version == "G51LIT")
51 {
52 return arm_compute::GPUTarget::G51LIT;
53 }
Georgios Pinitasa34286e2018-09-04 12:18:50 +010054 else if(version == "G52")
55 {
56 return arm_compute::GPUTarget::G52;
57 }
58 else if(version == "G52LIT")
59 {
60 return arm_compute::GPUTarget::G52LIT;
61 }
Georgios Pinitasb03f7c52018-07-12 10:49:53 +010062 else if(version == "G76")
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010063 {
Georgios Pinitasb03f7c52018-07-12 10:49:53 +010064 return arm_compute::GPUTarget::G76;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010065 }
66 else if(version == "TTRX")
67 {
68 return arm_compute::GPUTarget::TTRX;
69 }
70 else if(version == "TBOX")
71 {
72 return arm_compute::GPUTarget::TBOX;
73 }
74 else
75 {
76 return arm_compute::GPUTarget::BIFROST;
77 }
78}
79
80arm_compute::GPUTarget get_midgard_target(const std::string &version)
81{
82 if(version == "T600")
83 {
84 return arm_compute::GPUTarget::T600;
85 }
86 else if(version == "T700")
87 {
88 return arm_compute::GPUTarget::T700;
89 }
90 else if(version == "T800")
91 {
92 return arm_compute::GPUTarget::T800;
93 }
94 else
95 {
96 return arm_compute::GPUTarget::MIDGARD;
97 }
98}
99} // namespace
100
101namespace arm_compute
102{
103const std::string &string_from_target(GPUTarget target)
104{
105 static std::map<GPUTarget, const std::string> gpu_target_map =
106 {
107 { GPUTarget::MIDGARD, "midgard" },
108 { GPUTarget::BIFROST, "bifrost" },
109 { GPUTarget::T600, "t600" },
110 { GPUTarget::T700, "t700" },
111 { GPUTarget::T800, "t800" },
112 { GPUTarget::G71, "g71" },
113 { GPUTarget::G72, "g72" },
114 { GPUTarget::G51, "g51" },
115 { GPUTarget::G51BIG, "g51big" },
116 { GPUTarget::G51LIT, "g51lit" },
Georgios Pinitasa34286e2018-09-04 12:18:50 +0100117 { GPUTarget::G52, "g52" },
118 { GPUTarget::G52LIT, "g52lit" },
Georgios Pinitasb03f7c52018-07-12 10:49:53 +0100119 { GPUTarget::G76, "g76" },
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100120 { GPUTarget::TTRX, "ttrx" },
121 { GPUTarget::TBOX, "tbox" }
122 };
123
124 return gpu_target_map[target];
125}
126
127GPUTarget get_target_from_name(const std::string &device_name)
128{
129 std::regex mali_regex(R"(Mali-(.*))");
130 std::smatch name_parts;
131 const bool found_mali = std::regex_search(device_name, name_parts, mali_regex);
132
133 if(!found_mali)
134 {
Vidhya Sudhan Loganathanbdff4912018-05-22 15:03:09 +0100135 ARM_COMPUTE_LOG_INFO_MSG_CORE("Can't find valid Mali GPU. Target is set to default.");
136 return GPUTarget::MIDGARD;
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +0100137 }
138
139 const char target = name_parts.str(1)[0];
140 const std::string &version = name_parts.str(1);
141
142 std::regex future_regex(R"(.*X)");
143 const bool is_future_bifrost = std::regex_search(version, future_regex);
144
145 if(target == 'G' || is_future_bifrost)
146 {
147 return get_bifrost_target(version);
148 }
149 else if(target == 'T')
150 {
151 return get_midgard_target(version);
152 }
153 else
154 {
155 ARM_COMPUTE_LOG_INFO_MSG_CORE("Mali GPU unknown. Target is set to the default one. (BIFROST)");
156 return GPUTarget::BIFROST;
157 }
158}
159
160GPUTarget get_arch_from_target(GPUTarget target)
161{
162 return (target & GPUTarget::GPU_ARCH_MASK);
163}
164} // namespace arm_compute