From 845af6e04691f04c49b7f79ffed25ed2317f976c Mon Sep 17 00:00:00 2001 From: Xiaoyang LI Date: Wed, 25 Sep 2019 12:15:54 +0800 Subject: [PATCH] fix arm device_info error, fix bind big core error, improve 855 performance, test=develop (#2133) --- lite/api/benchmark.cc | 2 +- lite/api/mobilenetv1_int8_test.cc | 2 +- lite/api/mobilenetv1_ssd_test.cc | 2 +- lite/api/mobilenetv1_test.cc | 2 +- lite/api/mobilenetv1_yolov3_test.cc | 2 +- lite/api/mobilenetv2_test.cc | 2 +- lite/core/device_info.cc | 102 +++++++++++----------- lite/tests/math/conv_compute_test.cc | 2 +- lite/tests/math/conv_int8_compute_test.cc | 2 +- lite/tests/math/gemm_int8_compute_test.cc | 2 +- lite/tests/math/sgemm_compute_test.cc | 2 +- 11 files changed, 62 insertions(+), 60 deletions(-) diff --git a/lite/api/benchmark.cc b/lite/api/benchmark.cc index e525484c19..3fabd33dc0 100644 --- a/lite/api/benchmark.cc +++ b/lite/api/benchmark.cc @@ -68,7 +68,7 @@ void Run(const std::vector>& input_shapes, lite_api::MobileConfig config; config.set_threads(thread_num); if (thread_num == 1) { - config.set_power_mode(LITE_POWER_HIGH); + config.set_power_mode(LITE_POWER_NO_BIND); } else { config.set_power_mode(LITE_POWER_NO_BIND); } diff --git a/lite/api/mobilenetv1_int8_test.cc b/lite/api/mobilenetv1_int8_test.cc index 0b6c3216ce..472e2a2595 100644 --- a/lite/api/mobilenetv1_int8_test.cc +++ b/lite/api/mobilenetv1_int8_test.cc @@ -28,7 +28,7 @@ namespace lite { void TestModel(const std::vector& valid_places, const Place& preferred_place) { DeviceInfo::Init(); - DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); + DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads); lite::Predictor predictor; predictor.Build(FLAGS_model_dir, "", "", preferred_place, valid_places); diff --git a/lite/api/mobilenetv1_ssd_test.cc b/lite/api/mobilenetv1_ssd_test.cc index e37e180f9b..c93da43c11 100644 --- a/lite/api/mobilenetv1_ssd_test.cc +++ b/lite/api/mobilenetv1_ssd_test.cc @@ -29,7 +29,7 @@ namespace lite { void TestModel(const std::vector& valid_places, const Place& preferred_place) { DeviceInfo::Init(); - DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); + DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads); lite::Predictor predictor; predictor.Build(FLAGS_model_dir, "", "", preferred_place, valid_places); diff --git a/lite/api/mobilenetv1_test.cc b/lite/api/mobilenetv1_test.cc index 91d1828a94..f4bb7318df 100644 --- a/lite/api/mobilenetv1_test.cc +++ b/lite/api/mobilenetv1_test.cc @@ -32,7 +32,7 @@ void TestModel(const std::vector& valid_places, const std::string& model_dir = FLAGS_model_dir, bool save_model = false) { DeviceInfo::Init(); - DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); + DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads); lite::Predictor predictor; predictor.Build(model_dir, "", "", preferred_place, valid_places); diff --git a/lite/api/mobilenetv1_yolov3_test.cc b/lite/api/mobilenetv1_yolov3_test.cc index 3a12203b71..7ea33528ca 100644 --- a/lite/api/mobilenetv1_yolov3_test.cc +++ b/lite/api/mobilenetv1_yolov3_test.cc @@ -29,7 +29,7 @@ namespace lite { void TestModel(const std::vector& valid_places, const Place& preferred_place) { DeviceInfo::Init(); - DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); + DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads); lite::Predictor predictor; predictor.Build(FLAGS_model_dir, "", "", preferred_place, valid_places); diff --git a/lite/api/mobilenetv2_test.cc b/lite/api/mobilenetv2_test.cc index ca36943cb9..09dbd0f8bf 100644 --- a/lite/api/mobilenetv2_test.cc +++ b/lite/api/mobilenetv2_test.cc @@ -33,7 +33,7 @@ void TestModel(const std::vector& valid_places, const std::string& model_dir = FLAGS_model_dir, bool save_model = false) { DeviceInfo::Init(); - DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); + DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads); lite::Predictor predictor; predictor.Build(model_dir, "", "", preferred_place, valid_places); diff --git a/lite/core/device_info.cc b/lite/core/device_info.cc index de53d9ba67..078464ccf4 100644 --- a/lite/core/device_info.cc +++ b/lite/core/device_info.cc @@ -237,65 +237,74 @@ std::string get_cpu_name() { return ""; } -void get_cpu_max_min_freq(int cpu_id, int* max_freq, int* min_freq) { - *max_freq = 0; - *min_freq = 0; +int get_min_freq_khz(int cpuid) { + // first try, for all possible cpu + char path[256]; + snprintf(path, + sizeof(path), + "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", + cpuid); + FILE* fp = fopen(path, "rb"); + if (!fp) { + return -1; + } + + int min_freq_khz = -1; + fscanf(fp, "%d", &min_freq_khz); + fclose(fp); + return min_freq_khz; +} + +int get_max_freq_khz(int cpuid) { // first try, for all possible cpu char path[256]; snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpufreq/stats/cpu%d/time_in_state", - cpu_id); + cpuid); + FILE* fp = fopen(path, "rb"); if (!fp) { // second try, for online cpu snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/stats/time_in_state", - cpu_id); + cpuid); fp = fopen(path, "rb"); - if (!fp) { - // third try, for online cpu - // get max_freq - snprintf(path, - sizeof(path), - "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", - cpu_id); - fp = fopen(path, "rb"); - if (!fp) { - return; + } + + int max_freq_khz = 0; + if (fp) { + while (!feof(fp)) { + int freq_khz = 0; + int nscan = fscanf(fp, "%d %*d", &freq_khz); + if (nscan != 1) { + break; } - fscanf(fp, "%d", max_freq); - fclose(fp); - // get min_freq - snprintf(path, - sizeof(path), - "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", - cpu_id); - fp = fopen(path, "rb"); - if (!fp) { - return; + + if (freq_khz > max_freq_khz) { + max_freq_khz = freq_khz; } - fscanf(fp, "%d", min_freq); - fclose(fp); - return; } } - *min_freq = std::numeric_limits::max(); - while (!feof(fp)) { - int freq = 0; - int nscan = fscanf(fp, "%d %*d", &freq); - if (nscan != 1) { - break; - } - if (freq > *max_freq) { - *max_freq = freq; - } - if (freq < *min_freq) { - *min_freq = freq; + if (max_freq_khz == 0 || !fp) { + // third try, for online cpu + snprintf(path, + sizeof(path), + "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", + cpuid); + fp = fopen(path, "rb"); + if (!fp) { + return -1; } + int max_freq_khz = -1; + fscanf(fp, "%d", &max_freq_khz); + fclose(fp); + return max_freq_khz; } + fclose(fp); + return max_freq_khz; } void sort_cpuid_by_max_freq(const std::vector& max_freqs, @@ -835,7 +844,7 @@ void DeviceInfo::RequestPowerHighMode(int thread_num) { active_ids_ = big_core_ids_; } else { for (int i = 0; i < thread_num; ++i) { - active_ids_.push_back(big_core_ids_[i]); + active_ids_.push_back(big_core_ids_[big_core_size - 1 - i]); } } } else { @@ -972,8 +981,8 @@ int DeviceInfo::Setup() { #ifdef LITE_WITH_LINUX // get max&min freq for (int i = 0; i < core_num_; ++i) { - int max_freq, min_freq; - get_cpu_max_min_freq(i, &max_freq, &min_freq); + int max_freq = get_max_freq_khz(i); + int min_freq = get_min_freq_khz(i); max_freqs_[i] = max_freq / 1000; min_freqs_[i] = min_freq / 1000; } @@ -982,13 +991,6 @@ int DeviceInfo::Setup() { if (!SetCPUInfoByName()) { SetCPUInfoByProb(); } - core_ids_.resize(core_num_); - cluster_ids_.resize(core_num_); - for (int i = 0; i < core_num_; ++i) { - max_freqs_[i] = 1000000; - min_freqs_[i] = 1000000; - cluster_ids_[i] = 0; - } #else #ifdef TARGET_IOS dev_name_ = "Apple"; diff --git a/lite/tests/math/conv_compute_test.cc b/lite/tests/math/conv_compute_test.cc index dfb0ec0cd7..aa83c5163a 100644 --- a/lite/tests/math/conv_compute_test.cc +++ b/lite/tests/math/conv_compute_test.cc @@ -24,7 +24,7 @@ #include "lite/kernels/arm/conv_compute.h" #endif // LITE_WITH_ARM -DEFINE_int32(cluster, 0, "cluster id"); +DEFINE_int32(cluster, 3, "cluster id"); DEFINE_int32(threads, 1, "threads num"); DEFINE_int32(warmup, 0, "warmup times"); DEFINE_int32(repeats, 1, "repeats times"); diff --git a/lite/tests/math/conv_int8_compute_test.cc b/lite/tests/math/conv_int8_compute_test.cc index 9a03e7cd63..b2ad011f8c 100644 --- a/lite/tests/math/conv_int8_compute_test.cc +++ b/lite/tests/math/conv_int8_compute_test.cc @@ -24,7 +24,7 @@ #include "lite/kernels/arm/conv_compute.h" #endif // LITE_WITH_ARM -DEFINE_int32(cluster, 0, "cluster id"); +DEFINE_int32(cluster, 3, "cluster id"); DEFINE_int32(threads, 1, "threads num"); DEFINE_int32(warmup, 0, "warmup times"); DEFINE_int32(repeats, 1, "repeats times"); diff --git a/lite/tests/math/gemm_int8_compute_test.cc b/lite/tests/math/gemm_int8_compute_test.cc index 02bf8dbd43..575dc27cb2 100644 --- a/lite/tests/math/gemm_int8_compute_test.cc +++ b/lite/tests/math/gemm_int8_compute_test.cc @@ -26,7 +26,7 @@ typedef paddle::lite::Tensor Tensor; -DEFINE_int32(cluster, 0, "cluster id"); +DEFINE_int32(cluster, 3, "cluster id"); DEFINE_int32(threads, 1, "threads num"); DEFINE_int32(warmup, 0, "warmup times"); DEFINE_int32(repeats, 1, "repeats times"); diff --git a/lite/tests/math/sgemm_compute_test.cc b/lite/tests/math/sgemm_compute_test.cc index 7744bb6df1..56cdf6179a 100644 --- a/lite/tests/math/sgemm_compute_test.cc +++ b/lite/tests/math/sgemm_compute_test.cc @@ -26,7 +26,7 @@ typedef paddle::lite::Tensor Tensor; -DEFINE_int32(cluster, 0, "cluster id"); +DEFINE_int32(cluster, 3, "cluster id"); DEFINE_int32(threads, 1, "threads num"); DEFINE_int32(warmup, 0, "warmup times"); DEFINE_int32(repeats, 1, "repeats times"); -- GitLab