diff --git a/lite/api/CMakeLists.txt b/lite/api/CMakeLists.txt index 173de922f930e8c3aa624c9b8808d6bc0f975926..5d9787f4cb587ae32d1eb36da8de7b1a9d7ee0a4 100644 --- a/lite/api/CMakeLists.txt +++ b/lite/api/CMakeLists.txt @@ -176,7 +176,7 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING) # FPGA_DEPS ${fpga_kernels}) endif() -lite_cc_library(paddle_api SRCS paddle_api.cc DEPS op_params tensor) +lite_cc_library(paddle_api SRCS paddle_api.cc DEPS op_params tensor device_info) #----------------------------------------------------------------------------------------------------- # The final inference library for both CxxConfig and MobileConfig. diff --git a/lite/api/light_api_impl.cc b/lite/api/light_api_impl.cc index 5aa9bfb0857050bc0a8a0242249829c0cf59ae83..4dedc5332db3082ee636eabc8eac1215034b2abe 100644 --- a/lite/api/light_api_impl.cc +++ b/lite/api/light_api_impl.cc @@ -77,29 +77,5 @@ std::shared_ptr CreatePaddlePredictor( return x; } -MobileConfig::MobileConfig(PowerMode mode, int threads) { -#ifdef LITE_WITH_ARM - lite::DeviceInfo::Global().SetRunMode(mode, threads); - mode_ = lite::DeviceInfo::Global().mode(); - threads_ = lite::DeviceInfo::Global().threads(); -#endif -} - -void MobileConfig::set_power_mode(paddle::lite_api::PowerMode mode) { -#ifdef LITE_WITH_ARM - lite::DeviceInfo::Global().SetRunMode(mode, threads_); - mode_ = lite::DeviceInfo::Global().mode(); - threads_ = lite::DeviceInfo::Global().threads(); -#endif -} - -void MobileConfig::set_threads(int threads) { -#ifdef LITE_WITH_ARM - lite::DeviceInfo::Global().SetRunMode(mode_, threads); - mode_ = lite::DeviceInfo::Global().mode(); - threads_ = lite::DeviceInfo::Global().threads(); -#endif -} - } // namespace lite_api } // namespace paddle diff --git a/lite/api/paddle_api.cc b/lite/api/paddle_api.cc index f2841cee0f208f0484a8f8ebe615883f1fc961bb..954d687a481ae70663b77ea51529054af921dc9d 100644 --- a/lite/api/paddle_api.cc +++ b/lite/api/paddle_api.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "lite/api/paddle_api.h" +#include "lite/core/device_info.h" #include "lite/core/tensor.h" namespace paddle { @@ -73,5 +74,30 @@ std::shared_ptr CreatePaddlePredictor(const ConfigT &) { return std::shared_ptr(); } +ConfigBase::ConfigBase(PowerMode mode, int threads) { +#ifdef LITE_WITH_ARM + lite::DeviceInfo::Init(); + lite::DeviceInfo::Global().SetRunMode(mode, threads); + mode_ = lite::DeviceInfo::Global().mode(); + threads_ = lite::DeviceInfo::Global().threads(); +#endif +} + +void ConfigBase::set_power_mode(paddle::lite_api::PowerMode mode) { +#ifdef LITE_WITH_ARM + lite::DeviceInfo::Global().SetRunMode(mode, threads_); + mode_ = lite::DeviceInfo::Global().mode(); + threads_ = lite::DeviceInfo::Global().threads(); +#endif +} + +void ConfigBase::set_threads(int threads) { +#ifdef LITE_WITH_ARM + lite::DeviceInfo::Global().SetRunMode(mode_, threads); + mode_ = lite::DeviceInfo::Global().mode(); + threads_ = lite::DeviceInfo::Global().threads(); +#endif +} + } // namespace lite_api } // namespace paddle diff --git a/lite/api/paddle_api.h b/lite/api/paddle_api.h index 36a6a16ee52a87560ac9c9239041e54266eb50a7..e4da4af4a942d46ffe4429e589762a8878faf54b 100644 --- a/lite/api/paddle_api.h +++ b/lite/api/paddle_api.h @@ -90,11 +90,20 @@ class LITE_API PaddlePredictor { /// Base class for all the configs. class LITE_API ConfigBase { std::string model_dir_; + int threads_{1}; + PowerMode mode_{LITE_POWER_NO_BIND}; public: + explicit ConfigBase(PowerMode mode = LITE_POWER_NO_BIND, int threads = 1); + // set Model_dir void set_model_dir(const std::string& x) { model_dir_ = x; } - const std::string& model_dir() const { return model_dir_; } + // set Power_mode + void set_power_mode(PowerMode mode); + PowerMode power_mode() const { return mode_; } + // set Thread + void set_threads(int threads); + int threads() const { return threads_; } }; /// CxxConfig is the config for the Full feature predictor. @@ -129,16 +138,11 @@ class LITE_API CxxConfig : public ConfigBase { /// MobileConfig is the config for the light weight predictor, it will skip /// IR optimization or other unnecessary stages. class LITE_API MobileConfig : public ConfigBase { - PowerMode mode_{LITE_POWER_HIGH}; - int threads_{1}; std::string model_buffer_; std::string param_buffer_; bool model_from_memory_{false}; public: - explicit MobileConfig(PowerMode mode = LITE_POWER_NO_BIND, int threads = 1); - void set_power_mode(PowerMode mode); - void set_threads(int threads); void set_model_buffer(const char* model_buffer, size_t model_buffer_size, const char* param_buffer, @@ -148,8 +152,6 @@ class LITE_API MobileConfig : public ConfigBase { model_from_memory_ = true; } - PowerMode power_mode() const { return mode_; } - int threads() const { return threads_; } bool model_from_memory() const { return model_from_memory_; } const std::string& model_buffer() const { return model_buffer_; } const std::string& param_buffer() const { return param_buffer_; }