blob: b080a86938e8f808749e49074c0a8ff72d079277 [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) \
Fadi Arafeh73bb6b72022-10-06 16:20:14 +000051 X(A64FX) \
52 X(N1)
Georgios Pinitas08302c12021-06-09 10:08:27 +010053
54/** CPU models types
Pablo Tello7fad9b12018-03-14 17:55:27 +000055 *
Georgios Pinitas08302c12021-06-09 10:08:27 +010056 * @note We only need to detect CPUs we have microarchitecture-specific code for.
57 * @note Architecture features are detected via HWCAPs.
Pablo Tello7fad9b12018-03-14 17:55:27 +000058 */
59enum class CPUModel
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010060{
Georgios Pinitas08302c12021-06-09 10:08:27 +010061#define X(model) model,
62 ARM_COMPUTE_CPU_MODEL_LIST
63#undef X
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010064};
Moritz Pflanzerc186b572017-09-07 09:48:04 +010065
Pablo Tello7fad9b12018-03-14 17:55:27 +000066class CPUInfo final
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010067{
Michalis Spyrou20fca522021-06-07 14:23:57 +010068protected:
Pablo Tello7fad9b12018-03-14 17:55:27 +000069 CPUInfo();
Georgios Pinitas08302c12021-06-09 10:08:27 +010070 ~CPUInfo();
Pablo Tello7fad9b12018-03-14 17:55:27 +000071
Michalis Spyrou20fca522021-06-07 14:23:57 +010072public:
73 /** Access the KernelLibrary singleton.
74 * This method has been deprecated and will be removed in future releases
75 * @return The KernelLibrary instance.
Pablo Tello7fad9b12018-03-14 17:55:27 +000076 */
Michalis Spyrou20fca522021-06-07 14:23:57 +010077 static CPUInfo &get();
78
79 /* Delete move and copy constructors and assignment operator
80 s */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010081 CPUInfo(CPUInfo const &) = delete; // Copy construct
82 CPUInfo(CPUInfo &&) = delete; // Move construct
Michalis Spyrou20fca522021-06-07 14:23:57 +010083 CPUInfo &operator=(CPUInfo const &) = delete; // Copy assign
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010084 CPUInfo &operator=(CPUInfo &&) = delete; // Move assign
Pablo Tello7fad9b12018-03-14 17:55:27 +000085
86 /** Checks if the cpu model supports fp16.
87 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +010088 * @return true if the cpu supports fp16, false otherwise
Pablo Tello7fad9b12018-03-14 17:55:27 +000089 */
90 bool has_fp16() const;
Georgios Pinitas08302c12021-06-09 10:08:27 +010091 /** Checks if the cpu model supports bf16.
92 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +010093 * @return true if the cpu supports bf16, false otherwise
Georgios Pinitas08302c12021-06-09 10:08:27 +010094 */
95 bool has_bf16() const;
Michalis Spyrou20fca522021-06-07 14:23:57 +010096 /** Checks if the cpu model supports bf16.
97 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +010098 * @return true if the cpu supports bf16, false otherwise
Michalis Spyrou20fca522021-06-07 14:23:57 +010099 */
100 bool has_svebf16() const;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000101 /** Checks if the cpu model supports dot product.
102 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100103 * @return true if the cpu supports dot product, false otherwise
Pablo Tello7fad9b12018-03-14 17:55:27 +0000104 */
105 bool has_dotprod() const;
Michalis Spyrou20fca522021-06-07 14:23:57 +0100106 /** Checks if the cpu model supports floating-point matrix multiplication.
107 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100108 * @return true if the cpu supports floating-point matrix multiplication, false otherwise
Michalis Spyrou20fca522021-06-07 14:23:57 +0100109 */
110 bool has_svef32mm() const;
111 /** Checks if the cpu model supports integer matrix multiplication.
112 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100113 * @return true if the cpu supports integer matrix multiplication, false otherwise
Michalis Spyrou20fca522021-06-07 14:23:57 +0100114 */
115 bool has_i8mm() const;
116 /** Checks if the cpu model supports integer matrix multiplication.
117 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100118 * @return true if the cpu supports integer matrix multiplication, false otherwise
Michalis Spyrou20fca522021-06-07 14:23:57 +0100119 */
120 bool has_svei8mm() const;
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +0000121 /** Checks if the cpu model supports sve.
122 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100123 * @return true if the cpu supports sve, false otherwise
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +0000124 */
125 bool has_sve() const;
Michalis Spyrou20fca522021-06-07 14:23:57 +0100126 /** Checks if the cpu model supports sve2.
127 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100128 * @return true if the cpu supports sve2, false otherwise
Michalis Spyrou20fca522021-06-07 14:23:57 +0100129 */
130 bool has_sve2() const;
ramelg01a1f78512022-06-29 16:28:10 +0100131 /** Checks if the cpu model supports sme.
132 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100133 * @return true if the cpu supports sme, false otherwise
ramelg01a1f78512022-06-29 16:28:10 +0100134 */
135 bool has_sme() const;
136 /** Checks if the cpu model supports sme2.
137 *
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100138 * @return true if the cpu supports sme2, false otherwise
ramelg01a1f78512022-06-29 16:28:10 +0100139 */
140 bool has_sme2() const;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000141 /** Gets the cpu model for a given cpuid.
142 *
143 * @param[in] cpuid the id of the cpu core to be retrieved,
144 *
145 * @return the @ref CPUModel of the cpuid queiried.
146 */
147 CPUModel get_cpu_model(unsigned int cpuid) const;
148 /** Gets the current thread's cpu model
149 *
150 * @return Current thread's @ref CPUModel
151 */
152 CPUModel get_cpu_model() const;
Giorgio Arena5ae8d802021-11-18 18:02:13 +0000153 /** Gets the current cpu's ISA information
154 *
155 * @return Current cpu's ISA information
156 */
157 cpuinfo::CpuIsaInfo get_isa() const;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000158 /** Gets the L1 cache size
159 *
160 * @return the size of the L1 cache
161 */
162 unsigned int get_L1_cache_size() const;
163 /** Gets the L2 cache size
164 *
165 * @return the size of the L1 cache
166 */
167 unsigned int get_L2_cache_size() const;
Anthony Barbier8914e322018-08-10 15:28:25 +0100168 /** Return the maximum number of CPUs present
169 *
170 * @return Number of CPUs
171 */
172 unsigned int get_cpu_num() const;
173
Pablo Tello7fad9b12018-03-14 17:55:27 +0000174private:
Georgios Pinitas08302c12021-06-09 10:08:27 +0100175 struct Impl;
176 std::unique_ptr<Impl> _impl;
Pablo Tello0cf77982018-10-24 15:32:39 +0100177};
178
Alex Gildayc357c472018-03-21 13:54:09 +0000179/** Information about executing thread and CPU. */
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100180struct ThreadInfo
181{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100182 int thread_id{0};
183 int num_threads{1};
184 const CPUInfo *cpu_info{nullptr};
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100185};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100186} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000187#endif /* ARM_COMPUTE_CPP_TYPES_H */