Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] fix incorrect bubble sort in sort_cpuid_by_max_freq, add header file that should be included in metal_converter.h #10518

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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