Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 1 | /* |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2022 Arm Limited. |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [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 | |
| 25 | #include "arm_compute/core/CPP/CPPTypes.h" |
| 26 | |
| 27 | #include "arm_compute/core/Error.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 28 | |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 29 | #include "src/common/cpuinfo/CpuInfo.h" |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 30 | #include "src/common/cpuinfo/CpuIsaInfo.h" |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 31 | |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 32 | namespace arm_compute |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 33 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 34 | struct CPUInfo::Impl |
| 35 | { |
| 36 | cpuinfo::CpuInfo info{}; |
| 37 | unsigned int L1_cache_size = 32768; |
| 38 | unsigned int L2_cache_size = 262144; |
| 39 | }; |
| 40 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 41 | CPUInfo &CPUInfo::get() |
| 42 | { |
| 43 | static CPUInfo _cpuinfo; |
| 44 | return _cpuinfo; |
| 45 | } |
| 46 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 47 | CPUInfo::CPUInfo() : _impl(std::make_unique<Impl>()) |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 48 | { |
| 49 | _impl->info = cpuinfo::CpuInfo::build(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 52 | CPUInfo::~CPUInfo() = default; |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 53 | |
Anthony Barbier | 8914e32 | 2018-08-10 15:28:25 +0100 | [diff] [blame] | 54 | unsigned int CPUInfo::get_cpu_num() const |
| 55 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 56 | return _impl->info.num_cpus(); |
Anthony Barbier | 8914e32 | 2018-08-10 15:28:25 +0100 | [diff] [blame] | 57 | } |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 58 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 59 | bool CPUInfo::has_fp16() const |
| 60 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 61 | return _impl->info.has_fp16(); |
| 62 | } |
| 63 | |
| 64 | bool CPUInfo::has_bf16() const |
| 65 | { |
| 66 | return _impl->info.has_bf16(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 69 | bool CPUInfo::has_svebf16() const |
| 70 | { |
| 71 | return _impl->info.has_svebf16(); |
| 72 | } |
| 73 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 74 | bool CPUInfo::has_dotprod() const |
| 75 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 76 | return _impl->info.has_dotprod(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 79 | bool CPUInfo::has_svef32mm() const |
| 80 | { |
| 81 | return _impl->info.has_svef32mm(); |
| 82 | } |
| 83 | |
| 84 | bool CPUInfo::has_i8mm() const |
| 85 | { |
| 86 | return _impl->info.has_i8mm(); |
| 87 | } |
| 88 | |
| 89 | bool CPUInfo::has_svei8mm() const |
| 90 | { |
| 91 | return _impl->info.has_svei8mm(); |
| 92 | } |
| 93 | |
| 94 | bool CPUInfo::has_sve() const |
| 95 | { |
| 96 | return _impl->info.has_sve(); |
| 97 | } |
| 98 | |
| 99 | bool CPUInfo::has_sve2() const |
| 100 | { |
| 101 | return _impl->info.has_sve2(); |
| 102 | } |
| 103 | |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 104 | bool CPUInfo::has_sme() const |
| 105 | { |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 106 | return _impl->info.has_sme(); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | bool CPUInfo::has_sme2() const |
| 110 | { |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 111 | return _impl->info.has_sme2(); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 114 | CPUModel CPUInfo::get_cpu_model() const |
| 115 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 116 | return _impl->info.cpu_model(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 117 | } |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 118 | |
| 119 | CPUModel CPUInfo::get_cpu_model(unsigned int cpuid) const |
| 120 | { |
| 121 | return _impl->info.cpu_model(cpuid); |
| 122 | } |
| 123 | |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 124 | cpuinfo::CpuIsaInfo CPUInfo::get_isa() const |
| 125 | { |
| 126 | return _impl->info.isa(); |
| 127 | } |
| 128 | |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 129 | unsigned int CPUInfo::get_L1_cache_size() const |
| 130 | { |
| 131 | return _impl->L1_cache_size; |
| 132 | } |
| 133 | |
| 134 | unsigned int CPUInfo::get_L2_cache_size() const |
| 135 | { |
| 136 | return _impl->L2_cache_size; |
| 137 | } |
| 138 | } // namespace arm_compute |