Compute Library
 22.05
CpuInfo Class Reference

Aggregate class that contains CPU related information. More...

#include <CpuInfo.h>

Public Member Functions

 CpuInfo ()=default
 Default constructor. More...
 
 CpuInfo (CpuIsaInfo isa, std::vector< CpuModel > cpus)
 Construct a new Cpu Info object. More...
 
bool has_neon () const
 
bool has_sve () const
 
bool has_sve2 () const
 
bool has_fp16 () const
 
bool has_bf16 () const
 
bool has_svebf16 () const
 
bool has_dotprod () const
 
bool has_i8mm () const
 
bool has_svei8mm () const
 
bool has_svef32mm () const
 
const CpuIsaInfoisa () const
 
const std::vector< CpuModel > & cpus () const
 
CpuModel cpu_model (uint32_t cpuid) const
 
CpuModel cpu_model () const
 
uint32_t num_cpus () const
 

Static Public Member Functions

static CpuInfo build ()
 CpuInfo builder function from system related information. More...
 

Detailed Description

Aggregate class that contains CPU related information.

Contains information about the numbers of the CPUs, the model of each CPU, ISA related information and more

Note
We can safely assume that the ISA is common between different clusters of cores

Definition at line 44 of file CpuInfo.h.

Constructor & Destructor Documentation

◆ CpuInfo() [1/2]

CpuInfo ( )
default

Default constructor.

◆ CpuInfo() [2/2]

CpuInfo ( CpuIsaInfo  isa,
std::vector< CpuModel cpus 
)

Construct a new Cpu Info object.

Parameters
[in]isaISA capabilities information
[in]cpusCPU models information

Definition at line 298 of file CpuInfo.cpp.

299  : _isa(std::move(isa)), _cpus(std::move(cpus))
300 {
301 }
const std::vector< CpuModel > & cpus() const
Definition: CpuInfo.h:107
const CpuIsaInfo & isa() const
Definition: CpuInfo.h:103

Member Function Documentation

◆ build()

CpuInfo build ( )
static

CpuInfo builder function from system related information.

Returns
CpuInfo A populated CpuInfo structure

Definition at line 303 of file CpuInfo.cpp.

References ARM_COMPUTE_CPU_FEATURE_HWCAP_CPUID, ARM_COMPUTE_GET_FEATURE_REG, CpuIsaInfo::dot, arm_compute::mlgo::parser::end(), CpuIsaInfo::fp16, arm_compute::GENERIC, arm_compute::test::validation::info, arm_compute::cpuinfo::init_cpu_isa_from_hwcaps(), arm_compute::cpuinfo::init_cpu_isa_from_regs(), CpuInfo::isa(), arm_compute::cpuinfo::midr_to_model(), and CpuIsaInfo::neon.

Referenced by CPUInfo::get().

