Skip to content

Commit

Permalink
[core] fix incorrect bubble sort in sort_cpuid_by_max_freq, add heade…
Browse files Browse the repository at this point in the history
…r file that should be included in metal_converter.h,test=develop (#10518)
  • Loading branch information
ddchenhao66 authored May 20, 2024
1 parent 0741366 commit 7aa1db7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
1 change: 1 addition & 0 deletions lite/backends/metal/metal_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "lite/backends/metal/metal_common.h"
#include "lite/backends/metal/metal_half.h"
#include "lite/core/dim.h"
#include <cassert>

namespace paddle {
namespace lite {
Expand Down
18 changes: 3 additions & 15 deletions lite/core/device_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,24 +422,12 @@ void sort_cpuid_by_max_freq(const std::vector<int>& max_freqs,
for (int i = 0; i < cpu_num; i++) {
cpu_ids->at(i) = i;
}
// sort cpuid as big core first
// simple bubble sort
for (int i = 0; i < cpu_num; i++) {
for (int j = i + 1; j < cpu_num; j++) {
if (max_freqs[i] < max_freqs[j]) {
// swap
int tmp = cpu_ids->at(i);
cpu_ids->at(i) = cpu_ids->at(j);
cpu_ids->at(j) = tmp;
}
}
}
// SMP
int mid_max_freq =
(max_freqs[cpu_ids->at(0)] + max_freqs[cpu_ids->at(cpu_num - 1)]) / 2;
int freq_max = *std::max_element(max_freqs.begin(), max_freqs.end());
int freq_min = *std::min_element(max_freqs.begin(), max_freqs.end());
int mid_max_freq = (freq_max + freq_min) / 2;

for (int i = 0; i < cpu_num; i++) {
cpu_ids->at(i) = i;
if (max_freqs[i] >= mid_max_freq) {
cluster_ids->at(i) = 0;
} else {
Expand Down

0 comments on commit 7aa1db7

Please sign in to comment.