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