304 {
305 #if !defined(_WIN64) && !defined(BARE_METAL) && !defined(__APPLE__) && !defined(__OpenBSD__) && (defined(__arm__) || defined(__aarch64__))
306  const uint32_t hwcaps = getauxval(AT_HWCAP);
307  const uint32_t hwcaps2 = getauxval(AT_HWCAP2);
308  const uint32_t max_cpus = get_max_cpus();
309 
310  // Populate midr values
311  std::vector<uint32_t> cpus_midr;
313  {
314  cpus_midr = midr_from_cpuid(max_cpus);
315  }
316  if(cpus_midr.empty())
317  {
318  cpus_midr = midr_from_proc_cpuinfo(max_cpus);
319  }
320  if(cpus_midr.empty())
321  {
322  cpus_midr.resize(max_cpus, 0);
323  }
324 
325  // Populate isa (Assume homogeneous ISA specification)
326  CpuIsaInfo isa = init_cpu_isa_from_hwcaps(hwcaps, hwcaps2, cpus_midr.back());
327 
328  // Convert midr to models
329  std::vector<CpuModel> cpus_model;
330  std::transform(std::begin(cpus_midr), std::end(cpus_midr), std::back_inserter(cpus_model),
331  [](uint32_t midr) -> CpuModel { return midr_to_model(midr); });
332 
333  CpuInfo info(isa, cpus_model);
334  return info;
335 
336 #elif(BARE_METAL) && defined(__aarch64__) /* !defined(BARE_METAL) && !defined(__APPLE__) && !defined(__OpenBSD__) && (defined(__arm__) || defined(__aarch64__)) */
337 
338  // Assume single CPU in bare metal mode. Just read the ID register and feature bits directly.
339  uint64_t isar0 = 0, isar1 = 0, pfr0 = 0, svefr0 = 0, midr = 0;
340  ARM_COMPUTE_GET_FEATURE_REG(isar0, ID_AA64ISAR0_EL1);
341  ARM_COMPUTE_GET_FEATURE_REG(isar1, ID_AA64ISAR1_EL1);
342  ARM_COMPUTE_GET_FEATURE_REG(pfr0, ID_AA64PFR0_EL1);
343  ARM_COMPUTE_GET_FEATURE_REG(midr, MIDR_EL1);
344  if((pfr0 >> 32) & 0xf)
345  {
346  svefr0 = get_sve_feature_reg();
347  }
348 
349  CpuIsaInfo isa = init_cpu_isa_from_regs(isar0, isar1, pfr0, svefr0, midr);
350  std::vector<CpuModel> cpus_model(1, midr_to_model(midr));
351  CpuInfo info(isa, cpus_model);
352  return info;
353 #elif defined(__aarch64__) && defined(__APPLE__) /* #elif(BARE_METAL) && defined(__aarch64__) */
354  int ncpus = get_hw_capability("hw.logicalcpu");
355  CpuIsaInfo isainfo;
356  std::vector<CpuModel> cpus_model(ncpus);
357  isainfo.neon = get_hw_capability("hw.optional.neon");
358  isainfo.fp16 = get_hw_capability("hw.optional.neon_fp16");
359  isainfo.dot = get_hw_capability("hw.optional.arm.FEAT_DotProd");
360  CpuInfo info(isainfo, cpus_model);
361  return info;
362 #else /* #elif defined(__aarch64__) && defined(__APPLE__) */
363  CpuInfo info(CpuIsaInfo(), { CpuModel::GENERIC });
364  return info;
365 #endif /* !defined(BARE_METAL) && !defined(__APPLE__) && !defined(__OpenBSD__) && (defined(__arm__) || defined(__aarch64__)) */
366 }
arm_compute::CPUModel CpuModel
Definition: CpuModel.h:36
#define ARM_COMPUTE_GET_FEATURE_REG(var, freg)
Definition: CpuInfo.cpp:57
const CpuIsaInfo & isa() const
Definition: CpuInfo.h:103
CpuIsaInfo init_cpu_isa_from_hwcaps(uint32_t hwcaps, uint32_t hwcaps2, uint32_t midr)
Identify ISA related information through system information.
Definition: CpuIsaInfo.cpp:131
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
CpuIsaInfo init_cpu_isa_from_regs(uint64_t isar0, uint64_t isar1, uint64_t pfr0, uint64_t svefr0, uint64_t midr)
Identify ISA related information through register information.
Definition: CpuIsaInfo.cpp:143
CpuInfo()=default
Default constructor.
#define ARM_COMPUTE_CPU_FEATURE_HWCAP_CPUID
Definition: CpuInfo.cpp:56
CpuModel midr_to_model(uint32_t midr)
Extract the model type from the MIDR value.
Definition: CpuModel.cpp:78

◆ cpu_model() [1/2]

CpuModel cpu_model ( uint32_t  cpuid) const

Definition at line 368 of file CpuInfo.cpp.

References arm_compute::GENERIC.

369 {
370  if(cpuid < _cpus.size())
371  {
372  return _cpus[cpuid];
373  }
374  return CpuModel::GENERIC;
375 }

◆ cpu_model() [2/2]

CpuModel cpu_model ( ) const

