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" |
| 28 | |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 29 | #if !defined(BARE_METAL) |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 30 | #include <sched.h> |
| 31 | #endif /* defined(BARE_METAL) */ |
| 32 | |
| 33 | using namespace arm_compute; |
| 34 | |
| 35 | void CPUInfo::set_fp16(const bool fp16) |
| 36 | { |
| 37 | _fp16 = fp16; |
| 38 | } |
| 39 | |
| 40 | void CPUInfo::set_dotprod(const bool dotprod) |
| 41 | { |
| 42 | _dotprod = dotprod; |
| 43 | } |
| 44 | |
| 45 | void CPUInfo::set_cpu_model(unsigned int cpuid, CPUModel model) |
| 46 | { |
| 47 | ARM_COMPUTE_ERROR_ON(cpuid >= _percpu.size()); |
| 48 | if(_percpu.size() > cpuid) |
| 49 | { |
| 50 | _percpu[cpuid] = model; |
| 51 | } |
| 52 | } |
| 53 | |
Anthony Barbier | 8914e32 | 2018-08-10 15:28:25 +0100 | [diff] [blame] | 54 | unsigned int CPUInfo::get_cpu_num() const |
| 55 | { |
| 56 | return _percpu.size(); |
| 57 | } |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 58 | bool CPUInfo::has_fp16() const |
| 59 | { |
| 60 | return _fp16; |
| 61 | } |
| 62 | |
| 63 | bool CPUInfo::has_dotprod() const |
| 64 | { |
| 65 | return _dotprod; |
| 66 | } |
| 67 | |
| 68 | CPUModel CPUInfo::get_cpu_model(unsigned int cpuid) const |
| 69 | { |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 70 | if(cpuid < _percpu.size()) |
| 71 | { |
| 72 | return _percpu[cpuid]; |
| 73 | } |
| 74 | return CPUModel::GENERIC; |
| 75 | } |
| 76 | |
| 77 | unsigned int CPUInfo::get_L1_cache_size() const |
| 78 | { |
| 79 | return _L1_cache_size; |
| 80 | } |
| 81 | |
| 82 | void CPUInfo::set_L1_cache_size(unsigned int size) |
| 83 | { |
| 84 | _L1_cache_size = size; |
| 85 | } |
| 86 | |
| 87 | unsigned int CPUInfo::get_L2_cache_size() const |
| 88 | { |
| 89 | return _L2_cache_size; |
| 90 | } |
| 91 | |
| 92 | void CPUInfo::set_L2_cache_size(unsigned int size) |
| 93 | { |
| 94 | _L2_cache_size = size; |
| 95 | } |
| 96 | |
| 97 | void CPUInfo::set_cpu_num(unsigned int cpu_count) |
| 98 | { |
| 99 | _percpu.resize(cpu_count); |
| 100 | } |
| 101 | |
| 102 | CPUInfo::CPUInfo() |
| 103 | : _percpu(1) |
| 104 | { |
| 105 | // The core library knows nothing about the CPUs so we set only 1 CPU to be generic. |
| 106 | // The runtime NESCheduler will initialise this vector with the correct CPU models. |
| 107 | // See void detect_cpus_configuration(CPUInfo &cpuinfo) in CPPUtils.h |
| 108 | _percpu[0] = CPUModel::GENERIC; |
| 109 | } |
| 110 | |
| 111 | CPUModel CPUInfo::get_cpu_model() const |
| 112 | { |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 113 | #if defined(BARE_METAL) || defined(__APPLE__) || (!defined(__arm__) && !defined(__aarch64__)) |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 114 | return get_cpu_model(0); |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 115 | #else /* defined(BARE_METAL) || defined(__APPLE__) || (!defined(__arm__) && !defined(__aarch64__)) */ |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 116 | return get_cpu_model(sched_getcpu()); |
Georgios Pinitas | 4551403 | 2020-12-30 00:03:09 +0000 | [diff] [blame] | 117 | #endif /* defined(BARE_METAL) || defined(__APPLE__) || (!defined(__arm__) && !defined(__aarch64__)) */ |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 118 | } |