MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / get_max_cpus

Function get_max_cpus

src/common/cpuinfo/CpuInfo.cpp:248–289  ·  view source on GitHub ↗

Get the maximim number of CPUs in the system by parsing /sys/devices/system/cpu/present * * @return int Maximum number of CPUs */

Source from the content-addressed store, hash-verified

246 * @return int Maximum number of CPUs
247 */
248int get_max_cpus()
249{
250 int max_cpus = 1;
251 std::ifstream CPUspresent;
252 CPUspresent.open("/sys/devices/system/cpu/present", std::ios::in);
253 bool success = false;
254
255 if (CPUspresent.is_open())
256 {
257 std::string line;
258
259 if (bool(getline(CPUspresent, line)))
260 {
261 /* The content of this file is a list of ranges or single values, e.g.
262 * 0-5, or 1-3,5,7 or similar. As we are interested in the
263 * max valid ID, we just need to find the last valid
264 * delimiter ('-' or ',') and parse the integer immediately after that.
265 */
266 auto startfrom = line.begin();
267
268 for (auto i = line.begin(); i < line.end(); ++i)
269 {
270 if (*i == '-' || *i == ',')
271 {
272 startfrom = i + 1;
273 }
274 }
275
276 line.erase(line.begin(), startfrom);
277
278 max_cpus = support::cpp11::stoi(line, nullptr) + 1;
279 success = true;
280 }
281 }
282
283 // Return std::thread::hardware_concurrency() as a fallback.
284 if (!success)
285 {
286 max_cpus = std::thread::hardware_concurrency();
287 }
288 return max_cpus;
289}
290#if defined(__ANDROID__)
291std::vector<uint32_t> get_cpu_capacities()
292{

Callers 2

get_cpu_capacitiesFunction · 0.85
buildMethod · 0.85

Calls 5

stoiFunction · 0.85
openMethod · 0.45
is_openMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected