Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 1 | /* |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 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 | */ |
| 24 | #ifndef __ARM_COMPUTE_CPP_TYPES_H__ |
| 25 | #define __ARM_COMPUTE_CPP_TYPES_H__ |
| 26 | |
Pablo Tello | 4e0ac6f | 2018-10-01 14:31:11 +0100 | [diff] [blame^] | 27 | #include "arm_compute/core/Error.h" |
| 28 | |
| 29 | #include <string> |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 30 | #include <vector> |
| 31 | |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 32 | namespace arm_compute |
| 33 | { |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 34 | /** CPU models - we only need to detect CPUs we have |
| 35 | * microarchitecture-specific code for. |
| 36 | * |
| 37 | * Architecture features are detected via HWCAPs. |
| 38 | */ |
| 39 | enum class CPUModel |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 40 | { |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 41 | GENERIC, |
Anthony Barbier | 5a3ee4f | 2018-07-24 11:24:17 +0100 | [diff] [blame] | 42 | GENERIC_FP16, |
| 43 | GENERIC_FP16_DOT, |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 44 | A53, |
| 45 | A55r0, |
Anthony Barbier | 5a3ee4f | 2018-07-24 11:24:17 +0100 | [diff] [blame] | 46 | A55r1 |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 47 | }; |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 48 | |
Pablo Tello | 4e0ac6f | 2018-10-01 14:31:11 +0100 | [diff] [blame^] | 49 | /** Convert a cpumodel value to a string |
| 50 | * |
| 51 | * @param val CPUModel value to be converted |
| 52 | * |
| 53 | * @return String representing the corresponding CPUModel. |
| 54 | */ |
| 55 | inline std::string cpu_model_to_string(CPUModel val) |
| 56 | { |
| 57 | switch(val) |
| 58 | { |
| 59 | case CPUModel::GENERIC: |
| 60 | { |
| 61 | return std::string("GENERIC"); |
| 62 | } |
| 63 | case CPUModel::GENERIC_FP16: |
| 64 | { |
| 65 | return std::string("GENERIC_FP16"); |
| 66 | } |
| 67 | case CPUModel::GENERIC_FP16_DOT: |
| 68 | { |
| 69 | return std::string("GENERIC_FP16_DOT"); |
| 70 | } |
| 71 | case CPUModel::A53: |
| 72 | { |
| 73 | return std::string("A53"); |
| 74 | } |
| 75 | case CPUModel::A55r0: |
| 76 | { |
| 77 | return std::string("A55r0"); |
| 78 | } |
| 79 | case CPUModel::A55r1: |
| 80 | { |
| 81 | return std::string("A55r1"); |
| 82 | } |
| 83 | default: |
| 84 | { |
| 85 | ARM_COMPUTE_ERROR("Invalid CPUModel."); |
| 86 | return std::string("GENERIC"); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 91 | class CPUInfo final |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 92 | { |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 93 | public: |
| 94 | /** Constructor */ |
| 95 | CPUInfo(); |
| 96 | |
| 97 | /** Disable copy constructor and assignment operator to avoid copying the vector of CPUs each time |
| 98 | * CPUInfo is initialized once in the IScheduler and ThreadInfo will get a pointer to it. |
| 99 | */ |
| 100 | CPUInfo &operator=(const CPUInfo &cpuinfo) = delete; |
| 101 | CPUInfo(const CPUInfo &cpuinfo) = delete; |
| 102 | CPUInfo &operator=(const CPUInfo &&cpuinfo) = delete; |
| 103 | CPUInfo(const CPUInfo &&cpuinfo) = delete; |
| 104 | |
| 105 | /** Checks if the cpu model supports fp16. |
| 106 | * |
| 107 | * @return true of the cpu supports fp16, false otherwise |
| 108 | */ |
| 109 | bool has_fp16() const; |
| 110 | /** Checks if the cpu model supports dot product. |
| 111 | * |
| 112 | * @return true of the cpu supports dot product, false otherwise |
| 113 | */ |
| 114 | bool has_dotprod() const; |
| 115 | /** Gets the cpu model for a given cpuid. |
| 116 | * |
| 117 | * @param[in] cpuid the id of the cpu core to be retrieved, |
| 118 | * |
| 119 | * @return the @ref CPUModel of the cpuid queiried. |
| 120 | */ |
| 121 | CPUModel get_cpu_model(unsigned int cpuid) const; |
| 122 | /** Gets the current thread's cpu model |
| 123 | * |
| 124 | * @return Current thread's @ref CPUModel |
| 125 | */ |
| 126 | CPUModel get_cpu_model() const; |
| 127 | /** Gets the L1 cache size |
| 128 | * |
| 129 | * @return the size of the L1 cache |
| 130 | */ |
| 131 | unsigned int get_L1_cache_size() const; |
| 132 | /** Gets the L2 cache size |
| 133 | * |
| 134 | * @return the size of the L1 cache |
| 135 | */ |
| 136 | unsigned int get_L2_cache_size() const; |
| 137 | /** Set the L1 cache size |
| 138 | * |
| 139 | * @param[in] size the new size to be set. |
| 140 | */ |
| 141 | void set_L1_cache_size(unsigned int size); |
| 142 | /** Set the L2 cache size |
| 143 | * |
| 144 | * @param[in] size the new size to be set. |
| 145 | */ |
| 146 | void set_L2_cache_size(unsigned int size); |
| 147 | /** Set fp16 support |
| 148 | * |
| 149 | * @param[in] fp16 whether the cpu supports fp16. |
| 150 | */ |
| 151 | void set_fp16(const bool fp16); |
| 152 | /** Set dot product support |
| 153 | * |
| 154 | * @param[in] dotprod whether the cpu supports dot product. |
| 155 | */ |
| 156 | void set_dotprod(const bool dotprod); |
| 157 | /** Set the cpumodel for a given cpu core |
| 158 | * |
| 159 | * @param[in] cpuid the id of the core to be set. |
| 160 | * @param[in] model the @ref CPUModel to be set. |
| 161 | */ |
| 162 | void set_cpu_model(unsigned int cpuid, CPUModel model); |
| 163 | /** Set max number of cpus |
| 164 | * |
| 165 | * @param[in] cpu_count the number of CPUs in the system. |
| 166 | */ |
| 167 | void set_cpu_num(unsigned int cpu_count); |
| 168 | |
Anthony Barbier | 8914e32 | 2018-08-10 15:28:25 +0100 | [diff] [blame] | 169 | /** Return the maximum number of CPUs present |
| 170 | * |
| 171 | * @return Number of CPUs |
| 172 | */ |
| 173 | unsigned int get_cpu_num() const; |
| 174 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 175 | private: |
| 176 | std::vector<CPUModel> _percpu = {}; |
| 177 | bool _fp16 = false; |
| 178 | bool _dotprod = false; |
| 179 | unsigned int _L1_cache_size = 32768; |
| 180 | unsigned int _L2_cache_size = 262144; |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 181 | }; |
| 182 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 183 | /** Information about executing thread and CPU. */ |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 184 | struct ThreadInfo |
| 185 | { |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 186 | int thread_id{ 0 }; |
| 187 | int num_threads{ 1 }; |
| 188 | const CPUInfo *cpu_info{ nullptr }; |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 189 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 190 | } // namespace arm_compute |
Moritz Pflanzer | d929b9c | 2017-06-28 10:15:48 +0100 | [diff] [blame] | 191 | #endif /* __ARM_COMPUTE_CPP_TYPES_H__ */ |