blob: 8c3f8a8fafaa31424781459949645a7ce1c435ff [file] [log] [blame]
Georgios Pinitas08302c12021-06-09 10:08:27 +01001/*
Viet-Hoa Doa7ddd602023-10-24 17:28:05 +01002 * Copyright (c) 2021-2023 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{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010032 switch (model)
Georgios Pinitas08302c12021-06-09 10:08:27 +010033 {
34#define X(MODEL) \
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010035 case CpuModel::MODEL: \
36 return #MODEL;
37 ARM_COMPUTE_CPU_MODEL_LIST
Georgios Pinitas08302c12021-06-09 10:08:27 +010038#undef X
39 default:
40 {
41 return std::string("GENERIC");
42 }
43 };
44}
45
46bool model_supports_fp16(CpuModel model)
47{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010048 switch (model)
Georgios Pinitas08302c12021-06-09 10:08:27 +010049 {
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{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010066 switch (model)
Georgios Pinitas08302c12021-06-09 10:08:27 +010067 {
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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010090 if (implementer == 0x41) // Arm CPUs
Georgios Pinitas08302c12021-06-09 10:08:27 +010091 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010092 switch (cpunum)
Georgios Pinitas08302c12021-06-09 10:08:27 +010093 {
94 case 0xd03: // A53
95 case 0xd04: // A35
96 model = CpuModel::A53;
97 break;
98 case 0xd05: // A55
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010099 if (variant != 0)
Georgios Pinitas08302c12021-06-09 10:08:27 +0100100 {
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
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100112 if (variant != 0)
Georgios Pinitas08302c12021-06-09 10:08:27 +0100113 {
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;
Viet-Hoa Doa7ddd602023-10-24 17:28:05 +0100139 case 0xd46: // A510
140 case 0xd80: // A520
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100141 model = CpuModel::A510;
142 break;
Viet-Hoa Doa7ddd602023-10-24 17:28:05 +0100143 case 0xd15: // R82
144 model = CpuModel::A55r1;
145 break;
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100146 default:
147 model = CpuModel::GENERIC;
148 break;
149 }
150 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100151 else if (implementer == 0x46)
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100152 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100153 switch (cpunum)
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100154 {
155 case 0x001: // A64FX
156 model = CpuModel::A64FX;
Georgios Pinitas08302c12021-06-09 10:08:27 +0100157 break;
158 default:
159 model = CpuModel::GENERIC;
160 break;
161 }
162 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100163 else if (implementer == 0x48)
Georgios Pinitas08302c12021-06-09 10:08:27 +0100164 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100165 switch (cpunum)
Georgios Pinitas08302c12021-06-09 10:08:27 +0100166 {
167 case 0xd40: // A76
168 model = CpuModel::GENERIC_FP16_DOT;
169 break;
170 default:
171 model = CpuModel::GENERIC;
172 break;
173 }
174 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100175 else if (implementer == 0x51)
Georgios Pinitas08302c12021-06-09 10:08:27 +0100176 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100177 switch (cpunum)
Georgios Pinitas08302c12021-06-09 10:08:27 +0100178 {
179 case 0x800: // A73
180 model = CpuModel::A73;
181 break;
182 case 0x801: // A53
183 model = CpuModel::A53;
184 break;
185 case 0x803: // A55r0
186 model = CpuModel::A55r0;
187 break;
188 case 0x804: // A76
189 model = CpuModel::GENERIC_FP16_DOT;
190 break;
191 case 0x805: // A55r1
192 model = CpuModel::A55r1;
193 break;
194 default:
195 model = CpuModel::GENERIC;
196 break;
197 }
198 }
199
200 return model;
201}
202} // namespace cpuinfo
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100203} // namespace arm_compute