Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 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" |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 28 | #include "src/common/cpuinfo/CpuInfo.h" |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 29 | |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 30 | namespace arm_compute |
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 | struct CPUInfo::Impl |
| 33 | { |
| 34 | cpuinfo::CpuInfo info{}; |
| 35 | unsigned int L1_cache_size = 32768; |
| 36 | unsigned int L2_cache_size = 262144; |
| 37 | }; |
| 38 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 39 | CPUInfo &CPUInfo::get() |
| 40 | { |
| 41 | static CPUInfo _cpuinfo; |
| 42 | return _cpuinfo; |
| 43 | } |
| 44 | |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 45 | CPUInfo::CPUInfo() |
| 46 | : _impl(std::make_unique<Impl>()) |
| 47 | { |
| 48 | _impl->info = cpuinfo::CpuInfo::build(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 51 | CPUInfo::~CPUInfo() = default; |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 52 | |
Anthony Barbier | 8914e32 | 2018-08-10 15:28:25 +0100 | [diff] [blame] | 53 | unsigned int CPUInfo::get_cpu_num() const |
| 54 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 55 | return _impl->info.num_cpus(); |
Anthony Barbier | 8914e32 | 2018-08-10 15:28:25 +0100 | [diff] [blame] | 56 | } |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 57 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 58 | bool CPUInfo::has_fp16() const |
| 59 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 60 | return _impl->info.has_fp16(); |
| 61 | } |
| 62 | |
| 63 | bool CPUInfo::has_bf16() const |
| 64 | { |
| 65 | return _impl->info.has_bf16(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 68 | bool CPUInfo::has_svebf16() const |
| 69 | { |
| 70 | return _impl->info.has_svebf16(); |
| 71 | } |
| 72 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 73 | bool CPUInfo::has_dotprod() const |
| 74 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 75 | return _impl->info.has_dotprod(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 78 | bool CPUInfo::has_svef32mm() const |
| 79 | { |
| 80 | return _impl->info.has_svef32mm(); |
| 81 | } |
| 82 | |
| 83 | bool CPUInfo::has_i8mm() const |
| 84 | { |
| 85 | return _impl->info.has_i8mm(); |
| 86 | } |
| 87 | |
| 88 | bool CPUInfo::has_svei8mm() const |
| 89 | { |
| 90 | return _impl->info.has_svei8mm(); |
| 91 | } |
| 92 | |
| 93 | bool CPUInfo::has_sve() const |
| 94 | { |
| 95 | return _impl->info.has_sve(); |
| 96 | } |
| 97 | |
| 98 | bool CPUInfo::has_sve2() const |
| 99 | { |
| 100 | return _impl->info.has_sve2(); |
| 101 | } |
| 102 | |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 103 | CPUModel CPUInfo::get_cpu_model() const |
| 104 | { |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 105 | return _impl->info.cpu_model(); |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 106 | } |
Georgios Pinitas | 08302c1 | 2021-06-09 10:08:27 +0100 | [diff] [blame] | 107 | |
| 108 | CPUModel CPUInfo::get_cpu_model(unsigned int cpuid) const |
| 109 | { |
| 110 | return _impl->info.cpu_model(cpuid); |
| 111 | } |
| 112 | |
| 113 | unsigned int CPUInfo::get_L1_cache_size() const |
| 114 | { |
| 115 | return _impl->L1_cache_size; |
| 116 | } |
| 117 | |
| 118 | unsigned int CPUInfo::get_L2_cache_size() const |
| 119 | { |
| 120 | return _impl->L2_cache_size; |
| 121 | } |
| 122 | } // namespace arm_compute |