blob: 2328f625158002de437a9d508adb565b2fbf9bf3 [file] [log] [blame]
Georgios Pinitas08302c12021-06-09 10:08:27 +01001/*
2 * Copyright (c) 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 */
24#include "src/common/cpuinfo/CpuModel.h"
25
26namespace arm_compute
27{
28namespace cpuinfo
29{
30std::string cpu_model_to_string(CpuModel model)
31{
32 switch(model)
33 {
34#define X(MODEL) \
35case CpuModel::MODEL: \
36 return #MODEL;
37 ARM_COMPUTE_CPU_MODEL_LIST
38#undef X
39 default:
40 {
41 return std::string("GENERIC");
42 }
43 };
44}
45
46bool model_supports_fp16(CpuModel model)
47{
48 switch(model)
49 {
50 case CpuModel::GENERIC_FP16:
51 case CpuModel::GENERIC_FP16_DOT:
52 case CpuModel::A55r1:
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010053 case CpuModel::A510:
Georgios Pinitas08302c12021-06-09 10:08:27 +010054 case CpuModel::X1:
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010055 case CpuModel::V1:
56 case CpuModel::A64FX:
Georgios Pinitas08302c12021-06-09 10:08:27 +010057 return true;
58 default:
59 return false;
60 }
61}
62
63bool model_supports_dot(CpuModel model)
64{
65 switch(model)
66 {
67 case CpuModel::GENERIC_FP16_DOT:
68 case CpuModel::A55r1:
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010069 case CpuModel::A510:
Georgios Pinitas08302c12021-06-09 10:08:27 +010070 case CpuModel::X1:
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010071 case CpuModel::V1:
72 case CpuModel::A64FX:
Georgios Pinitas08302c12021-06-09 10:08:27 +010073 return true;
74 default:
75 return false;
76 }
77}
78
79bool model_supports_sve(CpuModel model)
80{
81 switch(model)
82 {
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010083 case CpuModel::A510:
84 case CpuModel::V1:
85 case CpuModel::A64FX:
Georgios Pinitas08302c12021-06-09 10:08:27 +010086 return true;
87 default:
88 return false;
89 }
90}
91
92CpuModel midr_to_model(uint32_t midr)
93{
94 CpuModel model = CpuModel::GENERIC;
95
96 // Unpack variant and CPU ID
97 const int implementer = (midr >> 24) & 0xFF;
98 const int variant = (midr >> 20) & 0xF;
99 const int cpunum = (midr >> 4) & 0xFFF;
100
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100101 // Only CPUs we have code paths for are detected. All other CPUs can be safely classed as "GENERIC"
Georgios Pinitas08302c12021-06-09 10:08:27 +0100102 if(implementer == 0x41) // Arm CPUs
103 {
Georgios Pinitas08302c12021-06-09 10:08:27 +0100104 switch(cpunum)
105 {
106 case 0xd03: // A53
107 case 0xd04: // A35
108 model = CpuModel::A53;
109 break;
110 case 0xd05: // A55
111 if(variant != 0)
112 {
113 model = CpuModel::A55r1;
114 }
115 else
116 {
117 model = CpuModel::A55r0;
118 }
119 break;
120 case 0xd09: // A73
121 model = CpuModel::A73;
122 break;
123 case 0xd0a: // A75
124 if(variant != 0)
125 {
126 model = CpuModel::GENERIC_FP16_DOT;
127 }
128 else
129 {
130 model = CpuModel::GENERIC_FP16;
131 }
132 break;
133 case 0xd06: // A65
134 case 0xd0b: // A76
135 case 0xd0c: // N1
136 case 0xd0d: // A77
137 case 0xd0e: // A76AE
138 case 0xd41: // A78
139 case 0xd42: // A78AE
140 case 0xd4a: // E1
141 model = CpuModel::GENERIC_FP16_DOT;
142 break;
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100143 case 0xd40: // V1
144 model = CpuModel::V1;
145 break;
Georgios Pinitas08302c12021-06-09 10:08:27 +0100146 case 0xd44: // X1
147 model = CpuModel::X1;
148 break;
149 case 0xd46:
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100150 model = CpuModel::A510;
151 break;
152 default:
153 model = CpuModel::GENERIC;
154 break;
155 }
156 }
157 else if(implementer == 0x46)
158 {
159 switch(cpunum)
160 {
161 case 0x001: // A64FX
162 model = CpuModel::A64FX;
Georgios Pinitas08302c12021-06-09 10:08:27 +0100163 break;
164 default:
165 model = CpuModel::GENERIC;
166 break;
167 }
168 }
169 else if(implementer == 0x48)
170 {
Georgios Pinitas08302c12021-06-09 10:08:27 +0100171 switch(cpunum)
172 {
173 case 0xd40: // A76
174 model = CpuModel::GENERIC_FP16_DOT;
175 break;
176 default:
177 model = CpuModel::GENERIC;
178 break;
179 }
180 }
181 else if(implementer == 0x51)
182 {
Georgios Pinitas08302c12021-06-09 10:08:27 +0100183 switch(cpunum)
184 {
185 case 0x800: // A73
186 model = CpuModel::A73;
187 break;
188 case 0x801: // A53
189 model = CpuModel::A53;
190 break;
191 case 0x803: // A55r0
192 model = CpuModel::A55r0;
193 break;
194 case 0x804: // A76
195 model = CpuModel::GENERIC_FP16_DOT;
196 break;
197 case 0x805: // A55r1
198 model = CpuModel::A55r1;
199 break;
200 default:
201 model = CpuModel::GENERIC;
202 break;
203 }
204 }
205
206 return model;
207}
208} // namespace cpuinfo
209} // namespace arm_compute