blob: afefb1aeb0662b74610a9f7dc1710325c1f72572 [file] [log] [blame]
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +01001/*
Giorgio Arena5ae8d802021-11-18 18:02:13 +00002 * Copyright (c) 2017-2022 Arm Limited.
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CPP_TYPES_H
25#define ARM_COMPUTE_CPP_TYPES_H
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010026
Pablo Tello4e0ac6f2018-10-01 14:31:11 +010027#include "arm_compute/core/Error.h"
28
Georgios Pinitas08302c12021-06-09 10:08:27 +010029#include <memory>
Pablo Tello7fad9b12018-03-14 17:55:27 +000030
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010031namespace arm_compute
32{
Giorgio Arena5ae8d802021-11-18 18:02:13 +000033namespace cpuinfo
34{
35struct CpuIsaInfo;
36} // namespace cpuinfo
37
Georgios Pinitas08302c12021-06-09 10:08:27 +010038#define ARM_COMPUTE_CPU_MODEL_LIST \
39 X(GENERIC) \
40 X(GENERIC_FP16) \
41 X(GENERIC_FP16_DOT) \
Georgios Pinitas08302c12021-06-09 10:08:27 +010042 X(A53) \
43 X(A55r0) \
44 X(A55r1) \
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010045 X(A35) \
Georgios Pinitas08302c12021-06-09 10:08:27 +010046 X(A73) \
Mohammed Suhail Munshicff6f3b2021-12-09 17:36:25 +000047 X(A76) \
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010048 X(A510) \
49 X(X1) \
50 X(V1) \
51 X(A64FX)
Georgios Pinitas08302c12021-06-09 10:08:27 +010052
53/** CPU models types
Pablo Tello7fad9b12018-03-14 17:55:27 +000054 *
Georgios Pinitas08302c12021-06-09 10:08:27 +010055 * @note We only need to detect CPUs we have microarchitecture-specific code for.
56 * @note Architecture features are detected via HWCAPs.
Pablo Tello7fad9b12018-03-14 17:55:27 +000057 */
58enum class CPUModel
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010059{
Georgios Pinitas08302c12021-06-09 10:08:27 +010060#define X(model) model,
61 ARM_COMPUTE_CPU_MODEL_LIST
62#undef X
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010063};
Moritz Pflanzerc186b572017-09-07 09:48:04 +010064
Pablo Tello7fad9b12018-03-14 17:55:27 +000065class CPUInfo final
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010066{
Michalis Spyrou20fca522021-06-07 14:23:57 +010067protected:
Pablo Tello7fad9b12018-03-14 17:55:27 +000068 CPUInfo();
Georgios Pinitas08302c12021-06-09 10:08:27 +010069 ~CPUInfo();
Pablo Tello7fad9b12018-03-14 17:55:27 +000070
Michalis Spyrou20fca522021-06-07 14:23:57 +010071public:
72 /** Access the KernelLibrary singleton.
73 * This method has been deprecated and will be removed in future releases
74 * @return The KernelLibrary instance.
Pablo Tello7fad9b12018-03-14 17:55:27 +000075 */
Michalis Spyrou20fca522021-06-07 14:23:57 +010076 static CPUInfo &get();
77
78 /* Delete move and copy constructors and assignment operator
79 s */
80 CPUInfo(CPUInfo const &) = delete; // Copy construct
81 CPUInfo(CPUInfo &&) = delete; // Move construct
82 CPUInfo &operator=(CPUInfo const &) = delete; // Copy assign
83 CPUInfo &operator=(CPUInfo &&) = delete; // Move assign
Pablo Tello7fad9b12018-03-14 17:55:27 +000084
85 /** Checks if the cpu model supports fp16.
86 *
87 * @return true of the cpu supports fp16, false otherwise
88 */
89 bool has_fp16() const;
Georgios Pinitas08302c12021-06-09 10:08:27 +010090 /** Checks if the cpu model supports bf16.
91 *
92 * @return true of the cpu supports bf16, false otherwise
93 */
94 bool has_bf16() const;
Michalis Spyrou20fca522021-06-07 14:23:57 +010095 /** Checks if the cpu model supports bf16.
96 *
97 * @return true of the cpu supports bf16, false otherwise
98 */
99 bool has_svebf16() const;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000100 /** Checks if the cpu model supports dot product.
101 *
102 * @return true of the cpu supports dot product, false otherwise
103 */
104 bool has_dotprod() const;
Michalis Spyrou20fca522021-06-07 14:23:57 +0100105 /** Checks if the cpu model supports floating-point matrix multiplication.
106 *
107 * @return true of the cpu supports floating-point matrix multiplication, false otherwise
108 */
109 bool has_svef32mm() const;
110 /** Checks if the cpu model supports integer matrix multiplication.
111 *
112 * @return true of the cpu supports integer matrix multiplication, false otherwise
113 */
114 bool has_i8mm() const;
115 /** Checks if the cpu model supports integer matrix multiplication.
116 *
117 * @return true of the cpu supports integer matrix multiplication, false otherwise
118 */
119 bool has_svei8mm() const;
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +0000120 /** Checks if the cpu model supports sve.
121 *
122 * @return true of the cpu supports sve, false otherwise
123 */
124 bool has_sve() const;
Michalis Spyrou20fca522021-06-07 14:23:57 +0100125 /** Checks if the cpu model supports sve2.
126 *
127 * @return true of the cpu supports sve2, false otherwise
128 */
129 bool has_sve2() const;
ramelg01a1f78512022-06-29 16:28:10 +0100130 /** Checks if the cpu model supports sme.
131 *
132 * @return true of the cpu supports sme, false otherwise
133 */
134 bool has_sme() const;
135 /** Checks if the cpu model supports sme2.
136 *
137 * @return true of the cpu supports sme2, false otherwise
138 */
139 bool has_sme2() const;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000140 /** Gets the cpu model for a given cpuid.
141 *
142 * @param[in] cpuid the id of the cpu core to be retrieved,
143 *
144 * @return the @ref CPUModel of the cpuid queiried.
145 */
146 CPUModel get_cpu_model(unsigned int cpuid) const;
147 /** Gets the current thread's cpu model
148 *
149 * @return Current thread's @ref CPUModel
150 */
151 CPUModel get_cpu_model() const;
Giorgio Arena5ae8d802021-11-18 18:02:13 +0000152 /** Gets the current cpu's ISA information
153 *
154 * @return Current cpu's ISA information
155 */
156 cpuinfo::CpuIsaInfo get_isa() const;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000157 /** Gets the L1 cache size
158 *
159 * @return the size of the L1 cache
160 */
161 unsigned int get_L1_cache_size() const;
162 /** Gets the L2 cache size
163 *
164 * @return the size of the L1 cache
165 */
166 unsigned int get_L2_cache_size() const;
Anthony Barbier8914e322018-08-10 15:28:25 +0100167 /** Return the maximum number of CPUs present
168 *
169 * @return Number of CPUs
170 */
171 unsigned int get_cpu_num() const;
172
Pablo Tello7fad9b12018-03-14 17:55:27 +0000173private:
Georgios Pinitas08302c12021-06-09 10:08:27 +0100174 struct Impl;
175 std::unique_ptr<Impl> _impl;
Pablo Tello0cf77982018-10-24 15:32:39 +0100176};
177
Alex Gildayc357c472018-03-21 13:54:09 +0000178/** Information about executing thread and CPU. */
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100179struct ThreadInfo
180{
Pablo Tello7fad9b12018-03-14 17:55:27 +0000181 int thread_id{ 0 };
182 int num_threads{ 1 };
183 const CPUInfo *cpu_info{ nullptr };
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100184};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100185} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000186#endif /* ARM_COMPUTE_CPP_TYPES_H */