Definition at line 377 of file CpuInfo.cpp.

Referenced by CpuInfo::cpus().

378 {
379 #if defined(_WIN64) || defined(BARE_METAL) || defined(__APPLE__) || defined(__OpenBSD__) || (!defined(__arm__) && !defined(__aarch64__))
380  return cpu_model(0);
381 #else /* defined(BARE_METAL) || defined(__APPLE__) || defined(__OpenBSD__) || (!defined(__arm__) && !defined(__aarch64__)) */
382  return cpu_model(sched_getcpu());
383 #endif /* defined(BARE_METAL) || defined(__APPLE__) || defined(__OpenBSD__) || (!defined(__arm__) && !defined(__aarch64__)) */
384 }
CpuModel cpu_model() const
Definition: CpuInfo.cpp:377

◆ cpus()

const std::vector<CpuModel>& cpus ( ) const
inline

Definition at line 107 of file CpuInfo.h.

References CpuInfo::cpu_model(), CpuInfo::num_cpus(), and arm_compute::cpuinfo::num_threads_hint().

Referenced by arm_compute::cpuinfo::num_threads_hint().

108  {
109  return _cpus;
110  }

◆ has_bf16()

bool has_bf16 ( ) const
inline

Definition at line 78 of file CpuInfo.h.

References CpuIsaInfo::bf16.

79  {
80  return _isa.bf16;
81  }

◆ has_dotprod()

bool has_dotprod ( ) const
inline

Definition at line 86 of file CpuInfo.h.

References CpuIsaInfo::dot.

Referenced by arm_compute::test::validation::TEST_CASE().

87  {
88  return _isa.dot;
89  }

◆ has_fp16()

bool has_fp16 ( ) const
inline

Definition at line 74 of file CpuInfo.h.

References CpuIsaInfo::fp16.

Referenced by arm_compute::test::validation::TEST_CASE().

75  {
76  return _isa.fp16;
77  }

◆ has_i8mm()

bool has_i8mm ( ) const
inline

Definition at line 90 of file CpuInfo.h.

References CpuIsaInfo::i8mm.

Referenced by arm_compute::test::validation::TEST_CASE().

91  {
92  return _isa.i8mm;
93  }

◆ has_neon()

bool has_neon ( ) const
inline

Definition at line 62 of file CpuInfo.h.

References CpuIsaInfo::neon.

63  {
64  return _isa.neon;
65  }

◆ has_sve()

bool has_sve ( ) const
inline

Definition at line 66 of file CpuInfo.h.

References CpuIsaInfo::sve.

67  {
68  return _isa.sve;
69  }

◆ has_sve2()

bool has_sve2 ( ) const
inline

Definition at line 70 of file CpuInfo.h.

References CpuIsaInfo::sve2.

Referenced by arm_compute::test::validation::TEST_CASE().

71  {
72  return _isa.sve2;
73  }

◆ has_svebf16()

bool has_svebf16 ( ) const
inline

Definition at line 82 of file CpuInfo.h.

References CpuIsaInfo::svebf16.

83  {
84  return _isa.svebf16;
85  }

◆ has_svef32mm()

bool has_svef32mm ( ) const
inline

Definition at line 98 of file CpuInfo.h.

References CpuIsaInfo::svef32mm.

99  {
100  return _isa.svef32mm;
101  }

◆ has_svei8mm()

bool has_svei8mm ( ) const
inline

Definition at line 94 of file CpuInfo.h.

References CpuIsaInfo::svei8mm.

95  {
96  return _isa.svei8mm;
97  }

◆ isa()

const CpuIsaInfo& isa ( ) const
inline

Definition at line 103 of file CpuInfo.h.

Referenced by CpuInfo::build().

104  {
105  return _isa;
106  }

◆ num_cpus()

uint32_t num_cpus ( ) const

Definition at line 386 of file CpuInfo.cpp.

Referenced by CpuInfo::cpus().

387 {
388  return _cpus.size();
389 }

The documentation for this class was generated from the following files: