Compute Library
 22.05
arm_compute::cpuinfo Namespace Reference

Data Structures

class  CpuInfo
 Aggregate class that contains CPU related information. More...
 
struct  CpuIsaInfo
 CPU ISA (Instruction Set Architecture) information. More...
 

Typedefs

using CpuModel = arm_compute::CPUModel
 

Functions

uint32_t num_threads_hint ()
 Some systems have both big and small cores, this fuction computes the minimum number of cores that are exactly the same on the system. More...
 
CpuIsaInfo init_cpu_isa_from_hwcaps (uint32_t hwcaps, uint32_t hwcaps2, uint32_t midr)
 Identify ISA related information through system information. More...
 
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. More...
 
std::string cpu_model_to_string (CpuModel model)
 Convert a CPU model value to a string. More...
 
bool model_supports_fp16 (CpuModel model)
 Check if a model supports half-precision floating point arithmetic. More...
 
bool model_supports_dot (CpuModel model)
 Check if a model supports dot product. More...
 
CpuModel midr_to_model (uint32_t midr)
 Extract the model type from the MIDR value. More...
 

Typedef Documentation

◆ CpuModel

Definition at line 36 of file CpuModel.h.

Function Documentation

◆ cpu_model_to_string()

std::string cpu_model_to_string ( CpuModel  model)

Convert a CPU model value to a string.

Parameters
modelCpuModel value to be converted
Returns
String representing the corresponding CpuModel

Definition at line 30 of file CpuModel.cpp.

References ARM_COMPUTE_CPU_MODEL_LIST.

Referenced by main().

31 {
32  switch(model)
33  {
34 #define X(MODEL) \
35 case CpuModel::MODEL: \
36  return #MODEL;
38 #undef X
39  default:
40  {
41  return std::string("GENERIC");
42  }
43  };
44 }
#define ARM_COMPUTE_CPU_MODEL_LIST
Definition: CPPTypes.h:38

◆ init_cpu_isa_from_hwcaps()

CpuIsaInfo init_cpu_isa_from_hwcaps ( uint32_t  hwcaps,
uint32_t  hwcaps2,
uint32_t  midr 
)

Identify ISA related information through system information.

Parameters
[in]hwcapsHWCAPS feature information
[in]hwcaps2HWCAPS2 feature information
[in]midrMIDR value
Returns
CpuIsaInfo A populated ISA feature structure

Definition at line 131 of file CpuIsaInfo.cpp.

References isa, and midr_to_model().

Referenced by CpuInfo::build().

132 {
133  CpuIsaInfo isa;
134 
135  decode_hwcaps(isa, hwcaps, hwcaps2);
136 
137  const CpuModel model = midr_to_model(midr);
138  allowlisted_model_features(isa, model);
139 
140  return isa;
141 }
arm_compute::CPUModel CpuModel
Definition: CpuModel.h:36
cpuinfo::CpuIsaInfo isa
CpuModel midr_to_model(uint32_t midr)
Extract the model type from the MIDR value.
Definition: CpuModel.cpp:78

◆ init_cpu_isa_from_regs()

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.

Parameters
[in]isar0Value of Instruction Set Attribute Register 0 (ID_AA64ISAR0_EL1)
[in]isar1Value of Instruction Set Attribute Register 1 (ID_AA64ISAR1_EL1)
[in]pfr0Value of Processor Feature Register 0 (ID_AA64PFR0_EL1)
[in]svefr0Value of SVE feature ID register 0 (ID_AA64ZFR0_EL1)
[in]midrValue of Main ID Register (MIDR)
Returns
CpuIsaInfo A populated ISA feature structure

Definition at line 143 of file CpuIsaInfo.cpp.

References isa, and midr_to_model().

Referenced by CpuInfo::build().

144 {
145  CpuIsaInfo isa;
146 
147  decode_regs(isa, isar0, isar1, pfr0, svefr0);
148 
149  const CpuModel model = midr_to_model(midr);
150  allowlisted_model_features(isa, model);
151 
152  return isa;
153 }
arm_compute::CPUModel CpuModel
Definition: CpuModel.h:36
cpuinfo::CpuIsaInfo isa
CpuModel midr_to_model(uint32_t midr)
Extract the model type from the MIDR value.
Definition: CpuModel.cpp:78

◆ midr_to_model()

CpuModel midr_to_model ( uint32_t  midr)

Extract the model type from the MIDR value.

Parameters
[in]midrMIDR information
Returns
CpuModel a mapped CPU model

Definition at line 78 of file CpuModel.cpp.

References arm_compute::A510, arm_compute::A53, arm_compute::A55r0, arm_compute::A55r1, arm_compute::A64FX, arm_compute::A73, arm_compute::GENERIC, arm_compute::GENERIC_FP16, arm_compute::GENERIC_FP16_DOT, arm_compute::V1, and arm_compute::X1.

Referenced by CpuInfo::build(), init_cpu_isa_from_hwcaps(), and init_cpu_isa_from_regs().

79 {
80  CpuModel model = CpuModel::GENERIC;
81 
82  // Unpack variant and CPU ID
83  const int implementer = (midr >> 24) & 0xFF;
84  const int variant = (midr >> 20) & 0xF;
85  const int cpunum = (midr >> 4) & 0xFFF;
86 
87  // Only CPUs we have code paths for are detected. All other CPUs can be safely classed as "GENERIC"
88  if(implementer == 0x41) // Arm CPUs
89  {
90  switch(cpunum)
91  {
92  case 0xd03: // A53
93  case 0xd04: // A35
94  model = CpuModel::A53;
95  break;
96  case 0xd05: // A55
97  if(variant != 0)
98  {
99  model = CpuModel::A55r1;
100  }
101  else
102  {
103  model = CpuModel::A55r0;
104  }
105  break;
106  case 0xd09: // A73
107  model = CpuModel::A73;
108  break;
109  case 0xd0a: // A75
110  if(variant != 0)
111  {
112  model = CpuModel::GENERIC_FP16_DOT;
113  }
114  else
115  {
116  model = CpuModel::GENERIC_FP16;
117  }
118  break;
119  case 0xd06: // A65
120  case 0xd0b: // A76
121  case 0xd0c: // N1
122  case 0xd0d: // A77
123  case 0xd0e: // A76AE
124  case 0xd41: // A78
125  case 0xd42: // A78AE
126  case 0xd4a: // E1
127  model = CpuModel::GENERIC_FP16_DOT;
128  break;
129  case 0xd40: // V1
130  model = CpuModel::V1;
131  break;
132  case 0xd44: // X1
133  model = CpuModel::X1;
134  break;
135  case 0xd46:
136  model = CpuModel::A510;
137  break;
138  default:
139  model = CpuModel::GENERIC;
140  break;
141  }
142  }
143  else if(implementer == 0x46)
144  {
145  switch(cpunum)
146  {
147  case 0x001: // A64FX
148  model = CpuModel::A64FX;
149  break;
150  default:
151  model = CpuModel::GENERIC;
152  break;
153  }
154  }
155  else if(implementer == 0x48)
156  {
157  switch(cpunum)
158  {
159  case 0xd40: // A76
160  model = CpuModel::GENERIC_FP16_DOT;
161  break;
162  default:
163  model = CpuModel::GENERIC;
164  break;
165  }
166  }
167  else if(implementer == 0x51)
168  {
169  switch(cpunum)
170  {
171  case 0x800: // A73
172  model = CpuModel::A73;
173  break;
174  case 0x801: // A53
175  model = CpuModel::A53;
176  break;
177  case 0x803: // A55r0
178  model = CpuModel::A55r0;
179  break;
180  case 0x804: // A76
181  model = CpuModel::GENERIC_FP16_DOT;
182  break;
183  case 0x805: // A55r1
184  model = CpuModel::A55r1;
185  break;
186  default:
187  model = CpuModel::GENERIC;
188  break;
189  }
190  }
191 
192  return model;
193 }
arm_compute::CPUModel CpuModel
Definition: CpuModel.h:36

◆ model_supports_dot()

bool model_supports_dot ( CpuModel  model)

Check if a model supports dot product.

Note
This is used in case of old kernel configurations where some capabilities are not exposed.
Parameters
[in]modelModel to check for allowlisted capabilities

Definition at line 63 of file CpuModel.cpp.

References arm_compute::A510, arm_compute::A55r1, arm_compute::GENERIC_FP16_DOT, arm_compute::V1, and arm_compute::X1.

64 {
65  switch(model)
66  {
67  case CpuModel::GENERIC_FP16_DOT:
68  case CpuModel::A55r1:
69  case CpuModel::A510:
70  case CpuModel::X1:
71  case CpuModel::V1:
72  return true;
73  default:
74  return false;
75  }
76 }

◆ model_supports_fp16()

bool model_supports_fp16 ( CpuModel  model)

Check if a model supports half-precision floating point arithmetic.

Note
This is used in case of old kernel configurations where some capabilities are not exposed.
Parameters
[in]modelModel to check for allowlisted capabilities

Definition at line 46 of file CpuModel.cpp.

References arm_compute::A510, arm_compute::A55r1, arm_compute::A64FX, arm_compute::GENERIC_FP16, arm_compute::GENERIC_FP16_DOT, arm_compute::V1, and arm_compute::X1.

47 {
48  switch(model)
49  {
50  case CpuModel::GENERIC_FP16:
51  case CpuModel::GENERIC_FP16_DOT:
52  case CpuModel::A55r1:
53  case CpuModel::A510:
54  case CpuModel::X1:
55  case CpuModel::V1:
56  case CpuModel::A64FX:
57  return true;
58  default:
59  return false;
60  }
61 }

◆ num_threads_hint()

uint32_t num_threads_hint ( )

Some systems have both big and small cores, this fuction computes the minimum number of cores that are exactly the same on the system.

To maximize performance the library attempts to process workloads concurrently using as many threads as big cores are available on the system.

Returns
The minumum number of common cores.

Definition at line 391 of file CpuInfo.cpp.

References ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_UNUSED, CpuInfo::cpus(), arm_compute::mlgo::parser::end(), and arm_compute::wrapper::vmin().

Referenced by CpuInfo::cpus(), and IScheduler::IScheduler().

392 {
393  unsigned int num_threads_hint = 1;
394 
395 #if !defined(BARE_METAL) && !defined(_WIN64)
396  std::vector<std::string> cpus;
397  cpus.reserve(64);
398 
399  // CPU part regex
400  regex_t cpu_part_rgx;
401  memset(&cpu_part_rgx, 0, sizeof(regex_t));
402  int ret_status = regcomp(&cpu_part_rgx, R"(.*CPU part.+/?\:[[:space:]]+([[:alnum:]]+).*)", REG_EXTENDED);
403  ARM_COMPUTE_UNUSED(ret_status);
404  ARM_COMPUTE_ERROR_ON_MSG(ret_status != 0, "Regex compilation failed.");
405 
406  // Read cpuinfo and get occurrence of each core
407  std::ifstream cpuinfo_file("/proc/cpuinfo", std::ios::in);
408  if(cpuinfo_file.is_open())
409  {
410  std::string line;
411  while(bool(getline(cpuinfo_file, line)))
412  {
413  std::array<regmatch_t, 2> match;
414  if(regexec(&cpu_part_rgx, line.c_str(), 2, match.data(), 0) == 0)
415  {
416  cpus.emplace_back(line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so)));
417  }
418  }
419  }
420  regfree(&cpu_part_rgx);
421 
422  // Get min number of threads
423  std::sort(std::begin(cpus), std::end(cpus));
424  auto least_frequent_cpu_occurences = [](const std::vector<std::string> &cpus) -> uint32_t
425  {
426  std::unordered_map<std::string, uint32_t> cpus_freq;
427  for(const auto &cpu : cpus)
428  {
429  cpus_freq[cpu]++;
430  }
431 
432  uint32_t vmin = cpus.size() + 1;
433  for(const auto &cpu_freq : cpus_freq)
434  {
435  vmin = std::min(vmin, cpu_freq.second);
436  }
437  return vmin;
438  };
439 
440  // Set thread hint
441  num_threads_hint = cpus.empty() ? std::thread::hardware_concurrency() : least_frequent_cpu_occurences(cpus);
442 #endif /* !defined(BARE_METAL) */
443 
444  return num_threads_hint;
445 }
uint32_t num_threads_hint()
Some systems have both big and small cores, this fuction computes the minimum number of cores that ar...
Definition: CpuInfo.cpp:391
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
uint8x8_t vmin(const uint8x8_t &a, const uint8x8_t &b)
Definition: min.h:39
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290