blob: 4484271d635da0bdbe160682664a9b881f657872 [file] [log] [blame]
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +01001/*
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +00002 * Copyright (c) 2017-2021 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{
Georgios Pinitas08302c12021-06-09 10:08:27 +010033#define ARM_COMPUTE_CPU_MODEL_LIST \
34 X(GENERIC) \
35 X(GENERIC_FP16) \
36 X(GENERIC_FP16_DOT) \
37 X(A35) \
38 X(A53) \
39 X(A55r0) \
40 X(A55r1) \
41 X(A73) \
42 X(KLEIN) \
43 X(X1)
44
45/** CPU models types
Pablo Tello7fad9b12018-03-14 17:55:27 +000046 *
Georgios Pinitas08302c12021-06-09 10:08:27 +010047 * @note We only need to detect CPUs we have microarchitecture-specific code for.
48 * @note Architecture features are detected via HWCAPs.
Pablo Tello7fad9b12018-03-14 17:55:27 +000049 */
50enum class CPUModel
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010051{
Georgios Pinitas08302c12021-06-09 10:08:27 +010052#define X(model) model,
53 ARM_COMPUTE_CPU_MODEL_LIST
54#undef X
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010055};
Moritz Pflanzerc186b572017-09-07 09:48:04 +010056
Pablo Tello7fad9b12018-03-14 17:55:27 +000057class CPUInfo final
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010058{
Michalis Spyrou20fca522021-06-07 14:23:57 +010059protected:
Pablo Tello7fad9b12018-03-14 17:55:27 +000060 CPUInfo();
Georgios Pinitas08302c12021-06-09 10:08:27 +010061 ~CPUInfo();
Pablo Tello7fad9b12018-03-14 17:55:27 +000062
Michalis Spyrou20fca522021-06-07 14:23:57 +010063public:
64 /** Access the KernelLibrary singleton.
65 * This method has been deprecated and will be removed in future releases
66 * @return The KernelLibrary instance.
Pablo Tello7fad9b12018-03-14 17:55:27 +000067 */
Michalis Spyrou20fca522021-06-07 14:23:57 +010068 static CPUInfo &get();
69
70 /* Delete move and copy constructors and assignment operator
71 s */
72 CPUInfo(CPUInfo const &) = delete; // Copy construct
73 CPUInfo(CPUInfo &&) = delete; // Move construct
74 CPUInfo &operator=(CPUInfo const &) = delete; // Copy assign
75 CPUInfo &operator=(CPUInfo &&) = delete; // Move assign
Pablo Tello7fad9b12018-03-14 17:55:27 +000076
77 /** Checks if the cpu model supports fp16.
78 *
79 * @return true of the cpu supports fp16, false otherwise
80 */
81 bool has_fp16() const;
Georgios Pinitas08302c12021-06-09 10:08:27 +010082 /** Checks if the cpu model supports bf16.
83 *
84 * @return true of the cpu supports bf16, false otherwise
85 */
86 bool has_bf16() const;
Michalis Spyrou20fca522021-06-07 14:23:57 +010087 /** Checks if the cpu model supports bf16.
88 *
89 * @return true of the cpu supports bf16, false otherwise
90 */
91 bool has_svebf16() const;
Pablo Tello7fad9b12018-03-14 17:55:27 +000092 /** Checks if the cpu model supports dot product.
93 *
94 * @return true of the cpu supports dot product, false otherwise
95 */
96 bool has_dotprod() const;
Michalis Spyrou20fca522021-06-07 14:23:57 +010097 /** Checks if the cpu model supports floating-point matrix multiplication.
98 *
99 * @return true of the cpu supports floating-point matrix multiplication, false otherwise
100 */
101 bool has_svef32mm() const;
102 /** Checks if the cpu model supports integer matrix multiplication.
103 *
104 * @return true of the cpu supports integer matrix multiplication, false otherwise
105 */
106 bool has_i8mm() const;
107 /** Checks if the cpu model supports integer matrix multiplication.
108 *
109 * @return true of the cpu supports integer matrix multiplication, false otherwise
110 */
111 bool has_svei8mm() const;
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +0000112 /** Checks if the cpu model supports sve.
113 *
114 * @return true of the cpu supports sve, false otherwise
115 */
116 bool has_sve() const;
Michalis Spyrou20fca522021-06-07 14:23:57 +0100117 /** Checks if the cpu model supports sve2.
118 *
119 * @return true of the cpu supports sve2, false otherwise
120 */
121 bool has_sve2() const;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000122 /** Gets the cpu model for a given cpuid.
123 *
124 * @param[in] cpuid the id of the cpu core to be retrieved,
125 *
126 * @return the @ref CPUModel of the cpuid queiried.
127 */
128 CPUModel get_cpu_model(unsigned int cpuid) const;
129 /** Gets the current thread's cpu model
130 *
131 * @return Current thread's @ref CPUModel
132 */
133 CPUModel get_cpu_model() const;
134 /** Gets the L1 cache size
135 *
136 * @return the size of the L1 cache
137 */
138 unsigned int get_L1_cache_size() const;
139 /** Gets the L2 cache size
140 *
141 * @return the size of the L1 cache
142 */
143 unsigned int get_L2_cache_size() const;
Anthony Barbier8914e322018-08-10 15:28:25 +0100144 /** Return the maximum number of CPUs present
145 *
146 * @return Number of CPUs
147 */
148 unsigned int get_cpu_num() const;
149
Pablo Tello7fad9b12018-03-14 17:55:27 +0000150private:
Georgios Pinitas08302c12021-06-09 10:08:27 +0100151 struct Impl;
152 std::unique_ptr<Impl> _impl;
Pablo Tello0cf77982018-10-24 15:32:39 +0100153};
154
Alex Gildayc357c472018-03-21 13:54:09 +0000155/** Information about executing thread and CPU. */
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100156struct ThreadInfo
157{
Pablo Tello7fad9b12018-03-14 17:55:27 +0000158 int thread_id{ 0 };
159 int num_threads{ 1 };
160 const CPUInfo *cpu_info{ nullptr };
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100161};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100162} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000163#endif /* ARM_COMPUTE_CPP_TYPES_H */