From 08302c17cd57356b35d46e17dc8d8f76672da5cf Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Wed, 9 Jun 2021 10:08:27 +0100 Subject: Add CPU discovery capabilities. Resolves: COMPMID-4500 Signed-off-by: Georgios Pinitas Change-Id: I008c51934ef813fb1f489b531288c4419e701955 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5799 Reviewed-by: Michele Di Giorgio Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins --- src/core/CPP/CPPTypes.cpp | 92 ++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 65 deletions(-) (limited to 'src/core/CPP') diff --git a/src/core/CPP/CPPTypes.cpp b/src/core/CPP/CPPTypes.cpp index 0850df29fd..edcb9cb1ba 100644 --- a/src/core/CPP/CPPTypes.cpp +++ b/src/core/CPP/CPPTypes.cpp @@ -25,105 +25,67 @@ #include "arm_compute/core/CPP/CPPTypes.h" #include "arm_compute/core/Error.h" +#include "src/common/cpuinfo/CpuInfo.h" -#if !defined(BARE_METAL) -#include -#endif /* defined(BARE_METAL) */ - -using namespace arm_compute; - -void CPUInfo::set_fp16(const bool fp16) +namespace arm_compute { - _fp16 = fp16; -} - -void CPUInfo::set_dotprod(const bool dotprod) +struct CPUInfo::Impl { - _dotprod = dotprod; -} + cpuinfo::CpuInfo info{}; + unsigned int L1_cache_size = 32768; + unsigned int L2_cache_size = 262144; +}; -void CPUInfo::set_sve(const bool sve) +CPUInfo::CPUInfo() + : _impl(std::make_unique()) { - _sve = sve; + _impl->info = cpuinfo::CpuInfo::build(); } -void CPUInfo::set_cpu_model(unsigned int cpuid, CPUModel model) -{ - ARM_COMPUTE_ERROR_ON(cpuid >= _percpu.size()); - if(_percpu.size() > cpuid) - { - _percpu[cpuid] = model; - } -} +CPUInfo::~CPUInfo() = default; unsigned int CPUInfo::get_cpu_num() const { - return _percpu.size(); + return _impl->info.num_cpus(); } bool CPUInfo::has_sve() const { - return _sve; + return _impl->info.has_sve(); } bool CPUInfo::has_fp16() const { - return _fp16; -} - -bool CPUInfo::has_dotprod() const -{ - return _dotprod; -} - -CPUModel CPUInfo::get_cpu_model(unsigned int cpuid) const -{ - if(cpuid < _percpu.size()) - { - return _percpu[cpuid]; - } - return CPUModel::GENERIC; + return _impl->info.has_fp16(); } -unsigned int CPUInfo::get_L1_cache_size() const +bool CPUInfo::has_bf16() const { - return _L1_cache_size; + return _impl->info.has_bf16(); } -void CPUInfo::set_L1_cache_size(unsigned int size) -{ - _L1_cache_size = size; -} - -unsigned int CPUInfo::get_L2_cache_size() const +bool CPUInfo::has_dotprod() const { - return _L2_cache_size; + return _impl->info.has_dotprod(); } -void CPUInfo::set_L2_cache_size(unsigned int size) +CPUModel CPUInfo::get_cpu_model() const { - _L2_cache_size = size; + return _impl->info.cpu_model(); } -void CPUInfo::set_cpu_num(unsigned int cpu_count) +CPUModel CPUInfo::get_cpu_model(unsigned int cpuid) const { - _percpu.resize(cpu_count); + return _impl->info.cpu_model(cpuid); } -CPUInfo::CPUInfo() - : _percpu(1) +unsigned int CPUInfo::get_L1_cache_size() const { - // The core library knows nothing about the CPUs so we set only 1 CPU to be generic. - // The runtime NESCheduler will initialise this vector with the correct CPU models. - // See void detect_cpus_configuration(CPUInfo &cpuinfo) in CPPUtils.h - _percpu[0] = CPUModel::GENERIC; + return _impl->L1_cache_size; } -CPUModel CPUInfo::get_cpu_model() const +unsigned int CPUInfo::get_L2_cache_size() const { -#if defined(BARE_METAL) || defined(__APPLE__) || (!defined(__arm__) && !defined(__aarch64__)) - return get_cpu_model(0); -#else /* defined(BARE_METAL) || defined(__APPLE__) || (!defined(__arm__) && !defined(__aarch64__)) */ - return get_cpu_model(sched_getcpu()); -#endif /* defined(BARE_METAL) || defined(__APPLE__) || (!defined(__arm__) && !defined(__aarch64__)) */ + return _impl->L2_cache_size; } +} // namespace arm_compute -- cgit v1.2.1