// 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 #include #include #include #include "lite/core/tensor.h" #include "lite/utils/cp_logging.h" namespace paddle { namespace lite { #ifdef LITE_WITH_ARM 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; } static int Init() { static int ret = Global().Setup(); return ret; } int Setup(); void SetRunMode(lite_api::PowerMode mode, int thread_num); void SetCache(int l1size, int l2size, int l3size); void SetArch(ARMArch arch) { arch_ = arch; } lite_api::PowerMode mode() const { return mode_; } int threads() const { return active_ids_.size(); } ARMArch arch() const { return arch_; } 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]]; } int llc_size() const { auto size = L3_cache_[active_ids_[0]] > 0 ? L3_cache_[active_ids_[0]] : L2_cache_[active_ids_[0]]; return size > 0 ? size : 512 * 1024; } bool has_dot() const { return dot_[active_ids_[0]]; } bool has_fp16() const { return fp16_[active_ids_[0]]; } template T* workspace_data() { return reinterpret_cast(workspace_.mutable_data()); } bool ExtendWorkspace(int size); private: int core_num_; std::vector max_freqs_; std::vector min_freqs_; int mem_size_; std::string dev_name_; std::vector L1_cache_; std::vector L2_cache_; std::vector L3_cache_; std::vector core_ids_; std::vector big_core_ids_; std::vector little_core_ids_; std::vector cluster_ids_; std::vector archs_; std::vector fp32_; std::vector fp16_; std::vector dot_; 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 lite_api::PowerMode mode_; std::vector active_ids_; TensorLite workspace_; int64_t count_{0}; void SetDotInfo(int argc, ...); void SetFP16Info(int argc, ...); void SetFP32Info(int argc, ...); void SetCacheInfo(int cache_id, int argc, ...); void SetArchInfo(int argc, ...); bool SetCPUInfoByName(); void SetCPUInfoByProb(); void RequestPowerFullMode(int thread_num); void RequestPowerHighMode(int thread_num); void RequestPowerLowMode(int thread_num); void RequestPowerNoBindMode(int thread_num); void RequestPowerRandHighMode(int shift_num, int thread_num); void RequestPowerRandLowMode(int shift_num, int thread_num); DeviceInfo() = default; }; #endif // LITE_WITH_ARM } // namespace lite } // namespace paddle