cpu_info.h 3.2 KB
Newer Older
T
tensor-tang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

H
hong19860320 已提交
17
#include <cstdarg>
T
tensor-tang 已提交
18 19
#include <string>
#include <vector>
20
#include "paddle/fluid/lite/core/lite_tensor.h"
T
tensor-tang 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include "paddle/fluid/lite/utils/cp_logging.h"

namespace paddle {
namespace lite {

#ifdef LITE_WITH_ARM

typedef enum {
  LITE_POWER_HIGH = 0,
  LITE_POWER_LOW = 1,
  LITE_POWER_FULL = 2,
  LITE_POWER_NO_BIND = 3,
  LITE_POWER_RAND_HIGH = 4,
  LITE_POWER_RAND_LOW = 5
} PowerMode;

typedef enum {
  kAPPLE = 0,
  kA53 = 53,
  kA55 = 55,
  kA57 = 57,
  kA72 = 72,
  kA73 = 73,
  kA75 = 75,
  kA76 = 76,
  kARMArch_UNKOWN = -1
} ARMArch;

class DeviceInfo {
 public:
  static DeviceInfo& Global() {
    static auto* x = new DeviceInfo;
    return *x;
  }

H
hong19860320 已提交
56 57 58
  static int Init() {
    static int ret = Global().Setup();
    return ret;
T
tensor-tang 已提交
59 60
  }

H
hong19860320 已提交
61 62 63
  int Setup();

  void SetRunMode(PowerMode mode, int thread_num);
64 65 66 67 68 69
  void SetCache(int l1size, int l2size, int l3size);
  void SetArch(ARMArch arch) { arch_ = arch; }

  PowerMode mode() const { return mode_; }
  int threads() const { return active_ids_.size(); }
  ARMArch arch() const { return arch_; }
H
hong19860320 已提交
70 71 72
  int l1_cache_size() const { return L1_cache_[active_ids_[0]]; }
  int l2_cache_size() const { return L2_cache_[active_ids_[0]]; }
  int l3_cache_size() const { return L3_cache_[active_ids_[0]]; }
73 74 75 76 77 78 79

  template <typename T>
  T* workspace_data() {
    return workspace_.mutable_data<T>();
  }
  bool ExtendWorkspace(DDimLite dims);

T
tensor-tang 已提交
80
 private:
H
hong19860320 已提交
81 82 83 84 85
  int core_num_;
  std::vector<int> max_freqs_;
  std::vector<int> min_freqs_;
  int mem_size_;
  std::string dev_name_;
T
tensor-tang 已提交
86

H
hong19860320 已提交
87 88 89 90 91 92 93 94
  std::vector<int> L1_cache_;
  std::vector<int> L2_cache_;
  std::vector<int> L3_cache_;
  std::vector<int> core_ids_;
  std::vector<int> big_core_ids_;
  std::vector<int> little_core_ids_;
  std::vector<int> cluster_ids_;
  std::vector<ARMArch> archs_;
T
tensor-tang 已提交
95

H
hong19860320 已提交
96 97 98 99 100 101 102 103
  ARMArch arch_;
  // LITE_POWER_HIGH stands for using big cores,
  // LITE_POWER_LOW stands for using small core,
  // LITE_POWER_FULL stands for using all cores
  PowerMode mode_;
  std::vector<int> active_ids_;
  TensorLite workspace_;
  int64_t count_{0};
T
tensor-tang 已提交
104

H
hong19860320 已提交
105 106 107 108 109 110 111 112 113 114
  void SetCacheInfo(int cache_id, int argc, ...);
  void SetArchInfo(int argc, ...);
  bool SetCPUInfoByName();
  void SetCPUInfoByProb();
  void RequestPowerFullMode(const int thread_num);
  void RequestPowerHighMode(const int thread_num);
  void RequestPowerLowMode(const int thread_num);
  void RequestPowerNoBindMode(const int thread_num);
  void RequestPowerRandHighMode(const int shift_num, const int thread_num);
  void RequestPowerRandLowMode(const int shift_num, const int thread_num);
T
tensor-tang 已提交
115

H
hong19860320 已提交
116 117
  DeviceInfo() = default;
};
T
tensor-tang 已提交
118 119 120 121 122

#endif  // LITE_WITH_ARM

}  // namespace lite
}  // namespace paddle