Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 1 | /* |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2022 Arm Limited. |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CPP_TYPES_H |
| 25 | #define ARM_COMPUTE_CPP_TYPES_H |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 26 | |
Pablo Tello | 4e0ac6f | 2018-10-01 14:31:11 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Error.h" |
| 28 | |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 29 | #include <memory> |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 30 | |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 31 | namespace arm_compute |
| 32 | { |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 33 | namespace cpuinfo |
| 34 | { |
| 35 | struct CpuIsaInfo; |
| 36 | } // namespace cpuinfo |
| 37 | |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 38 | #define ARM_COMPUTE_CPU_MODEL_LIST \ |
| 39 | X(GENERIC) \ |
| 40 | X(GENERIC_FP16) \ |
| 41 | X(GENERIC_FP16_DOT) \ |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 42 | X(A53) \ |
| 43 | X(A55r0) \ |
| 44 | X(A55r1) \ |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 45 | X(A35) \ |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 46 | X(A73) \ |
Mohammed Suhail Munshi | cff6f3b | 2021-12-09 17:36:25 +0000 | [diff] [blame] | 47 | X(A76) \ |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 48 | X(A510) \ |
| 49 | X(X1) \ |
| 50 | X(V1) \ |
Fadi Arafeh | 73bb6b7 | 2022-10-06 16:20:14 +0000 | [diff] [blame] | 51 | X(A64FX) \ |
| 52 | X(N1) |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 53 | |
| 54 | /** CPU models types |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 55 | * |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 56 | * @note We only need to detect CPUs we have microarchitecture-specific code for. |
| 57 | * @note Architecture features are detected via HWCAPs. |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 58 | */ |
| 59 | enum class CPUModel |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 60 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 61 | #define X(model) model, |
| 62 | ARM_COMPUTE_CPU_MODEL_LIST |
| 63 | #undef X |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 64 | }; |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 65 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 66 | class CPUInfo final |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 67 | { |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 68 | protected: |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 69 | CPUInfo(); |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 70 | ~CPUInfo(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 71 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 72 | public: |
| 73 | /** Access the KernelLibrary singleton. |
| 74 | * This method has been deprecated and will be removed in future releases |
| 75 | * @return The KernelLibrary instance. |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 76 | */ |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 77 | static CPUInfo &get(); |
| 78 | |
| 79 | /* Delete move and copy constructors and assignment operator |
| 80 | s */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 81 | CPUInfo(CPUInfo const &) = delete; // Copy construct |
| 82 | CPUInfo(CPUInfo &&) = delete; // Move construct |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 83 | CPUInfo &operator=(CPUInfo const &) = delete; // Copy assign |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 84 | CPUInfo &operator=(CPUInfo &&) = delete; // Move assign |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 85 | |
| 86 | /** Checks if the cpu model supports fp16. |
| 87 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 88 | * @return true if the cpu supports fp16, false otherwise |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 89 | */ |
| 90 | bool has_fp16() const; |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 91 | /** Checks if the cpu model supports bf16. |
| 92 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 93 | * @return true if the cpu supports bf16, false otherwise |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 94 | */ |
| 95 | bool has_bf16() const; |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 96 | /** Checks if the cpu model supports bf16. |
| 97 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 98 | * @return true if the cpu supports bf16, false otherwise |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 99 | */ |
| 100 | bool has_svebf16() const; |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 101 | /** Checks if the cpu model supports dot product. |
| 102 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 103 | * @return true if the cpu supports dot product, false otherwise |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 104 | */ |
| 105 | bool has_dotprod() const; |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 106 | /** Checks if the cpu model supports floating-point matrix multiplication. |
| 107 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 108 | * @return true if the cpu supports floating-point matrix multiplication, false otherwise |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 109 | */ |
| 110 | bool has_svef32mm() const; |
| 111 | /** Checks if the cpu model supports integer matrix multiplication. |
| 112 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 113 | * @return true if the cpu supports integer matrix multiplication, false otherwise |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 114 | */ |
| 115 | bool has_i8mm() const; |
| 116 | /** Checks if the cpu model supports integer matrix multiplication. |
| 117 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 118 | * @return true if the cpu supports integer matrix multiplication, false otherwise |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 119 | */ |
| 120 | bool has_svei8mm() const; |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 121 | /** Checks if the cpu model supports sve. |
| 122 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 123 | * @return true if the cpu supports sve, false otherwise |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 124 | */ |
| 125 | bool has_sve() const; |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 126 | /** Checks if the cpu model supports sve2. |
| 127 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 128 | * @return true if the cpu supports sve2, false otherwise |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 129 | */ |
| 130 | bool has_sve2() const; |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 131 | /** Checks if the cpu model supports sme. |
| 132 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 133 | * @return true if the cpu supports sme, false otherwise |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 134 | */ |
| 135 | bool has_sme() const; |
| 136 | /** Checks if the cpu model supports sme2. |
| 137 | * |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 138 | * @return true if the cpu supports sme2, false otherwise |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 139 | */ |
| 140 | bool has_sme2() const; |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 141 | /** 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 Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 153 | /** Gets the current cpu's ISA information |
| 154 | * |
| 155 | * @return Current cpu's ISA information |
| 156 | */ |
| 157 | cpuinfo::CpuIsaInfo get_isa() const; |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 158 | /** 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 Barbier | 8914e32 | 2018-08-10 15:28:25 +0100 | [diff] [blame] | 168 | /** Return the maximum number of CPUs present |
| 169 | * |
| 170 | * @return Number of CPUs |
| 171 | */ |
| 172 | unsigned int get_cpu_num() const; |
| 173 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 174 | private: |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 175 | struct Impl; |
| 176 | std::unique_ptr<Impl> _impl; |
Pablo Tello | 0cf7798 | 2018-10-24 15:32:39 +0100 | [diff] [blame] | 177 | }; |
| 178 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 179 | /** Information about executing thread and CPU. */ |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 180 | struct ThreadInfo |
| 181 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 182 | int thread_id{0}; |
| 183 | int num_threads{1}; |
| 184 | const CPUInfo *cpu_info{nullptr}; |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 185 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 186 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 187 | #endif /* ARM_COMPUTE_CPP_TYPES_H */ |