blob: a7dd46454063fe877d2d841fa0c11c81608ca8ab [file] [log] [blame]
Pablo Tello7fad9b12018-03-14 17:55:27 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Pablo Tello7fad9b12018-03-14 17:55:27 +00003 *
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 */
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010024#include "src/runtime/CPUUtils.h"
Pablo Tello7fad9b12018-03-14 17:55:27 +000025
26#include "arm_compute/core/CPP/CPPTypes.h"
27#include "arm_compute/core/Error.h"
Matthew Bentham758b5ba2020-03-05 23:37:48 +000028#include "support/StringSupport.h"
Pablo Tello7fad9b12018-03-14 17:55:27 +000029
Matthew Bentham758b5ba2020-03-05 23:37:48 +000030#include <algorithm>
Pablo Tello7fad9b12018-03-14 17:55:27 +000031#include <array>
32#include <cstdlib>
33#include <cstring>
Pablo Tello7fad9b12018-03-14 17:55:27 +000034#include <fstream>
35#include <map>
Pablo Tello7fad9b12018-03-14 17:55:27 +000036
37#ifndef BARE_METAL
Michalis Spyrou8e5174c2018-12-04 11:43:23 +000038/* C++ std::regex takes up a lot of space in the standalone builds */
39#include <regex.h>
Pablo Tello7fad9b12018-03-14 17:55:27 +000040#include <thread>
41#endif /* BARE_METAL */
42
43#if !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__))
44#include <sys/auxv.h>
45
46/* Get HWCAP bits from asm/hwcap.h */
47#include <asm/hwcap.h>
48#endif /* !BARE_METAL */
49
50/* Make sure the bits we care about are defined, just in case asm/hwcap.h is
51 * out of date (or for bare metal mode) */
52#ifndef HWCAP_ASIMDHP
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010053#define HWCAP_ASIMDHP (1 << 10) // NOLINT
54#endif /* HWCAP_ASIMDHP */
Pablo Tello7fad9b12018-03-14 17:55:27 +000055
56#ifndef HWCAP_CPUID
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010057#define HWCAP_CPUID (1 << 11) // NOLINT
58#endif /* HWCAP_CPUID */
Pablo Tello7fad9b12018-03-14 17:55:27 +000059
60#ifndef HWCAP_ASIMDDP
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010061#define HWCAP_ASIMDDP (1 << 20) // NOLINT
62#endif /* HWCAP_ASIMDDP */
Pablo Tello7fad9b12018-03-14 17:55:27 +000063
64namespace
65{
66using namespace arm_compute;
67
68#if !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__))
Pablo Tello7fad9b12018-03-14 17:55:27 +000069
Anthony Barbier3efb3752018-07-20 15:30:46 +010070bool model_supports_dot(CPUModel model)
71{
72 switch(model)
73 {
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +010074 case CPUModel::GENERIC_FP16_DOT:
Anthony Barbier3efb3752018-07-20 15:30:46 +010075 case CPUModel::A55r1:
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010076 case CPUModel::X1:
Anthony Barbier3efb3752018-07-20 15:30:46 +010077 return true;
78 default:
79 return false;
80 }
81}
82
83bool model_supports_fp16(CPUModel model)
84{
85 switch(model)
86 {
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +010087 case CPUModel::GENERIC_FP16:
88 case CPUModel::GENERIC_FP16_DOT:
Anthony Barbier3efb3752018-07-20 15:30:46 +010089 case CPUModel::A55r1:
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010090 case CPUModel::X1:
Anthony Barbier3efb3752018-07-20 15:30:46 +010091 return true;
92 default:
93 return false;
94 }
95}
Georgios Pinitas18960692018-12-21 18:18:46 +000096
Pablo Tello7fad9b12018-03-14 17:55:27 +000097/* Convert an MIDR register value to a CPUModel enum value. */
98CPUModel midr_to_model(const unsigned int midr)
99{
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100100 CPUModel model = CPUModel::GENERIC;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000101
102 // Unpack variant and CPU ID
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100103 const int implementer = (midr >> 24) & 0xFF;
104 const int variant = (midr >> 20) & 0xF;
105 const int cpunum = (midr >> 4) & 0xFFF;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000106
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100107 if(implementer == 0x41) // Arm CPUs
Pablo Tello7fad9b12018-03-14 17:55:27 +0000108 {
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100109 // Only CPUs we have code paths for are detected. All other CPUs can be safely classed as "GENERIC"
110 switch(cpunum)
111 {
112 case 0xd03: // A53
113 case 0xd04: // A35
114 model = CPUModel::A53;
115 break;
116 case 0xd05: // A55
117 if(variant != 0)
118 {
119 model = CPUModel::A55r1;
120 }
121 else
122 {
123 model = CPUModel::A55r0;
124 }
125 break;
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +0100126 case 0xd44: // X1
127 model = CPUModel::X1;
128 break;
David Mansell318c9f42020-07-08 13:28:45 +0100129 case 0xd09: // A73
130 model = CPUModel::A73;
131 break;
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100132 case 0xd0a: // A75
133 if(variant != 0)
134 {
135 model = CPUModel::GENERIC_FP16_DOT;
136 }
137 else
138 {
139 model = CPUModel::GENERIC_FP16;
140 }
141 break;
142 case 0xd0b: // A76
Isabella Gottardibe2de402018-11-21 15:23:49 +0000143 case 0xd06:
144 case 0xd0c:
145 case 0xd0d:
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100146 model = CPUModel::GENERIC_FP16_DOT;
147 break;
148 default:
149 model = CPUModel::GENERIC;
150 break;
151 }
Pablo Tello7fad9b12018-03-14 17:55:27 +0000152 }
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100153 else if(implementer == 0x48)
Georgios Pinitas18960692018-12-21 18:18:46 +0000154 {
155 // Only CPUs we have code paths for are detected. All other CPUs can be safely classed as "GENERIC"
156 switch(cpunum)
157 {
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100158 case 0xd40: // A76
Georgios Pinitas18960692018-12-21 18:18:46 +0000159 model = CPUModel::GENERIC_FP16_DOT;
160 break;
161 default:
162 model = CPUModel::GENERIC;
163 break;
164 }
165 }
Pablo Tello7fad9b12018-03-14 17:55:27 +0000166
167 return model;
168}
169
Anthony Barbier3efb3752018-07-20 15:30:46 +0100170void populate_models_cpuid(std::vector<CPUModel> &cpusv)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000171{
172 // If the CPUID capability is present, MIDR information is provided in /sys. Use that to populate the CPU model table.
173 uint32_t i = 0;
174 for(auto &c : cpusv)
175 {
176 std::stringstream str;
177 str << "/sys/devices/system/cpu/cpu" << i++ << "/regs/identification/midr_el1";
178 std::ifstream file;
179 file.open(str.str(), std::ios::in);
180 if(file.is_open())
181 {
182 std::string line;
183 if(bool(getline(file, line)))
184 {
Georgios Pinitas9c2ec7e2018-11-12 17:07:18 +0000185 const uint32_t midr = support::cpp11::stoul(line, nullptr, support::cpp11::NumericBase::BASE_16);
186 c = midr_to_model(midr & 0xffffffff);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000187 }
188 }
189 }
190}
191
Anthony Barbier3efb3752018-07-20 15:30:46 +0100192void populate_models_cpuinfo(std::vector<CPUModel> &cpusv)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000193{
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000194 regex_t proc_regex;
195 regex_t imp_regex;
196 regex_t var_regex;
197 regex_t part_regex;
198 regex_t rev_regex;
199
200 memset(&proc_regex, 0, sizeof(regex_t));
201 memset(&imp_regex, 0, sizeof(regex_t));
202 memset(&var_regex, 0, sizeof(regex_t));
203 memset(&part_regex, 0, sizeof(regex_t));
204 memset(&rev_regex, 0, sizeof(regex_t));
205
206 int ret_status = 0;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000207 // If "long-form" cpuinfo is present, parse that to populate models.
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000208 ret_status |= regcomp(&proc_regex, R"(^processor.*([[:digit:]]+)$)", REG_EXTENDED);
209 ret_status |= regcomp(&imp_regex, R"(^CPU implementer.*0x(..)$)", REG_EXTENDED);
210 ret_status |= regcomp(&var_regex, R"(^CPU variant.*0x(.)$)", REG_EXTENDED);
211 ret_status |= regcomp(&part_regex, R"(^CPU part.*0x(...)$)", REG_EXTENDED);
212 ret_status |= regcomp(&rev_regex, R"(^CPU revision.*([[:digit:]]+)$)", REG_EXTENDED);
213 ARM_COMPUTE_UNUSED(ret_status);
214 ARM_COMPUTE_ERROR_ON_MSG(ret_status != 0, "Regex compilation failed.");
Pablo Tello7fad9b12018-03-14 17:55:27 +0000215
216 std::ifstream file;
217 file.open("/proc/cpuinfo", std::ios::in);
218
219 if(file.is_open())
220 {
221 std::string line;
222 int midr = 0;
223 int curcpu = -1;
224
225 while(bool(getline(file, line)))
226 {
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100227 std::array<regmatch_t, 2> match;
228 ret_status = regexec(&proc_regex, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000229 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000230 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000231 std::string id = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
Pablo Tello65f99822018-05-24 11:40:15 +0100232 int newcpu = support::cpp11::stoi(id, nullptr);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000233
234 if(curcpu >= 0 && midr == 0)
235 {
236 // Matched a new CPU ID without any description of the previous one - looks like old format.
237 return;
238 }
239
240 if(curcpu >= 0)
241 {
Anthony Barbier3efb3752018-07-20 15:30:46 +0100242 cpusv[curcpu] = midr_to_model(midr);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000243 }
244
245 midr = 0;
246 curcpu = newcpu;
247
248 continue;
249 }
250
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100251 ret_status = regexec(&imp_regex, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000252 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000253 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000254 std::string subexp = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
255 int impv = support::cpp11::stoi(subexp, nullptr, support::cpp11::NumericBase::BASE_16);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000256 midr |= (impv << 24);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000257
Pablo Tello7fad9b12018-03-14 17:55:27 +0000258 continue;
259 }
260
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100261 ret_status = regexec(&var_regex, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000262 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000263 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000264 std::string subexp = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
265 int varv = support::cpp11::stoi(subexp, nullptr, support::cpp11::NumericBase::BASE_16);
Anthony Barbier3efb3752018-07-20 15:30:46 +0100266 midr |= (varv << 20);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000267
Pablo Tello7fad9b12018-03-14 17:55:27 +0000268 continue;
269 }
270
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100271 ret_status = regexec(&part_regex, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000272 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000273 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000274 std::string subexp = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
275 int partv = support::cpp11::stoi(subexp, nullptr, support::cpp11::NumericBase::BASE_16);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000276 midr |= (partv << 4);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000277
Pablo Tello7fad9b12018-03-14 17:55:27 +0000278 continue;
279 }
280
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100281 ret_status = regexec(&rev_regex, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000282 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000283 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000284 std::string subexp = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
285 int regv = support::cpp11::stoi(subexp, nullptr);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000286 midr |= (regv);
287 midr |= (0xf << 16);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000288
Pablo Tello7fad9b12018-03-14 17:55:27 +0000289 continue;
290 }
291 }
292
293 if(curcpu >= 0)
294 {
Anthony Barbier3efb3752018-07-20 15:30:46 +0100295 cpusv[curcpu] = midr_to_model(midr);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000296 }
297 }
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000298
299 // Free allocated memory
300 regfree(&proc_regex);
301 regfree(&imp_regex);
302 regfree(&var_regex);
303 regfree(&part_regex);
304 regfree(&rev_regex);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000305}
306
307int get_max_cpus()
308{
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100309 int max_cpus = 1;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000310 std::ifstream CPUspresent;
311 CPUspresent.open("/sys/devices/system/cpu/present", std::ios::in);
312 bool success = false;
313
314 if(CPUspresent.is_open())
315 {
316 std::string line;
317
318 if(bool(getline(CPUspresent, line)))
319 {
320 /* The content of this file is a list of ranges or single values, e.g.
321 * 0-5, or 1-3,5,7 or similar. As we are interested in the
322 * max valid ID, we just need to find the last valid
323 * delimiter ('-' or ',') and parse the integer immediately after that.
324 */
325 auto startfrom = line.begin();
326
327 for(auto i = line.begin(); i < line.end(); ++i)
328 {
329 if(*i == '-' || *i == ',')
330 {
331 startfrom = i + 1;
332 }
333 }
334
335 line.erase(line.begin(), startfrom);
336
Pablo Tello65f99822018-05-24 11:40:15 +0100337 max_cpus = support::cpp11::stoi(line, nullptr) + 1;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000338 success = true;
339 }
340 }
341
342 // Return std::thread::hardware_concurrency() as a fallback.
343 if(!success)
344 {
345 max_cpus = std::thread::hardware_concurrency();
346 }
Pablo Tello7fad9b12018-03-14 17:55:27 +0000347 return max_cpus;
348}
349#endif /* !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) */
350
351} // namespace
352
353namespace arm_compute
354{
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100355namespace utils
356{
357namespace cpu
358{
Pablo Tello7fad9b12018-03-14 17:55:27 +0000359void get_cpu_configuration(CPUInfo &cpuinfo)
360{
361#if !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__))
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100362 bool cpuid = false;
363 bool hwcaps_fp16_support = false;
364 bool hwcaps_dot_support = false;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000365
366 const uint32_t hwcaps = getauxval(AT_HWCAP);
367
368 if((hwcaps & HWCAP_CPUID) != 0)
369 {
370 cpuid = true;
371 }
372
373 if((hwcaps & HWCAP_ASIMDHP) != 0)
374 {
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100375 hwcaps_fp16_support = true;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000376 }
377
Pablo Tellodf3b5bb2018-10-09 10:51:51 +0100378#if defined(__aarch64__)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000379 if((hwcaps & HWCAP_ASIMDDP) != 0)
380 {
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100381 hwcaps_dot_support = true;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000382 }
Pablo Tellodf3b5bb2018-10-09 10:51:51 +0100383#endif /* defined(__aarch64__) */
Pablo Tello7fad9b12018-03-14 17:55:27 +0000384
Pablo Tello7fad9b12018-03-14 17:55:27 +0000385 const unsigned int max_cpus = get_max_cpus();
386 cpuinfo.set_cpu_num(max_cpus);
Anthony Barbier3efb3752018-07-20 15:30:46 +0100387 std::vector<CPUModel> percpu(max_cpus, CPUModel::GENERIC);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000388 if(cpuid)
389 {
390 populate_models_cpuid(percpu);
391 }
392 else
393 {
394 populate_models_cpuinfo(percpu);
395 }
396 int j(0);
Georgios Pinitasecae3a12018-10-09 15:13:12 +0100397 // Update dot product and FP16 support if one of the CPUs support these features
398 // We assume that the system does not have mixed architectures
399 bool one_supports_dot = false;
400 bool one_supports_fp16 = false;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000401 for(const auto &v : percpu)
402 {
Georgios Pinitas9c2ec7e2018-11-12 17:07:18 +0000403 one_supports_dot = one_supports_dot || model_supports_dot(v);
404 one_supports_fp16 = one_supports_fp16 || model_supports_fp16(v);
Anthony Barbier3efb3752018-07-20 15:30:46 +0100405 cpuinfo.set_cpu_model(j++, v);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000406 }
Georgios Pinitasecae3a12018-10-09 15:13:12 +0100407 cpuinfo.set_dotprod(one_supports_dot || hwcaps_dot_support);
408 cpuinfo.set_fp16(one_supports_fp16 || hwcaps_fp16_support);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000409#else /* !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) */
410 ARM_COMPUTE_UNUSED(cpuinfo);
411#endif /* !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) */
412}
413
414unsigned int get_threads_hint()
415{
416 unsigned int num_threads_hint = 1;
417
Georgios Pinitase8291ac2020-02-26 09:58:13 +0000418#if !defined(BARE_METAL)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000419 std::map<std::string, unsigned int> cpu_part_occurrence_map;
420
421 // CPU part regex
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000422 regex_t cpu_part_rgx;
423 memset(&cpu_part_rgx, 0, sizeof(regex_t));
Georgios Pinitasde6dbfe2018-12-24 15:02:55 +0000424 int ret_status = regcomp(&cpu_part_rgx, R"(.*CPU part.+/?\:[[:space:]]+([[:alnum:]]+).*)", REG_EXTENDED);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000425 ARM_COMPUTE_UNUSED(ret_status);
426 ARM_COMPUTE_ERROR_ON_MSG(ret_status != 0, "Regex compilation failed.");
Pablo Tello7fad9b12018-03-14 17:55:27 +0000427
428 // Read cpuinfo and get occurrence of each core
429 std::ifstream cpuinfo;
430 cpuinfo.open("/proc/cpuinfo", std::ios::in);
431 if(cpuinfo.is_open())
432 {
433 std::string line;
434 while(bool(getline(cpuinfo, line)))
435 {
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100436 std::array<regmatch_t, 2> match;
437 ret_status = regexec(&cpu_part_rgx, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000438 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000439 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000440 std::string cpu_part = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
Pablo Tello7fad9b12018-03-14 17:55:27 +0000441 if(cpu_part_occurrence_map.find(cpu_part) != cpu_part_occurrence_map.end())
442 {
443 cpu_part_occurrence_map[cpu_part]++;
444 }
445 else
446 {
447 cpu_part_occurrence_map[cpu_part] = 1;
448 }
449 }
450 }
451 }
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000452 regfree(&cpu_part_rgx);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000453
454 // Get min number of threads
455 auto min_common_cores = std::min_element(cpu_part_occurrence_map.begin(), cpu_part_occurrence_map.end(),
456 [](const std::pair<std::string, unsigned int> &p1, const std::pair<std::string, unsigned int> &p2)
457 {
458 return p1.second < p2.second;
459 });
460
461 // Set thread hint
462 num_threads_hint = cpu_part_occurrence_map.empty() ? std::thread::hardware_concurrency() : min_common_cores->second;
Georgios Pinitase8291ac2020-02-26 09:58:13 +0000463#endif /* !defined(BARE_METAL) */
Pablo Tello7fad9b12018-03-14 17:55:27 +0000464
465 return num_threads_hint;
466}
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100467} // namespace cpu
468} // namespace utils
Pablo Tello7fad9b12018-03-14 17:55:27 +0000469} // namespace arm_compute