From 807156f1890df33618975f5a1512163e57f40746 Mon Sep 17 00:00:00 2001 From: Bin Li Date: Thu, 10 May 2018 17:15:16 +0800 Subject: [PATCH] fix GetCPUBigLittleCoreIDs --- mace/core/runtime/cpu/cpu_runtime.cc | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/mace/core/runtime/cpu/cpu_runtime.cc b/mace/core/runtime/cpu/cpu_runtime.cc index 88754f23..c0c97c35 100644 --- a/mace/core/runtime/cpu/cpu_runtime.cc +++ b/mace/core/runtime/cpu/cpu_runtime.cc @@ -126,7 +126,6 @@ MaceStatus GetCPUBigLittleCoreIDs(std::vector *big_core_ids, int cpu_count = GetCPUCount(); #endif std::vector cpu_max_freq(cpu_count); - std::vector cpu_ids(cpu_count); // set cpu max frequency for (int i = 0; i < cpu_count; ++i) { @@ -136,25 +135,21 @@ MaceStatus GetCPUBigLittleCoreIDs(std::vector *big_core_ids, << "'s max frequency info, maybe it is offline."; return MACE_INVALID_ARGS; } - cpu_ids[i] = i; } - // sort cpu ids by max frequency asc - std::sort(cpu_ids.begin(), cpu_ids.end(), - [&cpu_max_freq](int a, int b) { - return cpu_max_freq[a] < cpu_max_freq[b]; - }); + int big_core_freq = + *(std::max_element(cpu_max_freq.begin(), cpu_max_freq.end())); + int little_core_freq = + *(std::min_element(cpu_max_freq.begin(), cpu_max_freq.end())); big_core_ids->reserve(cpu_count); little_core_ids->reserve(cpu_count); - int little_core_freq = cpu_max_freq.front(); - int big_core_freq = cpu_max_freq.back(); for (int i = 0; i < cpu_count; ++i) { if (cpu_max_freq[i] == little_core_freq) { - little_core_ids->push_back(cpu_ids[i]); + little_core_ids->push_back(i); } if (cpu_max_freq[i] == big_core_freq) { - big_core_ids->push_back(cpu_ids[i]); + big_core_ids->push_back(i); } } -- GitLab