blob: d6d91df1332c29d747a047d92f50179dc68efcbc [file] [log] [blame]
Georgios Pinitas08302c12021-06-09 10:08:27 +01001/*
Fadi Arafeh73bb6b72022-10-06 16:20:14 +00002 * Copyright (c) 2021-2022 Arm Limited.
Georgios Pinitas08302c12021-06-09 10:08:27 +01003 *
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:
Fadi Arafeh73bb6b72022-10-06 16:20:14 +000057 case CpuModel::N1:
Georgios Pinitas08302c12021-06-09 10:08:27 +010058 return true;
59 default:
60 return false;
61 }
62}
63
64bool model_supports_dot(CpuModel model)
65{
66 switch(model)
67 {
68 case CpuModel::GENERIC_FP16_DOT:
69 case CpuModel::A55r1:
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010070 case CpuModel::A510:
Georgios Pinitas08302c12021-06-09 10:08:27 +010071 case CpuModel::X1:
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010072 case CpuModel::V1:
Fadi Arafeh73bb6b72022-10-06 16:20:14 +000073 case CpuModel::N1:
Georgios Pinitas08302c12021-06-09 10:08:27 +010074 return true;
75 default:
76 return false;
77 }
78}
79
Georgios Pinitas08302c12021-06-09 10:08:27 +010080CpuModel midr_to_model(uint32_t midr)
81{
82 CpuModel model = CpuModel::GENERIC;
83
84 // Unpack variant and CPU ID
85 const int implementer = (midr >> 24) & 0xFF;
86 const int variant = (midr >> 20) & 0xF;
87 const int cpunum = (midr >> 4) & 0xFFF;
88
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010089 // 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 +010090 if(implementer == 0x41) // Arm CPUs
91 {
Georgios Pinitas08302c12021-06-09 10:08:27 +010092 switch(cpunum)
93 {
94 case 0xd03: // A53
95 case 0xd04: // A35
96 model = CpuModel::A53;
97 break;
98 case 0xd05: // A55
99 if(variant != 0)
100 {
101 model = CpuModel::A55r1;
102 }
103 else
104 {
105 model = CpuModel::A55r0;
106 }
107 break;
108 case 0xd09: // A73
109 model = CpuModel::A73;
110 break;
111 case 0xd0a: // A75
112 if(variant != 0)
113 {
114 model = CpuModel::GENERIC_FP16_DOT;
115 }
116 else
117 {
118 model = CpuModel::GENERIC_FP16;
119 }
120 break;
Fadi Arafeh73bb6b72022-10-06 16:20:14 +0000121 case 0xd0c: // N1
122 model = CpuModel::N1;
123 break;
Georgios Pinitas08302c12021-06-09 10:08:27 +0100124 case 0xd06: // A65
125 case 0xd0b: // A76
Georgios Pinitas08302c12021-06-09 10:08:27 +0100126 case 0xd0d: // A77
127 case 0xd0e: // A76AE
128 case 0xd41: // A78
129 case 0xd42: // A78AE
130 case 0xd4a: // E1
131 model = CpuModel::GENERIC_FP16_DOT;
132 break;
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100133 case 0xd40: // V1
134 model = CpuModel::V1;
135 break;
Georgios Pinitas08302c12021-06-09 10:08:27 +0100136 case 0xd44: // X1
137 model = CpuModel::X1;
138 break;
139 case 0xd46:
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100140 model = CpuModel::A510;
141 break;
142 default:
143 model = CpuModel::GENERIC;
144 break;
145 }
146 }
147 else if(implementer == 0x46)
148 {
149 switch(cpunum)
150 {
151 case 0x001: // A64FX
152 model = CpuModel::A64FX;
Georgios Pinitas08302c12021-06-09 10:08:27 +0100153 break;
154 default:
155 model = CpuModel::GENERIC;
156 break;
157 }
158 }
159 else if(implementer == 0x48)
160 {
Georgios Pinitas08302c12021-06-09 10:08:27 +0100161 switch(cpunum)
162 {
163 case 0xd40: // A76
164 model = CpuModel::GENERIC_FP16_DOT;
165 break;
166 default:
167 model = CpuModel::GENERIC;
168 break;
169 }
170 }
171 else if(implementer == 0x51)
172 {
Georgios Pinitas08302c12021-06-09 10:08:27 +0100173 switch(cpunum)
174 {
175 case 0x800: // A73
176 model = CpuModel::A73;
177 break;
178 case 0x801: // A53
179 model = CpuModel::A53;
180 break;
181 case 0x803: // A55r0
182 model = CpuModel::A55r0;
183 break;
184 case 0x804: // A76
185 model = CpuModel::GENERIC_FP16_DOT;
186 break;
187 case 0x805: // A55r1
188 model = CpuModel::A55r1;
189 break;
190 default:
191 model = CpuModel::GENERIC;
192 break;
193 }
194 }
195
196 return model;
197}
198} // namespace cpuinfo
199} // namespace arm_compute