Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 1 | /* |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 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 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 33 | #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 Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 46 | * |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 47 | * @note We only need to detect CPUs we have microarchitecture-specific code for. |
| 48 | * @note Architecture features are detected via HWCAPs. |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 49 | */ |
| 50 | enum class CPUModel |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 51 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 52 | #define X(model) model, |
| 53 | ARM_COMPUTE_CPU_MODEL_LIST |
| 54 | #undef X |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 55 | }; |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 56 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 57 | class CPUInfo final |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 58 | { |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 59 | protected: |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 60 | CPUInfo(); |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 61 | ~CPUInfo(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 62 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 63 | public: |
| 64 | /** Access the KernelLibrary singleton. |
| 65 | * This method has been deprecated and will be removed in future releases |
| 66 | * @return The KernelLibrary instance. |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 67 | */ |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 68 | 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 Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 76 | |
| 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 Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 82 | /** 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 Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 87 | /** 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 Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 92 | /** 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 Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 97 | /** 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 Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 112 | /** 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 Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 117 | /** 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 Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 122 | /** 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 Barbier | 8914e32 | 2018-08-10 15:28:25 +0100 | [diff] [blame] | 144 | /** Return the maximum number of CPUs present |
| 145 | * |
| 146 | * @return Number of CPUs |
| 147 | */ |
| 148 | unsigned int get_cpu_num() const; |
| 149 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 150 | private: |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 151 | struct Impl; |
| 152 | std::unique_ptr<Impl> _impl; |
Pablo Tello | 0cf7798 | 2018-10-24 15:32:39 +0100 | [diff] [blame] | 153 | }; |
| 154 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 155 | /** Information about executing thread and CPU. */ |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 156 | struct ThreadInfo |
| 157 | { |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 158 | int thread_id{ 0 }; |
| 159 | int num_threads{ 1 }; |
| 160 | const CPUInfo *cpu_info{ nullptr }; |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 161 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 162 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 163 | #endif /* ARM_COMPUTE_CPP_TYPES_H */ |