blob: e874f0f14b0fd2921b0fcd458b954c9c8c2d6bf8 [file] [log] [blame]
Pablo Tello7fad9b12018-03-14 17:55:27 +00001/*
Georgios Pinitase8291ac2020-02-26 09:58:13 +00002 * 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 */
24#include "arm_compute/runtime/CPUUtils.h"
25
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;
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100129 case 0xd0a: // A75
130 if(variant != 0)
131 {
132 model = CPUModel::GENERIC_FP16_DOT;
133 }
134 else
135 {
136 model = CPUModel::GENERIC_FP16;
137 }
138 break;
139 case 0xd0b: // A76
Isabella Gottardibe2de402018-11-21 15:23:49 +0000140 case 0xd06:
141 case 0xd0c:
142 case 0xd0d:
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100143 model = CPUModel::GENERIC_FP16_DOT;
144 break;
145 default:
146 model = CPUModel::GENERIC;
147 break;
148 }
Pablo Tello7fad9b12018-03-14 17:55:27 +0000149 }
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100150 else if(implementer == 0x48)
Georgios Pinitas18960692018-12-21 18:18:46 +0000151 {
152 // Only CPUs we have code paths for are detected. All other CPUs can be safely classed as "GENERIC"
153 switch(cpunum)
154 {
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100155 case 0xd40: // A76
Georgios Pinitas18960692018-12-21 18:18:46 +0000156 model = CPUModel::GENERIC_FP16_DOT;
157 break;
158 default:
159 model = CPUModel::GENERIC;
160 break;
161 }
162 }
Pablo Tello7fad9b12018-03-14 17:55:27 +0000163
164 return model;
165}
166
Anthony Barbier3efb3752018-07-20 15:30:46 +0100167void populate_models_cpuid(std::vector<CPUModel> &cpusv)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000168{
169 // If the CPUID capability is present, MIDR information is provided in /sys. Use that to populate the CPU model table.
170 uint32_t i = 0;
171 for(auto &c : cpusv)
172 {
173 std::stringstream str;
174 str << "/sys/devices/system/cpu/cpu" << i++ << "/regs/identification/midr_el1";
175 std::ifstream file;
176 file.open(str.str(), std::ios::in);
177 if(file.is_open())
178 {
179 std::string line;
180 if(bool(getline(file, line)))
181 {
Georgios Pinitas9c2ec7e2018-11-12 17:07:18 +0000182 const uint32_t midr = support::cpp11::stoul(line, nullptr, support::cpp11::NumericBase::BASE_16);
183 c = midr_to_model(midr & 0xffffffff);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000184 }
185 }
186 }
187}
188
Anthony Barbier3efb3752018-07-20 15:30:46 +0100189void populate_models_cpuinfo(std::vector<CPUModel> &cpusv)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000190{
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000191 regex_t proc_regex;
192 regex_t imp_regex;
193 regex_t var_regex;
194 regex_t part_regex;
195 regex_t rev_regex;
196
197 memset(&proc_regex, 0, sizeof(regex_t));
198 memset(&imp_regex, 0, sizeof(regex_t));
199 memset(&var_regex, 0, sizeof(regex_t));
200 memset(&part_regex, 0, sizeof(regex_t));
201 memset(&rev_regex, 0, sizeof(regex_t));
202
203 int ret_status = 0;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000204 // If "long-form" cpuinfo is present, parse that to populate models.
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000205 ret_status |= regcomp(&proc_regex, R"(^processor.*([[:digit:]]+)$)", REG_EXTENDED);
206 ret_status |= regcomp(&imp_regex, R"(^CPU implementer.*0x(..)$)", REG_EXTENDED);
207 ret_status |= regcomp(&var_regex, R"(^CPU variant.*0x(.)$)", REG_EXTENDED);
208 ret_status |= regcomp(&part_regex, R"(^CPU part.*0x(...)$)", REG_EXTENDED);
209 ret_status |= regcomp(&rev_regex, R"(^CPU revision.*([[:digit:]]+)$)", REG_EXTENDED);
210 ARM_COMPUTE_UNUSED(ret_status);
211 ARM_COMPUTE_ERROR_ON_MSG(ret_status != 0, "Regex compilation failed.");
Pablo Tello7fad9b12018-03-14 17:55:27 +0000212
213 std::ifstream file;
214 file.open("/proc/cpuinfo", std::ios::in);
215
216 if(file.is_open())
217 {
218 std::string line;
219 int midr = 0;
220 int curcpu = -1;
221
222 while(bool(getline(file, line)))
223 {
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100224 std::array<regmatch_t, 2> match;
225 ret_status = regexec(&proc_regex, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000226 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000227 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000228 std::string id = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
Pablo Tello65f99822018-05-24 11:40:15 +0100229 int newcpu = support::cpp11::stoi(id, nullptr);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000230
231 if(curcpu >= 0 && midr == 0)
232 {
233 // Matched a new CPU ID without any description of the previous one - looks like old format.
234 return;
235 }
236
237 if(curcpu >= 0)
238 {
Anthony Barbier3efb3752018-07-20 15:30:46 +0100239 cpusv[curcpu] = midr_to_model(midr);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000240 }
241
242 midr = 0;
243 curcpu = newcpu;
244
245 continue;
246 }
247
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100248 ret_status = regexec(&imp_regex, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000249 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000250 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000251 std::string subexp = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
252 int impv = support::cpp11::stoi(subexp, nullptr, support::cpp11::NumericBase::BASE_16);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000253 midr |= (impv << 24);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000254
Pablo Tello7fad9b12018-03-14 17:55:27 +0000255 continue;
256 }
257
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100258 ret_status = regexec(&var_regex, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000259 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000260 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000261 std::string subexp = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
262 int varv = support::cpp11::stoi(subexp, nullptr, support::cpp11::NumericBase::BASE_16);
Anthony Barbier3efb3752018-07-20 15:30:46 +0100263 midr |= (varv << 20);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000264
Pablo Tello7fad9b12018-03-14 17:55:27 +0000265 continue;
266 }
267
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100268 ret_status = regexec(&part_regex, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000269 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000270 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000271 std::string subexp = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
272 int partv = support::cpp11::stoi(subexp, nullptr, support::cpp11::NumericBase::BASE_16);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000273 midr |= (partv << 4);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000274
Pablo Tello7fad9b12018-03-14 17:55:27 +0000275 continue;
276 }
277
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100278 ret_status = regexec(&rev_regex, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000279 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000280 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000281 std::string subexp = line.substr(match[1].rm_so, (match[1].rm_eo - match[1].rm_so));
282 int regv = support::cpp11::stoi(subexp, nullptr);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000283 midr |= (regv);
284 midr |= (0xf << 16);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000285
Pablo Tello7fad9b12018-03-14 17:55:27 +0000286 continue;
287 }
288 }
289
290 if(curcpu >= 0)
291 {
Anthony Barbier3efb3752018-07-20 15:30:46 +0100292 cpusv[curcpu] = midr_to_model(midr);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000293 }
294 }
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000295
296 // Free allocated memory
297 regfree(&proc_regex);
298 regfree(&imp_regex);
299 regfree(&var_regex);
300 regfree(&part_regex);
301 regfree(&rev_regex);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000302}
303
304int get_max_cpus()
305{
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100306 int max_cpus = 1;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000307 std::ifstream CPUspresent;
308 CPUspresent.open("/sys/devices/system/cpu/present", std::ios::in);
309 bool success = false;
310
311 if(CPUspresent.is_open())
312 {
313 std::string line;
314
315 if(bool(getline(CPUspresent, line)))
316 {
317 /* The content of this file is a list of ranges or single values, e.g.
318 * 0-5, or 1-3,5,7 or similar. As we are interested in the
319 * max valid ID, we just need to find the last valid
320 * delimiter ('-' or ',') and parse the integer immediately after that.
321 */
322 auto startfrom = line.begin();
323
324 for(auto i = line.begin(); i < line.end(); ++i)
325 {
326 if(*i == '-' || *i == ',')
327 {
328 startfrom = i + 1;
329 }
330 }
331
332 line.erase(line.begin(), startfrom);
333
Pablo Tello65f99822018-05-24 11:40:15 +0100334 max_cpus = support::cpp11::stoi(line, nullptr) + 1;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000335 success = true;
336 }
337 }
338
339 // Return std::thread::hardware_concurrency() as a fallback.
340 if(!success)
341 {
342 max_cpus = std::thread::hardware_concurrency();
343 }
Pablo Tello7fad9b12018-03-14 17:55:27 +0000344 return max_cpus;
345}
346#endif /* !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) */
347
348} // namespace
349
350namespace arm_compute
351{
352void get_cpu_configuration(CPUInfo &cpuinfo)
353{
354#if !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__))
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100355 bool cpuid = false;
356 bool hwcaps_fp16_support = false;
357 bool hwcaps_dot_support = false;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000358
359 const uint32_t hwcaps = getauxval(AT_HWCAP);
360
361 if((hwcaps & HWCAP_CPUID) != 0)
362 {
363 cpuid = true;
364 }
365
366 if((hwcaps & HWCAP_ASIMDHP) != 0)
367 {
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100368 hwcaps_fp16_support = true;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000369 }
370
Pablo Tellodf3b5bb2018-10-09 10:51:51 +0100371#if defined(__aarch64__)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000372 if((hwcaps & HWCAP_ASIMDDP) != 0)
373 {
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +0100374 hwcaps_dot_support = true;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000375 }
Pablo Tellodf3b5bb2018-10-09 10:51:51 +0100376#endif /* defined(__aarch64__) */
Pablo Tello7fad9b12018-03-14 17:55:27 +0000377
Pablo Tello7fad9b12018-03-14 17:55:27 +0000378 const unsigned int max_cpus = get_max_cpus();
379 cpuinfo.set_cpu_num(max_cpus);
Anthony Barbier3efb3752018-07-20 15:30:46 +0100380 std::vector<CPUModel> percpu(max_cpus, CPUModel::GENERIC);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000381 if(cpuid)
382 {
383 populate_models_cpuid(percpu);
384 }
385 else
386 {
387 populate_models_cpuinfo(percpu);
388 }
389 int j(0);
Georgios Pinitasecae3a12018-10-09 15:13:12 +0100390 // Update dot product and FP16 support if one of the CPUs support these features
391 // We assume that the system does not have mixed architectures
392 bool one_supports_dot = false;
393 bool one_supports_fp16 = false;
Pablo Tello7fad9b12018-03-14 17:55:27 +0000394 for(const auto &v : percpu)
395 {
Georgios Pinitas9c2ec7e2018-11-12 17:07:18 +0000396 one_supports_dot = one_supports_dot || model_supports_dot(v);
397 one_supports_fp16 = one_supports_fp16 || model_supports_fp16(v);
Anthony Barbier3efb3752018-07-20 15:30:46 +0100398 cpuinfo.set_cpu_model(j++, v);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000399 }
Georgios Pinitasecae3a12018-10-09 15:13:12 +0100400 cpuinfo.set_dotprod(one_supports_dot || hwcaps_dot_support);
401 cpuinfo.set_fp16(one_supports_fp16 || hwcaps_fp16_support);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000402#else /* !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) */
403 ARM_COMPUTE_UNUSED(cpuinfo);
404#endif /* !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) */
405}
406
407unsigned int get_threads_hint()
408{
409 unsigned int num_threads_hint = 1;
410
Georgios Pinitase8291ac2020-02-26 09:58:13 +0000411#if !defined(BARE_METAL)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000412 std::map<std::string, unsigned int> cpu_part_occurrence_map;
413
414 // CPU part regex
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000415 regex_t cpu_part_rgx;
416 memset(&cpu_part_rgx, 0, sizeof(regex_t));
Georgios Pinitasde6dbfe2018-12-24 15:02:55 +0000417 int ret_status = regcomp(&cpu_part_rgx, R"(.*CPU part.+/?\:[[:space:]]+([[:alnum:]]+).*)", REG_EXTENDED);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000418 ARM_COMPUTE_UNUSED(ret_status);
419 ARM_COMPUTE_ERROR_ON_MSG(ret_status != 0, "Regex compilation failed.");
Pablo Tello7fad9b12018-03-14 17:55:27 +0000420
421 // Read cpuinfo and get occurrence of each core
422 std::ifstream cpuinfo;
423 cpuinfo.open("/proc/cpuinfo", std::ios::in);
424 if(cpuinfo.is_open())
425 {
426 std::string line;
427 while(bool(getline(cpuinfo, line)))
428 {
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100429 std::array<regmatch_t, 2> match;
430 ret_status = regexec(&cpu_part_rgx, line.c_str(), 2, match.data(), 0);
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000431 if(ret_status == 0)
Pablo Tello7fad9b12018-03-14 17:55:27 +0000432 {
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000433 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 +0000434 if(cpu_part_occurrence_map.find(cpu_part) != cpu_part_occurrence_map.end())
435 {
436 cpu_part_occurrence_map[cpu_part]++;
437 }
438 else
439 {
440 cpu_part_occurrence_map[cpu_part] = 1;
441 }
442 }
443 }
444 }
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000445 regfree(&cpu_part_rgx);
Pablo Tello7fad9b12018-03-14 17:55:27 +0000446
447 // Get min number of threads
448 auto min_common_cores = std::min_element(cpu_part_occurrence_map.begin(), cpu_part_occurrence_map.end(),
449 [](const std::pair<std::string, unsigned int> &p1, const std::pair<std::string, unsigned int> &p2)
450 {
451 return p1.second < p2.second;
452 });
453
454 // Set thread hint
455 num_threads_hint = cpu_part_occurrence_map.empty() ? std::thread::hardware_concurrency() : min_common_cores->second;
Georgios Pinitase8291ac2020-02-26 09:58:13 +0000456#endif /* !defined(BARE_METAL) */
Pablo Tello7fad9b12018-03-14 17:55:27 +0000457
458 return num_threads_hint;
459}
460
461} // namespace arm_compute