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) \ |
| 51 | X(A64FX) |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 52 | |
| 53 | /** CPU models types |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 54 | * |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 55 | * @note We only need to detect CPUs we have microarchitecture-specific code for. |
| 56 | * @note Architecture features are detected via HWCAPs. |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 57 | */ |
| 58 | enum class CPUModel |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 59 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 60 | #define X(model) model, |
| 61 | ARM_COMPUTE_CPU_MODEL_LIST |
| 62 | #undef X |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 63 | }; |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 64 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 65 | class CPUInfo final |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 66 | { |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 67 | protected: |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 68 | CPUInfo(); |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 69 | ~CPUInfo(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 70 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 71 | public: |
| 72 | /** Access the KernelLibrary singleton. |
| 73 | * This method has been deprecated and will be removed in future releases |
| 74 | * @return The KernelLibrary instance. |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 75 | */ |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 76 | 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 Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 84 | |
| 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 Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 90 | /** 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 Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 95 | /** 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 Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 100 | /** 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 Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 105 | /** 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 Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 120 | /** 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 Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 125 | /** Checks if the cpu model supports sve2. |
| 126 | * |
| 127 | * @return true of the cpu supports sve2, false otherwise |
| 128 | */ |
| 129 | bool has_sve2() const; |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 130 | /** Gets the cpu model for a given cpuid. |
| 131 | * |
| 132 | * @param[in] cpuid the id of the cpu core to be retrieved, |
| 133 | * |
| 134 | * @return the @ref CPUModel of the cpuid queiried. |
| 135 | */ |
| 136 | CPUModel get_cpu_model(unsigned int cpuid) const; |
| 137 | /** Gets the current thread's cpu model |
| 138 | * |
| 139 | * @return Current thread's @ref CPUModel |
| 140 | */ |
| 141 | CPUModel get_cpu_model() const; |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame^] | 142 | /** Gets the current cpu's ISA information |
| 143 | * |
| 144 | * @return Current cpu's ISA information |
| 145 | */ |
| 146 | cpuinfo::CpuIsaInfo get_isa() const; |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 147 | /** Gets the L1 cache size |
| 148 | * |
| 149 | * @return the size of the L1 cache |
| 150 | */ |
| 151 | unsigned int get_L1_cache_size() const; |
| 152 | /** Gets the L2 cache size |
| 153 | * |
| 154 | * @return the size of the L1 cache |
| 155 | */ |
| 156 | unsigned int get_L2_cache_size() const; |
Anthony Barbier | 8914e32 | 2018-08-10 15:28:25 +0100 | [diff] [blame] | 157 | /** Return the maximum number of CPUs present |
| 158 | * |
| 159 | * @return Number of CPUs |
| 160 | */ |
| 161 | unsigned int get_cpu_num() const; |
| 162 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 163 | private: |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 164 | struct Impl; |
| 165 | std::unique_ptr<Impl> _impl; |
Pablo Tello | 0cf7798 | 2018-10-24 15:32:39 +0100 | [diff] [blame] | 166 | }; |
| 167 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 168 | /** Information about executing thread and CPU. */ |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 169 | struct ThreadInfo |
| 170 | { |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 171 | int thread_id{ 0 }; |
| 172 | int num_threads{ 1 }; |
| 173 | const CPUInfo *cpu_info{ nullptr }; |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 174 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 175 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 176 | #endif /* ARM_COMPUTE_CPP_TYPES_H */ |