blob: 6382ffd5b497d70e18508fac802455005391fb65 [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:
Georgios Pinitas08302c12021-06-09 10:08:27 +010072 return true;
73 default:
74 return false;
75 }
76}
77
Georgios Pinitas08302c12021-06-09 10:08:27 +010078CpuModel midr_to_model(uint32_t midr)
79{
80 CpuModel model = CpuModel::GENERIC;
81
82 // Unpack variant and CPU ID
83 const int implementer = (midr >> 24) & 0xFF;
84 const int variant = (midr >> 20) & 0xF;
85 const int cpunum = (midr >> 4) & 0xFFF;
86
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010087 // 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 +010088 if(implementer == 0x41) // Arm CPUs
89 {
Georgios Pinitas08302c12021-06-09 10:08:27 +010090 switch(cpunum)
91 {
92 case 0xd03: // A53
93 case 0xd04: // A35
94 model = CpuModel::A53;
95 break;
96 case 0xd05: // A55
97 if(variant != 0)
98 {
99 model = CpuModel::A55r1;
100 }
101 else
102 {
103 model = CpuModel::A55r0;
104 }
105 break;
106 case 0xd09: // A73
107 model = CpuModel::A73;
108 break;
109 case 0xd0a: // A75
110 if(variant != 0)
111 {
112 model = CpuModel::GENERIC_FP16_DOT;
113 }
114 else
115 {
116 model = CpuModel::GENERIC_FP16;
117 }
118 break;
119 case 0xd06: // A65
120 case 0xd0b: // A76
121 case 0xd0c: // N1
122 case 0xd0d: // A77
123 case 0xd0e: // A76AE
124 case 0xd41: // A78
125 case 0xd42: // A78AE
126 case 0xd4a: // E1
127 model = CpuModel::GENERIC_FP16_DOT;
128 break;
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100129 case 0xd40: // V1
130 model = CpuModel::V1;
131 break;
Georgios Pinitas08302c12021-06-09 10:08:27 +0100132 case 0xd44: // X1
133 model = CpuModel::X1;
134 break;
135 case 0xd46:
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100136 model = CpuModel::A510;
137 break;
138 default:
139 model = CpuModel::GENERIC;
140 break;
141 }
142 }
143 else if(implementer == 0x46)
144 {
145 switch(cpunum)
146 {
147 case 0x001: // A64FX
148 model = CpuModel::A64FX;
Georgios Pinitas08302c12021-06-09 10:08:27 +0100149 break;
150 default:
151 model = CpuModel::GENERIC;
152 break;
153 }
154 }
155 else if(implementer == 0x48)
156 {
Georgios Pinitas08302c12021-06-09 10:08:27 +0100157 switch(cpunum)
158 {
159 case 0xd40: // A76
160 model = CpuModel::GENERIC_FP16_DOT;
161 break;
162 default:
163 model = CpuModel::GENERIC;
164 break;
165 }
166 }
167 else if(implementer == 0x51)
168 {
Georgios Pinitas08302c12021-06-09 10:08:27 +0100169 switch(cpunum)
170 {
171 case 0x800: // A73
172 model = CpuModel::A73;
173 break;
174 case 0x801: // A53
175 model = CpuModel::A53;
176 break;
177 case 0x803: // A55r0
178 model = CpuModel::A55r0;
179 break;
180 case 0x804: // A76
181 model = CpuModel::GENERIC_FP16_DOT;
182 break;
183 case 0x805: // A55r1
184 model = CpuModel::A55r1;
185 break;
186 default:
187 model = CpuModel::GENERIC;
188 break;
189 }
190 }
191
192 return model;
193}
194} // namespace cpuinfo
195} // namespace arm_compute